diff options
author | Tor Norbye <tnorbye@google.com> | 2012-06-15 09:34:57 -0700 |
---|---|---|
committer | android code review <noreply-gerritcodereview@google.com> | 2012-06-15 09:34:58 -0700 |
commit | d2e6f894cfe4df9ab8fdfb44114b245115e58645 (patch) | |
tree | b4d2bbc3f1ae7bad02772ff8ae2ffba4f8e46bc7 | |
parent | 8f15cf21cb1ef9ef528ca367918096e249bba605 (diff) | |
parent | 7f10682cf646bcb3e761fbb6bcb2f645bd748c03 (diff) | |
download | sdk-d2e6f894cfe4df9ab8fdfb44114b245115e58645.zip sdk-d2e6f894cfe4df9ab8fdfb44114b245115e58645.tar.gz sdk-d2e6f894cfe4df9ab8fdfb44114b245115e58645.tar.bz2 |
Merge "Add format handling to the template wizards"
9 files changed, 97 insertions, 31 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/ActivityPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/ActivityPage.java index d9f650c..1cd0739 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/ActivityPage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/ActivityPage.java @@ -210,11 +210,11 @@ class ActivityPage extends WizardPage implements SelectionListener { private void validatePage() { IStatus status = null; - if (status == null || status.getSeverity() != IStatus.ERROR) { - if (mList.getSelectionCount() < 1) { - status = new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, - "Select an activity type"); - } + if (mList.getSelectionCount() < 1) { + status = new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, + "Select an activity type"); + } else { + status = mValues.activityValues.getTemplateHandler().validateTemplate(); } setPageComplete(status == null || status.getSeverity() != IStatus.ERROR); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java index b6993c7..3ba3939 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java @@ -538,33 +538,42 @@ public class NewProjectPage extends WizardPage // Validation private void validatePage() { - IStatus appStatus = validateAppName(); - - IStatus status = appStatus; + IStatus status = mValues.template.validateTemplate(); + if (status != null && !status.isOK()) { + updateDecorator(mApplicationDec, null, true); + updateDecorator(mPackageDec, null, true); + updateDecorator(mProjectDec, null, true); + } else { + IStatus appStatus = validateAppName(); + if (appStatus != null && (status == null + || appStatus.getSeverity() > status.getSeverity())) { + status = appStatus; + } - IStatus projectStatus = validateProjectName(); - if (projectStatus != null && (status == null - || projectStatus.getSeverity() > status.getSeverity())) { - status = projectStatus; - } + IStatus projectStatus = validateProjectName(); + if (projectStatus != null && (status == null + || projectStatus.getSeverity() > status.getSeverity())) { + status = projectStatus; + } - IStatus packageStatus = validatePackageName(); - if (packageStatus != null && (status == null - || packageStatus.getSeverity() > status.getSeverity())) { - status = packageStatus; - } + IStatus packageStatus = validatePackageName(); + if (packageStatus != null && (status == null + || packageStatus.getSeverity() > status.getSeverity())) { + status = packageStatus; + } - if (status == null || status.getSeverity() != IStatus.ERROR) { - if (mValues.target == null) { - status = new Status(IStatus.WARNING, AdtPlugin.PLUGIN_ID, - "Select an Android build target version"); + if (status == null || status.getSeverity() != IStatus.ERROR) { + if (mValues.target == null) { + status = new Status(IStatus.WARNING, AdtPlugin.PLUGIN_ID, + "Select an Android build target version"); + } } - } - if (status == null || status.getSeverity() != IStatus.ERROR) { - if (mValues.minSdk == null || mValues.minSdk.isEmpty()) { - status = new Status(IStatus.WARNING, AdtPlugin.PLUGIN_ID, - "Select a minimum SDK version"); + if (status == null || status.getSeverity() != IStatus.ERROR) { + if (mValues.minSdk == null || mValues.minSdk.isEmpty()) { + status = new Status(IStatus.WARNING, AdtPlugin.PLUGIN_ID, + "Select a minimum SDK version"); + } } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplatePage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplatePage.java index eece39b..1e443bc 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplatePage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplatePage.java @@ -492,7 +492,7 @@ public class NewTemplatePage extends WizardPage // ---- Validation ---- private void validatePage() { - IStatus status = null; + IStatus status = mValues.getTemplateHandler().validateTemplate(); // -- validate project if (mChooseProject && mValues.project == null) { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateHandler.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateHandler.java index ee6115f..1532228 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateHandler.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateHandler.java @@ -43,9 +43,13 @@ import freemarker.template.DefaultObjectWrapper; import freemarker.template.Template; import freemarker.template.TemplateException; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; +import org.osgi.framework.Constants; +import org.osgi.framework.Version; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -78,6 +82,9 @@ import lombok.ast.libs.org.parboiled.google.collect.Lists; * and merging into existing files */ class TemplateHandler { + /** Highest supported format; templates with a higher number will be skipped */ + static final int CURRENT_FORMAT = 1; + /** * Special marker indicating that this path refers to the special shared * resource directory rather than being somewhere inside the root/ directory @@ -113,6 +120,9 @@ class TemplateHandler { static final String TAG_OPEN = "open"; //$NON-NLS-1$ static final String TAG_THUMB = "thumb"; //$NON-NLS-1$ static final String TAG_THUMBS = "thumbs"; //$NON-NLS-1$ + static final String TAG_DEPENDENCY = "dependency"; //$NON-NLS-1$ + static final String ATTR_FORMAT = "format"; //$NON-NLS-1$ + static final String ATTR_REVISION = "revision"; //$NON-NLS-1$ static final String ATTR_VALUE = "value"; //$NON-NLS-1$ static final String ATTR_DEFAULT = "default"; //$NON-NLS-1$ static final String ATTR_SUGGEST = "suggest"; //$NON-NLS-1$ @@ -936,7 +946,8 @@ class TemplateHandler { } } - /** Returns all the templates with the given prefix + /** + * Returns all the templates with the given prefix * * @param folder the folder prefix * @return the available templates @@ -967,4 +978,26 @@ class TemplateHandler { return templates; } + + /** + * Validates this template to make sure it's supported + * + * @return a status object with the error, or null if there is no problem + */ + @SuppressWarnings("cast") // In Eclipse 3.6.2 cast below is needed + @Nullable + public IStatus validateTemplate() { + TemplateMetadata template = getTemplate(); + if (template != null && !template.isSupported()) { + String versionString = (String) AdtPlugin.getDefault().getBundle().getHeaders().get( + Constants.BUNDLE_VERSION); + Version version = new Version(versionString); + return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, + String.format("This template requires a more recent version of the " + + "Android Eclipse plugin. Please update from version %1$d.%2$d.%3$d.", + version.getMajor(), version.getMinor(), version.getMicro())); + } + + return null; + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateMetadata.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateMetadata.java index eac818a..db0f8ce 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateMetadata.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateMetadata.java @@ -16,6 +16,7 @@ package com.android.ide.eclipse.adt.internal.wizards.templates; import static com.android.ide.eclipse.adt.internal.wizards.templates.TemplateHandler.ATTR_DESCRIPTION; +import static com.android.ide.eclipse.adt.internal.wizards.templates.TemplateHandler.ATTR_FORMAT; import static com.android.ide.eclipse.adt.internal.wizards.templates.TemplateHandler.ATTR_NAME; import static com.android.ide.eclipse.adt.internal.wizards.templates.TemplateHandler.TAG_PARAMETER; import static com.android.ide.eclipse.adt.internal.wizards.templates.TemplateHandler.TAG_THUMB; @@ -58,6 +59,21 @@ class TemplateMetadata { } } + public boolean isSupported() { + String versionString = mDocument.getDocumentElement().getAttribute(ATTR_FORMAT); + if (versionString != null && !versionString.isEmpty()) { + try { + int version = Integer.parseInt(versionString); + return version <= TemplateHandler.CURRENT_FORMAT; + } catch (NumberFormatException nufe) { + return false; + } + } + + // Older templates without version specified: supported + return true; + } + @Nullable String getTitle() { String name = mDocument.getDocumentElement().getAttribute(ATTR_NAME); diff --git a/templates/activities/BlankActivity/template.xml b/templates/activities/BlankActivity/template.xml index f7fa903..997051e 100644 --- a/templates/activities/BlankActivity/template.xml +++ b/templates/activities/BlankActivity/template.xml @@ -1,5 +1,7 @@ <?xml version="1.0"?> <template + format="1" + revision="1" name="New Blank Activity" description="Creates a new blank activity, with optional inner navigation."> diff --git a/templates/activities/MasterDetailFlow/template.xml b/templates/activities/MasterDetailFlow/template.xml index d67fb65..4f759cf 100644 --- a/templates/activities/MasterDetailFlow/template.xml +++ b/templates/activities/MasterDetailFlow/template.xml @@ -1,5 +1,7 @@ <?xml version="1.0"?> <template + format="1" + revision="1" name="New Master/Detail Flow" description="Creates a new master/detail flow, which is two columns on tablets, and one column on smaller screens. This creates a master fragment, detail fragment, and two activities."> @@ -51,4 +53,4 @@ <globals file="globals.xml.ftl" /> <execute file="recipe.xml.ftl" /> -</template>
\ No newline at end of file +</template> diff --git a/templates/other/CustomView/template.xml b/templates/other/CustomView/template.xml index 9511566..9bd6d98 100644 --- a/templates/other/CustomView/template.xml +++ b/templates/other/CustomView/template.xml @@ -1,5 +1,7 @@ <?xml version="1.0"?> <template + format="1" + revision="1" name="New Custom View" description="Creates a new custom view that extends android.view.View, and exposes custom attributes."> @@ -23,4 +25,4 @@ <globals file="globals.xml.ftl" /> <execute file="recipe.xml.ftl" /> -</template>
\ No newline at end of file +</template> diff --git a/templates/projects/NewAndroidApplication/template.xml b/templates/projects/NewAndroidApplication/template.xml index 84ba6c7..f0ee375 100644 --- a/templates/projects/NewAndroidApplication/template.xml +++ b/templates/projects/NewAndroidApplication/template.xml @@ -1,5 +1,7 @@ <?xml version="1.0"?> <template + format="1" + revision="1" name="New Android Application" description="Creates a new Android application with an activity."> |