diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/META-INF/MANIFEST.MF b/tools/eclipse/plugins/com.android.ide.eclipse.adt/META-INF/MANIFEST.MF index cce59c256..406285a71 100644 --- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/META-INF/MANIFEST.MF +++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/META-INF/MANIFEST.MF @@ -84,7 +84,6 @@ Export-Package: com.android.ide.eclipse.adt;x-friends:="com.android.ide.eclipse. com.android.ide.eclipse.adt.internal.sdk;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.internal.ui;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.internal.wizards.actions;x-friends:="com.android.ide.eclipse.tests", - com.android.ide.eclipse.adt.internal.wizards.avdmanager;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.internal.wizards.export;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.internal.wizards.newproject;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.internal.wizards.newxmlfile;x-friends:="com.android.ide.eclipse.tests", diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/avdmanager/AvdManagerListPage.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/avdmanager/AvdManagerListPage.java deleted file mode 100755 index 5867f7e95..000000000 --- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/avdmanager/AvdManagerListPage.java +++ /dev/null @@ -1,572 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package com.android.ide.eclipse.adt.internal.wizards.avdmanager; - -import com.android.ide.eclipse.adt.AdtPlugin; -import com.android.ide.eclipse.adt.internal.sdk.Sdk; -import com.android.ide.eclipse.adt.internal.sdk.Sdk.ITargetChangeListener; -import com.android.prefs.AndroidLocation; -import com.android.prefs.AndroidLocation.AndroidLocationException; -import com.android.sdklib.IAndroidTarget; -import com.android.sdklib.ISdkLog; -import com.android.sdklib.internal.avd.AvdManager; -import com.android.sdklib.internal.avd.AvdManager.AvdInfo; -import com.android.sdkuilib.internal.widgets.AvdSelector; -import com.android.sdkuilib.internal.widgets.AvdSelector.DisplayMode; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.TreeMap; - -/** - * This is the single page of the {@link AvdManagerWizard} which provides the ability to display - * the AVDs and edit them quickly. - */ -class AvdManagerListPage extends WizardPage { - - private AvdSelector mAvdSelector; - private Button mRefreshButton; - private Text mCreateName; - private Combo mCreateTargetCombo; - private Text mCreateSdCard; - private Combo mCreateSkinCombo; - private Button mCreateForce; - private Button mCreateButton; - private HashSet mKnownAvdNames = new HashSet(); - private TreeMap mCurrentTargets = new TreeMap(); - private ITargetChangeListener mSdkTargetChangeListener; - - /** - * Constructs a new {@link AvdManagerListPage}. - *

- * Called by {@link AvdManagerWizard#createMainPage()}. - */ - protected AvdManagerListPage(String pageName) { - super(pageName); - setPageComplete(false); - } - - /** - * Called by the parent Wizard to create the UI for this Wizard Page. - * - * {@inheritDoc} - * - * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) - */ - public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - composite.setFont(parent.getFont()); - - initializeDialogUnits(parent); - - composite.setLayout(new GridLayout(1, false /*makeColumnsEqualWidth*/)); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - - createAvdGroup(composite); - createCreateGroup(composite); - registerSdkChangeListener(); - - // Show description the first time - setErrorMessage(null); - setMessage(null); - setControl(composite); - - // Update state the first time - reloadAvdList(); - reloadTargetCombo(); - validatePage(); - } - - private void registerSdkChangeListener() { - - mSdkTargetChangeListener = new ITargetChangeListener() { - public void onProjectTargetChange(IProject changedProject) { - // Ignore - } - - public void onTargetsLoaded() { - // Update the AVD list, since the SDK change will influence the "good" avd list - reloadAvdList(); - // Update the sdk target combo with the new targets - reloadTargetCombo(); - validatePage(); - } - }; - AdtPlugin.getDefault().addTargetListener(mSdkTargetChangeListener); - - } - - @Override - public void dispose() { - if (mSdkTargetChangeListener != null) { - AdtPlugin.getDefault().removeTargetListener(mSdkTargetChangeListener); - mSdkTargetChangeListener = null; - } - - super.dispose(); - } - - // --- UI creation --- - - /** - * Creates the AVD selector and refresh & delete buttons. - */ - private void createAvdGroup(Composite parent) { - final Composite grid2 = new Composite(parent, SWT.NONE); - grid2.setLayout(new GridLayout(2, false /*makeColumnsEqualWidth*/)); - grid2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Label label = new Label(grid2, SWT.NONE); - label.setText("List of existing Android Virtual Devices:"); - label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false)); - - mRefreshButton = new Button(grid2, SWT.PUSH); - mRefreshButton.setText("Refresh"); - mRefreshButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); - mRefreshButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - reloadAvdList(); - } - }); - - mAvdSelector = new AvdSelector(parent, getAvdManager(), DisplayMode.MANAGER); - } - - /** - * Creates the "Create" group - */ - private void createCreateGroup(Composite parent) { - - Group grid = new Group(parent, SWT.SHADOW_ETCHED_IN); - grid.setLayout(new GridLayout(4, false /*makeColumnsEqualWidth*/)); - grid.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - grid.setFont(parent.getFont()); - grid.setText("Create AVD"); - - // first line - - Label label = new Label(grid, SWT.NONE); - label.setText("Name"); - - mCreateName = new Text(grid, SWT.BORDER); - mCreateName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - mCreateName.addModifyListener(new CreateNameModifyListener()); - - label = new Label(grid, SWT.NONE); - label.setText("Target"); - - mCreateTargetCombo = new Combo(grid, SWT.READ_ONLY | SWT.DROP_DOWN); - mCreateTargetCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - mCreateTargetCombo.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - super.widgetSelected(e); - reloadSkinCombo(); - validatePage(); - } - }); - - // second line - - label = new Label(grid, SWT.NONE); - label.setText("SDCard"); - - ValidateListener validateListener = new ValidateListener(); - - mCreateSdCard = new Text(grid, SWT.BORDER); - mCreateSdCard.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - mCreateSdCard.addModifyListener(validateListener); - - label = new Label(grid, SWT.NONE); - label.setText("Skin"); - - mCreateSkinCombo = new Combo(grid, SWT.READ_ONLY | SWT.DROP_DOWN); - mCreateSkinCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - // dummies for alignment - label = new Label(grid, SWT.NONE); - label = new Label(grid, SWT.NONE); - - mCreateForce = new Button(grid, SWT.CHECK); - mCreateForce.setText("Force"); - mCreateForce.setEnabled(false); - mCreateForce.addSelectionListener(validateListener); - - mCreateButton = new Button(grid, SWT.PUSH); - mCreateButton.setText("Create AVD"); - mCreateButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); - mCreateButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - super.widgetSelected(e); - onCreate(); - } - }); - } - - /** - * Callback when the AVD name is changed. - * Enables the force checkbox if the name is a duplicate. - */ - private class CreateNameModifyListener implements ModifyListener { - - public void modifyText(ModifyEvent e) { - String name = mCreateName.getText().trim(); - if (mKnownAvdNames.contains(name)) { - mCreateForce.setEnabled(true); - } else { - mCreateForce.setEnabled(false); - mCreateForce.setSelection(false); - } - validatePage(); - } - } - - private class ValidateListener extends SelectionAdapter implements ModifyListener { - - public void modifyText(ModifyEvent e) { - validatePage(); - } - - @Override - public void widgetSelected(SelectionEvent e) { - super.widgetSelected(e); - validatePage(); - } - } - - private void reloadTargetCombo() { - - String selected = null; - int index = mCreateTargetCombo.getSelectionIndex(); - if (index >= 0) { - selected = mCreateTargetCombo.getItem(index); - } - - mCurrentTargets.clear(); - mCreateTargetCombo.removeAll(); - - boolean found = false; - index = -1; - - Sdk sdk = Sdk.getCurrent(); - if (sdk != null) { - for (IAndroidTarget target : sdk.getTargets()) { - String name = String.format("%s - %s", - target.getName(), - target.getApiVersionName()); - mCurrentTargets.put(name, target); - mCreateTargetCombo.add(name); - if (!found) { - index++; - found = name.equals(selected); - } - } - } - - mCreateTargetCombo.setEnabled(mCurrentTargets.size() > 0); - - if (found) { - mCreateTargetCombo.select(index); - } - - reloadSkinCombo(); - } - - private void reloadSkinCombo() { - String selected = null; - int index = mCreateSkinCombo.getSelectionIndex(); - if (index >= 0) { - selected = mCreateSkinCombo.getItem(index); - } - - mCreateSkinCombo.removeAll(); - mCreateSkinCombo.setEnabled(false); - - index = mCreateTargetCombo.getSelectionIndex(); - if (index >= 0) { - - String targetName = mCreateTargetCombo.getItem(index); - - boolean found = false; - IAndroidTarget target = mCurrentTargets.get(targetName); - if (target != null) { - mCreateSkinCombo.add(String.format("Default (%s)", target.getDefaultSkin())); - - index = -1; - for (String skin : target.getSkins()) { - mCreateSkinCombo.add(skin); - if (!found) { - index++; - found = skin.equals(selected); - } - } - - mCreateSkinCombo.setEnabled(true); - - if (found) { - mCreateSkinCombo.select(index); - } else { - mCreateSkinCombo.select(0); // default - } - } - } - } - - /** - * Validates the fields, displays errors and warnings. - * Enables the finish button if there are no errors. - *

- * Not really used here yet. Keep as a placeholder. - */ - private void validatePage() { - String error = null; - String warning = null; - - - // Validate AVD name - String avdName = mCreateName.getText().trim(); - boolean hasAvdName = avdName.length() > 0; - if (hasAvdName && !AvdManager.RE_AVD_NAME.matcher(avdName).matches()) { - error = String.format( - "AVD name '%1$s' contains invalid characters. Allowed characters are: %2$s", - avdName, AvdManager.CHARS_AVD_NAME); - } - - // Validate target - if (hasAvdName && error == null && mCreateTargetCombo.getSelectionIndex() < 0) { - error = "A target must be selected in order to create an AVD."; - } - - // Validate SDCard path or value - if (error == null) { - String sdName = mCreateSdCard.getText().trim(); - - if (sdName.length() > 0 && - !new File(sdName).isFile() && - !AvdManager.SDCARD_SIZE_PATTERN.matcher(sdName).matches()) { - error = "SD Card must be either a file path or a size such as 128K or 64M."; - } - } - - // Check for duplicate AVD name - if (hasAvdName && error == null) { - if (mKnownAvdNames.contains(avdName) && !mCreateForce.getSelection()) { - error = String.format( - "The AVD name '%s' is already used. " + - "Check \"Force\" if you really want to create a new AVD with that name and delete the previous one.", - avdName); - } - } - - // Validate the create button - boolean can_create = hasAvdName && error == null; - if (can_create) { - can_create &= mCreateTargetCombo.getSelectionIndex() >= 0; - } - mCreateButton.setEnabled(can_create); - - // -- update UI - setPageComplete(true); - if (error != null) { - setMessage(error, WizardPage.ERROR); - } else if (warning != null) { - setMessage(warning, WizardPage.WARNING); - } else { - setErrorMessage(null); - setMessage(null); - } - } - - /** - * Reloads the AVD list in the AVD selector. - * Tries to preserve the selection. - */ - private void reloadAvdList() { - mAvdSelector.refresh(true /* reload */); - - // Keep the list of known AVD names to check if they exist quickly. however - // use the list of all AVDs, including broken ones (unless we don't know their - // name). - AvdManager avdm = getAvdManager(); - mKnownAvdNames.clear(); - if (avdm != null) { - for (AvdInfo avd : avdm.getAllAvds()) { - String name = avd.getName(); - if (name != null) { - mKnownAvdNames.add(name); - } - } - } - } - - /** - * Triggered when the user selects the "create" button. - */ - private void onCreate() { - String avdName = mCreateName.getText().trim(); - String sdName = mCreateSdCard.getText().trim(); - int targetIndex = mCreateTargetCombo.getSelectionIndex(); - int skinIndex = mCreateSkinCombo.getSelectionIndex(); - boolean force = mCreateForce.getSelection(); - AvdManager avdm = getAvdManager(); - - if (avdm == null || - avdName.length() == 0 || - targetIndex < 0) { - return; - } - - String targetName = mCreateTargetCombo.getItem(targetIndex); - IAndroidTarget target = mCurrentTargets.get(targetName); - if (target == null) { - return; - } - - String skinName = null; - if (skinIndex > 0) { - // index 0 is the default, we don't use it - skinName = mCreateSkinCombo.getItem(skinIndex); - } - - SdkLog log = new SdkLog(String.format("Result of creating AVD '%s':", avdName)); - - File avdFolder; - try { - avdFolder = new File( - AndroidLocation.getFolder() + AndroidLocation.FOLDER_AVD, - avdName + AvdManager.AVD_FOLDER_EXTENSION); - } catch (AndroidLocationException e) { - AdtPlugin.logAndPrintError(e, null /*tag*/, - "AndroidLocation.getFolder failed"); //$NON-NLS-1$ - return; - } - - ISdkLog oldLog = null; - boolean success = false; - try { - // Temporarily change the AvdManager's logger for ours, since the API no longer - // takes a logger argument. - // TODO revisit this later. See comments in AvdManager#mSdkLog. - oldLog = avdm.setSdkLog(log); - - AvdInfo avdInfo = avdm.createAvd( - avdFolder, - avdName, - target, - skinName, - sdName, - null, // hardwareConfig, - force); - - success = avdInfo != null; - - } finally { - avdm.setSdkLog(oldLog); - } - - log.display(success); - - if (success) { - // clear the name field on success - mCreateName.setText(""); //$NON-NLS-1$ - } - - reloadAvdList(); - } - - /** - * Collects all log from the AVD action and displays it in a dialog. - */ - private class SdkLog implements ISdkLog { - - final ArrayList logMessages = new ArrayList(); - private final String mMessage; - - public SdkLog(String message) { - mMessage = message; - } - - public void error(Throwable throwable, String errorFormat, Object... arg) { - if (errorFormat != null) { - logMessages.add(String.format("Error: " + errorFormat, arg)); - } - - if (throwable != null) { - logMessages.add(throwable.getMessage()); - } - } - - public void warning(String warningFormat, Object... arg) { - logMessages.add(String.format("Warning: " + warningFormat, arg)); - } - - public void printf(String msgFormat, Object... arg) { - logMessages.add(String.format(msgFormat, arg)); - } - - /** - * Displays the log if anything was captured. - */ - public void display(boolean success) { - if (logMessages.size() > 0) { - StringBuilder sb = new StringBuilder(mMessage + "\n"); - for (String msg : logMessages) { - sb.append('\n'); - sb.append(msg); - } - if (success) { - AdtPlugin.displayWarning("Android Virtual Devices Manager", sb.toString()); - } else { - AdtPlugin.displayError("Android Virtual Devices Manager", sb.toString()); - } - } - } - } - - /** - * Returns the current AVD Manager or null if none has been created yet. - * This can happen when the SDK hasn't finished loading or the manager failed to - * parse the AVD directory. - */ - private AvdManager getAvdManager() { - Sdk sdk = Sdk.getCurrent(); - if (sdk != null) { - return sdk.getAvdManager(); - } - return null; - } -} diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/avdmanager/AvdManagerWizard.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/avdmanager/AvdManagerWizard.java deleted file mode 100755 index d8f77cced..000000000 --- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/avdmanager/AvdManagerWizard.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - - -package com.android.ide.eclipse.adt.internal.wizards.avdmanager; - -import com.android.ide.eclipse.adt.internal.editors.IconFactory; -import com.android.ide.eclipse.adt.internal.ui.IUpdateWizardDialog; -import com.android.ide.eclipse.adt.internal.ui.WizardDialogEx; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.swt.widgets.Button; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; - -/** - * The "AVD Manager Wizard" provides a quick way to edit AVDs. - *

- * The wizard has one page, {@link AvdManagerListPage}, used to display and edit the AVDs. - * In fact the whole UI is not really a wizard. It has just been implemented that way - * to get something quick out of the door. We'll need to revisit this when we implement - * the final standalone AVD Manager UI and this Wizard will go away. - */ -public class AvdManagerWizard extends Wizard implements INewWizard, IUpdateWizardDialog { - - private static final String PROJECT_LOGO_LARGE = "android_large"; //$NON-NLS-1$ - - protected static final String MAIN_PAGE_NAME = "avdManagerListPage"; //$NON-NLS-1$ - - private AvdManagerListPage mMainPage; - - public void init(IWorkbench workbench, IStructuredSelection selection) { - setHelpAvailable(false); // TODO have help - setWindowTitle("Android Virtual Devices Manager"); - setImageDescriptor(); - - mMainPage = createMainPage(); - mMainPage.setTitle("Android Virtual Devices Manager"); - mMainPage.setDescription("Displays existing Android Virtual Devices. Lets you create new ones or delete existing ones."); - } - - /** - * Creates the wizard page. - *

- * Please do NOT override this method. - *

- * This is protected so that it can be overridden by unit tests. - * However the contract of this class is private and NO ATTEMPT will be made - * to maintain compatibility between different versions of the plugin. - */ - protected AvdManagerListPage createMainPage() { - return new AvdManagerListPage(MAIN_PAGE_NAME); - } - - // -- Methods inherited from org.eclipse.jface.wizard.Wizard -- - // - // The Wizard class implements most defaults and boilerplate code needed by - // IWizard - - /** - * Adds pages to this wizard. - */ - @Override - public void addPages() { - addPage(mMainPage); - } - - /** - * Performs any actions appropriate in response to the user having pressed - * the Finish button, or refuse if finishing now is not permitted: here, it does nothing. - * - * @return True - */ - @Override - public boolean performFinish() { - return true; - } - - /** - * Returns an image descriptor for the wizard logo. - */ - private void setImageDescriptor() { - ImageDescriptor desc = IconFactory.getInstance().getImageDescriptor(PROJECT_LOGO_LARGE); - setDefaultPageImageDescriptor(desc); - } - - /** - * Invoked once the dialog frame as been created. - * We use it to hide the cancel button, which looks odd here. - */ - public void updateWizardDialog(WizardDialogEx dialog) { - Button cancel = dialog.getCancelButtonEx(); - if (cancel != null) { - cancel.setVisible(false); - } - } - -}