Class PaletteCustomizerDialog

  • All Implemented Interfaces:
    EntryPageContainer, IShellProvider

    public class PaletteCustomizerDialog
    extends Dialog
    implements EntryPageContainer
    This class implements a default dialog that allows customization of the different entries/items on a GEF palette, i.e. the model behind the palette.

    The construction of the dialog is broken down into different methods in order to allow clients to further customize the appearance of the dialog, if so desired.

    This dialog can be re-used, i.e., it can be re-opened once closed. There is no need to create a new PaletteCustomizerDialog everytime a palette needs to be customized.

    See Also:
    PaletteEntry, PaletteCustomizer
    • Constructor Detail

      • PaletteCustomizerDialog

        public PaletteCustomizerDialog​(Shell shell,
                                       PaletteCustomizer customizer,
                                       PaletteRoot root)
        Constructs a new customizer dialog.
        Parameters:
        shell - the parent Shell
        customizer - the customizer
        root - the palette root
    • Method Detail

      • close

        public boolean close()

        NOTE: This dialog can be re-opened.

        Overrides:
        close in class Dialog
        See Also:
        Window.close()
      • createButton

        protected Button createButton​(Composite parent,
                                      int id,
                                      java.lang.String label,
                                      int stylebits,
                                      ImageDescriptor descriptor)
        This method should not be used to create buttons for the button bar. Use Dialog.createButton(Composite, int, String, boolean) for that. This method can be used to create any other button in the dialog. The parent Composite must have a GridLayout. These buttons will be available through getButton(int) and getWidget(int). Ensure that the various buttons created by this method are given unique IDs. Pass in a null image descriptor if you don't want the button to have an icon. This method will take care of disposing the images that it creates. buttonPressed(int) will be called when any of the buttons created by this method are clicked (selected).
        Parameters:
        parent - The composite in which the button is to be created
        id - The button's unique ID
        label - The button's text
        stylebits - The style bits for creating the button (eg., SWT.PUSH or SWT.CHECK)
        descriptor - The ImageDescriptor from which the image/icon for this button should be created
        Returns:
        The newly created button for convenience
      • createOutlineActions

        protected java.util.List createOutlineActions()
        Creates the actions that manipulate the palette model. These actions will populate the toolbar and the outline's context menu.

        IMPORTANT: All the elements in the returned List MUST be PaletteCustomizationActions.

        Returns:
        A List of PaletteCustomizationActions
      • createOutlineContextMenu

        protected Menu createOutlineContextMenu()
        Uses a MenuManager to create the context menu for the outline. The IActions used to create the context menu are those created in createOutlineActions().
        Returns:
        The newly created Menu
      • createOutlineToolBar

        protected Control createOutlineToolBar​(Composite parent)
        Uses a ToolBarManager to create the ToolBar in the outline part of the dialog. The Actions used in the ToolBarManager are those that are created in createOutlineActions().
        Parameters:
        parent - The Composite to which the ToolBar is to be added
        Returns:
        The newly created ToolBar
      • createOutlineTreeViewer

        protected TreeViewer createOutlineTreeViewer​(Composite composite)
        Creates the TreeViewer that is the outline of the model.
        Parameters:
        composite - The Composite to which the ToolBar is to be added
        Returns:
        The newly created TreeViewer
      • createPropertiesPanel

        protected Control createPropertiesPanel​(Composite container)
        Creates the part of the dialog where the properties of the element selected in the outline will be displayed.

        The properties panel contains the following:

        The rest of the panel is constructed in this method.

        Parameters:
        container - The Composite to which this part is to be added
        Returns:
        The properties panel
      • createPropertiesPanelTitle

        protected PageBook createPropertiesPanelTitle​(Composite parent)
        Creates the title for the properties panel. It is a PageBook that can switch between showing the regular title (the selected entry's label and icon) and an error message if an error has occured.
        Parameters:
        parent - The parent composite
        Returns:
        The newly created PageBook title
      • createSectionTitle

        protected CLabel createSectionTitle​(Composite composite,
                                            java.lang.String text)
        A convenient method to create CLabel titles (like the ones used in the Preferences dialog in the Eclipse workbench) throughout the dialog.
        Parameters:
        composite - The composite in which the title is to be created (it must have a GridLayout with two columns).
        text - The title to be displayed
        Returns:
        The newly created CLabel for convenience
      • getCustomizer

        protected PaletteCustomizer getCustomizer()
        Returns:
        The customizer that is responsible for handling the various tasks and updating the model.
      • getEntryPage

        protected EntryPage getEntryPage​(PaletteEntry entry)
        Returns the EntryPage for the given PaletteEntry. The EntryPage is retrieved from the customizer. If the given entry is null, null will be returned. If the customizer returns null for the valid entry, a default page will be created and returned.
        Parameters:
        entry - The PaletteEntry whose properties need to be displayed
        Returns:
        The EntryPage with the properties of the given PaletteEntry
      • getOutlineActions

        protected final java.util.List getOutlineActions()
        Provides access to the actions that are used to manipulate the model. The actions will be created, if they haven't been yet.
        Returns:
        the list of PaletteCustomizationActions
        See Also:
        createOutlineActions()
      • getPaletteRoot

        protected PaletteRoot getPaletteRoot()
        Provides sub-classes with access to the PaletteRoot
        Returns:
        the palette root
      • getSelectedPaletteEntry

        protected PaletteEntry getSelectedPaletteEntry()
        Returns:
        The PaletteEntry that is currently selected in the Outline Tree; null if none is selected
      • getSelectedTreeItem

        protected TreeItem getSelectedTreeItem()
        Returns:
        The TreeItem that is currently selected in the Outline Tree; null if none is selected
      • getWidget

        protected Widget getWidget​(int id)
        The Widgets that were created with a unique ID and added to this class' internal map can be retrieved through this method.
        Parameters:
        id - The unique ID of the Widget that you wish to retrieve
        Returns:
        The Widget, if one with the given id exists; null otherwise
      • handleApplyPressed

        protected final void handleApplyPressed()
        This method is invoked when the Apply button is pressed

        IMPORTANT: It is recommended that you not override this method. Closing the dialog with the 'X' at the top right of the window, or by hitting 'Esc' or any other way, corresponds to a "Cancel." That will, however, not result in this method being invoked. To handle such cases, saving or rejecting the changes is handled in close(). Override save() and revertToSaved() to add to what needs to be done when saving or cancelling.

      • handleDelete

        protected void handleDelete()
        This method is called when the "Delete" action is run (either through the context menu or the toolbar). It deletes the selected palette entry.
      • handleMoveDown

        protected void handleMoveDown()
        This method is called when the "Move Down" action is run (either through the context menu or the toolbar). It moves the selected palette entry down.
      • handleMoveUp

        protected void handleMoveUp()
        This method is called when the "Move Up" action is run (either through the context menu or the toolbar). It moves the selected entry up.
      • handleOutlineSelectionChanged

        protected void handleOutlineSelectionChanged()
        This is the method that is called everytime the selection in the outline (treeviewer) changes.
      • revertToSaved

        protected void revertToSaved()
        This method is invoked when the changes made since the last save need to be cancelled.
      • save

        protected void save()
        This method is invoked when the changes made since the last save need to be saved.
      • setActiveEntry

        protected void setActiveEntry​(PaletteEntry entry)
        This methods sets the active entry. Based on the selection, this method will appropriately enable or disable the ToolBar items, will change the CLabel heading of the propreties panel, and will show the properties of the selected item in the properties panel.
        Parameters:
        entry - The new active entry, i.e., the new selected entry (it can be null)
      • setActiveEntryPage

        protected void setActiveEntryPage​(EntryPage page)
        Sets the given EntryPage as the top page in the PageBook that shows the properties of the item selected in the Outline. If the given EntryPage is null, nothing will be shown.
        Parameters:
        page - The EntryPage to be shown
      • setDefaultSelection

        public void setDefaultSelection​(PaletteEntry entry)
        Sets the given PaletteEntry as the one to be selected when the dialog opens. It is discarded when the dialog is closed.
        Parameters:
        entry - The PaletteEntry that should be selected when the dialog is opened
      • showProblem

        public void showProblem​(java.lang.String error)
        This method should be invoked by EntryPages when there is an error. It will show the given error in the title of the properties panel. OK and Apply buttons will be disabled. Selecting some other entry in the outline tree will not be allowed until the error is fixed.
        Specified by:
        showProblem in interface EntryPageContainer
        Parameters:
        error - A description of the problem. Should be as brief as possible.
        See Also:
        EntryPageContainer.showProblem(String)
      • updateActions

        protected void updateActions()
        Updates the actions created in createOutlineActions(), enabling or disabling them as necessary.