use of com.android.tools.idea.gradle.parser.BuildFileKeyType in project android by JetBrains.
the class KeyValuePane method updateCurrentObjectFromUi.
/**
* Reads the state of the UI form objects and writes them into the currently selected object in the list, setting the dirty bit as
* appropriate.
*/
private void updateCurrentObjectFromUi() {
if (myIsUpdating || myCurrentBuildFileObject == null) {
return;
}
for (Map.Entry<BuildFileKey, JComponent> entry : myProperties.entrySet()) {
BuildFileKey key = entry.getKey();
JComponent component = entry.getValue();
Object currentValue = myCurrentBuildFileObject.get(key);
Object newValue;
BuildFileKeyType type = key.getType();
switch(type) {
case BOOLEAN:
{
ComboBox comboBox = (ComboBox) component;
JBTextField editorComponent = (JBTextField) comboBox.getEditor().getEditorComponent();
int index = comboBox.getSelectedIndex();
if (index == 2) {
newValue = Boolean.FALSE;
editorComponent.setForeground(JBColor.BLACK);
} else if (index == 1) {
newValue = Boolean.TRUE;
editorComponent.setForeground(JBColor.BLACK);
} else {
newValue = null;
editorComponent.setForeground(JBColor.GRAY);
}
break;
}
case FILE:
case FILE_AS_STRING:
{
newValue = ((TextFieldWithBrowseButton) component).getText();
if ("".equals(newValue)) {
newValue = null;
}
if (newValue != null) {
newValue = new File(newValue.toString());
}
break;
}
case INTEGER:
{
try {
if (hasKnownValues(key)) {
String newStringValue = ((ComboBox) component).getEditor().getItem().toString();
newStringValue = getMappedValue(myKeysWithKnownValues.get(key).inverse(), newStringValue);
newValue = Integer.valueOf(newStringValue);
} else {
newValue = Integer.valueOf(((JBTextField) component).getText());
}
} catch (Exception e) {
newValue = null;
}
break;
}
case REFERENCE:
{
newValue = ((ComboBox) component).getEditor().getItem();
String newStringValue = (String) newValue;
if (hasKnownValues(key)) {
newStringValue = getMappedValue(myKeysWithKnownValues.get(key).inverse(), newStringValue);
}
if (newStringValue != null && newStringValue.isEmpty()) {
newStringValue = null;
}
String prefix = getReferencePrefix(key);
if (newStringValue != null && !newStringValue.startsWith(prefix)) {
newStringValue = prefix + newStringValue;
}
newValue = newStringValue;
break;
}
case CLOSURE:
case STRING:
default:
{
if (hasKnownValues(key)) {
String newStringValue = ((ComboBox) component).getEditor().getItem().toString();
newStringValue = getMappedValue(myKeysWithKnownValues.get(key).inverse(), newStringValue);
if (newStringValue.isEmpty()) {
newStringValue = null;
}
newValue = newStringValue;
} else {
newValue = ((JBTextField) component).getText();
if ("".equals(newValue)) {
newValue = null;
}
}
if (type == BuildFileKeyType.CLOSURE && newValue != null) {
List newListValue = new ArrayList();
for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split((String) newValue)) {
newListValue.add(key.getValueFactory().parse(s, myProject));
}
newValue = newListValue;
}
break;
}
}
if (!Objects.equal(currentValue, newValue)) {
if (newValue == null) {
myCurrentBuildFileObject.remove(key);
} else {
myCurrentBuildFileObject.put(key, newValue);
}
if (GradleBuildFile.shouldWriteValue(currentValue, newValue)) {
myListener.modified(key);
}
}
}
}
Aggregations