use of org.eclipse.wst.xsd.ui.internal.adt.design.FlatCCombo in project webtools.sourceediting by eclipse.
the class CommonMultiPageEditor method createViewModeToolbar.
protected void createViewModeToolbar(Composite parent) {
EditorModeManager manager = (EditorModeManager) getAdapter(EditorModeManager.class);
final ProductCustomizationProvider productCustomizationProvider = (ProductCustomizationProvider) getAdapter(ProductCustomizationProvider.class);
EditorMode[] modeList = manager.getModes();
int modeListLength = modeList.length;
boolean showToolBar = modeListLength > 1;
if (showToolBar) {
toolbar = new Composite(parent, SWT.FLAT | SWT.DRAW_TRANSPARENT);
toolbar.setBackground(ColorConstants.listBackground);
toolbar.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Rectangle clientArea = toolbar.getClientArea();
e.gc.setForeground(ColorConstants.lightGray);
e.gc.drawRectangle(clientArea.x, clientArea.y, clientArea.width - 1, clientArea.height - 1);
}
});
GridLayout gridLayout = new GridLayout(3, false);
toolbar.setLayout(gridLayout);
Label label = new Label(toolbar, SWT.FLAT | SWT.HORIZONTAL);
label.setBackground(ColorConstants.listBackground);
label.setText(Messages._UI_LABEL_VIEW);
label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));
modeCombo = new FlatCCombo(toolbar, SWT.FLAT);
modeCombo.setEditable(false);
modeCombo.setText(getEditModeName(manager.getCurrentMode(), productCustomizationProvider));
GC gc = new GC(modeCombo);
int textWidth = 0;
maxLength = 0;
// populate combo with modes
editorModeAndCustomizedNames = new EditorModeAndCustomizedName[modeListLength];
for (int i = 0; i < modeListLength; i++) {
EditorModeAndCustomizedName entry = new EditorModeAndCustomizedName();
editorModeAndCustomizedNames[i] = entry;
entry.name = getEditModeName(modeList[i], productCustomizationProvider);
entry.mode = modeList[i];
}
Arrays.sort(editorModeAndCustomizedNames, new Comparator() {
public int compare(Object arg0, Object arg1) {
EditorModeAndCustomizedName a = (EditorModeAndCustomizedName) arg0;
EditorModeAndCustomizedName b = (EditorModeAndCustomizedName) arg1;
return Collator.getInstance().compare(a.name, b.name);
}
});
for (int i = 0; i < editorModeAndCustomizedNames.length; i++) {
EditorModeAndCustomizedName entry = editorModeAndCustomizedNames[i];
modeCombo.add(entry.name);
maxLength = Math.max(gc.stringExtent(entry.name).x, maxLength);
int approxWidthOfStrings = Math.max(gc.stringExtent(entry.name).x, textWidth);
if (approxWidthOfStrings > maxLength)
maxLength = approxWidthOfStrings;
}
maxLength += gc.stringExtent(Messages._UI_LABEL_VIEW).x;
gc.dispose();
modeComboListener = new ModeComboListener();
modeCombo.addSelectionListener(modeComboListener);
modeCombo.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));
modeCombo.setBackground(toolbar.getBackground());
ImageHyperlink hyperlink = new ImageHyperlink(toolbar, SWT.FLAT);
hyperlink.setBackground(ColorConstants.white);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=154457
Image image = XSDEditorPlugin.getDefault().getIconImage("etool16/help_contents");
hyperlink.setImage(image);
hyperlink.setToolTipText(Messages._UI_HOVER_VIEW_MODE_DESCRIPTION);
hyperlink.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));
hyperlink.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
if (productCustomizationProvider != null) {
productCustomizationProvider.handleAction("showEditorModeHelp");
}
}
});
}
}
Aggregations