From f72c4e8f22ac99fd52a4793523897cf692efc1d0 Mon Sep 17 00:00:00 2001 From: Evgeny Zakrevsky Date: Fri, 27 Jan 2012 23:35:18 +0400 Subject: [PATCH] ToolbarDecorator for PathEditor --- .../JavadocOrderRootTypeUIFactory.java | 1 - .../src/com/intellij/util/PlatformIcons.java | 1 + platform/icons/src/tables/url.png | Bin 0 -> 922 bytes .../openapi/projectRoots/ui/PathEditor.java | 123 +++++++----------- .../projectRoots/ui/SdkPathEditor.java | 1 - .../src/messages/ProjectBundle.properties | 2 +- 6 files changed, 49 insertions(+), 79 deletions(-) create mode 100644 platform/icons/src/tables/url.png diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/JavadocOrderRootTypeUIFactory.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/JavadocOrderRootTypeUIFactory.java index 803ea45c1ae3..728fd1617933 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/JavadocOrderRootTypeUIFactory.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/JavadocOrderRootTypeUIFactory.java @@ -72,7 +72,6 @@ public class JavadocOrderRootTypeUIFactory implements OrderRootTypeUIFactory { if(virtualFile != null){ addElement(virtualFile); setModified(true); - updateButtons(); requestDefaultFocus(); setSelectedRoots(new Object[]{virtualFile}); } diff --git a/platform/core-api/src/com/intellij/util/PlatformIcons.java b/platform/core-api/src/com/intellij/util/PlatformIcons.java index 0daa134d2349..12ec1feb41e2 100644 --- a/platform/core-api/src/com/intellij/util/PlatformIcons.java +++ b/platform/core-api/src/com/intellij/util/PlatformIcons.java @@ -122,6 +122,7 @@ public interface PlatformIcons { Icon TABLE_EXCEPTION = IconLoader.getIcon("/tables/exception.png"); Icon TABLE_EDIT_ROW = IconLoader.getIcon("/tables/edit.png"); Icon TABLE_ANALYZE = IconLoader.getIcon("/tables/analyze.png"); + Icon TABLE_URL = IconLoader.getIcon("/tables/url.png"); Icon COMBOBOX_ARROW_ICON = IconLoader.getIcon("/general/comboArrow.png"); diff --git a/platform/icons/src/tables/url.png b/platform/icons/src/tables/url.png new file mode 100644 index 0000000000000000000000000000000000000000..ac9329cedeba376072b86567216b5b43082cd54a GIT binary patch literal 922 zcmV;L17-Y)P)1 z(*qDda07zV`%*c6-0lc4eko{aC&kDuEY83uEXDATorU55*EJZ*nG6z2N(?;zKQl=1eqvx{`N+WV^#Ty@ zV_^8UpW*%`4u<@tq4!>VlL`WP2Oxl$K&F8F{FYl<@sfTY!&gB=24&ty3=(`FfSUg@ z{P_iv2fE@f3y{IipeXT)AyE6gJW!hpNH0JDv499rfPLgwVgASbkHLy-IRo2&W(Edk zTZX@X85tNESQ*$jWEmJ3RT%y;US(ils);n4!r+6xdsU;{v*{hou5k@@>I z2EkujfX)?TU|^SKC~rRpl>N)V@c#$H|9?OS{E1}v_m73)H_$a-ejH%mzJ1FnfB=FR z0F0`iKmIUW`@qfc;QbE<>HilQ*m#A38krf|>RN#sfNK8!2h+d){Ac(DWCOJ@hDN6{ z0R#}t1=pEAzSlVUP?xciqlm$k?-)aZ@id_20SteDHoyJym!YY1D#Pu&_rWm+iny6m zd%$df00IXhD3J(!fA;s=>vs$r&L}ao9`$J>Wo3~w2J{`|=B{?j*x%TKI;1~7n~{q5I(hQr5BF|1j=n!(dA z1Z=|Je~^R(5I|r9K=H}(_fN0f+shxg|G#GV$iU37;jJOVw?EQg|H3qT0X1vt88b-A z$}>P6zyJ_HOt2(*W^>DQ?qA=kWZz%8EAson-y;m13@`rhGyDMt+Mz>-!J0LInn5lK zicV*MWdMKxVnNOrXEruXH}kDK#{2D#OVD?TqDy~%Ndh%6w$zsZ1M@#9NErV9hXf)l w3jqWWBfjh$m{@h}{^RE$SE4I|^8o@30RK68E9-;3xBvhE07*qoM6N<$f;2F;5dZ)H literal 0 HcmV?d00001 diff --git a/platform/lang-api/src/com/intellij/openapi/projectRoots/ui/PathEditor.java b/platform/lang-api/src/com/intellij/openapi/projectRoots/ui/PathEditor.java index 24c02608ae4a..bf285be9c8a4 100644 --- a/platform/lang-api/src/com/intellij/openapi/projectRoots/ui/PathEditor.java +++ b/platform/lang-api/src/com/intellij/openapi/projectRoots/ui/PathEditor.java @@ -16,7 +16,8 @@ package com.intellij.openapi.projectRoots.ui; import com.intellij.ide.DataManager; -import com.intellij.openapi.actionSystem.CommonShortcuts; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CustomShortcutSet; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; @@ -33,8 +34,7 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.ex.http.HttpFileSystem; -import com.intellij.ui.ListUtil; -import com.intellij.ui.ScrollPaneFactory; +import com.intellij.ui.*; import com.intellij.ui.components.JBList; import com.intellij.util.PlatformIcons; import com.intellij.util.containers.HashSet; @@ -43,12 +43,7 @@ import gnu.trove.TIntArrayList; import org.jetbrains.annotations.NotNull; import javax.swing.*; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -62,10 +57,7 @@ public class PathEditor { public static final Color INVALID_COLOR = new Color(210, 0, 0); protected JPanel myPanel; - private JButton myRemoveButton; - private JButton myAddButton; - private JButton mySpecifyUrlButton; - private JList myList; + private JBList myList; private DefaultListModel myModel; private final Set myAllFiles = new HashSet(); private boolean myModified = false; @@ -124,61 +116,68 @@ public class PathEditor { addElement(file); } setModified(false); - updateButtons(); } public JComponent createComponent() { - myPanel = new JPanel(new GridBagLayout()); + myList = new JBList(getListModel()); + myList.setCellRenderer(createListCellRenderer(myList)); - myList = createList(myPanel, getListModel()); - - createButtons(myPanel); - - return myPanel; - } - - protected void createButtons(@NotNull JPanel panel) { - Insets anInsets = new Insets(2, 2, 2, 2); - myRemoveButton = new JButton(ProjectBundle.message("button.remove")); - myAddButton = new JButton(ProjectBundle.message("button.add")); - mySpecifyUrlButton = new JButton(ProjectBundle.message("sdk.paths.specify.url.button")); - - mySpecifyUrlButton.setVisible(isShowUrlButton()); - - myAddButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { + ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(myList).disableUpDownActions(); + toolbarDecorator.setAddAction(new AnActionButtonRunnable() { + @Override + public void run(AnActionButton button) { final VirtualFile[] added = doAdd(); if (added.length > 0) { setModified(true); } - updateButtons(); requestDefaultFocus(); setSelectedRoots(added); } }); - UIUtil.addKeyboardShortcut(myList, myAddButton, CommonShortcuts.getInsertKeystroke()); - myRemoveButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { + + toolbarDecorator.setRemoveAction(new AnActionButtonRunnable() { + @Override + public void run(AnActionButton button) { int[] idxs = myList.getSelectedIndices(); doRemoveItems(idxs, myList); } }); - UIUtil.addKeyboardShortcut(myList, myRemoveButton, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); - mySpecifyUrlButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onSpecifyUrlButtonClicked(); + + if (isShowUrlButton()) { + AnActionButton specifyUrlButton = new AnActionButton(ProjectBundle.message("sdk.paths.specify.url.button"), PlatformIcons.TABLE_URL) { + @Override + public void actionPerformed(AnActionEvent e) { + onSpecifyUrlButtonClicked(); + } + }; + specifyUrlButton.setShortcut(CustomShortcutSet.fromString("alt S")); + specifyUrlButton.addCustomUpdater(new AnActionButtonUpdater() { + @Override + public boolean isEnabled(AnActionEvent e) { + return myEnabled && !isUrlInserted(); + } + }); + toolbarDecorator.addExtraAction(specifyUrlButton); + } + + myPanel = toolbarDecorator.createPanel(); + myPanel.setBorder(null); + + ToolbarDecorator.findAddButton(myPanel).addCustomUpdater(new AnActionButtonUpdater() { + @Override + public boolean isEnabled(AnActionEvent e) { + return myEnabled; + } + }); + ToolbarDecorator.findRemoveButton(myPanel).addCustomUpdater(new AnActionButtonUpdater() { + @Override + public boolean isEnabled(AnActionEvent e) { + Object[] values = getSelectedRoots(); + return values.length > 0 && myEnabled; } }); - - panel.add(myAddButton, - new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, anInsets, 0, 0)); - panel.add(myRemoveButton, - new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, anInsets, 0, 0)); - panel.add(mySpecifyUrlButton, - new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, anInsets, 0, 0)); - panel.add(Box.createRigidArea(new Dimension(mySpecifyUrlButton.getPreferredSize().width, 4)), - new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, anInsets, 0, 0)); + return myPanel; } protected void doRemoveItems(int[] idxs, JList list) { @@ -190,24 +189,6 @@ public class PathEditor { return new DefaultListModel(); } - protected JBList createList(JPanel panel, DefaultListModel listModel) { - Insets anInsets = new Insets(2, 2, 2, 2); - - JBList list = new JBList(listModel); - list.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent e) { - updateButtons(); - } - }); - list.setCellRenderer(createListCellRenderer(list)); - - JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(list); - scrollPane.setPreferredSize(new Dimension(500, 500)); - panel - .add(scrollPane, new GridBagConstraints(0, 0, 1, 8, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, anInsets, 0, 0)); - return list; - } - protected ListCellRenderer createListCellRenderer(JBList list) { return new MyCellRenderer(); } @@ -217,7 +198,6 @@ public class PathEditor { if (removedItems.size() > 0) { setModified(true); } - updateButtons(); requestDefaultFocus(); } @@ -254,14 +234,6 @@ public class PathEditor { return files; } - public void updateButtons() { - Object[] values = getSelectedRoots(); - myRemoveButton.setEnabled((values.length > 0) && myEnabled); - myAddButton.setEnabled(myEnabled); - mySpecifyUrlButton.setEnabled(myEnabled && !isUrlInserted()); - mySpecifyUrlButton.setVisible(isShowUrlButton()); - } - private boolean isUrlInserted() { if (getRowCount() > 0) { return ((VirtualFile)getListModel().lastElement()).getFileSystem() instanceof HttpFileSystem; @@ -285,7 +257,6 @@ public class PathEditor { } if (added) { setModified(true); - updateButtons(); } } diff --git a/platform/lang-api/src/com/intellij/openapi/projectRoots/ui/SdkPathEditor.java b/platform/lang-api/src/com/intellij/openapi/projectRoots/ui/SdkPathEditor.java index 09621f3c8fc5..78eaf1867a08 100644 --- a/platform/lang-api/src/com/intellij/openapi/projectRoots/ui/SdkPathEditor.java +++ b/platform/lang-api/src/com/intellij/openapi/projectRoots/ui/SdkPathEditor.java @@ -46,7 +46,6 @@ public class SdkPathEditor extends PathEditor { sdkModificator.addRoot(getValueAt(i), myOrderRootType); } setModified(false); - updateButtons(); } public void reset(@Nullable SdkModificator modificator) { diff --git a/platform/platform-resources-en/src/messages/ProjectBundle.properties b/platform/platform-resources-en/src/messages/ProjectBundle.properties index ab1c4ae0ee85..694fc07924ea 100644 --- a/platform/platform-resources-en/src/messages/ProjectBundle.properties +++ b/platform/platform-resources-en/src/messages/ProjectBundle.properties @@ -64,7 +64,7 @@ sdk.list.name.required.error=Please specify SDK name sdk.list.unique.name.required.error=Please specify a different SDK name button.add=Add button.remove=Remove -sdk.paths.specify.url.button=&Specify URL... +sdk.paths.specify.url.button=Specify URL... sdk.configure.title=Configure SDK sdk.configure.save.settings.error=Cannot Save Settings sdk.configure.editor.title=SDK Editor