summaryrefslogtreecommitdiff
path: root/platform/platform-impl/src/com/intellij/ui/CheckboxTreeTable.java
blob: 369dd0cc1803231201aaed4ae197e838f8d73b70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Copyright 2000-2012 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.ui;

import com.intellij.ui.dualView.TreeTableView;
import com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns;
import com.intellij.ui.treeStructure.treetable.TreeTableTree;
import com.intellij.util.EventDispatcher;
import com.intellij.util.ui.ColumnInfo;
import org.jetbrains.annotations.NotNull;

/**
 * @author nik
 */
public class CheckboxTreeTable extends TreeTableView {
  private final EventDispatcher<CheckboxTreeListener> myEventDispatcher;

  public CheckboxTreeTable(CheckedTreeNode root, CheckboxTree.CheckboxTreeCellRenderer renderer, final ColumnInfo[] columns) {
    super(new ListTreeTableModelOnColumns(root, columns));
    final TreeTableTree tree = getTree();
    myEventDispatcher = EventDispatcher.create(CheckboxTreeListener.class);
    CheckboxTreeHelper helper = new CheckboxTreeHelper(CheckboxTreeHelper.DEFAULT_POLICY, myEventDispatcher);
    helper.initTree(tree, this, renderer);
    tree.setSelectionRow(0);
  }

  public void addCheckboxTreeListener(@NotNull CheckboxTreeListener listener) {
    myEventDispatcher.addListener(listener);
  }

  public <T> T[] getCheckedNodes(final Class<T> nodeType) {
    return CheckboxTreeHelper.getCheckedNodes(nodeType, null, getTree().getModel());
  }
}