From 840db70be6d9129808e85de98b07b3f5e0701c46 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 28 Jul 2011 11:37:08 +0400 Subject: [PATCH] new framework detection: editor for excludes --- .../projectRoot/AddFacetOfTypeAction.java | 2 +- .../EditFrameworkDetectionExcludesAction.java | 44 ++++ .../FacetStructureConfigurable.java | 2 + .../detection/FrameworkDetector.java | 17 +- .../impl/FrameworkDetectionManager.java | 2 +- .../impl/FrameworkDetectorRegistry.java | 9 + .../impl/FrameworkDetectorRegistryImpl.java | 33 ++- .../DetectionExcludesConfigurable.java | 222 ++++++++++++++++++ .../DetectionExcludesConfigurationImpl.java | 4 +- .../impl/exclude/ExcludeListItem.java | 45 ++++ .../impl/exclude/InvalidExcludeListItem.java | 60 +++++ .../impl/exclude/ValidExcludeListItem.java | 66 ++++++ 12 files changed, 489 insertions(+), 17 deletions(-) create mode 100644 java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/EditFrameworkDetectionExcludesAction.java create mode 100644 platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurable.java create mode 100644 platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ExcludeListItem.java create mode 100644 platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/InvalidExcludeListItem.java create mode 100644 platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ValidExcludeListItem.java diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/AddFacetOfTypeAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/AddFacetOfTypeAction.java index dc2a14e3567c..41f397ab005a 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/AddFacetOfTypeAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/AddFacetOfTypeAction.java @@ -44,7 +44,7 @@ import java.util.List; * @author nik */ class AddFacetOfTypeAction extends DumbAwareAction { - private FacetStructureConfigurable myFacetStructureConfigurable; + private final FacetStructureConfigurable myFacetStructureConfigurable; AddFacetOfTypeAction(FacetStructureConfigurable facetStructureConfigurable) { super("New Facet", null, PlatformIcons.ADD_ICON); 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 new file mode 100644 index 000000000000..5d2c911170cc --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/EditFrameworkDetectionExcludesAction.java @@ -0,0 +1,44 @@ +/* + * 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 b56c5a1fc4be..3b44253e3729 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 @@ -187,6 +187,8 @@ 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/platform/lang-impl/src/com/intellij/framework/detection/FrameworkDetector.java b/platform/lang-impl/src/com/intellij/framework/detection/FrameworkDetector.java index 9a1bb63a1afd..d457011bb38e 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/FrameworkDetector.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/FrameworkDetector.java @@ -15,6 +15,7 @@ */ package com.intellij.framework.detection; +import com.intellij.framework.FrameworkType; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.vfs.VirtualFile; @@ -30,15 +31,15 @@ import java.util.List; */ public abstract class FrameworkDetector { public static final ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.framework.detector"); - private final String myFrameworkTypeId; + private final String myDetectorId; private final int myDetectorVersion; - protected FrameworkDetector(String frameworkTypeId) { - this(frameworkTypeId, 0); + protected FrameworkDetector(String detectorId) { + this(detectorId, 0); } - protected FrameworkDetector(@NotNull String frameworkTypeId, int detectorVersion) { - myFrameworkTypeId = frameworkTypeId; + protected FrameworkDetector(@NotNull String detectorId, int detectorVersion) { + myDetectorId = detectorId; myDetectorVersion = detectorVersion; } @@ -52,11 +53,13 @@ public abstract class FrameworkDetector { @NotNull FrameworkDetectionContext context); @NotNull - public final String getFrameworkTypeId() { - return myFrameworkTypeId; + public final String getDetectorId() { + return myDetectorId; } public final int getDetectorVersion() { return myDetectorVersion; } + + public abstract FrameworkType getFrameworkType(); } diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionManager.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionManager.java index b4c6a1e3882d..eecbcd6aa9db 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionManager.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionManager.java @@ -157,7 +157,7 @@ public class FrameworkDetectionManager extends AbstractProjectComponent implemen if (detector != null) { excludesConfiguration.removeExcluded(newFiles, detector); if (LOG.isDebugEnabled()) { - LOG.debug("Detector '" + detector.getFrameworkTypeId() + "': " + files.size() + " accepted files, " + newFiles.size() + " files to process"); + LOG.debug("Detector '" + detector.getDetectorId() + "': " + files.size() + " accepted files, " + newFiles.size() + " files to process"); } final List frameworks; if (!newFiles.isEmpty()) { diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectorRegistry.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectorRegistry.java index 150310b939e5..7e0235a7480d 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectorRegistry.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectorRegistry.java @@ -15,6 +15,7 @@ */ package com.intellij.framework.detection.impl; +import com.intellij.framework.FrameworkType; import com.intellij.framework.detection.FrameworkDetector; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.fileTypes.FileType; @@ -22,6 +23,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.List; /** * @author nik @@ -31,6 +33,13 @@ public abstract class FrameworkDetectorRegistry { return ServiceManager.getService(FrameworkDetectorRegistry.class); } + @Nullable + public abstract FrameworkType findFrameworkType(@NotNull String typeId); + + @NotNull + public abstract List getFrameworkTypes(); + + public abstract int getDetectorsVersion(); public abstract int getDetectorId(@NotNull FrameworkDetector detector); diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectorRegistryImpl.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectorRegistryImpl.java index ad0607b6c41b..f7567374f1b5 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectorRegistryImpl.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectorRegistryImpl.java @@ -15,6 +15,7 @@ */ package com.intellij.framework.detection.impl; +import com.intellij.framework.FrameworkType; import com.intellij.framework.detection.FrameworkDetector; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; @@ -47,7 +48,7 @@ public class FrameworkDetectorRegistryImpl extends FrameworkDetectorRegistry { private void loadDetectors() { Map newDetectors = new HashMap(); for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) { - newDetectors.put(detector.getFrameworkTypeId(), detector); + newDetectors.put(detector.getDetectorId(), detector); } myDetectorIds = new TObjectIntHashMap(); @@ -106,10 +107,10 @@ public class FrameworkDetectorRegistryImpl extends FrameworkDetectorRegistry { myDetectorById = new TIntObjectHashMap(); myDetectorsByFileType = new MultiMap(); for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) { - final int id = myDetectorIds.get(detector.getFrameworkTypeId()); + final int id = myDetectorIds.get(detector.getDetectorId()); myDetectorsByFileType.putValue(detector.getFileType(), id); myDetectorById.put(id, detector); - LOG.debug("'" + detector.getFrameworkTypeId() + "' framework detector: id = " + id); + LOG.debug("'" + detector.getDetectorId() + "' framework detector: id = " + id); } } @@ -124,8 +125,8 @@ public class FrameworkDetectorRegistryImpl extends FrameworkDetectorRegistry { final FrameworkDetector[] detectors = FrameworkDetector.EP_NAME.getExtensions(); output.writeInt(detectors.length); for (FrameworkDetector detector : detectors) { - output.writeUTF(detector.getFrameworkTypeId()); - output.writeInt(myDetectorIds.get(detector.getFrameworkTypeId())); + output.writeUTF(detector.getDetectorId()); + output.writeInt(myDetectorIds.get(detector.getDetectorId())); output.writeInt(detector.getDetectorVersion()); } } @@ -146,6 +147,26 @@ public class FrameworkDetectorRegistryImpl extends FrameworkDetectorRegistry { return PathManager.getSystemPath() + File.separator + "frameworks" + File.separator + "detection"; } + @Override + public FrameworkType findFrameworkType(@NotNull String typeId) { + for (FrameworkType type : getFrameworkTypes()) { + if (typeId.equals(type.getId())) { + return type; + } + } + return null; + } + + @NotNull + @Override + public List getFrameworkTypes() { + final List types = new ArrayList(); + for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) { + types.add(detector.getFrameworkType()); + } + return types; + } + @Override public int getDetectorsVersion() { return myDetectorsVersion; @@ -153,7 +174,7 @@ public class FrameworkDetectorRegistryImpl extends FrameworkDetectorRegistry { @Override public int getDetectorId(@NotNull FrameworkDetector detector) { - return myDetectorIds.get(detector.getFrameworkTypeId()); + return myDetectorIds.get(detector.getDetectorId()); } @Override 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 new file mode 100644 index 000000000000..8728090aec82 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurable.java @@ -0,0 +1,222 @@ +/* + * 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.framework.detection.impl.exclude; + +import com.intellij.framework.FrameworkType; +import com.intellij.framework.detection.impl.FrameworkDetectorRegistry; +import com.intellij.openapi.fileChooser.FileChooser; +import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; +import com.intellij.openapi.options.Configurable; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.openapi.ui.popup.PopupStep; +import com.intellij.openapi.ui.popup.util.BaseListPopupStep; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.ui.ColoredListCellRenderer; +import com.intellij.ui.SortedListModel; +import com.intellij.ui.ToolbarDecorator; +import com.intellij.ui.components.JBList; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +/** + * @author nik + */ +public class DetectionExcludesConfigurable implements Configurable { + private final Project myProject; + private final DetectionExcludesConfigurationImpl myConfiguration; + private SortedListModel myModel; + private JPanel myMainPanel; + + public DetectionExcludesConfigurable(@NotNull Project project, @NotNull DetectionExcludesConfigurationImpl configuration) { + myProject = project; + myConfiguration = configuration; + myModel = new SortedListModel(ExcludeListItem.COMPARATOR); + } + + @Nls + @Override + public JComponent createComponent() { + myMainPanel = new JPanel(new BorderLayout()); + final JBList excludesList = new JBList(myModel); + excludesList.setCellRenderer(new ColoredListCellRenderer() { + @Override + protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) { + if (value instanceof ExcludeListItem) { + ((ExcludeListItem)value).renderItem(this); + } + } + }); + final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(excludesList) + .disableUpAction().disableDownAction() + .setAddAction(new Runnable() { + @Override + public void run() { + doAddAction(); + } + }); + myMainPanel.add(decorator.createPanel()); + return myMainPanel; + } + + private void doAddAction() { + final List types = new ArrayList(); + types.addAll(FrameworkDetectorRegistry.getInstance().getFrameworkTypes()); + Collections.sort(types, new Comparator() { + @Override + public int compare(FrameworkType o1, FrameworkType o2) { + return o1.getPresentableName().compareToIgnoreCase(o2.getPresentableName()); + } + }); + types.add(0, null); + JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep("Select Framework", types) { + @Override + public Icon getIconFor(FrameworkType value) { + return value != null ? value.getIcon() : null; + } + + @NotNull + @Override + public String getTextFor(FrameworkType value) { + return value != null ? value.getPresentableName() : "All Frameworks"; + } + + @Override + public boolean hasSubstep(FrameworkType selectedValue) { + return selectedValue != null; + } + + @Override + public PopupStep onChosen(final FrameworkType frameworkType, boolean finalChoice) { + if (frameworkType == null) { + return doFinalStep(new Runnable() { + @Override + public void run() { + chooseDirectoryAndAdd(null); + } + }); + } + else { + return addExcludedFramework(frameworkType); + } + } + }).showInCenterOf(myMainPanel); + } + + private PopupStep addExcludedFramework(final @NotNull FrameworkType frameworkType) { + final String projectItem = "In the whole project"; + return new BaseListPopupStep(null, new String[]{projectItem, "In directory..."}) { + @Override + public PopupStep onChosen(String selectedValue, boolean finalChoice) { + if (selectedValue.equals(projectItem)) { + myModel.add(new ValidExcludeListItem(frameworkType, null)); + return FINAL_CHOICE; + } + else { + return doFinalStep(new Runnable() { + @Override + public void run() { + chooseDirectoryAndAdd(frameworkType); + } + }); + } + } + }; + } + + private void chooseDirectoryAndAdd(final @Nullable FrameworkType type) { + final VirtualFile[] files = FileChooser.chooseFiles(myMainPanel, FileChooserDescriptorFactory.createSingleFolderDescriptor(), myProject.getBaseDir()); + final VirtualFile file = files.length > 0 ? files[0] : null; + if (file != null) { + myModel.add(new ValidExcludeListItem(type, file)); + } + } + + @Override + public boolean isModified() { + return !computeState().equals(myConfiguration.getState()); + } + + @Override + public void apply() { + myConfiguration.loadState(computeState()); + } + + private ExcludesConfigurationState computeState() { + final ExcludesConfigurationState state = new ExcludesConfigurationState(); + for (ExcludeListItem item : myModel.getItems()) { + final String url = item.getFileUrl(); + final String typeId = item.getFrameworkTypeId(); + if (url == null) { + state.getFrameworkTypes().add(typeId); + } + else { + state.getFiles().add(new ExcludedFileState(url, typeId)); + } + } + return state; + } + + @Override + public void reset() { + myModel.clear(); + final ExcludesConfigurationState state = myConfiguration.getState(); + for (String typeId : state.getFrameworkTypes()) { + final FrameworkType frameworkType = FrameworkDetectorRegistry.getInstance().findFrameworkType(typeId); + myModel.add(frameworkType != null ? new ValidExcludeListItem(frameworkType, null) : new InvalidExcludeListItem(typeId, null)); + } + for (ExcludedFileState fileState : state.getFiles()) { + VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(fileState.getUrl()); + final String typeId = fileState.getFrameworkType(); + if (typeId == null) { + myModel.add(file != null ? new ValidExcludeListItem(null, file) : new InvalidExcludeListItem(null, fileState.getUrl())); + } + else { + final FrameworkType frameworkType = FrameworkDetectorRegistry.getInstance().findFrameworkType(typeId); + myModel.add(frameworkType != null && file != null? new ValidExcludeListItem(frameworkType, file) : new InvalidExcludeListItem(typeId, fileState.getUrl())); + } + } + } + + @Override + public void disposeUIResources() { + } + + @Nls + @Override + public String getDisplayName() { + return "Framework Detection Excludes"; + } + + @Override + public Icon getIcon() { + return null; + } + + @Override + public String getHelpTopic() { + return null; + } +} 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 003bba04b14c..9766e7f37b54 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 @@ -114,7 +114,7 @@ public class DetectionExcludesConfigurationImpl extends DetectionExcludesConfigu @Override public void removeExcluded(@NotNull Collection files, @NotNull FrameworkDetector detector) { - if (myExcludedFrameworks.contains(detector.getFrameworkTypeId())) { + if (myExcludedFrameworks.contains(detector.getFrameworkType().getId())) { files.clear(); return; } @@ -122,7 +122,7 @@ public class DetectionExcludesConfigurationImpl extends DetectionExcludesConfigu final Iterator iterator = files.iterator(); while (iterator.hasNext()) { VirtualFile file = iterator.next(); - if (isFileExcluded(file, detector.getFrameworkTypeId())) { + if (isFileExcluded(file, detector.getFrameworkType().getId())) { iterator.remove(); } } 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 new file mode 100644 index 000000000000..41700ac5a321 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ExcludeListItem.java @@ -0,0 +1,45 @@ +/* + * 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.framework.detection.impl.exclude; + +import com.intellij.openapi.util.Comparing; +import com.intellij.ui.ColoredListCellRenderer; +import org.jetbrains.annotations.Nullable; + +import java.util.Comparator; + +/** +* @author nik +*/ +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()); + } + }; + + public abstract void renderItem(ColoredListCellRenderer renderer); + + @Nullable + public abstract String getPresentableFrameworkName(); + + @Nullable + public abstract String getFrameworkTypeId(); + + @Nullable + public abstract String getFileUrl(); +} diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/InvalidExcludeListItem.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/InvalidExcludeListItem.java new file mode 100644 index 000000000000..8c6bf80d8944 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/InvalidExcludeListItem.java @@ -0,0 +1,60 @@ +/* + * 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.framework.detection.impl.exclude; + +import com.intellij.ui.ColoredListCellRenderer; +import com.intellij.ui.SimpleTextAttributes; + +/** +* @author nik +*/ +class InvalidExcludeListItem extends ExcludeListItem { + private String myFileUrl; + private String myFrameworkTypeId; + + InvalidExcludeListItem(String frameworkTypeId, String fileUrl) { + myFrameworkTypeId = frameworkTypeId; + myFileUrl = fileUrl; + } + + @Override + public String getFrameworkTypeId() { + return myFrameworkTypeId; + } + + @Override + public String getFileUrl() { + return myFileUrl; + } + + @Override + public void renderItem(ColoredListCellRenderer renderer) { + if (myFrameworkTypeId != null) { + renderer.append(myFrameworkTypeId, SimpleTextAttributes.ERROR_ATTRIBUTES); + if (myFileUrl != null) { + renderer.append(" in " + myFileUrl, SimpleTextAttributes.ERROR_ATTRIBUTES); + } + } + else { + renderer.append(myFileUrl, SimpleTextAttributes.ERROR_ATTRIBUTES); + } + } + + @Override + public String getPresentableFrameworkName() { + return myFrameworkTypeId; + } +} diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ValidExcludeListItem.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ValidExcludeListItem.java new file mode 100644 index 000000000000..2c06ab85f083 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/ValidExcludeListItem.java @@ -0,0 +1,66 @@ +/* + * 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.framework.detection.impl.exclude; + +import com.intellij.framework.FrameworkType; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.ui.ColoredListCellRenderer; +import com.intellij.ui.SimpleTextAttributes; + +/** +* @author nik +*/ +class ValidExcludeListItem extends ExcludeListItem { + private VirtualFile myFile; + private FrameworkType myFrameworkType; + + ValidExcludeListItem(FrameworkType frameworkType, VirtualFile file) { + myFrameworkType = frameworkType; + myFile = file; + } + + @Override + public String getFrameworkTypeId() { + return myFrameworkType != null ? myFrameworkType.getId() : null; + } + + @Override + public String getFileUrl() { + return myFile != null ? myFile.getUrl() : null; + } + + @Override + public void renderItem(ColoredListCellRenderer renderer) { + if (myFrameworkType != null) { + renderer.setIcon(myFrameworkType.getIcon()); + renderer.append(myFrameworkType.getPresentableName()); + if (myFile != null) { + renderer.append(" in " + myFile.getName()); + renderer.append(" (" + myFile.getPresentableUrl() + ")", SimpleTextAttributes.GRAY_ATTRIBUTES); + } + } + else { + renderer.setIcon(myFile.getIcon()); + renderer.append(myFile.getName()); + renderer.append(" (" + myFile.getPresentableUrl() + ")", SimpleTextAttributes.GRAY_ATTRIBUTES); + } + } + + @Override + public String getPresentableFrameworkName() { + return myFrameworkType != null ? myFrameworkType.getPresentableName() : null; + } +}