summaryrefslogtreecommitdiffstats
path: root/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/ResetVolumeOptionsAction.java
blob: cd2b3ff5f3a1fc3571fea75f29ed7eaa6ab673aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.gluster.storage.management.console.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Display;

import com.gluster.storage.management.client.VolumesClient;
import com.gluster.storage.management.console.GlusterDataModelManager;
import com.gluster.storage.management.console.utils.GUIHelper;
import com.gluster.storage.management.core.model.Volume;

public class ResetVolumeOptionsAction extends AbstractActionDelegate {
	private Volume volume;
	private GlusterDataModelManager modelManager = GlusterDataModelManager.getInstance();

	@Override
	public void dispose() {
	}

	@Override
	protected void performAction(final IAction action) {
		Display.getDefault().asyncExec(new Runnable() {

			@Override
			public void run() {
				final String actionDesc = action.getDescription();

				boolean confirmed = showConfirmDialog(actionDesc,
						"Are you sure you want to reset all options of the volume [" + volume.getName() + "] ?");
				if (!confirmed) {
					return;
				}

				try {
					new VolumesClient().resetVolumeOptions(volume.getName());
					showInfoDialog(actionDesc, "Volume options for [" + volume.getName() + "] reset successfully!");
					modelManager.resetVolumeOptions(volume);
				} catch (Exception e) {
					showErrorDialog(actionDesc, "Volume options for [" + volume.getName()
							+ "] could not be reset! Error: [" + e.getMessage() + "]");
				}
			}
		});
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.gluster.storage.management.console.actions.AbstractActionDelegate#selectionChanged(org.eclipse.jface.action.IAction
	 * , org.eclipse.jface.viewers.ISelection)
	 */
	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		volume = GUIHelper.getInstance().getSelectedEntity(getWindow(), Volume.class);
		if (volume != null) {
			action.setEnabled(volume.getOptions().size() > 0);
		} else {
			action.setEnabled(false);
		}
	}
}