use of com.android.tools.idea.ui.validation.Validator in project android by JetBrains.
the class ConfigureAvdOptionsStep method addValidators.
private void addValidators() {
myValidatorPanel.registerValidator(getModel().getAvdDeviceData().ramStorage(), new Validator<Storage>() {
@NotNull
@Override
public Result validate(@NotNull Storage ram) {
return (ram.getSizeAsUnit(Storage.Unit.MiB) < 128) ? new Result(Severity.ERROR, "RAM must be a numeric (integer) value of at least 128MB. Recommendation is 1GB.") : Result.OK;
}
});
myValidatorPanel.registerValidator(getModel().vmHeapStorage(), new Validator<Storage>() {
@NotNull
@Override
public Result validate(@NotNull Storage heap) {
return (heap.getSizeAsUnit(Storage.Unit.MiB) < 16) ? new Result(Severity.ERROR, "VM Heap must be a numeric (integer) value of at least 16MB.") : Result.OK;
}
});
myValidatorPanel.registerValidator(getModel().internalStorage(), new Validator<Storage>() {
@NotNull
@Override
public Result validate(@NotNull Storage heap) {
return (heap.getSizeAsUnit(Storage.Unit.MiB) < 200) ? new Result(Severity.ERROR, "Internal storage must be a numeric (integer) value of at least 200MB.") : Result.OK;
}
});
// If we're using an external SD card, make sure it exists
myValidatorPanel.registerValidator(getModel().externalSdCardLocation(), new Validator<String>() {
@NotNull
@Override
public Result validate(@NotNull String path) {
return (getModel().useExternalSdCard().get() && !new File(path).isFile()) ? new Result(Severity.ERROR, "The specified SD image file must be a valid image file") : Result.OK;
}
});
// If we are not lets make sure it has the right amount of memory
myValidatorPanel.registerValidator(getModel().sdCardStorage(), new Validator<Optional<Storage>>() {
@NotNull
@Override
public Result validate(@NotNull Optional<Storage> value) {
return (!getModel().useExternalSdCard().get() && getModel().sdCardStorage().get().isPresent() && getModel().sdCardStorage().getValue().getSizeAsUnit(Storage.Unit.MiB) < 10) ? new Result(Severity.ERROR, "The SD card must be larger than 10MB") : Result.OK;
}
});
myValidatorPanel.registerValidator(getModel().getAvdDeviceData().customSkinFile(), new Validator<Optional<File>>() {
@NotNull
@Override
public Result validate(@NotNull Optional<File> value) {
Result result = Result.OK;
if (value.isPresent() && !FileUtil.filesEqual(value.get(), AvdWizardUtils.NO_SKIN)) {
File layoutFile = new File(value.get(), SdkConstants.FN_SKIN_LAYOUT);
if (!layoutFile.isFile()) {
result = new Result(Severity.ERROR, "The skin directory does not point to a valid skin.");
}
}
return result;
}
});
myValidatorPanel.registerValidator(getModel().avdDisplayName(), new Validator<String>() {
@NotNull
@Override
public Result validate(@NotNull String value) {
value = value.trim();
Severity severity = Severity.OK;
String errorMessage = "";
if (value.isEmpty()) {
severity = Severity.ERROR;
errorMessage = "The AVD name cannot be empty.";
} else if (!AvdNameVerifier.isValid(value)) {
severity = Severity.ERROR;
errorMessage = "The AVD name can contain only the characters " + AvdNameVerifier.humanReadableAllowedCharacters();
} else if (!getModel().isInEditMode().get() && AvdManagerConnection.getDefaultAvdManagerConnection().findAvdWithName(value)) {
severity = Severity.ERROR;
errorMessage = String.format("An AVD with the name \"%1$s\" already exists.", getModel().avdDisplayName());
}
return new Result(severity, errorMessage);
}
});
myValidatorPanel.registerValidator(getModel().device().isPresent().and(getModel().systemImage().isPresent()), new Validator<Boolean>() {
@NotNull
@Override
public Result validate(@NotNull Boolean deviceAndImageArePresent) {
if (deviceAndImageArePresent) {
Optional<Device> device = getModel().device().get();
Optional<SystemImageDescription> systemImage = getModel().systemImage().get();
if (!ChooseSystemImagePanel.systemImageMatchesDevice(systemImage.get(), device.get())) {
return new Validator.Result(Validator.Severity.ERROR, "The selected system image is incompatible with the selected device.");
}
} else {
if (!getModel().device().get().isPresent()) {
return new Result(Severity.ERROR, "You must select a Device to create an AVD.");
} else if (!getModel().systemImage().get().isPresent()) {
return new Result(Severity.ERROR, "You must select a System Image to create an AVD.");
}
}
return Result.OK;
}
});
myValidatorPanel.registerValidator(getModel().getAvdDeviceData().compatibleSkinSize(), Validator.Severity.WARNING, "The selected skin is not large enough to view the entire screen.");
}
use of com.android.tools.idea.ui.validation.Validator in project android by JetBrains.
the class ConfigureTemplateParametersStep method onEntering.
@Override
protected void onEntering() {
// The Model TemplateHandle may have changed, rebuild the panel
resetPanel();
final TemplateHandle templateHandle = getModel().getTemplateHandle();
ApplicationManager.getApplication().invokeLater(() -> {
// We want to set the label's text AFTER the wizard has been packed. Otherwise, its
// width calculation gets involved and can really stretch out some wizards if the label is
// particularly long (see Master/Detail Activity for example).
myTemplateDescriptionLabel.setText(WizardUtils.toHtmlString(Strings.nullToEmpty(templateHandle.getMetadata().getDescription())));
}, ModalityState.any());
final IconProperty thumb = new IconProperty(myTemplateThumbLabel);
BoolProperty thumbVisibility = new VisibleProperty(myTemplateThumbLabel);
myBindings.bind(thumb, new Expression<Optional<Icon>>(myThumbPath) {
@NotNull
@Override
public Optional<Icon> get() {
return myThumbnailsCache.getUnchecked(new File(templateHandle.getRootPath(), myThumbPath.get()));
}
});
myBindings.bind(thumbVisibility, new Expression<Boolean>(thumb) {
@NotNull
@Override
public Boolean get() {
return thumb.get().isPresent();
}
});
myThumbPath.set(getDefaultThumbnailPath());
final TextProperty parameterDescription = new TextProperty(myParameterDescriptionLabel);
myBindings.bind(new VisibleProperty(myFooterSeparator), new Expression<Boolean>(parameterDescription) {
@NotNull
@Override
public Boolean get() {
return !parameterDescription.get().isEmpty();
}
});
Module module = myFacet == null ? null : myFacet.getModule();
final Collection<Parameter> parameters = templateHandle.getMetadata().getParameters();
for (final Parameter parameter : parameters) {
RowEntry row = createRowForParameter(module, parameter);
final ObservableValue<?> property = row.getProperty();
if (property != null) {
property.addListener(sender -> {
if (myEvaluationState != EvaluationState.EVALUATING) {
myUserValues.put(parameter, property.get());
enqueueEvaluateParameters();
}
});
final ActionGroup resetParameterGroup = new ActionGroup() {
@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
return new AnAction[] { new ResetParameterAction(parameter) };
}
};
row.getComponent().addMouseListener(new PopupHandler() {
@Override
public void invokePopup(Component comp, int x, int y) {
ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, resetParameterGroup).getComponent().show(comp, x, y);
}
});
}
myParameterRows.put(parameter, row);
row.addToPanel(myParametersPanel);
}
if (mySourceSets.size() > 1) {
RowEntry row = new RowEntry<>("Target Source Set", new SourceSetComboProvider(mySourceSets));
row.setEnabled(mySourceSets.size() > 1);
row.addToPanel(myParametersPanel);
//noinspection unchecked
SelectedItemProperty<AndroidSourceSet> sourceSet = (SelectedItemProperty<AndroidSourceSet>) row.getProperty();
// SourceSetComboProvider always sets this
assert sourceSet != null;
myBindings.bind(getModel().getSourceSet(), new OptionalToValuePropertyAdapter<>(sourceSet));
sourceSet.addListener(sender -> enqueueEvaluateParameters());
}
myValidatorPanel.registerValidator(myInvalidParameterMessage, message -> (message.isEmpty() ? Validator.Result.OK : new Validator.Result(Validator.Severity.ERROR, message)));
// TODO: This code won't be needed until we migrate this enough to support
// NewAndroidApplication/template.xml and NewAndroidLibrary/template.xml
// Add it in then. Probably we can add an optional validator API to ComponentProvider? Then we
// could move this code into EnumComboProvider and it won't be a hack anymore.
//
// if (value instanceof ApiComboBoxItem) {
// ApiComboBoxItem selectedItem = (ApiComboBoxItem)value;
//
// if (minApi != null && selectedItem.minApi > minApi.getFeatureLevel()) {
// setErrorHtml(String.format("The \"%s\" option for %s requires a minimum API level of %d",
// selectedItem.label, param.name, selectedItem.minApi));
// return false;
// }
// if (buildApi != null && selectedItem.minBuildApi > buildApi) {
// setErrorHtml(String.format("The \"%s\" option for %s requires a minimum API level of %d",
// selectedItem.label, param.name, selectedItem.minBuildApi));
// return false;
// }
//}
evaluateParameters();
}
Aggregations