@Test
 @UI
 public void testOtherObservablesPreservedWhenOptionInvalid() throws Exception {
   ITypedObservableValue<Instrument> instrument =
       TypedObservableValueDecorator.create(Instrument.class);
   Instrument option = new Option("ABC", "200910", BigDecimal.ONE, OptionType.Put);
   instrument.setValue(option);
   OptionObservable optionObservable = new OptionObservable(instrument);
   ImmutableList<IObservableValue> children =
       ImmutableList.<IObservableValue>of(
           optionObservable.observeSymbol(),
           optionObservable.observeExpiry(),
           optionObservable.observeStrikePrice(),
           optionObservable.observeOptionType());
   for (IObservableValue observable : children) {
     Object value = observable.getValue();
     observable.setValue(null);
     assertThat(instrument.getValue(), nullValue());
     for (IObservableValue other : children) {
       if (other != observable) {
         assertThat(other.getValue(), not(nullValue()));
       }
     }
     observable.setValue(value);
     assertThat(instrument.getTypedValue(), is(option));
   }
 }
  public void testSetValue_PropagatesToTarget() {
    assertEquals(oldValue, delayed.getValue());
    assertEquals(oldValue, target.getValue());

    delayed.setValue(newValue);

    assertEquals(newValue, target.getValue());
    assertEquals(newValue, delayed.getValue());
  }
  public void testSetValue() throws Exception {
    // preconditions
    assertEquals("", group.getText());
    assertEquals("", observable.getValue());

    String value = "value";
    observable.setValue(value);
    assertEquals("label text", value, group.getText());
    assertEquals("observable value", value, observable.getValue());
  }
Пример #4
0
  public void testUpdateFromModelOnRequest() throws Exception {
    assertNull(target.getValue());

    bean.setProperty("TestValue"); // $NON-NLS-1$

    assertNull(target.getValue());

    valueBindingSupport.updateFromModel();

    assertEquals("TestValue", target.getValue()); // $NON-NLS-1$
  }
  public void testSetValue_CachesGetValueFromTarget() {
    Object overrideValue = target.overrideValue = new Object();

    assertEquals(oldValue, delayed.getValue());
    assertEquals(oldValue, target.getValue());

    delayed.setValue(newValue);

    assertEquals(overrideValue, target.getValue());
    assertEquals(overrideValue, delayed.getValue());
  }
Пример #6
0
  private void display() {
    View view = resolveView();

    if (view == null) {
      Activator.log.warn("Unabled to resolve view : " + viewPath); // $NON-NLS-1$
      return;
    }

    IObservable observable = getInputObservable();
    if (observable == null) {
      return;
    }

    DisplayEngine display = new DefaultDisplayEngine(true);

    sections = new LinkedList<XWTSection>();

    if (observable instanceof IObservableValue) {
      IObservableValue observableValue = (IObservableValue) observable;
      if (observableValue instanceof MultipleObservableValue) {
        MultipleObservableValue multipleObservable = (MultipleObservableValue) observableValue;
        display(display, multipleObservable.getObservedValues(), view);
      } else {
        Object value = observableValue.getValue();
        display(display, value, view);
      }
    } else if (observable instanceof IObservableList) {
      IObservableList observableList = (IObservableList) observable;
      for (Object value : observableList) {
        display(display, value, view);
      }
    }

    updateControls();
  }
 /** @return the list of observed values */
 public List<Object> getObservedValues() {
   List<Object> result = new LinkedList<Object>();
   for (IObservableValue value : getObservableValues()) {
     result.add(value.getValue());
   }
   return result;
 }
 /**
  * Copies the current value of the source observable to the destination observable, and upon value
  * change events fired by the source observable, updates the destination observable accordingly,
  * until the source observable is disposed. This method assumes that both observables are on the
  * same realm.
  *
  * @param source the source observable
  * @param destination the destination observable
  * @since 1.2
  */
 public static void pipe(IObservableValue source, final IObservableValue destination) {
   destination.setValue(source.getValue());
   source.addValueChangeListener(
       new IValueChangeListener() {
         public void handleValueChange(ValueChangeEvent event) {
           destination.setValue(event.diff.getNewValue());
         }
       });
 }
 protected void onUserdocLinkClicked(final IObservableValue userdocUrlObservable) {
   String userdocUrl = (String) userdocUrlObservable.getValue();
   if (StringUtils.isEmpty(userdocUrl)) {
     return;
   }
   new BrowserUtility()
       .checkedCreateExternalBrowser(
           userdocUrl,
           OpenShiftCommonUIActivator.PLUGIN_ID,
           OpenShiftCommonUIActivator.getDefault().getLog());
 }
  public void testChange_ValueChangeEventDiff() throws Exception {
    ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable);
    Object oldValue = observable.getValue();

    delegate.change(observable);

    ValueChangeEvent event = listener.event;

    assertTrue(formatFail("Change Listeners were not notified on change."), listener.count > 0);

    assertEquals(
        formatFail(
            "When a value change event is fired the old value should be the previous value of the observable value."),
        oldValue,
        event.diff.getOldValue());
    assertEquals(
        formatFail(
            "When a value change event is fired the new value should be the same as the current value of the observable value."),
        observable.getValue(),
        event.diff.getNewValue());
  }
Пример #11
0
 @Override
 protected Object doGetValue() {
   StringBuilder builder = new StringBuilder();
   for (IObservableValue value : myObservableValues) {
     String stringValue = ((String) value.getValue());
     if (stringValue != null && stringValue.trim().length() > 0) {
       builder.append(stringValue.trim());
       builder.append(" "); // $NON-NLS-1$
     }
   }
   myCurrentStringValue = builder.toString().trim();
   return myCurrentStringValue;
 }
  public boolean hasDifferentValues() {
    if (observableValues.isEmpty()) {
      return false;
    }

    Object currentValue = null;
    boolean firstValue = true;
    for (IObservableValue observable : observableValues) {
      if (firstValue) {
        firstValue = false;
        currentValue = observable.getValue();
      } else {
        Object value = observable.getValue();
        if (equals(value, currentValue)) {
          continue;
        }
        return true;
      }
    }

    return false;
  }
  /**
   *
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated NOT
   */
  @Override
  public String getDisplayText() {
    Object value = null;
    final IUIAttribute la = getLabelUIAttribute();
    if (la == null) return "";
    final IObservableValue displayValue = la.getCurrentValue();
    if (displayValue != null) {
      value = displayValue.getValue();
    }

    if (value == null) return "";
    return value.toString();
  }
Пример #14
0
  public void testUpdateFromModelOnRequest2() {
    final Person person = new Person("muster", "max"); // $NON-NLS-1$ //$NON-NLS-2$
    valueBindingSupport.bindToModel(person, "firstname"); // $NON-NLS-1$
    valueBindingSupport.updateFromModel();

    assertEquals("max", person.getFirstname()); // $NON-NLS-1$
    assertEquals("max", target.getValue()); // $NON-NLS-1$

    target.setValue("moritz"); // $NON-NLS-1$

    assertEquals("moritz", person.getFirstname()); // $NON-NLS-1$
    assertEquals("moritz", target.getValue()); // $NON-NLS-1$

    person.setFirstname("michel"); // $NON-NLS-1$

    assertEquals("michel", person.getFirstname()); // $NON-NLS-1$
    assertEquals("moritz", target.getValue()); // $NON-NLS-1$

    valueBindingSupport.updateFromModel();

    assertEquals("michel", person.getFirstname()); // $NON-NLS-1$
    assertEquals("michel", target.getValue()); // $NON-NLS-1$
  }
 private void recompute() {
   if (isDirty) {
     Map newContents = new HashMap();
     for (Iterator it = bindings.iterator(); it.hasNext(); ) {
       Binding binding = (Binding) it.next();
       IObservableValue validationError = binding.getValidationStatus();
       dependencies.add(validationError);
       validationError.addChangeListener(markDirtyChangeListener);
       IStatus validationStatusValue = (IStatus) validationError.getValue();
       newContents.put(binding, validationStatusValue);
     }
     wrappedMap.putAll(newContents);
     isDirty = false;
   }
 }
  public void testChange_ValueChangeEventFiredAfterValueIsSet() throws Exception {
    class ValueChangeListener implements IValueChangeListener {
      Object value;

      public void handleValueChange(ValueChangeEvent event) {
        this.value = event.getObservableValue().getValue();
      }
    }

    ValueChangeListener listener = new ValueChangeListener();
    observable.addValueChangeListener(listener);
    delegate.change(observable);
    assertEquals(
        formatFail(
            "When a value change event is fired the new value should be applied before firing the change event."),
        listener.value,
        observable.getValue());
  }
  @Override
  public void handleEvent(Event event) {
    // LogUtils.debug(this, "event=" + ToStringUtils.toString(event));

    if (!isChangeable()) return;

    final IObservableValue v = getObjectValue();
    final Object modelType = v.getValueType();

    switch (event.type) {
      case SWT.Selection:
        if (event.detail == SWT.CHECK) {
          // TODO: changeable
          final boolean checkable = modelType == Boolean.class || modelType == Boolean.TYPE;
          if (checkable) {
            v.setValue(v.getValue() != Boolean.TRUE);
          }
        }
        break;
      case SWT.MouseDown:
        getGrid()
            .editCell(
                this,
                new ColumnViewerEditorActivationEvent(
                    myActivationEventViewerCell, new MouseEvent(event)));
        break;
      case SWT.MouseDoubleClick:
        getGrid()
            .editCell(
                this,
                new ColumnViewerEditorActivationEvent(
                    myActivationEventViewerCell, new MouseEvent(event)));
        break;
      case SWT.KeyDown:
        final KeyEvent keyEvent = new KeyEvent(event);
        getGrid()
            .editCell(
                this, new ColumnViewerEditorActivationEvent(myActivationEventViewerCell, keyEvent));
        event.doit = keyEvent.doit;
        break;
      default:
        break;
    }
  }
 @Override
 public void change(IObservable observable) {
   IObservableValue value = (IObservableValue) observable;
   value.setValue(value.getValue() + "a");
 }
  /**
   * Initializes the cell with the information from the model.
   *
   * @param column the column
   * @param row the row
   */
  public void init(IGridBindingColumnInformation column, IGridBindingRowInformation row) {
    setColumn(column);
    setRow(row);

    final IGridBinding grid = getGrid();
    final IBindingContext context = grid.getContext();
    final IGridModel model = grid.getModel();
    final Object columnID = column.getId();
    final Object rowID = row.getId();

    // LogUtils.debug(this, "\ncolumn=" + columnID + "\nrow=" + rowID);
    IGridCell cell = null;
    try {
      if (Activator.getDefault().TRACE_SOURCE_MODEL) {
        LogUtils.debug(
            model,
            "Model[" + grid.getGrid().hashCode() + "]: getcell(" + columnID + ", " + rowID + ")");
      }
      cell = model.getCell(columnID, rowID);
      if (Activator.getDefault().TRACE_SOURCE_MODEL) {
        LogUtils.debug(model, "Model: >>> " + cell);
      }
    } catch (final Exception ex) {
      LogUtils.throwException(this, "Cannot get cell", ex);
    }
    try {
      if (Activator.getDefault().TRACE_SOURCE_MODEL) {
        LogUtils.debug(model, "Model[" + grid.getGrid().hashCode() + "]: getValue");
      }
      final IObservableValue value = cell.getValue();
      if (Activator.getDefault().TRACE_SOURCE_MODEL) {
        LogUtils.debug(model, "Model: >>> " + value);
      }
      /*
       * Retrieve the wanted information
       */
      setObjectValue(value);

      /*
       * If we didn't get a IOV, then just ignore it...
       */
      if (value == null) return;

      // TODO: set the renderer: final item.s

      setDataType(IBindingDataType.Factory.create(value.getValue(), value.getValueType()));

      /*
       * We will use a UI binding to convert from myValue to myLabelUIAttribute...
       */
      final AbstractUIAttribute attribute = new VirtualUIAttribute(String.class);
      setLabelUIAttribute(attribute);

      final IValueBinding lb = context.addBinding().model(value).ui(attribute);
      final Map<String, Object> args = cell.getArguments();
      if (args != null) {
        lb.args(args);
      }
      lb.setCell(this);
      setLabelBinding(lb);

      /*
       * Set up the painter
       */
      final Grid gridControl = grid.getGrid();
      final UIAttributePainter p = new UIAttributePainter(gridControl, attribute);
      p.setDefaultBackground(gridControl.getBackground());
      setPainter(p);

      /*
       * The column header sets the column width based on the arguments of the label binding
       */
      if (rowID == IGridModel.HEADER1) {
        final GridColumn gridColumn = column.getGridColumn();
        gridColumn.setWidth(lb.getArgument(Constants.ARG_WIDTH, Integer.class, 60));

        // TODO: cell renderer
        // TODO: alignment
      }

      /*
       * We added a new binding so call finish as well...
       */
      context.finish(FinishOption.IF_ALREADY_FINISHED);

      attribute.addChangeListener(myPropertyValueListener);

      // An immediate update
      updateCellValuesDelayed();
    } catch (final Exception ex) {
      LogUtils.error(this, ex);
    } finally {
      cell.dispose();
    }
  }
 @Override
 public Object createValue(IObservableValue observable) {
   return observable.getValue() + "a";
 }
  /** Updates this cell - delayed. */
  protected void updateCellValuesDelayed() {
    /*
     * Check if the cell has been disposed
     */
    if (getColumn() == null) return;
    // LogUtils.debug(GridBindingCellInformationImpl.this, "");
    final IGridBinding grid = getGrid();
    final GridColumn gridColumn = getColumn().getGridColumn();
    final GridItem gridItem = getRow().getGridItem();

    /*
     * Update the cell
     */
    final IUIAttribute attr = getLabelUIAttribute();
    final IObservableValue currentValue = attr.getCurrentValue();
    if (currentValue.isDisposed()) return;
    final IObservableValue v = getObjectValue();

    final String text = (String) currentValue.getValue();
    final Color foreground = attr.getForeground();
    final Color background = attr.getBackground();
    final Image image = attr.getImage();
    final Font font = attr.getFont();
    final String tooltip = attr.getTooltip();
    // TODO: the rest: cursor, enabled, style range
    if (gridItem == null) {
      /*
       * Column header:
       */
      gridColumn.setText(text == null ? "" : text);
      gridColumn.setImage(image);
      // TODO gridColumn.set
      /*
       * The changes in the column name and image only take effect when the table is redrawn
       */
      grid.getGrid().redraw();
    } else if (gridColumn == null) {
      /*
       * Row Header
       */
      gridItem.setHeaderText(text == null ? "" : text);
      gridItem.setHeaderImage(image);
      gridItem.setHeaderForeground(foreground);
      gridItem.setHeaderBackground(background);
    } else {
      /*
       * Normal cell
       */
      final int index = grid.getGrid().indexOf(gridColumn);
      Assert.isTrue(index != -1);

      // gridItem.setChecked(index, v.getValue() == Boolean.TRUE);
      // gridItem.setText(index, null);
      // gridItem.setImage(index, null);
      // gridItem.setFont(index, null);

      gridItem.setText(index, text == null ? "" : text);
      gridItem.setImage(index, image);
      gridItem.setFont(index, font);
      gridItem.setForeground(index, foreground);
      gridItem.setBackground(index, background);
      gridItem.setToolTipText(index, tooltip);
    }
  }
 @Override
 public void change(IObservable observable) {
   final IObservableValue master = ((DetailObservableListStub) observable).master;
   master.setValue(Integer.valueOf(((Integer) master.getValue()).intValue() + 1));
 }