Package org.eclipse.gef.ui.parts
Class GraphicalEditor
- java.lang.Object
-
- org.eclipse.core.commands.common.EventManager
-
- org.eclipse.ui.part.WorkbenchPart
-
- org.eclipse.ui.part.EditorPart
-
- org.eclipse.gef.ui.parts.GraphicalEditor
-
- All Implemented Interfaces:
java.util.EventListener
,IAdaptable
,IExecutableExtension
,CommandStackListener
,IEditorPart
,ISaveablePart
,ISelectionListener
,IWorkbenchPart
,IWorkbenchPart2
,IWorkbenchPart3
,IWorkbenchPartOrientation
- Direct Known Subclasses:
GraphicalEditorWithFlyoutPalette
,GraphicalEditorWithPalette
public abstract class GraphicalEditor extends EditorPart implements CommandStackListener, ISelectionListener
This class serves as a quick starting point for clients who are new to GEF. It will create an Editor containing a single GraphicalViewer as its control.IMPORTANTThis class should only be used as a reference for creating your own EditorPart implementation. This class will not suit everyone's needs, and may change in the future. Clients may copy the implementation.
-
-
Field Summary
-
Fields inherited from interface org.eclipse.ui.IEditorPart
PROP_DIRTY, PROP_INPUT
-
Fields inherited from interface org.eclipse.ui.IWorkbenchPart
PROP_TITLE
-
-
Constructor Summary
Constructors Constructor Description GraphicalEditor()
Constructs the editor part
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
commandStackChanged(java.util.EventObject event)
When the command stack changes, the actions interested in the command stack are updated.protected void
configureGraphicalViewer()
Called to configure the graphical viewer before it receives its contents.protected void
createActions()
Creates actions for this editor.protected void
createGraphicalViewer(Composite parent)
Creates the GraphicalViewer on the specifiedComposite
.void
createPartControl(Composite parent)
Realizes the Editor by creating it's Control.void
dispose()
void
doSaveAs()
Does nothing be default.protected void
firePropertyChange(int property)
protected ActionRegistry
getActionRegistry()
Lazily creates and returns the action registry.java.lang.Object
getAdapter(java.lang.Class type)
Returns the adapter for the specified key.protected CommandStack
getCommandStack()
Returns the command stack.protected DefaultEditDomain
getEditDomain()
Returns the edit domain.protected GraphicalViewer
getGraphicalViewer()
Returns the graphical viewer.protected java.util.List
getPropertyActions()
Returns the list ofIActions
dependant on property changes in the Editor.protected java.util.List
getSelectionActions()
Returns the list of IDs of Actions that are dependant on changes in the workbench'sISelectionService
.protected SelectionSynchronizer
getSelectionSynchronizer()
Returns the selection syncronizer object.protected java.util.List
getStackActions()
Returns the list of IDs of Actions that are dependant on the CommmandStack's state.protected void
hookGraphicalViewer()
Hooks the GraphicalViewer to the rest of the Editor.void
init(IEditorSite site, IEditorInput input)
Sets the site and input for this editor then creates and initializes the actions.protected void
initializeActionRegistry()
Initializes the ActionRegistry.protected abstract void
initializeGraphicalViewer()
Override to set the contents of the GraphicalViewer after it has been created.boolean
isDirty()
Returnstrue
if the command stack is dirtyboolean
isSaveAsAllowed()
Returnsfalse
by default.void
selectionChanged(IWorkbenchPart part, ISelection selection)
protected void
setActionRegistry(ActionRegistry registry)
Sets the ActionRegistry for this EditorPart.protected void
setEditDomain(DefaultEditDomain ed)
Sets the EditDomain for this EditorPart.void
setFocus()
protected void
setGraphicalViewer(GraphicalViewer viewer)
Sets the graphicalViewer for this EditorPart.protected void
updateActions(java.util.List actionIds)
A convenience method for updating a set of actions defined by the given List of action IDs.-
Methods inherited from class org.eclipse.ui.part.EditorPart
checkSite, doSave, getEditorInput, getEditorSite, getTitleToolTip, isSaveOnCloseNeeded, setContentDescription, setInitializationData, setInput, setInputWithNotify, setPartName
-
Methods inherited from class org.eclipse.ui.part.WorkbenchPart
addPartPropertyListener, addPropertyListener, firePartPropertyChanged, getConfigurationElement, getContentDescription, getDefaultImage, getOrientation, getPartName, getPartProperties, getPartProperty, getSite, getTitle, getTitleImage, removePartPropertyListener, removePropertyListener, setPartProperty, setSite, setTitle, setTitleImage, setTitleToolTip, showBusy
-
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.ui.IWorkbenchPart
addPropertyListener, getSite, getTitle, getTitleImage, removePropertyListener
-
-
-
-
Method Detail
-
commandStackChanged
public void commandStackChanged(java.util.EventObject event)
When the command stack changes, the actions interested in the command stack are updated.- Specified by:
commandStackChanged
in interfaceCommandStackListener
- Parameters:
event
- the change event
-
configureGraphicalViewer
protected void configureGraphicalViewer()
Called to configure the graphical viewer before it receives its contents. This is where the root editpart should be configured. Subclasses should extend or override this method as needed.
-
createActions
protected void createActions()
Creates actions for this editor. Subclasses should override this method to create and register actions with theActionRegistry
.
-
createGraphicalViewer
protected void createGraphicalViewer(Composite parent)
Creates the GraphicalViewer on the specifiedComposite
.- Parameters:
parent
- the parent composite
-
createPartControl
public void createPartControl(Composite parent)
Realizes the Editor by creating it's Control.WARNING: This method may or may not be called by the workbench prior to
dispose()
.- Specified by:
createPartControl
in interfaceIWorkbenchPart
- Specified by:
createPartControl
in classWorkbenchPart
- Parameters:
parent
- the parent composite
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceIWorkbenchPart
- Overrides:
dispose
in classWorkbenchPart
- See Also:
IWorkbenchPart.dispose()
-
doSaveAs
public void doSaveAs()
Does nothing be default. This method should be overridden ifisSaveAsAllowed()
has been overridden to returntrue
.- Specified by:
doSaveAs
in interfaceISaveablePart
- Specified by:
doSaveAs
in classEditorPart
- See Also:
ISaveablePart.doSaveAs()
-
firePropertyChange
protected void firePropertyChange(int property)
- Overrides:
firePropertyChange
in classWorkbenchPart
- See Also:
WorkbenchPart.firePropertyChange(int)
-
getActionRegistry
protected ActionRegistry getActionRegistry()
Lazily creates and returns the action registry.- Returns:
- the action registry
-
getAdapter
public java.lang.Object getAdapter(java.lang.Class type)
Returns the adapter for the specified key.IMPORTANT certain requests, such as the property sheet, may be made before or after
createPartControl(Composite)
is called. The order is unspecified by the Workbench.- Specified by:
getAdapter
in interfaceIAdaptable
- Overrides:
getAdapter
in classWorkbenchPart
- See Also:
IAdaptable.getAdapter(java.lang.Class)
-
getCommandStack
protected CommandStack getCommandStack()
Returns the command stack.- Returns:
- the command stack
-
getEditDomain
protected DefaultEditDomain getEditDomain()
Returns the edit domain.- Returns:
- the edit domain
-
getGraphicalViewer
protected GraphicalViewer getGraphicalViewer()
Returns the graphical viewer.- Returns:
- the graphical viewer
-
getPropertyActions
protected java.util.List getPropertyActions()
Returns the list ofIActions
dependant on property changes in the Editor. These actions should implement theUpdateAction
interface so that they can be updated in response to property changes. An example is the "Save" action.- Returns:
- the list of property-dependant actions
-
getSelectionActions
protected java.util.List getSelectionActions()
Returns the list of IDs of Actions that are dependant on changes in the workbench'sISelectionService
. The associated Actions can be found in the action registry. Such actions should implement theUpdateAction
interface so that they can be updated in response to selection changes.- Returns:
- the list of selection-dependant action IDs
- See Also:
updateActions(List)
-
getSelectionSynchronizer
protected SelectionSynchronizer getSelectionSynchronizer()
Returns the selection syncronizer object. The synchronizer can be used to sync the selection of 2 or more EditPartViewers.- Returns:
- the syncrhonizer
-
getStackActions
protected java.util.List getStackActions()
Returns the list of IDs of Actions that are dependant on the CommmandStack's state. The associated Actions can be found in the action registry. These actions should implement theUpdateAction
interface so that they can be updated in response to command stack changes. An example is the "undo" action.- Returns:
- the list of stack-dependant action IDs
-
hookGraphicalViewer
protected void hookGraphicalViewer()
Hooks the GraphicalViewer to the rest of the Editor. By default, the viewer is added to the SelectionSynchronizer, which can be used to keep 2 or more EditPartViewers in sync. The viewer is also registered as the ISelectionProvider for the Editor's PartSite.
-
init
public void init(IEditorSite site, IEditorInput input) throws PartInitException
Sets the site and input for this editor then creates and initializes the actions. Subclasses may extend this method, but should always callsuper.init(site, input)
.- Specified by:
init
in interfaceIEditorPart
- Specified by:
init
in classEditorPart
- Throws:
PartInitException
- See Also:
IEditorPart.init(IEditorSite, IEditorInput)
-
initializeActionRegistry
protected void initializeActionRegistry()
Initializes the ActionRegistry. This registry may be used byActionBarContributors
and/orContextMenuProviders
.This method may be called on Editor creation, or lazily the first time
getActionRegistry()
is called.
-
initializeGraphicalViewer
protected abstract void initializeGraphicalViewer()
Override to set the contents of the GraphicalViewer after it has been created.- See Also:
createGraphicalViewer(Composite)
-
isDirty
public boolean isDirty()
Returnstrue
if the command stack is dirty- Specified by:
isDirty
in interfaceISaveablePart
- Specified by:
isDirty
in classEditorPart
- See Also:
ISaveablePart.isDirty()
-
isSaveAsAllowed
public boolean isSaveAsAllowed()
- Specified by:
isSaveAsAllowed
in interfaceISaveablePart
- Specified by:
isSaveAsAllowed
in classEditorPart
- See Also:
ISaveablePart.isSaveAsAllowed()
-
selectionChanged
public void selectionChanged(IWorkbenchPart part, ISelection selection)
- Specified by:
selectionChanged
in interfaceISelectionListener
- See Also:
ISelectionListener.selectionChanged(IWorkbenchPart, ISelection)
-
setActionRegistry
protected void setActionRegistry(ActionRegistry registry)
Sets the ActionRegistry for this EditorPart.- Parameters:
registry
- the registry
-
setEditDomain
protected void setEditDomain(DefaultEditDomain ed)
Sets the EditDomain for this EditorPart.- Parameters:
ed
- the domain
-
setFocus
public void setFocus()
- Specified by:
setFocus
in interfaceIWorkbenchPart
- Specified by:
setFocus
in classWorkbenchPart
- See Also:
IWorkbenchPart.setFocus()
-
setGraphicalViewer
protected void setGraphicalViewer(GraphicalViewer viewer)
Sets the graphicalViewer for this EditorPart.- Parameters:
viewer
- the graphical viewer
-
updateActions
protected void updateActions(java.util.List actionIds)
A convenience method for updating a set of actions defined by the given List of action IDs. The actions are found by looking up the ID in theaction registry
. If the corresponding action is anUpdateAction
, it will have itsupdate()
method called.- Parameters:
actionIds
- the list of IDs to update
-
-