Ejemplo n.º 1
0
 public void actionPerformed(ActionEvent e) {
   // Launch ModelCenter with the filename provided
   try {
     openModelInModelCenter();
   } catch (ElementIsNotAModelCenterModel e1) {
     // Do nothing - this should not happen anyway
   } catch (UserCanceledOperation e1) {
     // Do nothing - user simply canceled when creating a new file
   } catch (ModelCenterException e1) {
     JOptionPane.showMessageDialog(
         MDDialogParentProvider.getProvider().getDialogParent(),
         "Error communicating with ModelCenter",
         "ModelCenter Plugin - Critical Error",
         JOptionPane.ERROR_MESSAGE);
   } catch (FailedToLaunchModelCenter e1) {
     JOptionPane.showMessageDialog(
         MDDialogParentProvider.getProvider().getDialogParent(),
         "Failed to launch ModelCenter - please ensure that ModelCenter is installed",
         "ModelCenter Plugin",
         JOptionPane.WARNING_MESSAGE);
   } catch (ModelCenterProfileNotLoaded e1) {
     JOptionPane.showMessageDialog(
         MDDialogParentProvider.getProvider().getDialogParent(),
         "The ModelCenter profile no longer seems to be loaded - failed to synchronize changes\nfrom ModelCenter model. Load the profile and synchronize manually",
         "ModelCenter Plugin - Critical Error",
         JOptionPane.ERROR_MESSAGE);
   }
 }
Ejemplo n.º 2
0
  /**
   * @throws ElementIsNotAModelCenterModel
   * @throws UserCanceledOperation
   * @throws ModelCenterException
   * @throws FailedToLaunchModelCenter
   * @throws ModelCenterProfileNotLoaded
   */
  private void openModelInModelCenter()
      throws ElementIsNotAModelCenterModel, UserCanceledOperation, ModelCenterException,
          FailedToLaunchModelCenter, ModelCenterProfileNotLoaded {
    // Get the selected element
    Node modelNode = (Node) getTree().getSelectedNode();
    Element model = (Element) modelNode.getUserObject();

    // Check whether it truly is a model center data model
    if (ModelCenterPlugin.getMDModelHandlerInstance().isModelCenterDataModel(model)) {
      // Check whether element selected has a filename specified
      String filename =
          ModelCenterPlugin.getMDModelHandlerInstance().getModelCenterDataModelFilename(model);

      if (filename.equals("")) {
        // If not, either ask user or default to a name (in which case you have to check whether
        // file exists)
        filename = createNewModelCenterFile(((Class) model).getName());

        ModelCenterPlugin.ensureMDSessionIsActive();

        ModelCenterPlugin.getMDModelHandlerInstance()
            .setModelCenterDataModelFilename(model, filename);

        ModelCenterPlugin.closeMDSession();
      } else {
        // Check to see whether ModelCenter file exists on file system
        File mcFile = new File(filename);

        if (!mcFile.exists()) initializeNewModelCenterFile(filename, ((Class) model).getName());
      }

      // Load model
      try {
        ModelCenterPlugin.getModelCenterInstance().loadModel(filename);
      } catch (ModelCenterException e) {
        e.printStackTrace();

        JOptionPane.showMessageDialog(
            MDDialogParentProvider.getProvider().getDialogParent(),
            "Failed to open associated ModelCenter model at specified filename",
            "ModelCenter Plugin",
            JOptionPane.ERROR_MESSAGE);

        Application.getInstance().getGUILog().log(e.getMessage());

        throw new UserCanceledOperation();
      }

      // Synchronize model
      ModelCenterPlugin.getSynchronizationEngineInstance()
          .updateModelCenterModelFromSysMLModel(model);

      // Save any changes made to the model
      ModelCenterPlugin.getModelCenterInstance().saveModel();

      // Launch ModelCenter with new file as argument
      // Note that MagicDraw will "hand" for as long as the user is updating the model - not sure
      // whether this is good!
      ModelCenterPlugin.getSynchronizationEngineInstance().launchModelCenter(filename);

      // Reload model internally to see changes
      ModelCenterPlugin.getModelCenterInstance().loadModel(filename);

      // Synchronize changes made in model with SysML model
      ModelCenterPlugin.getSynchronizationEngineInstance()
          .updateSysMLModelFromModelCenterModel(modelNode);
    } else {
      throw new ElementIsNotAModelCenterModel();
    }
  }
  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");
    }
  }