/** refreshDiagram void */
  private void refreshDiagram() {

    Object obj = getSelectedObjects().get(0);
    RootEditPart root = null;

    if (!(obj instanceof EditPart)) {
      return;
    }

    root = ((EditPart) obj).getRoot();
    root.refresh();

    List<EditPart> editparts = root.getChildren();
    for (EditPart editpart : editparts) {
      editpart.refresh();

      List<EditPart> nodeEditParts = editpart.getChildren();
      for (EditPart nodeEditPart : nodeEditParts) {
        if (nodeEditPart instanceof GraphicalEditPart) {

          List<EditPart> sConnectionList =
              ((GraphicalEditPart) nodeEditPart).getSourceConnections();
          List<EditPart> tConnectionList =
              ((GraphicalEditPart) nodeEditPart).getTargetConnections();

          for (EditPart sConnectionEditPart : sConnectionList) {
            sConnectionEditPart.refresh();
          }
          for (EditPart tConnectionEditPart : tConnectionList) {
            tConnectionEditPart.refresh();
          }

          if (nodeEditPart.getModel() instanceof LifeLineNode) {
            List<EditPart> childrenEditPart = nodeEditPart.getChildren();
            for (EditPart child : childrenEditPart) {
              List<EditPart> csConnectionList = ((GraphicalEditPart) child).getSourceConnections();
              List<EditPart> ctConnectionList = ((GraphicalEditPart) child).getTargetConnections();

              for (EditPart sConnectionEditPart : csConnectionList) {
                sConnectionEditPart.refresh();
              }
              for (EditPart tConnectionEditPart : ctConnectionList) {
                tConnectionEditPart.refresh();
              }
            }
          }
        }
      }
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.gef.EditPartFactory#createEditPart(org.eclipse.gef.EditPart,
   * java.lang.Object)
   */
  public EditPart createEditPart(EditPart context, Object model) {
    EditPart ret = null;
    if (model instanceof Diagram) {
      ret = new DiagramTreeEditPart(id, (Diagram) model);
    } else if (context instanceof AbstractGraphicsTreeEditPart) {
      EditPart root = context;
      while (root.getParent() != null) root = root.getParent();
      DiagramTreeEditPart dep = (DiagramTreeEditPart) root.getChildren().get(0);

      if (model instanceof RootElement) {
        ret = new RootElementTreeEditPart(dep, (RootElement) model);
      } else if (model instanceof FlowElement) {
        ret = new FlowElementTreeEditPart(dep, (FlowElement) model);
      } else if (model instanceof BaseElement) {
        ret = new BaseElementTreeEditPart(dep, (BaseElement) model);
      } else if (model instanceof BPMNDiagram) {
        ret = new Bpmn2DiagramTreeEditPart(dep, (BPMNDiagram) model);
      } else if (model instanceof BPMNShape) {
        ret = new Bpmn2ShapeTreeEditPart(dep, (BPMNShape) model);
      } else if (model instanceof BPMNEdge) {
        ret = new Bpmn2EdgeTreeEditPart(dep, (BPMNEdge) model);
      }
    }
    return ret;
  }
예제 #3
0
 public EditPart getMyRoot() {
   EditPart root = getRoot();
   Iterator iter = root.getChildren().iterator();
   EditPart part = null;
   while (iter.hasNext() && !(part instanceof SQLRootEditPart)) {
     part = (EditPart) iter.next();
   } // end of while ()
   return part;
 }
예제 #4
0
 public void setEnabled(boolean enabled) {
   EditPart root = getContents();
   List v = root.getChildren();
   if (v != null) {
     int max = v.size();
     for (int i = 0; i < max; i++) {
       setCategoryEnabled((EditPart) v.get(i), enabled);
     }
   }
 }
예제 #5
0
 private void describe(EditPart part, int indent, StringBuffer buffer) {
   indent(indent, buffer);
   describePartTo(part, buffer);
   List children = part.getChildren();
   if (children.size() > 0) newline(buffer);
   for (Iterator iter = children.iterator(); iter.hasNext(); ) {
     EditPart childPart = (EditPart) iter.next();
     describe(childPart, indent + getIndent(), buffer);
     newline(buffer);
   }
 }
  @Override
  public void setSelected(int value) {
    final EditPart parent = this.getParent();

    final NormalColumnFigure figure = (NormalColumnFigure) this.getFigure();

    Color backgroundColor = null;
    Color foregroundColor = null;
    boolean isSelected = false;

    if (value != 0 && parent != null && parent.getParent() != null) {
      List selectedEditParts = this.getViewer().getSelectedEditParts();

      if (selectedEditParts == null || selectedEditParts.size() != 1) {
        return;
      }

      backgroundColor = ColorConstants.titleBackground;
      foregroundColor = ColorConstants.titleForeground;
      isSelected = true;
    }

    final NormalColumn normalColumn = (NormalColumn) this.getModel();
    final ColumnHolder columnHolder = normalColumn.getColumnHolder();

    if (columnHolder instanceof ColumnGroup) {
      if (parent != null) {
        for (Object child : parent.getChildren()) {
          final GraphicalEditPart childEditPart = (GraphicalEditPart) child;

          if (childEditPart.getModel() instanceof NormalColumn) {
            final NormalColumn column = (NormalColumn) childEditPart.getModel();
            if (column.getColumnHolder() == columnHolder) {
              setGroupColumnFigureColor(
                  (TableViewEditPart) parent, (ColumnGroup) columnHolder, isSelected);
            }
          }
        }
      }

    } else {
      figure.setBackgroundColor(backgroundColor);
      figure.setForegroundColor(foregroundColor);
      selected = isSelected;
    }

    super.setSelected(value);
  }
예제 #7
0
  private void setCategoryEnabled(EditPart part, boolean enabled) {
    List v = part.getChildren();
    if (v != null) {
      int max = v.size();
      for (int i = 0; i < max; i++) {
        Object obj = v.get(i);
        if (obj instanceof GraphicalEditPart) {
          IFigure fig = ((GraphicalEditPart) obj).getFigure();

          if (fig instanceof Clickable) {
            ((Clickable) fig).setEnabled(enabled);
          }
        }
      }
    }
  }
 /**
  * Set all part specify and its descendant to "Moving State"
  *
  * @param targetedEditPart
  */
 protected void stopMovingParts(Iterable<IGraphicalEditPart> targetedEditPart) {
   if (targetedEditPart != null) {
     for (EditPart part : targetedEditPart) {
       EditPolicy editPolicy =
           part.getEditPolicy(IGroupEditPolicies.GROUP_FRAMEWORK_NOTIFYING_ON_MOVE_EDIT_POLICY);
       if (editPolicy instanceof GroupNotifyingOnMoveEditPolicy) {
         GroupNotifyingOnMoveEditPolicy editPolicy2 = (GroupNotifyingOnMoveEditPolicy) editPolicy;
         if (DebugUtils.isDebugging()) {
           StringBuilder stringBuilder = new StringBuilder();
           stringBuilder.append(Utils.getCorrectLabel(editPolicy2.getEObject()));
           stringBuilder.append(" is stoping to move");
           DebugUtils.getLog().debug(stringBuilder.toString());
         }
         editPolicy2.stopMoving();
       }
       stopMovingParts(part.getChildren());
     }
   }
 }
  protected EditPart getEditPart(EditPart parent, Object object) {
    EditPart result = null;
    for (Iterator i = parent.getChildren().iterator(); i.hasNext(); ) {
      EditPart editPart = (EditPart) i.next();
      if (editPart.getModel() == object
          && !(editPart instanceof IHolderEditPart)
          && !(editPart instanceof RootContentEditPart)) {
        result = editPart;
        break;
      }
    }

    if (result == null) {
      for (Iterator i = parent.getChildren().iterator(); i.hasNext(); ) {
        EditPart editPart = getEditPart((EditPart) i.next(), object);
        if (editPart != null) {
          // First check to see if there is a selection
          ISelection currentSelection = getSelection();

          // If there is a selection then we will try to select
          // the target edit part that is one of its children
          // This is handy when you add an element to a structured edit part
          // then you want to select the element immediately and put it in
          // direct edit mode
          if (currentSelection != null) {
            if (currentSelection instanceof StructuredSelection) {
              EditPart targetStructureEditPart =
                  (EditPart) ((StructuredSelection) currentSelection).getFirstElement();
              if (targetStructureEditPart != null) {
                while (targetStructureEditPart != null) {
                  if (targetStructureEditPart instanceof StructureEditPart) {
                    break;
                  }
                  targetStructureEditPart = targetStructureEditPart.getParent();
                }
              }
              EditPart potentialEditPartToSelect = editPart;

              while (potentialEditPartToSelect != null) {
                if (potentialEditPartToSelect instanceof StructureEditPart) {
                  break;
                }
                potentialEditPartToSelect = potentialEditPartToSelect.getParent();
              }

              // If we found a potential edit part to select then return it
              // OR, if there is no target found, then we should just return
              // the edit part we found
              if (potentialEditPartToSelect == targetStructureEditPart
                  || potentialEditPartToSelect == null
                  || targetStructureEditPart == null) {
                result = editPart;
                break;
              }
            }
          } else // Otherwise just find the first one and return
          {
            result = editPart;
            break;
          }
        }
      }
    }

    return result;
  }
  /**
   * transform binary association to n-ary association.
   *
   * @param createConnectionViewAndElementRequest the create connection view and element request
   * @param command the command
   * @return the command in charge of this job
   */
  private Command getAssociationToMultiAssociationCommand(
      CreateConnectionViewAndElementRequest createConnectionViewAndElementRequest,
      Command command) {
    // 0. creation of variables
    command = new CompoundCommand();
    Point sourceLocation = null;
    Point targetLocation = null;
    Point nodeLocation = null;
    NamedElement newSemanticElement = null; // element that will be added as
    // client ou supplier of the
    // association
    EStructuralFeature feature = null; // role client or supplier
    EditPart sourceEditPart = createConnectionViewAndElementRequest.getSourceEditPart();
    EditPart targetEditPart = createConnectionViewAndElementRequest.getTargetEditPart();
    View associationView = null;
    Association association = null;
    View parentView = null;

    Property sourceEnd = null;
    Property targetEnd = null;

    // ---------------------------------------------------------
    // help to debug
    //		System.err.println("\n+ 0. creation of variables");
    //		System.err.println("+-> editting domain"+ getEditingDomain());
    //		System.err.println("+-> sourceEditpart:" + sourceEditPart);
    //		System.err.println("+-> targetEditPart:" + targetEditPart);
    // ---------------------------------------------------------

    // 1. initialization
    ICommandProxy startcommand =
        ((ICommandProxy) createConnectionViewAndElementRequest.getStartCommand());
    if (startcommand == null) {
      return null;
    }
    Iterator<?> ite = ((CompositeCommand) startcommand.getICommand()).iterator();

    while (ite.hasNext()) {
      ICommand currentCommand = (ICommand) ite.next();
      if (currentCommand instanceof SetConnectionBendpointsCommand) {
        sourceLocation = ((SetConnectionBendpointsCommand) currentCommand).getSourceRefPoint();
        targetLocation = ((SetConnectionBendpointsCommand) currentCommand).getTargetRefPoint();
      }
    }

    if (targetEditPart != null) {
      // the source or the target must be a association
      // look for the edit part that represent the editpart
      if (((View) sourceEditPart.getModel()).getElement() != null
          && ((View) sourceEditPart.getModel()).getElement() instanceof Association) {
        associationView = ((View) sourceEditPart.getModel());
        association = (Association) ((View) sourceEditPart.getModel()).getElement();
        nodeLocation = sourceLocation;
        newSemanticElement = (NamedElement) ((View) targetEditPart.getModel()).getElement();
        feature = UMLPackage.eINSTANCE.getTypedElement_Type();
        sourceEnd =
            AssociationEndSourceLabelHelper.getInstance()
                .getUMLElement(
                    (org.eclipse.gef.GraphicalEditPart) sourceEditPart.getChildren().get(0));
        targetEnd =
            AssociationEndTargetLabelHelper.getInstance()
                .getUMLElement(
                    (org.eclipse.gef.GraphicalEditPart) sourceEditPart.getChildren().get(1));
      }

      if (((View) targetEditPart.getModel()).getElement() != null
          && ((View) targetEditPart.getModel()).getElement() instanceof Association) {
        associationView = ((View) targetEditPart.getModel());
        association = (Association) ((View) targetEditPart.getModel()).getElement();
        nodeLocation = targetLocation;
        newSemanticElement = (NamedElement) ((View) sourceEditPart.getModel()).getElement();
        feature = UMLPackage.eINSTANCE.getTypedElement_Type();
        sourceEnd =
            AssociationEndSourceLabelHelper.getInstance()
                .getUMLElement(
                    (org.eclipse.gef.GraphicalEditPart) targetEditPart.getChildren().get(0));
        targetEnd =
            AssociationEndTargetLabelHelper.getInstance()
                .getUMLElement(
                    (org.eclipse.gef.GraphicalEditPart) targetEditPart.getChildren().get(1));
      }

      if (associationView == null || (targetEditPart.getModel() instanceof Edge)) {
        return null;
      }
      parentView = (View) associationView.eContainer();
      // ---------------------------------------------------------
      // help to debug
      //			System.err.println("+ 1. initialization");
      //			System.err.println("+-> sourceLocation:" + sourceLocation);
      //			System.err.println("+-> targetLocation:" + targetLocation);
      //			System.err.println("+-> AssociationView:" + associationView);
      //			System.err.println("+-> association:" + association);
      //			System.err.println("+-> nodeLocation:" + nodeLocation);
      //			System.err.println("+-> newSemanticElement:" + newSemanticElement);
      //			System.err.println("+-> feature:" + feature);
      //			System.err.println("+-> parentView:" + parentView);
      // ---------------------------------------------------------
      // 8 Ensure that all member ends belong to the association
      ArrayList<Property> ownedProperty = new ArrayList<Property>();
      ownedProperty.addAll(association.getMemberEnds());
      IElementEditService provider = ElementEditServiceUtils.getCommandProvider(association);
      if (provider != null) {
        SetRequest setRequest =
            new SetRequest(
                association, UMLPackage.eINSTANCE.getAssociation_OwnedEnd(), ownedProperty);
        ICommand iCommand = provider.getEditCommand(setRequest);
        ((CompoundCommand) command).add(new ICommandProxy(iCommand));
      }

      // 2. Remove the view of the association
      DeleteCommand deleteCommand =
          new DeleteLinkDuringCreationCommand(
              getEditingDomain(), (Edge) associationView, sourceEditPart.getViewer());
      deleteCommand.setReuseParentTransaction(true);
      Command removecommand = new ICommandProxy(deleteCommand);
      // to execute
      ((CompoundCommand) command).add(removecommand);

      // ((CompoundCommand)command).add(removecommand);

      // ---------------------------------------------------------
      // help to debug
      //			System.err.println("+ 2. Remove the view of the association");
      //			System.err.println("+-> command:" + command.canExecute());
      // ---------------------------------------------------------

      // 3. set a new end association in the UML model
      // 3.1 creation of the property
      CreateElementRequest request =
          new CreateElementRequest(
              getEditingDomain(),
              association,
              UMLElementTypes.Property_3005,
              UMLPackage.eINSTANCE.getAssociation_OwnedEnd());
      request.setParameter("type", newSemanticElement);
      EditElementCommand propertyCreateCommand = new PropertyCommandForAssociation(request);
      propertyCreateCommand.setReuseParentTransaction(true);
      ((CompoundCommand) command).add(new ICommandProxy(propertyCreateCommand));

      // 3. Node creation at this position
      View associationViewSource = ((Edge) associationView).getSource();
      View associationViewTarget = ((Edge) associationView).getTarget();
      AssociationDiamonViewCreateCommand nodeCreation =
          new AssociationDiamonViewCreateCommand(
              getEditingDomain(),
              parentView,
              sourceEditPart.getViewer(),
              ((IGraphicalEditPart) sourceEditPart).getDiagramPreferencesHint(),
              nodeLocation,
              new SemanticAdapter(association, null));
      nodeCreation.setReuseParentTransaction(true);
      ((CompoundCommand) command).add(new ICommandProxy(nodeCreation));

      // 4. reconstruction of the old link by taking in account the old
      // connection
      ConnectionViewDescriptor viewDescriptor =
          new ConnectionViewDescriptor(
              UMLElementTypes.Association_4019,
              ((IHintedType) UMLElementTypes.Association_4019).getSemanticHint(),
              ((IGraphicalEditPart) sourceEditPart).getDiagramPreferencesHint());

      // 5. reconstruction of the first branch between old source to node
      ICommand firstBranchCommand =
          new GraphicalAssociationBranchViewCommand(
              getEditingDomain(),
              (IAdaptable) nodeCreation.getCommandResult().getReturnValue(),
              new SemanticAdapter(null, associationViewSource),
              sourceEditPart.getViewer(),
              ((IGraphicalEditPart) sourceEditPart).getDiagramPreferencesHint(),
              viewDescriptor,
              sourceEnd);

      // ICommand firstBranchCommand = new
      // CustomDeferredCreateConnectionViewCommand(getEditingDomain(),
      // ((IHintedType)UMLElementTypes.Association_4019).getSemanticHint(),
      // (IAdaptable)nodeCreation.getCommandResult().getReturnValue(), new SemanticAdapter(null,
      // associationViewSource), sourceEditPart.getViewer(),
      // ((IGraphicalEditPart)sourceEditPart).getDiagramPreferencesHint(), viewDescriptor, null);
      ((GraphicalAssociationBranchViewCommand) firstBranchCommand).setElement(association);
      ((CompoundCommand) command).add(new ICommandProxy(firstBranchCommand));
      // 6. reconstruction of the second branch between node to old target
      ICommand secondBranchCommand =
          new GraphicalAssociationBranchViewCommand(
              getEditingDomain(),
              (IAdaptable) nodeCreation.getCommandResult().getReturnValue(),
              new SemanticAdapter(null, associationViewTarget),
              sourceEditPart.getViewer(),
              ((IGraphicalEditPart) sourceEditPart).getDiagramPreferencesHint(),
              viewDescriptor,
              targetEnd);

      // ICommand secondBranchCommand = new
      // CustomDeferredCreateConnectionViewCommand(getEditingDomain(),
      // ((IHintedType)UMLElementTypes.Association_4019).getSemanticHint(),
      // (IAdaptable)nodeCreation.getCommandResult().getReturnValue(), new SemanticAdapter(null,
      // associationViewTarget), sourceEditPart.getViewer(),
      // ((IGraphicalEditPart)sourceEditPart).getDiagramPreferencesHint(), viewDescriptor, null);
      ((GraphicalAssociationBranchViewCommand) secondBranchCommand).setElement(association);
      ((CompoundCommand) command).add(new ICommandProxy(secondBranchCommand));

      // 7. Create of the third branch between node and target our source.
      ICommand thirdBranchCommand = null;

      if (associationView.equals((sourceEditPart.getModel()))) {
        // third branch node and target
        thirdBranchCommand =
            new GraphicalAssociationBranchViewCommand(
                getEditingDomain(),
                (IAdaptable) nodeCreation.getCommandResult().getReturnValue(),
                new SemanticAdapter(null, targetEditPart.getModel()),
                sourceEditPart.getViewer(),
                ((IGraphicalEditPart) sourceEditPart).getDiagramPreferencesHint(),
                viewDescriptor,
                request);

        // thirdBranchCommand = new CustomDeferredCreateConnectionViewCommand(getEditingDomain(),
        // ((IHintedType)UMLElementTypes.Association_4019).getSemanticHint(),
        // (IAdaptable)nodeCreation.getCommandResult().getReturnValue(), new SemanticAdapter(null,
        // targetEditPart.getModel()), sourceEditPart.getViewer(),
        // ((IGraphicalEditPart)sourceEditPart).getDiagramPreferencesHint(), viewDescriptor, null);
      } else {
        // third branch source and node
        thirdBranchCommand =
            new GraphicalAssociationBranchViewCommand(
                getEditingDomain(),
                new SemanticAdapter(null, sourceEditPart.getModel()),
                (IAdaptable) nodeCreation.getCommandResult().getReturnValue(),
                sourceEditPart.getViewer(),
                ((IGraphicalEditPart) sourceEditPart).getDiagramPreferencesHint(),
                viewDescriptor,
                request);

        // thirdBranchCommand = new CustomDeferredCreateConnectionViewCommand(getEditingDomain(),
        // ((IHintedType)UMLElementTypes.Association_4019).getSemanticHint(), new
        // SemanticAdapter(null, sourceEditPart.getModel()),
        // (IAdaptable)nodeCreation.getCommandResult().getReturnValue(), sourceEditPart.getViewer(),
        // ((IGraphicalEditPart)sourceEditPart).getDiagramPreferencesHint(), viewDescriptor, null);
      }
      ((GraphicalAssociationBranchViewCommand) thirdBranchCommand).setElement(association);
      ((CompoundCommand) command).add(new ICommandProxy(thirdBranchCommand));
    }
    return command;
  }