/** * Validates the fields, displays errors and warnings. Enables the finish button if there are no * errors. */ private void validatePage() { String error = null; String warning = null; // -- validate type TypeInfo type = mValues.type; if (error == null) { if (type == null) { error = "One of the types must be selected (e.g. layout, values, etc.)"; } } // -- validate project if (mValues.project == null) { error = "Please select an Android project."; } // -- validate type API level if (error == null) { IAndroidTarget target = Sdk.getCurrent().getTarget(mValues.project); int currentApiLevel = 1; if (target != null) { currentApiLevel = target.getVersion().getApiLevel(); } assert type != null; if (type.getTargetApiLevel() > currentApiLevel) { error = "The API level of the selected type (e.g. AppWidget, etc.) is not " + "compatible with the API level of the project."; } } // -- validate filename if (error == null) { String fileName = mValues.getFileName(); assert type != null; ResourceFolderType folderType = type.getResFolderType(); error = ResourceNameValidator.create(true, folderType).isValid(fileName); } // -- validate destination file doesn't exist if (error == null) { IFile file = mValues.getDestinationFile(); if (file != null && file.exists()) { warning = "The destination file already exists"; } } // -- update UI & enable finish if there's no error setPageComplete(error == null); if (error != null) { setMessage(error, IMessageProvider.ERROR); } else if (warning != null) { setMessage(warning, IMessageProvider.WARNING); } else { setErrorMessage(null); setMessage(null); } }
/** * Add the available types in the type combobox, based on whether they are available for the * current SDK. * * <p>A type is available either if: - if mProject is null, API level 1 is considered valid - if * mProject is !null, the project->target->API must be >= to the type's API level. */ private void updateAvailableTypes() { IProject project = mValues.project; IAndroidTarget target = project != null ? Sdk.getCurrent().getTarget(project) : null; int currentApiLevel = 1; if (target != null) { currentApiLevel = target.getVersion().getApiLevel(); } List<String> items = new ArrayList<String>(sTypes.length); List<TypeInfo> types = new ArrayList<TypeInfo>(sTypes.length); for (int i = 0, n = sTypes.length; i < n; i++) { TypeInfo type = sTypes[i]; if (type.getTargetApiLevel() <= currentApiLevel) { items.add(type.getUiName()); types.add(type); } } mTypeCombo.setItems(items.toArray(new String[items.size()])); mTypeCombo.setData(types.toArray(new TypeInfo[types.size()])); }