private void configureGraphicalViewer() {
   viewer.getControl().setBackground(ColorConstants.listBackground);
   viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
   ((FigureCanvas) viewer.getControl()).setScrollBarVisibility(FigureCanvas.AUTOMATIC);
   DiagramEditDomain editDomain = new DiagramEditDomain(null);
   editDomain.setCommandStack(new DiagramCommandStack(editDomain));
   viewer.setEditDomain(editDomain);
 }
Esempio n. 2
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);
      }
    }
  }
 // DS-1534
 public void showItem(List<EObject> items) {
   for (EObject item : items) {
     List<EditPart> editParts = getEditPartsForElement(item);
     if (editParts.size() > 0) {
       EditPart ep = editParts.get(0);
       viewer.select(ep);
       viewer.reveal(ep);
     } else {
       // DS-1534
       viewer.deselectAll();
     }
   }
 }
 // DS-1534
 @SuppressWarnings("unchecked")
 private List<EditPart> getEditPartsForElement(EObject item) {
   if (item == null) {
     return Collections.EMPTY_LIST;
   }
   String id = ((XMLResource) item.eResource()).getID(item);
   List<EditPart> editParts = viewer.findEditPartsForElement(id, EditPart.class);
   if (editParts.isEmpty() && item.eContainer() != null) {
     return getEditPartsForElement(item.eContainer());
   }
   return editParts;
 }
 /** @param input */
 private void setInput(Object input) {
   Diagram diagram = null;
   if (input instanceof Pageflow) {
     Pageflow pageflow = (Pageflow) input;
     diagram = fetchDiagram(pageflow.eResource());
   } else if (input instanceof Diagram) {
     diagram = (Diagram) input;
   } else if (input instanceof Resource) {
     Resource res = (Resource) input;
     diagram = fetchDiagram(res);
   } else if (input instanceof ResourceSet) {
     Resource res = ((ResourceSet) input).getResources().get(0);
     diagram = fetchDiagram(res);
   } else if (input instanceof List) {
     Resource res = (Resource) ((List<?>) input).get(0);
     diagram = fetchDiagram(res);
   }
   if (diagram != null) {
     TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(
         diagram.eResource().getResourceSet());
     RootEditPart rootEP = EditPartService.getInstance().createRootEditPart(diagram);
     if (rootEP instanceof DiagramRootEditPart) {
       ((DiagramRootEditPart) rootEP)
           .setPreferencesHint(PageflowDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
     }
     viewer.setRootEditPart(rootEP);
     viewer.setEditPartFactory(new PageflowEditPartFactory());
     viewer.setContents(diagram);
     viewer.flush();
     if (viewer.getContents() instanceof DiagramEditPart) {
       DiagramEditPart dp = (DiagramEditPart) viewer.getContents();
       dp.disableEditMode();
     }
   }
   return;
 }
 /**
  * @param composite
  * @param partSide
  */
 public PageflowContentMergeModelPart(Composite composite, int partSide) {
   this.partSide = partSide;
   viewer = new DiagramGraphicalViewer();
   viewer.createControl(composite);
   configureGraphicalViewer();
 }
 /* (non-Javadoc)
  * @see org.eclipse.emf.compare.ui.viewer.content.part.IModelContentMergeViewerTab#getSelectedElements()
  */
 public List<? extends Item> getSelectedElements() {
   return viewer.getSelectedEditParts();
 }
 /* (non-Javadoc)
  * @see org.eclipse.emf.compare.ui.viewer.content.part.IModelContentMergeViewerTab#redraw()
  */
 public void redraw() {
   viewer.getControl().redraw();
 }
 /* (non-Javadoc)
  * @see org.eclipse.emf.compare.ui.viewer.content.part.IModelContentMergeViewerTab#getControl()
  */
 public Control getControl() {
   return viewer.getControl();
 }
 /* (non-Javadoc)
  * @see org.eclipse.emf.compare.ui.viewer.content.part.IModelContentMergeViewerTab#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
  */
 public void addSelectionChangedListener(ISelectionChangedListener selectionChangedListener) {
   viewer.addSelectionChangedListener(selectionChangedListener);
 }