Search in sources :

Example 1 with ObservableValue

use of com.android.tools.idea.ui.properties.ObservableValue in project android by JetBrains.

the class ServiceContext method toValueMap.

/**
   * Converts this service context, which is itself backed by a flat map, into a hierarchical map,
   * a data structure that freemarker works well with.
   * <p/>
   * For example, a service context with the values "parent.child1" and "parent.child2" will return
   * a map that is nested like so
   * <pre>
   * parent
   *   child1
   *   child2
   * </pre>
   */
@NotNull
public Map<String, Object> toValueMap() {
    Map<String, Object> valueMap = Maps.newHashMap();
    Splitter splitter = Splitter.on('.');
    for (String key : myValues.keySet()) {
        ObservableValue value = getValue(key);
        Map<String, Object> currLevel = valueMap;
        Iterator<String> keyParts = splitter.split(key).iterator();
        while (keyParts.hasNext()) {
            String keyPart = keyParts.next();
            if (keyParts.hasNext()) {
                if (currLevel.containsKey(keyPart)) {
                    currLevel = (Map<String, Object>) currLevel.get(keyPart);
                } else {
                    Map<String, Object> nextLevel = Maps.newHashMap();
                    currLevel.put(keyPart, nextLevel);
                    currLevel = nextLevel;
                }
            } else {
                // We're the last part of the key
                currLevel.put(keyPart, value);
            }
        }
    }
    return valueMap;
}
Also used : Splitter(com.google.common.base.Splitter) ObservableValue(com.android.tools.idea.ui.properties.ObservableValue) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ObservableValue

use of com.android.tools.idea.ui.properties.ObservableValue in project android by JetBrains.

the class ServicePanelBuilder method addComboBox.

public JComboBox addComboBox(@NotNull final ObservableList<String> backingList) {
    final CollectionComboBoxModel<String> model = new CollectionComboBoxModel<String>(backingList) {

        @NotNull
        @Override
        public List<String> getItems() {
            return backingList;
        }
    };
    final ComboBox comboBox = new ComboBox(model);
    InvalidationListener onListModified = new InvalidationListener() {

        @Override
        public void onInvalidated(@NotNull ObservableValue<?> sender) {
            model.update();
            if (backingList.size() > 0 && comboBox.getSelectedIndex() < 0) {
                comboBox.setSelectedIndex(0);
            }
        }
    };
    addComponent(comboBox);
    backingList.addWeakListener(onListModified);
    // Keep weak listener alive as long as the combobox is alive
    comboBox.putClientProperty("onListModified", onListModified);
    return comboBox;
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) ObservableValue(com.android.tools.idea.ui.properties.ObservableValue) CollectionComboBoxModel(com.intellij.ui.CollectionComboBoxModel) InvalidationListener(com.android.tools.idea.ui.properties.InvalidationListener) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ObservableValue

use of com.android.tools.idea.ui.properties.ObservableValue in project android by JetBrains.

the class FormatExpression method get.

@NotNull
@Override
public String get() {
    Object[] values = new Object[myValues.size()];
    int i = 0;
    for (ObservableValue observableValue : myValues) {
        values[i++] = observableValue.get();
    }
    return String.format(myFormatString, values);
}
Also used : ObservableValue(com.android.tools.idea.ui.properties.ObservableValue) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ObservableValue (com.android.tools.idea.ui.properties.ObservableValue)3 NotNull (org.jetbrains.annotations.NotNull)3 InvalidationListener (com.android.tools.idea.ui.properties.InvalidationListener)1 Splitter (com.google.common.base.Splitter)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 CollectionComboBoxModel (com.intellij.ui.CollectionComboBoxModel)1