Eclipse GEF
2.1

org.eclipse.gef.ui.palette.customize
Class PaletteEntryFactory

java.lang.Object
  |
  +--org.eclipse.gef.ui.palette.customize.PaletteEntryFactory
Direct Known Subclasses:
PaletteContainerFactory, PaletteSeparatorFactory

public abstract class PaletteEntryFactory
extends Object

A PaletteEntryFactory creates certain type of PaletteEntries.

This class only creates PaletteEntries in PaletteContainers and not directly in the root. It is recommended that sub-classes not do that either.

To keep palette customization consistent across different types of editors, it is recommended that a new entry be created after the currently selected entry. If the new entry needs to be created inside the currently selected entry (i.e., if the currently selected entry is a PaletteContainer), it should be added as the last child. Look at determineContainerForNewEntry(PaletteEntry) and determineIndexForNewEntry(PaletteContainer, PaletteEntry) in this class and PaletteContainerFactory to see what the general guidelines are for creating containers and leaf entries.

See Also:
PaletteCustomizer, PaletteCustomizerDialog

Constructor Summary
PaletteEntryFactory()
           
 
Method Summary
 boolean canCreate(PaletteEntry selected)
          This method is called by the PaletteCustomizerDialog to determine whether to enable or disable this action on the toolbar and the context menu.
protected abstract  PaletteEntry createNewEntry(Shell shell)
          Create the PaletteEntry
 PaletteEntry createNewEntry(Shell shell, PaletteEntry selected)
          This method is called when a new palette entry of the type supported by this PaletteEntryFactory is to be created.
protected  PaletteContainer determineContainerForNewEntry(PaletteEntry selected)
          Given the current selection, this method determines the parent for the new entry to be created.
protected  int determineIndexForNewEntry(PaletteContainer c, PaletteEntry selected)
          Calculates the index at which the new entry is to be created, given the current selection.
 ImageDescriptor getImageDescriptor()
           
 String getLabel()
           
 void setImageDescriptor(ImageDescriptor imgDesc)
          Sets the ImageDescriptor used to create the image to represent this factory
 void setLabel(String newLabel)
          Sets this factory's name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PaletteEntryFactory

public PaletteEntryFactory()
Method Detail

createNewEntry

public final PaletteEntry createNewEntry(Shell shell,
                                         PaletteEntry selected)
This method is called when a new palette entry of the type supported by this PaletteEntryFactory is to be created.

Parameters:
shell - The Shell of the PaletteCustomizerDialog
selected - The PaletteEntry that was selected in the outline when this action was launched. Will never be null.
Returns:
PaletteEntry The newly created PaletteEntry

createNewEntry

protected abstract PaletteEntry createNewEntry(Shell shell)
Create the PaletteEntry

Parameters:
shell - The Shell of the PaletteCustomizerDialog; it can be used to create another warning or information dialog.
Returns:
The newly created entry

canCreate

public boolean canCreate(PaletteEntry selected)
This method is called by the PaletteCustomizerDialog to determine whether to enable or disable this action on the toolbar and the context menu.

This default implementation allows the creation of a new entry only in PaletteContainers with the following user permission: PERMISSION_FULL_MODIFICATION

Parameters:
selected - The selected PaletteEntry (Will never be null)
Returns:
true if, given the current selection, this PaletteEntryFactory can create a new PaletteEntry

determineContainerForNewEntry

protected PaletteContainer determineContainerForNewEntry(PaletteEntry selected)
Given the current selection, this method determines the parent for the new entry to be created.

Sub-classes may override this method.

Parameters:
selected - The selected entry
Returns:
The parent of the new entry to be created

determineIndexForNewEntry

protected int determineIndexForNewEntry(PaletteContainer c,
                                        PaletteEntry selected)
Calculates the index at which the new entry is to be created, given the current selection.

Sub-classes may override this method.

Parameters:
c - The parent container
selected - The selected entry
Returns:
the index at which the new entry should be added in the given container (-1 indicates add at the end)

getImageDescriptor

public ImageDescriptor getImageDescriptor()
Returns:
ImageDescriptor used to create the image to represent this factory

getLabel

public String getLabel()
Returns:
This factory's name

setImageDescriptor

public void setImageDescriptor(ImageDescriptor imgDesc)
Sets the ImageDescriptor used to create the image to represent this factory

Parameters:
imgDesc - The new ImageDescriptor

setLabel

public void setLabel(String newLabel)
Sets this factory's name. It will be used to list this factory in the toolbar, context menu, etc.

Parameters:
newLabel - The new name for this factory

Eclipse GEF
2.1

Copyright (c) IBM Corp. and others 2000, 2003. All Rights Reserved.