Esempio n. 1
0
  @Override
  @Execute
  public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    if (bm.wIsSet("viewer") && Clipboard.instance().getInternalOrNativeEntityContents() == null) {
      IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
      if (ClipboardUtils.hasTextFocus(viewer) || ClipboardUtils.hasTextSeletion(viewer)) {
        IEntity focusEntity = bm.wGet("focusEntity");
        ITextualEntityPart focusPart =
            (ITextualEntityPart) viewer.getEditPartRegistry().get(focusEntity);

        String textContents = Clipboard.instance().getTextContents();
        Command command = focusPart.getCommand(TextualRequest.createInsertRequest(textContents));

        CommandStack commandStack = viewer.getEditDomain().getCommandStack();
        if (command instanceof ITextCommand) {
          TextTransactionCommand transactionCommand = new TextTransactionCommand();
          transactionCommand.setModel(focusEntity);
          transactionCommand.merge((ITextCommand) command);
          transactionCommand.setLabel(getLabel(bm));
          commandStack.execute(transactionCommand);
        } else {
          command.setLabel(getLabel(bm) + " text");
          commandStack.execute(command);
        }
        return;
      }
    }
    super.execute(bm);
  }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.papyrus.layout.LayouttoolInterface#execute(java.util.Map)
  */
 public void execute(Map<EditPart, Rectangle> map) {
   TransactionalEditingDomain ted = getTransactionalEditingDomain();
   if (ted != null) {
     CommandStack cs = null;
     // Add a command to apply new bounds of all nodes
     for (Entry<EditPart, Rectangle> s : map.entrySet()) {
       SetBoundsCommand boundsCommand =
           new SetBoundsCommand(
               ted,
               "apply layout",
               new EObjectAdapter((View) s.getKey().getModel()),
               s.getValue());
       command.add(boundsCommand);
       GraphicalEditPart gep = (GraphicalEditPart) s.getKey();
       if (cs == null) {
         cs = gep.getViewer().getEditDomain().getCommandStack();
       }
     }
     try {
       // Execute layout commands with animation
       Animation.markBegin();
       cs.execute(new ICommandProxy(command));
       Animation.run(1000);
     } catch (Exception e) {
       Activator.getDefault().log(e.getMessage() + " : Cannot apply new bounds of all nodes", e);
     }
   }
 }
 /**
  * Executes the specified command.
  *
  * @param command a command
  */
 private void execute(Command command) {
   CommandStack commandStack = getCommandStack();
   if (commandStack != null) {
     commandStack.execute(command);
   } else {
     throw new IllegalArgumentException("Could not execute command. No command stack available");
   }
 }
 @SuppressWarnings("unchecked")
 public void run() {
   List<ICloneableModel> model = (List<ICloneableModel>) Clipboard.getDefault().getContents();
   if (model == null) {
     return;
   }
   CommandStack stack =
       (CommandStack) ((VisualDBEditor) getWorkbenchPart()).getAdapter(CommandStack.class);
   stack.execute(new PasteCommand(model));
 }
 public void run(IAction action) {
   CommandStack commandStack;
   String eventType = getEventType(action.getId());
   if (eventType == null) return;
   if (targetPart instanceof ContentOutline) {
     commandStack =
         ((DesignerOutlineViewer) ((ContentOutline) targetPart).getCurrentPage())
             .getCommandStack();
   } else if (targetPart instanceof DesignerEditor) {
     commandStack = ((DesignerEditor) targetPart).getCommandStack();
   } else return;
   GraphElementAddActionCommand command = new GraphElementAddActionCommand();
   command.setTarget(getTargetElement());
   command.setEventType(eventType);
   commandStack.execute(command);
 }
 protected void doubleClicked() {
   super.doubleClicked();
   // open custom editor pane if one exists
   WorkDefinition workDefinition = getWorkDefinition();
   if (workDefinition instanceof WorkDefinitionExtension) {
     String editor = ((WorkDefinitionExtension) workDefinition).getCustomEditor();
     if (editor != null) {
       Work work = openEditor(editor, workDefinition);
       if (work != null) {
         SetWorkCommand setCommand = new SetWorkCommand();
         setCommand.setPropertyValue(work);
         CommandStack stack = getViewer().getEditDomain().getCommandStack();
         stack.execute(setCommand);
       }
     }
   }
 }
  /**
   * ggu Comment method "changeContextOrder".
   *
   * <p>order the context parameter
   */
  public static boolean changeContextOrder(
      TreeViewer viewer, IContextModelManager modelManager, boolean up) {
    if (viewer == null || modelManager == null) {
      return false;
    }
    final ISelection selection = viewer.getSelection();
    if (selection == null || selection.isEmpty()) {
      return false;
    }
    if (!(selection instanceof IStructuredSelection)) {
      return false;
    }
    IStructuredSelection sSection = (IStructuredSelection) selection;
    if (sSection.size() != 1) { // not support multi-selection
      return false;
    }

    Object element = sSection.getFirstElement();
    IContextParameter movedParam = null;
    if (element instanceof ContextVariableTabParentModel) {
      movedParam = ((ContextVariableTabParentModel) element).getContextParameter();
    }

    if (element instanceof ContextTableTabParentModel) {
      movedParam = ((ContextTableTabParentModel) element).getContextParameter();
    }
    if (movedParam == null) {
      return false;
    }

    OrderContextParameterCommand orderCommand =
        new OrderContextParameterCommand(modelManager.getContextManager(), movedParam, up);
    final CommandStack commandStack = modelManager.getCommandStack();
    if (commandStack != null) {
      commandStack.execute(orderCommand);
    } else {
      orderCommand.execute();
    }
    //
    modelManager.refresh();

    revertTreeSelection(viewer, movedParam);

    return orderCommand.isExecution();
  }
  /**
   * ggu Comment method "changeContextOrder".
   *
   * <p>order the context parameter
   */
  public static boolean changeContextOrder(
      ISelection selObj, IContextModelManager modelManager, boolean up) {
    if (selObj == null || selObj.isEmpty()) {
      return false;
    }
    if (!(selObj instanceof IStructuredSelection)) {
      return false;
    }
    IStructuredSelection sSection = (IStructuredSelection) selObj;
    if (sSection.size() != 1) { // not support multi-selection
      return false;
    }

    Object element = sSection.getFirstElement();
    Object model = ((ContextTreeNode) element).getTreeData();
    IContextParameter movedParam = null;

    if (model instanceof ContextTableTabParentModel) {
      movedParam = ((ContextTableTabParentModel) model).getContextParameter();
    } else if (model instanceof ContextTableTabChildModel) { // for bug TDI-32821
      movedParam = ((ContextTableTabChildModel) model).getContextParameter();
    }
    if (movedParam == null) {
      return false;
    }

    OrderContextParameterCommand orderCommand =
        new OrderContextParameterCommand(modelManager.getContextManager(), movedParam, up);
    final CommandStack commandStack = modelManager.getCommandStack();
    if (commandStack != null) {
      commandStack.execute(orderCommand);
    } else {
      orderCommand.execute();
    }

    modelManager.refresh();

    return orderCommand.isExecution();
  }
Esempio n. 9
0
  private void deleteConnections(Collection<ConnectionFigure> connections) {
    boolean dirty = false;
    List<Connection> connectionsToDelete = new ArrayList<>();
    for (ConnectionFigure connectionFigure : connections) {
      connectionsToDelete.add(connectionFigure.getConnection());
      dirty = true;
    }

    if (editorsCommandStack == null) {
      description.removeConnections(connectionsToDelete);
      targetTreeViewer.refresh();
      sourceTreeViewer.refresh();
    } else {
      ConnectionDeleteCommand connectionDeleteCommand =
          new ConnectionDeleteCommand(description, connectionsToDelete);
      editorsCommandStack.execute(connectionDeleteCommand);
    }

    if (dirty) {
      repaint();
    }
  }
 protected void execute(Command command) {
   CommandStack commandStack = (CommandStack) editor.getAdapter(CommandStack.class);
   commandStack.execute(command);
 }