@Override public Collection<? extends Object> getModelElementsByStereotype(String stereotypeName) { Project magicDrawProject = (Project) getActiveProject(); // find stereotype Stereotype stereotype = StereotypesHelper.getStereotype(magicDrawProject, stereotypeName); List<Element> stereotypedElements = StereotypesHelper.getExtendedElements(stereotype); return stereotypedElements; }
/** * Create an input variable * * @param name * @return * @throws ModelCenterProfileNotLoaded */ public Port createInputVariable(String name) throws ModelCenterProfileNotLoaded { // First, create a new variable Port newPort = createVariable(name); // Now set the stereotype property "Is Input" to true Stereotype variableStereotype = StereotypesHelper.getStereotype( Application.getInstance().getProject(), "ModelCenterVariable"); StereotypesHelper.setStereotypePropertyValue(newPort, variableStereotype, "isInput", true); return newPort; }
public void addDiagramTable(Tree tree, NamedElement father, Element after) { ElementsFactory factory = null; if (!SessionManager.getInstance().isSessionCreated()) { SessionManager.getInstance().createSession("MBSE-doc"); factory = Application.getInstance().getProject().getElementsFactory(); ArrayList<Class<?>> select = new ArrayList<Class<?>>(); select.add(com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Diagram.class); ArrayList<Class<?>> display = new ArrayList<Class<?>>(); display.add(com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Package.class); display.add(com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class.class); display.add(com.nomagic.uml2.ext.magicdraw.mdprofiles.Profile.class); ArrayList<Class<?>> create = new ArrayList<Class<?>>(); ArrayList<Class<?>> restricted = new ArrayList<Class<?>>(); SelectElementTypes seTypes = new SelectElementTypes(display, select, create, restricted); // Martynas says: ElementSelectionDlg is preferred SelectElementInfo sei = new SelectElementInfo( true, true, Application.getInstance().getProject().getModel(), true); ElementSelectionDlg dlg = ElementSelectionDlgFactory.create(MDDialogParentProvider.getProvider().getDialogParent()); ElementSelectionDlgFactory.initSingle( dlg, seTypes, sei, Application.getInstance().getProject().getModel()); dlg.show(); if (dlg.getResult() == com.nomagic.ui.DialogConstants.OK && dlg.getSelectedElement() != null) { BaseElement be = dlg.getSelectedElement(); com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class theTable = factory.createClassInstance(); StereotypesHelper.addStereotype(theTable, ut.getTheTableDiagramStereotype()); try { ModelElementsManager.getInstance().addElement(theTable, father); } catch (ReadOnlyElementException roee) { Utilities.displayWarning("Read only element"); } // add hyperlink to selected model element final Stereotype hyperlinkOwnerStereotype = StereotypesHelper.getStereotype( Application.getInstance().getProject(), "HyperlinkOwner"); StereotypesHelper.addStereotype(theTable, hyperlinkOwnerStereotype); StereotypesHelper.setStereotypePropertyValue( theTable, hyperlinkOwnerStereotype, "hyperlinkModel", be, true); StereotypesHelper.setStereotypePropertyValue( theTable, hyperlinkOwnerStereotype, "hyperlinkModelActive", be, false); if (StereotypesHelper.hasStereotypeOrDerived(father, "section")) { StereotypesHelper.setStereotypePropertyValue( father, ut.getTheSectionStereotype(), "blockelements", theTable, true); } else if (StereotypesHelper.hasStereotypeOrDerived(father, "chapter")) { StereotypesHelper.setStereotypePropertyValue( father, ut.getTheChapterStereotype(), "blockelements", theTable, true); } // set tag to selected diagram StereotypesHelper.setStereotypePropertyValue( theTable, ut.getTheTableDiagramStereotype(), "diagramTable", be, true); // set tag with caption text StereotypesHelper.setStereotypePropertyValue( theTable, ut.getTheTableDiagramStereotype(), "captionText", be.getHumanName(), true); theTable.setName(be.getHumanName()); tree.openNode(theTable, true, true); MBSEShowEditPanelAction.updateEditorView(father, theTable, "tableDiagram"); } else { System.out.println("User cancelled Diagram selection"); } SessionManager.getInstance().closeSession(); } else { Utilities.displayWarning("could not create session manager"); } }