@Override
 public void init(IEditorSite site, IEditorInput input) throws PartInitException {
   super.init(site, input);
   getEditingDomain().addResourceSetListener(validationListener);
   checkXtextNature();
   initValidationJob();
 }
 @Override
 protected void createGraphicalViewer(Composite parent) {
   super.createGraphicalViewer(parent);
   IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem();
   helpSystem.setHelp(
       getGraphicalViewer().getControl(), HelpContextIds.SC_EDITOR_GRAPHICAL_VIEWER);
 }
 @Override
 protected void createGraphicalViewer(Composite parent) {
   super.createGraphicalViewer(parent);
   // Tag the viewer with the desired help context id
   PlatformUI.getWorkbench()
       .getHelpSystem()
       .setHelp(
           getGraphicalViewer().getControl(),
           IYakinduSctHelpContextIds.SC_EDITOR_GRAPHICAL_VIEWER);
 }
 @Override
 protected void configureGraphicalViewer() {
   super.configureGraphicalViewer();
   RootEditPart rootEditPart = getDiagramGraphicalViewer().getRootEditPart();
   if (rootEditPart instanceof LayerManager) {
     ConnectionLayer connectionLayer =
         (ConnectionLayer) ((LayerManager) rootEditPart).getLayer(LayerConstants.CONNECTION_LAYER);
     connectionLayer.setClippingStrategy(
         new ViewportAwareConnectionLayerClippingStrategy(connectionLayer));
   }
 }
 @Override
 public void dispose() {
   validationJob.cancel();
   getEditingDomain().removeResourceSetListener(validationListener);
   getEditingDomain().removeResourceSetListener(domainAdapter);
   domainAdapter.dispose();
   IFileEditorInput editorInput = (IFileEditorInput) getEditorInput();
   try {
     // Touch the file for revalidation, when the user did not save
     // the changes
     if (editorInput.getFile() != null && editorInput.getFile().exists()) {
       editorInput.getFile().touch(new NullProgressMonitor());
     }
   } catch (CoreException e) {
     e.printStackTrace();
   }
   super.dispose();
 }
  @Override
  public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);

    getEditingDomain()
        .addResourceSetListener(
            new ResourceSetListenerImpl() {
              @Override
              public void resourceSetChanged(ResourceSetChangeEvent event) {
                Display.getDefault()
                    .asyncExec(
                        new Runnable() {
                          public void run() {
                            if (getDiagram() != null) {
                              ValidationAction.validate(getDiagramEditPart(), getDiagram());
                            }
                          }
                        });
              }
            });
  }
 @Override
 public void dispose() {
   removeDirtyResources();
   super.dispose();
 };
 @Override
 public void init(IEditorSite site, IEditorInput input) throws PartInitException {
   super.init(site, input);
   createDirtyResources();
 }
  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;
  }
  /**
   * Corresponds to ticket #1811. Check that after a creation of a diagram with ports from an
   * existing diagram, the layoutConstraint of all ports is not {0, 0}.
   */
  public void testPortLocationForCreationFromNavigation() {
    // Get the desired package
    final Model model = (Model) semanticModel;
    assertNotNull("Corrupted input data", model);
    // Get the diagram for the root of this model.
    diagram = (DDiagram) createRepresentation(NODE_REPRESENTATION_DESC_NAME, model);

    // Open the editor (and refresh it)
    final IEditorPart editorPart =
        DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();

    // Set the focus to the desired package
    assertTrue(
        "We should have a DiagramDocumentEditor", editorPart instanceof DiagramDocumentEditor);

    final DiagramDocumentEditor diagramEditor = (DiagramDocumentEditor) editorPart;

    // Get the package named "SubPackage"
    PackageableElement element = model.getPackagedElement("SubPackage");
    assertTrue("Corrupted input data", element instanceof Package);
    final Package packageSubPackage = (Package) element;

    IMenuManager popupMenu = new MenuManager();
    popupMenu.add(
        new MenuManager(
            IWorkbenchActionConstants.MB_ADDITIONS,
            IWorkbenchActionConstants.MB_ADDITIONS)); // $NON-NLS-1$ //$NON-NLS-2$
    popupMenu.add(new MenuManager("popup.new", "popup.new")); // $NON-NLS-1$

    // Set the focus to package SubPackage
    IGraphicalEditPart elementEditPart =
        getEditPart(getFirstDiagramElement(diagram, packageSubPackage));
    diagramEditor.getDiagramGraphicalViewer().setFocus(elementEditPart);

    DNode focusedElement =
        (DNode)
            ((GraphicalEditPart) diagramEditor.getDiagramGraphicalViewer().getFocusEditPart())
                .resolveSemanticElement();
    assertTrue(
        "This is not the good focused element", focusedElement.getTarget() instanceof Package);
    assertEquals(
        "This is not the good focused element",
        "SubPackage",
        ((Package) focusedElement.getTarget()).getName());

    ContributionItemService.getInstance().contributeToPopupMenu(popupMenu, diagramEditor);

    // Check the popup menu.
    IMenuManager newRepresentationMenu = (IMenuManager) popupMenu.find("popup.new");
    IContributionItem[] items = newRepresentationMenu.getItems();

    boolean inNewRepresentationToGroup = false;

    ActionContributionItem actionContribution = null;

    for (int i = 0; i < items.length; i++) {
      if (items[i] instanceof Separator) {
        Separator sep = (Separator) items[i];
        if ("createRepresentationGroup".equals(sep.getId())) {
          inNewRepresentationToGroup = true;
        } else {
          inNewRepresentationToGroup = false;
        }
      }
      if (inNewRepresentationToGroup && items[i] instanceof ActionContributionItem) {
        assertNull("There should be only one ActionContributionItem", actionContribution);
        actionContribution = (ActionContributionItem) items[i];
      }
    }

    assertNotNull("There should be one ActionContributionItem", actionContribution);
    final IAction action = actionContribution.getAction();

    assertEquals("Action has not the correct text", "New diagram", action.getText());

    // Disabling ui callback of diagram command factory
    final Object adapter = diagramEditor.getAdapter(IDiagramCommandFactoryProvider.class);
    final IDiagramCommandFactoryProvider diagramCmdFactoryProvider =
        (IDiagramCommandFactoryProvider) adapter;
    final IDiagramCommandFactory diagramCommandFactory =
        diagramCmdFactoryProvider.getCommandFactory(session.getTransactionalEditingDomain());
    diagramCommandFactory.setUserInterfaceCallBack(new NoUICallback());

    action.run();

    IEditorPart editor2 =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    assertTrue("We should have a DiagramDocumentEditor", editor2 instanceof DiagramDocumentEditor);

    final DiagramDocumentEditor diagramEditor2 = (DiagramDocumentEditor) editor2;
    GraphicalEditPart diagramPart = (GraphicalEditPart) diagramEditor2.getDiagramEditPart();
    final DSemanticDiagram diagram2 = (DSemanticDiagram) diagramPart.resolveSemanticElement();

    assertEquals(
        "The opened diagram is not valid", diagram2.getTarget(), focusedElement.getTarget());

    // Get the class named "SubClass1"
    element = packageSubPackage.getPackagedElement("SubClass1");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class subClass1 = (Class) element;

    final Property firstProperty = subClass1.getOwnedAttribute("Prop1", subClass1);
    final Property secondProperty = subClass1.getOwnedAttribute("Prop2", subClass1);

    final DDiagramElement firstPropertyDiagramElement =
        getFirstDiagramElement(diagram2, firstProperty);
    assertNotNull(
        "The first property has no corresponding diagramElement", firstPropertyDiagramElement);
    final Node firstPropertyNode = getGmfNode(firstPropertyDiagramElement);
    assertNotNull("The first property has no corresponding GMF node", firstPropertyNode);
    assertTrue(
        "Bag layout constraint type", firstPropertyNode.getLayoutConstraint() instanceof Location);
    final Location firstLocation = (Location) firstPropertyNode.getLayoutConstraint();
    final DDiagramElement secondPropertyDiagramElement =
        getFirstDiagramElement(diagram2, secondProperty);
    assertNotNull(
        "The second property has no corresponding diagramElement", secondPropertyDiagramElement);
    final Node secondPropertyNode = getGmfNode(secondPropertyDiagramElement);
    assertNotNull("The second property has no corresponding GMF node", secondPropertyNode);
    assertTrue(
        "Bag layout constraint type", secondPropertyNode.getLayoutConstraint() instanceof Location);
    final Location secondLocation = (Location) secondPropertyNode.getLayoutConstraint();

    assertFalse(
        "All the layout constraints of the ports should not be in {0,0}",
        firstLocation.getX() == 0
            && firstLocation.getY() == 0
            && secondLocation.getX() == 0
            && secondLocation.getY() == 0);
    assertTrue(
        "All the layout constraints of the ports should be different",
        firstLocation.getX() != secondLocation.getX()
            || firstLocation.getY() != secondLocation.getY());

    DialectUIManager.INSTANCE.closeEditor(editorPart, false);
    TestsUtil.synchronizationWithUIThread();

    DialectUIManager.INSTANCE.closeEditor(editor2, false);
    TestsUtil.synchronizationWithUIThread();
  }