Automated import from //branches/cupcake/...@142852,142852

This commit is contained in:
Raphael Moll
2009-03-25 21:11:59 -07:00
committed by The Android Open Source Project
parent c22f78e238
commit 4ec2d6f603
2 changed files with 85 additions and 12 deletions

View File

@@ -22,7 +22,9 @@
package com.android.ide.eclipse.adt.wizards.newproject;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.sdk.Sdk;
import com.android.ide.eclipse.adt.sdk.Sdk.ITargetChangeListener;
import com.android.ide.eclipse.common.AndroidConstants;
import com.android.ide.eclipse.common.project.AndroidManifestParser;
import com.android.sdklib.IAndroidTarget;
@@ -122,6 +124,7 @@ public class NewProjectCreationPage extends WizardPage {
private Button mCreateActivityCheck;
private Text mMinSdkVersionField;
private SdkTargetSelector mSdkTargetSelector;
private ITargetChangeListener mSdkTargetChangeListener;
private boolean mInternalLocationPathUpdate;
protected boolean mInternalProjectNameUpdate;
@@ -264,6 +267,17 @@ public class NewProjectCreationPage extends WizardPage {
setPageComplete(validatePage());
}
@Override
public void dispose() {
if (mSdkTargetChangeListener != null) {
AdtPlugin.getDefault().removeTargetListener(mSdkTargetChangeListener);
mSdkTargetChangeListener = null;
}
super.dispose();
}
/**
* Creates the group for the project name:
* [label: "Project Name"] [text field]
@@ -389,18 +403,35 @@ public class NewProjectCreationPage extends WizardPage {
group.setFont(parent.getFont());
group.setText("Target");
// The selector is created without targets. They are added below in the change listener.
mSdkTargetSelector = new SdkTargetSelector(group, null, false /*multi-selection*/);
mSdkTargetChangeListener = new ITargetChangeListener() {
public void onProjectTargetChange(IProject changedProject) {
// Ignore
}
public void onTargetsLoaded() {
// Update the sdk target selector with the new targets
// get the targets from the sdk
IAndroidTarget[] targets = null;
if (Sdk.getCurrent() != null) {
targets = Sdk.getCurrent().getTargets();
}
mSdkTargetSelector = new SdkTargetSelector(group, targets, false /*multi-selection*/);
mSdkTargetSelector.setTargets(targets);
// If there's only one target, select it
if (targets != null && targets.length == 1) {
mSdkTargetSelector.setSelection(targets[0]);
}
}
};
AdtPlugin.getDefault().addTargetListener(mSdkTargetChangeListener);
// Invoke it once to initialize the targets
mSdkTargetChangeListener.onTargetsLoaded();
mSdkTargetSelector.setSelectionListener(new SelectionAdapter() {
@Override

View File

@@ -20,6 +20,7 @@ package com.android.ide.eclipse.editors.wizards;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.sdk.AndroidTargetData;
import com.android.ide.eclipse.adt.sdk.Sdk;
import com.android.ide.eclipse.adt.sdk.Sdk.ITargetChangeListener;
import com.android.ide.eclipse.common.AndroidConstants;
import com.android.ide.eclipse.common.project.ProjectChooserHelper;
import com.android.ide.eclipse.editors.descriptors.DocumentDescriptor;
@@ -237,7 +238,7 @@ class NewXmlFileCreationPage extends WizardPage {
"An XML file that describes preferences.", // tooltip
ResourceFolderType.XML, // folder type
AndroidTargetData.DESCRIPTOR_PREFERENCES, // root seed
AndroidConstants.CLASS_PREFERENCE_SCREEN, // default root
AndroidConstants.CLASS_NAME_PREFERENCE_SCREEN, // default root
SdkConstants.NS_RESOURCES, // xmlns
null, // default attributes
1 // target API level
@@ -290,7 +291,9 @@ class NewXmlFileCreationPage extends WizardPage {
private boolean mInternalTypeUpdate;
private boolean mInternalConfigSelectorUpdate;
private ProjectChooserHelper mProjectChooserHelper;
private ITargetChangeListener mSdkTargetChangeListener;
private TypeInfo mCurrentTypeInfo;
// --- UI creation ---
@@ -337,9 +340,44 @@ class NewXmlFileCreationPage extends WizardPage {
initializeFromSelection(mInitialSelection);
initializeRootValues();
enableTypesBasedOnApi();
if (mCurrentTypeInfo != null) {
updateRootCombo(mCurrentTypeInfo);
}
installTargetChangeListener();
validatePage();
}
private void installTargetChangeListener() {
mSdkTargetChangeListener = new ITargetChangeListener() {
public void onProjectTargetChange(IProject changedProject) {
// If this is the current project, force it to reload its data
if (changedProject != null && changedProject == mProject) {
changeProject(mProject);
}
}
public void onTargetsLoaded() {
// Reload the current project, if any, in case its target has changed.
if (mProject != null) {
changeProject(mProject);
}
}
};
AdtPlugin.getDefault().addTargetListener(mSdkTargetChangeListener);
}
@Override
public void dispose() {
if (mSdkTargetChangeListener != null) {
AdtPlugin.getDefault().removeTargetListener(mSdkTargetChangeListener);
mSdkTargetChangeListener = null;
}
super.dispose();
}
/**
* Returns the target project or null.
*/
@@ -652,7 +690,6 @@ class NewXmlFileCreationPage extends WizardPage {
return;
}
// Find the best match in the element list. In case there are multiple selected elements
// select the one that provides the most information and assign them a score,
// e.g. project=1 + folder=2 + file=4.
@@ -848,6 +885,10 @@ class NewXmlFileCreationPage extends WizardPage {
/**
* Changes mProject to the given new project and update the UI accordingly.
* <p/>
* Note that this does not check if the new project is the same as the current one
* on purpose, which allows a project to be updated when its target has changed or
* when targets are loaded in the background.
*/
private void changeProject(IProject newProject) {
mProject = newProject;
@@ -1067,6 +1108,7 @@ class NewXmlFileCreationPage extends WizardPage {
private void selectType(TypeInfo type) {
if (type == null || !type.getWidget().getSelection()) {
mInternalTypeUpdate = true;
mCurrentTypeInfo = type;
for (TypeInfo type2 : sTypes) {
type2.getWidget().setSelection(type2 == type);
}