Properly enable/disable buttons in the AVD selector.

Also fixed a small issue with selection in the checkbox
mode.
This commit is contained in:
Xavier Ducrohet
2009-06-30 07:34:04 -07:00
parent c916aec2b2
commit 6c3fa89aad
2 changed files with 84 additions and 27 deletions

View File

@@ -48,7 +48,7 @@ import org.eclipse.swt.widgets.Text;
import java.io.File; import java.io.File;
import java.util.TreeMap; import java.util.TreeMap;
public class AvdCreationDialog extends Dialog { final class AvdCreationDialog extends Dialog {
private final AvdManager mAvdManager; private final AvdManager mAvdManager;
private final TreeMap<String, IAndroidTarget> mCurrentTargets = private final TreeMap<String, IAndroidTarget> mCurrentTargets =

View File

@@ -59,17 +59,27 @@ import java.util.ArrayList;
* and finally use {@link #getSelected()} to retrieve the selection. * and finally use {@link #getSelected()} to retrieve the selection.
*/ */
public final class AvdSelector { public final class AvdSelector {
private SelectionListener mSelectionListener;
private Table mTable;
private static int NUM_COL = 2; private static int NUM_COL = 2;
private final DisplayMode mDisplayMode; private final DisplayMode mDisplayMode;
private Button mManagerButton;
private IAvdFilter mTargetFilter;
private AvdManager mAvdManager; private AvdManager mAvdManager;
private Table mTable;
private Button mDeleteButton;
private Button mDetailsButton;
private Button mNewButton;
private Button mRefreshButton;
private Button mManagerButton;
private SelectionListener mSelectionListener;
private IAvdFilter mTargetFilter;
private boolean mIsEnabled = true;
private ImageFactory mImageFactory;
private Image mOkImage; private Image mOkImage;
private Image mBrokenImage; private Image mBrokenImage;
private ImageFactory mImageFactory;
/** /**
* The display mode of the AVD Selector. * The display mode of the AVD Selector.
@@ -199,20 +209,20 @@ public final class AvdSelector {
buttons.setFont(group.getFont()); buttons.setFont(group.getFont());
if (displayMode == DisplayMode.MANAGER) { if (displayMode == DisplayMode.MANAGER) {
Button newButton = new Button(buttons, SWT.PUSH | SWT.FLAT); mNewButton = new Button(buttons, SWT.PUSH | SWT.FLAT);
newButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); mNewButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
newButton.setText("New..."); mNewButton.setText("New...");
newButton.addSelectionListener(new SelectionAdapter() { mNewButton.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent arg0) { public void widgetSelected(SelectionEvent arg0) {
onNew(); onNew();
} }
}); });
Button deleteButton = new Button(buttons, SWT.PUSH | SWT.FLAT); mDeleteButton = new Button(buttons, SWT.PUSH | SWT.FLAT);
deleteButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); mDeleteButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
deleteButton.setText("Delete"); mDeleteButton.setText("Delete");
deleteButton.addSelectionListener(new SelectionAdapter() { mDeleteButton.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent arg0) { public void widgetSelected(SelectionEvent arg0) {
onDelete(); onDelete();
@@ -223,10 +233,10 @@ public final class AvdSelector {
l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
} }
Button infoButton = new Button(buttons, SWT.PUSH | SWT.FLAT); mDetailsButton = new Button(buttons, SWT.PUSH | SWT.FLAT);
infoButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); mDetailsButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
infoButton.setText("Details..."); mDetailsButton.setText("Details...");
infoButton.addSelectionListener(new SelectionAdapter() { mDetailsButton.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent arg0) { public void widgetSelected(SelectionEvent arg0) {
onDetails(); onDetails();
@@ -236,10 +246,10 @@ public final class AvdSelector {
Composite padding = new Composite(buttons, SWT.NONE); Composite padding = new Composite(buttons, SWT.NONE);
padding.setLayoutData(new GridData(GridData.FILL_VERTICAL)); padding.setLayoutData(new GridData(GridData.FILL_VERTICAL));
Button refreshButton = new Button(buttons, SWT.PUSH | SWT.FLAT); mRefreshButton = new Button(buttons, SWT.PUSH | SWT.FLAT);
refreshButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); mRefreshButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
refreshButton.setText("Resfresh"); mRefreshButton.setText("Resfresh");
refreshButton.addSelectionListener(new SelectionAdapter() { mRefreshButton.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent arg0) { public void widgetSelected(SelectionEvent arg0) {
refresh(true); refresh(true);
@@ -452,11 +462,14 @@ public final class AvdSelector {
mSelectionListener.widgetSelected(null); mSelectionListener.widgetSelected(null);
} }
enableActionButtons();
return found; return found;
} }
/** /**
* Returns the currently selected item. * Returns the currently selected item. In {@link DisplayMode#SIMPLE_CHECK} mode this will
* return the {@link AvdInfo} that is checked instead of the list selection.
* *
* @return The currently selected item or null. * @return The currently selected item or null.
*/ */
@@ -485,7 +498,23 @@ public final class AvdSelector {
* @param enabled the new enabled state. * @param enabled the new enabled state.
*/ */
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
mTable.setEnabled(enabled); mIsEnabled = enabled;
mTable.setEnabled(mIsEnabled);
mRefreshButton.setEnabled(mIsEnabled);
if (mNewButton != null) {
mNewButton.setEnabled(mIsEnabled);
}
if (mManagerButton != null) {
mManagerButton.setEnabled(mIsEnabled);
}
enableActionButtons();
}
public boolean isEnabled() {
return mIsEnabled;
} }
/** /**
@@ -533,6 +562,8 @@ public final class AvdSelector {
if (mSelectionListener != null) { if (mSelectionListener != null) {
mSelectionListener.widgetSelected(e); mSelectionListener.widgetSelected(e);
} }
enableActionButtons();
} }
/** /**
@@ -564,6 +595,8 @@ public final class AvdSelector {
if (showDetails) { if (showDetails) {
onDetails(); onDetails();
} }
enableActionButtons();
} }
/** /**
@@ -654,6 +687,30 @@ public final class AvdSelector {
} }
} }
/**
* Returns the currently selected AVD in the table.
* <p/>
* Unlike {@link #getSelected()} this will always return the item being selected
* in the list, ignoring the check boxes state in {@link DisplayMode#SIMPLE_CHECK} mode.
*/
private AvdInfo getTableSelection() {
int selIndex = mTable.getSelectionIndex();
if (selIndex >= 0) {
return (AvdInfo) mTable.getItem(selIndex).getData();
}
return null;
}
private void enableActionButtons() {
boolean enabled = mIsEnabled == false ? false : getTableSelection() != null;
mDetailsButton.setEnabled(enabled);
if (mDeleteButton != null) {
mDeleteButton.setEnabled(enabled);
}
}
private void onNew() { private void onNew() {
AvdCreationDialog dlg = new AvdCreationDialog(mTable.getShell(), mAvdManager, AvdCreationDialog dlg = new AvdCreationDialog(mTable.getShell(), mAvdManager,
mImageFactory); mImageFactory);
@@ -663,14 +720,14 @@ public final class AvdSelector {
} }
private void onDetails() { private void onDetails() {
final AvdInfo avdInfo = getSelected(); final AvdInfo avdInfo = getTableSelection();
AvdDetailsDialog dlg = new AvdDetailsDialog(mTable.getShell(), avdInfo); AvdDetailsDialog dlg = new AvdDetailsDialog(mTable.getShell(), avdInfo);
dlg.open(); dlg.open();
} }
private void onDelete() { private void onDelete() {
final AvdInfo avdInfo = getSelected(); final AvdInfo avdInfo = getTableSelection();
// get the current Display // get the current Display
final Display display = mTable.getDisplay(); final Display display = mTable.getDisplay();