Skip to main content
Jump to: navigation, search

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

(Create page)
 
(Add More Examples section)
Line 1: Line 1:
 
== Core Examples  ==
 
== Core Examples  ==
This section contains code examples related to the 'core'
+
 
 +
This section contains code examples related to the 'core'  
  
 
=== How to get the ServiceRegistry  ===
 
=== How to get the ServiceRegistry  ===
Line 37: Line 38:
 
Then you need to register your listener to the sashWindowContainer:<br>  
 
Then you need to register your listener to the sashWindowContainer:<br>  
  
 +
<br>
  
 
     ISashWindowsContainer container = getISashWindowsContainer(); // see&nbsp;;
 
     ISashWindowsContainer container = getISashWindowsContainer(); // see&nbsp;;
Line 75: Line 77:
  
 
</pre>  
 
</pre>  
=== How to get the list of visible nested editors<br> ===
+
=== How to get the list of visible nested 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>
+
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;;
   List<IEditorPart> visibleEditors = container .getVisibleIEditorParts();
+
   List&lt;IEditorPart&gt; visibleEditors = container .getVisibleIEditorParts();
 +
 
 +
<br>
 +
 
 +
== Diagram Examples  ==
  
 +
This section contains code example related to diagrams.
  
 +
== More Examples<br>  ==
  
== Diagram Examples ==
+
*The following folder contains more examples (sometime deprecated).
This section contains code example related to diagrams.
+
**http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments/cookbook/
 +
*Check the cookbook ([http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments/cookbook/PapyrusCookBook.odt PapyrusCookBook.odt])

Revision as of 06:40, 14 April 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 ;
   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 
  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 ;
        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 ;
 List<IEditorPart> visibleEditors = container .getVisibleIEditorParts();


Diagram Examples

This section contains code example related to diagrams.

More Examples

Back to the top