/**
  * 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");
     }
   }
 }
 /**
  * Updates the node corresponding to the document tree node in the diagram viewer and the model
  * elements list.
  *
  * @param documentTreeNode the document tree node
  * @param isSelected the flag whether selecting or unselecting the node
  */
 private void selectNode(DocumentTreeNode documentTreeNode, boolean isSelected) {
   DocumentTreeNodeType type = documentTreeNode.getType();
   if (type != DocumentTreeNodeType.DIAGRAM_CATEGORY) {
     Object object = documentTreeNode.getNodeObject();
     if (object instanceof Diagram) {
       selectDiagram((Diagram) object, isSelected);
     } else {
       List<JComponent> jComponents = new ArrayList<JComponent>();
       ModelElement modelElement;
       if (type == DocumentTreeNodeType.MODEL_ELEMENT) {
         modelElement = (ModelElement) object;
         jComponents = DeployHelper.getComponent((ModelElement) object, mainFrame);
       } else {
         modelElement = DeployHelper.getElement((GraphElement) object);
         JComponent component = DeployHelper.getComponent((GraphElement) object, mainFrame);
         if (component != null) {
           jComponents.add(component);
         }
       }
       if (jComponents.size() > 0) {
         for (JComponent jComponent : jComponents) {
           if (isSelected) {
             mainFrame.getDiagramViewer().addSelectedElement(jComponent);
           } else {
             mainFrame.getDiagramViewer().removeSelectedElement(jComponent);
           }
           updateDiagramViewAndStyle(jComponent, isSelected);
         }
       }
       if (isSelected) {
         modelElements.add(modelElement);
       } else {
         remove(modelElement);
       }
     }
   }
 }