use of com.android.tools.idea.gradle.parser.NamedObject in project android by JetBrains.
the class NamedObjectPanel method init.
@Override
public void init() {
super.init();
myPanelGroup.myPanes.add(myDetailsPane);
if (myGradleBuildFile == null) {
return;
}
List<NamedObject> namedObjects = (List<NamedObject>) myGradleBuildFile.getValue(myBuildFileKey);
if (namedObjects != null) {
for (NamedObject object : namedObjects) {
// consistent between the case where you've customized it and you haven't.
if (myBuildFileKey == BuildFileKey.BUILD_TYPES && HARDCODED_BUILD_TYPES.contains(object.getName())) {
object = new UndeletableNamedObject(object);
}
addElement(object);
}
}
// If this is a flavor panel, add a synthetic flavor entry for defaultConfig.
if (myBuildFileKey == BuildFileKey.FLAVORS) {
GrStatementOwner defaultConfig = myGradleBuildFile.getClosure(BuildFileKey.DEFAULT_CONFIG.getPath());
NamedObject obj = new UndeletableNamedObject(DEFAULT_CONFIG);
if (defaultConfig != null) {
for (BuildFileKey key : DEFAULT_CONFIG_KEYS) {
Object value = myGradleBuildFile.getValue(defaultConfig, key);
obj.setValue(key, value);
}
}
addElement(obj);
}
NamedObject.Factory objectFactory = (NamedObject.Factory) myBuildFileKey.getValueFactory();
if (objectFactory == null) {
throw new IllegalArgumentException("Can't instantiate a NamedObjectPanel for BuildFileKey " + myBuildFileKey.toString());
}
Collection<BuildFileKey> properties = objectFactory.getProperties();
// Query the model for its view of the world, and merge it with the build file-based view.
for (NamedObject obj : getObjectsFromModel(properties)) {
boolean found = false;
for (NamedObject o : myListModel) {
if (o.getName().equals(obj.getName())) {
found = true;
}
}
if (!found) {
NamedObject namedObject = new UndeletableNamedObject(obj.getName());
addElement(namedObject);
// Keep track of objects that are only in the model and not in the build file. We want to avoid creating them in the build file
// unless some value in them is changed to non-default.
myModelOnlyObjects.add(namedObject);
}
myModelObjects.put(obj.getName(), obj.getValues());
}
myList.updateUI();
myDetailsPane.init(myGradleBuildFile, properties);
if (myListModel.getSize() > 0) {
myList.setSelectedIndex(0);
}
updateUiFromCurrentObject();
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
updatePanelGroup();
}
}, ModalityState.any());
}
use of com.android.tools.idea.gradle.parser.NamedObject in project android by JetBrains.
the class NamedObjectPanel method addObject.
private void addObject() {
int num = 1;
String name = myNewItemName;
while (getNamedItem(name) != null) {
name = myNewItemName + num++;
}
int index = addElement(new NamedObject(name));
// Select newly added element.
myList.getSelectionModel().setSelectionInterval(index, index);
updateUiFromCurrentObject();
// Make sure we scroll to selected element
myList.ensureIndexIsVisible(index);
myList.updateUI();
myModified = true;
updatePanelGroup();
}
use of com.android.tools.idea.gradle.parser.NamedObject in project android by JetBrains.
the class NamedObjectPanel method apply.
@Override
public void apply() {
if ((!myModified && myModifiedKeys.isEmpty()) || myGradleBuildFile == null) {
return;
}
List<NamedObject> objects = Lists.newArrayList();
for (NamedObject obj : myListModel) {
// Save the defaultConfig separately and don't write it out as a regular flavor.
if (myBuildFileKey == BuildFileKey.FLAVORS && obj.getName().equals(DEFAULT_CONFIG)) {
GrStatementOwner defaultConfig = myGradleBuildFile.getClosure(BuildFileKey.DEFAULT_CONFIG.getPath());
if (defaultConfig == null) {
myGradleBuildFile.setValue(BuildFileKey.DEFAULT_CONFIG, "{}");
defaultConfig = myGradleBuildFile.getClosure(BuildFileKey.DEFAULT_CONFIG.getPath());
}
assert defaultConfig != null;
for (BuildFileKey key : DEFAULT_CONFIG_KEYS) {
if (!isModified(obj, key)) {
continue;
}
Object value = obj.getValue(key);
if (value != null) {
myGradleBuildFile.setValue(defaultConfig, key, value);
} else {
myGradleBuildFile.removeValue(defaultConfig, key);
}
}
} else if (myModelOnlyObjects.contains(obj) && isObjectEmpty(obj)) {
// If this object wasn't in the build file to begin with and doesn't have non-default values, don't write it out.
continue;
} else {
objects.add(obj);
}
}
myGradleBuildFile.setValue(myBuildFileKey, objects, new ValueFactory.KeyFilter() {
@Override
public boolean shouldWriteKey(BuildFileKey key, Object object) {
return isModified((NamedObject) object, key);
}
});
myModified = false;
myModifiedKeys.clear();
}
Aggregations