@Override
 protected void setUp() throws Exception {
   super.setUp();
   target = new ObservableValueStub(Realm.getDefault());
   oldValue = new Object();
   newValue = new Object();
   target.setValue(oldValue);
   delayed = Observables.observeDelayedValue(1, target);
 }
  @Test
  public void testCreateLabel() throws NoLabelFoundException {
    /* setup */
    final VControl control1 = mock(VControl.class);
    final VFeaturePathDomainModelReference dmr1 = mock(VFeaturePathDomainModelReference.class);
    when(control1.getDomainModelReference()).thenReturn(dmr1);

    final VControl control2 = mock(VControl.class);
    final VFeaturePathDomainModelReference dmr2 = mock(VFeaturePathDomainModelReference.class);
    when(control2.getDomainModelReference()).thenReturn(dmr2);

    when(compoundControl.getControls()).thenReturn(ECollections.asEList(control1, control2));

    final EObject domainModel = mock(EObject.class);
    when(viewModelContext.getDomainModel()).thenReturn(domainModel);

    when(emfFormsLabelProvider.getDisplayName(dmr1, domainModel))
        .thenReturn(Observables.constantObservableValue(LABEL1, String.class));

    when(emfFormsLabelProvider.getDisplayName(dmr2, domainModel))
        .thenReturn(Observables.constantObservableValue(LABEL2, String.class));

    final CompoundControlSWTRenderer renderer = createRenderer();

    /* act */
    final Control label = renderer.createLabel(shell);

    /* assert */
    assertTrue(Composite.class.isInstance(label));
    final Composite labelComposite = Composite.class.cast(label);
    assertEquals(3, labelComposite.getChildren().length);
    for (final Control control : labelComposite.getChildren()) {
      assertTrue(Label.class.isInstance(control));
    }
    assertEquals(LABEL1, Label.class.cast(labelComposite.getChildren()[0]).getText());
    assertEquals("/", Label.class.cast(labelComposite.getChildren()[1]).getText()); // $NON-NLS-1$
    assertEquals(LABEL2, Label.class.cast(labelComposite.getChildren()[2]).getText());
  }
/**
 * Manages a collection of brokers objects.
 *
 * <p>This class is thread safe.
 *
 * @author <a href="mailto:[email protected]">Will Horn</a>
 * @version $Id$
 * @since 1.0.0
 */
@ClassVersion("$Id$")
public final class BrokerManager implements IBrokerIdValidator {

  /** The default/null broker. */
  private static final Broker AUTO_SELECT_BROKER =
      new Broker(Messages.BROKER_MANAGER_AUTO_SELECT.getText(), null);

  /**
   * Returns the singleton instance for the currently running plug-in.
   *
   * @return the singleton instance
   */
  public static BrokerManager getCurrent() {
    return PhotonPlugin.getDefault().getBrokerManager();
  }

  private final IObservableList mAvailableBrokers =
      new WritableList(new SyncRealm(), Lists.newArrayList(AUTO_SELECT_BROKER), Broker.class);

  private final IObservableList mUnmodifiableAvailableBrokers =
      Observables.unmodifiableObservableList(mAvailableBrokers);

  private final Map<BrokerID, Broker> mBrokerMap = Maps.newHashMap();

  /**
   * Returns an observable list of the available brokers managed by this class. The returned list
   * should not be modified.
   *
   * @return the available brokers
   */
  public IObservableList getAvailableBrokers() {
    return mUnmodifiableAvailableBrokers;
  }

  /**
   * 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);
  }

  @Override
  public synchronized boolean isValid(String brokerId) {
    Validate.notNull(brokerId, "brokerID"); // $NON-NLS-1$
    return mBrokerMap.containsKey(new BrokerID(brokerId));
  }

  /**
   * Returns the {@link Broker} object for a given {@link BrokerID}. If no Broker is found, null is
   * returned.
   *
   * @param brokerId the broker id
   * @return the broker
   */
  public synchronized Broker getBroker(BrokerID brokerId) {
    if (brokerId == null) {
      return AUTO_SELECT_BROKER;
    }
    return mBrokerMap.get(brokerId);
  }

  /** Synchronizes access to the available brokers list. */
  @ClassVersion("$Id$")
  private final class SyncRealm extends Realm {
    @Override
    public boolean isCurrent() {
      return true;
    }

    @Override
    protected void syncExec(Runnable runnable) {
      synchronized (BrokerManager.this) {
        super.syncExec(runnable);
      }
    }
  }

  /** A Photon abstraction for a broker. */
  @ClassVersion("$Id$")
  public static final class Broker {
    private final String mName;
    private final BrokerID mId;

    private Broker(String name, BrokerID id) {
      mName = name;
      mId = id;
    }

    /**
     * Returns the broker name.
     *
     * @return the broker name
     */
    public String getName() {
      return mName;
    }

    /**
     * Returns the broker id.
     *
     * @return the broker id
     */
    public BrokerID getId() {
      return mId;
    }
  }

  /** Adapter for displaying {@link Broker} objects. */
  @ClassVersion("$Id$")
  public static final class BrokerLabelProvider extends LabelProvider {

    @Override
    public String getText(Object element) {
      Broker broker = (Broker) element;
      if (broker == BrokerManager.AUTO_SELECT_BROKER) return broker.getName();
      return Messages.BROKER_LABEL_PATTERN.getText(broker.getName(), broker.getId());
    }
  }
}
 @Override
 public IObservableValue createObservableValue(Realm realm) {
   return Observables.observeDelayedValue(0, new ObservableValueStub(realm));
 }
 /**
  * Returns the collection of trade suggestions.
  *
  * @return the trade suggestions
  */
 public IObservableList getTradeSuggestions() {
   return Observables.unmodifiableObservableList(mSuggestions);
 }