diff options
| author | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-06-08 02:27:46 -0700 |
|---|---|---|
| committer | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-06-08 02:27:46 -0700 |
| commit | 76cb93060be51514c9fd1d54d68311eba448ad87 (patch) | |
| tree | 38c0b5205ae8787adcf3931bd8932486cbb93f35 | |
| parent | 405cd5d55f511cc60d3682aea69192f0d6709030 (diff) | |
| parent | 49204fb76167ea1f26803441b33caa105a2fcfe4 (diff) | |
Merge pull request #61 from Selvasundaram/master
Bug #2877 Using short cut key for resetting volume options selects irrelevant volume - fix
2 files changed, 30 insertions, 21 deletions
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ResetVolumeOptionsAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ResetVolumeOptionsAction.java index 5182d25f..f23f3b15 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ResetVolumeOptionsAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ResetVolumeOptionsAction.java @@ -2,6 +2,7 @@ package com.gluster.storage.management.gui.actions; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; @@ -10,6 +11,7 @@ import com.gluster.storage.management.client.VolumesClient; import com.gluster.storage.management.core.model.Status; import com.gluster.storage.management.core.model.Volume; import com.gluster.storage.management.core.model.Volume.VOLUME_STATUS; +import com.gluster.storage.management.gui.utils.GUIHelper; public class ResetVolumeOptionsAction extends AbstractActionDelegate { private Volume volume; @@ -22,23 +24,29 @@ public class ResetVolumeOptionsAction extends AbstractActionDelegate { } @Override - protected void performAction(IAction action) { - final String actionDesc = action.getDescription(); + protected void performAction(final IAction action) { + Display.getDefault().asyncExec(new Runnable() { - boolean confirmed = showConfirmDialog(actionDesc, - "Are you sure you want to reset all options of the volume [" + volume.getName() + "] ?"); - if (!confirmed) { - return; - } + @Override + public void run() { + final String actionDesc = action.getDescription(); - final Status status = resetVolumeOptions(); - if (status.isSuccess()) { - showInfoDialog(actionDesc, "Volume options for [" + volume.getName() + "] reset successfully!"); - modelManager.resetVolumeOptions(volume); - } else { - showErrorDialog(actionDesc, "Volume options for [" + volume.getName() + "] could not be reset! Error: [" + status - + "]"); - } + boolean confirmed = showConfirmDialog(actionDesc, + "Are you sure you want to reset all options of the volume [" + volume.getName() + "] ?"); + if (!confirmed) { + return; + } + + final Status status = resetVolumeOptions(); + if (status.isSuccess()) { + showInfoDialog(actionDesc, "Volume options for [" + volume.getName() + "] reset successfully!"); + modelManager.resetVolumeOptions(volume); + } else { + showErrorDialog(actionDesc, "Volume options for [" + volume.getName() + + "] could not be reset! Error: [" + status + "]"); + } + } + }); } private Status resetVolumeOptions() { @@ -54,11 +62,12 @@ public class ResetVolumeOptionsAction extends AbstractActionDelegate { */ @Override public void selectionChanged(IAction action, ISelection selection) { - super.selectionChanged(action, selection); - - if (selectedEntity instanceof Volume) { - volume = (Volume) selectedEntity; + volume = GUIHelper.getInstance().getSelectedEntity(getWindow(), Volume.class); + + if (volume instanceof Volume) { action.setEnabled(volume.getOptions().size() > 0); + } else { + action.setEnabled(false); } } } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/GUIHelper.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/GUIHelper.java index d08030be..56a6c94b 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/GUIHelper.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/GUIHelper.java @@ -363,14 +363,14 @@ public class GUIHelper { } @SuppressWarnings({ "unchecked", "rawtypes" }) - public Object getSelectedEntity(IWorkbenchWindow window, Class expectedType) { + public <T> T getSelectedEntity(IWorkbenchWindow window, Class<T> expectedType) { ISelection selection = window.getSelectionService().getSelection(NavigationView.ID); if (selection instanceof IStructuredSelection) { Iterator<Object> iter = ((IStructuredSelection) selection).iterator(); while (iter.hasNext()) { Object selectedObj = iter.next(); if (selectedObj.getClass() == expectedType) { - return selectedObj; + return (T)selectedObj; } } } |
