Ejemplo n.º 1
0
 /**
  * helper to destory view model and viewer
  *
  * @param vmOnly true to destory view model only and do not destroy viewer
  */
 void destroyViewer(boolean vmOnly) {
   fVMProvider.getNode().setFormattedValuesListener(null);
   fVMProvider.getNode().getLabelProvider().removePropertiesUpdateListener(fViewerListener);
   fVMProvider.getNode().setVMUpdateListener(null);
   fVMListener.dispose();
   if (vmOnly == false) {
     fViewerListener.dispose();
     fViewer.getPresentationContext().dispose();
     // Close the shell
     fShell.close();
     while (!fShell.isDisposed()) if (!fDisplay.readAndDispatch()) fDisplay.sleep();
   }
 }
Ejemplo n.º 2
0
  /** @throws java.lang.Exception */
  @Override
  protected void setUp() throws Exception {
    fDsfExecutor = new DefaultDsfExecutor();
    fDsfSession = DsfSession.startSession(fDsfExecutor, getClass().getName());

    fDisplay = PlatformUI.getWorkbench().getDisplay();
    fShell = new Shell(fDisplay /*, SWT.ON_TOP | SWT.SHELL_TRIM*/);
    fShell.setMaximized(true);
    fShell.setLayout(new FillLayout());

    fViewer = createViewer(fDisplay, fShell);

    fModel = new TestModel(fDsfSession);
    initializeService(fModel);
    fDummyValuesService = new DummyFormattedValueService(fDsfSession);
    initializeService(fDummyValuesService);

    fViewerListener = new TestModelUpdatesListener(fViewer, true, false);

    fModel.setRoot(new TestElement(fModel, "root", new TestElement[0]));
    fModel.setElementChildren(
        TreePath.EMPTY, makeModelElements(fModel, getTestModelDepth(), "model"));

    fVMAdapter =
        new AbstractVMAdapter() {
          @Override
          protected IVMProvider createViewModelProvider(IPresentationContext context) {
            return fVMProvider;
          }
        };
    fVMProvider =
        new TestModelCachingVMProvider(fVMAdapter, fViewer.getPresentationContext(), fDsfSession);

    fVMListener = new TestModelUpdatesListener();
    fVMProvider.getNode().setVMUpdateListener(fVMListener);
    fVMProvider.getNode().getLabelProvider().addPropertiesUpdateListener(fViewerListener);

    fFormattedValuesListener = new FormattedValuesListener(fModel);
    fVMProvider.getNode().setFormattedValuesListener(fFormattedValuesListener);
    fModel.setTestModelListener(fFormattedValuesListener);

    fShell.open();
  }
Ejemplo n.º 3
0
 /**
  * helper to create view model and viewer
  *
  * @param vmOnly true to create view model only and do not create viewer
  */
 void createViewer(boolean vmOnly) {
   if (vmOnly == false) {
     fDisplay = PlatformUI.getWorkbench().getDisplay();
     fShell = new Shell(fDisplay /*, SWT.ON_TOP | SWT.SHELL_TRIM*/);
     fShell.setMaximized(true);
     fShell.setLayout(new FillLayout());
     fViewer = createViewer(fDisplay, fShell);
     fViewerListener = new TestModelUpdatesListener(fViewer, true, false);
   }
   fVMProvider =
       new TestElementFormatVMProvider(fVMAdapter, fViewer.getPresentationContext(), fDsfSession);
   fVMListener = new TestModelUpdatesListener();
   fVMProvider.getNode().setVMUpdateListener(fVMListener);
   fVMProvider.getNode().getLabelProvider().addPropertiesUpdateListener(fViewerListener);
   fVMProvider.getNode().setFormattedValuesListener(fFormattedValuesListener);
   if (vmOnly == false) {
     fShell.open();
   }
 }
Ejemplo n.º 4
0
 private void postEventInManualUpdateMode() {
   // Generate an event which will cause all cache entries to be marked dirty.
   fViewerListener.reset();
   fViewerListener.addUpdates(
       TreePath.EMPTY, fModel.getRootElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
   fVMListener.reset();
   fFormattedValuesListener.reset();
   fVMProvider.postEvent(new TestEvent(fModel.getRootElement(), IModelDelta.CONTENT));
   while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES))
     if (!fDisplay.readAndDispatch()) fDisplay.sleep();
   assertTrue(fFormattedValuesListener.getFormattedValuesCompleted().isEmpty());
 }
Ejemplo n.º 5
0
  /** @throws java.lang.Exception */
  @Override
  protected void tearDown() throws Exception {
    fVMProvider.getNode().setFormattedValuesListener(null);
    fModel.setTestModelListener(null);

    fVMProvider.getNode().getLabelProvider().removePropertiesUpdateListener(fViewerListener);
    fVMProvider.getNode().setVMUpdateListener(null);

    fVMAdapter.dispose();

    fVMListener.dispose();
    fViewerListener.dispose();

    shutdownService(fDummyValuesService);
    shutdownService(fModel);
    fViewer.getPresentationContext().dispose();
    // Close the shell and exit.
    fShell.close();
    while (!fShell.isDisposed()) if (!fDisplay.readAndDispatch()) fDisplay.sleep();
    DsfSession.endSession(fDsfSession);
    fDsfExecutor.shutdown();
  }
Ejemplo n.º 6
0
  private void setUpdatePolicy(String policyId) {
    IVMUpdatePolicy[] policies = fVMProvider.getAvailableUpdatePolicies();
    IVMUpdatePolicy newPolicy = null;
    for (IVMUpdatePolicy policy : policies) {
      if (policyId.equals(policy.getID())) {
        newPolicy = policy;
        break;
      }
    }
    if (newPolicy != null) {
      fVMProvider.setActiveUpdatePolicy(newPolicy);
    } else {
      throw new RuntimeException("Update policy " + policyId + " not available");
    }
    fViewerListener.reset();
    fViewerListener.addUpdates(
        TreePath.EMPTY, fModel.getRootElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
    fVMListener.setFailOnRedundantUpdates(false);
    while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES))
      if (!fDisplay.readAndDispatch()) fDisplay.sleep();

    fVMListener.setFailOnRedundantUpdates(true);
  }
Ejemplo n.º 7
0
  /** Initial format is NATURAL. */
  private void setInput(String formatId) {
    // Set the new number format to the viewer.
    fViewer.getPresentationContext().setProperty(PROP_FORMATTED_VALUE_FORMAT_PREFERENCE, formatId);

    fViewer.setAutoExpandLevel(-1);
    TestElementVMContext rootVMC =
        fVMProvider.getElementVMContext(fViewer.getPresentationContext(), fModel.getRootElement());

    // Create the listener
    fViewerListener.reset();
    fViewerListener.addUpdates(
        TreePath.EMPTY, rootVMC.getElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
    fVMListener.reset();
    fVMListener.addUpdates(
        TreePath.EMPTY, rootVMC.getElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
    fFormattedValuesListener.reset();

    fViewer.setInput(rootVMC);
    while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES)
        || !fVMListener.isFinished(CONTENT_COMPLETE | PROPERTY_UPDATES))
      if (!fDisplay.readAndDispatch()) fDisplay.sleep();

    assertTrue(fFormattedValuesListener.isFinished());
  }