コード例 #1
0
 /** @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;
 }
コード例 #2
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$
  }
コード例 #3
0
  public void testChange_OrderOfNotifications() throws Exception {
    final List listeners = new ArrayList();
    IChangeListener changeListener =
        new IChangeListener() {
          public void handleChange(ChangeEvent event) {
            listeners.add(this);
          }
        };

    IValueChangeListener valueChangeListener =
        new IValueChangeListener() {
          public void handleValueChange(ValueChangeEvent event) {
            listeners.add(this);
          }
        };

    observable.addChangeListener(changeListener);
    observable.addValueChangeListener(valueChangeListener);

    delegate.change(observable);

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

    // not asserting the fact that both are notified as this is asserted in
    // other tests
    assertEquals(
        formatFail("Change listeners should be notified before value change listeners."),
        changeListener,
        listeners.get(0));
    assertEquals(
        formatFail("Value change listeners should be notified after change listeners."),
        valueChangeListener,
        listeners.get(1));
  }
 @Override
 public Object get(int index) {
   if (index < 0 || index >= masterList.size()) {
     throw new IndexOutOfBoundsException();
   }
   // We should have an element, now check to see if we've already
   // mapped it to an observable value.
   if (index >= observableValueList.size()) {
     // Just null-padding entries that we should have, but haven't
     // been explicitly requested.
     while (this.observableValueList.size() <= index) {
       this.observableValueList.add(null);
     }
   }
   // I'm assuming get is Realm-bound, so there are no concurrency issues
   // to worry about.
   if (observableValueList.get(index) == null) {
     IObservableValue value = aggregateProperty.observe(masterList.get(index));
     if (listener != null) {
       value.addValueChangeListener(listener);
     }
     observableValueList.set(index, value);
   }
   return observableValueList.get(index).getValue();
 }
コード例 #5
0
ファイル: ViewEditor.java プロジェクト: go2zo/flaming-bear
  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();
  }
 protected void lastListenerRemoved() {
   for (IObservableValue value : this.observableValueList) {
     value.removeValueChangeListener(listener);
   }
   this.masterList.removeStaleListener(listener);
   this.masterList.removeListChangeListener(listener);
   this.listener = null;
 }
コード例 #7
0
 @Override
 public synchronized void dispose() {
   super.dispose();
   for (IObservableValue observable : observableValues) {
     observable.removeChangeListener(this);
     observable.dispose();
   }
 }
コード例 #8
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());
         }
       });
 }
コード例 #9
0
  public void testSetValue_PropagatesToTarget() {
    assertEquals(oldValue, delayed.getValue());
    assertEquals(oldValue, target.getValue());

    delayed.setValue(newValue);

    assertEquals(newValue, target.getValue());
    assertEquals(newValue, delayed.getValue());
  }
コード例 #10
0
  public void testIsStale_DuringDelay() {
    assertFalse(target.isStale());
    assertFalse(delayed.isStale());

    target.setValue(newValue);

    assertFalse(target.isStale());
    assertTrue(delayed.isStale());
  }
コード例 #11
0
  public void testIsStale_WhenTargetIsStale() {
    assertFalse(target.isStale());
    assertFalse(delayed.isStale());

    target.fireStale();

    assertTrue(target.isStale());
    assertTrue(delayed.isStale());
  }
コード例 #12
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());
  }
 @Override
 public synchronized void dispose() {
   if (listener != null) {
     lastListenerRemoved();
   }
   for (IObservableValue value : this.observableValueList) {
     value.dispose();
   }
   super.dispose();
 }
コード例 #14
0
  public Control createControl(Composite composite, String label, int style) {

    // create a separate label to the LEFT of the checkbox, otherwise the grid layout will
    // be off by one column for all other widgets that are created after this one.
    createLabel(composite, label);

    button = getToolkit().createButton(composite, "", SWT.CHECK);
    button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    button.setSelection((Boolean) object.eGet(feature));
    IObservableValue buttonObserver = SWTObservables.observeSelection(button);
    buttonObserver.addValueChangeListener(
        new IValueChangeListener() {

          @SuppressWarnings("restriction")
          @Override
          public void handleValueChange(ValueChangeEvent event) {

            if (!object.eGet(feature).equals(button.getSelection())) {
              TransactionalEditingDomain editingDomain = getDiagramEditor().getEditingDomain();
              editingDomain
                  .getCommandStack()
                  .execute(
                      new RecordingCommand(editingDomain) {
                        @Override
                        protected void doExecute() {
                          object.eSet(feature, button.getSelection());
                        }
                      });

              //					if (getDiagramEditor().getDiagnostics()!=null) {
              //						// revert the change and display error errorList message.
              //						button.setSelection((Boolean) object.eGet(feature));
              //						ErrorUtils.showErrorMessage(getDiagramEditor().getDiagnostics().getMessage());
              //					}
              //					else
              //						ErrorUtils.showErrorMessage(null);
              button.setSelection((Boolean) object.eGet(feature));
            }
          }
        });

    button.addFocusListener(
        new FocusListener() {

          @Override
          public void focusGained(FocusEvent e) {}

          @Override
          public void focusLost(FocusEvent e) {
            ErrorUtils.showErrorMessage(null);
          }
        });

    return button;
  }
コード例 #15
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());
  }
コード例 #16
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$
  }
コード例 #17
0
  @SuppressWarnings("unchecked")
  private void removeConnectionChangedListener(
      final IValueChangeListener connectionChangedListener,
      final IObservableValue selectedConnection) {
    if (selectedConnection == null
        || selectedConnection.isDisposed()
        || connectionChangedListener == null) {
      return;
    }

    selectedConnection.removeValueChangeListener(connectionChangedListener);
  }
 @Override
 protected void firstListenerAdded() {
   // First time we add a listener to this observableList, we need to hook
   // up a listener to the masterList, as well as all observable values
   // we've already created.
   listener = new Listener();
   this.masterList.addListChangeListener(listener);
   this.masterList.addStaleListener(listener);
   for (IObservableValue value : this.observableValueList) {
     value.addValueChangeListener(listener);
   }
 }
コード例 #19
0
  /**
   *
   * <!-- 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();
  }
コード例 #20
0
  /**
   * Observes changes in the specified valuse with the associated event.
   *
   * @param event the event
   * @param newValues the observable values
   */
  protected void observe(Event event, List<IObservableValue> newValues) {
    myPreviousValueEvent = event;
    if (newValues.equals(myPreviousValues)) return;

    for (final IObservableValue v : myPreviousValues) {
      v.removeChangeListener(myObservedChangeListener);
    }
    myPreviousValues.clear();
    for (final IObservableValue v : newValues) {
      v.addChangeListener(myObservedChangeListener);
    }
    myPreviousValues.addAll(newValues);
  }
コード例 #21
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());
  }
コード例 #22
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;
 }
コード例 #23
0
  protected void bindFields() {
    if (dataBindingContext != null) {
      dataBindingContext.dispose();
    }
    dataBindingContext = new EMFDataBindingContext();
    if (downloadOnly != null) {
      if (ModelHelper.getForm(element) instanceof ViewForm) {
        downloadOnly.setSelection(true);
        downloadOnly.setEnabled(false);
      } else {
        dataBindingContext.bindValue(
            SWTObservables.observeSelection(downloadOnly),
            EMFEditObservables.observeValue(
                editingDomain, element, FormPackage.Literals.FILE_WIDGET__DOWNLOAD_ONLY));
      }
    }

    dataBindingContext.bindValue(
        SWTObservables.observeSelection(imagePreview),
        EMFEditObservables.observeValue(
            editingDomain, element, FormPackage.Literals.FILE_WIDGET__USE_PREVIEW));

    IObservableValue value =
        EMFObservables.observeValue(element, FormPackage.Literals.DUPLICABLE__DUPLICATE);

    value.addValueChangeListener(
        new IValueChangeListener() {

          public void handleValueChange(ValueChangeEvent arg0) {
            if (useDocumentButton != null
                && !useDocumentButton.isDisposed()
                && element.getInputType() == FileWidgetInputType.DOCUMENT) {
              useDocumentButton.notifyListeners(SWT.Selection, new Event());
              /*}else if(!useResourceButton.isDisposed() && element.getInputType() == FileWidgetInputType.URL){
              useURLButton.notifyListeners(SWT.Selection,new Event());*/
            } else if (!useResourceButton.isDisposed()
                && element.getInputType() == FileWidgetInputType.RESOURCE) {
              useResourceButton.notifyListeners(SWT.Selection, new Event());
            }
            if (inputExpressionViewer != null
                && !getInputExpressionHint()
                    .equals(inputExpressionViewer.getMessage(IStatus.INFO))) {
              inputExpressionViewer.setMessage(getInputExpressionHint(), IStatus.INFO);
            }
          }
        });

    bindInputExpressionViewer();
    bindResourceText();
  }
コード例 #24
0
  private void assertFiresPendingValueChange(Runnable runnable) {
    ValueChangeEventTracker tracker = ValueChangeEventTracker.observe(delayed);

    target.setValue(newValue);
    assertTrue(delayed.isStale());
    assertEquals(0, tracker.count);

    runnable.run();

    assertFalse(delayed.isStale());
    assertEquals(1, tracker.count);
    assertEquals(oldValue, tracker.event.diff.getOldValue());
    assertEquals(newValue, tracker.event.diff.getNewValue());
  }
コード例 #25
0
 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;
   }
 }
コード例 #26
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public boolean eIsSet(int featureID) {
   switch (featureID - EOFFSET_CORRECTION) {
     case IGridPackage.GRID_BINDING_CELL_INFORMATION__COLUMN:
       return column != null;
     case IGridPackage.GRID_BINDING_CELL_INFORMATION__ROW:
       return row != null;
     case IGridPackage.GRID_BINDING_CELL_INFORMATION__DATA_TYPE:
       return dataType != null;
     case IGridPackage.GRID_BINDING_CELL_INFORMATION__LABEL_BINDING:
       return labelBinding != null;
     case IGridPackage.GRID_BINDING_CELL_INFORMATION__LABEL_UI_ATTRIBUTE:
       return labelUIAttribute != null;
     case IGridPackage.GRID_BINDING_CELL_INFORMATION__OBJECT_VALUE:
       return OBJECT_VALUE_EDEFAULT == null
           ? objectValue != null
           : !OBJECT_VALUE_EDEFAULT.equals(objectValue);
     case IGridPackage.GRID_BINDING_CELL_INFORMATION__CHANGEABLE:
       return isChangeable() != CHANGEABLE_EDEFAULT;
     case IGridPackage.GRID_BINDING_CELL_INFORMATION__DISPLAY_TEXT:
       return DISPLAY_TEXT_EDEFAULT == null
           ? getDisplayText() != null
           : !DISPLAY_TEXT_EDEFAULT.equals(getDisplayText());
     case IGridPackage.GRID_BINDING_CELL_INFORMATION__VALUE_TYPE:
       return getValueType() != null;
     case IGridPackage.GRID_BINDING_CELL_INFORMATION__PASTE_UI_ATTRIBUTE:
       return pasteUIAttribute != null;
     case IGridPackage.GRID_BINDING_CELL_INFORMATION__ENABLED:
       return enabled != ENABLED_EDEFAULT;
     case IGridPackage.GRID_BINDING_CELL_INFORMATION__PAINTER:
       return PAINTER_EDEFAULT == null ? painter != null : !PAINTER_EDEFAULT.equals(painter);
   }
   return super.eIsSet(featureID);
 }
コード例 #27
0
ファイル: AbstractDetailViewer.java プロジェクト: 3GF/era_dev
 /**
  * Clean up when disposing the details viewer
  *
  * @see org.eclipse.swt.widgets.Widget#dispose()
  * @see era.foss.typeeditor.common.Ui#dispose()
  */
 @Override
 public void dispose() {
   super.dispose();
   this.disposeDetails();
   master.dispose();
   dataBindingContext.dispose();
 }
コード例 #28
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);
  }
コード例 #29
0
  public void testUpdateFromTargetImmediately() throws Exception {
    assertNull(bean.getProperty());

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

    assertEquals("TestValue", bean.getProperty()); // $NON-NLS-1$
  }
コード例 #30
0
ファイル: VariableFilter.java プロジェクト: nagyist/statet
 protected void registerObservable(final IObservable observable) {
   if (observable instanceof IObservableValue) {
     ((IObservableValue) observable).addValueChangeListener(fValueListener);
   }
   if (observable instanceof IObservableSet) {
     ((IObservableSet) observable).addSetChangeListener(fValueListener);
   }
 }