use of com.android.tools.idea.ui.ApiComboBoxItem in project android by JetBrains.
the class IconStep method updateDirectoryCombo.
private void updateDirectoryCombo() {
final boolean showLabelAndCombo;
List<File> folders = getResourceFolders();
File res = myState.get(ATTR_OUTPUT_FOLDER);
if (!folders.isEmpty()) {
if (res == null || !folders.contains(res)) {
res = folders.get(0);
myState.put(ATTR_OUTPUT_FOLDER, res);
}
showLabelAndCombo = folders.size() > 1;
mySourceSetComboBox.removeAllItems();
if (showLabelAndCombo) {
ApiComboBoxItem selected = null;
for (File directory : folders) {
ApiComboBoxItem item = new ApiComboBoxItem(directory, getResourceDirLabel(getModule(), directory), 0, 0);
if (Objects.equal(directory, res)) {
selected = item;
}
mySourceSetComboBox.addItem(item);
}
mySourceSetComboBox.setSelectedItem(selected);
}
} else {
showLabelAndCombo = false;
}
mySourceSetComboBox.setVisible(showLabelAndCombo);
mySourceSetLabel.setVisible(showLabelAndCombo);
}
use of com.android.tools.idea.ui.ApiComboBoxItem in project android by JetBrains.
the class TemplateParameterStep2 method validate.
@Override
public boolean validate() {
setErrorHtml(null);
AndroidVersion minApi = myState.get(AddAndroidActivityPath.KEY_MIN_SDK);
Integer buildApi = myState.get(AddAndroidActivityPath.KEY_BUILD_SDK);
TemplateEntry templateEntry = myState.get(AddAndroidActivityPath.KEY_SELECTED_TEMPLATE);
if (templateEntry == null) {
return false;
}
for (Parameter param : templateEntry.getParameters()) {
if (param != null) {
Object value = getStateParameterValue(param);
String error = param.validate(getProject(), getModule(), myState.get(AddAndroidActivityPath.KEY_SOURCE_PROVIDER), myState.get(myPackageNameKey), value != null ? value : "", getRelatedValues(param));
if (error != null) {
// Highlight?
setErrorHtml(error);
return false;
}
// Check to see that the selection's constraints are met if this is a combo box
if (value instanceof ApiComboBoxItem) {
ApiComboBoxItem selectedItem = (ApiComboBoxItem) value;
if (minApi == null || buildApi == null) {
return false;
}
String message = selectedItem.validate(minApi.getFeatureLevel(), buildApi);
if (message != null) {
setErrorHtml(message);
return false;
}
}
}
}
return true;
}
use of com.android.tools.idea.ui.ApiComboBoxItem in project android by JetBrains.
the class TemplateParameterStep2 method createEnumCombo.
private static JComponent createEnumCombo(Parameter parameter) {
List<Element> options = parameter.getOptions();
ApiComboBoxItem[] items = new ApiComboBoxItem[options.size()];
int initialSelection = -1;
int i = 0;
assert !options.isEmpty();
for (Element option : options) {
//noinspection unchecked
items[i++] = createItemForOption(parameter, option);
String isDefault = option.getAttribute(Template.ATTR_DEFAULT);
if (isDefault != null && !isDefault.isEmpty() && Boolean.valueOf(isDefault)) {
initialSelection = i - 1;
}
}
@SuppressWarnings("UndesirableClassUsage") JComboBox comboBox = new JComboBox(items);
comboBox.setSelectedIndex(initialSelection);
return comboBox;
}
use of com.android.tools.idea.ui.ApiComboBoxItem in project android by JetBrains.
the class TemplateParameterStep2 method addSourceSetControls.
private void addSourceSetControls(int row) {
if (mySourceProviders.length > 1) {
if (mySourceSetLabel == null) {
mySourceSetLabel = new JLabel("Target Source Set:");
//noinspection UndesirableClassUsage
mySourceSet = new JComboBox();
register(AddAndroidActivityPath.KEY_SOURCE_PROVIDER, mySourceSet);
setControlDescription(mySourceSet, "The selected folder contains multiple source sets, " + "this can include source sets that do not yet exist on disk. " + "Please select the target source set in which to create the files.");
}
mySourceSet.removeAllItems();
for (SourceProvider sourceProvider : mySourceProviders) {
//noinspection unchecked
mySourceSet.addItem(new ApiComboBoxItem(sourceProvider, sourceProvider.getName(), 0, 0));
}
addComponent(myTemplateParameters, mySourceSetLabel, row, 0, false);
addComponent(myTemplateParameters, mySourceSet, row, 1, true);
}
}
use of com.android.tools.idea.ui.ApiComboBoxItem in project android by JetBrains.
the class TemplateWizardStep method refreshUiFromParameters.
public void refreshUiFromParameters() {
if (myTemplateState.myTemplate == null) {
return;
}
for (Parameter param : myTemplateState.myTemplate.getMetadata().getParameters()) {
if (param.initial != null && !myTemplateState.myModified.contains(param.id)) {
myTemplateState.myParameters.remove(param.id);
}
}
myTemplateState.setParameterDefaults();
Template.convertApisToInt(myTemplateState.getParameters());
boolean oldIgnoreUpdates = myIgnoreUpdates;
try {
myIgnoreUpdates = true;
for (String paramName : myParamFields.keySet()) {
if (myTemplateState.myHidden.contains(paramName)) {
continue;
}
JComponent component = myParamFields.get(paramName);
Object value = myTemplateState.get(paramName);
if (value == null) {
continue;
}
if (component instanceof JCheckBox) {
((JCheckBox) component).setSelected(Boolean.parseBoolean(value.toString()));
} else if (component instanceof JComboBox) {
for (int i = 0; i < ((JComboBox) component).getItemCount(); i++) {
if (((ApiComboBoxItem) ((JComboBox) component).getItemAt(i)).getData().equals(value)) {
((JComboBox) component).setSelectedIndex(i);
break;
}
}
} else if (component instanceof JTextField) {
((JTextField) component).setText(value.toString());
} else if (component instanceof TextFieldWithBrowseButton) {
((TextFieldWithBrowseButton) component).setText(value.toString());
} else if (component instanceof JSlider) {
((JSlider) component).setValue(Integer.parseInt(value.toString()));
} else if (component instanceof JSpinner) {
((JSpinner) component).setValue(Integer.parseInt(value.toString()));
} else if (component instanceof ColorPanel) {
((ColorPanel) component).setSelectedColor((Color) value);
}
}
} finally {
myIgnoreUpdates = oldIgnoreUpdates;
}
}
Aggregations