Пример #1
0
 /**
  * Test that element format can be persisted in memento and viewer can restore to the persisted
  * settings.
  */
 public void testPersistElementFormat() {
   recreateViewModel();
   String preferenceFormat = IFormattedValues.HEX_FORMAT;
   setInput(IFormattedValues.NATURAL_FORMAT);
   setFormatAndValidate(preferenceFormat, false, false, false);
   // set each element to a format, and verify
   HashMap<String, ElementFormatSetting> map = new HashMap<String, ElementFormatSetting>();
   String[] format = {
     IFormattedValues.HEX_FORMAT,
     IFormattedValues.DECIMAL_FORMAT,
     IFormattedValues.OCTAL_FORMAT,
     IFormattedValues.BINARY_FORMAT,
     IFormattedValues.NATURAL_FORMAT
   };
   makeElementFormatSetting(fViewer, TreePath.EMPTY, format, -1, 0, map);
   ArrayList<ElementFormatSetting> elementFormats =
       new ArrayList<ElementFormatSetting>(map.values());
   setFormatAndValidate(preferenceFormat, elementFormats, elementFormats, false, false, false);
   // save settings
   XMLMemento memento = XMLMemento.createWriteRoot("TEST");
   if (fViewer instanceof TreeModelViewer == false) return;
   ((TreeModelViewer) fViewer).saveState(memento);
   // throw away any settings inside the viewer and create a new viewer
   // with memento settings, this is the same effect resulted from closing
   // and opening workspace again.
   recreateViewer();
   if (fViewer instanceof TreeModelViewer == false) return;
   ((TreeModelViewer) fViewer).initState(memento);
   setInput(IFormattedValues.NATURAL_FORMAT);
   preferenceFormat =
       (String)
           fViewer.getPresentationContext().getProperty(PROP_FORMATTED_VALUE_FORMAT_PREFERENCE);
   validateModel(elementFormats, preferenceFormat, "", preferenceFormat, "");
 }
  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();
  }
 protected VirtualItem performFind(List<VirtualItem> items, FindLabelProvider labelProvider) {
   FindElementDialog dialog =
       new FindElementDialog(
           fClientViewer.getControl().getShell(), labelProvider, items.toArray());
   dialog.setTitle(ActionMessages.FindDialog_3);
   dialog.setMessage(ActionMessages.FindDialog_1);
   if (dialog.open() == Window.OK) {
     Object[] elements = dialog.getResult();
     if (elements.length == 1) {
       return (VirtualItem) elements[0];
     }
   }
   return null;
 }
 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 void update() {
   setEnabled(fClientViewer.getInput() != null && fClientViewer.getChildCount(TreePath.EMPTY) > 0);
 }
 public void viewerInputComplete(IViewerInputUpdate update) {
   fViewer.setInput(fVariable = update.getInputElement());
 }
    @Override
    protected void createContent(Composite parent) {
      fSashForm = new SashForm(parent, parent.getStyle());
      fSashForm.setOrientation(SWT.VERTICAL);

      // update presentation context
      AbstractDebugView view = getViewToEmulate();
      fContext = new PresentationContext(TCFModel.ID_EXPRESSION_HOVER);
      if (view != null) {
        // copy over properties
        IPresentationContext copy = ((TreeModelViewer) view.getViewer()).getPresentationContext();
        try {
          String[] properties = copy.getProperties();
          for (int i = 0; i < properties.length; i++) {
            String key = properties[i];
            fContext.setProperty(key, copy.getProperty(key));
          }
        } catch (NoSuchMethodError e) {
          // ignore
        }
      }

      fViewer =
          new TreeModelViewer(fSashForm, SWT.MULTI | SWT.VIRTUAL | SWT.FULL_SELECTION, fContext);
      fViewer.setAutoExpandLevel(fExpansionLevel);

      if (view != null) {
        // copy over filters
        StructuredViewer structuredViewer = (StructuredViewer) view.getViewer();
        if (structuredViewer != null) {
          ViewerFilter[] filters = structuredViewer.getFilters();
          for (int i = 0; i < filters.length; i++) {
            fViewer.addFilter(filters[i]);
          }
        }
      }
      fInputService = new ViewerInputService(fViewer, this);
      fTree = fViewer.getTree();

      if (fShowDetailPane) {
        fDetailPaneComposite = SWTFactory.createComposite(fSashForm, 1, 1, GridData.FILL_BOTH);
        Layout layout = fDetailPaneComposite.getLayout();
        if (layout instanceof GridLayout) {
          GridLayout gl = (GridLayout) layout;
          gl.marginHeight = 0;
          gl.marginWidth = 0;
        }

        fDetailPane = new DetailPaneProxy(new DetailPaneContainer());
        fDetailPane.display(null); // Bring up the default pane so the
        // user doesn't see an empty
        // composite

        fTree.addSelectionListener(
            new SelectionListener() {
              public void widgetSelected(SelectionEvent e) {
                fDetailPane.display((IStructuredSelection) fViewer.getSelection());
              }

              public void widgetDefaultSelected(SelectionEvent e) {}
            });
      }

      initSashWeights();

      // add update listener to auto-select and display details of root
      // expression
      fViewer.addViewerUpdateListener(
          new IViewerUpdateListener() {
            public void viewerUpdatesComplete() {
              fViewer
                  .getDisplay()
                  .timerExec(
                      100,
                      new Runnable() {
                        public void run() {
                          if (fViewer.getControl().isDisposed()) return;
                          TreeSelection selection = (TreeSelection) fViewer.getSelection();
                          if (selection.isEmpty())
                            selection = new TreeSelection(fViewer.getTopElementPath());
                          fViewer.setSelection(selection);
                          if (fDetailPane != null) fDetailPane.display(selection);
                        }
                      });
            }

            public void viewerUpdatesBegin() {}

            public void updateStarted(IViewerUpdate update) {}

            public void updateComplete(IViewerUpdate update) {}
          });

      setBackgroundColor(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    }