IDEA-120038 - Redesing Git cloud frameworks UI - upload SSH key from account

This commit is contained in:
Michael Golubev
2014-02-20 13:41:46 +01:00
parent f1240134b1
commit b353744f65
2 changed files with 93 additions and 0 deletions
@@ -20,10 +20,12 @@ import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Progressive;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.remoteServer.configuration.deployment.DeploymentConfiguration;
import com.intellij.util.concurrency.Semaphore;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.concurrent.atomic.AtomicReference;
public abstract class CloudRuntimeTask<
@@ -36,6 +38,9 @@ public abstract class CloudRuntimeTask<
private final Project myProject;
private final String myTitle;
private final AtomicReference<Boolean> mySuccess = new AtomicReference<Boolean>();
private final AtomicReference<String> myErrorMessage = new AtomicReference<String>();
public CloudRuntimeTask(Project project, String title) {
myProject = project;
myTitle = title;
@@ -87,6 +92,9 @@ public abstract class CloudRuntimeTask<
};
}
mySuccess.set(false);
myErrorMessage.set(null);
AtomicReference<T> result = new AtomicReference<T>();
run(semaphore, result);
@@ -110,6 +118,7 @@ public abstract class CloudRuntimeTask<
public void run() {
try {
result.set(CloudRuntimeTask.this.run(serverRuntime));
mySuccess.set(true);
}
catch (ServerRuntimeException e) {
runtimeErrorOccurred(e.getMessage());
@@ -122,9 +131,21 @@ public abstract class CloudRuntimeTask<
}
protected void runtimeErrorOccurred(@NotNull String errorMessage) {
myErrorMessage.set(errorMessage);
LOG.info(errorMessage);
}
public void showMessageDialog(JComponent component, String successMessage, String title) {
if (mySuccess.get()) {
Messages.showInfoMessage(component, successMessage, title);
return;
}
String errorMessage = myErrorMessage.get();
if (errorMessage != null) {
Messages.showErrorDialog(component, errorMessage, title);
}
}
protected abstract SR getServerRuntime();
protected abstract T run(SR serverRuntime) throws ServerRuntimeException;
@@ -18,8 +18,15 @@ package com.intellij.remoteServer.util.ssh;
import com.intellij.execution.filters.HyperlinkInfo;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationListener;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.UnnamedConfigurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.Messages;
import com.intellij.remoteServer.ServerType;
import com.intellij.remoteServer.configuration.RemoteServer;
import com.intellij.remoteServer.configuration.ServerConfiguration;
import com.intellij.remoteServer.impl.configuration.RemoteServerImpl;
import com.intellij.remoteServer.runtime.ServerConnection;
import com.intellij.remoteServer.runtime.ServerConnectionManager;
import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager;
@@ -27,10 +34,12 @@ import com.intellij.remoteServer.runtime.deployment.DeploymentTask;
import com.intellij.remoteServer.runtime.log.LoggingHandler;
import com.intellij.remoteServer.runtime.ui.RemoteServersView;
import com.intellij.remoteServer.util.*;
import com.intellij.ui.HyperlinkLabel;
import com.intellij.util.ParameterizedRunnable;
import org.jetbrains.annotations.NotNull;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.io.File;
/**
@@ -63,6 +72,13 @@ public class SshKeyChecker {
}
}
public <C extends ServerConfiguration> void setupUploadLabel(HyperlinkLabel label,
UnnamedConfigurable serverConfigurable,
C serverConfiguration,
ServerType<C> serverType) {
new ConfigurableHandler<C>(label, serverConfigurable, serverConfiguration, serverType);
}
private class ServerHandler extends HandlerBase {
private final CloudNotifier myNotifier;
@@ -210,6 +226,62 @@ public class SshKeyChecker {
}
}
private class ConfigurableHandler<C extends ServerConfiguration> extends HandlerBase implements HyperlinkListener {
private final UnnamedConfigurable myServerConfigurable;
private final C myServerConfiguration;
private final ServerType<C> myServerType;
private final HyperlinkLabel myLabel;
public ConfigurableHandler(HyperlinkLabel label,
final UnnamedConfigurable serverConfigurable,
C serverConfiguration,
ServerType<C> serverType) {
myServerConfigurable = serverConfigurable;
myServerConfiguration = serverConfiguration;
myServerType = serverType;
label.setHyperlinkText("Upload Public SSH Key");
label.addHyperlinkListener(this);
myLabel = label;
}
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
chooseKey();
}
@Override
protected void uploadKey(final File sskKey) {
try {
myServerConfigurable.apply();
}
catch (ConfigurationException e) {
Messages.showErrorDialog("Cannot upload SSH key: " + e.getMessage(), e.getTitle());
return;
}
RemoteServer<C> server = new RemoteServerImpl<C>("<temp server to upload ssh key>", myServerType, myServerConfiguration);
CloudConnectionTask task = new CloudConnectionTask(null, "Uploading SSH key", server) {
@Override
protected Object run(CloudServerRuntimeInstance serverRuntime) throws ServerRuntimeException {
((SshKeyAwareServerRuntime)serverRuntime).addSshKey(sskKey);
return null;
}
};
task.performSync();
task.showMessageDialog(myLabel, "SSH key was uploaded", "Public SSH Key");
}
@Override
protected Project getProject() {
return null;
}
}
private static abstract class HandlerBase {
protected void chooseKey() {