@GET
  @Path("creator")
  @Produces(MediaType.TEXT_HTML)
  public void createHtmlPart(@PathParam("projectId") final String projectId)
      throws URISyntaxException, IOException {

    MagicDrawManager.loadSysMLProjects();

    List<String> possibleBlocks = new ArrayList<String>();
    possibleBlocks.add("NONE");
    for (com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class mdBlock :
        MagicDrawManager.mdSysmlBlocks) {
      possibleBlocks.add("BLOCK___" + mdBlock.getQualifiedName());
    }

    EClass eClass = ServiceUtil.getEClass("PartProperty");

    httpServletRequest.setAttribute(
        "creatorUri", MagicDrawManager.baseHTTPURI + "/services/" + projectId + "/partproperties");
    httpServletRequest.setAttribute("eclass", eClass);
    httpServletRequest.setAttribute("possibleBlocks", possibleBlocks);

    RequestDispatcher rd =
        httpServletRequest.getRequestDispatcher("/sysml/sysml_partproperty_creator.jsp");
    try {
      rd.forward(httpServletRequest, httpServletResponse);
    } catch (Exception e) {
      e.printStackTrace();
      throw new WebApplicationException(e);
    }
  }
Esempio n. 2
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;
  }
  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");
    }
  }