Esempio n. 1
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);
     }
   }
 }
Esempio n. 2
0
 protected static IViewPart createNewView() {
   IWorkbenchPage activePage =
       PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
   int nbView = 0;
   for (IViewReference ref : activePage.getViewReferences()) {
     if (ref.getId().startsWith(VIEW_ID)) {
       nbView++;
     }
   }
   // increment to have the second view named #2
   nbView++;
   IViewPart view = null;
   try {
     view = activePage.showView(VIEW_ID, VIEW_ID + "_" + nbView, IWorkbenchPage.VIEW_ACTIVATE);
     // view.
   } catch (PartInitException e) {
     e.printStackTrace();
   }
   return view;
 }
  private void selectAndReveal(final ISelection selection) {
    // validate the input
    IWorkbenchPage page = fSite.getPage();
    if (page == null) return;

    // get all the view and editor parts
    List parts = new ArrayList();
    IWorkbenchPartReference refs[] = page.getViewReferences();
    for (int i = 0; i < refs.length; i++) {
      IWorkbenchPart part = refs[i].getPart(false);
      if (part != null) parts.add(part);
    }
    refs = page.getEditorReferences();
    for (int i = 0; i < refs.length; i++) {
      if (refs[i].getPart(false) != null) parts.add(refs[i].getPart(false));
    }

    Iterator itr = parts.iterator();
    while (itr.hasNext()) {
      IWorkbenchPart part = (IWorkbenchPart) itr.next();

      // get the part's ISetSelectionTarget implementation
      ISetSelectionTarget target = null;
      if (part instanceof ISetSelectionTarget) target = (ISetSelectionTarget) part;
      else target = (ISetSelectionTarget) part.getAdapter(ISetSelectionTarget.class);

      if (target != null) {
        // select and reveal resource
        final ISetSelectionTarget finalTarget = target;
        page.getWorkbenchWindow()
            .getShell()
            .getDisplay()
            .asyncExec(
                new Runnable() {
                  public void run() {
                    finalTarget.selectReveal(selection);
                  }
                });
      }
    }
  }
  /**
   * maximum display CheatSheetView.
   *
   * @param view
   */
  public void maxDisplayCheatSheetView(CheatSheetView view) {
    // ADD msjian TDQ-7407 2013-8-23: Only display the Cheat Sheet view on new startup of the studio
    IWorkbenchPage activePage =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    activePage.setEditorAreaVisible(true);
    // activePage.resetPerspective();
    for (IViewReference ref : activePage.getViewReferences()) {
      if (view.equals(ref.getView(false))) {
        activePage.setPartState(ref, IWorkbenchPage.STATE_MAXIMIZED);
        activePage.bringToTop(ref.getView(false));
      } else {
        activePage.setPartState(ref, IWorkbenchPage.STATE_MINIMIZED);
      }
    }
    for (IEditorReference ref : activePage.getEditorReferences()) {
      activePage.setPartState(ref, IWorkbenchPage.STATE_MINIMIZED);
    }

    PrefUtil.getAPIPreferenceStore().setValue(this.getClass().getSimpleName(), true);
    setFirstTime(!PrefUtil.getAPIPreferenceStore().getBoolean(this.getClass().getSimpleName()));
    // TDQ-7407~
  }
  @Override
  public void perspectiveChanged(
      IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) {

    if (changeId.matches("viewShow")) {
      for (IViewReference ref : page.getViewReferences()) {
        if (ref.getId().matches(QueryExplorer.ID)) {
          CheckboxTableViewer tableViewer = QueryExplorer.getInstance().getPatternsViewer();
          int size = tableViewer.getTable().getItems().length;

          for (int i = 0; i < size; i++) {
            String element = tableViewer.getElementAt(i).toString();
            if (PatternRegistry.getInstance().isActive(element)) {
              tableViewer.setChecked(element, true);
            } else {
              tableViewer.setChecked(element, false);
            }
          }
        }
      }
    }

    super.perspectiveChanged(page, perspective, changeId);
  }
  public void showView(String hostname, String channelName) throws PartInitException {
    String buildSecondaryId = SecondaryIDCodec.buildSecondaryId(hostname, channelName);

    IWorkbenchPage activePage =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

    ChannelView view = null;

    IViewReference[] viewReferences = activePage.getViewReferences();
    for (IViewReference iViewReference : viewReferences) {
      if (iViewReference.getSecondaryId().equals(buildSecondaryId)) {
        view = (ChannelView) iViewReference.getView(false);
        break;
      }
    }

    if (view == null) {
      view =
          (ChannelView)
              activePage.showView(ChannelView.ID, buildSecondaryId, IWorkbenchPage.VIEW_ACTIVATE);
    }

    new ChannelViewPresenter(Networks.getInstance().get(hostname).getChannel(channelName), view);
  }
Esempio n. 7
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);
   }
 }