/**
   * Override to : -> Put in "Movin state" this edit part and all its children which are Group
   * Framework concern
   */
  @Override
  public Command getCommand(Request request) {
    if (request instanceof ChangeBoundsRequest) {
      final ChangeBoundsRequest req = (ChangeBoundsRequest) request;
      CompositeCommand cc = new CompositeCommand("GroupNotifyingEditPolicy ");
      for (final EditPart part : Utils.getTargetedEditPart(req)) {
        ICommand cmd =
            getGroupRequestAdvisor()
                .notifyGroupFramework(
                    new AbstractGroupRequest(
                        (IGraphicalEditPart) getHost(),
                        Utils.getChangeBoundsRequestCopy(req, part),
                        part,
                        getTargetGroupDescriptor(part)) {

                      public GroupRequestType getGroupRequestType() {
                        return GroupRequestType.MOVE;
                      }
                    });
        if (cmd != null && cmd.canExecute()) {
          cc.compose(cmd);
        }
      }
      stopMovingPartState(req);
      if (cc != null && cc.canExecute()) {
        return new ICommandProxy(cc);
      }
    }
    return null;
  }
コード例 #2
0
 /** @generated */
 protected void doConfigure(Assign newElement, IProgressMonitor monitor, IAdaptable info)
     throws ExecutionException {
   IElementType elementType = ((CreateElementRequest) getRequest()).getElementType();
   ConfigureRequest configureRequest =
       new ConfigureRequest(getEditingDomain(), newElement, elementType);
   configureRequest.setClientContext(((CreateElementRequest) getRequest()).getClientContext());
   configureRequest.addParameters(getRequest().getParameters());
   ICommand configureCommand = elementType.getEditCommand(configureRequest);
   if (configureCommand != null && configureCommand.canExecute()) {
     configureCommand.execute(monitor, info);
   }
 }
  /** {@inheritDoc} */
  @Override
  public ICommand create(ConfigureRequest request) {

    ICommand configureCommand = null;

    Shell shell = Display.getDefault().getActiveShell();
    // Start dialog to identify the new part type
    Property part = (Property) request.getElementToConfigure();
    Package partPkg = part.getNearestPackage();

    CreateOrSelectBlockPropertyTypeDialog dialog =
        new CreateOrSelectBlockPropertyTypeDialog(shell, partPkg);
    dialog.open();
    if (dialog.getReturnCode() == Window.OK) {

      final ICommand typeCreationCommand = dialog.getNewTypeCreateCommand();
      final Type partType = (Type) dialog.getExistingType();

      // Abort if type creation command exists but is not executable
      if ((typeCreationCommand != null) && (!typeCreationCommand.canExecute())) {
        return cancelCommand(request);
      } else {
        configureCommand = CompositeCommand.compose(configureCommand, typeCreationCommand);
      }

      // Create the configure command that will set the part type
      ICommand setTypeCommand =
          new ConfigureElementCommand(request) {

            @Override
            protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
                throws ExecutionException {

              Property part = (Property) getElementToEdit();
              if (partType != null) {
                part.setType(partType);
              } else {
                Type newType = (Type) GMFCommandUtils.getCommandEObjectResult(typeCreationCommand);
                part.setType(newType);
              }
              return CommandResult.newOKCommandResult(part);
            }
          };

      configureCommand = CompositeCommand.compose(configureCommand, setTypeCommand);
      return configureCommand;
    }

    return cancelCommand(request);
  }
 /** @generated */
 protected void doConfigure(
     ScopeToCompositeActionMapping newElement, IProgressMonitor monitor, IAdaptable info)
     throws ExecutionException {
   IElementType elementType = ((CreateElementRequest) getRequest()).getElementType();
   ConfigureRequest configureRequest =
       new ConfigureRequest(getEditingDomain(), newElement, elementType);
   configureRequest.setClientContext(((CreateElementRequest) getRequest()).getClientContext());
   configureRequest.addParameters(getRequest().getParameters());
   configureRequest.setParameter(CreateRelationshipRequest.SOURCE, getSource());
   configureRequest.setParameter(CreateRelationshipRequest.TARGET, getTarget());
   ICommand configureCommand = elementType.getEditCommand(configureRequest);
   if (configureCommand != null && configureCommand.canExecute()) {
     configureCommand.execute(monitor, info);
   }
 }
コード例 #5
0
  @Test
  public void testCreationAndDestructionOnRequirement() {
    Object result =
        ModelExplorerUtils.executeCreateNestedEditorHandlerInModelExplorer(
            papyrusEditor,
            TableCreationInSysMLModelTest.view,
            AllTests.COMMAND_ID,
            TableCreationInSysMLModelTest.requirement1,
            BUNDLE_ID);
    // to refresh the table content
    DisplayUtils.flushEventLoop();
    Assert.assertTrue(result instanceof NatTableEditor);
    NatTableEditor editor = (NatTableEditor) result;
    NattableModelManager manager =
        (NattableModelManager) editor.getAdapter(INattableModelManager.class);
    Assert.assertNotNull(manager);
    Table table = manager.getTable();
    Assert.assertEquals(AllTests.REQUIREMENT_TABLE_ID, table.getTableConfiguration().getType());

    IAxisManager rowAxisManager = manager.getRowAxisManager();
    Collection<Object> managedAxis = rowAxisManager.getAllManagedAxis();
    Assert.assertEquals(2, managedAxis.size());
    Assert.assertTrue(managedAxis.contains(nestedRequirement1));
    Assert.assertTrue(managedAxis.contains(nestedRequirement2));

    Assert.assertEquals(
        managedAxis.size(), rowAxisManager.getTableManager().getRowElementsList().size());
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement1));
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement2));

    final TransactionalEditingDomain domain =
        (TransactionalEditingDomain) papyrusEditor.getAdapter(TransactionalEditingDomain.class);
    Assert.assertNotNull(domain);
    IElementEditService provider =
        ElementEditServiceUtils.getCommandProvider(TableCreationInSysMLModelTest.requirement1);
    Assert.assertNotNull(provider);
    CreateElementRequest request =
        new CreateElementRequest(
            domain, TableCreationInSysMLModelTest.requirement1, SysMLElementTypes.REQUIREMENT);
    final ICommand creationCommand = provider.getEditCommand(request);
    Assert.assertNotNull(creationCommand);
    Assert.assertTrue(creationCommand.canExecute());

    domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(creationCommand));
    final NamedElement createdElement = (NamedElement) request.getNewElement();
    NamedElement requirement =
        TableCreationInSysMLModelTest.requirement1.getMember(
            createdElement.getName()); // $NON-NLS-1$
    Assert.assertNotNull(requirement);
    nestedRequirement3 = (Class) requirement;

    // to refresh the table content
    DisplayUtils.flushEventLoop();
    managedAxis = rowAxisManager.getAllManagedAxis();
    Assert.assertEquals(3, managedAxis.size());
    Assert.assertTrue(managedAxis.contains(nestedRequirement1));
    Assert.assertTrue(managedAxis.contains(nestedRequirement2));
    Assert.assertTrue(managedAxis.contains(nestedRequirement3));
    Assert.assertEquals(
        managedAxis.size(), rowAxisManager.getTableManager().getRowElementsList().size());
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement1));
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement2));
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement3));

    DestroyElementRequest destroyRequest =
        new DestroyElementRequest(domain, nestedRequirement3, false);
    provider = ElementEditServiceUtils.getCommandProvider(nestedRequirement3);
    final ICommand destroyCommand = provider.getEditCommand(destroyRequest);
    Assert.assertNotNull(destroyCommand);
    Assert.assertTrue(destroyCommand.canExecute());

    domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(destroyCommand));
    requirement =
        TableCreationInSysMLModelTest.requirement1.getMember(
            createdElement.getName()); // $NON-NLS-1$
    Assert.assertNull(requirement);
    nestedRequirement3 = (Class) requirement;

    // to refresh the table content
    DisplayUtils.flushEventLoop();

    managedAxis = rowAxisManager.getAllManagedAxis();
    Assert.assertEquals(2, managedAxis.size());
    Assert.assertTrue(managedAxis.contains(nestedRequirement1));
    Assert.assertTrue(managedAxis.contains(nestedRequirement2));

    Assert.assertEquals(
        managedAxis.size(), rowAxisManager.getTableManager().getRowElementsList().size());
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement1));
    Assert.assertTrue(
        rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement2));
  }
コード例 #6
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.emf.common.command.AbstractCommand#canExecute()
  */
 @Override
 public boolean canExecute() {
   return gmfCommand.canExecute();
 }
コード例 #7
0
  /**
   *
   *
   * <pre>
   * {@inheritDoc}
   *
   * Extends the default resize command by :
   * - fixing possible Port location issues before resizing parent
   * - make the default parent resize
   * - update the Port location after resize (uses the side of the parent where the Port is attached before resize)
   * </pre>
   */
  @Override
  protected Command getResizeCommand(ChangeBoundsRequest request) {

    // Prepare command to move the affixed children as well (and an optional fix command)
    CompoundCommand updatePortLocationsCommand =
        new CompoundCommand("Update border items location");
    CompoundCommand fixPortLocationsCommand = new CompoundCommand("Fix border items location");

    Iterator<?> it = getHost().getChildren().iterator();
    while (it.hasNext()) {
      Object tmp = it.next();
      if (!(tmp instanceof IBorderItemEditPart)) {
        continue;
      }

      IBorderItemEditPart borderItem = (IBorderItemEditPart) tmp;
      Shape borderItemView = (Shape) borderItem.getNotationView();
      TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(borderItemView);

      // Fix possible location issue in BorderItem bounds in notation model
      ICommand fixPortLocationCommand =
          new FixPortLocationCommand(editingDomain, borderItem, (GraphicalEditPart) getHost());
      if (fixPortLocationCommand.canExecute()) {
        fixPortLocationsCommand.add(new ICommandProxy(fixPortLocationCommand));
      }

      ICommand updatePortLocationCommand =
          new UpdatePortLocationCommand(
              editingDomain,
              (GraphicalEditPart) getHost(),
              borderItem,
              borderItem.getBorderItemLocator().getCurrentSideOfParent());
      if (updatePortLocationCommand.canExecute()) {
        updatePortLocationsCommand.add(new ICommandProxy(updatePortLocationCommand));
      }
    }

    // Create the complete resize command
    CompoundCommand resizeCommand = new CompoundCommand("Resize command");

    // Add command to fix border item locations.
    // The role of this command is to make sure that the Port is correctly located (here this means
    // that the figure and the view have the same location) before resizing its parent.
    // See bug. https://bugs.eclipse.org/bugs/show_bug.cgi?id=354814.
    if (!fixPortLocationsCommand.isEmpty()) {
      resizeCommand.add(fixPortLocationsCommand);
    }

    // Add command to update locations
    resizeCommand.add(super.getResizeCommand(request));

    // Add command to update border item locations.
    // This command uses the border side of the border item before the resize action, and thus
    // requires that the Port location is correct. Previous versions did not move the IBorderItem,
    // this is the reason
    // why a fix on the fly may be required.
    // See bug. https://bugs.eclipse.org/bugs/show_bug.cgi?id=354814.
    if (!updatePortLocationsCommand.isEmpty()) {
      resizeCommand.add(updatePortLocationsCommand);
    }

    return resizeCommand;
  }