|
||||||||||
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
de.tu_berlin.cs.tfs.muvitorkit.ui.MuvitorTreeEditor
public abstract class MuvitorTreeEditor
This is a rich-featured abstract implementation of an EditorPart
with
a GEF MuvitorTreeEditor.EditorTreeViewer
. Its purpose is to provide many generic features
available to GEF editors, or at least to make them easy to use by editor
programmers. Programmers only need to configure the editor by passing some
information by implementing the abstract methods.
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
.
MuvitorTreeEditor.EditorTreeViewer
is created.
MuvitorTreeEditor.EditorTreeViewer
's control is registered as resource user in
SWTResourceManager
so that we can use this to manage color, fonts,
and images. These will then be automatically disposed when the editor gets
closed.
SelectionSynchronizer
on the MuvitorTreeEditor.EditorTreeViewer
.
MuvitorTreeEditor.EditorTreeViewer
is set as ISelectionProvider
for this
IEditorSite
.
KeyHandler
for the MuvitorTreeEditor.EditorTreeViewer
.
Additionally it provides the following features:
MuvitorActivator.logError(String, Exception)
.
createActions()
for details.
CommandStack
of the EditDomain
is watched. When it
changes all actions will be updated. MuvitorTreeEditor.EditorTreeViewer
is watched for selection changes. When such a
change occurs all actions are updated. firePropertyChange(int)
occurs all actions 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.
IDUtil.getIDForModel(EObject)
the passed model will be
registered with an unique ID that is used with MuvitorPageBookView
s
to tell them with their secondary ID which model to show. These views make
use of IDUtil
to resolve the ID to the model. MuvitorPageBookView
s are opened from within
EditPart
s or actions via a call
showView(EObject)
. See
registerViewID(EClass, String)
.
MuvitorPageBookView
automatically when its
model has been deleted (i.e. model.eResource() == null
).
This class offers several static methods to open and close
MuvitorPageBookView
s: showView(EObject)
and
#closeViewsShowing(EObject)
for closing views showing a specific
model and closeViews(MuvitorTreeEditor)
for closing all views
showing a model whose root container is this editor's model root.
The following methods have to be implemented by subclasses. See their documentation for useful hints.
createDefaultModel()
: The default model that will be used if
loading from a file fails.
createCustomActions()
: Register your own actions here.
createContextMenuProvider(TreeViewer)
: The
ContextMenuProviderWithActionRegistry
for the MuvitorTreeEditor.EditorTreeViewer
. By
default, it conveniently populates the context menu with many standard
actions but is meant to be subclassed.
createTreeEditPartFactory()
: A suitable EditPartFactory
for the model elements.
setupKeyHandler(KeyHandler)
: Define additional key shortcuts for
actions here. May do nothing.
Nested Class Summary | |
---|---|
class |
MuvitorTreeEditor.EditorTreeViewer
This special TreeViewer is needed to allow the EditPart s to
access the editor. |
Field Summary | |
---|---|
static String |
fileExtension
The file extension this editor reacts on as specified in plugin.xml |
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 |
MuvitorTreeEditor()
The standard constructor creates a DefaultEditDomain and
registers itself as a CommandStackListener on the domains
CommandStack . |
Method Summary | |
---|---|
static ArrayList<EObject> |
closeViews(MuvitorTreeEditor editor)
Similar to closeViewShowing(EObject) this method closes all
views showing an EObject that belongs to the specified editor, according
to IDUtil.getHostEditor(EObject) . |
static void |
closeViewShowing(EObject model)
This is Muvitor's main method for closing a view in the workbench showing a specific EObject. |
void |
commandStackChanged(EventObject event)
When the command stack changes, the actions are updated. |
protected abstract ContextMenuProviderWithActionRegistry |
createContextMenuProvider(TreeViewer viewer)
Subclasses must implement to specify the ContextMenuProviderWithActionRegistry that should be used by this
editor's MuvitorTreeEditor.EditorTreeViewer and is responsible to show the created
actions in the context menu. |
protected abstract void |
createCustomActions()
To be implemented by subclasses. |
protected abstract EObject |
createDefaultModel()
Subclasses have to generate a default model in this method. |
protected List<EObject> |
createDefaultModels()
By default, MuvitorTreeEditor uses a single model root, which will be created in createDefaultModel() . |
IMarker |
createErrorMarker(EObject model,
String location,
String message)
Create an eclipse error marker for the currently edited file on given location with specified message. |
void |
createPartControl(Composite parent)
Realizes the editor by creating its Control . |
protected abstract EditPartFactory |
createTreeEditPartFactory()
Subclasses must implement this to specify the EditPartFactory
that should be used by this editor's MuvitorTreeEditor.EditorTreeViewer . |
void |
dispose()
Tries to close views for all models of the resource that have possibly been opened. |
void |
doSave(IProgressMonitor monitor)
|
void |
doSaveAs()
|
ArrayList<IMarker> |
findProblemMarkers(String attrName)
Convenience method that collects all problem markers like findProblemMarkers(String, Object) for which the attribute has
been set with any value. |
ArrayList<IMarker> |
findProblemMarkers(String attrName,
Object attrValue)
Helper method to find problem markers with specific attribute values. |
protected void |
firePropertyChange(int property)
|
protected ActionRegistry |
getActionRegistry()
Lazily creates, initializes and returns the action registry. |
Object |
getAdapter(Class type)
IMPORTANT certain requests, such as the property sheet, may be made before or after createPartControl(Composite) is called. |
protected CommandStack |
getCommandStack()
|
protected DefaultEditDomain |
getEditDomain()
|
protected KeyHandler |
getKeyHandler()
Need to create key handler lazily because accessing the action registry creates the actions which needs the editor site etc. |
List<EObject> |
getModelRoots()
Returns the list of EObject models that have been loaded by the
EMFModelManager . |
EObject |
getPrimaryModelRoot()
Returns by default the first model in the list of EObject models
that have been loaded by the EMFModelManager . |
IStatusLineManager |
getStatusLineManager()
This can be used to display messages in this page's status line. |
TreeViewer |
getTreeViewer()
|
void |
gotoMarker(IMarker marker)
This default implementation of IGotoMarker tries to resolve the
marker's IMarker.SOURCE_ID attribute to an EObject model. |
void |
init(IEditorSite site,
IEditorInput input)
Sets the site and input for this editor and opens the unique perspective defined in plugin.xml. |
boolean |
isDirty()
Returns true if the command stack is dirty |
boolean |
isSaveAsAllowed()
|
protected IAction |
registerAction(IAction action)
Registers the action with the editor's action registry. |
protected IAction |
registerActionOnToolBar(IAction action)
Registers the action with the editor's action registry and puts it on this editor's tool bar. |
static void |
registerViewID(EClass eClass,
String viewID)
Associate a class of models with the ID of a MuvitorPageBookView
that has been registered in plugin.xml. |
void |
restoreState(IMemento memento)
Restores the views that were opened when Eclipse was closed during an editor session if the editor is still able to work on the same file. |
void |
revertToLastSaved()
This method implements support for the Muvitor's RevertAction . |
protected void |
save(IFile file,
IProgressMonitor monitor)
This method saves the model to a file using the EMFModelManager . |
void |
saveState(IMemento memento)
Closes all views of this editor. |
void |
selectionChanged(IWorkbenchPart part,
ISelection selection)
|
void |
setFocus()
|
protected void |
setInput(IEditorInput input)
This method will create an EMFModelManager that handles loading
and saving to the file the passed IEditorInput relies on. |
protected abstract void |
setupKeyHandler(KeyHandler kh)
Subclasses must implement to associate KeyStroke s with Actions in
the passed KeyHandler which is the one used for the
MuvitorTreeEditor.EditorTreeViewer . |
static IViewPart |
showView(EObject model)
This is Muvitor's main method for opening a MuvitorPageBookView
in the workbench displaying a model. |
protected static IViewPart |
showView(String viewId,
EObject model)
This method does the actual work of opening a MuvitorPageBookView
. |
protected void |
updateActions()
Updates all UpdateAction s registered in the
actionRegistry . |
Methods inherited from class org.eclipse.ui.part.EditorPart |
---|
checkSite, getEditorInput, getEditorSite, getTitleToolTip, isSaveOnCloseNeeded, setContentDescription, setInitializationData, 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 |
Field Detail |
---|
public static final String fileExtension
Constructor Detail |
---|
protected MuvitorTreeEditor()
DefaultEditDomain
and
registers itself as a CommandStackListener
on the domains
CommandStack
.
PartInitException
Method Detail |
---|
protected final void setInput(IEditorInput input)
EMFModelManager
that handles loading
and saving to the file the passed IEditorInput
relies on. If
loading fails (possibly because we created a file with the creation
wizard) we create a new default model and put it to the file resource.
setInput
in class EditorPart
protected abstract EObject createDefaultModel()
createDefaultModels()
instead and leave this method
implementation empty.
setInput(IEditorInput)
protected List<EObject> createDefaultModels()
createDefaultModel()
. But it is capable to handle
multiple roots
public final void commandStackChanged(EventObject event)
commandStackChanged
in interface CommandStackListener
event
- the change eventprotected final IAction registerAction(IAction action)
There is no need to set handles that you register here (which will be
used if the TreeEditor is the active part) for the RetargetActions here
because this will be done by default in
ActionBarContributor.setActiveEditor(IEditorPart)
. This
will work as long as the handle action has the same ID as the
RetargetAction it is meant to handle.
Keep in mind that RetargetAction handles for MuvitorPage
s must
be set explicitly! See there for more information about registering
(shared) handles for RetargetActions.
action
- the action to be registered in this editor's
ActionRegistry
protected final IAction registerActionOnToolBar(IAction action)
With this, you will rarely need to create RetargetActions. But if you do,
use (subclass) MuvitorActionBarContributor
for this purpose and
check it and createActions()
for existing actions before.
action
- the action to be registered in this editor's
ActionRegistry
and to be put on the editors tool bar.registerAction(IAction)
protected abstract void createCustomActions()
To be available for the context menu, tool bar, key binding, or as shared
action instance for this editor's MuvitorPage
s (see there for
information about sharing action instances), custom actions have to
registered here via registerAction(IAction)
. Alternatively, you
may use the convenient method registerActionOnToolBar(IAction)
to put an action on a tool bar.
With this, you will rarely need to create RetargetActions. But if you do,
use (subclass) MuvitorActionBarContributor
for this purpose and
check it and createActions()
for existing actions before.
WorkbenchPartAction
s and SelectionAction
s created here
should get the editor (this
) as workbench part in their
constructor.
There is no need to set handles that you create here (which will be used
if the TreeEditor is the active part) for the RetargetActions here
because this will be done by default in
ActionBarContributor.setActiveEditor(IEditorPart)
. This
will work as long as the handle action has the same ID as the
RetargetAction it is meant to handle.
Keep in mind that RetargetAction handles for MuvitorPage
s must
be set explicitly! See there for more information about registering
(shared) handles for RetargetActions.
public final void createPartControl(Composite parent)
Control
. The tree 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. The editor again registers
itself as a listener to the global selection service to react on changes
in this plugin's MuvitorPageBookView
s.
WARNING: This method may or may not be called by the workbench prior to
dispose()
.
createPartControl
in interface IWorkbenchPart
createPartControl
in class WorkbenchPart
parent
- the parent compositeorg.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets
.Composite)
public void dispose()
dispose
in interface IWorkbenchPart
dispose
in class WorkbenchPart
protected final void firePropertyChange(int property)
firePropertyChange
in class WorkbenchPart
public EObject getPrimaryModelRoot()
EObject
models
that have been loaded by the EMFModelManager
. This will be set as
contents for the TreeViewer. Subclasses may override.
getModelRoots()
public final List<EObject> getModelRoots()
EObject
models that have been loaded by the
EMFModelManager
. The first of this (see
getPrimaryModelRoot()
) will be set as contents for the
TreeViewer.
protected final ActionRegistry getActionRegistry()
createActions()
,
updateActions()
protected final KeyHandler getKeyHandler()
public Object getAdapter(Class type)
createPartControl(Composite)
is called. The
order is unspecified by the Workbench. Subclasses may override but must
call super implementation!
getAdapter
in interface IAdaptable
getAdapter
in class WorkbenchPart
protected final CommandStack getCommandStack()
protected final DefaultEditDomain getEditDomain()
public final TreeViewer getTreeViewer()
MuvitorTreeEditor.EditorTreeViewer
in this editor.public final IStatusLineManager getStatusLineManager()
IStatusLineManager
from the IActionBars
of
this page's IPageSite
public void init(IEditorSite site, IEditorInput input)
init
in interface IEditorPart
init
in class EditorPart
protected abstract void setupKeyHandler(KeyHandler kh)
KeyStroke
s with Actions in
the passed KeyHandler
which is the one used for the
MuvitorTreeEditor.EditorTreeViewer
.
getKeyHandler()
protected abstract ContextMenuProviderWithActionRegistry createContextMenuProvider(TreeViewer viewer)
ContextMenuProviderWithActionRegistry
that should be used by this
editor's MuvitorTreeEditor.EditorTreeViewer
and is responsible to show the created
actions in the context menu.
viewer
- The graphical viewer for context menu provider
ContextMenuProviderWithActionRegistry
for the
specified MuvitorTreeEditor.EditorTreeViewer
.createTreeViewer(Composite)
protected abstract EditPartFactory createTreeEditPartFactory()
EditPartFactory
that should be used by this editor's MuvitorTreeEditor.EditorTreeViewer
.
EditPartFactory
for the GEF MuvitorTreeEditor.EditorTreeViewer
.public final boolean isDirty()
true
if the command stack is dirty
isDirty
in interface ISaveablePart
isDirty
in class EditorPart
ISaveablePart.isDirty()
public final void setFocus()
setFocus
in interface IWorkbenchPart
setFocus
in class WorkbenchPart
protected final void updateActions()
UpdateAction
s registered in the
actionRegistry
.
public final boolean isSaveAsAllowed()
isSaveAsAllowed
in interface ISaveablePart
isSaveAsAllowed
in class EditorPart
public final void doSave(IProgressMonitor monitor)
doSave
in interface ISaveablePart
doSave
in class EditorPart
public final void doSaveAs()
doSaveAs
in interface ISaveablePart
doSaveAs
in class EditorPart
public final void selectionChanged(IWorkbenchPart part, ISelection selection)
selectionChanged
in interface ISelectionListener
protected void save(IFile file, IProgressMonitor monitor) throws CoreException
EMFModelManager
.
Subclasses may extend but must call super implementation!
file
- The IFile
to save the model to.progressMonitor
- A progress monitor that could be used to show the saving
status.
CoreException
- This exception indicates that something went wrong during
saving.public static final void registerViewID(EClass eClass, String viewID)
MuvitorPageBookView
that has been registered in plugin.xml.
modelClass
- a class of EObjectsviewID
- the ID of a view to show the class of EObjectsshowView(EObject)
public static final IViewPart showView(EObject model)
MuvitorPageBookView
in the workbench displaying a model. It will check if the EClass
of the passed model or of one of its ancestors has been registered with a
view ID via registerViewID(EClass, String)
and will open a view
of this type showing the corresponding model. *
If a view can be opened successfully it will be returned.
model
- The model to be shown in the view
null
showView(String, EObject)
protected static final IViewPart showView(String viewId, EObject model)
MuvitorPageBookView
. An unique ID for the passed model is being created and set as secondary
ID of the new view. The model for this ID will be resolved y the view via
IDUtil
.
If a view can be opened successfully it will be returned.
In the special case that Eclipse has just been started and there is not
an active IWorkbenchPage
the opening of the view will be delayed
to when the IWorkbenchWindow
is being activated. So, this method
will return null, even if the view might be opened successfully later.
viewId
- The primary ID of the view to be opened. This must correspond
to an org.eclipse.ui.views entry in plugin.xmlmodel
- The model to be shown in the view
null
public static final void closeViewShowing(EObject model)
showView(EObject)
for this model.
public static final ArrayList<EObject> closeViews(MuvitorTreeEditor editor)
closeViewShowing(EObject)
this method closes all
views showing an EObject that belongs to the specified editor, according
to IDUtil.getHostEditor(EObject)
.
editor
- the editor whose views should be closed
public void saveState(IMemento memento)
IMemento
.
saveState
in interface IPersistable
public void restoreState(IMemento memento)
restoreState
in interface IPersistableEditor
public void revertToLastSaved()
RevertAction
.
Subclasses may extend but must call super implementation!
Closes all views, resets the actual input, and updates all actions.
public final IMarker createErrorMarker(EObject model, String location, String message)
MuvitorTreeEditor
to "jump" to the
error-causing model via gotoMarker(IMarker)
.
model
- an EObject model as the problem causelocation
- the location of the problemmessage
- a message describing the problem
gotoMarker(IMarker)
public final ArrayList<IMarker> findProblemMarkers(String attrName)
findProblemMarkers(String, Object)
for which the attribute has
been set with any value.
attrName
- some custom attribute that has been set to a marker
public final ArrayList<IMarker> findProblemMarkers(String attrName, Object attrValue)
attrName
- some custom attribute that has been set to a markerattrValue
- a value for the attrName attribute to be matched; will be
ignored if null
public void gotoMarker(IMarker marker)
IGotoMarker
tries to resolve the
marker's IMarker.SOURCE_ID
attribute to an EObject model. If such
a model exists it will be opened via showView(EObject)
(if
possible) and set as the selection in the corresponding viewer.
gotoMarker
in interface IGotoMarker
org.eclipse.ui.ide.IGotoMarker#gotoMarker(org.eclipse.core.resources.
IMarker)
,
createErrorMarker(EObject, String, String)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |