Ejemplo n.º 1
0
  /**
   * Create a generic variable
   *
   * @param name
   * @throws ModelCenterProfileNotLoaded
   * @return
   */
  public Port createVariable(String name) throws ModelCenterProfileNotLoaded {
    // Check whether profile is loaded
    checkForProfile();

    // Create a new class and set its name
    Port newVariable = getElementsFactory().createPortInstance();

    // Set name if specified
    if (!name.equals("")) newVariable.setName(name);

    // Add the corresponding stereotypes
    StereotypesHelper.addStereotypeByString(newVariable, "ModelCenterVariable");
    StereotypesHelper.addStereotypeByString(
        newVariable,
        "ConstraintParameter"); // Unfortunately this is necessary, even though the stereotype
                                // ModelCenterVariable is a generalization of ConstraintParameter

    // Check whether stereotype was applied
    if (!StereotypesHelper.getStereotypes(newVariable)
        .get(0)
        .getName()
        .equals("ModelCenterVariable")) throw new ModelCenterProfileNotLoaded();

    return newVariable;
  }
Ejemplo n.º 2
0
  /**
   * 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;
  }
  @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;
  }
Ejemplo n.º 4
0
  /**
   * Create a script
   *
   * @param name
   * @return
   * @throws ModelCenterProfileNotLoaded
   */
  public Constraint createScript(String name) throws ModelCenterProfileNotLoaded {
    // Check whether profile is loaded
    checkForProfile();

    // Create a new class and set its name
    Constraint newScript = getElementsFactory().createConstraintInstance();

    // Set name if specified
    if (!name.equals("")) newScript.setName(name);

    // Add the corresponding stereotypes
    StereotypesHelper.addStereotypeByString(newScript, "ModelCenterScript");

    // Check whether stereotype was applied
    if (!StereotypesHelper.getStereotypes(newScript).get(0).getName().equals("ModelCenterScript"))
      throw new ModelCenterProfileNotLoaded();

    return newScript;
  }
  @Override
  public boolean modelElementHasStereotype(Object modelElement, String stereotypeName) {
    if (!(modelElement instanceof Element)) {
      throw new RuntimeException(
          IGUILabels.TITLE
              + ": ERROR: can't get stereotype of model element "
              + modelElement.toString());
    }
    Element element = (Element) modelElement;

    boolean hasStereotype = StereotypesHelper.hasStereotype(element, stereotypeName);
    return hasStereotype;
  }
Ejemplo n.º 6
0
  /**
   * Create a ModelCenter root model of type "data model"
   *
   * @param name
   * @throws ModelCenterProfileNotLoaded
   * @return
   */
  public Class createDataModel(String name) throws ModelCenterProfileNotLoaded {
    // Check whether profile is loaded
    checkForProfile();

    // Create a new class and set its name
    Class newDataModel = getElementsFactory().createClassInstance();

    // Set name if specified
    if (!name.equals("")) newDataModel.setName(name);

    // Add the corresponding stereotypes
    StereotypesHelper.addStereotypeByString(newDataModel, "ModelCenterDataModel");

    return newDataModel;
  }
Ejemplo n.º 7
0
 /**
  * Check whether profile is loaded
  *
  * @throws ModelCenterProfileNotLoaded
  */
 private void checkForProfile() throws ModelCenterProfileNotLoaded {
   if (StereotypesHelper.getProfile(Application.getInstance().getProject(), "ModelCenter") == null)
     throw new ModelCenterProfileNotLoaded();
 }
  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");
    }
  }