/**
   * This method will check the action's name and type value.
   *
   * @param action the action instance to be checked.
   * @param name the name of action.
   * @param type the type of action.
   * @throws Exception if any exception occurs when testing.
   */
  private void checkCreateDiagramAction(CreateDiagramAction action, String name, String type)
      throws Exception {
    // check the attributes here.
    assertNotNull("The CreateDiagramAction constructor is incorrect.", action);

    // add the diagram into UMLModelManager.
    action.execute();

    // check the diagram here.
    Diagram diagram = UMLModelManager.getInstance().getDiagrams().get(0);
    assertEquals("The CreateDiagramAction constructor is incorrect.", diagram.getName(), name);

    Uml1SemanticModelBridge modelBridge = (Uml1SemanticModelBridge) diagram.getOwner();
    assertEquals(
        "The CreateDiagramAction constructor is incorrect.", modelBridge.getElement(), owner);
    /*
     * BugFix: UML-9507
     */
    //        assertEquals("The CreateDiagramAction constructor is incorrect.",
    //            StressTestHelper.findTypePropertyValue(diagram), type);
    assertEquals(
        "The CreateDiagramAction constructor is incorrect.",
        StressTestHelper.getTypeInfo(diagram),
        type);

    // remove the diagram from UMLModelManager.
    action.undo();
  }
 /**
  * Validate that the ActivityDiagram and the ActivityGraph are added to the UMLModelManager
  * instance.
  */
 private void validateActivityDiagram() {
   ActivityGraph activityGraph = UML_MODEL_MANAGER.getActivityGraphs().get(0);
   assertNotNull("The ActivityGraph should not be null.", activityGraph);
   Diagram diagram = UML_MODEL_MANAGER.getDiagrams().get(0);
   assertNotNull("The diagram should not be null.", diagram);
   // check the owner
   Uml1SemanticModelBridge modelBridge = (Uml1SemanticModelBridge) diagram.getOwner();
   assertNotNull("The Uml1SemanticModelBridge should not be null.", modelBridge);
   assertSame("The owner is incorrect.", activityGraph, modelBridge.getElement());
 }
 /**
  * Tests constructor for 'RemoveClassDiagramAction(Diagram)' for accuracy.
  *
  * <p>Verify that RemoveClassDiagramAction(Diagram) is correct and the instance should not be
  * null.
  */
 public void testRemoveClassDiagramAction() {
   assertNotNull("The RemoveClassDiagramAction instance should not be null.", action);
   assertEquals(
       "The presentation name is incorrect.",
       "Remove diagram " + diagram.getName(),
       action.getPresentationName());
 }
 /**
  * The documenttreenode's name is changed. Updates the element and panels.
  *
  * @param event the NameChangedEvent
  * @throws IllegalArgumentException if event is null
  */
 public void treeNodeNameChanged(NameChangedEvent event) {
   DeployHelper.checkNotNull(event, "event");
   DocumentTreeNode treeNode = event.getTreeNode();
   DocumentTreeNodeType nodeType = treeNode.getType();
   Object object = treeNode.getNodeObject();
   List<JComponent> jComponents = new ArrayList<JComponent>();
   ModelElement modelElement = null;
   if (nodeType == DocumentTreeNodeType.MODEL_ELEMENT) {
     // when the changed node is a model element.
     modelElement = (ModelElement) object;
     if (modelElement instanceof AssociationEnd) {
       jComponents =
           DeployHelper.getComponent(((AssociationEnd) modelElement).getAssociation(), mainFrame);
     } else {
       jComponents = DeployHelper.getComponent(modelElement, mainFrame);
     }
   } else if (nodeType == DocumentTreeNodeType.GRAPH_ELEMENT) {
     if (object instanceof Diagram) {
       // when the changed node is a diagram.
       ((Diagram) object).setName(event.getNewName());
       /*
        * BugFix: BUGR-65 Sorting diagrams
        */
       mainFrame.getDocumentTree().updateTree();
       mainFrame.getDiagramViewer().openDiagramView((Diagram) object);
       mainFrame
           .getDocumentTree()
           .getCurrentPanel()
           .getCurrentView()
           .setSelectedTreeNodes(new DocumentTreeNode[] {treeNode});
     } else {
       // When the changed node is a graph element.
       modelElement = DeployHelper.getElement((GraphElement) object);
       jComponents.add(DeployHelper.getComponent((GraphElement) object, mainFrame));
     }
   } else {
     mainFrame.getDocumentTree().getCurrentPanel().getCurrentView().updateTreeNode(treeNode);
   }
   if (modelElement != null) {
     if (modelElement instanceof ClassImpl) {
       DeployHelper.changeConstructors(
           mainFrame, (ClassImpl) modelElement, event.getNewName(), jComponents);
     } else {
       ChangeEntityNameAction changeEntityNameAction =
           new ChangeEntityNameAction(
               modelElement, event.getNewName(), mainFrame.isAutoGenerateMethods());
       mainFrame.handleActionEvent(changeEntityNameAction, jComponents, "change name");
     }
   }
 }
 /**
  * Sets up environment.
  *
  * @throws Exception to Junit
  */
 public void setUp() throws Exception {
   super.setUp();
   diagram = new Diagram();
   diagram.setName("Class Diagram");
   action = new RemoveClassDiagramAction(diagram);
 }
  public void exportAllImages(String extension, String filePath, boolean showProcess) {

    /*
     * BUGR-108: The aim is to export all the diagrams (along with the
     * hidden ones) and preview them in a separate JFrame, that will have
     * JLabels describing the current action.
     *
     * To fix that, I will create a JFrame and have its contentPane as a
     * JPanel that will have 2 JLabels, 1 JProgressBar and the
     * DiagramViewer. Then, create all the diagrams inside the DiagramViewer
     * as tabs. Next, export each diagram in it and update the JPanel's
     * JLabels and JProgressBar. Finally close the frame.
     */
    UMLModelManager modelManager = UMLModelManager.getInstance();

    JFrame exportingFrame = null;
    JProgressBar bar = null;
    JPanel panel = null;
    JLabel export_num = null;
    JLabel export_name = null;

    exportingFrame = new JFrame("Exporting All Diagrams");
    if (showProcess) {
      exportingFrame.setBounds(100, 100, 500, 500);
      exportingFrame.setAlwaysOnTop(true);
    } else {
      exportingFrame.setBounds(0, 0, 0, 0);
      exportingFrame.setUndecorated(true);
      exportingFrame.setAlwaysOnTop(false);
    }

    exportingFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    exportingFrame.setResizable(false);
    exportingFrame.setEnabled(false);

    panel = new JPanel();
    panel.setLayout(null);
    panel.setVisible(true);
    if (showProcess) {
      export_num = new JLabel("Exporting:");
      export_num.setBounds(10, 10, 200, 20);
      export_num.setVisible(true);
      panel.add(export_num);

      export_name = new JLabel("Current Diagram:");
      export_name.setBounds(10, 30, 480, 20);
      export_name.setVisible(true);
      panel.add(export_name);

      bar = new JProgressBar(0, 0);
      bar.setStringPainted(true);
      bar.setBounds(250, 10, 240, 20);
      bar.setVisible(true);
      panel.add(bar);
    }

    DiagramViewer viewer = null;
    try {
      viewer = new DiagramViewer();
      viewer.setBackgroundGridVisible(false);
      List<Diagram> diagrams = modelManager.getDiagrams();
      int length = diagrams.size();
      for (int i = 0; i < length; i++) {
        Diagram diagram = diagrams.get(i);
        DiagramView view = viewer.openDiagramView(diagram);
        mainFrame.recoverDiagramView(diagram, view, mainFrame.isConverted);
      }
      if (showProcess) {
        bar.setMaximum(length);
      }
      viewer.setBounds(0, 50, 500, 450);

      panel.add(viewer);
      exportingFrame.setContentPane(panel);
      exportingFrame.setVisible(true);

      DiagramView[] views = viewer.getCachedDiagramViews();
      for (int i = 0; i < length; i++) {
        DiagramView view = views[i];
        Diagram diagram = view.getDiagram();
        if (showProcess) {
          export_num.setText("Exporting:                 " + (i + 1) + " of " + length);
          export_name.setText("Current Diagram:    " + diagram.getName());
          bar.setValue(i + 1);
        }
        viewer.getTabbedPane().setSelectedIndex(i);

        panel.paintImmediately(0, 0, 500, 500);

        if (diagram.isVisible()) {
          DeployHelper.exportToFile(
              mainFrame,
              view,
              filePath,
              DeployHelper.generateOutputFileName(diagram.getName()) + "." + extension,
              extension);
        }
      }
      exportingFrame.dispose();

      mainFrame.setLastImageExportPath(filePath);
    } catch (ConfigurationException e) {
    }
  }