Example #1
0
 @Override
 public IWorkbenchPartSite getSite() {
   if (view != null) {
     return view.getSite();
   } else {
     return null;
   }
 }
  private void dumpToWriter(ArrayList<String> list) {
    /*for (String string : list) {
    	System.out.println(string); // echo to the console
    }*/

    SaveScriptIOTablesDialog saveDialog =
        new SaveScriptIOTablesDialog(view.getSite().getShell(), list);
    saveDialog.setBlockOnOpen(true);
    saveDialog.open();
  }
 private void handleGoToPackage(ISelection selection) {
   IPackageFragment frag = getPackageFragment(selection);
   if (frag != null)
     try {
       IViewPart part = PDEPlugin.getActivePage().showView(JavaUI.ID_PACKAGES);
       ShowInPackageViewAction action = new ShowInPackageViewAction(part.getSite());
       action.run(frag);
     } catch (PartInitException e) {
     }
 }
  @Test
  public void testRun() {
    File repositoryLocation = repositoryHelper.createRegisteredRepository("repo");
    projectHelper = new ProjectHelper(repositoryLocation.getParentFile());

    runActionDelegate(projectHelper.getProject());

    IViewPart consoleView = getConsoleView();
    assertThat(consoleView).isNotNull();
    assertThat(consoleView.getSite().getPage().getActivePart()).isEqualTo(consoleView);
  }
 /**
  * Creates a new <code>OpenActionGroup</code>. The group requires that the selection provided by
  * the given selection provider is of type {@link IStructuredSelection}.
  *
  * @param part the view part that owns this action group
  * @param selectionProvider the selection provider used instead of the page selection provider.
  * @since 3.2
  */
 public OpenViewActionGroup(IViewPart part, ISelectionProvider selectionProvider) {
   createSiteActions(part.getSite(), selectionProvider);
   // we do a name check here to avoid class loading.
   String partName = part.getClass().getName();
   fIsTypeHiararchyViewerOwner =
       "org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyViewPart"
           .equals(partName); // $NON-NLS-1$
   fIsCallHiararchyViewerOwner =
       "org.eclipse.jdt.internal.ui.callhierarchy.CallHierarchyViewPart"
           .equals(partName); // $NON-NLS-1$
 }
  @Override
  public void init(IViewPart view) {
    fView = view;

    // Get the current selection from the DebugView so we can determine if we want this menu action
    // to be live or not.
    IDebugContextService debugContextService =
        DebugUITools.getDebugContextManager()
            .getContextService(view.getSite().getWorkbenchWindow());
    debugContextService.addPostDebugContextListener(this);
    fDebugContext = debugContextService.getActiveContext();
  }
 @Override
 public void init(IViewPart view) {
   IWorkbenchWindow workbenchWindow = view.getSite().getWorkbenchWindow();
   setWindow(workbenchWindow);
   setSelection(workbenchWindow.getSelectionService().getSelection());
 }
  private void selectFiles(IProject project, List<? extends IResource> createdFiles) {
    // Attempt to select the newly created files in the Package Explorer
    IWorkbench workbench = AdtPlugin.getDefault().getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    IViewPart viewPart = page.findView(JavaUI.ID_PACKAGES);
    if (viewPart != null) {
      IWorkbenchPartSite site = viewPart.getSite();
      IJavaProject javaProject = null;
      try {
        javaProject = BaseProjectHelper.getJavaProject(project);
      } catch (CoreException e) {
        AdtPlugin.log(e, null);
      }
      final ISelectionProvider provider = site.getSelectionProvider();
      if (provider != null) {
        List<TreePath> pathList = new ArrayList<TreePath>();
        for (IResource file : createdFiles) {
          // Create a TreePath for the given file,
          // which should be the JavaProject, followed by the folders down to
          // the final file.
          List<Object> segments = new ArrayList<Object>();
          segments.add(file);
          IContainer folder = file.getParent();
          if (folder != null && !(folder instanceof IProject)) {
            segments.add(folder);
            // res folder
            folder = folder.getParent();
            if (folder != null && !(folder instanceof IProject)) {
              segments.add(folder);
            }
          }
          // project
          segments.add(javaProject);

          Collections.reverse(segments);
          TreePath path = new TreePath(segments.toArray());
          pathList.add(path);

          // IDEA: Maybe normalize the files backwards (IFile objects aren't unique)
          // by maybe using the package explorer icons instead
        }

        TreePath[] paths = pathList.toArray(new TreePath[pathList.size()]);
        final TreeSelection selection = new TreeSelection(paths);

        provider.setSelection(selection);

        // Workaround: The above doesn't always work; it will frequently select
        // some siblings of the real files. I've tried a number of workarounds:
        // normalizing the IFile objects by looking up the canonical ones via
        // their relative paths from the project; deferring execution with
        // Display.asyncRun; first calling select on the parents, etc.
        // However, it turns out a simple workaround works best: Calling this
        // method TWICE. The first call seems to expand all the necessary parents,
        // and the second call ensures that the correct children are selected!
        provider.setSelection(selection);

        viewPart.setFocus();
      }
    }
  }
Example #9
0
 /**
  * Creates a new <code>OpenActionGroup</code>. The group requires that the selection provided by
  * the part's selection provider is of type <code>
  * org.eclipse.jface.viewers.IStructuredSelection</code>.
  *
  * @param part the view part that owns this action group
  */
 public OpenEditorActionGroup(IViewPart part) {
   fSite = part.getSite();
   fOpen = new OpenAction(fSite);
   fOpen.setActionDefinitionId(IScriptEditorActionDefinitionIds.OPEN_EDITOR);
   initialize(fSite.getSelectionProvider());
 }
 /**
  * Creates a new <code>FindOccurrencesInFileAction</code>. The action requires that the selection
  * provided by the view part's selection provider is of type <code>
  * org.eclipse.jface.viewers.IStructuredSelection</code>.
  *
  * @param part the part providing context information for this action
  */
 public FindOccurrencesInFileAction(IViewPart part) {
   this(part.getSite());
 }
 /**
  * Creates a new <code>GenerateActionGroup</code>. The group requires that the selection provided
  * by the part's selection provider is of type <code>
  * org.eclipse.jface.viewers.IStructuredSelection</code>.
  *
  * @param part the view part that owns this action group
  */
 public GenerateIncludePathActionGroup(IViewPart part) {
   this(part.getSite());
 }
 /**
  * Creates a new <code>GenerateActionGroup</code>. The group requires that the selection provided
  * by the part's selection provider is of type <code>
  * org.eclipse.jface.viewers.IStructuredSelection</code>.
  *
  * @param part the view part that owns this action group
  */
 public GenerateActionGroup(IViewPart part) {
   this(part.getSite());
 }
  /* (non-Javadoc)
   * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
   */
  @SuppressWarnings("rawtypes")
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    // Get the view
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IWorkbenchPage page = window.getActivePage();
    IViewPart view = page.findView(LogResourcesView.ID);
    // Get the selection
    ISelection selection = view.getSite().getSelectionProvider().getSelection();
    if ((selection != null) && (selection instanceof IStructuredSelection)) {
      if (!MessageDialog.openQuestion(
          Display.getDefault().getActiveShell(),
          Messages.RemoveLogResourceHandler_confirm_title,
          Messages.RemoveLogResourceHandler_confirm_question)) {
        return null;
      }

      // Collect for multi status
      List<IStatus> statuses = new ArrayList<IStatus>();
      Iterator it = ((IStructuredSelection) selection).iterator();
      while (it.hasNext()) {
        ILogResource log = (ILogResource) it.next();
        if (UIPlugin.getDefault().getLogResourceManager().isJobInProgress(log)) {
          // Log index is in use
          statuses.add(
              new Status(
                  IStatus.INFO,
                  UIPlugin.PLUGIN_ID,
                  NLS.bind(Messages.Generic_info_jobInProgress, log.getName())));
          continue;
        }

        // Close editors
        IEditorReference[] editorRefs =
            page.findEditors(
                (IEditorInput) log.getAdapter(IEditorInput.class),
                null,
                IWorkbenchPage.MATCH_INPUT);
        page.closeEditors(editorRefs, false);

        try {
          UIPlugin.getDefault().getLogResourceManager().remove(log);
        } catch (CoreException e) {
          statuses.add(e.getStatus());
        }
      }

      // Save log resources
      try {
        UIPlugin.getDefault().getLogResourceManager().saveState();
      } catch (CoreException e) {
        statuses.add(e.getStatus());
      }

      // Refresh resource view
      IRefreshablePart refresh = (IRefreshablePart) view.getAdapter(IRefreshablePart.class);
      if (refresh != null) {
        refresh.refresh();
      }

      if (!statuses.isEmpty()) {
        IStatus multiStatus =
            new MultiStatus(
                UIPlugin.PLUGIN_ID,
                0,
                statuses.toArray(new IStatus[statuses.size()]),
                Messages.RemoveLogResourceHandler_info_someCouldNotBeRemoved,
                null);
        // Log and show error
        UIPlugin.logAndShowError(new CoreException(multiStatus), false);
      }
    }
    return null;
  }
  /**
   * selectionChanged() event handler. Fills the list of managed-built projects based on the
   * selection. If some non-managed-built projects are selected, disables the action.
   *
   * @param action The action
   * @param selection The selection
   */
  protected void onSelectionChanged(IAction action, ISelection selection) {
    fProjects.clear();

    boolean badObject = false;

    if (selection != null) {
      if (selection instanceof IStructuredSelection) {
        if (selection.isEmpty()) {
          // could be a form editor or something.  try to get the project from the active part
          IWorkbenchPage page = CUIPlugin.getActivePage();
          if (page != null) {
            IWorkbenchPart part = page.getActivePart();
            if (part != null) {
              Object o = part.getAdapter(IResource.class);
              if (o != null && o instanceof IResource) {
                fProjects.add(((IResource) o).getProject());
              }
            }
          }
        }
        Iterator<?> iter = ((IStructuredSelection) selection).iterator();
        while (iter.hasNext()) {
          Object selItem = iter.next();
          IProject project = null;
          if (selItem instanceof ICElement) {
            ICProject cproject = ((ICElement) selItem).getCProject();
            if (cproject != null) project = cproject.getProject();
          } else if (selItem instanceof IResource) {
            project = ((IResource) selItem).getProject();
          } else if (selItem instanceof IncludeRefContainer) {
            ICProject fCProject = ((IncludeRefContainer) selItem).getCProject();
            if (fCProject != null) project = fCProject.getProject();
          } else if (selItem instanceof IncludeReferenceProxy) {
            IncludeRefContainer irc = ((IncludeReferenceProxy) selItem).getIncludeRefContainer();
            if (irc != null) {
              ICProject fCProject = irc.getCProject();
              if (fCProject != null) project = fCProject.getProject();
            }
          } else if (selItem instanceof IAdaptable) {
            Object adapter = ((IAdaptable) selItem).getAdapter(IProject.class);
            if (adapter != null && adapter instanceof IProject) {
              project = (IProject) adapter;
            }
          }
          // Check whether the project is CDT project
          if (project != null) {
            if (!CoreModel.getDefault().isNewStyleProject(project)) project = null;
            else {
              ICConfigurationDescription[] tmp = getCfgs(project);
              if (tmp.length == 0) project = null;
            }
          }
          if (project != null) {
            fProjects.add(project);
          } else {
            badObject = true;
            break;
          }
        }
      } else if (selection instanceof ITextSelection) {
        // If a text selection check the selected part to see if we can find
        // an editor part that we can adapt to a resource and then
        // back to a project.
        IWorkbenchWindow window = CUIPlugin.getActiveWorkbenchWindow();
        if (window != null) {
          IWorkbenchPage page = window.getActivePage();
          if (page != null) {
            IWorkbenchPart part = page.getActivePart();
            if (part instanceof IEditorPart) {
              IEditorPart epart = (IEditorPart) part;
              IResource resource = epart.getEditorInput().getAdapter(IResource.class);
              if (resource != null) {
                IProject project = resource.getProject();
                badObject = !(project != null && CoreModel.getDefault().isNewStyleProject(project));

                if (!badObject) {
                  fProjects.add(project);
                }
              }
            }
          }
        }

      } else if (selection instanceof ImaginarySelection) {
        fProjects.add(((ImaginarySelection) selection).getProject());
      }
    }

    boolean enable = false;
    if (!badObject && !fProjects.isEmpty()) {
      Iterator<IProject> iter = fProjects.iterator();
      ICConfigurationDescription[] firstConfigs = getCfgs(iter.next());
      if (firstConfigs != null) {
        for (ICConfigurationDescription firstConfig : firstConfigs) {
          boolean common = true;
          Iterator<IProject> iter2 = fProjects.iterator();
          while (iter2.hasNext()) {
            ICConfigurationDescription[] currentConfigs = getCfgs(iter2.next());
            int j = 0;
            for (; j < currentConfigs.length; j++) {
              if (firstConfig.getName().equals(currentConfigs[j].getName())) break;
            }
            if (j == currentConfigs.length) {
              common = false;
              break;
            }
          }
          if (common) {
            enable = true;
            break;
          }
        }
      }
    }
    action.setEnabled(enable);

    // Bug 375760
    // If focus is on a view that doesn't provide a resource/project context. Use the selection in a
    // project/resource view. We support three views. If more than one is open, nevermind. If
    // there's only
    // one project in the workspace and it's a CDT one, use it unconditionally.
    //
    // Note that whatever project we get here is just a candidate; it's tested for suitability when
    // we
    // call ourselves recursively
    //
    if (badObject || fProjects.isEmpty()) {
      // Check for lone CDT project in workspace
      IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
      if (projects != null && projects.length == 1) {
        IProject project = projects[0];
        if (CoreModel.getDefault().isNewStyleProject(project) && (getCfgs(project).length > 0)) {
          onSelectionChanged(action, new ImaginarySelection(project));
          return;
        }
      }

      // Check the three supported views
      IWorkbenchPage page = CUIPlugin.getActivePage();
      int viewCount = 0;
      if (page != null) {
        IViewReference theViewRef = null;
        IViewReference viewRef = null;

        theViewRef = page.findViewReference("org.eclipse.cdt.ui.CView"); // $NON-NLS-1$
        viewCount += (theViewRef != null) ? 1 : 0;

        viewRef = page.findViewReference("org.eclipse.ui.navigator.ProjectExplorer"); // $NON-NLS-1$
        viewCount += (viewRef != null) ? 1 : 0;
        theViewRef = (theViewRef == null) ? viewRef : theViewRef;

        viewRef = page.findViewReference("org.eclipse.ui.views.ResourceNavigator"); // $NON-NLS-1$
        viewCount += (viewRef != null) ? 1 : 0;
        theViewRef = (theViewRef == null) ? viewRef : theViewRef;

        if (theViewRef != null && viewCount == 1) {
          IViewPart view = theViewRef.getView(false);
          if (view != null) {
            ISelection cdtSelection = view.getSite().getSelectionProvider().getSelection();
            if (cdtSelection != null) {
              if (!cdtSelection.isEmpty()) {
                if (!cdtSelection.equals(selection)) { // avoids infinite recursion
                  onSelectionChanged(action, cdtSelection);
                }
              }
            }
          }
        }
      }
    }
  }
Example #15
0
 /**
  * Creates a new <code>OpenActionGroup</code>. The group requires that the selection provided by
  * the part's selection provider is of type <code>
  * org.eclipse.jface.viewers.IStructuredSelection</code>.
  *
  * @param part the view part that owns this action group
  */
 public OpenEditorActionGroup(IViewPart part) {
   this(part.getSite(), null);
 }