/*
 * Copyright 2016 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.cloud.tools.eclipse.login.ui;

import org.eclipse.core.databinding.observable.Diffs;
import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
import org.eclipse.jface.databinding.swt.DisplayRealm;

/**
 * An object that represents and binds to the email value of an {@link AccountSelector}, whose
 * changes (i.e., account selection changes in the combo box) can be tracked by value change
 * listeners.
 */
public class AccountSelectorObservableValue extends AbstractObservableValue {

  private String oldValue;
  private AccountSelector accountSelector;

  public AccountSelectorObservableValue(final AccountSelector accountSelector) {
    super(DisplayRealm.getRealm(accountSelector.getDisplay()));
    this.accountSelector = accountSelector;

    accountSelector.addSelectionListener(new Runnable() {
      @Override
      public void run() {
        String newValue = accountSelector.getSelectedEmail();
        fireValueChange(Diffs.createValueDiff(oldValue, newValue));
        oldValue = newValue;
      }
    });
  }

  @Override
  public Object getValueType() {
    return String.class;
  }

  @Override
  protected Object doGetValue() {
    return accountSelector.getSelectedEmail();
  }

  @Override
  protected void doSetValue(final Object value) {
    accountSelector.selectAccount((String) value);
  }
}

@@ -1112,16 +1112,24 @@
 bleValue
+%3CString%3E
  %7B%0A%0A  pr
@@ -1764,22 +1764,22 @@
 otected 
-Object
+String
  doGetVa
@@ -1884,22 +1884,22 @@
 e(final 
-Object
+String
  value) 
@@ -1938,17 +1938,8 @@
 unt(
-(String) 
 valu

fix warning (#2819)