summaryrefslogtreecommitdiffstats
path: root/src/org.gluster.storage.management.console/src/org/gluster/storage/management/console/actions/ImportSshKeysAction.java
blob: 083cf193832596eeac6cba8824eeb6b707219362 (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
package org.gluster.storage.management.console.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.gluster.storage.management.client.KeysClient;


public class ImportSshKeysAction extends AbstractActionDelegate {

	@Override
	protected void performAction(IAction action) {
		final KeysClient client = new KeysClient();

		Display.getDefault().asyncExec(new Runnable() {
			
			@Override
			public void run() {
				FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
				dialog.setText("Open");
				dialog.setFilterNames(new String[] { "ssh-keys (*.tar)" });
				dialog.setFilterExtensions(new String[] { "*.tar" });

				String selectedFile = dialog.open();
				if (selectedFile == null) {
					return;
				}

				String title = "Import SSH Keys";
				try {
					client.importSshKeys(selectedFile);
					showInfoDialog(title, "SSH keys imported successfully!");
				} catch (Exception e) {
					showErrorDialog(title, e.getMessage());
				}
			}
		});		
	}			

	@Override
	public void dispose() {
	}
}