Class PaletteCustomizerDialog
- java.lang.Object
-
- org.eclipse.jface.window.Window
-
- org.eclipse.jface.dialogs.Dialog
-
- org.eclipse.gef.ui.palette.customize.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
PaletteCustomizerDialogeverytime a palette needs to be customized.- See Also:
PaletteEntry,PaletteCustomizer
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jface.window.Window
Window.IExceptionHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected static intAPPLY_IDThe unique ID for the Apply Button.protected static intCLIENT_IDSub-classes that need to create their own unique IDs should do so by adding to this ID.-
Fields inherited from class org.eclipse.jface.dialogs.Dialog
blockedHandler, buttonBar, DIALOG_DEFAULT_BOUNDS, DIALOG_PERSISTLOCATION, DIALOG_PERSISTSIZE, dialogArea, DLG_IMG_ERROR, DLG_IMG_HELP, DLG_IMG_INFO, DLG_IMG_MESSAGE_ERROR, DLG_IMG_MESSAGE_INFO, DLG_IMG_MESSAGE_WARNING, DLG_IMG_QUESTION, DLG_IMG_WARNING, ELLIPSIS
-
Fields inherited from class org.eclipse.jface.window.Window
CANCEL, OK, resizeHasOccurred
-
-
Constructor Summary
Constructors Constructor Description PaletteCustomizerDialog(Shell shell, PaletteCustomizer customizer, PaletteRoot root)Constructs a new customizer dialog.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbuttonPressed(int buttonId)This method will be invoked whenever anyButtoncreated usingcreateButton(Composite, int, String, int, ImageDescriptor)orDialog.createButton(Composite, int, String, boolean)is selected.voidclearProblem()This method should be invoked by EntryPages when an error that they had earlier reported (usingshowProblem(String)) is fixed.booleanclose()NOTE: This dialog can be re-opened.protected voidconfigureShell(Shell newShell)protected ButtoncreateButton(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.protected voidcreateButtonsForButtonBar(Composite parent)Creates the OK, Cancel and Apply buttonsprotected ControlcreateDialogArea(Composite parent)The dialog area contains the following: Outline (createOutline(Composite)) Properties Panel (createPropertiesPanel(Composite))protected ControlcreateOutline(Composite container)Creates the outline part of the dialog.protected java.util.ListcreateOutlineActions()Creates the actions that manipulate the palette model.protected MenucreateOutlineContextMenu()Uses aMenuManagerto create the context menu for the outline.protected ControlcreateOutlineToolBar(Composite parent)Uses a ToolBarManager to create the ToolBar in the outline part of the dialog.protected TreeViewercreateOutlineTreeViewer(Composite composite)Creates the TreeViewer that is the outline of the model.protected ControlcreatePropertiesPanel(Composite container)Creates the part of the dialog where the properties of the element selected in the outline will be displayed.protected PageBookcreatePropertiesPanelTitle(Composite parent)Creates the title for the properties panel.protected CLabelcreateSectionTitle(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.protected ButtongetButton(int id)Returns the Button with the given id; ornullif none was found.protected PaletteCustomizergetCustomizer()protected EntryPagegetEntryPage(PaletteEntry entry)Returns theEntryPagefor the givenPaletteEntry.protected java.util.ListgetOutlineActions()Provides access to the actions that are used to manipulate the model.protected PaletteRootgetPaletteRoot()Provides sub-classes with access to the PaletteRootprotected PaletteEntrygetSelectedPaletteEntry()protected TreeItemgetSelectedTreeItem()protected WidgetgetWidget(int id)TheWidgets that were created with a unique ID and added to this class' internal map can be retrieved through this method.protected voidhandleApplyPressed()This method is invoked when the Apply button is pressedprotected voidhandleDelete()This method is called when the "Delete" action is run (either through the context menu or the toolbar).protected voidhandleMoveDown()This method is called when the "Move Down" action is run (either through the context menu or the toolbar).protected voidhandleMoveUp()This method is called when the "Move Up" action is run (either through the context menu or the toolbar).protected voidhandleOutlineSelectionChanged()This is the method that is called everytime the selection in the outline (treeviewer) changes.protected voidrevertToSaved()This method is invoked when the changes made since the last save need to be cancelled.protected voidsave()This method is invoked when the changes made since the last save need to be saved.protected voidsetActiveEntry(PaletteEntry entry)This methods sets the active entry.protected voidsetActiveEntryPage(EntryPage page)Sets the given EntryPage as the top page in the PageBook that shows the properties of the item selected in the Outline.voidsetDefaultSelection(PaletteEntry entry)Sets the given PaletteEntry as the one to be selected when the dialog opens.voidshowProblem(java.lang.String error)This method should be invoked by EntryPages when there is an error.protected voidupdateActions()Updates the actions created increateOutlineActions(), enabling or disabling them as necessary.-
Methods inherited from class org.eclipse.jface.dialogs.Dialog
applyDialogFont, cancelPressed, convertHeightInCharsToPixels, convertHeightInCharsToPixels, convertHorizontalDLUsToPixels, convertHorizontalDLUsToPixels, convertVerticalDLUsToPixels, convertVerticalDLUsToPixels, convertWidthInCharsToPixels, convertWidthInCharsToPixels, create, createButton, createButtonBar, createContents, dialogFontIsDefault, getBlockedHandler, getButtonBar, getCancelButton, getDialogArea, getDialogBoundsSettings, getDialogBoundsStrategy, getImage, getInitialLocation, getInitialSize, getOKButton, initializeBounds, initializeDialogUnits, isResizable, okPressed, setBlockedHandler, setButtonLayoutData, setButtonLayoutFormData, shortenText
-
Methods inherited from class org.eclipse.jface.window.Window
canHandleShellCloseEvent, constrainShellSize, createShell, getConstrainedShellBounds, getContents, getDefaultImage, getDefaultImages, getDefaultOrientation, getLayout, getParentShell, getReturnCode, getShell, getShellListener, getShellStyle, getWindowManager, handleFontChange, handleShellCloseEvent, open, setBlockOnOpen, setDefaultImage, setDefaultImages, setDefaultModalParent, setDefaultOrientation, setExceptionHandler, setParentShell, setReturnCode, setShellStyle, setWindowManager
-
-
-
-
Field Detail
-
APPLY_ID
protected static final int APPLY_ID
The unique ID for the Apply Button. It can be used to retrieve that widget from the internal map (usinggetWidget(int)orgetButton(int)), or to identify that widget inbuttonPressed(int).- See Also:
- Constant Field Values
-
CLIENT_ID
protected static final int CLIENT_ID
Sub-classes that need to create their own unique IDs should do so by adding to this ID.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PaletteCustomizerDialog
public PaletteCustomizerDialog(Shell shell, PaletteCustomizer customizer, PaletteRoot root)
Constructs a new customizer dialog.- Parameters:
shell- the parent Shellcustomizer- the customizerroot- the palette root
-
-
Method Detail
-
buttonPressed
protected void buttonPressed(int buttonId)
This method will be invoked whenever anyButtoncreated usingcreateButton(Composite, int, String, int, ImageDescriptor)orDialog.createButton(Composite, int, String, boolean)is selected.- Overrides:
buttonPressedin classDialog- See Also:
Dialog.buttonPressed(int)
-
clearProblem
public void clearProblem()
This method should be invoked by EntryPages when an error that they had earlier reported (usingshowProblem(String)) is fixed. This will hide the error message, enable the OK and Apply buttons and re-allow changing selection in the outline tree.- Specified by:
clearProblemin interfaceEntryPageContainer- See Also:
EntryPageContainer.clearProblem(),showProblem(String)
-
close
public boolean close()
NOTE: This dialog can be re-opened.
- Overrides:
closein classDialog- See Also:
Window.close()
-
configureShell
protected void configureShell(Shell newShell)
- Overrides:
configureShellin classWindow- See Also:
Window.configureShell(Shell)
-
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. UseDialog.createButton(Composite, int, String, boolean)for that. This method can be used to create any other button in the dialog. The parentCompositemust have a GridLayout. These buttons will be available throughgetButton(int)andgetWidget(int). Ensure that the various buttons created by this method are given unique IDs. Pass in anullimage 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 createdid- The button's unique IDlabel- The button's textstylebits- The style bits for creating the button (eg.,SWT.PUSHorSWT.CHECK)descriptor- The ImageDescriptor from which the image/icon for this button should be created- Returns:
- The newly created button for convenience
-
createButtonsForButtonBar
protected void createButtonsForButtonBar(Composite parent)
Creates the OK, Cancel and Apply buttons- Overrides:
createButtonsForButtonBarin classDialog- See Also:
Dialog.createButtonsForButtonBar(Composite)
-
createDialogArea
protected Control createDialogArea(Composite parent)
The dialog area contains the following:- Outline (
createOutline(Composite)) - Properties Panel (
createPropertiesPanel(Composite))
It is recommended that this method not be overridden. Override one of the methods that this method calls in order to customize the appearance of the dialog.
- Overrides:
createDialogAreain classDialog- See Also:
Dialog.createDialogArea(Composite)
- Outline (
-
createOutline
protected Control createOutline(Composite container)
Creates the outline part of the dialog.The outline creates the following:
- ToolBar (
createOutlineToolBar(Composite)) - TreeViewer (
createOutlineTreeViewer(Composite)) - Context menu (
createOutlineContextMenu())
- Parameters:
container- The Composite within which the outline has to be created- Returns:
- The newly created Control that has the outline
- ToolBar (
-
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 aMenuManagerto create the context menu for the outline. TheIActionsused to create the context menu are those created increateOutlineActions().- 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 increateOutlineActions().- 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
-
getButton
protected Button getButton(int id)
Returns the Button with the given id; ornullif none was found.- Overrides:
getButtonin classDialog- See Also:
Dialog.getButton(int)
-
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 theEntryPagefor the givenPaletteEntry. TheEntryPageis retrieved from the customizer. If the given entry isnull,nullwill be returned. If the customizer returnsnullfor 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;
nullif none is selected
-
getSelectedTreeItem
protected TreeItem getSelectedTreeItem()
- Returns:
- The TreeItem that is currently selected in the Outline Tree;
nullif none is selected
-
getWidget
protected Widget getWidget(int id)
TheWidgets 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;
nullotherwise
-
handleApplyPressed
protected final void handleApplyPressed()
This method is invoked when the Apply button is pressedIMPORTANT: 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(). Overridesave()andrevertToSaved()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 benull)
-
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:
showProblemin interfaceEntryPageContainer- 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 increateOutlineActions(), enabling or disabling them as necessary.
-
-