Search in sources :

Example 1 with TreeTableTree

use of com.intellij.ui.treeStructure.treetable.TreeTableTree in project intellij-community by JetBrains.

the class DynamicToolWindowWrapper method createTable.

private JScrollPane createTable(final MutableTreeNode myTreeRoot) {
    ColumnInfo[] columnInfos = { new ClassColumnInfo(myColumnNames[CLASS_OR_ELEMENT_NAME_COLUMN]), new PropertyTypeColumnInfo(myColumnNames[TYPE_COLUMN]) };
    myTreeTableModel = new ListTreeTableModelOnColumns(myTreeRoot, columnInfos);
    myTreeTable = new MyTreeTable(myTreeTableModel);
    new TreeTableSpeedSearch(myTreeTable, new Convertor<TreePath, String>() {

        @Override
        public String convert(TreePath o) {
            final Object node = o.getLastPathComponent();
            if (node instanceof DefaultMutableTreeNode) {
                final Object object = ((DefaultMutableTreeNode) node).getUserObject();
                if (object instanceof DNamedElement) {
                    return ((DNamedElement) object).getName();
                }
            }
            return "";
        }
    });
    DefaultActionGroup group = new DefaultActionGroup();
    group.add(ActionManager.getInstance().getAction(RemoveDynamicAction.GROOVY_DYNAMIC_REMOVE));
    PopupHandler.installUnknownPopupHandler(myTreeTable, group, ActionManager.getInstance());
    final MyColoredTreeCellRenderer treeCellRenderer = new MyColoredTreeCellRenderer();
    myTreeTable.setDefaultRenderer(String.class, new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            if (value instanceof String) {
                try {
                    final PsiType type = JavaPsiFacade.getElementFactory(myProject).createTypeFromText((String) value, null);
                    String shortName = type.getPresentableText();
                    return new JLabel(shortName);
                } catch (IncorrectOperationException e) {
                    LOG.debug("Type cannot be created", e);
                }
                return new JLabel(QuickfixUtil.shortenType((String) value));
            }
            return new JLabel();
        }
    });
    myTreeTable.setTreeCellRenderer(treeCellRenderer);
    myTreeTable.setRootVisible(false);
    myTreeTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    final MyPropertyTypeCellEditor typeCellEditor = new MyPropertyTypeCellEditor();
    typeCellEditor.addCellEditorListener(new CellEditorListener() {

        @Override
        public void editingStopped(ChangeEvent e) {
            final TreeTableTree tree = getTree();
            String newTypeValue = ((MyPropertyTypeCellEditor) e.getSource()).getCellEditorValue();
            if (newTypeValue == null || tree == null) {
                myTreeTable.editingStopped(e);
                return;
            }
            try {
                final PsiType type = JavaPsiFacade.getElementFactory(myProject).createTypeFromText(newTypeValue, null);
                String canonical = type.getCanonicalText();
                if (canonical != null)
                    newTypeValue = canonical;
            } catch (IncorrectOperationException ex) {
            //do nothing in case bad string is entered
            }
            final TreePath editingTypePath = tree.getSelectionPath();
            if (editingTypePath == null)
                return;
            final TreePath editingClassPath = editingTypePath.getParentPath();
            Object oldTypeValue = myTreeTable.getValueAt(tree.getRowForPath(editingTypePath), TYPE_COLUMN);
            if (!(oldTypeValue instanceof String)) {
                myTreeTable.editingStopped(e);
                return;
            }
            final Object editingPropertyObject = myTreeTable.getValueAt(tree.getRowForPath(editingTypePath), CLASS_OR_ELEMENT_NAME_COLUMN);
            final Object editingClassObject = myTreeTable.getValueAt(tree.getRowForPath(editingClassPath), CLASS_OR_ELEMENT_NAME_COLUMN);
            if (!(editingPropertyObject instanceof DItemElement) || !(editingClassObject instanceof DClassElement)) {
                myTreeTable.editingStopped(e);
                return;
            }
            final DItemElement dynamicElement = (DItemElement) editingPropertyObject;
            final String name = dynamicElement.getName();
            final String className = ((DClassElement) editingClassObject).getName();
            if (dynamicElement instanceof DPropertyElement) {
                DynamicManager.getInstance(myProject).replaceDynamicPropertyType(className, name, (String) oldTypeValue, newTypeValue);
            } else if (dynamicElement instanceof DMethodElement) {
                final List<ParamInfo> myPairList = ((DMethodElement) dynamicElement).getPairs();
                DynamicManager.getInstance(myProject).replaceDynamicMethodType(className, name, myPairList, (String) oldTypeValue, newTypeValue);
            }
        }

        @Override
        public void editingCanceled(ChangeEvent e) {
            myTreeTable.editingCanceled(e);
        }
    });
    RefactoringListenerManager.getInstance(myProject).addListenerProvider(new RefactoringElementListenerProvider() {

        @Override
        @Nullable
        public RefactoringElementListener getListener(final PsiElement element) {
            if (element instanceof PsiClass) {
                final String qualifiedName = ((PsiClass) element).getQualifiedName();
                return new RefactoringElementListener() {

                    @Override
                    public void elementMoved(@NotNull PsiElement newElement) {
                        renameElement(qualifiedName, newElement);
                    }

                    @Override
                    public void elementRenamed(@NotNull PsiElement newElement) {
                        renameElement(qualifiedName, newElement);
                    }

                    private void renameElement(String oldClassName, PsiElement newElement) {
                        if (newElement instanceof PsiClass) {
                            final String newClassName = ((PsiClass) newElement).getQualifiedName();
                            final DRootElement rootElement = DynamicManager.getInstance(myProject).getRootElement();
                            final DClassElement oldClassElement = rootElement.getClassElement(oldClassName);
                            final TreeNode oldClassNode = TreeUtil.findNodeWithObject((DefaultMutableTreeNode) myTreeRoot, oldClassElement);
                            DynamicManager.getInstance(myProject).replaceClassName(oldClassElement, newClassName);
                            myTreeTableModel.nodeChanged(oldClassNode);
                        }
                    }
                };
            }
            return null;
        }
    });
    myTreeTable.setDefaultEditor(String.class, typeCellEditor);
    myTreeTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            final int selectionRow = myTreeTable.getTree().getLeadSelectionRow();
            myTreeTable.editCellAt(selectionRow, CLASS_OR_ELEMENT_NAME_COLUMN, event);
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), JComponent.WHEN_FOCUSED);
    myTreeTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            final int selectionRow = myTreeTable.getTree().getLeadSelectionRow();
            myTreeTable.editCellAt(selectionRow, TYPE_COLUMN, event);
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_F2, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED);
    myTreeTable.getTree().setShowsRootHandles(true);
    myTreeTable.getTableHeader().setReorderingAllowed(false);
    myTreeTable.setPreferredScrollableViewportSize(new Dimension(300, myTreeTable.getRowHeight() * 10));
    myTreeTable.getColumn(myColumnNames[CLASS_OR_ELEMENT_NAME_COLUMN]).setPreferredWidth(200);
    myTreeTable.getColumn(myColumnNames[TYPE_COLUMN]).setPreferredWidth(160);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTreeTable);
    scrollPane.setPreferredSize(JBUI.size(600, 400));
    return scrollPane;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) ColumnInfo(com.intellij.util.ui.ColumnInfo) CellEditorListener(javax.swing.event.CellEditorListener) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) TreeTableTree(com.intellij.ui.treeStructure.treetable.TreeTableTree) TableCellRenderer(javax.swing.table.TableCellRenderer) ListTreeTableModelOnColumns(com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) TreePath(javax.swing.tree.TreePath) ChangeEvent(javax.swing.event.ChangeEvent) RefactoringElementListenerProvider(com.intellij.refactoring.listeners.RefactoringElementListenerProvider) ActionListener(java.awt.event.ActionListener) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with TreeTableTree

use of com.intellij.ui.treeStructure.treetable.TreeTableTree in project intellij-community by JetBrains.

the class ExpandAllAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null)
        return;
    final TreeTableTree tree = DynamicToolWindowWrapper.getInstance(project).getTreeTable().getTree();
    TreeUtil.expandAll(tree);
}
Also used : Project(com.intellij.openapi.project.Project) TreeTableTree(com.intellij.ui.treeStructure.treetable.TreeTableTree)

Example 3 with TreeTableTree

use of com.intellij.ui.treeStructure.treetable.TreeTableTree in project intellij-community by JetBrains.

the class TaskExecutionView method getData.

@Nullable
@Override
public Object getData(@NonNls String dataId) {
    final TreeTableTree tree = myTreeTable.getTree();
    if (Location.DATA_KEYS.is(dataId)) {
        TreePath[] paths = tree.getSelectionModel().getSelectionPaths();
        if (paths != null && paths.length > 1) {
            final List<Location<?>> locations = new ArrayList<>(paths.length);
            for (TreePath path : paths) {
                if (tree.isPathSelected(path.getParentPath()))
                    continue;
                ExecutionInfo executionInfo = getSelectedExecution(path);
                if (executionInfo != null) {
                    final Location<?> location = (Location<?>) GradleRunnerUtil.getData(myProject, Location.DATA_KEY.getName(), executionInfo);
                    if (location != null) {
                        locations.add(location);
                    }
                }
            }
            return locations.isEmpty() ? null : locations.toArray(new Location[locations.size()]);
        }
    }
    if (Location.DATA_KEY.is(dataId)) {
        TreePath[] paths = tree.getSelectionModel().getSelectionPaths();
        if (paths != null && paths.length > 1) {
            final List<ExecutionInfo> executionInfos = ContainerUtil.newArrayListWithCapacity(paths.length);
            for (TreePath path : paths) {
                if (tree.isPathSelected(path.getParentPath()))
                    continue;
                ExecutionInfo executionInfo = getSelectedExecution(path);
                ContainerUtil.addIfNotNull(executionInfos, executionInfo);
            }
            return executionInfos.isEmpty() ? null : GradleRunnerUtil.getTaskLocation(myProject, executionInfos.toArray(new ExecutionInfo[executionInfos.size()]));
        }
    }
    final TreePath selectionPath = tree.getSelectionPath();
    if (selectionPath == null)
        return null;
    ExecutionInfo executionInfo = getSelectedExecution(selectionPath);
    if (executionInfo == null)
        return null;
    return GradleRunnerUtil.getData(myProject, dataId, executionInfo);
}
Also used : TreePath(javax.swing.tree.TreePath) TreeTableTree(com.intellij.ui.treeStructure.treetable.TreeTableTree) ArrayList(java.util.ArrayList) Location(com.intellij.execution.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with TreeTableTree

use of com.intellij.ui.treeStructure.treetable.TreeTableTree in project intellij-plugins by JetBrains.

the class CompilerOptionsConfigurable method createTreeTable.

private TreeTable createTreeTable() {
    final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    final TreeTableModel model = new ListTreeTableModel(rootNode, createColumns());
    final TreeTable treeTable = new TreeTable(model);
    treeTable.getColumnModel().getColumn(1).setCellRenderer(createValueRenderer());
    treeTable.getColumnModel().getColumn(1).setCellEditor(createValueEditor());
    final TreeTableTree tree = treeTable.getTree();
    tree.setRootVisible(false);
    tree.setLineStyleAngled();
    tree.setShowsRootHandles(true);
    tree.setCellRenderer(createTreeCellRenderer());
    treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    treeTable.setRowHeight(new JTextField("Fake").getPreferredSize().height + 3);
    //treeTable.setTableHeader(null);
    final DefaultActionGroup group = new DefaultActionGroup();
    group.add(new RestoreDefaultValueAction(tree));
    PopupHandler.installPopupHandler(treeTable, group, ActionPlaces.UNKNOWN, ActionManager.getInstance());
    new TreeTableSpeedSearch(treeTable, o -> {
        final Object userObject = ((DefaultMutableTreeNode) o.getLastPathComponent()).getUserObject();
        return userObject instanceof CompilerOptionInfo ? ((CompilerOptionInfo) userObject).DISPLAY_NAME : "";
    }).setComparator(new SpeedSearchComparator(false));
    return treeTable;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) EventDispatcher(com.intellij.util.EventDispatcher) HyperlinkEvent(javax.swing.event.HyperlinkEvent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ColumnInfo(com.intellij.util.ui.ColumnInfo) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) THashMap(gnu.trove.THashMap) TableCellRenderer(javax.swing.table.TableCellRenderer) CompilerUIConfigurable(com.intellij.compiler.options.CompilerUIConfigurable) BCUtils(com.intellij.lang.javascript.flex.projectStructure.options.BCUtils) Nls(org.jetbrains.annotations.Nls) FlexmojosSdkType(com.intellij.lang.javascript.flex.sdk.FlexmojosSdkType) CompilerOptionsListener(com.intellij.lang.javascript.flex.projectStructure.model.CompilerOptionsListener) Disposer(com.intellij.openapi.util.Disposer) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) FileUtil(com.intellij.openapi.util.io.FileUtil) ChangeListener(javax.swing.event.ChangeListener) Module(com.intellij.openapi.module.Module) TreeTable(com.intellij.ui.treeStructure.treetable.TreeTable) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ChangeEvent(javax.swing.event.ChangeEvent) TreePath(javax.swing.tree.TreePath) ActionCallback(com.intellij.openapi.util.ActionCallback) ValueSource(com.intellij.flex.model.bc.ValueSource) TreeTableTree(com.intellij.ui.treeStructure.treetable.TreeTableTree) FlexBundle(com.intellij.lang.javascript.flex.FlexBundle) com.intellij.ui(com.intellij.ui) ComponentWithBrowseButton(com.intellij.openapi.ui.ComponentWithBrowseButton) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) TreeCellRenderer(javax.swing.tree.TreeCellRenderer) CompilerOptions(com.intellij.lang.javascript.flex.projectStructure.model.CompilerOptions) ListTreeTableModel(com.intellij.ui.treeStructure.treetable.ListTreeTableModel) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NamedConfigurable(com.intellij.openapi.ui.NamedConfigurable) NotNull(org.jetbrains.annotations.NotNull) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) FlexUtils(com.intellij.lang.javascript.flex.FlexUtils) java.util(java.util) ShowSettingsUtil(com.intellij.openapi.options.ShowSettingsUtil) ActionListener(java.awt.event.ActionListener) FlexProjectLevelCompilerOptionsHolder(com.intellij.lang.javascript.flex.projectStructure.FlexProjectLevelCompilerOptionsHolder) ContainerUtil(com.intellij.util.containers.ContainerUtil) History(com.intellij.ui.navigation.History) FlexSdkType2(com.intellij.lang.javascript.flex.sdk.FlexSdkType2) TableCellEditor(javax.swing.table.TableCellEditor) Project(com.intellij.openapi.project.Project) DocumentEvent(javax.swing.event.DocumentEvent) PlatformIcons(com.intellij.util.PlatformIcons) TreeUtil(com.intellij.util.ui.tree.TreeUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) ActionEvent(java.awt.event.ActionEvent) Disposable(com.intellij.openapi.Disposable) Sdk(com.intellij.openapi.projectRoots.Sdk) BuildConfigurationNature(com.intellij.flex.model.bc.BuildConfigurationNature) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Place(com.intellij.ui.navigation.Place) ResourceFilesMode(com.intellij.lang.javascript.flex.projectStructure.model.CompilerOptions.ResourceFilesMode) ModifiableCompilerOptions(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableCompilerOptions) Pair(com.intellij.openapi.util.Pair) PathUtil(com.intellij.util.PathUtil) CompilerOptionInfo(com.intellij.flex.model.bc.CompilerOptionInfo) TreeTableModel(com.intellij.ui.treeStructure.treetable.TreeTableModel) javax.swing(javax.swing) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CompilerOptionInfo(com.intellij.flex.model.bc.CompilerOptionInfo) TreeTable(com.intellij.ui.treeStructure.treetable.TreeTable) ListTreeTableModel(com.intellij.ui.treeStructure.treetable.ListTreeTableModel) TreeTableModel(com.intellij.ui.treeStructure.treetable.TreeTableModel) ListTreeTableModel(com.intellij.ui.treeStructure.treetable.ListTreeTableModel) TreeTableTree(com.intellij.ui.treeStructure.treetable.TreeTableTree)

Example 5 with TreeTableTree

use of com.intellij.ui.treeStructure.treetable.TreeTableTree in project intellij-plugins by JetBrains.

the class CompilerOptionsConfigurable method updateTreeTable.

private void updateTreeTable() {
    final TreeTableTree tree = myTreeTable.getTree();
    final TreePath selectionPath = tree.getSelectionPath();
    final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(tree);
    final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
    final DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot();
    final CompilerOptionInfo[] optionInfos = CompilerOptionInfo.getRootInfos();
    final boolean showAll = myShowAllOptionsCheckBox.isSelected();
    updateChildNodes(rootNode, optionInfos, showAll);
    treeModel.reload(rootNode);
    TreeUtil.restoreExpandedPaths(tree, expandedPaths);
    tree.setSelectionPath(selectionPath);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CompilerOptionInfo(com.intellij.flex.model.bc.CompilerOptionInfo) TreeTableTree(com.intellij.ui.treeStructure.treetable.TreeTableTree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Aggregations

TreeTableTree (com.intellij.ui.treeStructure.treetable.TreeTableTree)8 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 TreePath (javax.swing.tree.TreePath)4 Project (com.intellij.openapi.project.Project)3 Nullable (org.jetbrains.annotations.Nullable)3 CompilerOptionInfo (com.intellij.flex.model.bc.CompilerOptionInfo)2 ColumnInfo (com.intellij.util.ui.ColumnInfo)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ChangeEvent (javax.swing.event.ChangeEvent)2 TableCellRenderer (javax.swing.table.TableCellRenderer)2 CompilerUIConfigurable (com.intellij.compiler.options.CompilerUIConfigurable)1 AddedFileInfo (com.intellij.cvsSupport2.cvsoperations.cvsAdd.AddedFileInfo)1 Location (com.intellij.execution.Location)1 BuildConfigurationNature (com.intellij.flex.model.bc.BuildConfigurationNature)1 ValueSource (com.intellij.flex.model.bc.ValueSource)1 FlexBundle (com.intellij.lang.javascript.flex.FlexBundle)1 FlexUtils (com.intellij.lang.javascript.flex.FlexUtils)1 FlexProjectLevelCompilerOptionsHolder (com.intellij.lang.javascript.flex.projectStructure.FlexProjectLevelCompilerOptionsHolder)1 CompilerOptions (com.intellij.lang.javascript.flex.projectStructure.model.CompilerOptions)1