use of com.android.tools.idea.ui.ApiComboBoxItem in project android by JetBrains.
the class TemplateWizardStep method validate.
@Override
public boolean validate() {
Template.convertApisToInt(myTemplateState.getParameters());
if (!myVisible) {
return true;
}
Integer minApi = (Integer) myTemplateState.get(ATTR_MIN_API_LEVEL);
Integer buildApi = (Integer) myTemplateState.get(ATTR_BUILD_API);
for (String paramName : myParamFields.keySet()) {
if (myTemplateState.myHidden.contains(paramName)) {
continue;
}
Parameter param = myTemplateState.hasTemplate() ? myTemplateState.getTemplateMetadata().getParameter(paramName) : null;
if (param != null) {
Set<Object> relatedValues = Sets.newHashSet();
for (Parameter related : myTemplateState.getTemplateMetadata().getRelatedParams(param)) {
relatedValues.add(myTemplateState.get(related.id));
}
String error = param.validate(myProject, myModule, myTemplateState.getSourceProvider(), (String) myTemplateState.get(ATTR_PACKAGE_NAME), myTemplateState.get(paramName), relatedValues);
if (error != null) {
setErrorHtml(error);
return false;
}
// Check to see that the selection's constraints are met if this is a combo box
if (myComboBoxValues.containsKey(param)) {
ApiComboBoxItem selectedItem = myComboBoxValues.get(param);
if (selectedItem == null) {
return false;
}
if (minApi == null || buildApi == null) {
return false;
}
String message = selectedItem.validate(minApi, 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 TemplateWizardStep method populateComboBox.
/**
* Takes a {@link JComboBox} instance and a {@Parameter} that represents an enumerated type and
* populates the combo box with all possible values of the enumerated type.
*/
protected static void populateComboBox(@NotNull JComboBox comboBox, @NotNull Parameter parameter) {
List<Element> options = parameter.getOptions();
assert !options.isEmpty();
for (int i = 0, n = options.size(); i < n; i++) {
Element option = options.get(i);
String optionId = option.getAttribute(ATTR_ID);
assert optionId != null && !optionId.isEmpty() : ATTR_ID;
NodeList childNodes = option.getChildNodes();
assert childNodes.getLength() == 1 && childNodes.item(0).getNodeType() == Node.TEXT_NODE;
String optionLabel = childNodes.item(0).getNodeValue().trim();
int minSdk = 1;
try {
minSdk = Integer.parseInt(option.getAttribute(TemplateMetadata.ATTR_MIN_API));
} catch (Exception e) {
}
int minBuildApi = 1;
try {
minBuildApi = Integer.parseInt(option.getAttribute(TemplateMetadata.ATTR_MIN_BUILD_API));
} catch (Exception e) {
}
comboBox.addItem(new ApiComboBoxItem(optionId, optionLabel, minSdk, minBuildApi));
String isDefault = option.getAttribute(ATTR_DEFAULT);
if (isDefault != null && !isDefault.isEmpty() && Boolean.valueOf(isDefault)) {
comboBox.setSelectedIndex(comboBox.getItemCount() - 1);
}
}
}
use of com.android.tools.idea.ui.ApiComboBoxItem in project android by JetBrains.
the class EnumComboProvider method createItemForOption.
/**
* Parse an enum option, which looks something like this:
*
* {@code
* <option id="choice_id" minApi="15" minBuildApi="17">Choice Description</option>
* }
*/
private static ApiComboBoxItem<String> createItemForOption(@NotNull Parameter parameter, @NotNull Element option) {
String optionId = option.getAttribute(SdkConstants.ATTR_ID);
assert optionId != null && !optionId.isEmpty() : SdkConstants.ATTR_ID;
NodeList childNodes = option.getChildNodes();
assert childNodes.getLength() == 1 && childNodes.item(0).getNodeType() == Node.TEXT_NODE;
String optionLabel = childNodes.item(0).getNodeValue().trim();
int minSdk = getIntegerOptionValue(option, TemplateMetadata.ATTR_MIN_API, parameter.name, 1);
int minBuildApi = getIntegerOptionValue(option, TemplateMetadata.ATTR_MIN_BUILD_API, parameter.name, 1);
return new ApiComboBoxItem<>(optionId, optionLabel, minSdk, minBuildApi);
}
use of com.android.tools.idea.ui.ApiComboBoxItem in project android by JetBrains.
the class TemplateParameterStep2 method createItemForOption.
public static ApiComboBoxItem createItemForOption(Parameter parameter, Element option) {
String optionId = option.getAttribute(SdkConstants.ATTR_ID);
assert optionId != null && !optionId.isEmpty() : SdkConstants.ATTR_ID;
NodeList childNodes = option.getChildNodes();
assert childNodes.getLength() == 1 && childNodes.item(0).getNodeType() == Node.TEXT_NODE;
String optionLabel = childNodes.item(0).getNodeValue().trim();
int minSdk = getIntegerOptionValue(option, TemplateMetadata.ATTR_MIN_API, parameter.name, 1);
int minBuildApi = getIntegerOptionValue(option, TemplateMetadata.ATTR_MIN_BUILD_API, parameter.name, 1);
return new ApiComboBoxItem(optionId, optionLabel, minSdk, minBuildApi);
}
use of com.android.tools.idea.ui.ApiComboBoxItem in project android by JetBrains.
the class CreateResourceDialogUtils method updateSourceSetCombo.
public static void updateSourceSetCombo(@NotNull JComponent label, @NotNull JComboBox combo, @Nullable AndroidFacet facet) {
// we're in here, so we default to always including the source set combo (if it's a Gradle project that is.)
if (facet != null && facet.requiresAndroidModel() && facet.getAndroidModel() != null) {
List<SourceProvider> providers = IdeaSourceProvider.getAllSourceProviders(facet);
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (SourceProvider sourceProvider : providers) {
//noinspection unchecked
model.addElement(new ApiComboBoxItem(sourceProvider, sourceProvider.getName(), 0, 0));
}
combo.setModel(model);
label.setVisible(true);
combo.setVisible(true);
} else {
label.setVisible(false);
combo.setVisible(false);
}
}
Aggregations