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) {
     }
 }
示例#2
0
 @Nullable
 public static <T> T findView(IWorkbenchWindow workbenchWindow, Class<T> viewClass) {
   IViewReference[] references = workbenchWindow.getActivePage().getViewReferences();
   for (IViewReference ref : references) {
     IViewPart view = ref.getView(false);
     if (view != null && viewClass.isAssignableFrom(view.getClass())) {
       return viewClass.cast(view);
     }
   }
   return null;
 }
  @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);
  }
示例#4
0
 /**
  * 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$
 }
示例#5
0
  private IOperation<? extends IOperationModel, ? extends OperationData>[] getOperations() {
    IViewPart view = getSite().getPage().findView("org.dawnsci.processing.ui.processingView");

    Object ob = view.getAdapter(IOperation.class);
    IOperation<? extends IOperationModel, ? extends OperationData>[] ops = null;

    if (ob == null) return null;

    if (ob.getClass().isArray() && Array.get(ob, 0) instanceof IOperation) {
      ops = (IOperation[]) ob;
    }

    return ops;
  }
 @SuppressWarnings("unchecked")
 public static <T extends IViewPart> Collection<T> getViews(String id, Class<T> clazz) {
   List<T> result = new LinkedList<T>();
   IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
   for (int i = 0; i < windows.length; ++i) {
     IWorkbenchPage[] pages = windows[i].getPages();
     for (int j = 0; j < pages.length; ++j) {
       IViewPart view = pages[j].findView(id);
       if (view != null) {
         if (clazz.isAssignableFrom(view.getClass())) result.add((T) view);
       }
     }
   }
   return result;
 }
示例#7
0
 /**
  * Show something in the status line; this is used when we don't have easy access to the view for
  * getting the StatusLineManager.
  *
  * @param message
  * @param debugMessage
  */
 private void showStatusMessage(String message, String debugMessage) {
   if (false) {
     message += " - "; // $NON-NLS-1$
     message += debugMessage;
   }
   IWorkbenchWindow ww = CommonPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
   IWorkbenchPage page = ww.getActivePage();
   IViewReference[] viewRefs = page.getViewReferences();
   for (int j = 0; j < viewRefs.length; j++) {
     IViewReference reference = viewRefs[j];
     IViewPart vp = reference.getView(false);
     if (vp != null) {
       vp.getViewSite().getActionBars().getStatusLineManager().setMessage(message);
     }
   }
 }
示例#8
0
 @Override
 public IWorkbenchPartSite getSite() {
   if (view != null) {
     return view.getSite();
   } else {
     return null;
   }
 }
 public void run(IAction action) {
   try {
     view.getViewSite().getWorkbenchWindow().getActivePage().showView(DatabaseBrowserView.ID);
   } catch (PartInitException e) {
     e.printStackTrace();
     String message = Messages.OpenInBrowserViewAction__errmsg_open_dbview;
     ExceptionDetailsDialog.openError(null, message, IStatus.ERROR, DatabasePlugin.PLUGIN_ID, e);
   }
 }
 /** Set the active editor */
 private void setActiveView(IWorkbenchPart part) {
   if (activeView == part) {
     return;
   }
   if (activeView != null) {
     activeView.removePropertyListener(propListener2);
     partsWithListeners.remove(activeView);
   }
   if (part instanceof IViewPart) {
     activeView = (IViewPart) part;
   } else {
     activeView = null;
   }
   if (activeView != null) {
     activeView.addPropertyListener(propListener2);
     partsWithListeners.add(activeView);
   }
   updateActiveSaveablePart();
 }
  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();
  }
 public CompanyExportActionDelegate(IWorkbenchWindow window) {
   this.window = window;
   shell = window.getShell();
   view =
       Activator.getDefault()
           .getWorkbench()
           .getActiveWorkbenchWindow()
           .getActivePage()
           .findView(AddressTreeView.ID);
   System.out.println("VIEW:" + view.getClass());
 }
  @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();
  }
示例#14
0
 private IAction getChartAction(IViewPart view) {
   IAction result = null;
   IToolBarManager manager = view.getViewSite().getActionBars().getToolBarManager();
   for (IContributionItem item : manager.getItems()) {
     if (item instanceof ActionContributionItem) {
       ActionContributionItem actionItem = (ActionContributionItem) item;
       if (actionItem.getAction().getId().equals(MassifViewPart.CHART_ACTION)) {
         result = actionItem.getAction();
       }
     }
   }
   return result;
 }
  public void setActiveView(IViewPart part) {
    IActionBars actionBars = part.getViewSite().getActionBars();
    if (!(part instanceof PropertySheet)) {
      actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), removeAction);
      actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), cutAction);
      actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction);
      actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), pasteAction);
    }
    actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
    actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);

    actionBars.updateActionBars();
  }
  /** @see org.eclipse.ui.part.IPage#setActionBars(org.eclipse.ui.IActionBars) */
  @Override
  public void setActionBars(final IActionBars actionBars) {
    // Override the undo and redo global action handlers
    // to use the contributor action handlers
    IActionBars partActionBars = null;
    if (contributor instanceof IEditorPart) {
      final IEditorPart editorPart = (IEditorPart) contributor;
      partActionBars = editorPart.getEditorSite().getActionBars();
    } else if (contributor instanceof IViewPart) {
      final IViewPart viewPart = (IViewPart) contributor;
      partActionBars = viewPart.getViewSite().getActionBars();
    }

    if (partActionBars != null) {
      IAction action = partActionBars.getGlobalActionHandler(ActionFactory.UNDO.getId());
      if (action != null) {
        actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), action);
      }
      action = partActionBars.getGlobalActionHandler(ActionFactory.REDO.getId());
      if (action != null) {
        actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), action);
      }
    }
  }
 /* (non-Javadoc)
  * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
  */
 public void init(IViewPart view) {
   this.window = view.getViewSite().getWorkbenchWindow();
 }
示例#18
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);
 }
 /**
  * Creates a new <code>DartSearchActionGroup</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 DartSearchActionGroup_OLD(IViewPart part) {
   this(part.getViewSite());
 }
  /**
   * 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);
                }
              }
            }
          }
        }
      }
    }
  }
 @Override
 public void init(IViewPart view) {
   IWorkbenchWindow workbenchWindow = view.getSite().getWorkbenchWindow();
   setWindow(workbenchWindow);
   setSelection(workbenchWindow.getSelectionService().getSelection());
 }
 /**
  * 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;
  }
示例#24
0
  @Override
  public void createPartControl(Composite parent) {

    fileManager = new FileManager(new SetupContextHelper());

    parent.setLayout(new GridLayout());
    viewer = new TableViewer(parent);
    viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    viewer.setLabelProvider(new ViewLabelProvider());
    viewer.setContentProvider(new BasicContentProvider());
    viewer.setInput(fileManager);
    viewer.addSelectionChangedListener(
        new ISelectionChangedListener() {

          @Override
          public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection() instanceof StructuredSelection) {
              inputData = null;
              eventManager.sendInputDataUpdate(null);
              selectedFile =
                  (String) ((StructuredSelection) event.getSelection()).getFirstElement();
              update(currentOperation);
            }
          }
        });
    ColumnViewerToolTipSupport.enableFor(viewer);

    DropTargetAdapter dropListener =
        new DropTargetAdapter() {
          @Override
          public void drop(DropTargetEvent event) {
            Object dropData = event.data;
            if (dropData instanceof TreeSelection) {
              TreeSelection selectedNode = (TreeSelection) dropData;
              Object obj[] = selectedNode.toArray();
              List<String> paths = new ArrayList<String>();
              for (int i = 0; i < obj.length; i++) {
                if (obj[i] instanceof IFile) {
                  IFile file = (IFile) obj[i];
                  paths.add(file.getLocation().toOSString());
                }
              }

              if (!paths.isEmpty()) fileManager.addFiles(paths.toArray(new String[paths.size()]));

            } else if (dropData instanceof String[]) {
              fileManager.addFiles((String[]) dropData);
            }
            viewer.setInput(fileManager);
          }
        };

    DropTarget dt =
        new DropTarget(viewer.getControl(), DND.DROP_MOVE | DND.DROP_DEFAULT | DND.DROP_COPY);
    dt.setTransfer(
        new Transfer[] {
          TextTransfer.getInstance(),
          FileTransfer.getInstance(),
          ResourceTransfer.getInstance(),
          LocalSelectionTransfer.getTransfer()
        });
    dt.addDropListener(dropListener);

    csw = new ChangeSliceWidget(parent);
    csw.addSliceChangeListener(
        new ISliceChangeListener() {

          @Override
          public void sliceChanged(SliceChangeEvent event) {
            inputData = null;
            eventManager.sendInputDataUpdate(null);
            String ss = Slice.createString(csw.getCurrentSlice());
            currentSliceLabel.setText("Current slice of data: [" + ss + "]");
            currentSliceLabel.getParent().layout(true);
            update(currentOperation);
          }
        });

    csw.disable();

    final MenuManager rightClick = new MenuManager();
    createActions(rightClick);
    viewer.getControl().setMenu(rightClick.createContextMenu(viewer.getControl()));

    getSite()
        .getPage()
        .addSelectionListener(
            "org.dawnsci.processing.ui.processingView",
            new ISelectionListener() {

              @Override
              public void selectionChanged(IWorkbenchPart part, ISelection selection) {

                if (selection instanceof StructuredSelection
                    && ((StructuredSelection) selection).getFirstElement()
                        instanceof OperationDescriptor) {
                  OperationDescriptor des =
                      (OperationDescriptor) ((StructuredSelection) selection).getFirstElement();
                  try {

                    currentOperation = des.getSeriesObject();
                    update(currentOperation);
                  } catch (InstantiationException e) {
                    logger.error(e.getMessage(), e);
                  }
                } else {
                  if (getOperations() == null || getOperations().length == 0) {
                    output.clear();
                  }
                }
              }
            });

    currentSliceLabel = new Label(parent, SWT.WRAP);
    currentSliceLabel.setText("Current slice of data: [ - - - - -]");

    IWorkbenchPage page = getSite().getPage();
    IViewPart view = page.findView("org.dawnsci.processing.ui.output");
    output = (IPlottingSystem<Composite>) view.getAdapter(IPlottingSystem.class);

    view = page.findView("org.dawnsci.processing.ui.input");
    input = (IPlottingSystem<Composite>) view.getAdapter(IPlottingSystem.class);

    fileManager.addFileListener(
        new IFilesAddedListener() {

          @Override
          public void filesAdded(FileAddedEvent event) {

            String[] paths = event.getPaths();
            boolean[] success = event.getSuccess();

            int first = -1;
            final List<String> failedPaths = new ArrayList<String>();
            for (int i = 0; i < success.length; i++) {
              if (success[i] && first < 0) first = i;
              if (!success[i]) failedPaths.add(paths[i]);
            }

            String dsName = "";

            try {
              dsName = " (" + fileManager.getContext().getDatasetNames().get(0) + ")";
            } catch (Exception e) {
              // ignore
            }

            final String dsn = dsName;

            final int f = first;

            Display.getDefault()
                .syncExec(
                    new Runnable() {

                      @Override
                      public void run() {
                        if (f < 0) {
                          MessageDialog.openError(
                              getSite().getShell(),
                              "Error loading files",
                              "None of the selected files contained suitable datasets" + dsn + "!");
                          return;
                        }

                        if (!failedPaths.isEmpty()) {
                          StringBuilder sb = new StringBuilder();
                          sb.append("Failed to load: ");
                          for (String p : failedPaths) sb.append(p + ", ");
                          sb.append("did not contain suitable datasets");
                          sb.append(dsn);

                          MessageDialog.openError(
                              getSite().getShell(), "Error loading some files", sb.toString());
                        }
                      }
                    });

            if (f < 0) return;

            final String path = paths[first];

            Display.getDefault()
                .syncExec(
                    new Runnable() {

                      @Override
                      public void run() {
                        viewer.refresh();
                        viewer.setSelection(new StructuredSelection(path), true);
                      }
                    });
          }
        });

    eventManager.addOperationRunnerListener(
        new IOperationGUIRunnerListener.Stub() {
          @Override
          public void updateRequested() {
            update(currentOperation);
          }
        });

    // hook up delete key to remove from list
    viewer
        .getTable()
        .addKeyListener(
            new KeyListener() {

              @Override
              public void keyReleased(KeyEvent e) {}

              @Override
              public void keyPressed(KeyEvent e) {
                if (e.keyCode == SWT.DEL) {
                  clearSelected();
                }
              }
            });
  }
 /**
  * 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>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());
 }
 @Override
 public void init(IViewPart view) {
   this.view = view;
   shell = view.getViewSite().getShell();
   System.out.println("VIEW::" + view.getClass());
 }
示例#28
0
 private void updateAnnotations(IWorkbenchWindow window, TCFNode node, Set<TCFAnnotation> set) {
   if (disposed) return;
   assert Thread.currentThread() == display.getThread();
   WorkbenchWindowInfo win_info = windows.get(window);
   if (win_info == null) return;
   Map<IEditorInput, IEditorPart> editors = new HashMap<IEditorInput, IEditorPart>();
   Map<IViewPart, ITCFDisassemblyPart> views = new HashMap<IViewPart, ITCFDisassemblyPart>();
   IWorkbenchPage page = window.getActivePage();
   if (page != null) {
     for (IEditorReference ref : page.getEditorReferences()) {
       IEditorPart editor = ref.getEditor(false);
       if (editor == null) continue;
       editors.put(editor.getEditorInput(), editor);
     }
     for (IViewReference ref : page.getViewReferences()) {
       IViewPart view = ref.getView(false);
       if (view == null) continue;
       ITCFDisassemblyPart disasm =
           (ITCFDisassemblyPart) view.getAdapter(ITCFDisassemblyPart.class);
       if (disasm != null) views.put(view, disasm);
     }
   }
   boolean flush_all =
       node == null
           || !views.keySet().equals(win_info.views.keySet())
           || !editors.equals(win_info.editors)
           || changed_launch_cfgs.contains(node.launch);
   win_info.views.clear();
   win_info.views.putAll(views);
   win_info.editors.clear();
   win_info.editors.putAll(editors);
   Iterator<TCFAnnotation> i = win_info.annotations.iterator();
   while (i.hasNext()) {
     TCFAnnotation a = i.next();
     if (!flush_all && set != null && set.remove(a)) continue;
     a.dispose();
     i.remove();
   }
   if (set != null) win_info.annotations.addAll(set);
   ISourcePresentation presentation = TCFModelPresentation.getDefault();
   // Disassembly views
   for (TCFAnnotation a : win_info.annotations) {
     if (a.addr == null) continue;
     for (ITCFDisassemblyPart disasm : views.values()) {
       IAnnotationModel ann_model = disasm.getAnnotationModel();
       if (ann_model == null) continue;
       if (a.models.contains(ann_model)) {
         ann_model.removeAnnotation(a);
         a.models.remove(ann_model);
       }
       Position p = disasm.getAddressPosition(a.addr);
       if (p == null) continue;
       if (a.breakpoint != null && hidePlantingAnnotation(ann_model, a.breakpoint, p)) continue;
       ann_model.addAnnotation(a, p);
       a.models.add(ann_model);
     }
   }
   // Disassembly editor
   for (TCFAnnotation a : win_info.annotations) {
     if (a.addr == null) continue;
     IEditorPart editor = editors.get(TCFModel.DisassemblyEditorInput.INSTANCE);
     if (editor == null) continue;
     ITCFDisassemblyPart disasm =
         (ITCFDisassemblyPart) editor.getAdapter(ITCFDisassemblyPart.class);
     if (disasm == null) continue;
     IAnnotationModel ann_model = disasm.getAnnotationModel();
     if (ann_model == null) continue;
     if (a.models.contains(ann_model)) {
       ann_model.removeAnnotation(a);
       a.models.remove(ann_model);
     }
     Position p = disasm.getAddressPosition(a.addr);
     if (p == null) continue;
     if (a.breakpoint != null && hidePlantingAnnotation(ann_model, a.breakpoint, p)) continue;
     ann_model.addAnnotation(a, p);
     a.models.add(ann_model);
   }
   // Source editors
   if (set == null) return;
   for (TCFAnnotation a : set) {
     if (a.area == null) continue;
     Object source_element = TCFSourceLookupDirector.lookup(node.launch, a.ctx, a.area);
     if (source_element == null) continue;
     IEditorInput editor_input = presentation.getEditorInput(source_element);
     IEditorPart editor = editors.get(editor_input);
     if (!(editor instanceof ITextEditor)) continue;
     IDocumentProvider doc_provider = ((ITextEditor) editor).getDocumentProvider();
     IAnnotationModel ann_model = doc_provider.getAnnotationModel(editor_input);
     if (ann_model == null) continue;
     IRegion region = null;
     try {
       doc_provider.connect(editor_input);
     } catch (CoreException e) {
     }
     try {
       IDocument document = doc_provider.getDocument(editor_input);
       if (document != null) region = document.getLineInformation(a.area.start_line - 1);
     } catch (BadLocationException e) {
     } finally {
       doc_provider.disconnect(editor_input);
     }
     if (region == null) continue;
     Position p = new Position(region.getOffset(), region.getLength());
     if (a.breakpoint != null && hidePlantingAnnotation(ann_model, a.breakpoint, p)) continue;
     ann_model.addAnnotation(a, p);
     a.models.add(ann_model);
   }
 }
  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();
      }
    }
  }
示例#30
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());
 }