protected void setUp() throws Exception {
    super.setUp();

    List children = getTestFixture().getDiagramEditPart().getChildren();
    if (children.isEmpty()) assertFalse(true);

    EditPart firstEP = (EditPart) children.get(0);
    if (firstEP instanceof CircuitEditPart) {
      CircuitEditPart circuitEditPart = (CircuitEditPart) firstEP;

      IElementType typeLED = ElementTypeRegistry.getInstance().getType("logic.led"); // $NON-NLS-1$
      Point pos = circuitEditPart.getFigure().getBounds().getBottomRight();
      circuitEditPart.getFigure().translateToAbsolute(pos);
      pos.translate(100, 100);
      LEDEditPart ledEP2 =
          (LEDEditPart)
              getLogicTestFixture().createShapeUsingTool(typeLED, pos, getDiagramEditPart());

      Terminal term1 =
          (Terminal)
              ((Circuit) circuitEditPart.getNotationView().getElement())
                  .getOutputTerminals()
                  .get(0);
      TerminalEditPart tep1 = null;
      ListIterator li = circuitEditPart.getChildren().listIterator();
      while (li.hasNext()) {
        IGraphicalEditPart gep = (IGraphicalEditPart) li.next();
        if (gep.getNotationView().getElement().equals(term1)) tep1 = (TerminalEditPart) gep;
      }

      Terminal term2 =
          (Terminal) ((LED) ledEP2.getNotationView().getElement()).getInputTerminals().get(0);
      TerminalEditPart tep2 = null;
      li = ledEP2.getChildren().listIterator();
      while (li.hasNext()) {
        IGraphicalEditPart gep = (IGraphicalEditPart) li.next();
        if (gep.getNotationView().getElement().equals(term2)) tep2 = (TerminalEditPart) gep;
      }

      IElementType typeWire =
          ElementTypeRegistry.getInstance().getType("logic.wire"); // $NON-NLS-1$

      getLogicTestFixture().createConnectorUsingTool(tep1, tep2, typeWire);

      IGraphicalEditPart logicCompartment =
          circuitEditPart.getChildBySemanticHint(LogicConstants.LOGIC_SHAPE_COMPARTMENT);

      Rectangle rect = new Rectangle(logicCompartment.getFigure().getBounds());
      logicCompartment.getFigure().translateToAbsolute(rect);

      CreateRequest request = getLogicTestFixture().getCreationRequest(typeLED);
      request.setLocation(rect.getCenter());
      Command cmd = logicCompartment.getCommand(request);

      getCommandStack().execute(cmd);

      assertEquals(
          "Unexpected LED count.", 1, logicCompartment.getChildren().size()); // $NON-NLS-1$
    }
  }
 public void setBoundsForOverlapComputation(IGraphicalEditPart ep, Rectangle result) {
   if (ep.resolveSemanticElement() instanceof FlowElement) {
     IFigure fig = ((IGraphicalEditPart) ep).getContentPane();
     result.setBounds(fig.getBounds());
     fig.translateToAbsolute(result);
     return;
   } else {
     result.setBounds(ep.getFigure().getBounds());
     ep.getFigure().translateToAbsolute(result);
   }
 }
  /** Shows a nice guideline to show the move */
  protected void showSourceFeedback() {
    if (_container == null) {
      return;
    }
    if (guideline.getParent() == null) {
      addFeedback(guideline);
    }
    Rectangle bounds = Rectangle.SINGLETON.getCopy();
    bounds.y = getCurrentPositionZoomed();

    Rectangle containerBounds = _container.getFigure().getBounds().getCopy();

    _container.getFigure().translateToAbsolute(containerBounds);

    ((DiagramEditPart) getCurrentViewer().getContents())
        .getFigure()
        .translateToRelative(containerBounds);

    bounds.x = containerBounds.x;
    bounds.height = 1;
    bounds.width = containerBounds.width;

    ZoomManager zoomManager =
        ((DiagramRootEditPart) getCurrentViewer().getRootEditPart()).getZoomManager();
    bounds.performScale(zoomManager.getZoom());

    guideline.setBounds(bounds);
    guideline.setVisible(getState() == STATE_DRAG_IN_PROGRESS);

    ChangeBoundsRequest request = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
    request.setMoveDelta(((ChangeBoundsRequest) getSourceRequest()).getMoveDelta());
    request.setSizeDelta(new Dimension(0, 0));
    request.setEditParts(_movingShapes);

    for (IGraphicalEditPart part : _movingShapes) {
      part.showSourceFeedback(request);
    }

    ChangeBoundsRequest spRequest = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE);
    Point moveDelta = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy();
    Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y);
    spRequest.setSizeDelta(spSizeDelta);
    spRequest.setMoveDelta(new Point(0, 0));
    spRequest.setEditParts(_subProcesses);

    for (IGraphicalEditPart sp : _subProcesses) {
      sp.showSourceFeedback(spRequest);
    }
    ((DiagramEditPart) getCurrentViewer().getContents()).getRoot().refresh();
  }
 private IFigure getTargetFigure(IGraphicalEditPart editPart) {
   IFigure figure = editPart.getFigure();
   if (figure instanceof BorderedNodeFigure) {
     figure = (IFigure) figure.getChildren().get(0);
   }
   if (figure instanceof DefaultSizeNodeFigure) {
     figure = (IFigure) figure.getChildren().get(0);
   }
   return figure;
 }
  public InlineTextInputDialog(final IGraphicalEditPart graphicalEditPart, final String value) {
    super(graphicalEditPart.getViewer().getControl().getShell());
    final IFigure theFigure = graphicalEditPart.getFigure();

    final org.eclipse.draw2d.geometry.Rectangle r = theFigure.getBounds().getCopy();
    theFigure.translateToAbsolute(r);

    final Control theCanvas = graphicalEditPart.getViewer().getControl();
    labelBounds =
        theCanvas.getDisplay().map(theCanvas, null, new Rectangle(r.x, r.y, r.width, r.height));

    this.value = value;
    setShellStyle(SWT.NO_TRIM | SWT.APPLICATION_MODAL);
  }
  /**
   * initialize the status of the compartment for the node (Showed or hidden)
   *
   * @param view the element to initialize
   * @param store the preference store
   * @param elementName the name to the element
   */
  public static void initCompartmentsStatusFromPrefs(
      View view, final IPreferenceStore store, String elementName) {
    EList<?> children = view.getPersistedChildren();
    if (children != null) {
      for (Object object : children) {

        // we look for the name of the compartment for this view
        EditPart dummyEP = EditPartService.getInstance().createGraphicEditPart((View) object);
        IGraphicalEditPart epp = (IGraphicalEditPart) dummyEP;
        IFigure fig1 = epp.getFigure();

        if (fig1 instanceof ResizableCompartmentFigure) {
          String compartmentName = ((ResizableCompartmentFigure) fig1).getCompartmentTitle();
          if (compartmentName != null) {
            String diagramKind = view.getDiagram().getType();
            String preferenceKey =
                PreferenceConstantHelper.getCompartmentElementConstant(
                    diagramKind + "_" + elementName,
                    compartmentName,
                    PreferenceConstantHelper.COMPARTMENT_VISIBILITY); // $NON-NLS-1$
            boolean value = store.getBoolean(preferenceKey);

            if (!value) { // the default value is true : nothing to
              // do
              ENamedElement namedElement =
                  PackageUtil.getElement("notation.View.visible"); // $NON-NLS-1$
              ViewUtil.setStructuralFeatureValue(
                  (View) object, (EStructuralFeature) namedElement, value);
            }

            String compartmentNameVisibilityPreference =
                PreferenceConstantHelper.getCompartmentElementConstant(
                    diagramKind + "_" + elementName,
                    compartmentName,
                    PreferenceConstantHelper.COMPARTMENT_NAME_VISIBILITY); // $NON-NLS-1$
            boolean showCompartmentName = store.getBoolean(compartmentNameVisibilityPreference);
            View childView = (View) object;
            TitleStyle style =
                (TitleStyle) childView.getStyle(NotationPackage.eINSTANCE.getTitleStyle());
            if (style != null) {
              style.setShowTitle(showCompartmentName);
            }
          }
        }
        dummyEP = null;
      }
    }
  }
Beispiel #7
0
  /**
   * Creates the appropriate review decoration if all the criteria is satisfied by the view passed
   * in.
   */
  public void refresh() {
    removeDecoration();

    Node node = getDecoratorTargetNode(getDecoratorTarget());
    IGraphicalEditPart gep =
        (IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class);

    if (node != null) {
      DescriptionStyle descStyle = getDescriptionStyle(node);

      if (descStyle != null) {
        if (isInherited(node)) {
          // if(Util.isAffixedChildNode(gep)) {

          // setDecoration(getDecoratorTarget().addDecoration(figure,
          // locator, false));
          // } else {
          // setDecoration(getDecoratorTarget().addShapeDecoration(figure,
          // getDirection(node), -1, false));
          // }

          if (gep != null && gep.getRoot() != null) { // if the gep has
            // no parent, we
            // can't test if
            // the container
            // is a
            // compartment
            // list
            // (because, we
            // call the
            // method
            // DiagramEditPartsUtil.getEditPartFromView((View)container,
            // gep);
            IFigure figure = getFigure(ICON_HYPERLINK);
            if (isInCompartmentList(node) && !Util.isAffixedChildNode(gep)) {
              setDecoration(
                  getDecoratorTarget().addShapeDecoration(figure, getDirection(node), -1, false));
            } else {
              Locator locator = new OverlayLocator(gep.getFigure(), getDirection(node));
              setDecoration(getDecoratorTarget().addDecoration(figure, locator, false));
            }
          }
        }
      }
    }
  }
  private boolean checkNewLocation(
      final SWTBotSiriusDiagramEditor editordiagram,
      final SWTBotGefEditPart botPart,
      final int x,
      final int y) {
    if (botPart == null) System.out.println("NULL");
    final EditPart rawPart = botPart.part();
    if (rawPart == null) System.out.println("rawPart NULL");
    if (rawPart instanceof IDiagramElementEditPart && !(rawPart instanceof DiagramEditPart)) {
      final IGraphicalEditPart gep = (IGraphicalEditPart) rawPart;
      final Rectangle r = gep.getFigure().getBounds().getCopy();
      System.out.println("REAL");
      System.out.println(r.x);
      System.out.println(r.y);
      System.out.println("EXPECTED");
      System.out.println(x);
      System.out.println(y);

      return (r.x == x) && (r.y == y);
    }
    return false;
  }
  /** creates the command to move the shapes left or right. */
  protected Command getCommand() {
    if (_container == null) {
      return null;
    }
    CompoundCommand command = new CompoundCommand("Multiple Shape Move");
    TransactionalEditingDomain editingDomain = _container.getEditingDomain();

    Point moveDelta = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy();
    Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y);
    ZoomManager zoomManager =
        ((DiagramRootEditPart) getCurrentViewer().getRootEditPart()).getZoomManager();
    spSizeDelta.scale(1 / zoomManager.getZoom());
    command.add(_container.getCommand(getSourceRequest()));

    for (IGraphicalEditPart sp : _subProcesses) {
      Dimension spDim = sp.getFigure().getBounds().getSize().getCopy();
      spDim.expand(spSizeDelta);
      SetBoundsCommand setBounds =
          new SetBoundsCommand(editingDomain, "MultipleShape Move", sp, spDim);
      command.add(new ICommandProxy(setBounds));
    }
    return command;
  }
 private Rectangle getAbsoluteBounds(IGraphicalEditPart editPart, Float[] preferPosition) {
   if (editPart == null) {
     return null;
   }
   Rectangle rect = editPart.getFigure().getBounds().getCopy();
   if (rect.isEmpty() && rect.x == 0 && rect.y == 0) { // Not displayed yet.
     View view = editPart.getNotationView();
     if (view instanceof Node) {
       LayoutConstraint constraint = ((Node) view).getLayoutConstraint();
       if (constraint instanceof Bounds) {
         Bounds bounds = (Bounds) constraint;
         if (bounds.getX() > 0) {
           rect.x = bounds.getX();
         }
         if (bounds.getY() > 0) {
           rect.y = bounds.getY();
         } else if (preferPosition != null
             && preferPosition.length > 0
             && preferPosition[0] != null) {
           rect.y = preferPosition[0].intValue();
         }
         if (bounds.getWidth() != -1) {
           rect.width = bounds.getWidth();
         }
         if (bounds.getHeight() != -1) {
           rect.height = bounds.getHeight();
         }
       }
     }
     Rectangle parentRect = getAbsoluteBounds((IGraphicalEditPart) editPart.getParent(), null);
     rect.x += parentRect.x;
     rect.y += parentRect.y;
   } else {
     rect = SequenceUtil.getAbsoluteBounds(editPart);
   }
   return rect;
 }