From 3a72bf03bbddd5e1d9233a40529cf199caf0970b Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Fri, 23 Oct 2009 20:04:29 +0400 Subject: [PATCH] SFTP support (WI-467) --- .../intellij/openapi/ui/NamedItemsListEditor.java | 71 +++++++++++++++++----- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java b/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java index 6169aa1760..cd83e19c9c 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java @@ -25,19 +25,19 @@ import com.intellij.openapi.actionSystem.CommonShortcuts; import com.intellij.openapi.actionSystem.CustomShortcutSet; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.UnnamedConfigurable; -import com.intellij.openapi.util.Cloner; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Condition; -import com.intellij.openapi.util.Factory; +import com.intellij.openapi.util.*; import com.intellij.util.Icons; +import com.intellij.util.ui.tree.TreeUtil; import gnu.trove.Equality; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.TreeNode; import java.awt.event.KeyEvent; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public abstract class NamedItemsListEditor extends MasterDetailsComponent { @@ -62,7 +62,7 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { myOriginalItems = items; myResultItems = items; reset(); - + initTree(); } @@ -138,14 +138,36 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { return true; } - protected abstract UnnamedConfigurable createConfigurable(T item); + protected abstract UnnamedConfigurable createConfigurable(T item); @Override protected void onItemDeleted(Object item) { myItems.remove((T)item); } - private class ItemConfigurable extends NamedConfigurable { + protected void setDisplayName(T item, String name) { + myNamer.setName(item, name); + } + + @Nullable + protected UnnamedConfigurable getItemConfigurable(final T item) { + final Ref result = new Ref(); + TreeUtil.traverse((TreeNode)myTree.getModel().getRoot(), new TreeUtil.Traverse() { + public boolean accept(Object node) { + final NamedConfigurable configurable = (NamedConfigurable)((DefaultMutableTreeNode)node).getUserObject(); + if (configurable.getEditableObject() == item) { + result.set(((ItemConfigurable)configurable).myConfigurable); + return false; + } + else { + return true; + } + } + }); + return result.get(); + } + + private class ItemConfigurable extends NamedConfigurable { private final T myItem; private final UnnamedConfigurable myConfigurable; @@ -156,7 +178,7 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { } public void setDisplayName(String name) { - myNamer.setName(myItem, name); + NamedItemsListEditor.this.setDisplayName(myItem, name); } public Object getEditableObject() { @@ -176,6 +198,9 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { } public Icon getIcon() { + if (myConfigurable instanceof Iconable) { + return ((Iconable)myConfigurable).getIcon(0); + } return null; } @@ -216,6 +241,10 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { myResultItems = myItems; } + protected List getCurrentItems() { + return Collections.unmodifiableList(myItems); + } + public List getItems() { return myResultItems; } @@ -239,6 +268,7 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { myNamer.setName(clone, profileName); addNewNode(clone); selectNodeInTree(clone); + onItemCloned(clone); } @@ -248,30 +278,39 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { } } - private class AddAction extends AnAction { + protected void onItemCloned(T clone) { + } + + private class AddAction extends AnAction { public AddAction() { super("Add", "Add", Icons.ADD_ICON); registerCustomShortcutSet(CommonShortcuts.INSERT, myTree); } public void actionPerformed(AnActionEvent event) { - final String name = askForProfileName("Create new {0}"); - if (name == null) return; - createItem(name); + final T newItem = createItem(); + if (newItem != null) { + onItemCreated(newItem); + } } - } public void selectItem(T item) { selectNodeInTree(findByName(myNamer.getName(item))); } - public void createItem(@NotNull String name) { + @Nullable + protected T createItem() { + final String name = askForProfileName("Create new {0}"); + if (name == null) return null; final T newItem = myFactory.create(); myNamer.setName(newItem, name); + return newItem; + } + protected void onItemCreated(T newItem) { addNewNode(newItem); selectNodeInTree(newItem); } -} \ No newline at end of file +} -- 2.11.4.GIT