de.cau.cs.kieler.core.model.gmf.triggers
Class ModelChangeTrigger.ActiveEditorState

java.lang.Object
  extended by de.cau.cs.kieler.core.kivi.AbstractTriggerState
      extended by de.cau.cs.kieler.core.model.gmf.triggers.ModelChangeTrigger.ActiveEditorState
All Implemented Interfaces:
ITriggerState
Enclosing class:
ModelChangeTrigger

public static class ModelChangeTrigger.ActiveEditorState
extends AbstractTriggerState

A state about the model viewers currently visible, e.g. the current active editor or active view. It contains lists of all active IWorkbenchParts and a list of all such parts that contain a diagram, i.e. are compatible with the GraphicalFrameworkService. Note that the parts can be either IViewParts or IEditorParts.

A scenario is to use the last opened editor or view of a specific kind. You can obtain the lists of currently open parts or diagram parts by getOpenWorkbenchParts() resp. getOpenDiagrams(). As the lists are ordered by the order in which the parts were activated (freshest part is the first), they can be iterated with choosing the first part that matches the right ID, e.g. by comparing their string IDs with IWorkbenchPart.getSite() and IWorkbenchPartSite#getID(). This ensures to (1) avoid doing something on a not supported editor or view and (2) to also be able to do something when some other editor or view is in the focus. Note that this might also do something on an editor that is not on top, i.e. not actually visible.

  String relevantID = "my.editor.id";
  IWorkbenchPart myPart = null;
  for(IWorkbenchPart part : activeEditorState.getOpenDiagrams()){
     if(relevantID.equals(part.getSite().getID()){
          myPart = part;
          break;
     }
  }
  if(myPart != null){
  ...
  }
 

Rating red

Constructor Summary
ModelChangeTrigger.ActiveEditorState()
          Default Constructor that can be used as a default state.
ModelChangeTrigger.ActiveEditorState(IWorkbenchPart focused, IWorkbenchPart opened, IWorkbenchPart closed)
          Constructor.
 
Method Summary
 IWorkbenchPart getLastActiveDiagram()
          Get the most recently opened editor or view that contains a diagram supported by the GraphicalFrameworkService.
 EObject getLastActiveSemanticModel()
          Get the semantic model in shape of the root EObject that corresponds to the diagram or other editor that was last active.
 IWorkbenchPart getLastActiveWorkbenchPart()
          Get the most recently opened editor or view.
 List<IWorkbenchPart> getOpenDiagrams()
          Get a list of all IWorkbenchParts (editors and views) that contain a diagram supported by the GraphicalFrameworkService.
 List<IWorkbenchPart> getOpenWorkbenchParts()
          Get a list of any active IWorkbenchParts.
 Class<? extends ITrigger> getTriggerClass()
          Get the trigger class associated with this trigger state.
 void merge(ITriggerState previous)
          Update the list of open diagram editors and views.
 
Methods inherited from class de.cau.cs.kieler.core.kivi.AbstractTriggerState
finish, getKeyClass, getSequenceNumber, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ModelChangeTrigger.ActiveEditorState

public ModelChangeTrigger.ActiveEditorState()
Default Constructor that can be used as a default state.


ModelChangeTrigger.ActiveEditorState

public ModelChangeTrigger.ActiveEditorState(IWorkbenchPart focused,
                                            IWorkbenchPart opened,
                                            IWorkbenchPart closed)
Constructor.

Parameters:
focused - an editor just focused
opened - a newly opened editor
closed - an editor just closed
Method Detail

getLastActiveWorkbenchPart

public IWorkbenchPart getLastActiveWorkbenchPart()
Get the most recently opened editor or view. Maybe null if there is no such.

Returns:
editor or view

getLastActiveDiagram

public IWorkbenchPart getLastActiveDiagram()
Get the most recently opened editor or view that contains a diagram supported by the GraphicalFrameworkService. Maybe null if there is no such.

Returns:
the last active diagram editor or view

getOpenDiagrams

public List<IWorkbenchPart> getOpenDiagrams()
Get a list of all IWorkbenchParts (editors and views) that contain a diagram supported by the GraphicalFrameworkService. The order in the list is starting with the last activated part. It will include all currently active parts.

Returns:
the open diagrams IViewPart or IEditorPart

getOpenWorkbenchParts

public List<IWorkbenchPart> getOpenWorkbenchParts()
Get a list of any active IWorkbenchParts. This may include views and editors. The order in the list is starting with the last activated part. It will include all currently active parts.

Returns:
list of currently active IWorkbenchParts, i.e. IViewPart or IEditorPart

getLastActiveSemanticModel

public EObject getLastActiveSemanticModel()
Get the semantic model in shape of the root EObject that corresponds to the diagram or other editor that was last active.

Returns:
last active EObject model

merge

public void merge(ITriggerState previous)
Update the list of open diagram editors and views. Merge this state instance with the previous instance in case of delta trigger events.

Specified by:
merge in interface ITriggerState
Overrides:
merge in class AbstractTriggerState
Parameters:
previous - the previous instance of this trigger state

getTriggerClass

public Class<? extends ITrigger> getTriggerClass()
Get the trigger class associated with this trigger state.

Returns:
the trigger class