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
.openapi
.project
.Project
;
20 import com
.intellij
.psi
.PsiElement
;
21 import com
.intellij
.psi
.impl
.search
.ThrowSearchUtil
;
22 import com
.intellij
.ui
.IdeBorderFactory
;
23 import com
.intellij
.ui
.StateRestoringCheckBox
;
28 public class FindThrowUsagesDialog
extends JavaFindUsagesDialog
{
29 private StateRestoringCheckBox myCbUsages
;
30 private JComboBox myCbExns
;
31 private boolean myHasFindWhatPanel
;
32 private ThrowSearchUtil
.Root
[] myRoots
;
34 public FindThrowUsagesDialog(final PsiElement element
, final Project project
,
35 final FindUsagesOptions findUsagesOptions
, boolean toShowInNewTab
, boolean mustOpenInNewTab
,
36 boolean isSingleFile
, FindUsagesHandler handler
){
37 super(element
, project
, findUsagesOptions
, toShowInNewTab
, mustOpenInNewTab
, isSingleFile
, handler
);
40 protected void init () {
41 // Kludge: myRoots used in super.init, which caller from constructor
42 myRoots
= ThrowSearchUtil
.getSearchRoots(myPsiElement
);
46 public JComponent
getPreferredFocusedControl() {
47 return myHasFindWhatPanel ? myCbUsages
: null;
50 protected JComponent
createNorthPanel() {
51 final JComponent panel
= new JPanel(new GridBagLayout());
52 GridBagConstraints gbConstraints
= new GridBagConstraints();
54 gbConstraints
.insets
= new Insets(4, 4, 4, 4);
55 gbConstraints
.fill
= GridBagConstraints
.BOTH
;
56 gbConstraints
.weightx
= 1;
57 gbConstraints
.weighty
= 1;
58 gbConstraints
.anchor
= GridBagConstraints
.EAST
;
59 myCbExns
= new JComboBox (myRoots
);
60 panel
.add(myCbExns
, gbConstraints
);
65 public void calcFindUsagesOptions(final FindUsagesOptions options
) {
66 super.calcFindUsagesOptions(options
);
67 options
.isUsages
= isSelected(myCbUsages
) || !myHasFindWhatPanel
;
68 options
.isThrowUsages
= true;
71 protected JPanel
createFindWhatPanel() {
72 final JPanel findWhatPanel
= new JPanel();
73 findWhatPanel
.setBorder(IdeBorderFactory
.createTitledBorder(FindBundle
.message("find.what.group")));
74 findWhatPanel
.setLayout(new BoxLayout(findWhatPanel
, BoxLayout
.Y_AXIS
));
76 myCbUsages
= addCheckboxToPanel(FindBundle
.message("find.what.usages.checkbox") , myFindUsagesOptions
.isUsages
, findWhatPanel
, true);
77 //final ThrowSearchUtil.Root[] searchRoots = ThrowSearchUtil.getSearchRoots(getPsiElement ());
79 //final PsiThrowStatement throwStatement = (PsiThrowStatement)getPsiElement();
80 //final boolean exactExnType = ThrowSearchUtil.isExactExnType(throwStatement.getException ());
82 // myCbStrict.setEnabled(false);
84 myHasFindWhatPanel
= true;
88 protected void doOKAction() {
89 myFindUsagesOptions
.putUserData(ThrowSearchUtil
.THROW_SEARCH_ROOT_KEY
, (ThrowSearchUtil
.Root
)myCbExns
.getSelectedItem());
93 protected void update(){
94 if (!myHasFindWhatPanel
){
95 setOKActionEnabled(true);
98 myFindUsagesOptions
.putUserData(ThrowSearchUtil
.THROW_SEARCH_ROOT_KEY
, (ThrowSearchUtil
.Root
)myCbExns
.getSelectedItem());
99 final boolean hasSelected
= isSelected(myCbUsages
);
100 setOKActionEnabled(hasSelected
);