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
.ui
;
19 import com
.intellij
.util
.containers
.Convertor
;
20 import com
.intellij
.ui
.treeStructure
.treetable
.TreeTable
;
22 import javax
.swing
.tree
.DefaultMutableTreeNode
;
23 import javax
.swing
.tree
.TreePath
;
25 public class TreeTableSpeedSearch
extends SpeedSearchBase
<TreeTable
> {
26 private static final Convertor
<TreePath
, String
> TO_STRING
= new Convertor
<TreePath
, String
>() {
27 public String
convert(TreePath object
) {
28 DefaultMutableTreeNode node
= (DefaultMutableTreeNode
)object
.getLastPathComponent();
29 return node
.toString();
32 private final Convertor
<TreePath
, String
> myToStringConvertor
;
34 public TreeTableSpeedSearch(TreeTable tree
, Convertor
<TreePath
, String
> toStringConvertor
) {
36 myToStringConvertor
= toStringConvertor
;
39 public TreeTableSpeedSearch(TreeTable tree
) {
40 this(tree
, TreeSpeedSearch
.NODE_DESCRIPTOR_TOSTRING
);
44 protected boolean isSpeedSearchEnabled() {
45 return !getComponent().isEditing() && super.isSpeedSearchEnabled();
48 protected void selectElement(Object element
, String selectedText
) {
49 final TreePath treePath
= (TreePath
)element
;
50 TableUtil
.selectRows(myComponent
, new int[] {myComponent
.getTree().getRowForPath(treePath
)});
51 TableUtil
.scrollSelectionToVisible(myComponent
);
54 protected int getSelectedIndex() {
55 int[] selectionRows
= myComponent
.getTree().getSelectionRows();
56 return selectionRows
== null || selectionRows
.length
== 0 ?
-1 : selectionRows
[0];
59 protected Object
[] getAllElements() {
60 TreePath
[] paths
= new TreePath
[myComponent
.getTree().getRowCount()];
61 for(int i
= 0; i
< paths
.length
; i
++){
62 paths
[i
] = myComponent
.getTree().getPathForRow(i
);
67 protected String
getElementText(Object element
) {
68 TreePath path
= (TreePath
)element
;
69 String string
= myToStringConvertor
.convert(path
);
70 if (string
== null) return TreeTableSpeedSearch
.TO_STRING
.convert(path
);