Skip to main content
Jump to: navigation, search

Difference between revisions of "Papyrus/Papyrus Developer Guide/How To Code Examples"

m
m (Add see xx references)
Line 40: Line 40:
 
<br>  
 
<br>  
  
     ISashWindowsContainer container = getISashWindowsContainer(); // see&nbsp;;
+
     ISashWindowsContainer container = getISashWindowsContainer(); // see&nbsp; How to get the ISashWindowsContainer;
 
     IPageChangedListener listener = ... // Get your listener
 
     IPageChangedListener listener = ... // Get your listener
 
     container.addPageChangedListener(listener);
 
     container.addPageChangedListener(listener);
Line 53: Line 53:
  
 
From the ServiceRegistry:<br>  
 
From the ServiceRegistry:<br>  
<pre>  ServicesRegistry serviceRegistry = getServiceRegistry(); // see  
+
<pre>  ServicesRegistry serviceRegistry = getServiceRegistry(); // see How to get the ServiceRegistry
 
   ISashWindowsContainer container = ServiceUtils.getInstance().getISashWindowsContainer(serviceRegistry);
 
   ISashWindowsContainer container = ServiceUtils.getInstance().getISashWindowsContainer(serviceRegistry);
 
</pre>  
 
</pre>  
Line 73: Line 73:
  
 
Second get the Active nested editor:<br>  
 
Second get the Active nested editor:<br>  
<pre>        ISashWindowsContainer container = getISashWindowsContainer(); // see&nbsp;;
+
<pre>        ISashWindowsContainer container = getISashWindowsContainer(); // see&nbsp; How to get the ISashWindowsContainer;
 
         IEditorPart activeEditor = container.getActiveEditor();
 
         IEditorPart activeEditor = container.getActiveEditor();
  
Line 81: Line 81:
 
A visible nested editor is one that is visible from the user. There can be several nested editors visible at one time. You can get the list of visible editors:<br>  
 
A visible nested editor is one that is visible from the user. There can be several nested editors visible at one time. You can get the list of visible editors:<br>  
  
   ISashWindowsContainer container = getISashWindowsContainer(); // see&nbsp;;
+
   ISashWindowsContainer container = getISashWindowsContainer(); // see&nbsp; How to get the ISashWindowsContainer;
 
   List&lt;IEditorPart&gt; visibleEditors = container .getVisibleIEditorParts();
 
   List&lt;IEditorPart&gt; visibleEditors = container .getVisibleIEditorParts();
  

Revision as of 09:26, 21 June 2011

Core Examples

This section contains code examples related to the 'core'

How to get the ServiceRegistry

The ServiceRegistry is a central point in Papyrus. It allows to get nearly all objects or services used by papyrus.

There is one and only one ServiceRegistry for each Papyrus Editor.

When you create a Diagram or a Service, Papyrus always provide the ServiceRegistry as an argument. You usually need to store it in a way you could easily retrieve it.

 import org.eclipse.papyrus.core.services.ServicesRegistry;

If you are implementaing a Command Handler, you can get the ServiceRegistry of the currently active Papyrus editor like that:

   ServicesRegistry serviceRegistry = ServiceUtilsForActionHandlers.getInstance().getServiceRegistry();

If you are in a GMF related stuff and you have the IDiagramEditDomain :

   IDiagramEditDomain domain = getIDiagramEditingDomain(); // 
   ServicesRegistry serviceRegistry = ServiceUtilsForGMF.getInstance().getServiceRegistry(domain);

If you have the Papyrus main editor part (IEditorPart):

 IEditorPart editorPart = getIEditorPart() // The Papyrus editor, not a nested editorPart
 ServicesRegistry serviceRegistry = (ServicesRegistry)editor.getAdapter(ServicesRegistry.class);


See also 'Papyrus Cookbook/How to get a Papyrus Service or the ServiceRegistry'

How to be notified when active page change

The SashWindows system send events when the current active page change (i.e. the nested editor). It is possible to listen on this event.

Your listener should implement the following interface:

org.eclipse.papyrus.sasheditor.editor.IPageChangedListener

Then you need to register your listener to the sashWindowContainer:


   ISashWindowsContainer container = getISashWindowsContainer(); // see  How to get the ISashWindowsContainer;
   IPageChangedListener listener = ... // Get your listener
   container.addPageChangedListener(listener);


How to get the ISashWindowsContainer

The ISashWindowContainer allows to listen on page changed events, or to refresh the windows. There is one ISashWindowsContainer for each Papyrus editor.

It is possible to get it in different ways:

From the ServiceRegistry:

  ServicesRegistry serviceRegistry = getServiceRegistry(); // see How to get the ServiceRegistry
  ISashWindowsContainer container = ServiceUtils.getInstance().getISashWindowsContainer(serviceRegistry);

From an Handler (and only from handler, check javadoc):

 ISashWindowsContainer container = ServiceUtilsForActionHandlers.getInstance().getISashWindowsContainer();
 

From the Papyrus IEditorPart ():

	
        IEditorPart editorPart = getIEditorPart() // The Papyrus editor, not a nested editorPart
        ISashWindowsContainer container = (ISashWindowsContainer)editorPart.getAdapter(ISashWindowsContainer.class);

How to get the currently active nested editor

You can get the nested editor that is currently active from the ISashWindowContainer.

First, get the ISashWindowsContainer (see ).

Second get the Active nested editor:

        ISashWindowsContainer container = getISashWindowsContainer(); // see  How to get the ISashWindowsContainer;
        IEditorPart activeEditor = container.getActiveEditor();

How to get the list of visible nested editors

A visible nested editor is one that is visible from the user. There can be several nested editors visible at one time. You can get the list of visible editors:

 ISashWindowsContainer container = getISashWindowsContainer(); // see  How to get the ISashWindowsContainer;
 List<IEditorPart> visibleEditors = container .getVisibleIEditorParts();


Diagram Examples

This section contains code example related to diagrams.

How to develop my own UML diagram

Papyrus allow to add new kind of UML diagrams. A plugin example with a doc can be found in the SVN:

[To be completed]

More Examples

Back to the top