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;
}
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;
}
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);
}
Aggregations