/**
   * @param filename
   * @param suggestedName
   * @throws ModelCenterException
   */
  private void initializeNewModelCenterFile(String filename, String suggestedName)
      throws ModelCenterException {
    // Create new ModelCenter model
    ModelCenterPlugin.getModelCenterInstance().newModel();
    ModelCenterPlugin.getModelCenterInstance().getModel().rename(suggestedName);

    // Save the newly created model
    ModelCenterPlugin.getModelCenterInstance().saveModelAs(filename);
  }
  /**
   * @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();
    }
  }