Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » How to create a classDiagram which which defines an Instance Specification?(How to create a classDiagram which which defines an Instance Specification?)
How to create a classDiagram which which defines an Instance Specification? [message #1017322] Mon, 11 March 2013 11:20 Go to next message
sabrina ing is currently offline sabrina ing
Messages: 39
Registered: February 2013
Member
Hi,


I am working with the commands and Handlers in eclipse.
I want to know how to create a classDiagram which contains an "InstanceSpecification" named for example "Task" and it has a classifier.

I'd appreciate any help on this.
Thanks in advance,


Re: How to create a classDiagram which which defines an Instance Specification? [message #1017340 is a reply to message #1017322] Mon, 11 March 2013 12:07 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 124
Registered: September 2011
Senior Member
Quote:
I am working with the commands and Handlers in eclipse.
what do you mean?



These are the steps to create an instance specification:
* create a class diagram
* add a class with the tool from the palette
* add an instance specification with the tool from the palette
* select the instance spec. and go to the properties view
* in uml tab, go to the classifier section, click the "+" sign and add the class you just created

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

Report message to a moderator

Re: How to create a classDiagram which which defines an Instance Specification? [message #1017383 is a reply to message #1017340] Mon, 11 March 2013 14:04 Go to previous messageGo to next message
sabrina ing is currently offline sabrina ing
Messages: 39
Registered: February 2013
Member
Hi,

Thanks for your reply.


I'm doing a project using the Plug-in papyrus Marte in eclipse, I add a popup menu
named "named import platform" using commands and Handlers in the view
of the Model Explorer when creating a papyrus Model.
My goal is when I click on the command which defined by the popup menu, a ClassDiagram will be created and it contains the "Instance Specification" which I have implemented.
I used this method
protected Diagram createDiagram(Resource diagramResource, EObject owner, String name) {

  Diagram diagram=null;
			
  if(owner instanceof org.eclipse.uml2.uml.Package) {

	Package pkg=(Package) ((Package) (owner)).getPackagedElement("UMLPackage.eINSTANCE.getPackage());
					
	Class sharedResource = (Class((Package)owner).createOwnedClass("sharedResource", false);
			Property attribute = sharedResource.createOwnedAttribute(
	                "newAttribute", null, UMLPackage.Literals.PROPERTY);
			
				diagram = ViewService.createDiagram(owner, getDiagramNotationID(), getPreferenceHint());

	
				diagram.setName(name);

				//diagram.setElement();

				diagramResource.getContents().add(diagram);
			}
		
			return diagram;	
		}

		@Override

	protected String getDiagramNotationID() {

		return ModelEditPart.MODEL_ID;

	}

	@Override

	protected PreferencesHint getPreferenceHint() {

		return UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT;

	}

	@Override

	protected String getDefaultDiagramName() {

		return super.openDiagramNameDialog("specific model diagram"); 

	}

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		return super.execute(event);
	}

}


But this method will create a class Diagram which contains Class not Instance Specification.

Can you help me please.
Re: How to create a classDiagram which which defines an Instance Specification? [message #1017408 is a reply to message #1017383] Mon, 11 March 2013 15:17 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 124
Registered: September 2011
Senior Member
can you concretize your problem? do you mean in the newly created class diagram there is no palette tool for instance specifications? or do you want to create instance specifications (and graphical representations for them) automatically when the new diagram is created?
Re: How to create a classDiagram which which defines an Instance Specification? [message #1017410 is a reply to message #1017408] Mon, 11 March 2013 15:23 Go to previous messageGo to next message
sabrina ing is currently offline sabrina ing
Messages: 39
Registered: February 2013
Member
Hi,

Yes, I want to create instance specifications (and graphical representations for them)in the view of the new Class Diagram automatically when the new diagram is created.

Re: How to create a classDiagram which which defines an Instance Specification? [message #1017423 is a reply to message #1017410] Mon, 11 March 2013 15:56 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 124
Registered: September 2011
Senior Member
try this in your handler (I have not tested it):

		ServicesRegistry serviceRegistry = ServiceUtilsForActionHandlers
				.getInstance().getServiceRegistry();
TransactionalEditingDomain ed = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
			
			RecordingCommand c = new RecordingCommand(ed) {
				
				@Override
				protected void doExecute() {
					
					Model model =// get a reference of the root element of the uml model
					
					InstanceSpecification spec = UMLFactory.eINSTANCE.createInstanceSpecification();
					org.eclipse.uml2.uml.Class type = UMLFactory.eINSTANCE.createClass();
					spec.getClassifiers().add(type);
					model.getPackagedElements().add(type);
					model.getPackagedElements().add(spec);
					
					
				}
			};
			
			ed.getCommandStack().execute(c);


In general, this only creates the model element. But if you're lucky the graphical representations in the diagram are also created for free.

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

Report message to a moderator

Re: How to create a classDiagram which which defines an Instance Specification? [message #1017434 is a reply to message #1017423] Mon, 11 March 2013 16:30 Go to previous messageGo to next message
sabrina ing is currently offline sabrina ing
Messages: 39
Registered: February 2013
Member
Hi,

How can I get a reference of the root element of the uml model to initialize the variable model ?
Can you give me an example please.

Re: How to create a classDiagram which which defines an Instance Specification? [message #1017469 is a reply to message #1017434] Mon, 11 March 2013 18:12 Go to previous messageGo to next message
Goood Guy is currently offline Goood Guy
Messages: 124
Registered: September 2011
Senior Member
I guess you can use the variable "owner" instead (Model inherits from Package)
Re: How to create a classDiagram which which defines an Instance Specification? [message #1017483 is a reply to message #1017469] Mon, 11 March 2013 18:58 Go to previous message
sabrina ing is currently offline sabrina ing
Messages: 39
Registered: February 2013
Member
Hi,


I'm very grateful for your help.
It works now Smile
Previous Topic:Sequence Diagram - Dental Clinic Management System
Next Topic:Get loaded resource from element
Goto Forum:
  


Current Time: Fri Apr 18 10:20:29 EDT 2014

Powered by FUDForum. Page generated in 0.02175 seconds