/** * 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"); } } }
/** Creates the model element for new node. */ protected void createModelElement() { element = new ClassImpl(); element.setName(name); // Obtain the stereotypes from project configuration manager Set<Stereotype> newStereotypes = new HashSet<Stereotype>(); newStereotypes.add(getStandardStereotype("Enum")); getMainFrame().getPropertiesPanel().addStereotypes(newStereotypes, element.getClass()); for (Stereotype stereotype : newStereotypes) { element.addStereotype(stereotype); } NodeContainer nodeContainer = getNodeContainer(); if (nodeContainer != null) { setAddModelElementAction( new AddClassAction( element, modelManager, (Namespace) DeployHelper.getElement(nodeContainer))); } else { setAddModelElementAction(new AddClassAction(element, modelManager)); } }
/** * 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); } } } }
/** * Creates an instance of RemoveAbstractionAction. * * @param edge edge to remove * @return an an instance of RemoveAbstractionAction */ private static RemoveAbstractionAction createRemoveAbstractionAction(AbstractionEdge edge) { Abstraction abstraction = (Abstraction) DeployHelper.getElement(edge.getGraphEdge()); return new RemoveAbstractionAction(abstraction); }
/** * Creates an instance of RemoveUseCaseAction. * * @param node node to remove * @return an an instance of RemoveUseCaseAction */ private static RemoveUseCaseAction createRemoveUseCaseAction(UseCaseNode node) { UseCase usecase = (UseCase) DeployHelper.getElement(node.getGraphNode()); return new RemoveUseCaseAction(usecase); }