コード例 #1
0
 /** @generated */
 public void run(IAction action) {
   TransactionalEditingDomain editingDomain =
       GMFEditingDomainFactory.INSTANCE.createEditingDomain();
   ResourceSet resourceSet = editingDomain.getResourceSet();
   EObject diagramRoot = null;
   try {
     Resource resource = resourceSet.getResource(domainModelURI, true);
     diagramRoot = (EObject) resource.getContents().get(0);
   } catch (WrappedException ex) {
     StateMachineDiagramEditorPlugin.getInstance()
         .logError("Unable to load resource: " + domainModelURI, ex); // $NON-NLS-1$
   }
   if (diagramRoot == null) {
     MessageDialog.openError(
         getShell(),
         Messages.InitDiagramFile_ResourceErrorDialogTitle,
         Messages.InitDiagramFile_ResourceErrorDialogMessage);
     return;
   }
   Wizard wizard =
       new StateMachineNewDiagramFileWizard(domainModelURI, diagramRoot, editingDomain);
   wizard.setWindowTitle(
       NLS.bind(Messages.InitDiagramFile_WizardTitle, StateMachineEditPart.MODEL_ID));
   StateMachineDiagramEditorUtil.runWizard(getShell(), wizard, "InitDiagramFile"); // $NON-NLS-1$
 }
コード例 #2
0
  /**
   * This method should be called within a workspace modify operation since it creates resources.
   *
   * @generated
   */
  public static Resource createDiagram(
      URI diagramURI,
      URI modelURI,
      final String diagramName,
      final String diagramNameWithoutExtension,
      final EClass initialObject,
      final String encoding,
      IProgressMonitor progressMonitor) {
    TransactionalEditingDomain editingDomain =
        GMFEditingDomainFactory.INSTANCE.createEditingDomain();
    progressMonitor.beginTask(Messages.UMLDiagramEditorUtil_CreateDiagramProgressTask, 3);
    final Resource diagramResource = editingDomain.getResourceSet().createResource(diagramURI);
    final Resource modelResource = editingDomain.getResourceSet().createResource(modelURI);
    AbstractTransactionalCommand command =
        new AbstractTransactionalCommand(
            editingDomain,
            Messages.UMLDiagramEditorUtil_CreateDiagramCommandLabel,
            Collections.EMPTY_LIST) {

          protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
              throws ExecutionException {
            Package model = createInitialModel(initialObject, diagramNameWithoutExtension);
            attachModelToResource(model, modelResource);

            Diagram diagram =
                ViewService.createDiagram(
                    model,
                    PackageEditPart.MODEL_ID,
                    UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
            if (diagram != null) {
              diagramResource.getContents().add(diagram);
              diagram.setName(diagramName);
              diagram.setElement(model);
            }

            try {
              modelResource.save(
                  org.eclipse.uml2.diagram.csd.part.UMLDiagramEditorUtil.getSaveOptions(encoding));
              diagramResource.save(
                  org.eclipse.uml2.diagram.csd.part.UMLDiagramEditorUtil.getSaveOptions(encoding));
            } catch (IOException e) {

              UMLDiagramEditorPlugin.getInstance()
                  .logError("Unable to store model and diagram resources", e); // $NON-NLS-1$
            }
            return CommandResult.newOKCommandResult();
          }
        };
    try {
      OperationHistoryFactory.getOperationHistory()
          .execute(command, new SubProgressMonitor(progressMonitor, 1), null);
    } catch (ExecutionException e) {
      UMLDiagramEditorPlugin.getInstance()
          .logError("Unable to create model and diagram", e); // $NON-NLS-1$
    }
    setCharset(WorkspaceSynchronizer.getFile(modelResource));
    setCharset(WorkspaceSynchronizer.getFile(diagramResource));
    return diagramResource;
  }
  /** @generated */
  public TOEDomainNavigatorContentProvider() {
    myAdapterFctoryContentProvier =
        new AdapterFactoryContentProvider(
            TOEDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory());
    TransactionalEditingDomain editingDomain =
        GMFEditingDomainFactory.INSTANCE.createEditingDomain();
    myEditingDomain = (AdapterFactoryEditingDomain) editingDomain;
    myEditingDomain.setResourceToReadOnlyMap(
        new HashMap() {

          public Object get(Object key) {
            if (!containsKey(key)) {
              put(key, Boolean.TRUE);
            }
            return super.get(key);
          }
        });
    myViewerRefreshRunnable =
        new Runnable() {

          public void run() {
            if (myViewer != null) {
              myViewer.refresh();
            }
          }
        };
    myWorkspaceSynchronizer =
        new WorkspaceSynchronizer(
            editingDomain,
            new WorkspaceSynchronizer.Delegate() {

              public void dispose() {}

              public boolean handleResourceChanged(final Resource resource) {
                unloadAllResources();
                asyncRefresh();
                return true;
              }

              public boolean handleResourceDeleted(Resource resource) {
                unloadAllResources();
                asyncRefresh();
                return true;
              }

              public boolean handleResourceMoved(Resource resource, final URI newURI) {
                unloadAllResources();
                asyncRefresh();
                return true;
              }
            });
  }
コード例 #4
0
 /** @generated */
 public void run(IAction action) {
   TransactionalEditingDomain editingDomain =
       GMFEditingDomainFactory.INSTANCE.createEditingDomain();
   Resource resource =
       AtomicDiagramEditorUtil.openModel(
           getShell(), Messages.InitDiagramFile_OpenModelFileDialogTitle, editingDomain);
   if (resource == null || resource.getContents().isEmpty()) {
     return;
   }
   EObject diagramRoot = (EObject) resource.getContents().get(0);
   Wizard wizard = new AtomicNewDiagramFileWizard(resource.getURI(), diagramRoot, editingDomain);
   wizard.setWindowTitle(NLS.bind(Messages.InitDiagramFile_WizardTitle, AGraphEditPart.MODEL_ID));
   AtomicDiagramEditorUtil.runWizard(getShell(), wizard, "InitDiagramFile"); // $NON-NLS-1$
 }
コード例 #5
0
  /** @generated */
  @SuppressWarnings({"unchecked", "serial", "rawtypes"})
  public StateAnalysisNavigatorContentProvider() {
    TransactionalEditingDomain editingDomain =
        GMFEditingDomainFactory.INSTANCE.createEditingDomain();
    myEditingDomain = (AdapterFactoryEditingDomain) editingDomain;
    myEditingDomain.setResourceToReadOnlyMap(
        new HashMap() {
          public Object get(Object key) {
            if (!containsKey(key)) {
              put(key, Boolean.TRUE);
            }
            return super.get(key);
          }
        });
    myViewerRefreshRunnable =
        new Runnable() {
          public void run() {
            if (myViewer != null) {
              myViewer.refresh();
            }
          }
        };
    myWorkspaceSynchronizer =
        new WorkspaceSynchronizer(
            editingDomain,
            new WorkspaceSynchronizer.Delegate() {
              public void dispose() {}

              public boolean handleResourceChanged(final Resource resource) {
                unloadAllResources();
                asyncRefresh();
                return true;
              }

              public boolean handleResourceDeleted(Resource resource) {
                unloadAllResources();
                asyncRefresh();
                return true;
              }

              public boolean handleResourceMoved(Resource resource, final URI newURI) {
                unloadAllResources();
                asyncRefresh();
                return true;
              }
            });
  }
コード例 #6
0
  /** @generated */
  public static Resource createDiagram(URI diagramURI, IProgressMonitor progressMonitor) {
    TransactionalEditingDomain editingDomain =
        GMFEditingDomainFactory.INSTANCE.createEditingDomain();
    progressMonitor.beginTask(Messages.RoxgtDiagramEditorUtil_CreateDiagramProgressTask, 3);
    final Resource diagramResource = editingDomain.getResourceSet().createResource(diagramURI);
    final String diagramName = diagramURI.lastSegment();
    AbstractTransactionalCommand command =
        new AbstractTransactionalCommand(
            editingDomain,
            Messages.RoxgtDiagramEditorUtil_CreateDiagramCommandLabel,
            Collections.EMPTY_LIST) {
          protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
              throws ExecutionException {
            Graph model = createInitialModel();
            attachModelToResource(model, diagramResource);

            Diagram diagram =
                ViewService.createDiagram(
                    model,
                    GraphEditPart.MODEL_ID,
                    RoxgtDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
            if (diagram != null) {
              diagramResource.getContents().add(diagram);
              diagram.setName(diagramName);
              diagram.setElement(model);
            }

            try {

              diagramResource.save(org.roxgt.diagram.part.RoxgtDiagramEditorUtil.getSaveOptions());
            } catch (IOException e) {

              RoxgtDiagramEditorPlugin.getInstance()
                  .logError("Unable to store model and diagram resources", e); // $NON-NLS-1$
            }
            return CommandResult.newOKCommandResult();
          }
        };
    try {
      OperationHistoryFactory.getOperationHistory()
          .execute(command, new SubProgressMonitor(progressMonitor, 1), null);
    } catch (ExecutionException e) {
      RoxgtDiagramEditorPlugin.getInstance()
          .logError("Unable to create model and diagram", e); // $NON-NLS-1$
    }
    return diagramResource;
  }
コード例 #7
0
  protected void initDiagramFile() throws CoreException {
    List<IFile> affectedFiles = new LinkedList<IFile>();
    final IFile diagramFile = createNewFile();
    PlwebDiagramEditorUtil.setCharset(diagramFile);
    affectedFiles.add(diagramFile);
    URI diagramModelURI = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
    TransactionalEditingDomain editingDomain =
        GMFEditingDomainFactory.INSTANCE.createEditingDomain();
    ResourceSet resourceSet = editingDomain.getResourceSet();
    final Resource diagramResource = resourceSet.createResource(diagramModelURI);
    AbstractTransactionalCommand command =
        new AbstractTransactionalCommand(
            editingDomain, Messages.PlwebNewDiagramFileWizard_InitDiagramCommand, affectedFiles) {

          protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
              throws ExecutionException {
            DiagramRoot element = getElement(getEditingDomain());
            int diagramVID = PlwebVisualIDRegistry.getDiagramVisualID(element);
            if (diagramVID != DiagramRootEditPart.VISUAL_ID) {
              return CommandResult.newErrorCommandResult(
                  Messages.PlwebNewDiagramFileWizard_IncorrectRootError);
            }
            Diagram diagram =
                ViewService.createDiagram(
                    element,
                    DiagramRootEditPart.MODEL_ID,
                    PlwebDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
            diagramResource.getContents().add(diagram);
            return CommandResult.newOKCommandResult();
          }
        };
    try {
      OperationHistoryFactory.getOperationHistory()
          .execute(command, new NullProgressMonitor(), null);
      diagramResource.save(PlwebDiagramEditorUtil.getSaveOptions());
      PlwebDiagramEditorUtil.openDiagram(diagramResource);
    } catch (ExecutionException e) {
      PlwebDiagramEditorPlugin.getInstance()
          .logError("Unable to create model and diagram", e); // $NON-NLS-1$
    } catch (IOException ex) {
      PlwebDiagramEditorPlugin.getInstance()
          .logError("Save operation failed for: " + diagramModelURI, ex); // $NON-NLS-1$
    } catch (PartInitException ex) {
      PlwebDiagramEditorPlugin.getInstance().logError("Unable to open editor", ex); // $NON-NLS-1$
    }
  }
コード例 #8
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;
  }