From 44e7c25e122a86e7fd47825586cbd203cc7aae64 Mon Sep 17 00:00:00 2001 From: nik Date: Wed, 10 Aug 2011 11:00:36 +0400 Subject: [PATCH] show detecting excludes configuration as a node in 'facets' tree --- .../EditFrameworkDetectionExcludesAction.java | 44 --------- .../FacetStructureConfigurable.java | 5 +- .../FrameworkDetectionConfigurable.java | 95 +++++++++++++++++++ .../DetectionExcludesConfigurable.java | 2 + .../DetectionExcludesConfigurationImpl.java | 6 +- .../impl/exclude/ExcludeListItem.java | 4 +- .../exclude/ExcludesConfigurationState.java | 3 +- .../com/intellij/openapi/util/Comparing.java | 5 - .../openapi/util/text/StringUtil.java | 5 + 9 files changed, 112 insertions(+), 57 deletions(-) delete mode 100644 java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/EditFrameworkDetectionExcludesAction.java create mode 100644 java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FrameworkDetectionConfigurable.java diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/EditFrameworkDetectionExcludesAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/EditFrameworkDetectionExcludesAction.java deleted file mode 100644 index 5d2c911170cc..000000000000 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/EditFrameworkDetectionExcludesAction.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2000-2011 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.openapi.roots.ui.configuration.projectRoot; - -import com.intellij.framework.detection.DetectionExcludesConfiguration; -import com.intellij.framework.detection.impl.exclude.DetectionExcludesConfigurable; -import com.intellij.framework.detection.impl.exclude.DetectionExcludesConfigurationImpl; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.options.ShowSettingsUtil; -import com.intellij.openapi.project.DumbAwareAction; -import com.intellij.openapi.project.Project; -import com.intellij.util.PlatformIcons; -import org.jetbrains.annotations.NotNull; - -/** - * @author nik - */ -public class EditFrameworkDetectionExcludesAction extends DumbAwareAction { - private final Project myProject; - - public EditFrameworkDetectionExcludesAction(@NotNull Project project) { - super("Edit Detection Excludes...", null, PlatformIcons.EDIT); - myProject = project; - } - - @Override - public void actionPerformed(AnActionEvent e) { - final DetectionExcludesConfigurationImpl configuration = (DetectionExcludesConfigurationImpl)DetectionExcludesConfiguration.getInstance(myProject); - ShowSettingsUtil.getInstance().editConfigurable(myProject, new DetectionExcludesConfigurable(myProject, configuration)); - } -} diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java index d4036fdd8845..3fd5de937fb2 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java @@ -43,6 +43,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.tree.DefaultTreeModel; import java.awt.*; import java.util.*; import java.util.List; @@ -83,6 +84,8 @@ public class FacetStructureConfigurable extends BaseStructureConfigurable { if (!InvalidFacetManager.getInstance(myProject).getInvalidFacets().isEmpty()) { addFacetTypeNode(InvalidFacetType.getInstance()); } + myRoot.add(new MyNode(new FrameworkDetectionConfigurable(myProject))); + ((DefaultTreeModel)myTree.getModel()).reload(); } private void addFacetTypeNode(FacetType facetType) { @@ -182,8 +185,6 @@ public class FacetStructureConfigurable extends BaseStructureConfigurable { actions.add(new MyRemoveAction()); actions.add(Separator.getInstance()); addCollapseExpandActions(actions); - actions.add(Separator.getInstance()); - actions.add(new EditFrameworkDetectionExcludesAction(myProject)); return actions; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FrameworkDetectionConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FrameworkDetectionConfigurable.java new file mode 100644 index 000000000000..fc183b7eb9ec --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FrameworkDetectionConfigurable.java @@ -0,0 +1,95 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.roots.ui.configuration.projectRoot; + +import com.intellij.framework.detection.DetectionExcludesConfiguration; +import com.intellij.framework.detection.impl.exclude.DetectionExcludesConfigurable; +import com.intellij.framework.detection.impl.exclude.DetectionExcludesConfigurationImpl; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.NamedConfigurable; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** + * @author nik + */ +public class FrameworkDetectionConfigurable extends NamedConfigurable { + private final DetectionExcludesConfiguration myExcludesConfiguration; + private final DetectionExcludesConfigurable myConfigurable; + + public FrameworkDetectionConfigurable(@NotNull Project project) { + myExcludesConfiguration = DetectionExcludesConfiguration.getInstance(project); + myConfigurable = new DetectionExcludesConfigurable(project, (DetectionExcludesConfigurationImpl)myExcludesConfiguration); + } + + @Override + public void setDisplayName(String name) { + } + + @Override + public DetectionExcludesConfiguration getEditableObject() { + return myExcludesConfiguration; + } + + @Override + public String getBannerSlogan() { + return "Framework Detection"; + } + + @Override + public JComponent createOptionsPanel() { + return myConfigurable.createComponent(); + } + + @Nls + @Override + public String getDisplayName() { + return "Detection"; + } + + @Override + public Icon getIcon() { + return myConfigurable.getIcon(); + } + + @Override + public String getHelpTopic() { + return myConfigurable.getHelpTopic(); + } + + @Override + public boolean isModified() { + return myConfigurable.isModified(); + } + + @Override + public void apply() throws ConfigurationException { + myConfigurable.apply(); + } + + @Override + public void reset() { + myConfigurable.reset(); + } + + @Override + public void disposeUIResources() { + myConfigurable.disposeUIResources(); + } +} diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurable.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurable.java index 370d40131de6..cd2fb1e1483f 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurable.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurable.java @@ -59,6 +59,7 @@ public class DetectionExcludesConfigurable implements Configurable { @Nls @Override + @NotNull public JComponent createComponent() { myMainPanel = new JPanel(new BorderLayout()); final JBList excludesList = new JBList(myModel); @@ -78,6 +79,7 @@ public class DetectionExcludesConfigurable implements Configurable { doAddAction(button); } }); + myMainPanel.add(new JLabel("Exclude from detection:"), BorderLayout.NORTH); myMainPanel.add(decorator.createPanel()); return myMainPanel; } diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurationImpl.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurationImpl.java index 677f1e8db3f5..986ad0d16e23 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurationImpl.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurationImpl.java @@ -23,7 +23,7 @@ import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; @@ -180,7 +180,7 @@ public class DetectionExcludesConfigurationImpl extends DetectionExcludesConfigu final ExcludesConfigurationState state = new ExcludesConfigurationState(); state.getFrameworkTypes().addAll(myExcludedFrameworks); - Collections.sort(state.getFrameworkTypes()); + Collections.sort(state.getFrameworkTypes(), String.CASE_INSENSITIVE_ORDER); for (String typeId : myExcludedFiles.keySet()) { final VirtualFilePointerContainer container = myExcludedFiles.get(typeId); @@ -191,7 +191,7 @@ public class DetectionExcludesConfigurationImpl extends DetectionExcludesConfigu Collections.sort(state.getFiles(), new Comparator() { @Override public int compare(ExcludedFileState o1, ExcludedFileState o2) { - return Comparing.comparePairs(o1.getUrl(), o1.getFrameworkType(), o2.getUrl(), o2.getFrameworkType()); + return StringUtil.comparePairs(o1.getFrameworkType(), o1.getUrl(), o2.getFrameworkType(), o2.getUrl(), true); } }); return state; diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ExcludeListItem.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ExcludeListItem.java index 41700ac5a321..170b8b203666 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ExcludeListItem.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ExcludeListItem.java @@ -15,7 +15,7 @@ */ package com.intellij.framework.detection.impl.exclude; -import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.ColoredListCellRenderer; import org.jetbrains.annotations.Nullable; @@ -28,7 +28,7 @@ abstract class ExcludeListItem { public static final Comparator COMPARATOR = new Comparator() { @Override public int compare(ExcludeListItem o1, ExcludeListItem o2) { - return Comparing.comparePairs(o1.getPresentableFrameworkName(), o1.getFileUrl(), o2.getPresentableFrameworkName(), o2.getFileUrl()); + return StringUtil.comparePairs(o1.getPresentableFrameworkName(), o1.getFileUrl(), o2.getPresentableFrameworkName(), o2.getFileUrl(), true); } }; diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ExcludesConfigurationState.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ExcludesConfigurationState.java index 828c153dd696..fd822649dbd8 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ExcludesConfigurationState.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ExcludesConfigurationState.java @@ -15,6 +15,7 @@ */ package com.intellij.framework.detection.impl.exclude; +import com.intellij.openapi.util.Comparing; import com.intellij.util.xmlb.annotations.AbstractCollection; import com.intellij.util.xmlb.annotations.Property; @@ -54,7 +55,7 @@ public class ExcludesConfigurationState { if (!(o instanceof ExcludesConfigurationState)) return false; ExcludesConfigurationState state = (ExcludesConfigurationState)o; - return myFiles.equals(state.myFiles) && myFrameworkTypes.equals(state.myFrameworkTypes); + return Comparing.haveEqualElements(myFiles, state.myFiles) && Comparing.haveEqualElements(myFrameworkTypes, state.myFrameworkTypes); } @Override diff --git a/platform/util/src/com/intellij/openapi/util/Comparing.java b/platform/util/src/com/intellij/openapi/util/Comparing.java index 21f01c0d8ae3..f87f848cd1b3 100644 --- a/platform/util/src/com/intellij/openapi/util/Comparing.java +++ b/platform/util/src/com/intellij/openapi/util/Comparing.java @@ -168,9 +168,4 @@ public class Comparing { if (o2 == null) return 1; return o1.compareTo(o2); } - - public static , S extends Comparable> int comparePairs(F aFirst, S aSecond, F bFirst, S bSecond) { - final int compare = compare(aFirst, bFirst); - return compare != 0 ? compare : compare(aSecond, bSecond); - } } diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java index 2d3b89ff5e57..e1f5407da39f 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -1965,6 +1965,11 @@ public class StringUtil { return ignoreCase ? s1.compareToIgnoreCase(s2) : s1.compareTo(s2); } + public static int comparePairs(@Nullable String s1, @Nullable String t1, @Nullable String s2, @Nullable String t2, boolean ignoreCase) { + final int compare = compare(s1, s2, ignoreCase); + return compare != 0 ? compare : compare(t1, t2, ignoreCase); + } + public static int hashCode(@NotNull CharSequence s) { return stringHashCode(s); }