Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » How to create new attribute in current class diagram programmatically
How to create new attribute in current class diagram programmatically [message #1602068] Thu, 05 February 2015 09:53
Emilio Dolce is currently offline Emilio DolceFriend
Messages: 10
Registered: November 2014
Junior Member
Hi,
I'm trying to create a set of attribute class from an handler command.
I'm able to create semantics attributes in the selected class but not in the current class diagram editor.

The code is:
		/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.gmf.runtime.emf.commands.core.command.
		 * AbstractTransactionalCommand
		 * #doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor ,
		 * org.eclipse.core.runtime.IAdaptable)
		 */
		@Override
		protected void doExecute() {
			if (context instanceof Class) {
				// IMultiDiagramEditor multiDiagramEditor =
				// EditorUtils.getMultiDiagramEditor();
				// if (multiDiagramEditor != null) {
				// IEditorPart activeEditor =
				// multiDiagramEditor.getActiveEditor();
				// if (activeEditor instanceof DiagramEditor) {
				// DiagramEditor diagramEditor = (DiagramEditor) activeEditor;
				// diagramEditor.getDiagramEditDomain()
				// Diagram
				// DiagramEditPartsUtil.getEObjectViews(context)
				// DiagramEditPart topEditPart =
				// diagramEditor.getDiagramEditPart();
				// if (topEditPart != null) {
				// DiagramHelper.refresh(topEditPart, true);
				// }
				// }
				// }
			}

			Class createUserType = (Class) context.getModel().getMember(
					"Create User");
			Class createTimeType = (Class) context.getModel().getMember(
					"Create Timestamp");
			Class lastUpdateUserType = (Class) context.getModel().getMember(
					"Last Update User");
			Class lastUpdateTimeType = (Class) context.getModel().getMember(
					"Last Update Timestamp");
			Property p = context.createOwnedAttribute("createUser",
					createUserType);
			Stereotype attributeStereotype = p
					.getApplicableStereotype("MiceGenProfile::Attribute");
			p.applyStereotype(attributeStereotype);
			context.createOwnedAttribute("createTimestamp", createTimeType)
					.applyStereotype(attributeStereotype);
			context.createOwnedAttribute("lastUpdateUser", lastUpdateUserType)
					.applyStereotype(attributeStereotype);
			context.createOwnedAttribute("lastUpdateTimestamp",
					lastUpdateTimeType).applyStereotype(attributeStereotype);
			
			org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil.getEObjectViews(context);
		}


How to add those just created attributes in the class attributes compartment?
Thanks in advance.
Previous Topic:DelegatingUndoContext exception
Next Topic:Cannot create connectors
Goto Forum:
  


Current Time: Fri Jul 10 14:00:08 GMT 2020

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

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

Back to the top