Class AbstractGraphicalEditorPart<C extends org.eclipse.emf.ecore.EObject,E extends GraphicalEditor<C>>
java.lang.Object
com.amalgamasimulation.graphicaleditor.e4.AbstractGraphicalEditorPart<C,E>
- Type Parameters:
C- type of the container shown in the editorE- type of the editor
public abstract class AbstractGraphicalEditorPart<C extends org.eclipse.emf.ecore.EObject,E extends GraphicalEditor<C>>
extends Object
Base e4 part for a graphical editor. Creates the toolbar and the editor, subscribes to the
platform topics and unsubscribes from them when the part is disposed.
The base handles the selection mode, Esc, navigation to an object and loading of a new scenario.
In the selection mode, the editor waits for a click on an object that another view requests with
PlatformTopics.WAITING_FOR_FILTERED_OBJECT_SELECTION. A subclass creates the editor and
returns the container. It can also add toolbar items and set up the editor.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.eclipse.e4.ui.model.application.MApplicationprotected EThe editor of the part.protected org.eclipse.e4.core.services.events.IEventBrokerprotected com.amalgamasimulation.desktop.utils.MessageManagerprotected org.eclipse.e4.ui.workbench.modeling.EModelServiceprotected org.eclipse.e4.ui.model.application.ui.basic.MPartThe e4 part.protected org.eclipse.e4.ui.workbench.modeling.EPartServiceprotected org.eclipse.swt.widgets.ToolBarThe toolbar of the part. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconfigureEditor(org.eclipse.swt.widgets.Composite parent) Sets up the editor after it is created and before the container is shown.protected abstract EcreateEditor(org.eclipse.swt.widgets.Composite parent) Creates the editor in the given composite.protected voidcreateToolbarElements(org.eclipse.swt.widgets.Composite parent) Adds items totoolBar.protected abstract CReturns the container to show in the editor, for example the current scenario.protected voidinitContents(org.eclipse.swt.widgets.Composite parent, org.eclipse.e4.ui.model.application.ui.basic.MPart mPart) Creates the editor, adds the click listener and the subscriptions to the platform topics, callsconfigureEditor(Composite)and shows the container.protected voidinitializeToolBar(org.eclipse.swt.widgets.Composite parent) Creates the toolbar and callscreateToolbarElements(Composite).protected voidMoves and zooms the view to the object or the list of objects and selects them.protected voidHandles the Esc key.protected voidonMouseClicked(javafx.scene.input.MouseEvent event, Object object) Handles a click in the editor.protected voidonNewFileLoaded(GraphicalEditor<C> editor) Shows the container fromgetContainer()in the editor.protected voidonObjectClicked(javafx.scene.input.MouseEvent event, Object object) Handles a click outside the selection mode.protected voidonObjectSelected(Object object) Passes an object accepted by the filter to the selection handler.voidpostConstruct(org.eclipse.e4.ui.model.application.ui.basic.MPart mPart, org.eclipse.swt.widgets.Composite parent) Creates the toolbar and the editor area.voidRemoves the subscriptions made withsubscribe(String, Consumer).protected final <T> voidSubscribes a handler to a topic throughmessageManagerand unsubscribes it when the part is disposed.
-
Field Details
-
eventBroker
@Inject protected org.eclipse.e4.core.services.events.IEventBroker eventBroker -
messageManager
@Inject protected com.amalgamasimulation.desktop.utils.MessageManager messageManager -
modelService
@Inject protected org.eclipse.e4.ui.workbench.modeling.EModelService modelService -
application
@Inject protected org.eclipse.e4.ui.model.application.MApplication application -
partService
@Inject protected org.eclipse.e4.ui.workbench.modeling.EPartService partService -
mPart
protected org.eclipse.e4.ui.model.application.ui.basic.MPart mPartThe e4 part. Set inpostConstruct(MPart, Composite). -
editor
The editor of the part. It isnulluntilinitContents(Composite, MPart)runs. -
toolBar
protected org.eclipse.swt.widgets.ToolBar toolBarThe toolbar of the part.createToolbarElements(Composite)adds items to it. -
onObjectSelectedHandler
-
onObjectSelectedFilter
-
-
Constructor Details
-
AbstractGraphicalEditorPart
public AbstractGraphicalEditorPart()
-
-
Method Details
-
createEditor
Creates the editor in the given composite. Called once frominitContents(Composite, MPart).- Parameters:
parent- the composite of the editor area- Returns:
- the new editor
-
getContainer
Returns the container to show in the editor, for example the current scenario. May returnnullwhen no scenario is open.- Returns:
- the container or
null
-
postConstruct
@PostConstruct public void postConstruct(org.eclipse.e4.ui.model.application.ui.basic.MPart mPart, org.eclipse.swt.widgets.Composite parent) Creates the toolbar and the editor area.- Parameters:
mPart- the e4 partparent- the composite of the part
-
initializeToolBar
protected void initializeToolBar(org.eclipse.swt.widgets.Composite parent) Creates the toolbar and callscreateToolbarElements(Composite).- Parameters:
parent- the composite of the toolbar
-
createToolbarElements
protected void createToolbarElements(org.eclipse.swt.widgets.Composite parent) Adds items totoolBar. Does nothing by default.- Parameters:
parent- the composite of the toolbar
-
initContents
protected void initContents(org.eclipse.swt.widgets.Composite parent, org.eclipse.e4.ui.model.application.ui.basic.MPart mPart) Creates the editor, adds the click listener and the subscriptions to the platform topics, callsconfigureEditor(Composite)and shows the container.- Parameters:
parent- the composite of the editor areamPart- the e4 part
-
configureEditor
protected void configureEditor(org.eclipse.swt.widgets.Composite parent) Sets up the editor after it is created and before the container is shown. Does nothing by default. The base removes the subscriptions made here withsubscribe(String, Consumer)when the part is disposed.- Parameters:
parent- the composite of the editor area
-
onMouseClicked
Handles a click in the editor. In the selection mode, passes the object toonObjectSelected(Object)if the filter accepts it. The base ignores a click on empty space and a click on an object that the filter rejects. Outside the selection mode, callsonObjectClicked(MouseEvent, Object). The filter comes fromPlatformTopics.WAITING_FOR_FILTERED_OBJECT_SELECTION.- Parameters:
event- the mouse eventobject- the clicked object ornull
-
onObjectClicked
Handles a click outside the selection mode. SendsPlatformTopics.PROPERTY_SELECTION_CHANGEDby default.- Parameters:
event- the mouse eventobject- the clicked object ornull
-
onObjectSelected
Passes an object accepted by the filter to the selection handler.- Parameters:
object- the selected object, notnull
-
onEscKeyTyped
protected void onEscKeyTyped()Handles the Esc key. Passes it to the editor by default. -
onNewFileLoaded
Shows the container fromgetContainer()in the editor. Called when the part opens and after a new scenario is loaded. If the container is the same object as before, the editor does nothing.- Parameters:
editor- the editor
-
subscribe
Subscribes a handler to a topic throughmessageManagerand unsubscribes it when the part is disposed. The handler gets the event data cast toT. Pass a new handler for each call becauseMessageManagerkeeps one subscription for each handler instance.- Type Parameters:
T- type of the event data- Parameters:
topic- the topichandler- the handler of the event data
-
preDestroy
@PreDestroy public void preDestroy()Removes the subscriptions made withsubscribe(String, Consumer).
-