ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInspection / ex / Descriptor.java
bloba9b2ce6a04e9971e88adf083e12777e0aa2da891
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.codeInspection.ex;
19 import com.intellij.codeHighlighting.HighlightDisplayLevel;
20 import com.intellij.codeInsight.daemon.HighlightDisplayKey;
21 import com.intellij.codeInspection.InspectionProfile;
22 import com.intellij.codeInspection.InspectionProfileEntry;
23 import com.intellij.openapi.diagnostic.Logger;
24 import com.intellij.openapi.util.WriteExternalException;
25 import com.intellij.psi.search.scope.packageSet.NamedScope;
26 import org.jdom.Element;
27 import org.jetbrains.annotations.NonNls;
28 import org.jetbrains.annotations.NotNull;
30 /**
31 * User: anna
32 * Date: Dec 8, 2004
34 public class Descriptor {
35 private final String myText;
36 private final String[] myGroup;
37 private final HighlightDisplayKey myKey;
39 private final Element myConfig;
40 private final InspectionProfileEntry myTool;
41 private final HighlightDisplayLevel myLevel;
42 private boolean myEnabled = false;
43 private final NamedScope myScope;
44 private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.Descriptor");
45 private final ScopeToolState myState;
47 public Descriptor(ScopeToolState pair, InspectionProfile inspectionProfile) {
48 myState = pair;
49 final InspectionProfileEntry tool = pair.getTool();
50 @NonNls Element config = new Element("options");
51 try {
52 tool.writeSettings(config);
54 catch (WriteExternalException e) {
55 LOG.error(e);
57 myConfig = config;
58 myText = tool.getDisplayName();
59 final String[] groupPath = tool.getGroupPath();
60 myGroup = groupPath.length == 0 ? new String[]{InspectionProfileEntry.GENERAL_GROUP_NAME} : groupPath;
61 myKey = HighlightDisplayKey.find(tool.getShortName());
62 myLevel = ((InspectionProfileImpl)inspectionProfile).getErrorLevel(myKey, pair.getScope());
63 myEnabled = ((InspectionProfileImpl)inspectionProfile).isToolEnabled(myKey, pair.getScope());
64 myTool = tool;
65 myScope = pair.getScope();
68 public boolean equals(Object obj) {
69 if (!(obj instanceof Descriptor)) return false;
70 final Descriptor descriptor = (Descriptor)obj;
71 return myKey.equals(descriptor.getKey()) &&
72 myLevel.equals(descriptor.getLevel()) &&
73 myEnabled == descriptor.isEnabled() &&
74 myState.equalTo(descriptor.getState());
77 public int hashCode() {
78 final int hash = myKey.hashCode() + 29 * myLevel.hashCode();
79 return myScope != null ? myScope.hashCode() + 29 * hash : hash;
82 public boolean isEnabled() {
83 return myEnabled;
86 public void setEnabled(final boolean enabled) {
87 myEnabled = enabled;
90 public String getText() {
91 return myText;
94 @NotNull
95 public HighlightDisplayKey getKey() {
96 return myKey;
99 public HighlightDisplayLevel getLevel() {
100 return myLevel;
105 public Element getConfig() {
106 return myConfig;
109 public InspectionProfileEntry getTool() {
110 return myTool;
113 public String loadDescription() {
114 if (!(myTool instanceof InspectionTool)) return null;
115 return myTool.loadDescription();
118 public String[] getGroup() {
119 return myGroup;
122 public NamedScope getScope() {
123 return myScope;
126 public ScopeToolState getState() {
127 return myState;
130 @Override
131 public String toString() {
132 return myKey.toString();