public Command getCreateLinkCommand(View source, View target, GenCommonBase linkType) {
      IElementType metamodelType = getElementType(linkType);
      CreateRelationshipRequest relationShipReq = new CreateRelationshipRequest(metamodelType);

      ConnectionViewAndElementDescriptor desc =
          new ConnectionViewAndElementDescriptor(
              new CreateElementRequestAdapter(relationShipReq),
              metamodelType instanceof IHintedType
                  ? ((IHintedType) metamodelType).getSemanticHint()
                  : "",
              getDefaultPreferencesHint());

      CreateConnectionViewAndElementRequest req = new CreateConnectionViewAndElementRequest(desc);
      req.setType(RequestConstants.REQ_CONNECTION_START);

      EditPart sourceEditPart = findEditPart(source);
      req.setSourceEditPart(sourceEditPart);
      // Note: initializes the sourceCommand in the request
      Command sourceCmd = sourceEditPart.getCommand(req);
      if (sourceCmd == null || !sourceCmd.canExecute()) {
        return null;
      }

      EditPart targetEditPart = target != null ? findEditPart(target) : null;
      if (targetEditPart != null) {
        req.setType(RequestConstants.REQ_CONNECTION_END);
        req.setTargetEditPart(targetEditPart);
        req.setLocation(new Point(0, 0));
        sourceEditPart.getCommand(req);
        Command targetCmd = targetEditPart.getCommand(req);
        return targetCmd;
      }
      return null;
    }
 /** @generated */
 private Collection<IAdaptable> createConnections(
     Collection<TaiPanLinkDescriptor> linkDescriptors, Domain2Notation domain2NotationMap) {
   LinkedList<IAdaptable> adapters = new LinkedList<IAdaptable>();
   for (TaiPanLinkDescriptor nextLinkDescriptor : linkDescriptors) {
     EditPart sourceEditPart = getSourceEditPart(nextLinkDescriptor, domain2NotationMap);
     EditPart targetEditPart = getTargetEditPart(nextLinkDescriptor, domain2NotationMap);
     if (sourceEditPart == null || targetEditPart == null) {
       continue;
     }
     CreateConnectionViewRequest.ConnectionViewDescriptor descriptor =
         new CreateConnectionViewRequest.ConnectionViewDescriptor(
             nextLinkDescriptor.getSemanticAdapter(),
             TaiPanVisualIDRegistry.getType(nextLinkDescriptor.getVisualID()),
             ViewUtil.APPEND,
             false,
             ((IGraphicalEditPart) getHost()).getDiagramPreferencesHint());
     CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(descriptor);
     ccr.setType(RequestConstants.REQ_CONNECTION_START);
     ccr.setSourceEditPart(sourceEditPart);
     sourceEditPart.getCommand(ccr);
     ccr.setTargetEditPart(targetEditPart);
     ccr.setType(RequestConstants.REQ_CONNECTION_END);
     Command cmd = targetEditPart.getCommand(ccr);
     if (cmd != null && cmd.canExecute()) {
       executeCommand(cmd);
       IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject();
       if (viewAdapter != null) {
         adapters.add(viewAdapter);
       }
     }
   }
   return adapters;
 }
 /** Handle resize InteractionOperand {@inheritDoc} */
 @Override
 protected Command getResizeCommand(ChangeBoundsRequest request) {
   if ((request.getResizeDirection() & PositionConstants.EAST_WEST) != 0) {
     EditPart parent = getHost().getParent().getParent();
     return parent.getCommand(request);
   } else {
     if (this.getHost() instanceof InteractionOperandEditPart
         && this.getHost().getParent()
             instanceof CombinedFragmentCombinedFragmentCompartmentEditPart) {
       InteractionOperandEditPart currentIOEP = (InteractionOperandEditPart) this.getHost();
       CombinedFragmentCombinedFragmentCompartmentEditPart compartEP =
           (CombinedFragmentCombinedFragmentCompartmentEditPart) this.getHost().getParent();
       // if first interaction operand and resize direction is NORTH
       if (this.getHost() == OperandBoundsComputeHelper.findFirstIOEP(compartEP)
           && (request.getResizeDirection() & PositionConstants.NORTH) != 0) {
         return getHost().getParent().getParent().getCommand(request);
       } else {
         int heightDelta = request.getSizeDelta().height();
         if ((request.getResizeDirection() & PositionConstants.NORTH) != 0) {
           return OperandBoundsComputeHelper.createIOEPResizeCommand(
               currentIOEP, heightDelta, compartEP, PositionConstants.NORTH);
         } else if ((request.getResizeDirection() & PositionConstants.SOUTH) != 0) {
           return OperandBoundsComputeHelper.createIOEPResizeCommand(
               currentIOEP, heightDelta, compartEP, PositionConstants.SOUTH);
         }
       }
     }
     return null;
   }
 }
 @Override
 protected Command getCommand() {
   final EditPart targetEditPart = getTargetEditPart();
   final CompositeCommand compositeCommand =
       new CompositeCommand(
           Messages.OccurrenceSpecificationCreationTool_CreateOccurrenceSpecification);
   EditPart timeline;
   if (targetEditPart instanceof FullStateInvariantEditPartCN) {
     final FullStateInvariantEditPartCN fullStateInvariantEditPartCN =
         (FullStateInvariantEditPartCN) targetEditPart;
     timeline =
         EditPartUtils.findParentEditPartWithId(
             targetEditPart, FullLifelineTimelineCompartmentEditPartCN.VISUAL_ID);
     compositeCommand.add(
         new CutAndInsertOccurrenceSpecificationCommand(
             fullStateInvariantEditPartCN, getLocation(), false));
   } else if (targetEditPart instanceof CompactStateInvariantEditPartCN) {
     final CompactStateInvariantEditPartCN compactStateInvariantEditPartCN =
         (CompactStateInvariantEditPartCN) targetEditPart;
     timeline =
         EditPartUtils.findParentEditPartWithId(
             targetEditPart, CompactLifelineCompartmentEditPartCN.VISUAL_ID);
     compositeCommand.add(
         new AddOccurrenceSpecificationInCompactLifelineCommand(
             compactStateInvariantEditPartCN, getLocation()));
   } else {
     return UnexecutableCommand.INSTANCE;
   }
   final Command updateLayoutCommand =
       timeline.getCommand(AbstractTimelineLayoutPolicy.UPDATE_LAYOUT_REQUEST);
   compositeCommand.add(new CommandProxy(updateLayoutCommand));
   return new ICommandProxy(compositeCommand);
 }
  /**
   * Returns a composite command with the given initial command and the RegionContainer specific
   * auto-size commands to propagate the auto-size to the regions.
   *
   * @param request the initial request
   * @param autoSizeCommand the initial command
   * @return a composite command with the initial command and the region container specific
   *     additional commands.
   */
  protected Command getRegionContainerAutoSizeCommand(Request request, Command autoSizeCommand) {
    IDiagramElementEditPart host = (IDiagramElementEditPart) getHost();
    TransactionalEditingDomain domain = host.getEditingDomain();
    CompositeTransactionalCommand ctc =
        new CompositeTransactionalCommand(
            domain,
            Messages.RegionContainerResizableEditPolicy_regionContainerAutoSizeCommandLabel);
    ctc.add(new CommandProxy(autoSizeCommand));
    Command regionContainerAutoSizeCommand = new ICommandProxy(ctc);

    // Propagate the auto-size request to the regions.
    Request req = new Request();
    req.setType(request.getType());
    req.getExtendedData().put(REGION_AUTO_SIZE_PROPAGATOR, host);

    Object object = request.getExtendedData().get(REGION_AUTO_SIZE_PROPAGATOR);
    for (EditPart regionPart : getRegionParts()) {
      if (object != regionPart) {
        ctc.add(new CommandProxy(regionPart.getCommand(req)));
      }
    }

    ctc.add(
        CommandFactory.createICommand(
            domain, new RegionContainerUpdateLayoutOperation((Node) host.getModel())));
    return regionContainerAutoSizeCommand;
  }
예제 #6
0
 public Command createOpacityCommand(final String opacity) {
   final Request opacityReq = new Request("opacity"); // $NON-NLS-1$
   final HashMap<String, String> reqData = new HashMap<String, String>();
   reqData.put("newOpacity", opacity); // $NON-NLS-1$
   opacityReq.setExtendedData(reqData);
   final EditPart object = (EditPart) getSelectedObjects().get(0);
   final Command cmd = object.getCommand(opacityReq);
   return cmd;
 }
 /**
  * Gets a command from each child in the group.
  *
  * @param request
  * @return the compound command
  */
 private Command getCommandFromChildren(Request request) {
   CompoundCommand cc = new CompoundCommand();
   for (Iterator iter = getHost().getChildren().iterator(); iter.hasNext(); ) {
     EditPart childEP = (EditPart) iter.next();
     cc.add(childEP.getCommand(request));
   }
   cc.unwrap();
   return cc;
 }
 /** @generated */
 private Collection createConnections(Collection linkDescriptors, Map domain2NotationMap) {
   List adapters = new LinkedList();
   for (Iterator linkDescriptorsIterator = linkDescriptors.iterator();
       linkDescriptorsIterator.hasNext(); ) {
     final AutomataLinkDescriptor nextLinkDescriptor =
         (AutomataLinkDescriptor) linkDescriptorsIterator.next();
     EditPart sourceEditPart = getEditPart(nextLinkDescriptor.getSource(), domain2NotationMap);
     EditPart targetEditPart =
         getEditPart(nextLinkDescriptor.getDestination(), domain2NotationMap);
     if (sourceEditPart == null || targetEditPart == null) {
       continue;
     }
     CreateConnectionViewRequest.ConnectionViewDescriptor descriptor =
         new CreateConnectionViewRequest.ConnectionViewDescriptor(
             nextLinkDescriptor.getSemanticAdapter(),
             null,
             ViewUtil.APPEND,
             false,
             ((IGraphicalEditPart) getHost()).getDiagramPreferencesHint());
     CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(descriptor);
     ccr.setType(RequestConstants.REQ_CONNECTION_START);
     ccr.setSourceEditPart(sourceEditPart);
     sourceEditPart.getCommand(ccr);
     ccr.setTargetEditPart(targetEditPart);
     ccr.setType(RequestConstants.REQ_CONNECTION_END);
     Command cmd = targetEditPart.getCommand(ccr);
     if (cmd != null && cmd.canExecute()) {
       executeCommand(cmd);
       IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject();
       if (viewAdapter != null) {
         adapters.add(viewAdapter);
       }
     }
   }
   return adapters;
 }
예제 #9
0
 /** @generated */
 protected Command getCommand(Request request) {
   List operationSet = getOperationSet();
   if (operationSet.isEmpty()) {
     return UnexecutableCommand.INSTANCE;
   }
   Iterator editParts = operationSet.iterator();
   CompositeTransactionalCommand command =
       new CompositeTransactionalCommand(getEditingDomain(), getCommandLabel());
   while (editParts.hasNext()) {
     EditPart editPart = (EditPart) editParts.next();
     Command curCommand = editPart.getCommand(request);
     if (curCommand != null) {
       command.compose(new CommandProxy(curCommand));
     }
   }
   if (command.isEmpty() || command.size() != operationSet.size()) {
     return UnexecutableCommand.INSTANCE;
   }
   return new ICommandProxy(command);
 }
 /**
  * Creates command to destroy the link.
  *
  * @generated
  */
 protected Command getDestroyElementCommand(View view) {
   EditPart editPart = (EditPart) getHost().getViewer().getEditPartRegistry().get(view);
   DestroyElementRequest request = new DestroyElementRequest(getEditingDomain(), false);
   return editPart.getCommand(new EditCommandRequestWrapper(request, Collections.EMPTY_MAP));
 }
예제 #11
0
  /** {@inheritDoc} */
  @Override
  protected Command getActionCommand() {
    /* for further information, see bug 302555 */
    ViewServiceUtil.forceLoad();

    ShowHideCompartmentRequest req = null;
    CompoundCommand completeCmd =
        new CompoundCommand("Destroy and Create Compartment Command"); // $NON-NLS-1$

    // the commands to hide compartment
    for (EditPartRepresentation current : this.viewsToDestroy) {
      if (current instanceof CompartmentEditPartRepresentation) {
        CompartmentEditPartRepresentation currentRepresentation =
            (CompartmentEditPartRepresentation) current;
        View currentView = currentRepresentation.getCompartmentView();
        EditPart currentEditPart =
            currentRepresentation
                .getRepresentedEditPart(); // should not be null, because a view to  delete should
                                           // be visible, and so have an existing associated edit
                                           // part.
        // if null, try to find it using gmf methods from the view

        if (currentEditPart == null) {
          Activator.log.debug(
              "Warning! An edit part representation wished to destroy a view, but no edit part exists currently!"
                  + current);
          currentEditPart =
              DiagramEditPartsUtil.getEditPartFromView(currentView, selectedElements.get(0))
                  .getParent();
        }

        if (currentEditPart != null) {
          req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.HIDE, currentView);
          req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
          Command tmp = currentEditPart.getCommand(req);
          if (tmp != null && tmp.canExecute()) {
            completeCmd.add(tmp);
          }
        } else {
          Activator.log.debug(
              "Impossible to find an edit part for the given representation: " + current);
        }
      }

      //			if(current instanceof View) {
      //				EditPart ep = DiagramEditPartsUtil.getEditPartFromView((View)current,
      // selectedElements.get(0)).getParent();
      //				req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.HIDE,
      // ((View)current).getType());
      //				req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
      //				Command tmp = ep.getCommand(req);
      //				if(tmp != null && tmp.canExecute()) {
      //					completeCmd.add(tmp);
      //				}
      //			} else if(current instanceof CompartmentTitleRepresentation) {
      //				ShowHideTitleOfCompartmentCommand tmp = new
      // ShowHideTitleOfCompartmentCommand(this.domain,
      // (View)((CompartmentTitleRepresentation)current).getRealObject(), false);
      //				if(tmp != null && tmp.canExecute()) {
      //					completeCmd.add(new ICommandProxy(tmp));
      //				}
      //			}
    }

    // the command to show compartment
    for (EditPartRepresentation current : this.viewsToCreate) {
      if (current instanceof CompartmentEditPartRepresentation) {
        CompartmentEditPartRepresentation currentRepresentation =
            (CompartmentEditPartRepresentation) current;
        View currentView = currentRepresentation.getCompartmentView();
        EditPartRepresentation parentRepresentation =
            currentRepresentation.getParentRepresentation();
        IGraphicalEditPart parentEditPart = parentRepresentation.getRepresentedEditPart();
        if (currentView != null && parentEditPart != null) {
          req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.SHOW, currentView);
          req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
          Command tmp = parentEditPart.getCommand(req);
          if (tmp != null && tmp.canExecute()) {
            completeCmd.add(tmp);
          }
        }
      }

      //			if(current instanceof View) {
      //				EditPart ep = CompartmentUtils.getCompartmentTitleRepresentation(rep,
      // (View)current).getParent();
      //				req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.SHOW,
      // ((View)current).getType());
      //				req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
      //				Command tmp = ep.getCommand(req);
      //				if(tmp != null && tmp.canExecute()) {
      //					completeCmd.add(tmp);
      //				}
      //			} else if(current instanceof CompartmentTitleRepresentation) {
      //				CompartmentTitleRepresentation compartmentTitleRep =
      // (CompartmentTitleRepresentation)current;
      //				final View view = (View)compartmentTitleRep.getRealObject();
      //				Style style = view.getStyle(NotationPackage.eINSTANCE.getTitleStyle());
      //				if(style == null) {
      //					// style is not existing yet (true for models created with Papyrus 0.7.x) => create now
      //					// See bug 351084
      //					completeCmd.add(new ICommandProxy(new AbstractTransactionalCommand(domain, "Create
      // title style", Collections.EMPTY_LIST) { //$NON-NLS-1$
      //
      //						public CommandResult doExecuteWithResult(IProgressMonitor dummy, IAdaptable info) {
      //							TitleStyle style =
      // (TitleStyle)view.createStyle(NotationPackage.eINSTANCE.getTitleStyle());
      //							style.setShowTitle(false);
      //							return CommandResult.newOKCommandResult();
      //						}
      //					}));
      //				}
      //				ShowHideTitleOfCompartmentCommand tmp = new
      // ShowHideTitleOfCompartmentCommand(this.domain, view, true);
      //				if(tmp != null && tmp.canExecute()) {
      //					completeCmd.add(new ICommandProxy(tmp));
      //				}
      //			}
    }

    // now sets the visibility for all shown views

    for (CompartmentEditPartRepresentation currentRepresentation : visibleRepresentations) {
      final View currentView = currentRepresentation.getCompartmentView();
      boolean newVisibility = currentRepresentation.isTitleVisible();
      boolean oldVisibility = CompartmentUtils.isCompartmentTitleVisible(currentView);

      IGraphicalEditPart parentEditPart =
          currentRepresentation.getParentRepresentation().getRepresentedEditPart();
      final TransactionalEditingDomain domain = parentEditPart.getEditingDomain();
      // visibility has changed => change the model
      if (newVisibility != oldVisibility) {
        Style style = currentView.getStyle(NotationPackage.eINSTANCE.getTitleStyle());
        if (style == null) {
          // style is not existing yet (true for models created with Papyrus 0.7.x) => create now
          // See bug 351084
          completeCmd.add(
              new ICommandProxy(
                  new AbstractTransactionalCommand(
                      domain, "Create title style", Collections.EMPTY_LIST) { // $NON-NLS-1$

                    @Override
                    public CommandResult doExecuteWithResult(
                        IProgressMonitor dummy, IAdaptable info) {
                      TitleStyle style =
                          (TitleStyle)
                              currentView.createStyle(NotationPackage.eINSTANCE.getTitleStyle());
                      style.setShowTitle(false);
                      return CommandResult.newOKCommandResult();
                    }
                  }));
        }
        ShowHideTitleOfCompartmentCommand tmp =
            new ShowHideTitleOfCompartmentCommand(domain, currentView, newVisibility);
        if (tmp != null && tmp.canExecute()) {
          completeCmd.add(new ICommandProxy(tmp));
        }
      }
    }

    return completeCmd;
  }
  /**
   * Gets the show link command from updater link descriptor.
   *
   * @param linkToShow the link to show
   * @param domain2NotationMap the domain2 notation map
   * @param descriptor the descriptor
   * @return the show link command from updater link descriptor
   */
  private ICommand getShowLinkCommandFromUpdaterLinkDescriptor(
      final EObject linkToShow,
      final Domain2Notation domain2NotationMap,
      UpdaterLinkDescriptor descriptor) {
    ConnectorUtils connectorUtils = new ConnectorUtils();

    if (descriptor != null) {

      Set<View> sourceViewList = domain2NotationMap.get(descriptor.getSource());
      Set<View> targetViewList = domain2NotationMap.get(descriptor.getDestination());

      final Set<View> linkSet = domain2NotationMap.get(linkToShow);

      CompositeCommand compositeCommand = new CompositeCommand("Restore All Related Links");
      for (View sourceView : sourceViewList) {
        for (View targetView : targetViewList) {
          if (canDisplayExistingLinkBetweenViews(linkToShow, sourceView, targetView)) {

            if (ConnectorUtils.canDisplayExistingConnectorBetweenViewsAccordingToNestedPaths(
                (Connector) linkToShow, sourceView, targetView)) {
              boolean alreadyDisplayed = false;
              if (linkSet != null) {
                for (View viewLink : linkSet) {
                  boolean linkForViews =
                      isLinkForViews(
                          (org.eclipse.gmf.runtime.notation.Connector) viewLink,
                          sourceView,
                          targetView);
                  alreadyDisplayed = alreadyDisplayed || linkForViews;
                }
              }

              if (!alreadyDisplayed) {
                EditPart sourceEditPart = getEditPartFromView(sourceView);
                EditPart targetEditPart = getEditPartFromView(targetView);

                // If the parts are still null...
                if (sourceEditPart == null || targetEditPart == null) {
                  return null;
                }
                String semanticHint = getSemanticHint(linkToShow);
                CreateConnectionViewRequest.ConnectionViewDescriptor viewDescriptor =
                    new CreateConnectionViewRequest.ConnectionViewDescriptor(
                        descriptor.getSemanticAdapter(),
                        semanticHint,
                        ViewUtil.APPEND,
                        false,
                        ((GraphicalEditPart) getHost()).getDiagramPreferencesHint());
                CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(viewDescriptor);
                ccr.setType(org.eclipse.gef.RequestConstants.REQ_CONNECTION_START);
                ccr.setSourceEditPart(sourceEditPart);
                sourceEditPart.getCommand(ccr);
                ccr.setTargetEditPart(targetEditPart);
                ccr.setType(org.eclipse.gef.RequestConstants.REQ_CONNECTION_END);
                CommandProxy commandProxy = new CommandProxy(targetEditPart.getCommand(ccr));
                compositeCommand.add(commandProxy);
              }
            }
          }
        }
      }
      return compositeCommand;
    }
    return null;
  }