remote servers: edit server settings from run configuration

This commit is contained in:
nik
2013-08-15 12:25:29 +04:00
parent cba9991727
commit 3385890eb9
3 changed files with 84 additions and 27 deletions
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -30,12 +31,23 @@ import java.util.Set;
*/
public class RemoteServerListConfigurable extends MasterDetailsComponent implements OptionalConfigurable, SearchableConfigurable {
private final RemoteServersManager myServersManager;
@Nullable private final ServerType<?> myServerType;
private RemoteServer<?> myLastSelectedServer;
public RemoteServerListConfigurable(RemoteServersManager manager) {
public RemoteServerListConfigurable(@NotNull RemoteServersManager manager) {
this(manager, null);
}
private RemoteServerListConfigurable(@NotNull RemoteServersManager manager, @Nullable ServerType<?> type) {
myServersManager = manager;
myServerType = type;
initTree();
}
public static RemoteServerListConfigurable createConfigurable(@NotNull ServerType<?> type) {
return new RemoteServerListConfigurable(RemoteServersManager.getInstance(), type);
}
@Nls
@Override
public String getDisplayName() {
@@ -45,12 +57,23 @@ public class RemoteServerListConfigurable extends MasterDetailsComponent impleme
@Override
public void reset() {
myRoot.removeAllChildren();
for (RemoteServer<?> server : myServersManager.getServers()) {
List<RemoteServer<?>> servers = getServers();
for (RemoteServer<?> server : servers) {
addServerNode(server, false);
}
super.reset();
}
private List<RemoteServer<?>> getServers() {
if (myServerType == null) {
return myServersManager.getServers();
}
else {
//code won't compile without this ugly cast (at least in jdk 1.6)
return (List<RemoteServer<?>>)((List)myServersManager.getServers(myServerType));
}
}
private MyNode addServerNode(RemoteServer<?> server, boolean isNew) {
MyNode node = new MyNode(new RemoteServerConfigurable(server, TREE_UPDATER, isNew));
addNode(node, myRoot);
@@ -77,7 +100,7 @@ public class RemoteServerListConfigurable extends MasterDetailsComponent impleme
}
List<RemoteServer<?>> toDelete = new ArrayList<RemoteServer<?>>();
for (RemoteServer<?> server : myServersManager.getServers()) {
for (RemoteServer<?> server : getServers()) {
if (!servers.contains(server)) {
toDelete.add(server);
}
@@ -90,7 +113,7 @@ public class RemoteServerListConfigurable extends MasterDetailsComponent impleme
@Override
public void apply() throws ConfigurationException {
super.apply();
Set<RemoteServer<?>> servers = new HashSet<RemoteServer<?>>(myServersManager.getServers());
Set<RemoteServer<?>> servers = new HashSet<RemoteServer<?>>(getServers());
for (NamedConfigurable<RemoteServer<?>> configurable : getConfiguredServers()) {
RemoteServer<?> server = configurable.getEditableObject();
server.setName(configurable.getDisplayName());
@@ -104,7 +127,12 @@ public class RemoteServerListConfigurable extends MasterDetailsComponent impleme
@Override
protected ArrayList<AnAction> createActions(boolean fromPopup) {
ArrayList<AnAction> actions = new ArrayList<AnAction>();
actions.add(new AddRemoteServerGroup());
if (myServerType == null) {
actions.add(new AddRemoteServerGroup());
}
else {
actions.add(new AddRemoteServerAction(myServerType, IconUtil.getAddIcon()));
}
actions.add(new MyDeleteAction());
return actions;
}
@@ -119,6 +147,18 @@ public class RemoteServerListConfigurable extends MasterDetailsComponent impleme
return true;
}
@Override
public void disposeUIResources() {
Object selectedObject = getSelectedObject();
myLastSelectedServer = selectedObject instanceof RemoteServer<?> ? (RemoteServer)selectedObject : null;
super.disposeUIResources();
}
@Nullable
public RemoteServer<?> getLastSelectedServer() {
return myLastSelectedServer;
}
private List<NamedConfigurable<RemoteServer<?>>> getConfiguredServers() {
List<NamedConfigurable<RemoteServer<?>>> configurables = new ArrayList<NamedConfigurable<RemoteServer<?>>>();
for (int i = 0; i < myRoot.getChildCount(); i++) {
@@ -140,7 +180,7 @@ public class RemoteServerListConfigurable extends MasterDetailsComponent impleme
ServerType[] serverTypes = ServerType.EP_NAME.getExtensions();
AnAction[] actions = new AnAction[serverTypes.length];
for (int i = 0; i < serverTypes.length; i++) {
actions[i] = new AddRemoteServerAction(serverTypes[i]);
actions[i] = new AddRemoteServerAction(serverTypes[i], serverTypes[i].getIcon());
}
return actions;
}
@@ -159,8 +199,8 @@ public class RemoteServerListConfigurable extends MasterDetailsComponent impleme
private class AddRemoteServerAction extends DumbAwareAction {
private final ServerType<?> myServerType;
private AddRemoteServerAction(ServerType<?> serverType) {
super(serverType.getPresentableName(), null, serverType.getIcon());
private AddRemoteServerAction(ServerType<?> serverType, final Icon icon) {
super(serverType.getPresentableName(), null, icon);
myServerType = serverType;
}
@@ -79,7 +79,7 @@ public class DeployToServerRunConfiguration<S extends ServerConfiguration, D ext
@NotNull
@Override
public SettingsEditor<DeployToServerRunConfiguration> getConfigurationEditor() {
return new DeployToServerSettingsEditor(myServerType, myDeploymentConfigurator, getProject());
return new DeployToServerSettingsEditor(myServerType, myDeploymentConfigurator);
}
@Nullable
@@ -17,7 +17,7 @@ package com.intellij.remoteServer.impl.configuration.deployment;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
@@ -28,10 +28,8 @@ import com.intellij.remoteServer.configuration.ServerConfiguration;
import com.intellij.remoteServer.configuration.deployment.DeploymentConfiguration;
import com.intellij.remoteServer.configuration.deployment.DeploymentConfigurator;
import com.intellij.remoteServer.configuration.deployment.DeploymentSource;
import com.intellij.ui.ColoredListCellRendererWrapper;
import com.intellij.ui.ListCellRendererWrapper;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.ui.SortedComboBoxModel;
import com.intellij.remoteServer.impl.configuration.RemoteServerListConfigurable;
import com.intellij.ui.*;
import com.intellij.util.ui.FormBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -46,29 +44,39 @@ import java.util.Comparator;
* @author nik
*/
public class DeployToServerSettingsEditor<S extends ServerConfiguration, D extends DeploymentConfiguration> extends SettingsEditor<DeployToServerRunConfiguration<S, D>> {
private final ServerType<S> myServerType;
private final DeploymentConfigurator<D> myDeploymentConfigurator;
private ComboBox myServerComboBox;
private ComboBox mySourceComboBox;
private final ComboboxWithBrowseButton myServerComboBox;
private final ComboBox mySourceComboBox;
private final SortedComboBoxModel<String> myServerListModel;
private final SortedComboBoxModel<DeploymentSource> mySourceListModel;
private final JPanel myDeploymentSettingsComponent;
private SettingsEditor<D> myDeploymentSettingsEditor;
private DeploymentSource myLastSelection;
private JPanel myDeploymentSettingsComponent;
public DeployToServerSettingsEditor(final ServerType<S> type, DeploymentConfigurator<D> deploymentConfigurator, Project project) {
public DeployToServerSettingsEditor(final ServerType<S> type, DeploymentConfigurator<D> deploymentConfigurator) {
myServerType = type;
myDeploymentConfigurator = deploymentConfigurator;
myServerListModel = new SortedComboBoxModel<String>(String.CASE_INSENSITIVE_ORDER);
for (RemoteServer<? extends ServerConfiguration> server : RemoteServersManager.getInstance().getServers(type)) {
myServerListModel.add(server.getName());
}
myServerComboBox = new ComboBox(myServerListModel);
myServerComboBox.setRenderer(new ColoredListCellRendererWrapper<String>() {
myServerListModel = new SortedComboBoxModel<String>(String.CASE_INSENSITIVE_ORDER);
myServerComboBox = new ComboboxWithBrowseButton(new ComboBox(myServerListModel));
fillApplicationServersList(null);
myServerComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
RemoteServerListConfigurable configurable = RemoteServerListConfigurable.createConfigurable(type);
if (ShowSettingsUtil.getInstance().editConfigurable(myServerComboBox, configurable)) {
fillApplicationServersList(configurable.getLastSelectedServer());
}
}
});
myServerComboBox.getComboBox().setRenderer(new ColoredListCellRendererWrapper<String>() {
@Override
protected void doCustomize(JList list, String value, int index, boolean selected, boolean hasFocus) {
if (value == null) return;
SimpleTextAttributes attributes = RemoteServersManager.getInstance().findByName(value, type) == null
? SimpleTextAttributes.ERROR_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES;
RemoteServer<S> server = RemoteServersManager.getInstance().findByName(value, type);
SimpleTextAttributes attributes = server == null ? SimpleTextAttributes.ERROR_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES;
setIcon(server != null ? server.getType().getIcon() : null);
append(value, attributes);
}
});
@@ -99,6 +107,15 @@ public class DeployToServerSettingsEditor<S extends ServerConfiguration, D exten
});
}
private void fillApplicationServersList(@Nullable RemoteServer<?> newSelection) {
String oldSelection = myServerListModel.getSelectedItem();
myServerListModel.clear();
for (RemoteServer<?> server : RemoteServersManager.getInstance().getServers(myServerType)) {
myServerListModel.add(server.getName());
}
myServerComboBox.getComboBox().setSelectedItem(newSelection != null ? newSelection.getName() : oldSelection);
}
private void updateDeploymentSettings(@Nullable D configuration) {
DeploymentSource selected = mySourceListModel.getSelectedItem();
if (Comparing.equal(selected, myLastSelection)) {
@@ -126,7 +143,7 @@ public class DeployToServerSettingsEditor<S extends ServerConfiguration, D exten
if (serverName != null && !myServerListModel.getItems().contains(serverName)) {
myServerListModel.add(serverName);
}
myServerComboBox.setSelectedItem(serverName);
myServerComboBox.getComboBox().setSelectedItem(serverName);
mySourceComboBox.setSelectedItem(configuration.getDeploymentSource());
updateDeploymentSettings(configuration.getDeploymentConfiguration());
}