/** 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.º 2
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();
  }
  private void createView() {
    myView = BaseUIBTestUtils.createUIBTestView(this);

    myGrid = new Grid(myView.getBody(), SWT.NONE);
    myContext = IBindingContext.Factory.createContext(myView.getBody());
    myGridBinding = IGridBinding.Factory.createGrid(myContext, myGrid, myModel);
    myContext.finish();
    yield();

    myView.getSite().getPage().activate(myView);
    myView.getBody().layout();

    yield();
  }
  /**
   * Tests the bindings are properly disposed - both the primary binding and any additional bindings
   */
  @Test
  public void testControlDispose() {
    final IBindingContext context = IBindingContext.Factory.createContext(myView.getScrolledForm());

    final IValueBinding binding1 =
        context.addBinding(myText, myShop, IMOAOPackage.Literals.NAMED_OBJECT__NAME);
    final IValueBinding binding2 =
        context.addBinding().ui(myText, Constants.ATTR_ENABLED).model(myBoolOV);
    context.finish();
    yield();

    assertEquals(BindingState.OK, binding1.getState());
    assertEquals(BindingState.OK, binding2.getState());

    myText.dispose();
    yield();

    assertEquals(BindingState.DISPOSED, binding1.getState());
    assertEquals(BindingState.DISPOSED, binding2.getState());
  }
  /**
   * Returns a Map with the current state for the specific event if specified.
   *
   * @param event the current event - possibly <code>null</code>
   * @return a Map with the current state
   */
  public Map<String, Object> getCurrentState(final Event event) {
    final Map<String, Object> map = new HashMap<String, Object>();
    final List<IObservableValue> values = new ArrayList<IObservableValue>();
    resetMap(map);
    if (event.type == SWT.MenuDetect) {
      // LogUtils.debug(event, "MenuDetect");
    }
    try {
      myLastBinding = IBindingContext.Factory.getBindingForWidget(event.widget);
      if (myLastBinding == null) return map;

      map.put(Constants.SOURCES_ACTIVE_CONTEXT, myLastBinding.getContext());

      final ISourceProviderStateContext context =
          new ISourceProviderStateContext() {
            @Override
            public Event getEvent() {
              return event;
            }

            private Point myLocation = null;

            @Override
            public Point getLocation() {
              if (myLocation == null) {
                myLocation = new Point(event.x, event.y);
                switch (event.type) {
                  case SWT.MenuDetect:
                    /*
                     * The location is relative to the display
                     */
                    myLocation =
                        event.widget.getDisplay().map(null, (Control) event.widget, myLocation);
                    break;
                  default:
                    break;
                }
              }
              return myLocation;
            }

            @Override
            public Map<String, Object> getState() {
              return map;
            }

            @Override
            public void putSourceValue(String name, Object value) {
              map.put(name, value);
            }

            @Override
            public void addObservedValue(IObservableValue value) {
              values.add(value);
            }

            @Override
            public void setSelectionProvider(ISelectionProvider provider) {
              if (provider == myCurrentSelectionProvider) return;
              if (myCurrentSelectionProvider != null) {
                myCurrentSelectionProvider.removeSelectionChangedListener(
                    myCurrentSelectionProviderListener);
              }
              myCurrentSelectionProvider = provider;
              if (myCurrentSelectionProvider != null) {
                myCurrentSelectionProvider.addSelectionChangedListener(
                    myCurrentSelectionProviderListener);
              }
            }
          };
      try {
        myLastBinding.updateSourceProviderState(context);
      } catch (final Exception ex) {
        LogUtils.error(myLastBinding, ex);
      }

      /*
       * If the active binding is a value binding, run all extenders as well...
       */
      final Object activeBinding = map.get(Constants.SOURCES_ACTIVE_BINDING);
      if (activeBinding instanceof IValueBinding) {
        final IValueBinding vb = (IValueBinding) activeBinding;
        for (final IUIBindingDecoratorExtenderDescriptor d :
            IManager.Factory.getManager().getDecoratorExtenders()) {
          final CEObjectHolder<IUIBindingDecoratorExtender> factory = d.getFactory();
          final IUIBindingDecoratorExtender extender = factory.getObject();
          if (extender == null) {
            LogUtils.error(factory.getConfigurationElement(), "Cannot create extender");
            continue;
          }

          try {
            if (!extender.isEnabled(vb)) {
              continue;
            }
            extender.updateSourceProviderState(vb, context);
          } catch (final Exception ex) {
            LogUtils.error(factory.getConfigurationElement(), ex);
          }
        }
      }

      observe(event, values);
    } catch (final Exception ex) {
      LogUtils.error(this, ex);
    }
    return map;
  }