コード例 #1
0
  /** As per Bug 313969 */
  public void testUsesBeanObservablesWhenBindingABean() {
    final Person person = new Person("Max", "Muster"); // $NON-NLS-1$ //$NON-NLS-2$
    final Address pdx =
        createAddress(
            "pdx",
            "Portland",
            "97209",
            "USA"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    final Address fra =
        createAddress(
            "fra",
            "Frankfurt",
            "60329",
            "DE"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    person.setAddress(pdx);

    valueBindingSupport.bindToModel(person, "address.streetAndNumber"); // $NON-NLS-1$

    assertEquals("pdx", person.getAddress().getStreetAndNumber()); // $NON-NLS-1$
    assertEquals("pdx", pdx.getStreetAndNumber()); // $NON-NLS-1$

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

    assertEquals("new 1", person.getAddress().getStreetAndNumber()); // $NON-NLS-1$
    assertEquals("new 1", pdx.getStreetAndNumber()); // $NON-NLS-1$

    person.setAddress(fra);
    target.setValue("new 2"); // $NON-NLS-1$

    assertEquals("new 2", person.getAddress().getStreetAndNumber()); // $NON-NLS-1$
    assertEquals("new 2", fra.getStreetAndNumber()); // $NON-NLS-1$
    assertEquals("new 1", pdx.getStreetAndNumber()); // $NON-NLS-1$
  }
コード例 #2
0
 @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));
   }
 }
コード例 #3
0
  public void testValidationMessagesAddAndRemoveWhileActive() throws Exception {
    valueBindingSupport.addValidationRule(
        new EvenNumberOfCharacters(), ValidationTime.ON_UPDATE_TO_MODEL);
    target.setValue("odd"); // $NON-NLS-1$

    assertEquals(1, markable.getMarkers().size());
    assertTrue(markable.getMarkers().iterator().next() instanceof ErrorMarker);

    valueBindingSupport.addValidationMessage("TestMessage1"); // $NON-NLS-1$

    assertEquals(2, markable.getMarkers().size());
    assertMessageMarkers("TestMessage1"); // $NON-NLS-1$

    final MessageMarker messageMarker = new MessageMarker("TestMessage2"); // $NON-NLS-1$
    valueBindingSupport.addValidationMessage(messageMarker);

    assertEquals(3, markable.getMarkers().size());
    assertMessageMarkers("TestMessage1", "TestMessage2"); // $NON-NLS-1$ //$NON-NLS-2$

    valueBindingSupport.removeValidationMessage("TestMessage1"); // $NON-NLS-1$

    assertEquals(2, markable.getMarkers().size());
    assertMessageMarkers("TestMessage2"); // $NON-NLS-1$

    valueBindingSupport.removeValidationMessage(messageMarker);

    assertEquals(1, markable.getMarkers().size());
    assertTrue(markable.getMarkers().iterator().next() instanceof ErrorMarker);
  }
コード例 #4
0
  public void testUpdateFromTargetImmediately() throws Exception {
    assertNull(bean.getProperty());

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

    assertEquals("TestValue", bean.getProperty()); // $NON-NLS-1$
  }
コード例 #5
0
  public void testSetValue_PropagatesToTarget() {
    assertEquals(oldValue, delayed.getValue());
    assertEquals(oldValue, target.getValue());

    delayed.setValue(newValue);

    assertEquals(newValue, target.getValue());
    assertEquals(newValue, delayed.getValue());
  }
コード例 #6
0
 /**
  * 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());
         }
       });
 }
コード例 #7
0
  public void testDisposeWhileFiringEvents() {
    IObservableValue master = new WritableValue();
    WritableListFactory factory = new WritableListFactory();
    master.setValue("");

    final IObservableList[] detailObservable = new IObservableList[1];

    master.addValueChangeListener(
        new IValueChangeListener() {
          @Override
          public void handleValueChange(ValueChangeEvent event) {
            detailObservable[0].dispose();
          }
        });

    detailObservable[0] = MasterDetailObservables.detailList(master, factory, null);

    master.setValue("New Value");
  }
コード例 #8
0
  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());
  }
コード例 #9
0
  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());
  }
コード例 #10
0
  public void testRemoveValidationMessageWhenRemovingRule() {
    final IValidator rule = new AlwaysWrongValidator();
    valueBindingSupport.addValidationMessage("foo", rule); // $NON-NLS-1$
    valueBindingSupport.addValidationRule(rule, ValidationTime.ON_UPDATE_TO_MODEL);

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

    assertEquals(1, markable.getMarkersOfType(ValidationMessageMarker.class).size());

    valueBindingSupport.removeValidationRule(rule);

    assertEquals(0, markable.getMarkersOfType(ValidationMessageMarker.class).size());
  }
コード例 #11
0
  public void testDisposeMasterDisposesDetail() {
    IObservableValue master = new WritableValue();
    WritableListFactory factory = new WritableListFactory();
    master.setValue("");

    IObservableList detailObservable = MasterDetailObservables.detailList(master, factory, null);
    DisposeEventTracker tracker = DisposeEventTracker.observe(detailObservable);

    master.dispose();

    assertEquals(1, tracker.count);
    assertTrue(detailObservable.isDisposed());
  }
コード例 #12
0
  public void testSetValue_FiresValueChangeEvent() {
    ValueChangeEventTracker targetTracker = ValueChangeEventTracker.observe(target);
    ValueChangeEventTracker delayedTracker = ValueChangeEventTracker.observe(delayed);

    delayed.setValue(newValue);

    assertEquals(1, targetTracker.count);
    assertEquals(oldValue, targetTracker.event.diff.getOldValue());
    assertEquals(newValue, targetTracker.event.diff.getNewValue());

    assertEquals(1, delayedTracker.count);
    assertEquals(oldValue, delayedTracker.event.diff.getOldValue());
    assertEquals(newValue, delayedTracker.event.diff.getNewValue());
  }
コード例 #13
0
  public void testSpecialValidationMessages() throws Exception {
    final EvenNumberOfCharacters evenNumberOfCharacters = new EvenNumberOfCharacters();
    final NotEndingWithDisaster notEndingWithDisaster = new NotEndingWithDisaster();
    valueBindingSupport.addValidationRule(
        evenNumberOfCharacters, ValidationTime.ON_UPDATE_TO_MODEL);
    valueBindingSupport.addValidationRule(notEndingWithDisaster, ValidationTime.ON_UPDATE_TO_MODEL);
    valueBindingSupport.addValidationMessage(
        "TestNotEvenMessage1", evenNumberOfCharacters); // $NON-NLS-1$
    valueBindingSupport.addValidationMessage(
        new MessageMarker("TestNotEvenMessage2"), evenNumberOfCharacters); // $NON-NLS-1$
    valueBindingSupport.addValidationMessage(
        "TestDisasterMessage", notEndingWithDisaster); // $NON-NLS-1$

    assertEquals(0, markable.getMarkers().size());

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

    assertEquals(2, markable.getMarkers().size());
    assertMessageMarkers("TestDisasterMessage"); // $NON-NLS-1$

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

    assertEquals(3, markable.getMarkers().size());
    assertMessageMarkers("TestNotEvenMessage1", "TestNotEvenMessage2"); // $NON-NLS-1$ //$NON-NLS-2$

    target.setValue("We are teetering on the brink of disaster"); // $NON-NLS-1$

    assertEquals(5, markable.getMarkers().size());
    assertMessageMarkers(
        "TestNotEvenMessage1",
        "TestNotEvenMessage2",
        "TestDisasterMessage"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

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

    assertEquals(0, markable.getMarkers().size());
  }
コード例 #14
0
  /** Tests that adding the same validation several times has no effect */
  public void testAddSameValidationMessage() {
    final EvenNumberOfCharacters rule = new EvenNumberOfCharacters();
    valueBindingSupport.addValidationRule(rule, ValidationTime.ON_UPDATE_TO_MODEL);
    valueBindingSupport.addValidationMessage("TestMessage1"); // $NON-NLS-1$
    valueBindingSupport.addValidationMessage("TestMessage1"); // $NON-NLS-1$
    valueBindingSupport.addValidationMessage("TestMessage2", rule); // $NON-NLS-1$
    valueBindingSupport.addValidationMessage("TestMessage2", rule); // $NON-NLS-1$
    final MessageMarker messageMarker = new MessageMarker("TestMessage3"); // $NON-NLS-1$
    valueBindingSupport.addValidationMessage(messageMarker);
    valueBindingSupport.addValidationMessage(messageMarker);
    final MessageMarker messageMarker2 = new MessageMarker("TestMessage4"); // $NON-NLS-1$
    valueBindingSupport.addValidationMessage(messageMarker2, rule);
    valueBindingSupport.addValidationMessage(messageMarker2, rule);

    assertEquals(0, markable.getMarkers().size());

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

    assertEquals(4, markable.getMarkersOfType(ValidationMessageMarker.class).size());

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

    assertEquals(0, markable.getMarkers().size());
  }
コード例 #15
0
  public void testAddAndRemoveValidationMessageWithoutRule() {
    assertEquals(0, markable.getMarkersOfType(ValidationMessageMarker.class).size());

    final MinLength rule = new MinLength(3);
    valueBindingSupport.addValidationRule(rule, ValidationTime.ON_UPDATE_TO_MODEL);
    valueBindingSupport.addValidationMessage("too short"); // $NON-NLS-1$
    target.setValue("a"); // $NON-NLS-1$

    assertEquals(1, markable.getMarkersOfType(ValidationMessageMarker.class).size());
    assertMessageMarkers("too short"); // $NON-NLS-1$

    valueBindingSupport.removeValidationMessage("too short"); // $NON-NLS-1$

    assertEquals(0, markable.getMarkersOfType(ValidationMessageMarker.class).size());
  }
コード例 #16
0
  /** Asynchronously updates the set of existing applications. Must be called from the UI thread. */
  private void refreshApplications() {
    /*
     * While the values load, we need to disable the controls and fake a
     * radio button selected event.
     */
    createNewApplicationRadioButton.setSelection(true);
    existingApplicationRadioButton.setSelection(false);
    existingApplicationRadioButton.setEnabled(false);
    radioButtonSelected(createNewApplicationRadioButton);

    existingApplicationCombo.setItems(new String[] {LOADING});
    existingApplicationCombo.select(0);
    cancelThread(loadApplicationsThread);
    applicationNamesLoaded.setValue(false);
    loadApplicationsThread = new LoadApplicationsThread();
    loadApplicationsThread.start();
  }
コード例 #17
0
  @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;
    }
  }
コード例 #18
0
  public void fireEvent(IObservableValueListener manager, IProperty property) {
    Object host = manager.getHost();
    IMetaclass metaclass = XWT.getMetaclass(host);

    EventProperty reaisedEventProperty = (EventProperty) property;
    String raisedName = reaisedEventProperty.getEvent().getName();
    for (String name : getEventNames()) {
      if (name.equalsIgnoreCase(raisedName)) {
        continue;
      }
      String eventPropertyName = IEventConstants.getEventPropertyName(name);
      IProperty eventProperty = metaclass.findProperty(eventPropertyName);

      IObservableValue value = manager.getValue(eventProperty);
      if (value != null) {
        value.setValue(false);
      }
    }
  }
コード例 #19
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$
  }
コード例 #20
0
 @Override
 public void change(IObservable observable) {
   IObservableValue value = (IObservableValue) observable;
   value.setValue(value.getValue() + "a");
 }
コード例 #21
0
 @Override
 protected void doSetValue(Object value) {
   for (IObservableValue observable : observableValues) {
     observable.setValue(value);
   }
 }
コード例 #22
0
 /** Asynchronously updates the set of existing environments for the current application. */
 private void refreshEnvironments() {
   cancelThread(loadEnvironmentsThread);
   environmentNamesLoaded.setValue(false);
   loadEnvironmentsThread = new LoadEnvironmentsThread();
   loadEnvironmentsThread.start();
 }
コード例 #23
0
 @Override
 public void change(IObservable observable) {
   IObservableValue observableValue = (IObservableValue) observable;
   observableValue.setValue(createValue(observableValue));
 }
コード例 #24
0
 @Override
 public void change(IObservable observable) {
   final IObservableValue master = ((DetailObservableListStub) observable).master;
   master.setValue(Integer.valueOf(((Integer) master.getValue()).intValue() + 1));
 }
コード例 #25
0
 @SuppressWarnings("unchecked")
 protected void onSelectedConnectionChanged(IObservableValue selectedConnection) {
   registryURLObservable.setValue(model.getRegistryURL());
 }
コード例 #26
0
 DeployWizardApplicationSelectionPage(DeployWizardDataModel wizardDataModel) {
   super(wizardDataModel);
   environmentNamesLoaded.setValue(false);
   applicationNamesLoaded.setValue(false);
   vpcConfigPage = new DeployWizardVpcConfigurationPage(wizardDataModel);
 }