Example usage for org.eclipse.jface.action ToolBarManager dispose

List of usage examples for org.eclipse.jface.action ToolBarManager dispose

Introduction

In this page you can find the example usage for org.eclipse.jface.action ToolBarManager dispose.

Prototype

public void dispose() 

Source Link

Document

Disposes of this tool bar manager and frees all allocated SWT resources.

Usage

From source file:org.eclipse.ui.tests.menus.MenuPopulationTest.java

License:Open Source License

public void testToolBarItems() throws Exception {
    Field iconField = CommandContributionItem.class.getDeclaredField(FIELD_ICON);
    iconField.setAccessible(true);/* ww w.j  a  v a  2 s.  c  o  m*/

    ToolBarManager manager = new ToolBarManager();
    menuService.populateContributionManager(manager, "toolbar:" + TEST_CONTRIBUTIONS_CACHE_ID);

    IContributionItem ici = manager.find(ID_DEFAULT);
    assertTrue(ici instanceof CommandContributionItem);
    CommandContributionItem cmd = (CommandContributionItem) ici;

    ImageDescriptor icon = (ImageDescriptor) iconField.get(cmd);
    assertNotNull(icon);
    String iconString = icon.toString();
    assertEquals(ICONS_ANYTHING_GIF, iconString.substring(iconString.lastIndexOf('/')));

    ici = manager.find(ID_ALL);
    assertTrue(ici instanceof CommandContributionItem);
    cmd = (CommandContributionItem) ici;
    icon = (ImageDescriptor) iconField.get(cmd);
    assertNotNull(icon);
    iconString = icon.toString();
    assertEquals(ICONS_MOCK_GIF, iconString.substring(iconString.lastIndexOf('/')));

    ici = manager.find(ID_TOOLBAR);
    assertTrue(ici instanceof CommandContributionItem);
    cmd = (CommandContributionItem) ici;
    icon = (ImageDescriptor) iconField.get(cmd);
    assertNotNull(icon);
    iconString = icon.toString();
    assertEquals(ICONS_VIEW_GIF, iconString.substring(iconString.lastIndexOf('/')));

    manager.dispose();
}

From source file:org.jboss.tools.vpe.editor.mozilla.MozillaEditor.java

License:Open Source License

public ToolBar createVisualToolbar(Composite parent) {
    final ToolBarManager toolBarManager = new ToolBarManager(SWT.VERTICAL | SWT.FLAT);
    verBar = toolBarManager.createControl(parent);

    /*// w w w .  j  av  a 2  s  . c  o  m
     * Create OPEN VPE PREFERENCES tool bar item
     */
    openVPEPreferencesAction = new Action(VpeUIMessages.PREFERENCES, IAction.AS_PUSH_BUTTON) {
        @Override
        public void run() {
            VpeEditorPreferencesPage.openPreferenceDialog();
        }
    };
    openVPEPreferencesAction
            .setImageDescriptor(ImageDescriptor.createFromFile(MozillaEditor.class, ICON_PREFERENCE));
    openVPEPreferencesAction.setToolTipText(VpeUIMessages.PREFERENCES);
    toolBarManager.add(openVPEPreferencesAction);

    /*
     * Create VPE VISUAL REFRESH tool bar item
     */
    visualRefreshAction = new Action(VpeUIMessages.REFRESH, IAction.AS_PUSH_BUTTON) {
        @Override
        public void run() {
            if (controller != null) {
                controller.visualRefresh();
            }
        }
    };
    visualRefreshAction.setImageDescriptor(ImageDescriptor.createFromFile(MozillaEditor.class, ICON_REFRESH));
    visualRefreshAction.setToolTipText(VpeUIMessages.REFRESH);
    toolBarManager.add(visualRefreshAction);

    /*
     * Create SHOW RESOURCE DIALOG tool bar item
     * 
     * https://jira.jboss.org/jira/browse/JBIDE-3966
     * Disabling Page Design Options for external files. 
     */
    IEditorInput input = getEditorInput();
    IFile file = null;
    if (input instanceof IFileEditorInput) {
        file = ((IFileEditorInput) input).getFile();
    } else if (input instanceof ILocationProvider) {
        ILocationProvider provider = (ILocationProvider) input;
        IPath path = provider.getPath(input);
        if (path != null) {
            file = FileUtil.getFile(input, path.lastSegment());
        }
    }
    boolean fileExistsInWorkspace = ((file != null) && (file.exists()));
    showResouceDialogAction = new Action(VpeUIMessages.PAGE_DESIGN_OPTIONS, IAction.AS_PUSH_BUTTON) {
        @Override
        public void run() {
            VpeResourcesDialogFactory.openVpeResourcesDialog(getEditorInput());
        }
    };
    showResouceDialogAction.setImageDescriptor(ImageDescriptor.createFromFile(MozillaEditor.class,
            fileExistsInWorkspace ? ICON_PAGE_DESIGN_OPTIONS : ICON_PAGE_DESIGN_OPTIONS_DISABLED));
    if (!fileExistsInWorkspace) {
        showResouceDialogAction.setEnabled(false);
    }
    showResouceDialogAction.setToolTipText(VpeUIMessages.PAGE_DESIGN_OPTIONS);
    toolBarManager.add(showResouceDialogAction);

    /*
     * Create ROTATE EDITORS tool bar item
     * 
     * https://jira.jboss.org/jira/browse/JBIDE-4152
     * Compute initial icon state and add it to the tool bar.
     */
    String newOrientation = JspEditorPlugin.getDefault().getPreferenceStore()
            .getString(IVpePreferencesPage.VISUAL_SOURCE_EDITORS_SPLITTING);
    currentOrientationIndex = layoutValues.indexOf(newOrientation);
    rotateEditorsAction = new Action(VpeUIMessages.VISUAL_SOURCE_EDITORS_SPLITTING, IAction.AS_PUSH_BUTTON) {
        @Override
        public void run() {
            /*
             * Rotate editors orientation clockwise.
             */
            currentOrientationIndex++;
            if (currentOrientationIndex >= layoutValues.size()) {
                currentOrientationIndex = currentOrientationIndex % layoutValues.size();
            }
            String newOrientation = layoutValues.get(currentOrientationIndex);
            /*
             * Update icon and tooltip
             */
            this.setImageDescriptor(
                    ImageDescriptor.createFromFile(MozillaEditor.class, layoutIcons.get(newOrientation)));

            this.setToolTipText(layoutNames.get(newOrientation));
            /*
             * Call <code>filContainer()</code> from VpeEditorPart
             * to redraw CustomSashForm with new layout.
             */
            getController().getPageContext().getEditPart().fillContainer(true, newOrientation);
            JspEditorPlugin.getDefault().getPreferenceStore()
                    .setValue(IVpePreferencesPage.VISUAL_SOURCE_EDITORS_SPLITTING, newOrientation);
        }
    };
    rotateEditorsAction.setImageDescriptor(
            ImageDescriptor.createFromFile(MozillaEditor.class, layoutIcons.get(newOrientation)));
    rotateEditorsAction.setToolTipText(layoutNames.get(newOrientation));
    toolBarManager.add(rotateEditorsAction);

    /*
     * Create SHOW BORDER FOR UNKNOWN TAGS tool bar item
     */
    showBorderAction = new Action(VpeUIMessages.SHOW_BORDER_FOR_UNKNOWN_TAGS, IAction.AS_CHECK_BOX) {
        @Override
        public void run() {
            /*
             * Set new value to VpeVisualDomBuilder.
             */
            getController().getVisualBuilder().setShowBorderForUnknownTags(this.isChecked());
            /*
            * Update VPE
            */
            controller.visualRefresh();
            JspEditorPlugin.getDefault().getPreferenceStore()
                    .setValue(IVpePreferencesPage.SHOW_BORDER_FOR_UNKNOWN_TAGS, this.isChecked());
        }
    };
    showBorderAction.setImageDescriptor(
            ImageDescriptor.createFromFile(MozillaEditor.class, ICON_SHOW_BORDER_FOR_UNKNOWN_TAGS));
    showBorderAction.setToolTipText(VpeUIMessages.SHOW_BORDER_FOR_UNKNOWN_TAGS);
    toolBarManager.add(showBorderAction);

    /*
     * Create SHOW INVISIBLE TAGS tool bar item
     */
    showNonVisualTagsAction = new Action(VpeUIMessages.SHOW_NON_VISUAL_TAGS, IAction.AS_CHECK_BOX) {
        @Override
        public void run() {

            /*
             * Change flag
             */
            controller.getVisualBuilder().setShowInvisibleTags(this.isChecked());
            /*
             * Update VPE
             */
            controller.visualRefresh();
            JspEditorPlugin.getDefault().getPreferenceStore().setValue(IVpePreferencesPage.SHOW_NON_VISUAL_TAGS,
                    this.isChecked());
        }
    };
    showNonVisualTagsAction
            .setImageDescriptor(ImageDescriptor.createFromFile(MozillaEditor.class, ICON_NON_VISUAL_TAGS));
    showNonVisualTagsAction.setToolTipText(VpeUIMessages.SHOW_NON_VISUAL_TAGS);
    toolBarManager.add(showNonVisualTagsAction);

    /*
     * Create SHOW TEXT FORMATTING tool bar item
     */
    showTextFormattingAction = new Action(VpeUIMessages.SHOW_TEXT_FORMATTING, IAction.AS_CHECK_BOX) {
        @Override
        public void run() {
            /*
             * Update Text Formatting Bar 
             */
            vpeToolBarManager.setToolbarVisibility(this.isChecked());
            JspEditorPlugin.getDefault().getPreferenceStore().setValue(IVpePreferencesPage.SHOW_TEXT_FORMATTING,
                    this.isChecked());
        }
    };
    showTextFormattingAction
            .setImageDescriptor(ImageDescriptor.createFromFile(MozillaEditor.class, ICON_TEXT_FORMATTING));
    showTextFormattingAction.setToolTipText(VpeUIMessages.SHOW_TEXT_FORMATTING);
    toolBarManager.add(showTextFormattingAction);

    /*
     * Create SHOW BUNDLE'S MESSAGES AS EL tool bar item
     */
    showBundleAsELAction = new Action(VpeUIMessages.SHOW_BUNDLES_AS_EL, IAction.AS_CHECK_BOX) {
        @Override
        public void run() {
            /*
             * Update bundle messages. 
             */
            controller.getPageContext().getBundle().updateShowBundleUsageAsEL(this.isChecked());
            controller.visualRefresh();
            JspEditorPlugin.getDefault().getPreferenceStore()
                    .setValue(IVpePreferencesPage.SHOW_RESOURCE_BUNDLES_USAGE_AS_EL, this.isChecked());
        }
    };
    showBundleAsELAction
            .setImageDescriptor(ImageDescriptor.createFromFile(MozillaEditor.class, ICON_BUNDLE_AS_EL));
    showBundleAsELAction.setToolTipText(VpeUIMessages.SHOW_BUNDLES_AS_EL);
    toolBarManager.add(showBundleAsELAction);

    /*
     * https://issues.jboss.org/browse/JBIDE-11302
     * Create SYNCHRONIZE_SCROLLING_BETWEEN_SOURCE_VISUAL_PANES tool bar item
     */
    scrollLockAction = new Action(VpeUIMessages.SYNCHRONIZE_SCROLLING_BETWEEN_SOURCE_VISUAL_PANES,
            IAction.AS_CHECK_BOX) {
        @Override
        public void run() {
            /*
             * Change the enabled state, listeners in VpeController will do the rest
             */
            JspEditorPlugin.getDefault().getPreferenceStore().setValue(
                    IVpePreferencesPage.SYNCHRONIZE_SCROLLING_BETWEEN_SOURCE_VISUAL_PANES, this.isChecked());
        }
    };
    scrollLockAction.setImageDescriptor(ImageDescriptor.createFromFile(MozillaEditor.class, ICON_SCROLL_LOCK));
    scrollLockAction.setToolTipText(VpeUIMessages.SYNCHRONIZE_SCROLLING_BETWEEN_SOURCE_VISUAL_PANES);
    toolBarManager.add(scrollLockAction);

    /*
     * Create EXTERNALIZE STRINGS tool bar item
     */
    externalizeStringsAction = new Action(JstUIMessages.EXTERNALIZE_STRINGS, IAction.AS_PUSH_BUTTON) {

        @Override
        public void run() {
            /*
             * Externalize strings action.
             * Show a dialog to add properties key and value.
             * When selection is correct show the dialog
             * otherwise the toolbar icon will be disabled.
             */
            ExternalizeStringsDialog dlg = new ExternalizeStringsDialog(
                    PlatformUI.getWorkbench().getDisplay().getActiveShell(), new ExternalizeStringsWizard(
                            controller.getSourceEditor(), controller.getPageContext().getBundle()));
            dlg.open();
        }
    };
    externalizeStringsAction
            .setImageDescriptor(ImageDescriptor.createFromFile(MozillaEditor.class, ICON_EXTERNALIZE_STRINGS));
    externalizeStringsAction.setToolTipText(JstUIMessages.EXTERNALIZE_STRINGS_POPUP_MENU_TITLE);
    toolBarManager.add(externalizeStringsAction);

    /*
     * Create SHOW SELECTION BAR tool bar item
     */
    showSelectionBarAction = new Action(VpeUIMessages.SHOW_SELECTION_BAR, IAction.AS_CHECK_BOX) {
        @Override
        public void run() {
            /*
             * Update Selection Bar 
             */
            controller.getPageContext().getEditPart().updateSelectionBar(this.isChecked());
            JspEditorPlugin.getDefault().getPreferenceStore()
                    .setValue(IVpePreferencesPage.SHOW_SELECTION_TAG_BAR, this.isChecked());
        }
    };
    JspEditorPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            /*
             * Change icon state after sel bar was closed
             */
            if (IVpePreferencesPage.SHOW_SELECTION_TAG_BAR.equalsIgnoreCase(event.getProperty())) {
                boolean newValue = (Boolean) event.getNewValue();
                if (showSelectionBarAction.isChecked() != newValue) {
                    showSelectionBarAction.setChecked(newValue);
                }
            }
        }
    });
    showSelectionBarAction
            .setImageDescriptor(ImageDescriptor.createFromFile(MozillaEditor.class, ICON_SELECTION_BAR));
    showSelectionBarAction.setToolTipText(VpeUIMessages.SHOW_SELECTION_BAR);
    toolBarManager.add(showSelectionBarAction);

    updateToolbarItemsAccordingToPreferences();
    toolBarManager.update(true);

    parent.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            toolBarManager.dispose();
            toolBarManager.removeAll();
            openVPEPreferencesAction = null;
            visualRefreshAction = null;
            showResouceDialogAction = null;
            rotateEditorsAction = null;
            ;
            showBorderAction = null;
            showSelectionBarAction = null;
            showNonVisualTagsAction = null;
            showTextFormattingAction = null;
            showBundleAsELAction = null;
            externalizeStringsAction = null;
        }
    });
    return verBar;
}

From source file:org.kalypso.contribs.eclipse.swt.widgets.SectionUtils.java

License:Open Source License

/**
 * Creates a Toolbar on a section (i.e. sets it as the text client).
 *//*  w  w  w .ja  v a2s.  c o m*/
public static ToolBarManager createSectionToolbar(final Section section) {
    final ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT | SWT.FLAT | SWT.HORIZONTAL);

    final ToolBar toolbar = toolBarManager.createControl(section);

    final Cursor handCursor = section.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
    toolbar.setCursor(handCursor);
    toolbar.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(final DisposeEvent e) {
            toolBarManager.dispose();
        }
    });

    section.setTextClient(toolbar);

    return toolBarManager;
}

From source file:org.kalypso.kalypso1d2d.pjt.map.HydrographManagementWidget.java

License:Open Source License

@Override
public Control createControl(final Composite parent, final FormToolkit toolkit) {
    final ToolBarManager toolbarManager = new ToolBarManager(SWT.VERTICAL);
    initalizeHydrographActions(toolbarManager);

    parent.addDisposeListener(new DisposeListener() {
        @Override/*from   w w w  .j  ava2 s .co  m*/
        public void widgetDisposed(final DisposeEvent e) {
            toolbarManager.dispose();
        }
    });

    final ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
    sc.setMinWidth(200);
    sc.setExpandVertical(true);
    sc.setExpandHorizontal(true);

    final Composite panel = toolkit.createComposite(sc, SWT.NONE);
    panel.setLayout(new GridLayout());

    sc.setContent(panel);

    // Basic Layout

    /* Theme selection combo + add / remove calc unit hydrograph theme buttons */
    final Composite themeSelectionPanel = toolkit.createComposite(panel, SWT.NONE);
    final GridLayout themeGridLayout = new GridLayout(5, false);
    themeGridLayout.marginWidth = 0;
    themeSelectionPanel.setLayout(themeGridLayout);
    final GridData themeGridLayoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    themeSelectionPanel.setLayoutData(themeGridLayoutData);
    toolkit.createLabel(themeSelectionPanel,
            Messages.getString("org.kalypso.kalypso1d2d.pjt.map.HydrographManagementWidget.5"), SWT.NONE); //$NON-NLS-1$
    m_themeCombo = new ComboViewer(themeSelectionPanel, SWT.READ_ONLY | SWT.DROP_DOWN);
    final GridData comboGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    m_themeCombo.getControl().setLayoutData(comboGridData);

    // buttons
    createAddCalcUnitButtonControl(themeSelectionPanel, toolkit);
    createRemoveCalcUnitButtonControl(themeSelectionPanel, toolkit);
    createProcessHydrographButtonControl(themeSelectionPanel, toolkit);

    /* Hydrograph table + info pane */
    final Composite hydrographPanel = toolkit.createComposite(panel, SWT.NONE);
    final GridLayout hydrographPanelLayout = new GridLayout(2, false);
    final GridData hydrographPanelData = new GridData(SWT.FILL, SWT.FILL, true, false);
    hydrographPanelData.heightHint = 140;
    hydrographPanel.setLayoutData(hydrographPanelData);
    hydrographPanelLayout.marginHeight = 0;
    hydrographPanelLayout.marginWidth = 0;
    hydrographPanel.setLayout(hydrographPanelLayout);

    m_hydrographViewer = new ListViewer(hydrographPanel, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    final GridData hydrographViewerData = new GridData(SWT.FILL, SWT.FILL, true, false);
    hydrographViewerData.heightHint = 100;
    m_hydrographViewer.getControl().setLayoutData(hydrographViewerData);
    toolkit.adapt(m_hydrographViewer.getControl(), true, false);

    final ToolBar hydrographToolbar = toolbarManager.createControl(hydrographPanel);
    toolkit.adapt(hydrographToolbar);
    hydrographToolbar.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, true));

    /* Info view */
    final Group hydrographInfoGroup = new Group(panel, SWT.H_SCROLL);
    hydrographInfoGroup.setLayout(new GridLayout());
    final GridData infoGroupData = new GridData(SWT.FILL, SWT.FILL, true, true);
    hydrographInfoGroup.setLayoutData(infoGroupData);
    toolkit.adapt(hydrographInfoGroup);
    hydrographInfoGroup
            .setText(Messages.getString("org.kalypso.kalypso1d2d.pjt.map.HydrographManagementWidget.6")); //$NON-NLS-1$

    final CachedFeatureviewFactory featureviewFactory = new CachedFeatureviewFactory(new FeatureviewHelper());
    featureviewFactory.addView(getClass().getResource(m_featureTemplateGft));
    final FeatureComposite featureComposite = new FeatureComposite(null, null, featureviewFactory);
    featureComposite.setFormToolkit(toolkit);

    featureComposite.addChangeListener(new IFeatureChangeListener() {
        @Override
        @SuppressWarnings("synthetic-access")
        public void featureChanged(final ICommand changeCommand) {
            m_theme.postCommand(changeCommand, null);
            updateHydrographProperties();
        }

        @Override
        public void openFeatureRequested(final Feature feature, final IPropertyType pt) {
        }
    });

    // Fill contents
    initalizeHydrographViewer(m_hydrographViewer);

    /* Hook Events */
    m_hydrographViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            try {
                handleListSelectionChanged(parent, hydrographInfoGroup, featureComposite, event);
            } catch (final Exception e) {
                e.printStackTrace();
            }
        }
    });

    m_themeCombo.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            handleThemeComboSelected(event);
        }
    });

    initializeThemeCombo();

    if (m_hydrographs != null) {
        final IFeatureBindingCollection<IHydrograph> hydrographs = m_hydrographs.getHydrographs();
        if (hydrographs != null && hydrographs.size() > 0)
            m_hydrographViewer.setSelection(new StructuredSelection(hydrographs.get(0)));
    }

    final Point size = panel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    panel.setSize(size);
    sc.setMinHeight(size.y);

    return panel;

}

From source file:org.kalypso.model.flood.ui.map.EventManagementWidget.java

License:Open Source License

@Override
public Control createControl(final Composite parent, final FormToolkit toolkit) {
    final ToolBarManager treeManager = new ToolBarManager(SWT.VERTICAL);
    initalizeTreeActions(treeManager);/*from   w  w w. jav  a 2  s  . c om*/

    final ToolBarManager colormapManager = new ToolBarManager(SWT.VERTICAL);
    initalizeColorMapActions(colormapManager);

    // TRICKY: Scrolling behavior:
    // - vertical: all components have a minimum height and fill the whole area
    // - vertical: if size is too small, a global scroll-bar appears
    // - horizontal: the panel has a minimum width, if the total area is too small, a global scrollbar appears
    // - horizontal: the components (tree/table) have their additional horizontal scrollbars which appars if the content
    // of the individual control is too big

    // FIXME: probably we should use scrolled form instead
    final ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
    sc.setMinWidth(200);
    sc.setExpandVertical(true);
    sc.setExpandHorizontal(true);

    final Composite panel = toolkit.createComposite(sc, SWT.NONE);
    panel.setLayout(new GridLayout());

    sc.setContent(panel);
    parent.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(final ControlEvent e) {
            final Point size = panel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            panel.setSize(size);
            sc.setMinHeight(size.y);
        }
    });

    // Basic Layout

    /* Tree table + info pane */
    final Composite treePanel = toolkit.createComposite(panel, SWT.NONE);
    final GridData treePanelData = new GridData(SWT.FILL, SWT.FILL, true, false);
    treePanelData.heightHint = 200;
    treePanel.setLayoutData(treePanelData);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(treePanel);

    m_eventViewer = new TreeViewer(treePanel, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    final GridData eventViewerData = new GridData(SWT.FILL, SWT.FILL, true, false);
    eventViewerData.heightHint = 100;
    m_eventViewer.getControl().setLayoutData(eventViewerData);
    toolkit.adapt(m_eventViewer.getControl(), true, false);

    final ToolBar treeToolbar = treeManager.createControl(treePanel);
    toolkit.adapt(treeToolbar);
    treeToolbar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));

    treeToolbar.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(final DisposeEvent e) {
            treeManager.dispose();
        }
    });

    /* Info view */
    final Pair<Group, FeatureComposite> infoGroupComponents = createInfoGroup(toolkit, panel);

    /* Color Map table */
    final Composite colormapPanel = toolkit.createComposite(panel, SWT.NONE);
    final GridLayout colormapPanelLayout = new GridLayout();
    colormapPanelLayout.numColumns = 2;
    colormapPanelLayout.makeColumnsEqualWidth = false;
    colormapPanelLayout.marginWidth = 0;
    colormapPanelLayout.marginHeight = 0;

    colormapPanel.setLayout(colormapPanelLayout);
    final GridData colormapPanelData = new GridData(SWT.FILL, SWT.FILL, true, true);
    colormapPanel.setLayoutData(colormapPanelData);

    m_colorMapTableViewer = new TableViewer(colormapPanel, SWT.BORDER | SWT.H_SCROLL);
    final GridData colormapTableData = new GridData(SWT.FILL, SWT.FILL, true, true);

    m_colorMapTableViewer.getControl().setLayoutData(colormapTableData);
    toolkit.adapt(m_colorMapTableViewer.getControl(), true, true);

    final ToolBar colormapToolBar = colormapManager.createControl(colormapPanel);
    toolkit.adapt(colormapToolBar);
    colormapToolBar.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, false));

    colormapToolBar.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(final DisposeEvent e) {
            colormapManager.dispose();
        }
    });

    /* Fill contents */
    initalizeEventViewer(m_eventViewer);
    initializeColorMapTableViewer(m_colorMapTableViewer);

    /* Hook Events */
    m_eventViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            handleEventSelectionChanged(sc, infoGroupComponents, (IStructuredSelection) event.getSelection());
        }
    });

    handleEventSelectionChanged(sc, infoGroupComponents, (IStructuredSelection) m_eventViewer.getSelection());

    final Point size = panel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    panel.setSize(size);
    sc.setMinHeight(size.y);

    return panel;
}

From source file:org.xmind.ui.color.PaletteViewer.java

License:Open Source License

protected void handleDispose(DisposeEvent e) {
    if (autoToolBar != null)
        autoToolBar.dispose();//w  ww .  j a  v  a2s.  c om
    if (noneToolBar != null)
        noneToolBar.dispose();
    if (customToolBar != null)
        customToolBar.dispose();
    if (paletteToolBarManagers != null) {
        for (ToolBarManager toolBarManager : paletteToolBarManagers) {
            toolBarManager.dispose();
        }
        paletteToolBarManagers.clear();
        paletteToolBarManagers = null;
    }
    //        if (paletteToolBar != null)
    //            paletteToolBar.dispose();
    if (sep1 != null) {
        sep1.dispose();
        sep1 = null;
    }
    if (sep2 != null) {
        sep2.dispose();
        sep2 = null;
    }
    if (sep3 != null) {
        sep3.dispose();
        sep3 = null;
    }
}

From source file:org.xmind.ui.color.PaletteViewer.java

License:Open Source License

private void update(Composite parent, Object input, Object oldInput) {
    boolean showAutoItem = getShowAutoItem();
    boolean showNoneItem = getShowNoneItem();
    boolean showCustomItem = getShowCustomItem();

    PaletteItem[] oldItems = oldInput == null ? null : ((PaletteContents) oldInput).toArray();
    PaletteItem[] newItems = input == null ? null : ((PaletteContents) input).toArray();
    boolean paletteChanged = !equals(oldItems, newItems);
    boolean showPaletteItems = newItems != null && newItems.length > 0;

    int selType = selection == null ? -1 : selection.getType();
    RGB selColor = selection == null ? null : selection.getColor();

    Control last = null;/* www . ja v  a 2  s .com*/

    if (showAutoItem) {
        last = showItemBar(autoToolBar, parent, last);
        if (showPaletteItems || showNoneItem || showCustomItem) {
            if (sep1 == null || sep1.isDisposed()) {
                sep1 = createSeparator(parent);
            }
            last = moveControl(sep1, last);
        }
    }

    if (paletteActions != null) {
        paletteActions.clear();
        paletteActions = null;
    }

    if (paletteToolBarManagers != null) {
        if (!paletteToolBarManagers.isEmpty())
            for (ToolBarManager toolBarManager : paletteToolBarManagers) {
                toolBarManager.removeAll();
                toolBarManager.dispose();
            }
        paletteToolBarManagers.clear();
        paletteToolBarManagers = null;
    }

    if (showPaletteItems) {
        if (isShowStandardLabel()) {
            int cols = ((PaletteContents) input).getPreferredColumns();
            List<PaletteItem> items = Arrays.asList(newItems);
            List<PaletteItem> genItems = items.subList(0, items.size() - cols);
            last = showPalette(input, genItems.toArray(new PaletteItem[genItems.size()]), paletteChanged,
                    parent, last);

            if (sep2 == null || sep2.isDisposed()) {
                sep2 = createSeparator(parent);
            }
            last = moveControl(sep2, last);

            if (standard == null || standard.isDisposed()) {
                standard = new Label(parent, SWT.NONE);
                standard.setText(PaletteMessages.PaletteItem_Standard_label);
                GridData labelLayout = new GridData(GridData.FILL_HORIZONTAL);
                labelLayout.horizontalIndent = 7;
                labelLayout.verticalIndent = 5;
                standard.setLayoutData(labelLayout);
            }
            last = moveControl(standard, last);

            List<PaletteItem> staItems = items.subList(items.size() - cols, items.size());
            last = showPalette(input, staItems.toArray(new PaletteItem[staItems.size()]), paletteChanged,
                    parent, last);
        } else {
            List<PaletteItem> items = Arrays.asList(newItems);
            last = showPalette(input, items.toArray(new PaletteItem[items.size()]), paletteChanged, parent,
                    last);
        }
    }

    if (showCustomItem) {
        if (showAutoItem || showPaletteItems || showNoneItem) {
            if (sep3 == null || sep3.isDisposed()) {
                sep3 = createSeparator(parent);
            }
            last = moveControl(sep3, last);
        }
        if (showNoneItem) {
            Composite moreAndNone = new Composite(parent, SWT.NONE);
            GridLayout layout = new GridLayout();
            layout.numColumns = 2;
            layout.marginLeft = 0;
            layout.horizontalSpacing = 2;
            moreAndNone.setLayout(layout);

            last = showItemBar(noneToolBar, moreAndNone, last);
            last = showItemBar(customToolBar, moreAndNone, last);
        } else {
            last = showItemBar(customToolBar, parent, last);
        }
    }

    selection = findActionToSelect(selType, selColor);

    parent.layout();
}