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));
 }
  /** 将工作流树节点对象保存到指定目录下 文件名为该对象的id */
  public static void SaveFileModelToFile(FileModel fileModel) throws IOException {
    if (fileModel == null) {
      logger.error("传入的FileModel的为空,保存失败!");
      return;
    }

    //		File file = fileModel.getFile();
    // 数据库设计文件
    File spdFile =
        new File(
            SystemConstants.WORKSPACEPATH,
            fileModel.getFolderName() + File.separator + SystemConstants.ZIP_FILE_SUNCARDDESIGNER);
    if (!spdFile.exists()) {
      spdFile.createNewFile();
    }

    // 表格初始化信息文件
    File spddFile =
        new File(
            SystemConstants.WORKSPACEPATH,
            fileModel.getFolderName()
                + File.separator
                + SystemConstants.ZIP_FILE_SUNCARDDESIGNER_DATA);
    if (!spddFile.exists()) {
      spddFile.createNewFile();
    }
    //		// 存放表格初始化信息的文件夹
    //		File spddFolder = new File(SystemConstants.WORKSPACEPATH,
    //				fileModel.getFolderName() + File.separator +
    // SystemConstants.ZIP_FILE_SUNCARDDESIGNER_DATA_FOLDER + File.separator);
    //		if(!spddFolder.exists()) {
    //			spddFolder.mkdirs();
    //		}

    Document document = SwitchObjAndXml.getDocFromFileModel(fileModel);
    // 写入设计文件信息
    OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(spdFile), "UTF-8");
    out.write(document.asXML());
    out.close();

    // 写入表格初始化信息
    document = SwitchObjAndXml.getInitTableDataDocFromFileModel(fileModel);
    out = new OutputStreamWriter(new FileOutputStream(spddFile), "UTF-8");
    out.write(document.asXML());
    out.close();

    // 给文件模型对应的CommandStack设定保存点
    CommandStack commandStack = DefaultViewPart.getFileCommandFromObj(fileModel);
    if (commandStack != null) {
      commandStack.markSaveLocation();
    }
  }
 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);
       }
     }
   }
 }
  /** 将工作流树节点对象保存到指定目录下 文件名为该对象的id */
  public static void SaveProjectModelToFile(ProjectModel projectModel) throws IOException {
    if (projectModel == null) {
      logger.error("传入的FileModel的为空,保存失败!");
      return;
    }

    // 数据库设计文件
    File ppdFile =
        new File(
            SystemConstants.PROJECTSPACEPATH,
            projectModel.getFolderName() + File.separator + SystemConstants.ZIP_FILE_PROJECT);
    if (!ppdFile.exists()) {
      ppdFile.createNewFile();
    }

    // 表格初始化信息文件
    File spddFile =
        new File(
            SystemConstants.PROJECTSPACEPATH,
            projectModel.getFolderName()
                + File.separator
                + SystemConstants.ZIP_FILE_SUNCARDDESIGNER_DATA);
    if (!spddFile.exists()) {
      spddFile.createNewFile();
    }

    Document document = SwitchObjAndXml.getDocFromProjectModel(projectModel);
    // 写入项目文件信息
    OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(ppdFile), "UTF-8");
    out.write(document.asXML());
    out.close();

    // 写入表格初始化信息
    document = SwitchObjAndXml.getInitTableDataDocFromProjectModel(projectModel);
    out = new OutputStreamWriter(new FileOutputStream(spddFile), "UTF-8");
    out.write(document.asXML());
    out.close();

    // 给文件模型对应的CommandStack设定保存点
    CommandStack commandStack =
        ProjectDefaultViewPart.getCommandStackFromProjectModel(projectModel);
    if (commandStack != null) {
      commandStack.markSaveLocation();
    }
  }
  /**
   * 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();
  }
  /**
   * Constructs a new {@link UndoablePropertySheetPage}.
   *
   * @param commandStack The {@link CommandStack} shared with the editor.
   * @param undoAction The global action handler to be registered for undo operations.
   * @param redoAction The global action handler to be registered for redo operations.
   */
  public UndoablePropertySheetPage(
      final CommandStack commandStack, IAction undoAction, IAction redoAction) {
    this.undoHandler = undoAction;
    this.redoHandler = redoAction;
    this.commandStack = commandStack;
    this.commandStackEventListener =
        new CommandStackEventListener() {

          public void stackChanged(CommandStackEvent event) {
            if (event.getDetail() == CommandStack.PRE_UNDO
                || event.getDetail() == CommandStack.PRE_REDO) {
              // ensure the property sheet entry looses its current edit
              // state, otherwise it may revert the undo/redo operation
              // within valueChanged when the editor is activated again.
              refresh();
            }
          }
        };
    commandStack.addCommandStackEventListener(commandStackEventListener);
    setRootEntry(new UndoablePropertySheetEntry(commandStack));
  }
Esempio n. 12
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();
    }
  }
 /**
  * Overwritten to unregister command stack listener.
  *
  * @see org.eclipse.ui.views.properties.PropertySheetPage#dispose()
  */
 public void dispose() {
   if (commandStack != null)
     commandStack.removeCommandStackEventListener(commandStackEventListener);
   super.dispose();
 }
 protected void execute(Command command) {
   CommandStack commandStack = (CommandStack) editor.getAdapter(CommandStack.class);
   commandStack.execute(command);
 }