Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Composite Diagram -default Apply Profile (Palete customization tutorial, add default profile for the new diagrams )
Composite Diagram -default Apply Profile [message #631948] Sun, 10 October 2010 23:59 Go to next message
Andres  is currently offline Andres Friend
Messages: 57
Registered: July 2010
Member
Hello, I write again...

I make a profile (file xxx.profile.uml), i customize the palette for the composite structure diagram for my profile, and make my own plugin like the tutorial palette customization using org.eclipse.papyrus.composite sources.

This work fine, but when i created a new composite diagram and add my elements to the canvas my elements are show without the stereotypes.
i need always first add my profile in the profile tab of diagram.(apply profile), and before my stereotypes are show when i add a new element on the canvas.

Is there any method than i can use to set a default apply profile for my diagrams plugin?
....

what class of the sources ,or extension points i should modify to do this?...



Andres
Re: Composite Diagram -default Apply Profile [message #634007 is a reply to message #631948] Wed, 20 October 2010 09:13 Go to previous messageGo to next message
Remi Schnekenburger is currently offline Remi SchnekenburgerFriend
Messages: 169
Registered: July 2009
Location: Palaiseau, France
Senior Member
Hi Andres,

Perhaps you could try to create a new kind of post action for the elements in the palette, which could apply the profile to the root package of the nearest one if required before adding the stereotype.

All post actions are defined in the oep.diagram.common plugin. All the code is located in the org.eclipse.papyrus.diagram.common.service.palette package, and there are some extension points to add also.

Regards,
Rémi


Remi Schnekenburger

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: Composite Diagram -default Apply Profile [message #641874 is a reply to message #634007] Mon, 29 November 2010 03:05 Go to previous messageGo to next message
Andres  is currently offline Andres Friend
Messages: 57
Registered: July 2010
Member
Hi again=), i continue tryng do this without success..
how can i get the root package? what is the meanning of root package of the nearest one?...


i do this, in the constructor of the COnfiguration class (oep.common.service.palette), adding a new parameter editPart, i pass it from the run method of StereotypePostAction CLASS.

i try to load my file with my profile from a profile.uml file:

ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
URI fileURI = URI.createFileURI(new File("c:/SoaML.profile.uml").getAbsolutePath());
Resource resource = resourceSet.getResource(fileURI, true);

//
SoaML = (Profile) EcoreUtil.getObjectByType(
resource.getContents(), UMLPackage.Literals.PROFILE);



final EObject objectToEdit = ((View)editPart.getModel()).getElement();
¿this is the correct way to obtain the root package?

then i instance the PackageUtil class from oep.umlutils

and invoke method
applyProfile(((org.eclipse.uml2.uml.Package)packageContainer ), SoaML, false);

This code not work, you can oriented me about the correct steps to do this?

Thanks


Re: Composite Diagram -default Apply Profile [message #642225 is a reply to message #641874] Tue, 30 November 2010 13:18 Go to previous messageGo to next message
Remi Schnekenburger is currently offline Remi SchnekenburgerFriend
Messages: 169
Registered: July 2009
Location: Palaiseau, France
Senior Member
Hi Andres,

T have common terms:
- the root package is the main element of your model. Usually, in Papyrus, this is the model, the first element you see in the model explorer. This is the place where profiles are usually applied, as the packages see all profiles applied on them and their container packages. If you apply a profile on the root package, you will have access to the profile every where in your model.
- the nearest package is a utility method provided by UML2 project. It is based on the containement feature. When you follow the containement feature, you will get the first package which contains your element.
Imagine this model:
Model1
+ Package 1
+ Package 2
+ + Package 21
+ + Class 211
+ + + Property 2111
+ + Package 22

Root Package : Model 1
Nearest package for Property 2111: Package 21
Nearest package for Class 211: Package 21
Nearest package for Package 21: Package 21

To retrieve the root package, on which you should apply your profile, you can use the org.eclipse.papyrus.umlutils.PackageUtil#getRootPackage(Elem ent) method. when you get your Element using
Quote:
final EObject objectToEdit = ((View)editPart.getModel()).getElement();

: Try to cast the objectToEdit in a UML Element. If it is possible, you should retrieve the root package using the getRootPackage method. On this root package, apply your profile.

HTH,
Rémi


Remi Schnekenburger

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: Composite Diagram -default Apply Profile [message #643152 is a reply to message #642225] Sun, 05 December 2010 12:50 Go to previous messageGo to next message
Andres  is currently offline Andres Friend
Messages: 57
Registered: July 2010
Member
Thanks again=), i did this but i have the follow error :

java.lang.IllegalStateException: Cannot modify resource set without a write transaction
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ssertWriting(TransactionChangeRecorder.java:348)
...
...
...


I take the EditPart object from run method on StereotypePostAction class, and pass it to Configuration class (both in oep.diagram.common.service.palette package).

Is possible that the error was for the ResultSet when i load my *.profile.uml file?

To load my file , now I m using:
TransactionalEditingDomain domain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDom ain();
ResourceSet rset = domain.getResourceSet();
Resource resource2 = rset.getResource(URI.createFileURI("c:/SoaML.profile.uml"), true);
domain.loadResource("c:/SoaML.profile.uml");

before i used :

ResourceSet resourceSet = new ResourceSetImpl();
URI fileURI = URI.createFileURI(new File("c:/SoaML.profile.uml")
.getAbsolutePath());
resourceSet
.getResourceFactoryRegistry()
.getExtensionToFactoryMap()
.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());
Resource resource = resourceSet.getResource(fileURI, true);

but i had the same problem....



After download the file my code is:

SoaML = (Profile) EcoreUtil.getObjectByType(resource2.getContents(),
UMLPackage.Literals.PROFILE);
final EObject objectToEdit = ((View) edit.getModel())
.getElement();
org.eclipse.uml2.uml.Element packageContainerTmp = ((org.eclipse.uml2.uml.Element) objectToEdit);
do {
packageContainerTmp = packageContainerTmp.getOwner();
} while (!(packageContainerTmp instanceof org.eclipse.uml2.uml.Package));

PackageUtil.getRootPackage(packageContainerTmp).applyProfile (
SoaML);


Andrés
Re: Composite Diagram -default Apply Profile [message #643249 is a reply to message #643152] Mon, 06 December 2010 09:40 Go to previous messageGo to next message
Remi Schnekenburger is currently offline Remi SchnekenburgerFriend
Messages: 169
Registered: July 2009
Location: Palaiseau, France
Senior Member
Hi Andres,

to modify the model, you need to open a transaction. Papyrus is based on the EMFT transaction project, which means that all modifications on the model are based on transaction. This ensure a better stability for the tool, as a command that is not a succes will be undone and the tool will get in the previous stable state.

To open a write transaction, you can use this code snippet: (with command being a subclass of an AbstractTransactionnalCommand)
if(command.canExecute() && !(TransactionUtil.isReadTransactionInProgress(editingDomain, true, true))) {
	try {
		OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
			} catch (ExecutionException e) {
				log.error(e);
			}
		}


HTH,
Rémi


Remi Schnekenburger

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: Composite Diagram -default Apply Profile [message #645590 is a reply to message #643249] Sat, 18 December 2010 12:36 Go to previous message
Andres  is currently offline Andres Friend
Messages: 57
Registered: July 2010
Member
The solution=) :

I make my own common plugin (is the same that original common, with a new category and some added code)

And in the package oep.diagram.common.commands
in the class CreateUMLModelCommand, in the method initializeModel
i add this code at the end:

Profile myprofile = (Profile)PackageUtil.loadPackage(URI.createURI(" platform:/plugin/org.eclipse.papyrus.diagram.mydiagram/profi le/myprofile.profile.uml "), owner.eResource().getResourceSet());
if(myprofile != null) {
EList<Profile> ls=((org.eclipse.uml2.uml.Package)owner).getAllAppliedProfil es();
if(!ls.contains(myprofile))
PackageUtil.applyProfile(((org.eclipse.uml2.uml.Package)owne r), myprofile, true);

}


thanks for the help.

Andrés
Previous Topic:BUGs - External References .uml files
Next Topic:Association problems.
Goto Forum:
  


Current Time: Thu Apr 25 06:16:05 GMT 2024

Powered by FUDForum. Page generated in 0.03300 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top