@Override
  public void loadProject(String fileName) throws Exception {
    Application application = Application.getInstance();
    ProjectDescriptor projectDescriptor = null;

    // First, check if the user is logged in to teamwork server.
    /*String loggedUserName = TeamworkUtils.getLoggedUserName();
    if(loggedUserName != null){
    	// Ok, the user is logged in. So try to load the project remotely.
    	// load teamwork project
    	projectDescriptor =
    			TeamworkUtils.getRemoteProjectDescriptorByQualifiedName(fileName);
    }*/

    if (projectDescriptor == null) {
      File projectFile = new File(fileName);
      if (!projectFile.exists())
        throw new FileNotFoundException(IGUILabels.TITLE + ": Can't find project file " + fileName);
      String activeProjectFileName = getActiveProjectFileName();
      File activeProjectFile = null;
      if (activeProjectFileName != null) {
        activeProjectFile = new File(activeProjectFileName);
      }
      if (activeProjectFile == null || !(activeProjectFile.equals(projectFile))) {
        projectDescriptor = ProjectDescriptorsFactory.createProjectDescriptor(projectFile.toURI());
      }
    }

    if (projectDescriptor != null) {
      application.getProjectsManager().loadProject(projectDescriptor, true);
    }
  }
  @Override
  public Object getActiveProject() {
    ProjectsManager projectsManager = Application.getInstance().getProjectsManager();
    Project project = projectsManager.getActiveProject();

    return project;
  }
 @Override
 public void saveProject(String fileName) throws Exception {
   ProjectsManager projectsManager = Application.getInstance().getProjectsManager();
   File projectFile = new File(fileName);
   ProjectDescriptor projectDescriptor =
       ProjectDescriptorsFactory.createLocalProjectDescriptor(
           (Project) getActiveProject(), projectFile);
   projectsManager.saveProject(projectDescriptor, true);
 }
Exemple #4
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;
  }
Exemple #5
0
 /**
  * Check whether profile is loaded
  *
  * @throws ModelCenterProfileNotLoaded
  */
 private void checkForProfile() throws ModelCenterProfileNotLoaded {
   if (StereotypesHelper.getProfile(Application.getInstance().getProject(), "ModelCenter") == null)
     throw new ModelCenterProfileNotLoaded();
 }
Exemple #6
0
 /**
  * Returns an object for the element creation factory provided by MagicDraw
  *
  * @return
  */
 private ElementsFactory getElementsFactory() {
   return Application.getInstance().getProject().getElementsFactory();
 }
  /**
   * @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");
    }
  }