Search in sources :

Example 1 with FlatCCombo

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");
                }
            }
        });
    }
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) PaintListener(org.eclipse.swt.events.PaintListener) Rectangle(org.eclipse.swt.graphics.Rectangle) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.draw2d.geometry.Point) Comparator(java.util.Comparator) GridLayout(org.eclipse.swt.layout.GridLayout) FlatCCombo(org.eclipse.wst.xsd.ui.internal.adt.design.FlatCCombo) GridData(org.eclipse.swt.layout.GridData) EventObject(java.util.EventObject) GC(org.eclipse.swt.graphics.GC)

Aggregations

Comparator (java.util.Comparator)1 EventObject (java.util.EventObject)1 Point (org.eclipse.draw2d.geometry.Point)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 PaintEvent (org.eclipse.swt.events.PaintEvent)1 PaintListener (org.eclipse.swt.events.PaintListener)1 GC (org.eclipse.swt.graphics.GC)1 Image (org.eclipse.swt.graphics.Image)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 ImageHyperlink (org.eclipse.ui.forms.widgets.ImageHyperlink)1 FlatCCombo (org.eclipse.wst.xsd.ui.internal.adt.design.FlatCCombo)1