protected void setSelectionToClient(
      VirtualTreeModelViewer virtualViewer, ILabelProvider labelProvider, VirtualItem findItem) {
    virtualViewer.getTree().setSelection(new VirtualItem[] {findItem});
    ModelDelta stateDelta = new ModelDelta(virtualViewer.getInput(), IModelDelta.NO_CHANGE);
    virtualViewer.saveElementState(TreePath.EMPTY, stateDelta, IModelDelta.SELECT);
    // Set the force flag to all select delta in order to override model's selection policy.
    stateDelta.accept(
        new IModelDeltaVisitor() {
          @Override
          public boolean visit(IModelDelta delta, int depth) {
            if ((delta.getFlags() & IModelDelta.SELECT) != 0) {
              ((ModelDelta) delta).setFlags(delta.getFlags() | IModelDelta.FORCE);
            }
            return true;
          }
        });
    fClientViewer.updateViewer(stateDelta);

    ISelection selection = fClientViewer.getSelection();
    if (!selection.isEmpty()
        && selection instanceof IStructuredSelection
        && ((IStructuredSelection) selection).getFirstElement().equals(findItem.getData())) {
    } else {
      DebugUIPlugin.errorDialog(
          fClientViewer.getControl().getShell(),
          ActionMessages.VirtualFindAction_0,
          MessageFormat.format(
              ActionMessages.VirtualFindAction_1, new Object[] {labelProvider.getText(findItem)}),
          new Status(
              IStatus.ERROR,
              DebugUIPlugin.getUniqueIdentifier(),
              ActionMessages.VirtualFindAction_1));
    }
  }
  @Override
  public void run() {
    final VirtualViewerListener listener = new VirtualViewerListener();
    VirtualTreeModelViewer virtualViewer = initVirtualViewer(fClientViewer, listener);

    ProgressMonitorDialog dialog =
        new TimeTriggeredProgressMonitorDialog(fClientViewer.getControl().getShell(), 500);
    final IProgressMonitor monitor = dialog.getProgressMonitor();
    dialog.setCancelable(true);

    try {
      dialog.run(
          true,
          true,
          new IRunnableWithProgress() {
            @Override
            public void run(final IProgressMonitor m)
                throws InvocationTargetException, InterruptedException {
              synchronized (listener) {
                listener.fProgressMonitor = m;
                listener.fProgressMonitor.beginTask(
                    DebugUIPlugin.removeAccelerators(getText()), listener.fRemainingUpdatesCount);
              }

              while ((!listener.fLabelUpdatesComplete || !listener.fViewerUpdatesComplete)
                  && !listener.fProgressMonitor.isCanceled()) {
                Thread.sleep(1);
              }
              synchronized (listener) {
                listener.fProgressMonitor = null;
              }
            }
          });
    } catch (InvocationTargetException e) {
      DebugUIPlugin.log(e);
      return;
    } catch (InterruptedException e) {
      return;
    }

    VirtualItem root = virtualViewer.getTree();
    if (!monitor.isCanceled()) {
      List<VirtualItem> list = new ArrayList<VirtualItem>();
      collectAllChildren(root, list);
      FindLabelProvider labelProvider = new FindLabelProvider(virtualViewer, list);
      VirtualItem result = performFind(list, labelProvider);
      if (result != null) {
        setSelectionToClient(virtualViewer, labelProvider, result);
      }
    }

    virtualViewer.removeLabelUpdateListener(listener);
    virtualViewer.removeViewerUpdateListener(listener);
    virtualViewer.dispose();
  }
 public FindLabelProvider(VirtualTreeModelViewer viewer, List<VirtualItem> items) {
   fVirtualViewer = viewer;
   for (int i = 0; i < items.size(); i++) {
     VirtualItem item = items.get(i);
     fTextCache.put(item, fVirtualViewer.getText(item, 0));
   }
 }
 private VirtualTreeModelViewer initVirtualViewer(
     TreeModelViewer clientViewer, VirtualViewerListener listener) {
   Object input = clientViewer.getInput();
   ModelDelta stateDelta = new ModelDelta(input, IModelDelta.NO_CHANGE);
   clientViewer.saveElementState(TreePath.EMPTY, stateDelta, IModelDelta.EXPAND);
   listener.fRemainingUpdatesCount = calcUpdatesCount(stateDelta);
   VirtualTreeModelViewer fVirtualViewer =
       new VirtualTreeModelViewer(
           clientViewer.getDisplay(), SWT.NONE, clientViewer.getPresentationContext());
   fVirtualViewer.setFilters(clientViewer.getFilters());
   fVirtualViewer.addViewerUpdateListener(listener);
   fVirtualViewer.addLabelUpdateListener(listener);
   String[] columns = clientViewer.getPresentationContext().getColumns();
   fVirtualViewer.setInput(input);
   if (fVirtualViewer.canToggleColumns()) {
     fVirtualViewer.setShowColumns(clientViewer.isShowColumns());
     fVirtualViewer.setVisibleColumns(columns);
   }
   fVirtualViewer.updateViewer(stateDelta);
   return fVirtualViewer;
 }
 @Override
 public Image getImage(Object element) {
   return fVirtualViewer.getImage((VirtualItem) element, 0);
 }
Esempio n. 6
0
  protected TestProcessInfo initProcessModel(String testFunc) throws Exception {
    String bpId = "entryPointBreakpoint";
    createBreakpoint(bpId, testFunc);
    fDebugViewListener.reset();

    final TestProcessInfo processInfo = startProcess();

    ITCFObject processTCFContext =
        new ITCFObject() {
          @Override
          public String getID() {
            return processInfo.fProcessId;
          }

          @Override
          public IChannel getChannel() {
            return channels[0];
          }

          @Override
          public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
            return null;
          }

          @Override
          public ITCFModel getModel() {
            return null;
          }

          @Override
          public ITCFObject getParent() {
            return null;
          }
        };
    ITCFObject threadTCFContext =
        new ITCFObject() {
          @Override
          public String getID() {
            return processInfo.fThreadId;
          }

          @Override
          public IChannel getChannel() {
            return channels[0];
          }

          @Override
          public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
            return null;
          }

          @Override
          public ITCFModel getModel() {
            return null;
          }

          @Override
          public ITCFObject getParent() {
            return null;
          }
        };

    // Make sure that delta is posted after launching process so that it doesn't interfere
    // with the waiting for the whole viewer to update after breakpoint hit (below).
    fDebugViewListener.waitTillFinished(MODEL_CHANGED_COMPLETE | CONTENT_SEQUENCE_COMPLETE);
    fDebugViewListener.reset();

    runToTestEntry(processInfo, testFunc);
    removeBreakpoint(bpId);

    final String topFrameId =
        new Transaction<String>() {
          @Override
          protected String process() throws InvalidCacheException, ExecutionException {
            String[] frameIds = validate(fStackTraceCM.getChildren(processInfo.fThreadId));
            Assert.assertTrue("No stack frames", frameIds.length != 0);
            return frameIds[frameIds.length - 1];
          }
        }.get();

    ITCFObject frameTCFContext =
        new ITCFObject() {
          @Override
          public String getID() {
            return topFrameId;
          }

          @Override
          public IChannel getChannel() {
            return channels[0];
          }

          @Override
          public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
            return null;
          }

          @Override
          public ITCFModel getModel() {
            return null;
          }

          @Override
          public ITCFObject getParent() {
            return null;
          }
        };

    VirtualItem topFrameItem = null;
    long timeout = System.currentTimeMillis() + TIMEOUT_DEFAULT;
    do {
      fDebugViewListener.addLabelUpdate(
          new TreePath(
              new Object[] {fLaunch, processTCFContext, threadTCFContext, frameTCFContext}));
      fDebugViewListener.waitTillFinished(
          MODEL_CHANGED_COMPLETE
              | CONTENT_SEQUENCE_COMPLETE
              | LABEL_SEQUENCE_COMPLETE
              | LABEL_UPDATES);
      topFrameItem =
          fDebugViewListener.findElement(
              new Pattern[] {
                Pattern.compile(".*"),
                Pattern.compile(".*"),
                Pattern.compile(".*" + processInfo.fProcessId + ".*\\(.*[Bb]reakpoint.*"),
                Pattern.compile(".*")
              });
      fDebugViewListener.reset();
    } while (topFrameItem == null && System.currentTimeMillis() < timeout);

    if (topFrameItem == null) {
      Assert.fail(
          "Top stack frame not found. \n\nDebug view dump: \n:" + fDebugViewViewer.toString());
    }

    return processInfo;
  }