/**
   * The default implementation of this <code>IContributionItem</code> method does nothing.
   * Subclasses may override.
   */
  @Override
  public void fill(Menu menu, int index) {
    // retrieves current selection
    final Object selectedElement = getSelectedElement();

    // first case: this class was not able to retrieve the selection service
    // or does not understand the current selection.
    // does not build any sub-menu and returns.
    if (selectedElement == null) {
      return;
    }

    // get the UML object type of this element, using the business resolver
    final Object businessObject = EMFHelper.getEObject(selectedElement);

    // no object found: exit
    if (businessObject == null) {
      return;
    }

    // retrieves all editor configurations for this kind of element
    final Collection<DirectEditorExtensionPoint> configurations =
        DirectEditorExtensionPoint.getDirectEditorConfigurations(businessObject.getClass());

    // if configurations is not empty, a submenu should open to select which
    // editor to use...

    if (configurations.size() < 1) {
      return;
    }

    createSubMenu(menu, index, businessObject, configurations);
  }
    /**
     * {@inheritedDoc}.
     *
     * @param e the e
     */
    @Override
    public void widgetSelected(SelectionEvent e) {
      try {
        if (treeViewer.getSelection().isEmpty()) {
          return;
        }

        IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();

        EObject elt = EMFHelper.getEObject(selection.getFirstElement());
        if (elt == null) {
          return;
        }

        setContainer(elt);
        ModelSet modelSet = ServiceUtilsForEObject.getInstance().getModelSet(elt);

        ICreationCommand creationCommand =
            iCreationCommandRegistry.getCommand(commandDescriptor.getCommandId());
        creationCommand.createDiagram(modelSet, container, null);

        // refresh several filtered tree
        getDiagramfilteredTree().getViewer().refresh();
        getModeFilteredTree().getViewer().refresh();
      } catch (NotFoundException ex) {
        Activator.log.error(ex);
      } catch (ServiceException ex) {
        Activator.log.error(ex);
      }
    }
Exemplo n.º 3
0
 /**
  * Tests if all elements in the selection are EObject
  *
  * @param selection
  * @return
  */
 private boolean isObject(IStructuredSelection selection) {
   if (!selection.isEmpty()) {
     Iterator<?> iter = selection.iterator();
     while (iter.hasNext()) {
       EObject current = EMFHelper.getEObject(iter.next());
       return current != null;
     }
   }
   return false;
 }
Exemplo n.º 4
0
  protected boolean hasEClass(IStructuredSelection selection, String eClassQName) {
    if (!selection.isEmpty()) {
      // Resolve the EClass in the context of the first element. If we can't resolve it
      // in this context, then that element necessarily isn't an instance of that EClass,
      // so not all of the selection is an instance of that class. Thus, it doesn't
      // matter that we choose the first element to resolve the EClass
      EClassifier eClassifier =
          resolveEClass(EMFHelper.getEObject(selection.getFirstElement()), eClassQName);

      if (eClassifier != null) {
        boolean result = true;
        for (Iterator<?> iter = selection.iterator(); result && iter.hasNext(); ) {
          EObject next = EMFHelper.getEObject(iter.next());
          result = (next != null) && eClassifier.isInstance(next);
        }

        return result;
      }
    }
    return false;
  }
 protected void refresh(Object selectedElement) {
   selectedElement = EMFHelper.getEObject(selectedElement);
   Button but = getOKbutton();
   if (isAValidEditor(selectedElement)) {
     but = getOKbutton();
     but.setEnabled(true);
     selectedEditor = selectedElement;
   } else {
     but.setEnabled(false);
     selectedEditor = null;
   }
 }
Exemplo n.º 6
0
  /**
   * @param selection the current selection
   * @return <code>true</code> if all selected elements are pages
   */
  private boolean isPage(IStructuredSelection selection) {
    IPageManager pageManager = getPageManager(selection);
    if (pageManager != null) {
      if (!selection.isEmpty()) {
        Iterator<?> iter = selection.iterator();
        while (iter.hasNext()) {
          EObject current = EMFHelper.getEObject(iter.next());
          if (!isPage(current, pageManager)) {
            return false;
          }
        }

        return true;
      }
    }
    return false;
  }
Exemplo n.º 7
0
  /**
   * @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage,
   *     org.eclipse.jface.viewers.IStructuredSelection)
   */
  public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    // no selection
    if (aSelection == null || aSelection.isEmpty()) {
      return;
    }
    ISelectionService selectService = aPage.getWorkbenchWindow().getSelectionService();
    ISelection selection = selectService.getSelection();

    // test if the selection come the tree viewer in order to avoid  cycle: Diagram -> tree->
    // diagram
    // if the diagram has been selected the selection is not a TreeSelection
    if (selection instanceof ITreeSelection) {
      try {
        ISashWindowsContainer windowsContainer =
            ServiceUtilsForWorkbenchPage.getInstance().getISashWindowsContainer(aPage);

        Iterator<IEditorPart> iterPart = windowsContainer.getVisibleIEditorParts().iterator();

        while (iterPart.hasNext()) {
          IEditorPart diagramEditor = iterPart.next();
          if (diagramEditor instanceof IRevealSemanticElement) {
            if (aSelection instanceof IStructuredSelection) {
              Iterator<?> selectionIterator = aSelection.iterator();
              ArrayList<Object> semanticElementList = new ArrayList<Object>();
              while (selectionIterator.hasNext()) {
                Object currentSelection = selectionIterator.next();
                Object semanticElement = EMFHelper.getEObject(currentSelection);
                if (semanticElement != null) {
                  semanticElementList.add(semanticElement);
                }
              }
              ((IRevealSemanticElement) diagramEditor).revealSemanticElement(semanticElementList);
            }
          }
        }
      } catch (ServiceException ex) {
        // We cannot access the service registry. The PapyrusEditor is probably closed.
      } catch (Exception ex) {
        Activator.log.error("Impossible to acces to windows Container", ex); // $NON-NLS-1$
      }
    }
  }
Exemplo n.º 8
0
  /**
   * This method selects an element in the modelexplorer and test that the new selection is the
   * wanted selection using assertion
   *
   * @param elementToSelect the element to select
   */
  protected void selectElementInTheModelexplorer(EObject elementToSelect) {
    final List<EObject> selectedElement = new ArrayList<EObject>();
    selectedElement.add(elementToSelect);
    Display.getDefault()
        .syncExec(
            new Runnable() {

              public void run() {
                modelExplorerView.revealSemanticElement(selectedElement);
              }
            });

    IStructuredSelection currentSelection = (IStructuredSelection) selectionService.getSelection();
    Assert.assertEquals(
        "Only one element should be selected", 1, currentSelection.size()); // $NON-NLS-1$
    Object obj = currentSelection.getFirstElement();
    obj = EMFHelper.getEObject(obj);
    Assert.assertSame(
        "the current selected element is not the wanted element",
        elementToSelect,
        obj); //$NON-NLS-1$
  }