コード例 #1
0
 /** Sets the spec loaded */
 public void setSelection(ISelection selection) {
   if (selection == null) {
     setSpecLoaded(null);
     return;
   }
   if (selection instanceof IStructuredSelection) {
     IStructuredSelection sSelection = (IStructuredSelection) selection;
     if (sSelection.toArray() instanceof Spec[]) {
       Spec[] specs = (Spec[]) sSelection.toArray();
       if (specs.length == 0) {
         setSpecLoaded(null);
       } else if (specs.length == 1) {
         setSpecLoaded(specs[0]);
       } else {
         throw new IllegalArgumentException("Only one specification can be selected");
       }
     } else {
       throw new IllegalArgumentException(
           "Workspace specification manager only accepts specification objects to be selected");
     }
   } else {
     throw new IllegalArgumentException(
         "Workspace specification manager only accepts specification object in a StructuredSelection");
   }
 }
コード例 #2
0
ファイル: CommonViewer.java プロジェクト: rgwch/elexis-3-core
 /**
  * Die aktuelle Auswahl des Viewers liefern
  *
  * @return null oder ein Array mit den selektierten Objekten-
  */
 public Object[] getSelection() {
   IStructuredSelection sel = (IStructuredSelection) viewer.getSelection();
   if (sel != null) {
     return sel.toArray();
   }
   return null;
 }
コード例 #3
0
  public final void downButtonClicked() {
    final IStructuredSelection selection =
        (IStructuredSelection)
            LoadCustomizationsDialog.this.selectedCustomizationsTreeViewer.getSelection();
    final ArrayList<Object> selectedObjects = new ArrayList<Object>();
    for (final Object selectedObject : selection.toArray()) {
      selectedObjects.add(selectedObject);
    }

    // prevent the last two elements from swapping
    boolean canMove =
        !selectedObjects.contains(
            LoadCustomizationsDialog.this.selectedCustomizations.get(
                LoadCustomizationsDialog.this.selectedCustomizations.size() - 1));
    for (int i = LoadCustomizationsDialog.this.selectedCustomizations.size() - 2; i >= 0; i--) {
      final Customization selectedCustomization =
          LoadCustomizationsDialog.this.selectedCustomizations.get(i);
      if (selectedObjects.contains(selectedCustomization)) {
        if (canMove) {
          LoadCustomizationsDialog.this.selectedCustomizations.move(i + 1, selectedCustomization);
        }
      } else {
        canMove = true;
      }
    }

    LoadCustomizationsDialog.this.selectedCustomizationsTreeViewer.refresh();
  }
コード例 #4
0
ファイル: ArtifactSearchPage.java プロジェクト: eclipse/osee
  private Collection<Artifact> getSelectedArtifacts() {
    IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection();

    Object[] objects = selection.toArray();
    if (objects.length == 0) {
      return Collections.emptyList();
    }

    AbstractArtifactSearchResult resultInput = getInput();
    if (resultInput == null) {
      return Collections.emptyList();
    }

    Set<Artifact> artifacts = new LinkedHashSet<>();
    for (Object object : objects) {
      Artifact toAdd = null;
      if (object instanceof AttributeLineElement) {
        toAdd = (Artifact) ((IAdaptable) object).getAdapter(Artifact.class);
        artifacts.add(toAdd);
      } else if (object instanceof IAdaptable) {
        toAdd = (Artifact) ((IAdaptable) object).getAdapter(Artifact.class);
      } else if (object instanceof Match) {
        toAdd = (Artifact) ((Match) object).getElement();
      }
      if (toAdd != null) {
        artifacts.add(toAdd);
      }
    }
    return artifacts;
  }
コード例 #5
0
    @Override
    public void run() {
      IStructuredSelection selection = (IStructuredSelection) getColumnViewer().getSelection();
      List<RevisionHistory> viewerInput = (List<RevisionHistory>) getColumnViewer().getInput();
      if (selection != null && !selection.isEmpty()) {
        Object[] objs = selection.toArray();
        for (int i = 0; i < objs.length; i++) {

          int oldIndex = viewerInput.indexOf(objs[i]);

          // 已经最顶了,上移无意义
          if (oldIndex == 0) {
            continue;
          }

          // 不能超过一起被选中的
          if (i > 0 && viewerInput.get(oldIndex - 1) == objs[i - 1]) {
            continue;
          }

          RevisionHistory tmp = viewerInput.get(oldIndex - 1);
          RevisionHistory item1 = CoreFactory.eINSTANCE.createRevisionHistory();
          RevisionHistory item2 = CoreFactory.eINSTANCE.createRevisionHistory();
          viewerInput.set(oldIndex - 1, item1);
          viewerInput.set(oldIndex, item2);
          viewerInput.set(oldIndex - 1, (RevisionHistory) objs[i]);
          viewerInput.set(oldIndex, tmp);
        }
      }

      getColumnViewer().setInput(viewerInput);
    }
コード例 #6
0
  protected void initializeViewer() {
    Object[] elems = fSelection.toArray();
    ArrayList checked = new ArrayList(elems.length);

    for (int i = 0; i < elems.length; i++) {
      Object elem = elems[i];
      IProject project = null;

      if (elem instanceof IFile) {
        IFile file = (IFile) elem;
        project = file.getProject();
      } else if (elem instanceof IProject) {
        project = (IProject) elem;
      } else if (elem instanceof IJavaProject) {
        project = ((IJavaProject) elem).getProject();
      }
      if (project != null) {
        IModel model = findModelFor(project);
        if (model != null && !checked.contains(model)) {
          checked.add(model);
        }
      }
    }
    fExportPart.setSelection(checked.toArray());
    if (checked.size() > 0) fExportPart.getTableViewer().reveal(checked.get(0));
  }
コード例 #7
0
ファイル: TagsFilterComposite.java プロジェクト: xored/rcptt
  private void updateFilterControl(IStructuredSelection selection) {
    if (selection.size() >= 1) {
      ArrayList<String> tags = new ArrayList<String>();
      for (Object o : selection.toArray()) {
        if (o instanceof Tag) {
          String tagName = ((Tag) o).getPath();
          if (tagName.matches(REGEX_SPEC_CHARS)) {
            tags.add("\"" + tagName + "\"");
          } else {
            tags.add(tagName);
          }
        }
      }

      proposalAdapter.setEnabled(false);
      searchControl.getFilterControl().setText(StringUtils.join(" " + OPERATOR_OR + " ", tags));
      proposalAdapter.setEnabled(true);
      if (selection.size() == 1) {
        listViewer.setInput(
            selection.getFirstElement()); // Don't run searching if only one tag is selected
      } else {
        updateList();
      }
    }
  }
コード例 #8
0
ファイル: RTHandler.java プロジェクト: marietafasie/eRAISE
  /* (non-Javadoc)
   * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
   */
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    // clear console
    Console.getInstance().clear();

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
      Activator.getDefault().testsStarted();

      // get the selections in the Project explorer
      IStructuredSelection selection =
          (IStructuredSelection)
              window.getSelectionService().getSelection("org.eclipse.ui.navigator.ProjectExplorer");
      final Object[] selectedElements = selection.toArray();

      BusyIndicator.showWhile(
          null,
          new Runnable() {
            @Override
            public void run() {
              // go through each open selected project
              for (int index = 0; index < selectedElements.length; index++) {
                Object element = selectedElements[index];
                log.debug("Calling runTestsObject on " + selectedElements[index]);
                runTestsObject(element);
              }
            }
          });
    }
    return null;
  }
コード例 #9
0
  /**
   * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
   *     org.eclipse.jface.viewers.IStructuredSelection)
   * @since 4.0
   */
  @Override
  public void init(final IWorkbench workbench, final IStructuredSelection originalSelection) {

    IStructuredSelection selection = originalSelection;
    openProjectExists = ModelerUiViewUtils.workspaceHasOpenModelProjects();
    if (!openProjectExists) {
      newProject = ModelerUiViewUtils.queryUserToCreateModelProject();

      if (newProject != null) {
        selection = new StructuredSelection(newProject);
        openProjectExists = true;
      } else {
        openProjectExists = false;
      }
    }

    if (isAllModelsSelected(selection)) {
      initialSelection = new StructuredSelection(selection.toArray());
    }
    if (selection != null && !selection.isEmpty()) {
      this.folder = ModelUtil.getContainer(selection.getFirstElement());
    }

    if (folder != null && !folderInModelProject()) {
      // Create empty page
      this.mainPage =
          new WizardPage(NewVdbWizard.class.getSimpleName(), PAGE_TITLE, null) {
            @Override
            public void createControl(final Composite parent) {
              setControl(createEmptyPageControl(parent));
            }
          };
      this.mainPage.setMessage(NOT_MODEL_PROJECT_MSG, IMessageProvider.ERROR);
    } else {

      // Create and add page
      this.mainPage =
          new WizardPage(NewVdbWizard.class.getSimpleName(), PAGE_TITLE, null) {
            @Override
            public void createControl(final Composite parent) {
              setControl(createPageControl(parent));
            }
          };
      this.mainPage.setMessage(INITIAL_MESSAGE);

      // If current selection not null, set folder to selection if a folder, or to containing folder
      // if not
      if (this.folder != null) {
        if (!projectValidator.validate(new Object[] {this.folder}).isOK()) {
          this.folder = null;
        }
      } else { // folder == null
        this.mainPage.setMessage(SELECT_FOLDER_MESSAGE, IMessageProvider.ERROR);
      }
    }

    this.mainPage.setPageComplete(false);
    addPage(mainPage);
  }
コード例 #10
0
 /**
  * Given a selection known to be a structured selection, casts it and returns its elements as
  * IJavaElements. Will throw CastClassException if any of the types are incorrect.
  */
 public static List<IJavaElement> structuredSelection(ISelection selection) {
   IStructuredSelection structured = (IStructuredSelection) selection;
   List<IJavaElement> elements = new LinkedList<IJavaElement>();
   for (Object sel_ : structured.toArray()) {
     elements.add((IJavaElement) sel_);
   }
   return elements;
 }
コード例 #11
0
 String getFilterSuggestionBasedOnMultipleSelection(IStructuredSelection selection) {
   String[] names = new String[selection.size()];
   int index = 0;
   for (Object event : selection.toArray()) {
     names[index++] = ((UsageDataEventWrapper) event).getBundleId();
   }
   return FilterUtils.getFilterSuggestionBasedOnBundleIds(names);
 }
コード例 #12
0
 @Override
 public void createControl(Composite parent) {
   super.createControl(parent);
   IStructuredSelection sel = ((BasicNewResourceWizard) getWizard()).getSelection();
   if (sel != null) {
     tableViewer.setCheckedElements(sel.toArray());
     setPageComplete(validatePage());
   }
 }
コード例 #13
0
ファイル: CleanUpAction.java プロジェクト: Tagin/aurora-ide
 public ICompilationUnit[] getCompilationUnits(IStructuredSelection selection) {
   HashSet<IJavaElement> result = new HashSet<IJavaElement>();
   Object[] selected = selection.toArray();
   for (int i = 0; i < selected.length; i++) {
     Object element = selected[i];
     collectCompilationUnits(element, result);
   }
   return result.toArray(new ICompilationUnit[result.size()]);
 }
 @Override
 public Object execute(ExecutionEvent event) throws ExecutionException {
   IStructuredSelection selection =
       (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
   for (Object obj : selection.toArray()) {
     TradeSuggestionManager.getCurrent().removeSuggestion((TradeSuggestion) obj);
   }
   return null;
 }
コード例 #15
0
 private void handleDelete() {
   IStructuredSelection ssel = (IStructuredSelection) fPluginTable.getSelection();
   if (ssel.size() > 0) {
     Object[] objects = ssel.toArray();
     IProductPlugin[] plugins = new IProductPlugin[objects.length];
     System.arraycopy(objects, 0, plugins, 0, objects.length);
     getProduct().removePlugins(plugins);
     updateRemoveButtons(true, true);
   }
 }
コード例 #16
0
  public ServicesHandler(IStructuredSelection selection) {
    Object[] objects = selection.toArray();
    cloudServices = new ArrayList<CloudService>();

    for (Object obj : objects) {
      if (obj instanceof CloudService) {
        cloudServices.add((CloudService) obj);
      }
    }
  }
コード例 #17
0
  protected LinkedList<Dependency> getDependenciesList() {
    IStructuredSelection selection = (IStructuredSelection) dependenciesViewer.getSelection();

    LinkedList<Dependency> dependencies = new LinkedList<Dependency>();

    for (Object obj : selection.toArray()) {
      dependencies.add((Dependency) obj);
    }

    return dependencies;
  }
  private void edit() {
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();

    Object[] objects = selection.toArray();
    if ((objects == null) || (objects.length != 1)) {
      return;
    }

    SonarLintProperty data = (SonarLintProperty) selection.getFirstElement();
    edit(data);
  }
コード例 #19
0
 private IType getSelectedType(IStructuredSelection selection) throws JavaModelException {
   final Object[] elements = selection.toArray();
   if (elements.length == 1 && (elements[0] instanceof IType)) {
     final IType type = (IType) elements[0];
     if (type.getCompilationUnit() != null && !type.isInterface()) {
       return type;
     }
   } else if (elements[0] instanceof ICompilationUnit) {
     final IType type = ((ICompilationUnit) elements[0]).findPrimaryType();
     if (type != null && !type.isInterface()) return type;
   }
   return null;
 }
コード例 #20
0
 private void handleProperties() {
   IStructuredSelection ssel = (IStructuredSelection) fPluginTable.getSelection();
   if (ssel.size() == 1) {
     IProductPlugin plugin = (IProductPlugin) ssel.toArray()[0];
     VersionDialog dialog =
         new VersionDialog(PDEPlugin.getActiveWorkbenchShell(), isEditable(), plugin.getVersion());
     dialog.create();
     SWTUtil.setDialogSize(dialog, 400, 200);
     if (dialog.open() == Window.OK) {
       plugin.setVersion(dialog.getVersion());
     }
   }
 }
コード例 #21
0
  private ICompilationUnit[] getCompilationUnits(IStructuredSelection selection) {
    HashSet result = new HashSet();
    Object[] selected = selection.toArray();
    for (int i = 0; i < selected.length; i++) {
      try {
        if (selected[i] instanceof IJavaElement) {
          IJavaElement elem = (IJavaElement) selected[i];
          if (elem.exists()) {

            switch (elem.getElementType()) {
              case IJavaElement.TYPE:
                if (elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) {
                  result.add(elem.getParent());
                }
                break;
              case IJavaElement.COMPILATION_UNIT:
                result.add(elem);
                break;
              case IJavaElement.IMPORT_CONTAINER:
                result.add(elem.getParent());
                break;
              case IJavaElement.PACKAGE_FRAGMENT:
                collectCompilationUnits((IPackageFragment) elem, result);
                break;
              case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                collectCompilationUnits((IPackageFragmentRoot) elem, result);
                break;
              case IJavaElement.JAVA_PROJECT:
                IPackageFragmentRoot[] roots = ((IJavaProject) elem).getPackageFragmentRoots();
                for (int k = 0; k < roots.length; k++) {
                  collectCompilationUnits(roots[k], result);
                }
                break;
            }
          }
        } else if (selected[i] instanceof LogicalPackage) {
          IPackageFragment[] packageFragments = ((LogicalPackage) selected[i]).getFragments();
          for (int k = 0; k < packageFragments.length; k++) {
            IPackageFragment pack = packageFragments[k];
            if (pack.exists()) {
              collectCompilationUnits(pack, result);
            }
          }
        }
      } catch (JavaModelException e) {
        if (JavaModelUtil.isExceptionToBeLogged(e)) JavaPlugin.log(e);
      }
    }
    return (ICompilationUnit[]) result.toArray(new ICompilationUnit[result.size()]);
  }
コード例 #22
0
ファイル: DeleteAction.java プロジェクト: anod/pdt
 public void run(IStructuredSelection selection) {
   if (ReorgUtils.containsOnlyProjects(selection.toList())) {
     createWorkbenchAction(selection).run();
     return;
   }
   try {
     startDeleteRefactoring(selection.toArray(), getShell());
   } catch (CoreException e) {
     ExceptionHandler.handle(
         e,
         RefactoringMessages.OpenRefactoringWizardAction_refactoring,
         RefactoringMessages.OpenRefactoringWizardAction_exception);
   }
 }
コード例 #23
0
ファイル: DeleteAction.java プロジェクト: anod/pdt
 /*
  * @see SelectionDispatchAction#selectionChanged(IStructuredSelection)
  */
 public void selectionChanged(IStructuredSelection selection) {
   if (ReorgUtils.containsOnlyProjects(selection.toList())) {
     setEnabled(createWorkbenchAction(selection).isEnabled());
     return;
   }
   try {
     setEnabled(RefactoringAvailabilityTester.isDeleteAvailable(selection.toArray()));
   } catch (CoreException e) {
     // no ui here - this happens on selection changes
     // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
     if (ScriptModelUtil.isExceptionToBeLogged(e)) DLTKUIPlugin.log(e);
     setEnabled(false);
   }
 }
コード例 #24
0
ファイル: OpenAction.java プロジェクト: athilani/erlide
 /*
  * (non-Javadoc) Method declared on SelectionDispatchAction.
  */
 @Override
 public void run(final IStructuredSelection selection) {
   if (!checkEnabled(selection)) {
     return;
   }
   for (final Object i : selection.toArray()) {
     if (i instanceof IErlElement) {
       try {
         ErlModelUtils.openElement((IErlElement) i);
       } catch (final CoreException e) {
         ErlLogger.error(e);
       }
     }
   }
 }
コード例 #25
0
  /** Remove selected entries */
  public void removeSelectedEntries() {
    IStructuredSelection selection = (IStructuredSelection) getSelection();
    Object[] objects = selection.toArray();

    // Make sure we didn't get the empty selection
    if (objects.length == 0) {
      return;
    }

    // Delete
    for (int i = 0; i < objects.length; i++) {
      fItems.remove(objects[i]);
    }

    refresh();
    getTable().notifyListeners(SWT.Modify, null);
  }
コード例 #26
0
  /**
   * Performs the drop when the selection is a collection of IExpressions. Moves the given
   * expressions from their original locations to the location of the current target.
   *
   * @param selection the dragged selection
   * @return whether the drop could be completed
   */
  private boolean performExpressionDrop(IStructuredSelection selection) {
    IExpression targetExpression = getTargetExpression(getCurrentTarget());
    if (targetExpression != null) {
      IExpression[] expressions = new IExpression[selection.size()];
      Object[] selectionElements = selection.toArray();
      for (int i = 0; i < selectionElements.length; i++) {
        expressions[i] = getTargetExpression(selectionElements[i]);
      }

      IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager();
      if (manager instanceof ExpressionManager) {
        ((ExpressionManager) manager).moveExpressions(expressions, targetExpression, fInsertBefore);
      }
      return true;
    }
    return false;
  }
コード例 #27
0
 @Override
 public void selectionChanged(final IAction action, final ISelection selection) {
   fLaunch = null;
   if (selection instanceof IStructuredSelection) {
     final IStructuredSelection ss = (IStructuredSelection) selection;
     for (final Object o : ss.toArray()) {
       if (o instanceof ErlangDebugElement) {
         final ErlangDebugElement d = (ErlangDebugElement) o;
         fLaunch = d.getLaunch();
       } else if (o instanceof ILaunch) {
         fLaunch = (ILaunch) o;
       } else if (o instanceof IProcess) {
         final IProcess p = (IProcess) o;
         fLaunch = p.getLaunch();
       }
     }
   }
 }
コード例 #28
0
  private IFileRevision getFileRevision() {
    IStructuredSelection structSel = selection;

    IFileRevision revision = null;

    if (structSel == null) return null;

    Object[] objArray = structSel.toArray();

    for (int i = 0; i < objArray.length; i++) {
      Object tempRevision = objArray[i];
      // If not a revision, don't try opening
      if (tempRevision instanceof AbstractHistoryCategory) continue;

      revision = (IFileRevision) tempRevision;
    }
    return revision;
  }
コード例 #29
0
  private void doAddNature() {
    if (!(selection instanceof IStructuredSelection)) return;

    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
    Object[] selectionElements = structuredSelection.toArray();
    for (int i = 0; i < selectionElements.length; i++) {
      Object selectionElement = selectionElements[i];
      if (selectionElement instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) selectionElement;
        IProject project = (IProject) adaptable.getAdapter(IProject.class);
        if (project == null) continue;

        // fetch the corresponding adding vjo nature policy implementation
        IAddVjoNaturePolicy policy = AddVjoNaturePolicyManager.getInstance().getPolicy(project);
        policy.addVjoNature(project);
      }
    }
  }
コード例 #30
0
  protected IProject[] getSelectedProjects(ISelection selection) {
    List<IProject> selectedProjects = new ArrayList<IProject>();

    if (selection instanceof IStructuredSelection) {
      IStructuredSelection structuredSelection = (IStructuredSelection) selection;
      Object[] selectedObjects = structuredSelection.toArray();
      for (int i = 0; i < selectedObjects.length; i++) {
        if (selectedObjects[i] instanceof IAdaptable) {
          IProject project =
              (IProject) ((IAdaptable) selectedObjects[i]).getAdapter(IProject.class);
          if (project != null) {
            selectedProjects.add(project);
          }
        }
      }
    }

    return (IProject[]) selectedProjects.toArray(new IProject[selectedProjects.size()]);
  }