/**
   * Source values for a column binding for a simple feature after the previous column has been
   * deleted.
   */
  @Test
  public void testSimpleColumnBindingAfterDelete() {
    postMouse(myTable, 0 + myViewerBinding.getFirstTableColumnOffset(), 0);

    final IColumnBindingCellInformation ci =
        myViewerBinding.getCell(0, myViewerBinding.getList().get(1));
    assertNotNull(ci);

    /*
     * When the element is deleted, the current selected cell is changed, and this must be
     * monitored.
     */
    final MySourceProviderListener listener = new MySourceProviderListener();
    try {
      myProvider.addSourceProviderListener(listener);
      myContact1.setShop(null);
      yield();
    } finally {
      myProvider.removeSourceProviderListener(listener);
    }

    assertSource(Constants.SOURCES_THE_MANAGER, IManager.Factory.getManager());

    assertSource(Constants.SOURCES_ACTIVE_CONTEXT, myContext);

    assertSource(Constants.SOURCES_ACTIVE_CONTAINER_BINDING, myViewerBinding);
    assertSource(Constants.SOURCES_ACTIVE_BINDING, ci.getLabelBinding());
    assertSource(Constants.SOURCES_ACTIVE_BINDING_RO, false);
    assertSource(Constants.SOURCES_ACTIVE_BINDING_TYPE, "");
    assertSource(Constants.SOURCES_ACTIVE_BINDING_MODEL_OBJECT, myContact2);
    assertSource(
        Constants.SOURCES_ACTIVE_BINDING_FEATURE, IMOAOPackage.Literals.NAMED_OBJECT__NAME);
    assertSource(Constants.SOURCES_ACTIVE_BINDING_VALUE, myContact2.getName());
    assertSource(Constants.SOURCES_ACTIVE_BINDING_VALUE_DISPLAY, myContact2.getName());
  }
  /** Binds the UI */
  public void bindUI() {
    myContext = IBindingContext.Factory.createContext(myView.getScrolledForm());

    myViewerBinding =
        myContext.addViewer(myTableViewer, myShop, ShopPackage.Literals.SHOP__CONTACTS);
    myNameColumnBinding =
        myViewerBinding.addColumn(myNameColumn, IMOAOPackage.Literals.NAMED_OBJECT__NAME);
    myCountryColumnBinding =
        myViewerBinding
            .addColumn(myCountryColumn, ShopPackage.Literals.CONTACT__COUNTRY)
            .arg(Constants.ARG_FEATURE_NAME, "abbreviation")
            .validValues(myShop, ShopPackage.Literals.SHOP__COUNTRIES);
    myCountryNameColumnBinding =
        myCountryColumnBinding
            .addColumn(myCountryNameColumn, IMOAOPackage.Literals.NAMED_OBJECT__NAME)
            .readonly();

    final IObservableValue selection = myViewerBinding.getSingleSelection();

    myNameBinding =
        myContext.addBinding(myNameText, selection, IMOAOPackage.Literals.NAMED_OBJECT__NAME);

    myContext.finish();
    yield();
  }
Ejemplo n.º 3
0
 @Override
 public void dispose() {
   myViewer.unregisterService(this);
   if (myToolBar != null && !myToolBar.isDisposed()) {
     myViewer.unregisterWidget(myToolBar);
     myToolBar.dispose();
   }
 }
Ejemplo n.º 4
0
  /** Binds the UI */
  public void bindUI() {
    myContext = IBindingContext.Factory.createContext(myView.getScrolledForm());

    myViewer = myContext.addViewer(myTable, myShop, ShopPackage.Literals.SHOP__COUNTRIES);
    myViewer.addColumn(myNameColumn, IMOAOPackage.Literals.NAMED_OBJECT__NAME);
    myViewer.addColumn(myAbbreviationColumn, ShopPackage.Literals.COUNTRY__ABBREVIATION);

    myContext.finish();
    yield();
  }
Ejemplo n.º 5
0
  public static IViewerToolBar addToolBar(IViewerBinding viewer, int style) {
    IViewerToolBar bb = viewer.getService(IViewerToolBar.class);
    if (bb != null) return bb;

    bb = new ViewerToolBar(viewer, style);

    return bb;
  }
  /** Source values for a column binding for a reference feature */
  @Test
  public void testReferenceColumnBinding() {
    postMouse(myTable, 1 + myViewerBinding.getFirstTableColumnOffset(), 0);

    final IColumnBindingCellInformation ci =
        myViewerBinding.getCell(1, myViewerBinding.getList().get(0));
    assertNotNull(ci);

    assertSource(Constants.SOURCES_THE_MANAGER, IManager.Factory.getManager());

    assertSource(Constants.SOURCES_ACTIVE_CONTEXT, myContext);

    assertSource(Constants.SOURCES_ACTIVE_CONTAINER_BINDING, myViewerBinding);
    assertSource(Constants.SOURCES_ACTIVE_BINDING, ci.getLabelBinding());
    assertSource(Constants.SOURCES_ACTIVE_BINDING_RO, false);
    assertSource(Constants.SOURCES_ACTIVE_BINDING_FEATURE, ShopPackage.Literals.CONTACT__COUNTRY);
    assertSource(Constants.SOURCES_ACTIVE_BINDING_TYPE, "");
    assertSource(Constants.SOURCES_ACTIVE_BINDING_MODEL_OBJECT, myContact1);
    assertSource(Constants.SOURCES_ACTIVE_BINDING_VALUE, myCountry1);
    assertSource(Constants.SOURCES_ACTIVE_BINDING_VALUE_DISPLAY, myCountry1.getAbbreviation());
  }
  /** Source values for a column binding for a simple feature */
  @Test
  public void testROColumnBinding() {
    postMouse(myTable, 2 + myViewerBinding.getFirstTableColumnOffset(), 1);

    final IColumnBindingCellInformation ci =
        myViewerBinding.getCell(2, myViewerBinding.getList().get(1));
    assertNotNull(ci);

    assertSource(Constants.SOURCES_THE_MANAGER, IManager.Factory.getManager());

    assertSource(Constants.SOURCES_ACTIVE_CONTEXT, myContext);

    assertSource(Constants.SOURCES_ACTIVE_CONTAINER_BINDING, myViewerBinding);
    assertSource(Constants.SOURCES_ACTIVE_BINDING, ci.getLabelBinding());
    assertSource(Constants.SOURCES_ACTIVE_BINDING_RO, true);
    assertSource(
        Constants.SOURCES_ACTIVE_BINDING_FEATURE, IMOAOPackage.Literals.NAMED_OBJECT__NAME);
    assertSource(Constants.SOURCES_ACTIVE_BINDING_TYPE, "");
    assertSource(Constants.SOURCES_ACTIVE_BINDING_MODEL_OBJECT, myCountry2);
    assertSource(Constants.SOURCES_ACTIVE_BINDING_VALUE, myCountry2.getName());
    assertSource(Constants.SOURCES_ACTIVE_BINDING_VALUE_DISPLAY, myCountry2.getName());
  }
Ejemplo n.º 8
0
  @Test
  public void filterExists() {
    Listener[] listeners = myFilter.getListeners(SWT.Modify);
    assertNotNull(listeners);
    assertEquals(0, listeners.length);

    IFilteringTableAdapter.Factory.adapt(myViewer, myFilter);

    assertTrue(myViewer.getService(IFilteringTableAdapter.class) != null);
    listeners = myFilter.getListeners(SWT.Modify);
    assertNotNull(listeners);
    assertEquals(1, listeners.length);
  }
Ejemplo n.º 9
0
  /** Tests that all listeners are removed on dispose */
  @Test
  public void disposeTest() {
    final Listener[] filterKeyDownListeners = myFilter.getListeners(SWT.KeyDown);
    final Listener[] filterSelectionListeners = myFilter.getListeners(SWT.Selection);
    final Listener[] filterFocusInListeners = myFilter.getListeners(SWT.FocusIn);
    final Listener[] tableKeyDownListeners = myTable.getListeners(SWT.KeyDown);
    final Listener[] tableDisposeListeners = myTable.getListeners(SWT.Dispose);

    final IFilteringTableAdapter adapter = IFilteringTableAdapter.Factory.adapt(myViewer, myFilter);

    adapter.dispose();

    assertEquals(null, myViewer.getService(IFilteringTableAdapter.class));

    assertArrayEquals(filterKeyDownListeners, myFilter.getListeners(SWT.KeyDown));
    assertArrayEquals(filterSelectionListeners, myFilter.getListeners(SWT.Selection));
    assertArrayEquals(filterFocusInListeners, myFilter.getListeners(SWT.FocusIn));
    assertArrayEquals(tableKeyDownListeners, myTable.getListeners(SWT.KeyDown));
    assertArrayEquals(tableDisposeListeners, myTable.getListeners(SWT.Dispose));
  }
  /** Tests the colors of the row alternates */
  @Test
  public void colorTest() {
    final TableItem[] items = myTable.getItems();
    final Color evenColor =
        JFaceResources.getColorRegistry().get(Constants.COLOR_DEFINITIONS_EVEN_ROW_BACKGROUND);
    final Color oddColor = myTable.getDisplay().getSystemColor(SWT.COLOR_WHITE);
    sleep(50);
    // First row is selected and therefore a different color
    for (int i = 0; i < items.length; i++) {
      final TableItem item = items[i];
      final Rectangle bounds = item.getBounds(myViewer.getFirstTableColumnOffset());

      Color c;
      if (i == 0) {
        if (myHasFocus) {
          final Color focusColor =
              JFaceResources.getColorRegistry()
                  .get(Constants.COLOR_DEFINITIONS_SELECTION_FOCUS_BACKGROUND);
          c = focusColor;
        } else {
          c =
              JFaceResources.getColorRegistry()
                  .get(Constants.COLOR_DEFINITIONS_SELECTION_NO_FOCUS_BACKGROUND);
        }
      } else if (i % 2 == 0 && myEnable) {
        c = evenColor;
      } else {
        c = oddColor;
      }
      assertPixelColor(
          "enabled=" + myEnable + ", hasFocus=" + myHasFocus,
          myTable,
          bounds.x + 3,
          bounds.y + 3,
          c.getRGB());
    }
  }
Ejemplo n.º 11
0
  public ViewerToolBar(IViewerBinding viewer, int style) {
    myViewer = viewer;
    myStyle = style;

    // TODO: Check style

    myViewer.registerService(this);

    final IManager manager = IManager.Factory.getManager();
    myToolkit = manager.getFormToolkit();

    final IServiceLocator serviceLocator = getViewer().getContext().getServiceLocator();
    myCommandService = (ICommandService) serviceLocator.getService(ICommandService.class);
    myHandlerService = (IHandlerService) serviceLocator.getService(IHandlerService.class);
    myCommandImageService =
        (ICommandImageService) serviceLocator.getService(ICommandImageService.class);

    /*
     * Find the control of the viewer (a Table or Tree).
     *
     * Find the parent Composite.
     *
     * Add a new Composite (with a GridLayout) and reparent the control
     *
     * Then add the toolbar itself on the correct side of the control
     */
    final Control control = myViewer.getControl();
    final Composite parent = control.getParent();

    myComposite = myToolkit.createComposite(parent);
    myComposite.setLayoutData(control.getLayoutData());
    final GridLayout compLayout = new GridLayout(1, false);
    myComposite.setLayout(compLayout);

    control.setParent(myComposite);
    control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    myToolBar = new ToolBar(myComposite, SWT.FLAT | (style & (VERTICAL | HORIZONTAL)));
    if ((style & VERTICAL) != 0) {
      myToolBar.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, false));
      compLayout.numColumns = 2;
    } else {
      myToolBar.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
    }
    /*
     * Inlined from FormToolkit.adapt(Composite composite). Do not set focus though.
     */
    myToolBar.setBackground(myComposite.getBackground());
    myToolBar.setMenu(myComposite.getMenu());

    myViewer.registerWidget(myToolBar);

    /*
     * Add standard items
     */
    if ((style & ADD) != 0) {
      // TODO addItem(ADD, "");
    }
    if ((style & DELETE) != 0) {
      addItem(
          DELETE,
          IManager.Factory.getManager()
              .getCommandIDs()
              .get(IWorkbenchCommandConstants.EDIT_DELETE));
    }
    if ((style & UP) != 0) {
      addItem(UP, "com.rcpcompany.uibindings.commands.moveItemUp");
    }
    if ((style & DOWN) != 0) {
      addItem(DOWN, "com.rcpcompany.uibindings.commands.moveItemDown");
    }

    myComposite.layout(true);
  }