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.
16 package com
.intellij
.find
.findUsages
;
18 import com
.intellij
.find
.FindBundle
;
19 import com
.intellij
.find
.FindSettings
;
20 import com
.intellij
.openapi
.help
.HelpManager
;
21 import com
.intellij
.openapi
.project
.Project
;
22 import com
.intellij
.openapi
.util
.text
.StringUtil
;
23 import com
.intellij
.psi
.PsiElement
;
24 import com
.intellij
.psi
.PsiManager
;
25 import com
.intellij
.psi
.PsiMethod
;
26 import com
.intellij
.psi
.search
.LocalSearchScope
;
27 import com
.intellij
.psi
.util
.MethodSignatureUtil
;
28 import com
.intellij
.ui
.StateRestoringCheckBox
;
29 import com
.intellij
.usageView
.UsageViewUtil
;
33 public abstract class JavaFindUsagesDialog
extends AbstractFindUsagesDialog
{
34 protected final PsiElement myPsiElement
;
35 private StateRestoringCheckBox myCbIncludeOverloadedMethods
;
36 private boolean myIncludeOverloadedMethodsAvailable
= false;
38 protected JavaFindUsagesDialog(PsiElement element
, Project project
, FindUsagesOptions findUsagesOptions
, boolean toShowInNewTab
, boolean mustOpenInNewTab
,
40 FindUsagesHandler handler
) {
41 super(project
, findUsagesOptions
, toShowInNewTab
, mustOpenInNewTab
, isSingleFile
, isTextSearch(element
, isSingleFile
, handler
), !isSingleFile
&& !element
.getManager().isInProject(element
));
42 myPsiElement
= element
;
43 myIncludeOverloadedMethodsAvailable
= element
instanceof PsiMethod
&& MethodSignatureUtil
.hasOverloads((PsiMethod
)element
);
47 private static boolean isTextSearch(PsiElement element
, boolean isSingleFile
, FindUsagesHandler handler
) {
48 return FindUsagesUtil
.isSearchForTextOccurencesAvailable(element
, isSingleFile
, handler
);
51 public void calcFindUsagesOptions(FindUsagesOptions options
) {
52 super.calcFindUsagesOptions(options
);
53 options
.isIncludeOverloadUsages
=
54 myIncludeOverloadedMethodsAvailable
&& isToChange(myCbIncludeOverloadedMethods
) && myCbIncludeOverloadedMethods
.isSelected();
57 protected void doOKAction() {
58 if (shouldDoOkAction()) {
59 if (myIncludeOverloadedMethodsAvailable
) {
60 FindSettings
.getInstance().setSearchOverloadedMethods(myCbIncludeOverloadedMethods
.isSelected());
69 protected void addUsagesOptions(JPanel optionsPanel
) {
70 super.addUsagesOptions(optionsPanel
);
71 if (myIncludeOverloadedMethodsAvailable
) {
72 myCbIncludeOverloadedMethods
= addCheckboxToPanel(FindBundle
.message("find.options.include.overloaded.methods.checkbox"),
73 FindSettings
.getInstance().isSearchOverloadedMethods(), optionsPanel
, false);
78 private PsiManager
getPsiManager() {
79 return myPsiElement
.getManager();
82 protected boolean isInFileOnly() {
83 return super.isInFileOnly() ||
84 myPsiElement
!= null && getPsiManager().getSearchHelper().getUseScope(myPsiElement
)instanceof LocalSearchScope
;
87 public String
getLabelText() {
88 return StringUtil
.capitalize(UsageViewUtil
.getType(myPsiElement
)) + " " + UsageViewUtil
.getDescriptiveName(myPsiElement
);
91 protected final PsiElement
getPsiElement() {
95 protected void doHelpAction() {
96 HelpManager
.getInstance().invokeHelp(FindUsagesManager
.getHelpID(myPsiElement
));