Merge commit 'beb3214b46e18bb461760c47f04c5b909557d060' * commit 'beb3214b46e18bb461760c47f04c5b909557d060': ADT #1823896: Ability to add an "extra" action to the AVD Selector.
This commit is contained in:
@@ -65,7 +65,6 @@ import org.eclipse.jdt.launching.JavaRuntime;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
@@ -484,26 +483,22 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
|
||||
AdtPlugin.printToConsole(project, String.format(
|
||||
"Failed to find an AVD compatible with target '%1$s'.",
|
||||
projectTarget.getName()));
|
||||
|
||||
|
||||
final Display display = AdtPlugin.getDisplay();
|
||||
final int[] result = new int[] { Window.CANCEL };
|
||||
final boolean[] searchAgain = new boolean[] { false };
|
||||
// ask the user to create a new one.
|
||||
display.syncExec(new Runnable() {
|
||||
public void run() {
|
||||
Shell shell = display.getActiveShell();
|
||||
if (MessageDialog.openQuestion(shell, "AVD Error",
|
||||
"No Compatible targets were found. Do you wish to create one?")) {
|
||||
if (MessageDialog.openQuestion(shell, "Android AVD Error",
|
||||
"No compatible targets were found. Do you wish to a add new Android Virtual Device?")) {
|
||||
AvdManagerAction action = new AvdManagerAction();
|
||||
action.run(null /*action*/);
|
||||
result[0] = action.getDialogResult();
|
||||
searchAgain[0] = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (result[0] == Window.CANCEL) {
|
||||
AdtPlugin.printErrorToConsole(project, String.format("Launch aborted."));
|
||||
stopLaunch(launchInfo);
|
||||
return;
|
||||
} else {
|
||||
if (searchAgain[0]) {
|
||||
// attempt to reload the AVDs and find one compatible.
|
||||
defaultAvd = findMatchingAvd(avdManager, projectTarget);
|
||||
|
||||
@@ -588,9 +583,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
|
||||
}
|
||||
|
||||
/**
|
||||
* @param avdManager
|
||||
* @param projectTarget
|
||||
* @return
|
||||
* Find a matching AVD.
|
||||
*/
|
||||
private AvdInfo findMatchingAvd(AvdManager avdManager, final IAndroidTarget projectTarget) {
|
||||
AvdInfo[] avds = avdManager.getValidAvds();
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.android.sdklib.IAndroidTarget;
|
||||
import com.android.sdklib.avd.AvdManager;
|
||||
import com.android.sdklib.avd.AvdManager.AvdInfo;
|
||||
import com.android.sdkuilib.AvdSelector;
|
||||
import com.android.sdkuilib.AvdSelector.SelectionMode;
|
||||
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
@@ -327,7 +328,7 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener
|
||||
if (deviceMode) {
|
||||
handleDeviceSelection();
|
||||
} else {
|
||||
mResponse.setAvdToLaunch(mPreferredAvdSelector.getFirstSelected());
|
||||
mResponse.setAvdToLaunch(mPreferredAvdSelector.getSelected());
|
||||
}
|
||||
|
||||
enableOkButton();
|
||||
@@ -417,13 +418,22 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener
|
||||
mPreferredAvdSelector = new AvdSelector(offsetComp,
|
||||
getNonRunningAvds(false /*reloadAvds*/),
|
||||
mProjectTarget,
|
||||
new Runnable() {
|
||||
new AvdSelector.IExtraAction() {
|
||||
public void run() {
|
||||
AvdManagerAction action = new AvdManagerAction();
|
||||
action.run(null);
|
||||
refillAvdList(true /*reloadAvds*/);
|
||||
}
|
||||
});
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String label() {
|
||||
return "AVD Manager...";
|
||||
}
|
||||
},
|
||||
SelectionMode.CHECK);
|
||||
mPreferredAvdSelector.setTableHeightHint(100);
|
||||
mPreferredAvdSelector.setEnabled(false);
|
||||
mPreferredAvdSelector.setSelectionListener(new SelectionAdapter() {
|
||||
@@ -434,7 +444,7 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
if (mDisableAvdSelectionChange == false) {
|
||||
mResponse.setAvdToLaunch(mPreferredAvdSelector.getFirstSelected());
|
||||
mResponse.setAvdToLaunch(mPreferredAvdSelector.getSelected());
|
||||
enableOkButton();
|
||||
}
|
||||
}
|
||||
@@ -735,7 +745,7 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener
|
||||
AvdInfo[] array = getNonRunningAvds(reloadAvds);
|
||||
|
||||
// save the current selection
|
||||
AvdInfo selected = mPreferredAvdSelector.getFirstSelected();
|
||||
AvdInfo selected = mPreferredAvdSelector.getSelected();
|
||||
|
||||
// disable selection change.
|
||||
mDisableAvdSelectionChange = true;
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.android.sdklib.IAndroidTarget;
|
||||
import com.android.sdklib.avd.AvdManager;
|
||||
import com.android.sdklib.avd.AvdManager.AvdInfo;
|
||||
import com.android.sdkuilib.AvdSelector;
|
||||
import com.android.sdkuilib.AvdSelector.SelectionMode;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
@@ -192,13 +193,22 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
|
||||
mPreferredAvdLabel.setText("Select a preferred Android Virtual Device for deployment:");
|
||||
mPreferredAvdSelector = new AvdSelector(offsetComp,
|
||||
null /*avds*/,
|
||||
new Runnable() {
|
||||
new AvdSelector.IExtraAction() {
|
||||
public void run() {
|
||||
AvdManagerAction action = new AvdManagerAction();
|
||||
action.run(null);
|
||||
updateAvdList(null);
|
||||
}
|
||||
});
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String label() {
|
||||
return "AVD Manager...";
|
||||
}
|
||||
},
|
||||
SelectionMode.CHECK);
|
||||
mPreferredAvdSelector.setTableHeightHint(100);
|
||||
mPreferredAvdSelector.setSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
@@ -445,7 +455,7 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
|
||||
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
|
||||
configuration.setAttribute(LaunchConfigDelegate.ATTR_TARGET_MODE,
|
||||
mAutoTargetButton.getSelection());
|
||||
AvdInfo avd = mPreferredAvdSelector.getFirstSelected();
|
||||
AvdInfo avd = mPreferredAvdSelector.getSelected();
|
||||
if (avd != null) {
|
||||
configuration.setAttribute(LaunchConfigDelegate.ATTR_AVD_NAME, avd.getName());
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.ui;
|
||||
|
||||
import org.eclipse.jface.wizard.WizardDialog;
|
||||
|
||||
|
||||
/**
|
||||
* An interface that enables a client to update {@link WizardDialog} after its creation.
|
||||
*/
|
||||
public interface IUpdateWizardDialog {
|
||||
/**
|
||||
* Invoked after {@link WizardDialog#create()} to let the caller update the dialog.
|
||||
*/
|
||||
public void updateWizardDialog(WizardDialogEx dialog);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.ui;
|
||||
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.wizard.IWizard;
|
||||
import org.eclipse.jface.wizard.WizardDialog;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
/**
|
||||
* A {@link WizardDialog} that gives access to some inner controls.
|
||||
*/
|
||||
public final class WizardDialogEx extends WizardDialog {
|
||||
|
||||
/**
|
||||
* @see WizardDialog#WizardDialog(Shell, IWizard)
|
||||
*/
|
||||
public WizardDialogEx(Shell parentShell, IWizard newWizard) {
|
||||
super(parentShell, newWizard);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cancel button.
|
||||
* <p/>
|
||||
* Note: there is already a protected, deprecated method that does the same thing.
|
||||
* To avoid overriding a deprecated method, the name as be changed to ...Ex.
|
||||
*/
|
||||
public Button getCancelButtonEx() {
|
||||
return getButton(IDialogConstants.CANCEL_ID);
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,14 @@
|
||||
|
||||
package com.android.ide.eclipse.adt.wizards.actions;
|
||||
|
||||
import com.android.ide.eclipse.adt.ui.IUpdateWizardDialog;
|
||||
import com.android.ide.eclipse.adt.ui.WizardDialogEx;
|
||||
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.wizard.WizardDialog;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
@@ -124,9 +126,13 @@ import org.eclipse.ui.internal.util.Util;
|
||||
|
||||
// It's not visible yet until a dialog is created and opened
|
||||
Shell parent = window.getShell();
|
||||
WizardDialog dialog = new WizardDialog(parent, mWizard);
|
||||
WizardDialogEx dialog = new WizardDialogEx(parent, mWizard);
|
||||
dialog.create();
|
||||
|
||||
if (mWizard instanceof IUpdateWizardDialog) {
|
||||
((IUpdateWizardDialog) mWizard).updateWizardDialog(dialog);
|
||||
}
|
||||
|
||||
// This code comes straight from NewWizardShortcutAction#run()
|
||||
Point defaultSize = dialog.getShell().getSize();
|
||||
dialog.getShell().setSize(
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.android.sdklib.ISdkLog;
|
||||
import com.android.sdklib.avd.AvdManager;
|
||||
import com.android.sdklib.avd.AvdManager.AvdInfo;
|
||||
import com.android.sdkuilib.AvdSelector;
|
||||
import com.android.sdkuilib.AvdSelector.SelectionMode;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.wizard.WizardPage;
|
||||
@@ -56,7 +57,6 @@ import java.util.TreeMap;
|
||||
class AvdManagerListPage extends WizardPage {
|
||||
|
||||
private AvdSelector mAvdSelector;
|
||||
private Button mDeleteButton;
|
||||
private Button mRefreshButton;
|
||||
private Text mCreateName;
|
||||
private Combo mCreateTargetCombo;
|
||||
@@ -162,32 +162,21 @@ class AvdManagerListPage extends WizardPage {
|
||||
}
|
||||
});
|
||||
|
||||
mAvdSelector = new AvdSelector(parent, null);
|
||||
mAvdSelector.setSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
super.widgetSelected(e);
|
||||
updateDeleteButton();
|
||||
}
|
||||
});
|
||||
mAvdSelector = new AvdSelector(parent,
|
||||
SelectionMode.SELECT,
|
||||
new AvdSelector.IExtraAction() {
|
||||
public String label() {
|
||||
return "Delete AVD...";
|
||||
}
|
||||
|
||||
mDeleteButton = new Button(parent, SWT.PUSH);
|
||||
mDeleteButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
|
||||
mDeleteButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
onDelete();
|
||||
}
|
||||
});
|
||||
updateDeleteButton();
|
||||
}
|
||||
|
||||
private void updateDeleteButton() {
|
||||
AvdInfo selected = mAvdSelector.getFirstSelected();
|
||||
mDeleteButton.setText(String.format("Delete %s...",
|
||||
selected == null ? "" : selected.getName())); //$NON-NLS-1$
|
||||
mDeleteButton.pack();
|
||||
mDeleteButton.setEnabled(selected != null);
|
||||
public boolean isEnabled() {
|
||||
return mAvdSelector != null && mAvdSelector.getSelected() != null;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
onDelete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -441,19 +430,24 @@ class AvdManagerListPage extends WizardPage {
|
||||
* Tries to preserve the selection.
|
||||
*/
|
||||
private void reloadAvdList() {
|
||||
AvdInfo selected = mAvdSelector.getFirstSelected();
|
||||
AvdInfo selected = mAvdSelector.getSelected();
|
||||
|
||||
AvdManager avdm = getAvdManager();
|
||||
AvdInfo[] avds = null;
|
||||
|
||||
// For the AVD manager to reload the list, in case AVDs where created using the
|
||||
// command line tool.
|
||||
try {
|
||||
avdm.reloadAvds();
|
||||
} catch (AndroidLocationException e) {
|
||||
AdtPlugin.log(e, "AVD Manager reload failed"); //$NON-NLS-1$
|
||||
// The AVD manager may not exist yet, typically when loading the SDK.
|
||||
if (avdm != null) {
|
||||
try {
|
||||
avdm.reloadAvds();
|
||||
} catch (AndroidLocationException e) {
|
||||
AdtPlugin.log(e, "AVD Manager reload failed"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
avds = avdm.getValidAvds();
|
||||
}
|
||||
|
||||
AvdInfo[] avds = avdm == null ? null : avdm.getValidAvds();
|
||||
mAvdSelector.setAvds(avds, null /*filter*/);
|
||||
|
||||
// Keep the list of known AVD names to check if they exist quickly. however
|
||||
@@ -473,11 +467,11 @@ class AvdManagerListPage extends WizardPage {
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered when the user selects the "delete" button.
|
||||
* Triggered when the user selects the "delete" button (the extra action in the selector)
|
||||
* Deletes the currently selected AVD, if any.
|
||||
*/
|
||||
private void onDelete() {
|
||||
AvdInfo avdInfo = mAvdSelector.getFirstSelected();
|
||||
AvdInfo avdInfo = mAvdSelector.getSelected();
|
||||
AvdManager avdm = getAvdManager();
|
||||
if (avdInfo == null || avdm == null) {
|
||||
return;
|
||||
@@ -496,7 +490,6 @@ class AvdManagerListPage extends WizardPage {
|
||||
|
||||
log.display(success);
|
||||
reloadAvdList();
|
||||
updateDeleteButton();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,11 +18,14 @@
|
||||
|
||||
package com.android.ide.eclipse.adt.wizards.avdmanager;
|
||||
|
||||
import com.android.ide.eclipse.adt.ui.IUpdateWizardDialog;
|
||||
import com.android.ide.eclipse.adt.ui.WizardDialogEx;
|
||||
import com.android.ide.eclipse.editors.IconFactory;
|
||||
|
||||
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;
|
||||
|
||||
@@ -34,7 +37,7 @@ import org.eclipse.ui.IWorkbench;
|
||||
* 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 {
|
||||
public class AvdManagerWizard extends Wizard implements INewWizard, IUpdateWizardDialog {
|
||||
|
||||
private static final String PROJECT_LOGO_LARGE = "android_large"; //$NON-NLS-1$
|
||||
|
||||
@@ -97,4 +100,15 @@ public class AvdManagerWizard extends Wizard implements INewWizard {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user