Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » A New Diagram Editor integration into the Papyrus environment
A New Diagram Editor integration into the Papyrus environment [message #1016208] Tue, 05 March 2013 08:42 Go to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
Hello!

The Papyrus Developer Guide explains how to generate a new Papyrus diagram editor here: http://wiki.eclipse.org/Papyrus_Developer_Guide/Papyrus_diagram_generation#Run_the_generation

Where can I find the information how to INTEGRATE the generated diagram editor into the Papyrus environment?

Thanks.

Best regards
Mary
Re: A New Diagram Editor integration into the Papyrus environment [message #1016509 is a reply to message #1016208] Wed, 06 March 2013 12:38 Go to previous messageGo to next message
Remi Schnekenburger is currently offline Remi Schnekenburger
Messages: 127
Registered: July 2009
Senior Member
Hi Mary,

there is currently no online documentation on integrating a new editor in Papyrus.

However, this is quite easy and fast, as this is done by few hand-written classes, similar in each editor plugin. To see how you can do it, you can look in the class diagram plugin: org.eclipse.papyrus.uml.diagram.clazz.
The following classes are in charge of the integration of the generated editor into papyrus main editor:
- ClassDiagramCreationCondition.java
- ClassDiagramEditorFactory.java
- CreateClassDiagramCommand.java
- CreateClassDiagramWithNavigationHandler.java
- UmlClassDiagramForMultiEditor.java

Once you have 'duplicated' these classes in your plugin and updated your plugin.xml file, you should see your editor in Papyrus!

HTH
Remi


Re: A New Diagram Editor integration into the Papyrus environment [message #1017003 is a reply to message #1016509] Fri, 08 March 2013 09:37 Go to previous messageGo to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
Thank you =)
Re: A New Diagram Editor integration into the Papyrus environment [message #1017007 is a reply to message #1016509] Fri, 08 March 2013 09:50 Go to previous messageGo to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
Is it possible to integrate into Papyrus a diagram editor for NOT UML diagrams (or SysML)?
More precisely, I want to use my own element as a root element but not UML Model.
Re: A New Diagram Editor integration into the Papyrus environment [message #1017126 is a reply to message #1017007] Sat, 09 March 2013 12:03 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 126
Registered: September 2011
Senior Member
Yes, it is possible. Actually I've integrated a 3rd party GMF editor into Papyrus. See http://www.eclipse.org/forums/index.php/m/889856/?srch=integrate+editor#msg_889856 for more details.
Re: A New Diagram Editor integration into the Papyrus environment [message #1017128 is a reply to message #1017126] Sat, 09 March 2013 12:27 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 126
Registered: September 2011
Senior Member
So these are the steps to integrate a GMF editor into Papyrus, which operates on another model than the UML model:
* Create a new class MyGMFDiagramEditorOverride that extends the generated class MyGMFDiagramEditor. Merge the contents from org.eclipse.papyrus.uml.diagram.clazz.UmlClassDiagramForMultiEditor and org.eclipse.papyrus.uml.diagram.clazz.part.UMLDiagramEditor into MyGMFDiagramEditorOverride
* Create a new class MyGMFDiagramEditorFactory that extends org.eclipse.papyrus.infra.gmfdiag.common.GmfEditorFactory and in its constructor call super(MyGMFDiagramEditorOverride.class, MyRootElementEditPart.MODEL_ID)
* realize the extension point org.eclipse.papyrus.infra.core.papyrusDiagram and refer to MyGMFDiagramEditorFactory


plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.papyrus.infra.core.papyrusDiagram">
      <editorDiagram
            factoryClass="my.package.MyGMFDiagramEditorFactory"
            icon="platform:/plugin/my.plugin/icons/obj16/Editor.gif">
      </editorDiagram>
   </extension>
</plugin>



[Updated on: Mon, 11 March 2013 12:32]

Report message to a moderator

Re: A New Diagram Editor integration into the Papyrus environment [message #1017283 is a reply to message #1017128] Mon, 11 March 2013 09:33 Go to previous messageGo to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
Hello, Simon.

Thank you so much for the information.
I did what you told me but I still cannot see my diagram editor in Papyrus.

Is "org.eclipse.papyrus.infra.core.papyrusDiagram" the only extension that I need to add to plugin.xml?

The problem is that I tried to add one more extension which is

   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:org.eclipse.papyrus.ui.menu">
         <menu
               id="org.eclipse.papyrus.diagram.ui.menu.diagrams"
               label="Diagrams">
            <command
                  commandId="org.eclipse.papyrus.diagram.newdiagram.CreateDiagramCommand"
                  icon="icons/obj16/newDiagramFile.gif"
                  label="Create a new Simple Diagram"
                  style="push"
                  tooltip="Create a new Simple Diagram">
            </command>
         </menu>
      </menuContribution>
   </extension>


And this extension embeds a button for creation of my diagram.
But when I try to create a diagram it checks if my editor uses the model of the Papyrus Project in which I create this diagram. And I see that there are three possible types of Papyrus projects: UML, SysML and UMLProfile. My editor does not use the model of any of them, hence, the diagram cannot be created!

Is there any way to create a Papyrus project based on my own model?

For any hint I would be thankful!


Re: A New Diagram Editor integration into the Papyrus environment [message #1017336 is a reply to message #1017283] Mon, 11 March 2013 11:59 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 126
Registered: September 2011
Senior Member
yes, you will need to register your model resource to the modelset of papyrus.

Create a class like this:




public class MyResource extends org.eclipse.papyrus.infra.core.resource.AbstractBaseModel implements org.eclipse.papyrus.infra.core.resource.IModel{

	public static final String MODEL_FILE_EXTENSION = "myextension"; 

	public static final String MODEL_ID = "my.package.MyResource"; 
	



	@Override
	public void createModel(IPath fullPath) {
		super.createModel(fullPath);
		

		MyRootElement rootEl = MyModelPackage.eINSTANCE.getMyModelFactory().createMyRootElement();
		
		getResource().getContents().add(rootEl);
	}


	@Override
	public String getIdentifier() {
		return MODEL_ID;
	}


	@Override
	protected String getModelFileExtension() {
		return MODEL_FILE_EXTENSION;
	}


}



Add register it like this in plugin.xml

	<extension
		point="org.eclipse.papyrus.infra.core.model">
		<model
			classname="my.package.MyResource">
		</model>
	</extension>


Now every time you create a new papyrus model, you should get an extra model.myextension file. Do the same for the diagram resource.
(If you want to create the model only if needed, use AbstractDynamicModel instead of AbstractBaseModel).


If you want to add new model templates (besides UML, SysML) you must use the extension point org.eclipse.papyrus.uml.diagram.wizards.templates. (In my case, I am not using this extension point directly, but I use a customized version of its implementation, i.e. org.eclipse.papyrus.uml.diagram.wizards.CreateModelWizard and I call my wizard from the extension point org.eclipse.ui.newWizards)

[Updated on: Mon, 11 March 2013 18:15]

Report message to a moderator

Re: A New Diagram Editor integration into the Papyrus environment [message #1017648 is a reply to message #1017336] Tue, 12 March 2013 05:09 Go to previous messageGo to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
Hello.
Thank you so much for your help I really need it very much!

I added the file and the extension point. Now every time I create a new project a new file with .myextension is generated. But I still do not see the palette and cannot edit the model.
Sorry, but I also did not understand what to do in order to "Do the same for the diagram resource"... I mean I did not find any example of the diagram resource implementation. And how can I bind the diagram to the model?

I would like to be able to create my own type of Project in Papyrus (not UML or SysML) based on my own model with my diagram editor.
Re: A New Diagram Editor integration into the Papyrus environment [message #1017665 is a reply to message #1017648] Tue, 12 March 2013 05:39 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 126
Registered: September 2011
Senior Member
At first something that must be clear: do you want to use Papyrus UML diagrams to create non-UML models? Or do you want to have your own model and your own diagrams in addition to the UML models and diagrams? For your own diagrams, are you using GMF?

[Updated on: Tue, 12 March 2013 05:39]

Report message to a moderator

Re: A New Diagram Editor integration into the Papyrus environment [message #1017668 is a reply to message #1017648] Tue, 12 March 2013 05:43 Go to previous messageGo to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
I mean... I wish I could use my own editor in the UML project but it does not seem to be possible because in the UML project a check of the model is porformed and my model is not the UML one, hence, I do not see the editor.
So, maybe, I need to create my own kind of project? (or new Diagram Category)
Or is there any way to open the editor for my model in the UML Project?
Re: A New Diagram Editor integration into the Papyrus environment [message #1017673 is a reply to message #1017665] Tue, 12 March 2013 05:56 Go to previous messageGo to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
oh, sorry, I wrote a message and then saw your reply.

What I want exactly is:
To create my own diagram editor with on my own models. Yes, I generate this editor using GMF and I use this Tutorial http://wiki.eclipse.org/Papyrus_Developer_Guide/Papyrus_diagram_generation#How_to_generate_a_diagram_for_Papyrus

Then I want to perform the consistency check between my diagrams and UML Class diagrams generated with Papyrus


So, I would like
1. to use "Papyrus UML diagrams to create non-UML models" if it is possible. Because in this case it would be easier to perform the consistency check. But I do not understand how it may be possible if I want to have the elements that are different from the UML ones and that have different graphical representation. But if there is any way to extend the UML model (without using the Profile mechanism) it would be perfect.
2. If it is not possible I can us "my own model and my own diagrams in addition to the UML models and diagrams". Yes, I generate my diagrams using GMF.

[Updated on: Tue, 12 March 2013 11:50]

Report message to a moderator

Re: A New Diagram Editor integration into the Papyrus environment [message #1017917 is a reply to message #1017648] Tue, 12 March 2013 15:45 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 126
Registered: September 2011
Senior Member
Mary P. wrote on Tue, 12 March 2013 05:09
Hello.
Now every time I create a new project a new file with .myextension is generated.

Of course that must be the extension of your emf model files.


Mary P. wrote on Tue, 12 March 2013 05:09

Sorry, but I also did not understand what to do in order to "Do the same for the diagram resource"...

If you use your GMF standalone, it creates 2 files: the model file and the diagram file. The diagram file must also be registered in Papyrus via the previous mentioned extension point.

Mary P. wrote on Tue, 12 March 2013 05:09

I mean I did not find any example of the diagram resource implementation. And how can I bind the diagram to the model?

Have a look into the new file creation wizard implementation that is generated with your GMF editor.

Mary P. wrote on Tue, 12 March 2013 05:09

I would like to be able to create my own type of Project in Papyrus (not UML or SysML) based on my own model with my diagram editor.

You do not need an own project type necessarily.
Re: A New Diagram Editor integration into the Papyrus environment [message #1017940 is a reply to message #1017673] Tue, 12 March 2013 16:36 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 126
Registered: September 2011
Senior Member
Mary P. wrote on Tue, 12 March 2013 05:56

To create my own diagram editor with on my own models. Yes, I generate this editor using GMF and I use this Tutorial http://wiki.eclipse.org/Papyrus_Developer_Guide/Papyrus_diagram_generation#How_to_generate_a_diagram_for_Papyrus

I think this tutorial is not appropriate for that what you want to do.

Mary P. wrote on Tue, 12 March 2013 05:56

Then I want to perform the consistency check between my diagrams and UML Class diagrams generated with Papyrus

What kind of consistency check? Do you want to traverse the models and check if there is a corresponding element in each of the two models?


Mary P. wrote on Tue, 12 March 2013 05:56

2. If it is not possible I can us "my own model and my own diagrams in addition to the UML models and diagrams". Yes, I generate my diagrams using GMF.

Ok good, you should have your own models in addition. When you say you use GMF: do you mean you use the tutorial you mentioned above or do you mean you have created a diagram editor for your custom models with the Graphical Modeling Framework (GMF)?
Re: A New Diagram Editor integration into the Papyrus environment [message #1017945 is a reply to message #1017673] Tue, 12 March 2013 16:40 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 126
Registered: September 2011
Senior Member
duplicate deleted

[Updated on: Tue, 12 March 2013 16:41]

Report message to a moderator

Re: A New Diagram Editor integration into the Papyrus environment [message #1018121 is a reply to message #1017940] Wed, 13 March 2013 03:50 Go to previous messageGo to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
Hello =)

Quote:
Ok good, you should have your own models in addition. When you say you use GMF: do you mean you use the tutorial you mentioned above or do you mean you have created a diagram editor for your custom models with the Graphical Modeling Framework (GMF)

I have my own .ecore file.
I use EMF to generate the model files (and the java code of my model) and then GMF to generate the editor as it is described here: http://wiki.eclipse.org/Graphical_Modeling_Framework/Tutorial/Part_1
I tried both ways:
[1] to follow this Tutorial directly (using only EMF and GMF). (It works if I run it as a new plug-in, but I did not try to integgrate it in Papyrus)
[2] To follow this Tutorial but at the step of the editor code generation I used this Tutorial: http://wiki.eclipse.org/Papyrus_Developer_Guide/Papyrus_diagram_generation Yes. This is the one that I try to integrate into Papyrus

Quote:
What kind of consistency check? Do you want to traverse the models and check if there is a corresponding element in each of the two models?

Yes

Thank you again and again for your help!

Mary
Re: A New Diagram Editor integration into the Papyrus environment [message #1018159 is a reply to message #1018121] Wed, 13 March 2013 05:34 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 126
Registered: September 2011
Senior Member
Mary P. wrote on Wed, 13 March 2013 03:50

I have my own .ecore file.
I use EMF to generate the model files (and the java code of my model) and then GMF to generate the editor as it is described here: http://wiki.eclipse.org/Graphical_Modeling_Framework/Tutorial/Part_1

Perfect.


Mary P. wrote on Wed, 13 March 2013 03:50

[2] To follow this Tutorial but at the step of the editor code generation I used this Tutorial: http://wiki.eclipse.org/Papyrus_Developer_Guide/Papyrus_diagram_generation Yes. This is the one that I try to integrate into Papyrus

As I said, I assume you do not need the code generation templates. I integrated a 3rd party GMF editor into Papyrus without touching the code of Papyrus or the other diagram editor.



If you just want to do a consistency check you might not need an integration of Papyrus. You can load EMF models independently from Papyrus or GMF. So, instead of integrating your GMF editor into Papyrus you could open a dialog from the eclipse menu, that has two buttons to browse and load the uml and the custom model files. Then you can run your consistency check and show the results in a list.
Re: A New Diagram Editor integration into the Papyrus environment [message #1018176 is a reply to message #1018159] Wed, 13 March 2013 06:12 Go to previous messageGo to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
The problem is that I do not choose the technology and I need to use Papyrus.
Ok, then I will do everything you mentioned before in order integrate the editor generated only by GMF ([1]) wothout the Papyrus editor generation.

Quote:
I integrated a 3rd party GMF editor into Papyrus without touching the code of Papyrus or the other diagram editor.


Sorry, but then I have a couple of questions to you.
0. Is there any documentation that helped you to do this?
1. Did you need to create your own diagram Category? Did you add an extension like this:
	<diagramCategory 
		class="components.diagram.MyCreationCommand" 
		description="My diagram"
		icon="icons/obj16/newDiagramFile.gif" 
		id="mydi" 
		label="MyDi">
	</diagramCategory>

Did you create a class that implements IModelCreationCommand?

2. What extension points did you add to your plugin.xml besides
	<extension
		point="org.eclipse.papyrus.infra.core.model">
		<model
			classname="my.package.MyResource">
		</model>
	</extension>

and

   <extension
         point="org.eclipse.papyrus.infra.core.papyrusDiagram">
      <editorDiagram
            factoryClass="my.package.MyGMFDiagramEditorFactory"
            icon="platform:/plugin/my.plugin/icons/obj16/Editor.gif">
      </editorDiagram>
   </extension>



Thank you!!!!!!!!!!

Mary

[Updated on: Wed, 13 March 2013 06:20]

Report message to a moderator

Re: A New Diagram Editor integration into the Papyrus environment [message #1018483 is a reply to message #1018176] Wed, 13 March 2013 18:51 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 126
Registered: September 2011
Senior Member
I open the diagrams from the context menu

public class ViewVisualContractAction extends org.eclipse.core.commands.AbstractHandler{

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {

ServicesRegistry serviceRegistry = ServiceUtilsForActionHandlers
				.getInstance().getServiceRegistry();
		
		ModelSet modelSet = ServiceUtilsForActionHandlers.getInstance().getModelSet();
		
		HenshinDiagramResource henshinDiagramModel = (HenshinDiagramResource) modelSet.getModelChecked(HenshinDiagramResource.MODEL_ID);
		
		if(henshinDiagramModel.getResource()!=null){
			Diagram diagram = (Diagram) henshinDiagramModel.getResource().getContents().get(0);
				
			IPageMngr pageMngr = ServiceUtils.getInstance().getIPageMngr(
					serviceRegistry);
			


			if(pageMngr.isOpen(diagram)){
				pageMngr.closePage(diagram);
			}
			pageMngr.openPage(diagram);
			
		}
}

Replace HenshinDiagramResource with the name of your diagram resource.


further reading on how to call the handler: http://trac.rtsys.informatik.uni-kiel.de/trac/kieler/wiki/Help/EclipseCookbook/ContextMenu

[Updated on: Wed, 13 March 2013 18:52]

Report message to a moderator

Re: A New Diagram Editor integration into the Papyrus environment [message #1018670 is a reply to message #1018483] Thu, 14 March 2013 05:32 Go to previous messageGo to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
Hello, Goood Guy!

Tahnk you again for your kind help!

There are still two things that are unclear for me.
First, you told that I need to register the diagram in the same way as I registered the model and that I need the diagram resource class (like HenshinDiagramResource). What class/interface should this diagram resource extend/implement? In what extension point should I register it in plugin.xml?
Second, do you create your own diagram in a Papyrus Project? What kind of project do you use? I mean, it seems that Papyrus has three types of projects: for UML, SysML and Profile...

Thank you.

Best regards
Mary
Re: A New Diagram Editor integration into the Papyrus environment [message #1018724 is a reply to message #1018670] Thu, 14 March 2013 07:05 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 126
Registered: September 2011
Senior Member
public class HenshinDiagramResource extends AbstractBaseModel{

	
	/**
	 * File extension used for comment.
	 */
	public static final String MODEL_FILE_EXTENSION = "henshin_diagram"; //$NON-NLS-1$

	/**
	 * Model ID.
	 */
	public static final String MODEL_ID = "de.upb.swt.rsdl.ext.HenshinDiagramResource"; //$NON-NLS-1$

	@Override
	public void saveModel() throws IOException {
		if( getResource().getContents().size() <= 0) {
			return;
		}
		
		super.saveModel();
		
		if (!getModelManager().getTransactionalEditingDomain().isReadOnly(resource)
				&& !ModelUtils.resourceFailedOnLoad(resource)) {
			resource.save(HenshinDiagramEditorUtil.getSaveOptions());
		}
		
		HenshinDiagramEditorUtil.setCharset(WorkspaceSynchronizer.getFile(getResource()));
	}

	@Override
	public String getIdentifier() {
		return MODEL_ID;
	}


	@Override
	protected String getModelFileExtension() {
		return MODEL_FILE_EXTENSION;
	}
}


	<extension
		point="org.eclipse.papyrus.infra.core.model">
		<model
			classname="de.upb.swt.rsdl.editor.ext.resource.HenshinDiagramResource">
		</model>
	</extension>


Concerning the category:
As I said, I am not using the CreateModelWizard of Papyrus, but I am using my own wizard that uses its functionality. You should use the "uml" category or create your own category (but the category is not that important). For more information, have a look at org.eclipse.papyrus.uml.diagram.wizards.CreateModelWizard
Re: A New Diagram Editor integration into the Papyrus environment [message #1019177 is a reply to message #1018724] Fri, 15 March 2013 03:23 Go to previous messageGo to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
Thank you so much for your help!
Re: A New Diagram Editor integration into the Papyrus environment [message #1019313 is a reply to message #1018724] Fri, 15 March 2013 08:31 Go to previous messageGo to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
Hello Good Guy!

Thank you so much for your kind help.
I have implemented everything that you told.
Now when I create a diagram from the context menu I get an exception:

org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBoundsException: index=0, size=0
	at org.eclipse.emf.common.util.BasicEList.get(BasicEList.java:346)
	at forIntegration.ViewVisualContractAction.execute(ViewVisualContractAction.java:29)
	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
	at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:76)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:229)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:210)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:131)
	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:171)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:814)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:707)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:691)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:630)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3554)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3179)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1029)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:923)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)



It occurs in ViewVisualContractAction in the following line:
Diagram diagram = (Diagram) myDiagramModel.getResource().getContents().get(0);


because myDiagramModel.getResource().getContents() is empty.
Does it mean that a diagram was not created? What class is responsible for its creation? What should I do in order to create it?

Besr regards
Mary
Re: A New Diagram Editor integration into the Papyrus environment [message #1019390 is a reply to message #1019313] Fri, 15 March 2013 11:30 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 126
Registered: September 2011
Senior Member
	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {

		try {

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

			ModelSet modelSet = ServiceUtilsForActionHandlers.getInstance()
					.getModelSet();

			HenshinDiagramResource henshinDiagramModel = (HenshinDiagramResource) modelSet
					.getModelChecked(HenshinDiagramResource.MODEL_ID);

			// begin new
			if (henshinDiagramModel.getResource().getContents().size() == 0) {

				// get the root model element from the model set
				AbstractBaseModel baseModel = (AbstractBaseModel) modelSet
						.getModelChecked(HenshinResource.MODEL_ID);

				Module module = (Module) baseModel.getResource().getContents()
						.get(0);

				// create new diagram
				Diagram diagram = ViewService.createDiagram(module,
						ModuleEditPart.MODEL_ID,
						HenshinDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
				if (diagram != null) {
					henshinDiagramModel.getResource().getContents()
							.add(diagram);

					diagram.setName("my diagram name");
					diagram.setElement(module);
				}
			}
			// end new
			if (henshinDiagramModel.getResource() != null) {
				Diagram diagram = (Diagram) henshinDiagramModel.getResource()
						.getContents().get(0);

				IPageMngr pageMngr = ServiceUtils.getInstance().getIPageMngr(
						serviceRegistry);

				if (pageMngr.isOpen(diagram)) {
					pageMngr.closePage(diagram);
				}
				pageMngr.openPage(diagram);

			}
		} catch (Exception e) {
		}
		return null;


try this. Replace "Module" with the root element from your model. and moduleeditpart analogously.
Re: A New Diagram Editor integration into the Papyrus environment [message #1020475 is a reply to message #1019390] Mon, 18 March 2013 05:01 Go to previous messageGo to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
Hello!

Thank you again and again!

but i have a new exception now...
java.lang.IllegalStateException: Cannot modify resource set without a write transaction
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.appendNotification(TransactionChangeRecorder.java:302)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.processResourceNotification(TransactionChangeRecorder.java:272)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.notifyChanged(TransactionChangeRecorder.java:238)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
	at org.eclipse.emf.common.notify.impl.NotifyingListImpl.dispatchNotification(NotifyingListImpl.java:261)
	at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUnique(NotifyingListImpl.java:294)
	at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:301)
	at forIntegration.ViewVisualContractAction.execute(ViewVisualContractAction.java:54)
	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
	at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:76)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:229)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:210)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:131)
	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:171)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:814)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:707)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:691)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:630)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3554)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3179)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1029)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:923)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)


It occurs in the following line of execute method:
henshinDiagramModel.getResource().getContents().add(diagram);


It cannod add the created diagram.
Re: A New Diagram Editor integration into the Papyrus environment [message #1021132 is a reply to message #1020475] Tue, 19 March 2013 11:07 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 126
Registered: September 2011
Senior Member
I guess you must add the diagram to the resource within a command.

alternatively you can try this (remove the last change from the action before): add this to your MyDiagramResource:

	private TransformationSystem getHenshinModel(IPath fullPath){

		ResourceSet resourceSet = this.getResourceSet();
		if(resourceSet instanceof DiResourceSetExt){
			HenshinResource henshinResource = (HenshinResource) ((DiResourceSetExt) resourceSet).getModel(HenshinResource.MODEL_ID);
			
			if(henshinResource.getResource() == null){
				fullPath = fullPath.removeFileExtension();
				henshinResource.createModel(fullPath);
				try {
					henshinResource.saveModel();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
			return (TransformationSystem) henshinResource.getResource().getContents().get(0);
		}
		return null;
		

	}
	
	@Override
	public void createModel(IPath fullPath) {


		
		super.createModel(fullPath);
		
		TransformationSystem model = getHenshinModel(fullPath);
		
		Diagram diagram = ViewService.createDiagram(model,
				TransformationSystemEditPart.MODEL_ID,
				HenshinDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
		if (diagram != null) {
			getResource().getContents().add(diagram);
			 
			diagram.setName("some name");
			diagram.setElement(model);
		}
		

	}


Re: A New Diagram Editor integration into the Papyrus environment [message #1021624 is a reply to message #1021132] Wed, 20 March 2013 08:12 Go to previous messageGo to next message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
Hello!!!

Thank you SOOOO much for your help!!!

Now every time I create a Papyrus UML project my own diagram and my own model are created too!!!

But if I try to create one more diagram from the context menu I get an Exception:
!ENTRY org.eclipse.ui 4 0 2013-03-20 12:54:00.054
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError: org/eclipse/papyrus/infra/core/sasheditor/contentprovider/IPageMngr
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:229)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:210)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:131)
	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:171)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:814)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:707)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:691)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:630)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3554)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3179)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1029)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:923)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.NoClassDefFoundError: org/eclipse/papyrus/infra/core/sasheditor/contentprovider/IPageMngr
	at forIntegration.ViewVisualContractAction.execute(ViewVisualContractAction.java:72)
	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
	at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:76)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
	... 34 more
Caused by: java.lang.ClassNotFoundException: org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageMngr
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	... 42 more


It occurs in the following line of ViewVisualContractAction execute() method:
if(pageMngr.isOpen(diagram)){

And the second diagram is not created.

Do you have any idea how this exception can be avoided? What does this exception mean?
Is there any way to create several diagrams in the same project?
Is there any way not to create the diagram every time when a new Papyrus Project is created but only to create it from the context menu? (I use AbstractDynamicModel but not AbstractBaseModel for the diagram and model resources).

Best regards
Mary



Re: A New Diagram Editor integration into the Papyrus environment [message #1022200 is a reply to message #1021624] Thu, 21 March 2013 09:26 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 126
Registered: September 2011
Senior Member
the diagram resource can store a list of diagrams. just use the add(diagram) method to add more diagrams. You will get one file that contains all your diagrams.

if you want to create the diagrams on demand, AbstractDynamicModel is the right choice. Every time you want to update an existing resource you should do it in a command. For this, you need to get the commandstack from the editing domain and execute the command from the stack.

further reading



Re: A New Diagram Editor integration into the Papyrus environment [message #1022798 is a reply to message #1022200] Fri, 22 March 2013 10:45 Go to previous message
Mary P. is currently offline Mary P.
Messages: 42
Registered: November 2012
Member
Thank you SOOOO much!!!!!
Previous Topic:Package Diagrams
Next Topic:Moving profile from old to updated Papyrus/Eclipse
Goto Forum:
  


Current Time: Thu Aug 21 10:19:19 EDT 2014

Powered by FUDForum. Page generated in 0.02769 seconds