public SelectedArtifactSelectionManager getSelectedBindingManager() {
   if (selectedBindingManager == null) {
     selectedBindingManager = new SelectedArtifactSelectionManager(IBindingRipper.Utils.ripper());
     selectedBindingManager.addSelectedArtifactSelectionListener(
         new ISelectedBindingListener() {
           @Override
           public void selectionOccured(BindingRipperResult ripperResult) {
             Map<String, Object> context =
                 Maps.makeMap(DisplayCoreConstants.ripperResult, ripperResult);
             IUrlGeneratorMap urlGeneratorMap = getUrlGeneratorMap();
             IUrlGenerator urlGenerator = urlGeneratorMap.get(RepositoryConstants.entityJar);
             String hexDigest = ripperResult.hexDigest;
             String jarUrl = urlGenerator.apply(hexDigest);
             getRepository().getData(RepositoryConstants.entityJar, jarUrl, context);
           }
         });
     IWorkbench workbench = PlatformUI.getWorkbench();
     IWorkbenchWindow[] workbenchWindows = workbench.getWorkbenchWindows();
     for (int i = 0; i < workbenchWindows.length; i++) {
       IWorkbenchWindow workbenchWindow = workbench.getWorkbenchWindows()[i];
       ISelectionService selectionService = workbenchWindow.getSelectionService();
       selectionService.addPostSelectionListener(selectedBindingManager);
     }
   }
   return selectedBindingManager;
 }
 /**
  * Retrieves and return the current selection
  *
  * @return the current selection
  */
 protected ISelection getSelection() {
   ISelectionService selectionService = getSelectionService();
   if (selectionService != null) {
     return selectionService.getSelection();
   }
   return null;
 }
 private static ISelection getSelection() {
   IWorkbench workbench = PlatformUI.getWorkbench();
   IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
   ISelectionService selectionService = workbenchWindow.getSelectionService();
   ISelection selection = selectionService.getSelection();
   return selection;
 }
  @Override
  public void dispose() {
    // on disposal remove the selection listener
    ISelectionService s = getSite().getWorkbenchWindow().getSelectionService();
    s.removeSelectionListener(selectionListener);

    super.dispose();
  }
 private static IProject getSelectedProject(String viewID) {
   ISelectionService service = UIUtils.getActiveWorkbenchWindow().getSelectionService();
   IStructuredSelection structured = (IStructuredSelection) service.getSelection(viewID);
   if (structured instanceof IStructuredSelection) {
     Object selectedObject = ((IStructuredSelection) structured).getFirstElement();
     if (selectedObject instanceof IAdaptable) {
       IResource resource = (IResource) ((IAdaptable) selectedObject).getAdapter(IResource.class);
       if (resource != null) {
         return resource.getProject();
       }
     }
   }
   return null;
 }
 private String getActiveProject() {
   IWorkbench wb = PlatformUI.getWorkbench();
   ISelectionService iss = wb.getActiveWorkbenchWindow().getSelectionService();
   String projExpID = "org.eclipse.ui.navigator.ProjectExplorer";
   ISelection sel = iss.getSelection(projExpID);
   Object selectedObject = null;
   if (sel instanceof IStructuredSelection) {
     selectedObject = ((IStructuredSelection) sel).getFirstElement();
   }
   if (selectedObject instanceof IAdaptable) {
     IResource res = (IResource) ((IAdaptable) selectedObject).getAdapter(IResource.class);
     IProject project = res.getProject();
     return project.getName();
   }
   return "";
 }
  public void removeSelectionChangedListener(final ISelectionChangedListener listener) {
    final SelectionListenerAdapter adapter = m_adapters.get(listener);

    if (adapter != null) {
      m_selectionService.removeSelectionListener(adapter);
      m_adapters.remove(listener);
    }
  }
  /**
   * getSelected element in the diagram or in hte model explorer
   *
   * @return Element or null
   */
  protected ArrayList<Element> getSelectionSet() {
    ArrayList<Element> selectedSet = new ArrayList<Element>();
    ISelectionService selectionService =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
    ISelection selection = selectionService.getSelection();

    // look for papyrus
    int i = 0;
    while (!(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
            instanceof IMultiDiagramEditor)
        && i < 100000) {
      i++;
    }
    if ((PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
        instanceof IMultiDiagramEditor)) {
      IEditorPart editorPart =
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
      papyrusEditor = ((PapyrusMultiDiagramEditor) editorPart);

      if (selection instanceof IStructuredSelection) {
        @SuppressWarnings("rawtypes")
        Iterator selectedobjectIteractor = ((IStructuredSelection) selection).iterator();
        while (selectedobjectIteractor.hasNext()) {
          Object currentSelection = selectedobjectIteractor.next();
          if (currentSelection instanceof GraphicalEditPart) {
            Object graphicalElement = ((GraphicalEditPart) currentSelection).getModel();
            if ((graphicalElement instanceof View)
                && ((View) graphicalElement).getElement() instanceof org.eclipse.uml2.uml.Element) {
              selectedSet.add(
                  (org.eclipse.uml2.uml.Element) ((View) graphicalElement).getElement());
            }
          } else if (currentSelection instanceof IAdaptable) {
            EObject selectedEObject =
                (EObject) ((IAdaptable) currentSelection).getAdapter(EObject.class);
            if (selectedEObject instanceof org.eclipse.uml2.uml.Element) {
              selectedSet.add((Element) selectedEObject);
            }
          }
        }
      }
      return selectedSet;
    }
    return selectedSet;
  }
  /**
   * @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$
      }
    }
  }
 /**
  * This method returns currently selected project in workspace. Do not use WAEclipseHelper Utility
  * method instead of this method
  *
  * @return IProject
  */
 private IProject getSelectProject() {
   IWorkbench workbench = PlatformUI.getWorkbench();
   IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
   ISelectionService service = window.getSelectionService();
   ISelection selection = service.getSelection();
   Object element = null;
   IResource resource;
   IProject selProject = null;
   if (selection instanceof IStructuredSelection) {
     IStructuredSelection structuredSel = (IStructuredSelection) selection;
     element = structuredSel.getFirstElement();
   }
   if (element instanceof IProject) {
     resource = (IResource) element;
     selProject = resource.getProject();
   } else if (element instanceof IJavaProject) {
     IJavaProject proj = ((IJavaElement) element).getJavaProject();
     selProject = proj.getProject();
   }
   return selProject;
 }
 /**
  * This method returns currently selected project in workspace.
  *
  * @return IProject
  */
 public static IProject getSelectedProject() {
   IWorkbench workbench = PlatformUI.getWorkbench();
   IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
   ISelectionService service = window.getSelectionService();
   ISelection selection = service.getSelection();
   Object element = null;
   IResource resource;
   IProject selProject = null;
   if (selection instanceof IStructuredSelection) {
     IStructuredSelection structuredSel = (IStructuredSelection) selection;
     element = structuredSel.getFirstElement();
   }
   if (element instanceof IResource) {
     resource = (IResource) element;
     selProject = resource.getProject();
   } else {
     IWorkbenchPage page = window.getActivePage();
     IFile file = (IFile) page.getActiveEditor().getEditorInput().getAdapter(IFile.class);
     selProject = file.getProject();
   }
   return selProject;
 }
  /**
   * getSelected element in the diagram or in hte model explorer
   *
   * @return Element or null
   */
  protected Element getSelection() {
    org.eclipse.uml2.uml.Element selectedElement = null;
    ISelectionService selectionService =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
    ISelection selection = selectionService.getSelection();
    // look for papyrus
    int i = 0;
    while (!(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
            instanceof IMultiDiagramEditor)
        && i < 100000) {
      i++;
    }
    if ((PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
        instanceof IMultiDiagramEditor)) {
      IEditorPart editorPart =
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
      papyrusEditor = ((PapyrusMultiDiagramEditor) editorPart);

      if (selection instanceof IStructuredSelection) {
        Object selectedobject = ((IStructuredSelection) selection).getFirstElement();
        if (selectedobject instanceof GraphicalEditPart) {
          Object graphicalElement = ((GraphicalEditPart) selectedobject).getModel();
          if ((graphicalElement instanceof View)
              && ((View) graphicalElement).getElement() instanceof org.eclipse.uml2.uml.Element) {
            selectedElement = (org.eclipse.uml2.uml.Element) ((View) graphicalElement).getElement();
          }
        } else if (selectedobject instanceof IAdaptable) {
          EObject selectedEObject =
              (EObject) ((IAdaptable) selectedobject).getAdapter(EObject.class);
          if (selectedEObject instanceof org.eclipse.uml2.uml.Element) {
            selectedElement = (Element) selectedEObject;
          }
        }
      }
      return selectedElement;
    }
    return null;
  }
  /**
   * 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(final TreeElement elementToSelect) {
    Display.getDefault()
        .syncExec(
            new Runnable() {

              public void run() {
                commonViewer.setSelection(new StructuredSelection(elementToSelect));
              }
            });

    IStructuredSelection currentSelection = (IStructuredSelection) selectionService.getSelection();
    Assert.assertEquals(
        "Only one element should be selected", 1, currentSelection.size()); // $NON-NLS-1$
    Object obj = currentSelection.getFirstElement();
    Assert.assertSame(
        "the current selected element is not the wanted element",
        elementToSelect,
        obj); //$NON-NLS-1$
  }
  /**
   * 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$
  }
 protected IStructuredSelection getCurrentSelection() {
   return (IStructuredSelection) selectionService.getSelection();
 }
Exemple #16
0
  /** here the purpose is to test the creation of constraint on variable elements. */
  @Test
  public void testOpendiagramTest() throws Exception {

    // get the rootModel
    Assert.assertNotNull("RootModel is null", getRootUMLModel()); // $NON-NLS-1$
    // get all semantic elment that will handled
    Model model = (Model) getRootUMLModel();
    org.eclipse.uml2.uml.Class class1 =
        (org.eclipse.uml2.uml.Class) model.getPackagedElement("Class1");
    org.eclipse.uml2.uml.Class class2 =
        (org.eclipse.uml2.uml.Class) model.getPackagedElement("Class2");
    Diagram diagram1 = (Diagram) getPageManager().allPages().get(0);
    Diagram diagram2 = (Diagram) getPageManager().allPages().get(1);

    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    ISelectionService selectionService = activeWorkbenchWindow.getSelectionService();
    modelExplorerView = getModelExplorerView();
    modelExplorerView.setFocus();
    ArrayList<Object> elements = new ArrayList<Object>();
    elements.add(getRootUMLModel());
    modelExplorerView.revealSemanticElement(elements);

    // getItem for model
    Object modelTreeObject =
        ((IStructuredSelection) selectionService.getSelection()).getFirstElement();
    Assert.assertNotNull("Model TreeElement is null", modelTreeObject); // $NON-NLS-1$

    // get Item for class1
    elements.clear();
    elements.add(class1);
    modelExplorerView.revealSemanticElement(elements);
    Object class1TreeObject =
        ((IStructuredSelection) selectionService.getSelection()).getFirstElement();
    Assert.assertNotNull("Class1 TreeElement is null", class1TreeObject); // $NON-NLS-1$

    // get Item for class2
    elements.clear();
    elements.add(class2);
    modelExplorerView.revealSemanticElement(elements);
    Object class2TreeObject =
        ((IStructuredSelection) selectionService.getSelection()).getFirstElement();
    Assert.assertNotNull("Class2 TreeElement is null", class2TreeObject); // $NON-NLS-1$

    // get Item for diagram1
    elements.clear();
    elements.add(diagram1);
    modelExplorerView.revealSemanticElement(elements);
    Object diagram1TreeObject =
        ((IStructuredSelection) selectionService.getSelection()).getFirstElement();
    Assert.assertNotNull("digram1 TreeElement is null", diagram1TreeObject); // $NON-NLS-1$
    // get Item for diagram2
    elements.clear();
    elements.add(diagram2);
    modelExplorerView.revealSemanticElement(elements);
    Object diagram2TreeObject =
        ((IStructuredSelection) selectionService.getSelection()).getFirstElement();
    Assert.assertNotNull("digram2 TreeElement is null", diagram2TreeObject); // $NON-NLS-1$

    // test icons of closed diagram
    DecoratingLabelProviderWTooltips labeProvider =
        (DecoratingLabelProviderWTooltips) modelExplorerView.getCommonViewer().getLabelProvider();
    Assert.assertNotEquals(
        "the label of diagram1 is not good",
        "Diagram1",
        labeProvider.getText(diagram1)); // $NON-NLS-1$ //$NON-NLS-2$
    Assert.assertNotEquals(
        "the label of class1 is not good",
        "class1",
        labeProvider.getText(class1)); // $NON-NLS-1$ //$NON-NLS-2$

    // now test image about diagram for open and closed diagram
    // select all Tree element in the common viewer.
  }
Exemple #17
0
 private void removeSelectionListener() {
   ISelectionService service = getSite().getWorkbenchWindow().getSelectionService();
   service.removeSelectionListener(this.selectionListener);
 }
  /**
   * To draw controls on page.
   *
   * @param parent
   */
  @Override
  public void createControl(Composite parent) {
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IWorkspaceRoot root = workspace.getRoot();

    // display help contents
    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(
            parent.getShell(), "com.persistent.winazure.eclipseplugin." + "windows_azure_project");

    GridLayout gridLayout = new GridLayout();
    GridData gridData = new GridData();

    gridData.grabExcessHorizontalSpace = true;
    Composite container = new Composite(parent, SWT.NONE);

    container.setLayout(gridLayout);
    container.setLayoutData(gridData);

    // Composite for Project name label & text box
    createProjNameComposite(container);

    buttonUseDefLoc = new Button(container, SWT.CHECK);
    buttonUseDefLoc.setText(Messages.wizPageDefaultLoc);
    buttonUseDefLoc.setSelection(true);
    buttonUseDefLoc.addSelectionListener(
        new SelectionListener() {

          @Override
          public void widgetSelected(SelectionEvent arg0) {
            Button button = (Button) arg0.getSource();
            if (button.getSelection()) {
              lblLocation.setEnabled(false);
              textLocation.setText(root.getLocation().toPortableString());
              textLocation.setEnabled(false);
              buttonBrowse.setEnabled(false);
              setErrorMessage(null);
              setPageComplete(true);
            } else {
              lblLocation.setEnabled(true);
              textLocation.setEnabled(true);
              textLocation.setText(""); // $NON-NLS-1$
              buttonBrowse.setEnabled(true);
              setDescription(Messages.wizPageEnterLoc);
              setPageComplete(false);
            }
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent arg0) {}
        });
    gridData = new GridData();
    gridData.horizontalIndent = 5;
    buttonUseDefLoc.setLayoutData(gridData);

    // Composite for location of project
    createProjLocComposite(container);

    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    ISelectionService service = window.getSelectionService();
    ISelection selection = service.getSelection();

    IStructuredSelection structuredSel;
    if (selection instanceof IStructuredSelection) {
      structuredSel = (IStructuredSelection) selection;
    } else {
      structuredSel = new StructuredSelection();
    }

    workingSetGroup =
        new WorkingSetGroup(
            container, structuredSel, new String[] {Messages.rsrcPage, Messages.javaPage});
    setControl(container);
  }
  public void addSelectionChangedListener(final ISelectionChangedListener listener) {
    final SelectionListenerAdapter adapter = new SelectionListenerAdapter(listener);

    m_adapters.put(listener, adapter);
    m_selectionService.addSelectionListener(adapter);
  }
 public ISelection getSelection() {
   return m_selectionService.getSelection();
 }