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 editor
E - 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 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 mPart
      The e4 part. Set in postConstruct(MPart, Composite).
    • editor

      protected E extends GraphicalEditor<C> editor
      The editor of the part. It is null until initContents(Composite, MPart) runs.
    • toolBar

      protected org.eclipse.swt.widgets.ToolBar toolBar
      The toolbar of the part. createToolbarElements(Composite) adds items to it.
    • onObjectSelectedHandler

      protected Consumer<Object> onObjectSelectedHandler
    • onObjectSelectedFilter

      protected Predicate<Object> onObjectSelectedFilter
  • Constructor Details

    • AbstractGraphicalEditorPart

      public AbstractGraphicalEditorPart()
  • Method Details

    • createEditor

      protected abstract E createEditor(org.eclipse.swt.widgets.Composite parent)
      Creates the editor in the given composite. Called once from initContents(Composite, MPart).
      Parameters:
      parent - the composite of the editor area
      Returns:
      the new editor
    • getContainer

      protected abstract C getContainer()
      Returns the container to show in the editor, for example the current scenario. May return null when 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 part
      parent - the composite of the part
    • initializeToolBar

      protected void initializeToolBar(org.eclipse.swt.widgets.Composite parent)
      Creates the toolbar and calls createToolbarElements(Composite).
      Parameters:
      parent - the composite of the toolbar
    • createToolbarElements

      protected void createToolbarElements(org.eclipse.swt.widgets.Composite parent)
      Adds items to toolBar. 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, calls configureEditor(Composite) and shows the container.
      Parameters:
      parent - the composite of the editor area
      mPart - 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 with subscribe(String, Consumer) when the part is disposed.
      Parameters:
      parent - the composite of the editor area
    • onMouseClicked

      protected void onMouseClicked(javafx.scene.input.MouseEvent event, Object object)
      Handles a click in the editor. In the selection mode, passes the object to onObjectSelected(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, calls onObjectClicked(MouseEvent, Object). The filter comes from PlatformTopics.WAITING_FOR_FILTERED_OBJECT_SELECTION.
      Parameters:
      event - the mouse event
      object - the clicked object or null
    • onObjectClicked

      protected void onObjectClicked(javafx.scene.input.MouseEvent event, Object object)
      Handles a click outside the selection mode. Sends PlatformTopics.PROPERTY_SELECTION_CHANGED by default.
      Parameters:
      event - the mouse event
      object - the clicked object or null
    • onObjectSelected

      protected void onObjectSelected(Object object)
      Passes an object accepted by the filter to the selection handler.
      Parameters:
      object - the selected object, not null
    • onEscKeyTyped

      protected void onEscKeyTyped()
      Handles the Esc key. Passes it to the editor by default.
    • onNewFileLoaded

      protected void onNewFileLoaded(GraphicalEditor<C> editor)
      Shows the container from getContainer() 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

      protected final <T> void subscribe(String topic, Consumer<T> handler)
      Subscribes a handler to a topic through messageManager and unsubscribes it when the part is disposed. The handler gets the event data cast to T. Pass a new handler for each call because MessageManager keeps one subscription for each handler instance.
      Type Parameters:
      T - type of the event data
      Parameters:
      topic - the topic
      handler - the handler of the event data
    • preDestroy

      @PreDestroy public void preDestroy()
      Removes the subscriptions made with subscribe(String, Consumer).