Creation/Drawing of an element with pin

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Creation/Drawing of an element with pin

Postby pmuessig » Fri Jan 19, 2007 8:05 am

Hello,

I'm using the following code to create a behavior action in an activity
diagram:

public class EntityAction extends DrawShapeDiagramAction {
public static ModelElementsManager eManager =
ModelElementsManager.getInstance();
public static PresentationElementsManager peManager =
PresentationElementsManager.getInstance();
public static String DRAW_ENTITY_ACTION = "DRAW_ENTITY_ACTION";
public ElementsFactory eFactory;
private Pin inPin;

public EntityAction()
{
super(DRAW_ENTITY_ACTION, "Entity",
KeyStroke.getKeyStroke(KeyEvent.VK_E, 0));

setLargeIcon(ImageLoader.loadIcon("ch/e2e/builder/base/images/builder.logo.small.gif",
true));
}

protected Element createElement() {
Element action = createBehaviorAction();
createPin(action);
return action;
}

protected PresentationElement createPresentationElement() {
eFactory = Application.getInstance().getProject().getElementsFactory();
PresentationElement actionView = super.createPresentationElement();
createPinShape(actionView);
return actionView;
}

private Element createBehaviorAction() {
CallBehaviorAction action = eFactory.createCallBehaviorActionInstance();
action.setName("My Action");
StereotypesHelper.addStereotypeByString(action, "ActionScript");
return action;
}

private void createPin(Element owner) {
inPin = eFactory.createInputPinInstance();
inPin.setName("inPin");
inPin.setOwner(owner);
}

private void createPinShape(PresentationElement shapeElement) {
boolean created = createSession("Create Pin Shape");
try {
peManager.createShapeElement(inPin, shapeElement);
} catch (ReadOnlyElementException e) {
// empty
}
if (created) closeSession();
}

public boolean createSession(String name) {
SessionManager sManager = SessionManager.getInstance();
if (!sManager.isSessionCreated()) {
sManager.createSession(name);
return true;
} else {
return false;
}
}

public void closeSession() {
SessionManager sManager = SessionManager.getInstance();
if (sManager.isSessionCreated()) {
sManager.closeSession();
}
}
}

So far it seems to work quite good. The action and its pin are created
in the UML model. The action's presentation element is drawn in the
diagram. Unfortunately the pin's presentation element isn't drawn.
When I remove the line "inPin.setOwner(owner)" in the method
"createPin()" the pin's presentation element is drawn, but the pin isn't
created in the model.
Is there a way to have both things?

Regards,
Peter
pmuessig
 
Posts Rating:

Re: Creation/Drawing of an element with pin

Postby Martynas Lelevicius » Tue Jan 23, 2007 1:17 am

Hello Peter,

Unfortunately it is not possible to draw action and pin with current OpenAPI.

Pin symbol creation when owner is not set for pin is a trashy effect.

Sorry for the inconveniences.
Regards,
--
Martynas Lelevicius
Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
E-mail : marte
WWW: http://www.magicdraw.com

Martynas Lelevicius
 
Posts Rating:


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests