diff options
| author | Selvam <selvam@gluster.com> | 2011-04-05 15:35:52 +0530 |
|---|---|---|
| committer | Selvam <selvam@gluster.com> | 2011-04-05 16:00:47 +0530 |
| commit | 1fc1b836cab2003dff92a201d78a322d8f95ad3c (patch) | |
| tree | d2543f678a210a7fa223d86a884e08a81c7ee33c /src/com.gluster.storage.management.gui | |
| parent | 3e997efcd1f569d38b1ac7623c4e10dd35da416a (diff) | |
| parent | 5b0bc49b37634aa8923c33b96dd3e4630447874c (diff) | |
Merge remote branch 'upstream/master'
Conflicts:
src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java
src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/RunningTaskResource.java
src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java
Diffstat (limited to 'src/com.gluster.storage.management.gui')
12 files changed, 94 insertions, 72 deletions
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AbstractActionDelegate.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AbstractActionDelegate.java index 4aa387bc..adc98f98 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AbstractActionDelegate.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AbstractActionDelegate.java @@ -19,9 +19,11 @@ package com.gluster.storage.management.gui.actions; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; @@ -37,6 +39,20 @@ public abstract class AbstractActionDelegate implements IWorkbenchWindowActionDe protected Entity selectedEntity; @Override + public void run(final IAction action) { + // Real action code must be executed using Display#asyncExec. Otherwise the system can hang when opening new + // dialog boxes on linux platform + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + performAction(action); + } + }); + } + + abstract protected void performAction(IAction action); + + @Override public void selectionChanged(IAction action, ISelection selection) { if (selection instanceof StructuredSelection) { Entity selectedEntity = (Entity) ((StructuredSelection) selection).getFirstElement(); @@ -46,7 +62,7 @@ public abstract class AbstractActionDelegate implements IWorkbenchWindowActionDe return; } - if(selectedEntity != null) { + if (selectedEntity != null) { this.selectedEntity = selectedEntity; } } @@ -56,4 +72,27 @@ public abstract class AbstractActionDelegate implements IWorkbenchWindowActionDe public void init(IWorkbenchWindow window) { this.window = window; } + + private Shell getShell() { + if(window == null) { + return Display.getDefault().getActiveShell(); + } + return window.getShell(); + } + + protected void showInfoDialog(final String title, final String message) { + MessageDialog.openInformation(getShell(), title, message); + } + + protected void showWarningDialog(final String title, final String message) { + MessageDialog.openWarning(getShell(), title, message); + } + + protected void showErrorDialog(final String title, final String message) { + MessageDialog.openError(getShell(), title, message); + } + + protected synchronized boolean showConfirmDialog(final String title, final String message) { + return MessageDialog.openQuestion(getShell(), title, message); + } } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java index 7957b6f0..7d76d0ec 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java @@ -19,21 +19,20 @@ package com.gluster.storage.management.gui.actions; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.widgets.Display; import com.gluster.storage.management.client.GlusterDataModelManager; import com.gluster.storage.management.client.GlusterServersClient; import com.gluster.storage.management.core.model.Entity; import com.gluster.storage.management.core.model.EntityGroup; -import com.gluster.storage.management.core.model.GlusterServerResponse; import com.gluster.storage.management.core.model.Server; import com.gluster.storage.management.core.model.Volume; +import com.gluster.storage.management.core.response.GlusterServerResponse; public class AddServerAction extends AbstractActionDelegate { @Override - public void run(IAction action) { + protected void performAction(IAction action) { + final String actionDesc = action.getDescription(); GlusterDataModelManager modelManager = GlusterDataModelManager.getInstance(); GlusterServersClient glusterServersClient = new GlusterServersClient(modelManager.getSecurityToken()); Server server = (Server) selectedEntity; @@ -41,12 +40,10 @@ public class AddServerAction extends AbstractActionDelegate { if (response.getStatus().isSuccess()) { modelManager.removeDiscoveredServer(server); modelManager.addGlusterServer(response.getGlusterServer()); - new MessageDialog(Display.getDefault().getActiveShell(), "Add Server", null, "Server [" + server.getName() - + "] added successfully!", MessageDialog.INFORMATION, new String[] { "OK" }, 0).open(); + showInfoDialog(actionDesc, "Server [" + server.getName() + "] added successfully!"); } else { - new MessageDialog(Display.getDefault().getActiveShell(), "Add Server", null, "Server [" + server.getName() - + " could not be added to cluster! Error: [" + response.getStatus().getMessage() + "]", - MessageDialog.ERROR, new String[] { "OK" }, 0).open(); + showErrorDialog(actionDesc, "Server [" + server.getName() + " could not be added to cluster! Error: [" + + response.getStatus().getMessage() + "]"); } } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CreateVolumeAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CreateVolumeAction.java index 266db0af..9ec500bc 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CreateVolumeAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CreateVolumeAction.java @@ -29,7 +29,7 @@ import com.gluster.storage.management.gui.dialogs.CreateVolumeWizard; public class CreateVolumeAction extends AbstractActionDelegate { @Override - public void run(IAction action) { + protected void performAction(IAction action) { Display.getDefault().asyncExec(new Runnable() { @Override diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/DeleteVolumeAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/DeleteVolumeAction.java index b4b92c31..82ac1663 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/DeleteVolumeAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/DeleteVolumeAction.java @@ -22,7 +22,7 @@ import org.eclipse.jface.action.IAction; public class DeleteVolumeAction extends AbstractActionDelegate { @Override - public void run(IAction action) { + protected void performAction(IAction action) { System.out.println("Running [" + this.getClass().getSimpleName() + "]"); } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/EditVolumeAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/EditVolumeAction.java index 6f3fdf24..0f7f14b7 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/EditVolumeAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/EditVolumeAction.java @@ -22,7 +22,7 @@ import org.eclipse.jface.action.IAction; public class EditVolumeAction extends AbstractActionDelegate { @Override - public void run(IAction action) { + protected void performAction(IAction action) { System.out.println("Running [" + this.getClass().getSimpleName() + "]"); } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/MigrateDiskAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/MigrateDiskAction.java index 75be4e6b..04ee39fb 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/MigrateDiskAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/MigrateDiskAction.java @@ -32,7 +32,7 @@ public class MigrateDiskAction extends AbstractActionDelegate { private Disk disk; @Override - public void run(IAction action) { + protected void performAction(IAction action) { // MigrateDiskDialog dialog = new MigrateDiskDialog(window.getShell(), volume, disk); // dialog.create(); // dialog.open(); diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/MigrateVolumeAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/MigrateVolumeAction.java index 97f1c79b..aea7ea66 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/MigrateVolumeAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/MigrateVolumeAction.java @@ -22,7 +22,7 @@ import org.eclipse.jface.action.IAction; public class MigrateVolumeAction extends AbstractActionDelegate { @Override - public void run(IAction action) { + protected void performAction(IAction action) { System.out.println("Running [" + this.getClass().getSimpleName() + "]"); } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/PreferencesAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/PreferencesAction.java index f6fd88e4..9da1cbf1 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/PreferencesAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/PreferencesAction.java @@ -29,7 +29,7 @@ public class PreferencesAction extends AbstractActionDelegate { } @Override - public void run(IAction action) { + protected void performAction(IAction action) { ActionFactory.PREFERENCES.create(window).run(); } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RebalanceVolumeAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RebalanceVolumeAction.java index 65227b0b..5339beb0 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RebalanceVolumeAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RebalanceVolumeAction.java @@ -22,7 +22,7 @@ import org.eclipse.jface.action.IAction; public class RebalanceVolumeAction extends AbstractActionDelegate { @Override - public void run(IAction action) { + protected void performAction(IAction action) { System.out.println("Running [" + this.getClass().getSimpleName() + "]"); } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RemoveServerAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RemoveServerAction.java index d5d42363..b7ed0548 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RemoveServerAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RemoveServerAction.java @@ -19,13 +19,10 @@ package com.gluster.storage.management.gui.actions; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.IWorkbenchWindowActionDelegate; public class RemoveServerAction extends AbstractActionDelegate { @Override - public void run(IAction action) { + protected void performAction(IAction action) { System.out.println("Running [" + this.getClass().getSimpleName() + "]"); } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StartVolumeAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StartVolumeAction.java index cc0fbe94..34080f76 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StartVolumeAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StartVolumeAction.java @@ -19,9 +19,7 @@ package com.gluster.storage.management.gui.actions; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.widgets.Display; import com.gluster.storage.management.client.GlusterDataModelManager; import com.gluster.storage.management.client.VolumesClient; @@ -34,7 +32,7 @@ public class StartVolumeAction extends AbstractActionDelegate { private GlusterDataModelManager modelManager = GlusterDataModelManager.getInstance(); @Override - public void run(final IAction action) { + protected void performAction(IAction action) { if (volume.getStatus() == VOLUME_STATUS.ONLINE) { return; // Volume already online. Don't do anything. } @@ -42,23 +40,13 @@ public class StartVolumeAction extends AbstractActionDelegate { VolumesClient client = new VolumesClient(modelManager.getSecurityToken()); final Status status = client.startVolume(volume.getName()); final String actionDesc = action.getDescription(); - final Display display = Display.getDefault(); - display.asyncExec(new Runnable() { - - @Override - public void run() { - if (status.isSuccess()) { - new MessageDialog(display.getActiveShell(), actionDesc, null, "Volume [" - + volume.getName() + "] started successfully!", MessageDialog.INFORMATION, - new String[] { "OK" }, 0).open(); - modelManager.updateVolumeStatus(volume, VOLUME_STATUS.ONLINE); - } else { - new MessageDialog(display.getActiveShell(), actionDesc, null, "Volume [" - + volume.getName() + "] could not be started! Error: [" + status + "]", - MessageDialog.ERROR, new String[] { "OK" }, 0).open(); - } - } - }); + if (status.isSuccess()) { + showInfoDialog(actionDesc, "Volume [" + volume.getName() + "] started successfully!"); + modelManager.updateVolumeStatus(volume, VOLUME_STATUS.ONLINE); + } else { + showErrorDialog(actionDesc, "Volume [" + volume.getName() + "] could not be started! Error: [" + + status + "]"); + } } @Override diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StopVolumeAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StopVolumeAction.java index a89782f9..21ea4339 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StopVolumeAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StopVolumeAction.java @@ -19,9 +19,7 @@ package com.gluster.storage.management.gui.actions; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.widgets.Display; import com.gluster.storage.management.client.GlusterDataModelManager; import com.gluster.storage.management.client.VolumesClient; @@ -32,42 +30,45 @@ import com.gluster.storage.management.core.model.Volume.VOLUME_STATUS; public class StopVolumeAction extends AbstractActionDelegate { private Volume volume; private GlusterDataModelManager modelManager = GlusterDataModelManager.getInstance(); - + @Override - public void run(IAction action) { - if(volume.getStatus() == VOLUME_STATUS.OFFLINE) { + protected void performAction(IAction action) { + final String actionDesc = action.getDescription(); + if (volume.getStatus() == VOLUME_STATUS.OFFLINE) { + showWarningDialog(actionDesc, "Volume [" + volume.getName() + "] is already offline!"); return; // Volume already offline. Don't do anything. } - - VolumesClient client = new VolumesClient(modelManager.getSecurityToken()); - final Status status = client.stopVolume(volume.getName()); - final String actionDesc = action.getDescription(); - final Display display = Display.getDefault(); - - display.asyncExec(new Runnable() { - - @Override - public void run() { - if (status.isSuccess()) { - new MessageDialog(Display.getCurrent().getActiveShell(), actionDesc, null, "Volume [" - + volume.getName() + "] stopped successfully!", MessageDialog.INFORMATION, new String[] { "OK" }, 0) - .open(); - modelManager.updateVolumeStatus(volume, VOLUME_STATUS.OFFLINE); - } else { - new MessageDialog(Display.getCurrent().getActiveShell(), actionDesc, null, "Volume [" - + volume.getName() + "] could not be stopped! Error: [" + status + "]", MessageDialog.ERROR, - new String[] { "OK" }, 0).open(); - } - } - }); + + boolean confirmed = showConfirmDialog(actionDesc, + "Are you sure you want to stop the volume [" + volume.getName() + "] ?"); + if (!confirmed) { + return; + } + + final Status status = stopVolume(); + if (status.isSuccess()) { + showInfoDialog(actionDesc, "Volume [" + volume.getName() + "] stopped successfully!"); + modelManager.updateVolumeStatus(volume, VOLUME_STATUS.OFFLINE); + } else { + showErrorDialog(actionDesc, "Volume [" + volume.getName() + "] could not be stopped! Error: [" + status + + "]"); + } + } + + private Status stopVolume() { + return new VolumesClient(modelManager.getSecurityToken()).stopVolume(volume.getName()); } @Override public void dispose() { } - - /* (non-Javadoc) - * @see com.gluster.storage.management.gui.actions.AbstractActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + + /* + * (non-Javadoc) + * + * @see + * com.gluster.storage.management.gui.actions.AbstractActionDelegate#selectionChanged(org.eclipse.jface.action.IAction + * , org.eclipse.jface.viewers.ISelection) */ @Override public void selectionChanged(IAction action, ISelection selection) { |
