コード例 #1
0
 /**
  * Gets the transactional editing domain.
  *
  * @return the transactional editing domain
  */
 private TransactionalEditingDomain getTransactionalEditingDomain() {
   TransactionalEditingDomain ted = null;
   IEditorPart activeEditor =
       PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
   if (activeEditor instanceof IDiagramWorkbenchPart) {
     IDiagramWorkbenchPart workbenchPart = (IDiagramWorkbenchPart) activeEditor;
     ted = (TransactionalEditingDomain) workbenchPart.getAdapter(EditingDomain.class);
     if (ted == null) {
       if (workbenchPart instanceof DiagramEditor) {
         DiagramEditor editor = (DiagramEditor) workbenchPart;
         ted = editor.getEditingDomain();
       }
     }
   }
   return ted;
 }
コード例 #2
0
  /** @generated */
  public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    if (aSelection == null || aSelection.isEmpty()) {
      return;
    }
    if (false == aSelection.getFirstElement() instanceof MIDAbstractNavigatorItem) {
      return;
    }

    MIDAbstractNavigatorItem abstractNavigatorItem =
        (MIDAbstractNavigatorItem) aSelection.getFirstElement();
    View navigatorView = null;
    if (abstractNavigatorItem instanceof MIDNavigatorItem) {
      navigatorView = ((MIDNavigatorItem) abstractNavigatorItem).getView();
    } else if (abstractNavigatorItem instanceof MIDNavigatorGroup) {
      MIDNavigatorGroup navigatorGroup = (MIDNavigatorGroup) abstractNavigatorItem;
      if (navigatorGroup.getParent() instanceof MIDNavigatorItem) {
        navigatorView = ((MIDNavigatorItem) navigatorGroup.getParent()).getView();
      } else if (navigatorGroup.getParent() instanceof IAdaptable) {
        navigatorView = (View) ((IAdaptable) navigatorGroup.getParent()).getAdapter(View.class);
      }
    }
    if (navigatorView == null) {
      return;
    }
    IEditorInput editorInput = getEditorInput(navigatorView.getDiagram());
    IEditorPart editor = aPage.findEditor(editorInput);
    if (editor == null) {
      return;
    }
    aPage.bringToTop(editor);
    if (editor instanceof DiagramEditor) {
      DiagramEditor diagramEditor = (DiagramEditor) editor;
      ResourceSet diagramEditorResourceSet = diagramEditor.getEditingDomain().getResourceSet();
      EObject selectedView =
          diagramEditorResourceSet.getEObject(EcoreUtil.getURI(navigatorView), true);
      if (selectedView == null) {
        return;
      }
      GraphicalViewer graphicalViewer =
          (GraphicalViewer) diagramEditor.getAdapter(GraphicalViewer.class);
      EditPart selectedEditPart =
          (EditPart) graphicalViewer.getEditPartRegistry().get(selectedView);
      if (selectedEditPart != null) {
        graphicalViewer.select(selectedEditPart);
      }
    }
  }
コード例 #3
0
 /** @generated */
 protected void doGotoMarker(IMarker marker) {
   String elementId =
       marker.getAttribute(org.eclipse.gmf.runtime.common.core.resources.IMarker.ELEMENT_ID, null);
   if (elementId == null || !(getEditor() instanceof DiagramEditor)) {
     return;
   }
   DiagramEditor editor = (DiagramEditor) getEditor();
   Map editPartRegistry = editor.getDiagramGraphicalViewer().getEditPartRegistry();
   EObject targetView = editor.getDiagram().eResource().getEObject(elementId);
   if (targetView == null) {
     return;
   }
   EditPart targetEditPart = (EditPart) editPartRegistry.get(targetView);
   if (targetEditPart != null) {
     UMLDiagramEditorUtil.selectElementsInDiagram(
         editor, Arrays.asList(new EditPart[] {targetEditPart}));
   }
 }
コード例 #4
0
  /**
   * Applies all filters to the editor. If the filter is activated (or deactivated), it makes all
   * elements in the editor invisible (or visible)
   *
   * @param editor
   */
  private void applyFiltersToEditorView(DiagramEditor editor) {
    if (editor == null) return;

    Object adapter = editor.getAdapter(GraphicalViewer.class);
    if (!(adapter instanceof DiagramGraphicalViewer)) return;
    DiagramGraphicalViewer viewer = (DiagramGraphicalViewer) adapter;

    // get all EditParts of the Model
    Map<?, ?> editPartRegistry = viewer.getEditPartRegistry();
    Object editPart = null;

    Set<Object> visibleElements =
        getElementsForFilter(
            editPartRegistry, AttributeFilterController.getInstance().getAllFilters());

    // show all elements if the processed result is a non-empty set (look
    // AttributeAnalyser.getVisibleElementsForFilter())
    boolean showAll = (visibleElements != null && visibleElements.isEmpty());
    //
    boolean show = true;
    Set<EObject> visibleEObjects = new HashSet<EObject>();
    if (visibleElements != null) {
      for (Object element : visibleElements) {
        if (element instanceof EdgeImpl) visibleEObjects.add(((EdgeImpl) element).getElement());
        if (element instanceof NodeImpl) visibleEObjects.add(((NodeImpl) element).getElement());
      }
    }

    for (Object keyOfEditPartRegistry : editPartRegistry.keySet()) {
      if (keyOfEditPartRegistry instanceof NodeImpl) {
        editPart = editPartRegistry.get(keyOfEditPartRegistry);

        if (editPart instanceof GraphicalEditPart) {
          if (showAll
              || visibleEObjects.contains(((NodeImpl) keyOfEditPartRegistry).getElement())) {
            show = true;
          } else {
            show = false;
          }
          ((GraphicalEditPart) editPart).getFigure().setVisible(show);
        }
      } else if (keyOfEditPartRegistry instanceof EdgeImpl) {
        editPart = editPartRegistry.get(keyOfEditPartRegistry);
        if (showAll || visibleEObjects.contains(((EdgeImpl) keyOfEditPartRegistry).getElement())) {
          show = true;

        } else {
          show = false;
        }
        if (editPart instanceof ConnectionEditPart)
          ((ConnectionEditPart) editPartRegistry.get(keyOfEditPartRegistry))
              .getFigure()
              .setVisible(show);
      }
    }
  }
コード例 #5
0
  @Override
  public void dispose(
      IUndoContext context, boolean flushUndo, boolean flushRedo, boolean flushContext) {
    // dispose of any limit that was set for the context if it is not to be
    // used again.
    if (context instanceof EditingDomainUndoContext) {
      EditingDomainUndoContext editingDomainContext = (EditingDomainUndoContext) context;
      EditingDomain editingDomain = editingDomainContext.getEditingDomain();
      if (PlatformUI.isWorkbenchRunning()
          && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
          && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null
          && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
              != null) {

        IEditorReference[] editorReferences =
            PlatformUI.getWorkbench()
                .getActiveWorkbenchWindow()
                .getActivePage()
                .getEditorReferences();
        for (IEditorReference editorRef : editorReferences) {
          try {
            IWorkbenchPart part = editorRef.getPart(false);
            if (part instanceof DiagramEditor) {
              DiagramEditor editor = (DiagramEditor) part;
              if (editor.getEditingDomain() != null
                  && editor.getEditingDomain().equals(editingDomain)) {
                return; // do not dispose if the editing domain
                // is else
              }
            }
          } catch (Exception e) {
            BonitaStudioLog.error(e);
          }
        }
      }
    }
    defaultOperationHistory.dispose(context, flushUndo, flushRedo, flushContext);
  }