--- /dev/null
+/*
+ * 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 org.jetbrains.plugins.groovy.annotator.intentions.dynamic;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.project.Project;
+import com.intellij.ui.treeStructure.treetable.TreeTableTree;
+import com.intellij.util.ui.tree.TreeUtil;
+
+/**
+ * @author Max Medvedev
+ */
+public class CollapseAllAction extends AnAction {
+ @Override
+ public void actionPerformed(AnActionEvent e) {
+ final Project project = e.getProject();
+ if (project == null) return;
+
+ final TreeTableTree tree = DynamicToolWindowWrapper.getInstance(project).getTreeTable().getTree();
+ TreeUtil.collapseAll(tree, 0);
+ }
+
+ @Override
+ public void update(AnActionEvent e) {
+ final Project project = e.getProject();
+ if (project == null) {
+ e.getPresentation().setEnabled(false);
+ return;
+ }
+ e.getPresentation().setEnabled(DynamicToolWindowWrapper.getInstance(project).getTreeTable().getRowCount() > 0);
+ }
+}
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
+import com.intellij.openapi.ui.SimpleToolWindowPanel;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
* Date: 09.01.2008
*/
public class DynamicToolWindowWrapper {
+ private static final Logger LOG = Logger.getInstance(DynamicToolWindowWrapper.class);
+
+ private static final int CLASS_OR_ELEMENT_NAME_COLUMN = 0;
+ private static final int TYPE_COLUMN = 1;
+
+ private static final String[] myColumnNames = {"Dynamic Element", "Type"};
+
private final Project myProject;
private ToolWindow myToolWindow = null;
+ private JPanel myTreeTablePanel;
+ private SimpleToolWindowPanel myBigPanel;
+ private ListTreeTableModelOnColumns myTreeTableModel;
+ private MyTreeTable myTreeTable;
+
public DynamicToolWindowWrapper(Project project) {
myProject = project;
}
return ServiceManager.getService(project, DynamicToolWindowWrapper.class);
}
- public static final String DYNAMIC_TOOLWINDOW_ID = GroovyBundle.message("dynamic.tool.window.id");
- private JPanel myTreeTablePanel;
- private JPanel myBigPanel;
- private ListTreeTableModelOnColumns myTreeTableModel;
-
- private static final int CLASS_OR_ELEMENT_NAME_COLUMN = 0;
- private static final int TYPE_COLUMN = 1;
-
- private static final String[] myColumnNames = {"Dynamic Element", "Type"};
-
- private MyTreeTable myTreeTable;
-
- private static final Logger LOG = Logger.getInstance("org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicToolWindowWrapper");
-
public TreeTable getTreeTable() {
getToolWindow();
public ToolWindow getToolWindow() {
if (myToolWindow == null) {
- myToolWindow = ToolWindowManager.getInstance(myProject).registerToolWindow(DYNAMIC_TOOLWINDOW_ID, true, ToolWindowAnchor.RIGHT);
+ myToolWindow = ToolWindowManager.getInstance(myProject).registerToolWindow(GroovyBundle.message("dynamic.tool.window.id"), true, ToolWindowAnchor.RIGHT);
myToolWindow.setIcon(GroovyIcons.DYNAMIC_PROPERTY_TOOL_WINDOW_ICON);
myToolWindow.setTitle(GroovyBundle.message("dynamic.window"));
myToolWindow.setToHideOnEmptyContent(true);
}
private JPanel buildBigPanel() {
- myBigPanel = new JPanel(new BorderLayout());
+ myBigPanel = new SimpleToolWindowPanel(true);
+
+ final ActionManager actionManager = ActionManager.getInstance();
+ final ActionGroup actionGroup = (ActionGroup)actionManager.getAction("Groovy.Dynamic.Toolbar");
+ ActionToolbar actionToolbar = actionManager.createActionToolbar("Groovy.Dynamic.Toolbar", actionGroup, true);
+ myBigPanel.setToolbar(actionToolbar.getComponent());
+
myBigPanel.setBackground(UIUtil.getFieldForegroundColor());
final DynamicFilterComponent filter = new DynamicFilterComponent(GroovyBundle.message("dynamic.toolwindow.property.filter"), 10);
filter.setBackground(UIUtil.getLabelBackground());
- myBigPanel.add(new JLabel(GroovyBundle.message("dynamic.toolwindow.search.elements")), BorderLayout.NORTH);
- myBigPanel.add(filter, BorderLayout.NORTH);
+ final JPanel panel = new JPanel(new BorderLayout());
+ myBigPanel.add(panel, BorderLayout.CENTER);
+ panel.add(filter, BorderLayout.NORTH);
myTreeTablePanel = new JPanel(new BorderLayout());
rebuildTreePanel();
- myBigPanel.add(myTreeTablePanel);
+ panel.add(myTreeTablePanel);
myBigPanel.setPreferredSize(new Dimension(200, myBigPanel.getHeight()));
myBigPanel.revalidate();
myTreeTable = new MyTreeTable(myTreeTableModel);
DefaultActionGroup group = new DefaultActionGroup();
- group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_DELETE));
+ group.add(ActionManager.getInstance().getAction(RemoveDynamicAction.GROOVY_DYNAMIC_REMOVE));
PopupHandler.installUnknownPopupHandler(myTreeTable, group, ActionManager.getInstance());
final MyColoredTreeCellRenderer treeCellRenderer = new MyColoredTreeCellRenderer();
return scrollPane;
}
- private void deleteRow() {
- final int[] rows = myTreeTable.getSelectedRows();
+ void deleteRow() {
boolean isShowDialog = true;
- final int rowsCount = rows.length;
+ final int rowsCount = myTreeTable.getSelectedRows().length;
int i = 0;
- final TreeTableTree tree = myTreeTable.getTree();
+ final TreePath[] paths = myTreeTable.getTree().getSelectionPaths();
+ if (paths == null) return;
- for (TreePath selectionPath : tree.getSelectionPaths()) {
+ for (TreePath selectionPath : paths) {
if (rowsCount > 1) isShowDialog = false;
- if (i++ == 0) isShowDialog = true;
+ if (i == 0) isShowDialog = true;
+ i++;
//class
final TreePath parent = selectionPath.getParentPath();
IdeFocusManager.getInstance(myProject).requestFocus(myTreeTable, true);
}
-
public void removeFromParent(DefaultMutableTreeNode parent, DefaultMutableTreeNode child) {
int idx = myTreeTableModel.getIndexOfChild(parent, child);
child.removeFromParent();
myTreeTableModel.nodesWereRemoved(parent, new int[]{idx}, new TreeNode[]{child});
}
- static class PropertyTypeColumnInfo extends ColumnInfo<DefaultMutableTreeNode, String> {
+ @Nullable
+ private TreeTableTree getTree() {
+ return myTreeTable != null ? myTreeTable.getTree() : null;
+ }
+
+ private static class PropertyTypeColumnInfo extends ColumnInfo<DefaultMutableTreeNode, String> {
public PropertyTypeColumnInfo(String name) {
super(name);
}
}
}
- static class ClassColumnInfo extends ColumnInfo<DefaultMutableTreeNode, DNamedElement> {
+ private static class ClassColumnInfo extends ColumnInfo<DefaultMutableTreeNode, DNamedElement> {
public ClassColumnInfo(String name) {
super(name);
}
}
}
- @Nullable
- private TreeTableTree getTree() {
- return myTreeTable != null ? myTreeTable.getTree() : null;
- }
-
- public class MyTreeTable extends TreeTable implements DataProvider {
+ private class MyTreeTable extends TreeTable implements DataProvider {
public MyTreeTable(TreeTableModel treeTableModel) {
super(treeTableModel);
}
public Object getData(@NonNls String dataId) {
if (LangDataKeys.PSI_ELEMENT.is(dataId)) {
return getSelectedElement();
-
- } else if (LangDataKeys.PSI_FILE.is(dataId)) {
+ }
+ else if (LangDataKeys.PSI_FILE.is(dataId)) {
final PsiElement element = getSelectedElement();
if (element == null) return null;
return element.getContainingFile();
- } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
+ }
+ else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
return new DeleteProvider() {
@Override
public void deleteElement(DataContext dataContext) {
--- /dev/null
+/*
+ * 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 org.jetbrains.plugins.groovy.annotator.intentions.dynamic;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.project.Project;
+import com.intellij.ui.treeStructure.treetable.TreeTableTree;
+import com.intellij.util.ui.tree.TreeUtil;
+
+/**
+ * @author Max Medvedev
+ */
+public class ExpandAllAction extends AnAction {
+ @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);
+ }
+
+ @Override
+ public void update(AnActionEvent e) {
+ final Project project = e.getProject();
+ if (project == null) {
+ e.getPresentation().setEnabled(false);
+ return;
+ }
+ e.getPresentation().setEnabled(DynamicToolWindowWrapper.getInstance(project).getTreeTable().getRowCount() > 0);
+ }
+}
--- /dev/null
+/*
+ * 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 org.jetbrains.plugins.groovy.annotator.intentions.dynamic;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.project.Project;
+
+import javax.swing.tree.TreePath;
+
+/**
+ * @author Max Medvedev
+ */
+public class RemoveDynamicAction extends AnAction {
+ static final String GROOVY_DYNAMIC_REMOVE = "Groovy.Dynamic.Remove";
+
+ @Override
+ public void actionPerformed(AnActionEvent e) {
+ final DynamicToolWindowWrapper toolWindow = DynamicToolWindowWrapper.getInstance(e.getProject());
+
+ toolWindow.deleteRow();
+ }
+
+ @Override
+ public void update(AnActionEvent e) {
+ final Project project = e.getProject();
+ if (project == null) {
+ e.getPresentation().setEnabled(false);
+ return;
+ }
+ final TreePath[] paths = DynamicToolWindowWrapper.getInstance(project).getTreeTable().getTree().getSelectionPaths();
+ e.getPresentation().setEnabled(paths != null);
+ }
+}