コード例 #1
0
  @Override
  public PrettyPrintState print(EObject root) throws ModelCreatingException {
    // System.err.println("print open net root");
    getLayoutManager().setup();
    PrettyPrintState state = new PrettyPrintState(root);

    if (root instanceof PtNet) {
      PtNet net = (PtNet) root;

      for (Place p : net.getPlaces()) {
        state.append("place" + getWhiteSpace("ws") + "\"" + p.getName() + "\"");
        if (p.getToken() > 0)
          state.append(getWhiteSpace("ws") + "init" + getWhiteSpace("ws") + p.getToken());
        state.append(";" + getWhiteSpace("statement"));
      }
      state.append(getWhiteSpace("statement"));

      for (Transition t : net.getTransitions()) {
        state.append("trans" + getWhiteSpace("ws") + "\"" + t.getName() + "\"");
        state.append(getWhiteSpace("statement"));

        state.append("in");
        state.append(getWhiteSpace("blockstart"));
        for (Arc arc : t.getIncoming()) {
          state.append(
              getWhiteSpace("indent")
                  + "\""
                  + arc.getSource().getName()
                  + "\""
                  + getWhiteSpace("statement"));
        }
        state.append(getWhiteSpace("blockend") + getWhiteSpace("statement"));

        state.append("out");
        state.append(getWhiteSpace("blockstart"));
        for (Arc arc : t.getOutgoing()) {
          state.append(
              getWhiteSpace("indent")
                  + "\""
                  + arc.getTarget().getName()
                  + "\""
                  + getWhiteSpace("statement"));
        }
        state.append(";");
        state.append(getWhiteSpace("blockend") + getWhiteSpace("statement"));
        state.append(getWhiteSpace("statement"));
      }
    }

    return state;
  }
コード例 #2
0
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    PluginHelper plugin = hub.top.editor.Activator.getPluginHelper();
    try {
      /*
      if (!(window.getActivePage().getActiveEditor() instanceof
      		hub.top.editor.eclipse.IFrameWorkEditor ))
      	throw new Exception("Anonymize: action works in ServiceTechnology.org framework editors only.");

      // retrieve and prepare editor utils
      EditorUtil sourceEditor = ((IFrameWorkEditor)window.getActivePage().getActiveEditor()).getEditorUtil();
      EObject obj = sourceEditor.getCurrentResource().getContents().get(0);

      System.out.println(obj);
      */
      IEditorPart editor = window.getActivePage().getActiveEditor();

      Resource res = null;
      PtNet net = null;
      EditorUtil sourceEditor = null;

      if (editor instanceof DiagramDocumentEditor) {
        DiagramDocumentEditor diagEdit = (DiagramDocumentEditor) editor;
        net = (PtNet) diagEdit.getDiagram().getElement();
        res = diagEdit.getDiagram().eResource();
      } else if (editor instanceof hub.top.editor.eclipse.IFrameWorkEditor) {
        sourceEditor =
            ((IFrameWorkEditor) window.getActivePage().getActiveEditor()).getEditorUtil();
        net = (PtNet) sourceEditor.getCurrentRootModel();
        res = net.eResource();
      }

      if (net != null) {
        TransactionalEditingDomain editDomain =
            PtnetLoLAEditingDomainFactory.INSTANCE.getEditingDomain(
                net.eResource().getResourceSet());
        if (editDomain == null) editDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();

        CompoundCommand cc = new CompoundCommand();
        int placeNum = 0;
        for (Place p : net.getPlaces()) {
          String name = "p" + placeNum;
          SetCommand set =
              new SetCommand(editDomain, p, PtnetLoLAPackage.eINSTANCE.getNode_Name(), name);
          cc.append(set);
          placeNum++;
        }
        int transitionNum = 0;
        for (Transition t : net.getTransitions()) {
          String name = "t" + transitionNum;
          SetCommand set =
              new SetCommand(editDomain, t, PtnetLoLAPackage.eINSTANCE.getNode_Name(), name);
          cc.append(set);
          transitionNum++;
        }
        editDomain.getCommandStack().execute(cc);
        return res;
      }

      if (sourceEditor != null) {
        sourceEditor.refreshEditorView();
      }

      return null;
    } catch (Exception exception) {
      plugin.logError(exception);
      MessageDialog.openInformation(
          window.getShell(),
          "Anonymize",
          "We're sorry, we could not anonymize the model. See the error log for details.");
    }
    return null;
  }