|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.core.commands.common.EventManager
org.eclipse.ui.part.WorkbenchPart
org.eclipse.ui.part.EditorPart
roneditor.AbstractTreeEditor
public abstract class AbstractTreeEditor
This is a basic abstract implementation of an EditorPart
with a
AbstractTreeEditor.EditorTreeViewer
. It is designed to be used in an Eclipse plugin as it
demands a AbstractUIPlugin
to be able to access some of its
Bundle
information.
Prerequisites:
IPerspectiveFactory
that describes the perspective for this editor.
When instantiated (and in createPartControl(Composite)
) this class
does the following:
DefaultEditDomain
and sets itself as the
EditorPart
.
AbstractTreeEditor.EditorTreeViewer
is created.
SelectionSynchronizer
on the AbstractTreeEditor.EditorTreeViewer
.
AbstractTreeEditor.EditorTreeViewer
is set as ISelectionProvider
for this
IEditorSite
.
KeyHandler
for the AbstractTreeEditor.EditorTreeViewer
.
Additionally it provides the following features:
logError(String, Exception)
.
SaveAction
,
UndoAction
, RedoAction
,
SelectAllAction
, PrintAction
,
DirectEditAction
, DeleteAction
CommandStack
of the EditDomain
is watched. When
changed the actions of getStackActions()
are updated. UndoAction
and RedoAction
are updated then.
AbstractTreeEditor.EditorTreeViewer
is watched for selection changes. When occuring
the actions of getSelectionActions()
are updated. DirectEditAction
and DeleteAction
are updated
then.
firePropertyChange(int)
occurs the actions of
getPropertyActions()
are updated. SaveAction
, as it is intended to react
on firing of IEditorPart.PROP_DIRTY
.
CommandStack
is changed the editor checks its own dirty
state and fires IEditorPart.PROP_DIRTY
if it changes.
createIDForModel(EObject)
the passed model will be
registered with an unique ID that is used with AbstractPageBookView
s
to tell them with their secondary ID which model to show. These views make
use of getModelForID(String)
to resolve the ID to the model. EditPart
s via a
call
activePage.showView(viewID, editor.createIDForModel(model), IWorkbenchPage.VIEW_ACTIVATE);
where
null
).
These methods have to be implemented by subclasses:
getActivator()
: The AbstractUIPlugin
activator for
this eclipse plugin.
createContextMenuProvider(TreeViewer)
: The
ContextMenuProvider
for the AbstractTreeEditor.EditorTreeViewer
.
getModelRoot()
: The top model element to be set as contents of
the AbstractTreeEditor.EditorTreeViewer
.
createTreeEditPartFactory()
: A suitable
EditPartFactory
for the model elements.
save(IFile, IProgressMonitor)
: A method that handles saving
the model to a IFile
.
Nested Class Summary | |
---|---|
class |
AbstractTreeEditor.EditorTreeViewer
This special TreeViewer is needed to allow the EditPart s to
access the editor e.g. to generate IDs for models. |
Field Summary | |
---|---|
private org.eclipse.gef.ui.actions.ActionRegistry |
actionRegistry
The ActionRegistry containing the actions created by this editor. |
private org.eclipse.gef.DefaultEditDomain |
editDomain
The EditDomain of this editor. |
private java.util.Map<java.lang.String,org.eclipse.emf.ecore.EObject> |
id2ModelMap
A map to resolve unique ids to ecore models. |
private org.eclipse.gef.KeyHandler |
keyHandler
The key handler of this editor. |
private java.util.Map<org.eclipse.emf.ecore.EObject,java.lang.String> |
model2IdMap
A map reversing id2ModelMap to get possible previously generated ids for models rather that create new ones. |
private java.util.Map<org.eclipse.emf.ecore.EObject,org.eclipse.emf.common.notify.Adapter> |
model2ListenerMap
A map only used to be able to remove deletion listeners from the models when the editor is being closed. |
private boolean |
previousDirtyState
A helper flag to decide if the save action should be enabled. |
private java.util.List<org.eclipse.jface.action.IAction> |
propertyActions
The actions of this editor depending on property change notifications. |
private java.util.List<org.eclipse.jface.action.IAction> |
selectionActions
The actions of this editor depending on the actual selection. |
private java.util.List<org.eclipse.jface.action.IAction> |
stackActions
The actions of this editor depending on the actual command stack. |
private org.eclipse.gef.ui.parts.SelectionSynchronizer |
synchronizer
The SelectionSynchronizer managing the selections for this editor
and the views it can open. |
private org.eclipse.gef.ui.parts.TreeViewer |
treeViewer
The AbstractTreeEditor.EditorTreeViewer in this editor. |
Fields inherited from interface org.eclipse.ui.IEditorPart |
---|
PROP_DIRTY, PROP_INPUT |
Fields inherited from interface org.eclipse.ui.IWorkbenchPart |
---|
PROP_TITLE |
Constructor Summary | |
---|---|
protected |
AbstractTreeEditor()
The standard constructor creates a DefaultEditDomain and
registers itself as a CommandStackListener on the domains
CommandStack . |
Method Summary | |
---|---|
(package private) java.lang.String |
closeViewsShowing(org.eclipse.emf.ecore.EObject model)
Closes alls views in the site's page whose secondary ID correspond to the id the passed model has been registered with. |
void |
commandStackChanged(java.util.EventObject event)
When the command stack changes, the actions interested in the command stack are updated. |
protected void |
createActions()
Creates some standard GEF actions for this editor. |
protected abstract org.eclipse.gef.ContextMenuProvider |
createContextMenuProvider(org.eclipse.gef.ui.parts.TreeViewer viewer)
|
java.lang.String |
createIDForModel(org.eclipse.emf.ecore.EObject model)
Generates an unique ID for this model and registers them with each other in two maps. |
private java.lang.String |
createIDForModel(org.eclipse.emf.ecore.EObject model,
java.lang.String forceID)
Generates an unique ID for this model and registers them with each other in two maps. |
void |
createPartControl(org.eclipse.swt.widgets.Composite parent)
Realizes the editor by creating its Control . |
protected abstract org.eclipse.gef.EditPartFactory |
createTreeEditPartFactory()
|
protected void |
createTreeViewer(org.eclipse.swt.widgets.Composite parent)
Creates the GraphicalViewer on the specified Composite . |
void |
dispose()
|
void |
doSave(org.eclipse.core.runtime.IProgressMonitor monitor)
|
void |
doSaveAs()
|
protected void |
firePropertyChange(int property)
|
protected org.eclipse.gef.ui.actions.ActionRegistry |
getActionRegistry()
Lazily creates, initializes and returns the action registry. |
protected abstract org.eclipse.ui.plugin.AbstractUIPlugin |
getActivator()
To be implemented by concrete subclasses! |
java.lang.Object |
getAdapter(java.lang.Class type)
IMPORTANT certain requests, such as the property sheet, may be made before or after createPartControl(Composite) is called. |
protected org.eclipse.gef.commands.CommandStack |
getCommandStack()
|
protected org.eclipse.gef.DefaultEditDomain |
getEditDomain()
|
protected java.util.Vector<java.lang.String> |
getExtensionAttributeValues(java.lang.String exPointID,
java.lang.String attribID)
|
protected org.eclipse.gef.KeyHandler |
getKeyHandler()
|
org.eclipse.emf.ecore.EObject |
getModelForID(java.lang.String id)
Method to resolve an ID to a ECore model element. |
protected abstract org.eclipse.emf.ecore.EObject |
getModelRoot()
|
protected java.util.List<org.eclipse.jface.action.IAction> |
getPropertyActions()
Returns the list of IActions dependent on property
changes in the Editor. |
protected java.util.List<org.eclipse.jface.action.IAction> |
getSelectionActions()
Returns the list of IAction that depend on changes in the
workbench's ISelectionService . |
protected org.eclipse.gef.ui.parts.SelectionSynchronizer |
getSelectionSynchronizer()
Returns the selection synchronizer object. |
protected java.util.List<org.eclipse.jface.action.IAction> |
getStackActions()
Returns the list of IAction s dependent on the CommmandStack's
state. |
protected org.eclipse.gef.ui.parts.TreeViewer |
getTreeViewer()
|
protected java.lang.String |
getUniqueExtensionAttributeValue(java.lang.String exPointID,
java.lang.String attribID)
|
void |
init(org.eclipse.ui.IEditorSite site,
org.eclipse.ui.IEditorInput input)
Sets the site and input for this editor and opens a unique perspective defined in plugin.xml. |
protected void |
initializeActionRegistry()
Initializes the action registry. |
protected boolean |
isAnotherEditorActive()
A helper method that looks for other active instances of this editor in the site's page. |
boolean |
isDirty()
Returns true if the command stack is dirty |
boolean |
isSaveAsAllowed()
|
void |
logError(java.lang.String message,
java.lang.Exception e)
|
private void |
restoreModelRegistry()
Restores the model-id-mappings from the plugin's preferences if the editor is still working on the same file. |
protected abstract void |
save(org.eclipse.core.resources.IFile file,
org.eclipse.core.runtime.IProgressMonitor progressMonitor)
This method saves the model to a file using some facility like EMF Resource s. |
void |
selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event)
|
void |
setFocus()
|
void |
showView(java.lang.String viewId,
org.eclipse.emf.ecore.EObject model)
Opens a view on this side's page displaying a model. |
private void |
storeAndCleanModelRegistry()
Unregisters each registered model and closes the views that show them. |
protected void |
updateActions(java.util.List<org.eclipse.jface.action.IAction> actions)
A convenience method for updating a set of actions defined by the given List of actions. |
Methods inherited from class org.eclipse.ui.part.EditorPart |
---|
checkSite, getEditorInput, getEditorSite, getTitleToolTip, isSaveOnCloseNeeded, setContentDescription, setInitializationData, setInput, setInputWithNotify, setPartName |
Methods inherited from class org.eclipse.ui.part.WorkbenchPart |
---|
addPropertyListener, getConfigurationElement, getContentDescription, getDefaultImage, getOrientation, getPartName, getSite, getTitle, getTitleImage, removePropertyListener, 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 |
Field Detail |
---|
private final org.eclipse.gef.DefaultEditDomain editDomain
EditDomain
of this editor.
private org.eclipse.gef.ui.parts.TreeViewer treeViewer
AbstractTreeEditor.EditorTreeViewer
in this editor.
private org.eclipse.gef.ui.actions.ActionRegistry actionRegistry
ActionRegistry
containing the actions created by this editor.
private org.eclipse.gef.ui.parts.SelectionSynchronizer synchronizer
SelectionSynchronizer
managing the selections for this editor
and the views it can open.
private final java.util.List<org.eclipse.jface.action.IAction> selectionActions
private final java.util.List<org.eclipse.jface.action.IAction> stackActions
private final java.util.List<org.eclipse.jface.action.IAction> propertyActions
private org.eclipse.gef.KeyHandler keyHandler
private boolean previousDirtyState
private final java.util.Map<java.lang.String,org.eclipse.emf.ecore.EObject> id2ModelMap
private final java.util.Map<org.eclipse.emf.ecore.EObject,java.lang.String> model2IdMap
private final java.util.Map<org.eclipse.emf.ecore.EObject,org.eclipse.emf.common.notify.Adapter> model2ListenerMap
Constructor Detail |
---|
protected AbstractTreeEditor()
DefaultEditDomain
and
registers itself as a CommandStackListener
on the domains
CommandStack
.
Method Detail |
---|
protected org.eclipse.gef.KeyHandler getKeyHandler()
KeyHandler
for this editor.public void commandStackChanged(java.util.EventObject event)
commandStackChanged
in interface org.eclipse.gef.commands.CommandStackListener
event
- the change eventprotected void createActions()
ActionRegistry
.
protected void createTreeViewer(org.eclipse.swt.widgets.Composite parent)
Composite
.
parent
- the parent compositepublic void createPartControl(org.eclipse.swt.widgets.Composite parent)
Control
.
WARNING: This method may or may not be called by the workbench prior to
dispose()
.
createPartControl
in interface org.eclipse.ui.IWorkbenchPart
createPartControl
in class org.eclipse.ui.part.WorkbenchPart
parent
- the parent compositepublic void dispose()
dispose
in interface org.eclipse.ui.IWorkbenchPart
dispose
in class org.eclipse.ui.part.WorkbenchPart
protected boolean isAnotherEditorActive()
true
if another instance of this editor is activeprotected void firePropertyChange(int property)
firePropertyChange
in class org.eclipse.ui.part.WorkbenchPart
protected org.eclipse.gef.ui.actions.ActionRegistry getActionRegistry()
public java.lang.Object getAdapter(java.lang.Class type)
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.
(non-Javadoc)
getAdapter
in interface org.eclipse.core.runtime.IAdaptable
getAdapter
in class org.eclipse.ui.part.WorkbenchPart
IAdaptable.getAdapter(java.lang.Class)
protected org.eclipse.gef.commands.CommandStack getCommandStack()
protected org.eclipse.gef.DefaultEditDomain getEditDomain()
protected org.eclipse.gef.ui.parts.TreeViewer getTreeViewer()
AbstractTreeEditor.EditorTreeViewer
that allows to access
the editor.protected java.util.List<org.eclipse.jface.action.IAction> getPropertyActions()
IActions
dependent on property
changes in the Editor. These actions should implement the
UpdateAction
interface so that they can be updated in response to
property changes. An example is the "Save" action.
protected java.util.List<org.eclipse.jface.action.IAction> getSelectionActions()
IAction
that depend on changes in the
workbench's ISelectionService
. These actions can be updated in
response to selection changes. An example is the Delete action.
protected org.eclipse.gef.ui.parts.SelectionSynchronizer getSelectionSynchronizer()
SelectionSynchronizer
protected java.util.List<org.eclipse.jface.action.IAction> getStackActions()
IAction
s dependent on the CommmandStack's
state. These actions should implement the UpdateAction
interface
so that they can be updated in response to command stack changes. An
example is the "undo" action.
public void init(org.eclipse.ui.IEditorSite site, org.eclipse.ui.IEditorInput input)
super.init(site, input)
.
init
in interface org.eclipse.ui.IEditorPart
init
in class org.eclipse.ui.part.EditorPart
IEditorPart.init(org.eclipse.ui.IEditorSite,
org.eclipse.ui.IEditorInput)
protected void initializeActionRegistry()
ActionBarContributors
and/or
ContextMenuProviders
.
This method is being called the first time getActionRegistry()
gets called.
protected abstract org.eclipse.ui.plugin.AbstractUIPlugin getActivator()
Bundle
and IExtension
s.protected java.lang.String getUniqueExtensionAttributeValue(java.lang.String exPointID, java.lang.String attribID)
exPointID
- The extension to be looked at.attribID
- The attribute whose value is requested.
org.eclipse.core.runtime.CoreException
- This is thrown if no (unique) value can be determined.protected java.util.Vector<java.lang.String> getExtensionAttributeValues(java.lang.String exPointID, java.lang.String attribID)
exPointID
- The extension to be looked at.attribID
- The attribute whose value is requested.
Vector
.
org.eclipse.core.runtime.CoreException
- This is thrown if no (unique) value can be determined.public void logError(java.lang.String message, java.lang.Exception e)
message
- The message for the IStatus
to be logged for the
plugin determined by getActivator()
.e
- An optional Exception to be reported.protected abstract org.eclipse.gef.ContextMenuProvider createContextMenuProvider(org.eclipse.gef.ui.parts.TreeViewer viewer)
viewer
- The AbstractTreeEditor.EditorTreeViewer
for that this
ContextMenuProvider
constructs a menu.protected abstract org.eclipse.emf.ecore.EObject getModelRoot()
protected abstract org.eclipse.gef.EditPartFactory createTreeEditPartFactory()
EditPartFactory
for this GEF AbstractTreeEditor.EditorTreeViewer
.public boolean isDirty()
true
if the command stack is dirty
isDirty
in interface org.eclipse.ui.ISaveablePart
isDirty
in class org.eclipse.ui.part.EditorPart
ISaveablePart.isDirty()
public void setFocus()
setFocus
in interface org.eclipse.ui.IWorkbenchPart
setFocus
in class org.eclipse.ui.part.WorkbenchPart
protected void updateActions(java.util.List<org.eclipse.jface.action.IAction> actions)
action
- The list of actions to update.public boolean isSaveAsAllowed()
isSaveAsAllowed
in interface org.eclipse.ui.ISaveablePart
isSaveAsAllowed
in class org.eclipse.ui.part.EditorPart
public void doSave(org.eclipse.core.runtime.IProgressMonitor monitor)
doSave
in interface org.eclipse.ui.ISaveablePart
doSave
in class org.eclipse.ui.part.EditorPart
public void doSaveAs()
doSaveAs
in interface org.eclipse.ui.ISaveablePart
doSaveAs
in class org.eclipse.ui.part.EditorPart
public void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event)
selectionChanged
in interface org.eclipse.jface.viewers.ISelectionChangedListener
protected abstract void save(org.eclipse.core.resources.IFile file, org.eclipse.core.runtime.IProgressMonitor progressMonitor) throws org.eclipse.core.runtime.CoreException
Resource
s.
file
- The IFile
to save the model to.progressMonitor
- A progress monitor that could be used to show the saving
status.
org.eclipse.core.runtime.CoreException
- This exception indicates that something went wrong during
saving.public void showView(java.lang.String viewId, org.eclipse.emf.ecore.EObject model)
getModelForID(String)
.
viewId
- The primary ID of the view to be opened. Should be
correspondent to an org.eclipse.ui.views entry in plugin.xmlmodel
- The model to be shown in the viewpublic org.eclipse.emf.ecore.EObject getModelForID(java.lang.String id)
id
- The id that identifies the wanted model
createIDForModel(EObject)
public java.lang.String createIDForModel(org.eclipse.emf.ecore.EObject model)
Adapter
is added to the model. The adapter will
close the views that have been opened with this ID as secondary ID
automatically when deletion of the model is being notified.
model
- The model to get an ID for
private java.lang.String createIDForModel(org.eclipse.emf.ecore.EObject model, java.lang.String forceID)
Adapter
is added to the model. The adapter will
close the views that have been opened with this ID as secondary ID
automatically when deletion of the model is being notified. *
model
- The model to get an ID forforceID
- May be used to force a particular ID for a model. If
null
, a new ID will be generated.
java.lang.String closeViewsShowing(org.eclipse.emf.ecore.EObject model)
model
- The model
null
private void storeAndCleanModelRegistry()
restoreModelRegistry()
private void restoreModelRegistry()
storeAndCleanModelRegistry()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |