コード例 #1
0
  /**
   * Close selected page.
   *
   * @param pageMngr
   */
  public void execute(final Diagram diagram, final IEditorPart editorPart) {

    TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain();
    if (editingDomain != null) {
      InputDialog dialog =
          new InputDialog(
              Display.getCurrent().getActiveShell(),
              "Rename an existing diagram",
              "New name:",
              diagram.getName(),
              null);
      if (dialog.open() == Window.OK) {
        final String name = dialog.getValue();
        if (name != null && name.length() > 0) {

          Command command =
              new RecordingCommand(editingDomain) {

                @Override
                protected void doExecute() {
                  diagram.setName(name);
                }
              };

          editingDomain.getCommandStack().execute(command);
        }
      }
    }
  }
コード例 #2
0
  protected void removeAction() {
    // Erase image content
    if (getElement() instanceof Image) {

      TransactionalEditingDomain dom = EditorUtils.getTransactionalEditingDomain();
      AbstractTransactionalCommand operation =
          new AbstractTransactionalCommand(dom, "Remove Image content", null) {

            /** {@inheritDoc} */
            @Override
            protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
                throws ExecutionException {
              try {
                ImageUtil.setContent((Image) getElement(), null);
              } catch (Exception ex) {
                return CommandResult.newErrorCommandResult(ex);
              }
              return CommandResult.newOKCommandResult();
            }
          };

      dom.getCommandStack().execute(new GMFtoEMFCommandWrapper(operation));

      refresh();
    }
  }
コード例 #3
0
 /** Add the created invoked object to its selected parent */
 protected void addParameter(Parameter createdParameter) {
   TransactionalEditingDomain editingdomain = EditorUtils.getTransactionalEditingDomain();
   // Let the command find the relation on its own.
   Command addCmd =
       AddCommand.create(
           editingdomain, parameterOwner, null, Collections.singleton(createdParameter));
   addCmd.execute();
 }
コード例 #4
0
 /** Navigate to the linked element. Open it in model editor and print its properties. */
 protected void navigateToElement() {
   IMultiDiagramEditor editor = EditorUtils.getMultiDiagramEditor();
   IViewReference[] views = editor.getSite().getPage().getViewReferences();
   for (IViewReference view : views) {
     IWorkbenchPart part = view.getPart(false);
     if (part instanceof CommonNavigator) {
       CommonNavigator navigator = (CommonNavigator) part;
       // set focus to navigator, otherwise, diagram view will reset the selection
       navigator.setFocus();
       navigator.selectReveal(new StructuredSelection(element));
     }
   }
 }
コード例 #5
0
  /**
   * Execute the command : create the model element, then the corresponding views
   *
   * @see org.eclipse.gef.commands.Command#execute()
   */
  @Override
  public void execute() {
    Object constraint = null;
    if (elementCreationCommand != null) {
      elementCreationCommand.execute();
      constraint = elementCreationCommand.getICommand().getCommandResult().getReturnValue();
    }
    if (constraint instanceof Constraint && compartment != null && type != null) {
      // construct the complete command for views creation and execute it.
      viewsCreationCommand = new CompoundCommand();
      // creation of the node by the compartment
      ViewDescriptor descriptor =
          new CreateViewRequest.ViewDescriptor(
              new EObjectAdapter((EObject) constraint),
              Node.class,
              type.getSemanticHint(),
              compartment.getDiagramPreferencesHint());
      CreateViewRequest request = new CreateViewRequest(descriptor);
      Command nodeCreationCommand = compartment.getCommand(request);
      viewsCreationCommand.add(nodeCreationCommand);

      // try and recover the created edit part, then create the link
      if (linkedActionEditPart != null && getLinkType() != null) {
        IAdaptable targetAdapter = extractResult(nodeCreationCommand);
        if (targetAdapter != null) {
          IAdaptable sourceAdapter = new SemanticAdapter(null, linkedActionEditPart.getModel());
          // descriptor of the link
          CreateConnectionViewRequest.ConnectionViewDescriptor linkdescriptor =
              new CreateConnectionViewRequest.ConnectionViewDescriptor(
                  getLinkType(),
                  getLinkType().getSemanticHint(),
                  compartment.getDiagramPreferencesHint());
          CommonDeferredCreateConnectionViewCommand aLinkCommand =
              new CommonDeferredCreateConnectionViewCommand(
                  EditorUtils.getTransactionalEditingDomain(),
                  getLinkType().getSemanticHint(),
                  sourceAdapter,
                  targetAdapter,
                  compartment.getViewer(),
                  compartment.getDiagramPreferencesHint(),
                  linkdescriptor,
                  null);
          aLinkCommand.setElement((EObject) constraint);
          viewsCreationCommand.add(new ICommandProxy(aLinkCommand));
        }
      }
      viewsCreationCommand.execute();
    }
  }
コード例 #6
0
 /**
  * Execute the passed Runnable within a command
  *
  * @param label
  * @param command
  */
 public static void exec(String label, final Runnable command) {
   TransactionalEditingDomain domain = EditorUtils.getTransactionalEditingDomain();
   IOperationHistory history = OperationHistoryFactory.getOperationHistory();
   try {
     history.execute(
         new AbstractTransactionalCommand(domain, label, Collections.EMPTY_LIST) {
           @Override
           public CommandResult doExecuteWithResult(IProgressMonitor dummy, IAdaptable info) {
             command.run();
             return CommandResult.newOKCommandResult();
           }
         },
         null,
         null);
   } catch (ExecutionException e) {
     e.printStackTrace();
   }
 }
コード例 #7
0
  /** {@inheritDoc} */
  public Object[] getElements(Object inputElement) {
    try {
      IPageMngr iPageMngr = EditorUtils.getIPageMngr();
      Object[] result = iPageMngr.allPages().toArray();

      List<Object> res = new ArrayList<Object>();
      for (Object current : result) {
        if (current != null /* && current instanceof PapyrusTableInstance */) {
          //					 if the model is a little bit corrupted, we can have a null element in the list
          res.add(current);
        }
      }
      return res.toArray();

    } catch (Exception e) {
      Activator.log.error(e);
    }
    return null;
  }
コード例 #8
0
  @SuppressWarnings("deprecation")
  public void process(
      DiResourceSet diResourceSet, IFile newFile, String diagramCategoryId, String path) {

    createPapyrusModels(diResourceSet, newFile);

    // initDomainModel(diResourceSet, newFile, diagramCategoryId);
    createEmptyDomainModel(diResourceSet, diagramCategoryId);

    // initDiagrams(diResourceSet, null, "uml");
    List<ICreationCommand> creationCommands =
        new ArrayList<ICreationCommand>(); // getDiagramKindsFor("uml");
    creationCommands.add((ICreationCommand) new CreateSequenceDiagramCommand());
    String diagramName = "NewSequenceDiagram";
    if (creationCommands.isEmpty()) {
      EditorUtils.getTransactionalIPageMngr(
          diResourceSet.getDiResource(), diResourceSet.getTransactionalEditingDomain());
    } else {
      for (int i = 0; i < creationCommands.size(); i++) {
        creationCommands.get(i).createDiagram(diResourceSet, null, diagramName);
      }
    }

    try {
      diResourceSet.save(new NullProgressMonitor());
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    String sourceDir = newFile.getLocation().removeLastSegments(1).toOSString();
    String targitDir = new Path(path).removeLastSegments(1).toOSString();
    String filename = newFile.getLocation().removeFileExtension().lastSegment();

    moveFile(sourceDir, targitDir, filename, "di");
    moveFile(sourceDir, targitDir, filename, "notation");
    moveFile(sourceDir, targitDir, filename, "uml");

    //		openDiagram(newFile);
  }
コード例 #9
0
  protected void browseAction() {
    FileDialog fd = new FileDialog(composite.getShell());
    String extensions[] = {"*.jpg;*.bmp;*.ico;*.gif;*.png;*.wmf;*.emf"}; // $NON-NLS-1$
    fd.setFilterExtensions(extensions);
    String iconSelected = fd.open();

    // No image selected
    if (iconSelected == null) {
      return;
    }

    if (getElement() instanceof Image) {

      final File imgFile = new File(iconSelected);

      TransactionalEditingDomain domain = EditorUtils.getTransactionalEditingDomain();
      AbstractTransactionalCommand operation =
          new AbstractTransactionalCommand(domain, "Set Image content", null) {

            /** {@inheritDoc} */
            @Override
            protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
                throws ExecutionException {
              try {
                ImageUtil.setContent((Image) getElement(), imgFile);
                ((Image) getElement()).setFormat(PAPYRUS_FORMAT);
              } catch (Exception ex) {
                return CommandResult.newErrorCommandResult(ex);
              }
              return CommandResult.newOKCommandResult();
            }
          };
      domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(operation));

      refresh();
    }
  }