Esempio n. 1
0
  private void addLanguage(String language, int fillLanguage) {
    for (int i = 0; i < fillLanguage; i++) {
      languages.add(""); // $NON-NLS-1$
    }

    languages.add(language);
  }
Esempio n. 2
0
  private void addBody(String body, int fillBody) {
    for (int i = 0; i < fillBody; i++) {
      bodies.add(""); // $NON-NLS-1$
    }

    bodies.add(body);
  }
 @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();
 }
Esempio n. 4
0
  private void UMLToExpression() {
    int maxSize = Math.max(languages.size(), bodies.size());

    Iterator<?> languageIterator = languages.iterator();
    Iterator<?> bodyIterator = bodies.iterator();

    for (int i = 0; i < maxSize; i++) {
      Expression expression;
      if (i < expressions.size()) {
        expression = expressions.get(i);
      } else {
        expression = new Expression();
        if (nestedChangeListener != null) {
          expression.addChangeListener(nestedChangeListener);
        }
        expressions.add(expression);
      }

      if (languageIterator.hasNext()) {
        expression.setLanguage((String) languageIterator.next());
      }

      if (bodyIterator.hasNext()) {
        expression.setBody((String) bodyIterator.next());
      }
    }
    // remove additional entries in expressions list that are not in the UML list
    for (int i = maxSize; i < expressions.size(); i++) {
      expressions.remove(i);
    }
  }
  public void testAddAtIndex() throws Exception {
    String element = "1";
    assertEquals(0, list.size());

    list.add(0, element);
    assertEquals(element, bean.getList().get(0));
  }
  /**
   * Makes sure that the list set on the Pojo model after changing the observable list is modifiable
   * (see bugs 285307 and 301774).
   */
  public void testUpdatedPojoListIsModifiable() {
    Bean bean = new Bean(new ArrayList());
    IObservableList observable = PojoObservables.observeList(bean, "list");

    observable.add(new Object());
    bean.getList().clear();
  }
Esempio n. 7
0
 @Override
 protected Object getRowValue(final int i) {
   // return getRidget().getRowObservables().get(i);
   final IObservableList rowObservables =
       ReflectionUtils.invokeHidden(getRidget(), "getRowObservables"); // $NON-NLS-1$
   return rowObservables.get(i);
 }
  public void testAddAll() throws Exception {
    Collection elements = Arrays.asList(new String[] {"1", "2"});
    assertEquals(0, list.size());

    list.addAll(elements);

    assertEquals(2, bean.getList().size());
  }
  public void testRemove() throws Exception {
    String element = "1";
    list.add(element);

    assertEquals(1, bean.getList().size());
    list.remove(element);
    assertEquals(0, bean.getList().size());
  }
  public void testRemovesListenerAfterLastListenerIsRemoved() throws Exception {
    ListChangeEventTracker listener = new ListChangeEventTracker();
    list.addListChangeListener(listener);

    assertTrue(bean.changeSupport.hasListeners(propertyName));
    list.removeListChangeListener(listener);
    assertFalse(bean.changeSupport.hasListeners(propertyName));
  }
    @Override
    public IObservableCollection createObservableCollection(Realm realm, int elementCount) {
      String propertyName = "list";
      Object bean = new Bean(new ArrayList());

      IObservableList list = BeansObservables.observeList(realm, bean, propertyName, String.class);
      for (int i = 0; i < elementCount; i++) list.add(createElement(list));
      return list;
    }
  public void testAddAddsElement() throws Exception {
    int count = list.size();
    String element = "1";

    assertEquals(0, count);
    list.add(element);
    assertEquals(count + 1, list.size());
    assertEquals(element, bean.getList().get(count));
  }
  public void testSet() throws Exception {
    String oldElement = "old";
    String newElement = "new";
    list.add(oldElement);

    assertEquals(oldElement, bean.getList().get(0));

    list.set(0, newElement);
    assertEquals(newElement, bean.getList().get(0));
  }
  public void testRemoveAll() throws Exception {
    list.addAll(Arrays.asList(new String[] {"1", "2", "3", "4"}));
    assertEquals(4, bean.getList().size());

    list.removeAll(Arrays.asList(new String[] {"2", "4"}));

    assertEquals(2, bean.getList().size());
    assertEquals("1", bean.getList().get(0));
    assertEquals("3", bean.getList().get(1));
  }
  private void loadValues() {
    this.list.clear();

    final TaskTagsPreferences taskPrefs = new TaskTagsPreferences(this);
    this.list.addAll(taskPrefs.getTaskTags());

    if (!list.isEmpty()) {
      this.defaultValue.setValue(list.get(0));
    }
  }
  private void added(E input) {
    listeners.elementAdded(input);

    IObservableList<E> observable = observableFactory.createObservable(input);
    elementToObservable.put(input, observable);
    observable.addListChangeListener(listChangeListener);
    for (E element : observable) {
      added(element);
    }
  }
  public void testModifyObservableList_FiresListChange() {
    Bean bean = new Bean(new ArrayList());
    IObservableList observable = BeansObservables.observeList(bean, "list");
    ListChangeEventTracker tracker = ListChangeEventTracker.observe(observable);

    Object element = new Object();
    observable.add(element);

    assertEquals(1, tracker.count);
    assertDiff(tracker.event.diff, Collections.EMPTY_LIST, Collections.singletonList(element));
  }
  private void removed(E input) {
    listeners.elementRemoved(input);

    IObservableList<E> observable = elementToObservable.remove(input);
    if (observable != null) {
      observable.removeListChangeListener(listChangeListener);
      for (E element : observable) {
        removed(element);
      }
      observable.dispose();
    }
  }
  public void testAddAllAtIndex() throws Exception {
    List elements = Arrays.asList(new String[] {"1", "2"});
    list.addAll(elements);

    assertEquals(2, list.size());

    list.addAll(2, elements);

    assertEquals(4, bean.getList().size());
    assertEquals(elements.get(0), bean.getList().get(0));
    assertEquals(elements.get(1), bean.getList().get(1));
  }
Esempio n. 20
0
 @Override
 protected int[] getSelectedRows() {
   final IObservableList rowObservables =
       ReflectionUtils.invokeHidden(getRidget(), "getRowObservables"); // $NON-NLS-1$
   final Object[] elements = getRidget().getMultiSelectionObservable().toArray();
   final int[] result = new int[elements.length];
   for (int i = 0; i < elements.length; i++) {
     final Object element = elements[i];
     result[i] = rowObservables.indexOf(element);
   }
   return result;
 }
  public void testAddAtIndexListChangeEvent() throws Exception {
    String element = "1";
    assertEquals(0, list.size());

    ListChangeEventTracker listener = new ListChangeEventTracker();
    list.addListChangeListener(listener);

    list.add(0, element);

    ListChangeEvent event = listener.event;
    assertDiff(event.diff, Collections.EMPTY_LIST, Collections.singletonList("1"));
  }
  public void testRetailAll() throws Exception {
    List elements = Arrays.asList(new String[] {"0", "1", "2", "3"});
    list.addAll(elements);

    assertEquals(4, bean.getList().size());

    list.retainAll(elements.subList(0, 2));
    assertEquals(2, bean.getList().size());

    assertEquals(elements.get(0), bean.getList().get(0));
    assertEquals(elements.get(1), bean.getList().get(1));
  }
  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());
  }
Esempio n. 24
0
 /**
  * Updates the available brokers from a {@link BrokersStatus} event.
  *
  * @param statuses the new statuses
  */
 public synchronized void setBrokersStatus(BrokersStatus statuses) {
   mBrokerMap.clear();
   mAvailableBrokers.clear();
   List<Broker> availableBrokers = Lists.newArrayList();
   availableBrokers.add(AUTO_SELECT_BROKER);
   for (BrokerStatus status : statuses.getBrokers()) {
     if (status.getLoggedOn()) {
       Broker broker = new Broker(status.getName(), status.getId());
       mBrokerMap.put(status.getId(), broker);
       availableBrokers.add(broker);
     }
   }
   mAvailableBrokers.addAll(availableBrokers);
 }
Esempio n. 25
0
  /**
   * Constructor.
   *
   * @param languages The IObservableList containing Languages
   * @param bodies The IObservableList containing Bodies
   * @param nestedChangeListener Execute listener.
   */
  public ExpressionList(
      IObservableList languages, IObservableList bodies, IChangeListener nestedChangeListener) {
    super(new LinkedList<Expression>(), Expression.class);
    expressions = wrappedList;

    this.languages = languages;
    this.bodies = bodies;

    languages.addChangeListener(this);
    bodies.addChangeListener(this);
    this.nestedChangeListener = nestedChangeListener;

    UMLToExpression();
  }
 {
   Person fergus = new Person("Fergus McDuck", UNKNOWN, UNKNOWN);
   Person downy = new Person("Downy O'Drake", UNKNOWN, UNKNOWN);
   Person scrooge = new Person("Scrooge McDuck", downy, fergus);
   Person hortense = new Person("Hortense McDuck", downy, fergus);
   Person quackmore = new Person("Quackmore Duck", UNKNOWN, UNKNOWN);
   Person della = new Person("Della Duck", hortense, quackmore);
   Person donald = new Person("Donald Duck", hortense, quackmore);
   donald.setFather(quackmore);
   donald.setMother(hortense);
   della.setFather(quackmore);
   della.setMother(hortense);
   hortense.setMother(downy);
   hortense.setFather(fergus);
   scrooge.setMother(downy);
   scrooge.setFather(fergus);
   people.add(UNKNOWN);
   people.add(downy);
   people.add(fergus);
   people.add(scrooge);
   people.add(quackmore);
   people.add(hortense);
   people.add(della);
   people.add(donald);
 }
  public void testAddListChangeEvent() throws Exception {
    ListChangeEventTracker listener = new ListChangeEventTracker();
    list.addListChangeListener(listener);

    assertEquals(0, listener.count);
    String element = "1";

    list.add(element);

    assertEquals(1, listener.count);
    ListChangeEvent event = listener.event;

    assertSame(list, event.getObservableList());
    assertDiff(event.diff, Collections.EMPTY_LIST, Collections.singletonList("1"));
  }
  public void testAddAllListChangEvent() throws Exception {
    List elements = Arrays.asList(new String[] {"1", "2"});
    assertEquals(0, list.size());

    ListChangeEventTracker listener = new ListChangeEventTracker();
    list.addListChangeListener(listener);
    assertEquals(0, listener.count);

    list.addAll(elements);

    assertEquals(1, listener.count);
    ListChangeEvent event = listener.event;
    assertSame(list, event.getObservableList());

    assertDiff(event.diff, Collections.EMPTY_LIST, Arrays.asList(new String[] {"1", "2"}));
  }
  public void testMove() throws Exception {
    String element0 = "element0";
    String element1 = "element1";
    list.add(element0);
    list.add(element1);

    assertEquals(2, bean.getList().size());
    assertEquals(element0, bean.getList().get(0));
    assertEquals(element1, bean.getList().get(1));

    list.move(0, 1);

    assertEquals(2, bean.getList().size());
    assertEquals(element1, bean.getList().get(0));
    assertEquals(element0, bean.getList().get(1));
  }
  public void testFiresListChangeEvents() throws Exception {
    ListChangeEventTracker listener = new ListChangeEventTracker();
    list.addListChangeListener(listener);

    assertEquals(0, listener.count);
    bean.setList(Arrays.asList(new String[] {"value"}));
    assertEquals(1, listener.count);
  }