mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract LiveTemplateTree class
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.codeInsight.template.impl;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.CheckboxTree;
|
||||
import com.intellij.ui.CheckedTreeNode;
|
||||
import com.intellij.ui.TreeSpeedSearch;
|
||||
import com.intellij.util.containers.Convertor;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
class LiveTemplateTree extends CheckboxTree {
|
||||
LiveTemplateTree(final CheckboxTreeCellRenderer renderer, final CheckedTreeNode root) {
|
||||
super(renderer, root);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNodeStateChanged(final CheckedTreeNode node) {
|
||||
Object obj = node.getUserObject();
|
||||
if (obj instanceof TemplateImpl) {
|
||||
((TemplateImpl)obj).setDeactivated(!node.isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installSpeedSearch() {
|
||||
new TreeSpeedSearch(this, new Convertor<TreePath, String>() {
|
||||
@Override
|
||||
public String convert(TreePath o) {
|
||||
Object object = ((DefaultMutableTreeNode)o.getLastPathComponent()).getUserObject();
|
||||
if (object instanceof TemplateGroup) {
|
||||
return ((TemplateGroup)object).getName();
|
||||
}
|
||||
if (object instanceof TemplateImpl) {
|
||||
TemplateImpl template = (TemplateImpl)object;
|
||||
return StringUtil.notNullize(template.getKey()) +
|
||||
" " +
|
||||
StringUtil.notNullize(template.getDescription()) +
|
||||
" " +
|
||||
template.getTemplateText();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
+10
-39
@@ -39,7 +39,6 @@ import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.Convertor;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
import com.intellij.util.ui.update.UiNotifyConnector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -454,15 +453,15 @@ public class TemplateListPanel extends JPanel implements Disposable {
|
||||
private JPanel createTable() {
|
||||
myTreeRoot = new CheckedTreeNode(null);
|
||||
|
||||
myTree = new CheckboxTree(new CheckboxTree.CheckboxTreeCellRenderer(){
|
||||
myTree = new LiveTemplateTree(new CheckboxTree.CheckboxTreeCellRenderer() {
|
||||
@Override
|
||||
public void customizeRenderer(final JTree tree,
|
||||
Object value,
|
||||
final boolean selected,
|
||||
final boolean expanded,
|
||||
final boolean leaf,
|
||||
final int row,
|
||||
final boolean hasFocus) {
|
||||
Object value,
|
||||
final boolean selected,
|
||||
final boolean expanded,
|
||||
final boolean leaf,
|
||||
final int row,
|
||||
final boolean hasFocus) {
|
||||
if (!(value instanceof DefaultMutableTreeNode)) return;
|
||||
value = ((DefaultMutableTreeNode)value).getUserObject();
|
||||
|
||||
@@ -473,42 +472,14 @@ public class TemplateListPanel extends JPanel implements Disposable {
|
||||
getTextRenderer().append(template.getKey(), new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, fgColor));
|
||||
String description = template.getDescription();
|
||||
if (StringUtil.isNotEmpty(description)) {
|
||||
getTextRenderer().append (" (" + description + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
|
||||
getTextRenderer().append(" (" + description + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
|
||||
}
|
||||
}
|
||||
else if (value instanceof TemplateGroup) {
|
||||
getTextRenderer().append (((TemplateGroup)value).getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
|
||||
}
|
||||
|
||||
}
|
||||
}, myTreeRoot) {
|
||||
@Override
|
||||
protected void onNodeStateChanged(final CheckedTreeNode node) {
|
||||
Object obj = node.getUserObject();
|
||||
if (obj instanceof TemplateImpl) {
|
||||
((TemplateImpl)obj).setDeactivated(!node.isChecked());
|
||||
getTextRenderer().append(((TemplateGroup)value).getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installSpeedSearch() {
|
||||
new TreeSpeedSearch(this, new Convertor<TreePath, String>() {
|
||||
@Override
|
||||
public String convert(TreePath o) {
|
||||
Object object = ((DefaultMutableTreeNode)o.getLastPathComponent()).getUserObject();
|
||||
if (object instanceof TemplateGroup) {
|
||||
return ((TemplateGroup)object).getName();
|
||||
}
|
||||
if (object instanceof TemplateImpl) {
|
||||
TemplateImpl template = (TemplateImpl)object;
|
||||
return StringUtil.notNullize(template.getKey()) + " " + StringUtil.notNullize(template.getDescription()) + " " + template.getTemplateText();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}, true);
|
||||
|
||||
}
|
||||
};
|
||||
}, myTreeRoot);
|
||||
myTree.setRootVisible(false);
|
||||
myTree.setShowsRootHandles(true);
|
||||
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
|
||||
|
||||
Reference in New Issue
Block a user