Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #175 Liberty tool window doesn't scroll #485

Merged
merged 13 commits into from
Feb 13, 2024
Merged
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 IBM Corporation.
* Copyright (c) 2020, 2024 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -21,6 +21,7 @@
import com.intellij.psi.PsiFile;
import com.intellij.ui.DoubleClickListener;
import com.intellij.ui.PopupHandler;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.components.JBTextArea;
import com.intellij.ui.treeStructure.Tree;
import io.openliberty.tools.intellij.actions.LibertyGeneralAction;
Expand Down Expand Up @@ -51,7 +52,9 @@ public LibertyExplorer(@NotNull Project project) {
Tree tree = buildTree(project, getBackground());

if (tree != null) {
this.setContent(tree);
JBScrollPane scrollPane = new JBScrollPane(tree);
scrollPane.setName(Constants.LIBERTY_SCROLL_PANE);
this.setContent(scrollPane);
} else {
JBTextArea jbTextArea = new JBTextArea(LocalizedResourceUtil.getMessage("no.liberty.projects.detected"));
jbTextArea.setEditable(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 IBM Corporation.
* Copyright (c) 2020, 2024 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -18,6 +18,7 @@
import com.intellij.openapi.ui.SimpleToolWindowPanel;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.components.JBTextArea;
import com.intellij.ui.content.Content;
import com.intellij.ui.treeStructure.Tree;
Expand Down Expand Up @@ -60,8 +61,9 @@ public static void refreshDashboard(Project project) {
Component existingTree = null;
Component existingActionToolbar = null;
for (Component comp : components) {
if (comp.getName() != null && comp.getName().equals(Constants.LIBERTY_TREE)) {
existingTree = comp;
if (comp instanceof JBScrollPane && comp.getName() != null && comp.getName().equals(Constants.LIBERTY_SCROLL_PANE)) {
JBScrollPane scrollPane = (JBScrollPane) comp;
anusreelakshmi934 marked this conversation as resolved.
Show resolved Hide resolved
existingTree = scrollPane.getViewport().getView();
}
if (comp.getName() != null && comp.getName().equals(Constants.LIBERTY_ACTION_TOOLBAR)) {
existingActionToolbar = comp;
Expand All @@ -78,7 +80,9 @@ public static void refreshDashboard(Project project) {
}
simpleToolWindowPanel.setToolbar(actionToolbar.getComponent());
if (tree != null) {
simpleToolWindowPanel.setContent(tree);
JBScrollPane scrollPane = new JBScrollPane(tree);
scrollPane.setName(Constants.LIBERTY_SCROLL_PANE);
simpleToolWindowPanel.setContent(scrollPane);
} else {
JBTextArea jbTextArea = new JBTextArea(LocalizedResourceUtil.getMessage("no.liberty.projects.detected"));
jbTextArea.setEditable(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 IBM Corporation.
* Copyright (c) 2020, 2024 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -18,6 +18,7 @@
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.content.Content;
import com.intellij.ui.treeStructure.Tree;
import io.openliberty.tools.intellij.LibertyPluginIcons;
Expand Down Expand Up @@ -51,28 +52,41 @@ public void update(@NotNull AnActionEvent e) {
//if the action event data context returns a null project, just return and let successive update calls modify the presentation
return;
}
handleLibertyTreeEvent(e, project, true);
}

private void handleLibertyTreeEvent(@NotNull AnActionEvent e, Project project, boolean isUpdate) {
ToolWindow libertyDevToolWindow = ToolWindowManager.getInstance(project).getToolWindow(Constants.LIBERTY_DEV_DASHBOARD_ID);
if (libertyDevToolWindow != null) {
Content content = libertyDevToolWindow.getContentManager().findContent(LocalizedResourceUtil.getMessage("liberty.tool.window.display.name"));
JComponent libertyWindow = content.getComponent();
Component[] components = libertyWindow.getComponents();
Tree libertyTree = null;
for (Component comp : components) {
if (comp.getName() != null && comp.getName().equals(Constants.LIBERTY_TREE)) {
Tree libertyTree = (Tree) comp;

TreePath[] selectionPaths = libertyTree.getSelectionPaths();

// when only one child node is selected, enable this action
if (selectionPaths != null && selectionPaths.length == 1) {
String lastPathComponent = selectionPaths[0].getLastPathComponent().toString();
if (Constants.FULL_ACTIONS_MAP.containsKey(lastPathComponent)) {
e.getPresentation().setEnabled(true);
if (comp instanceof JBScrollPane scrollPane && comp.getName() != null && comp.getName().equals(Constants.LIBERTY_SCROLL_PANE)) {
Component view = scrollPane.getViewport().getView();
if (view instanceof Tree) {
libertyTree = (Tree) view;
TreePath[] selectionPaths = libertyTree.getSelectionPaths();
if (selectionPaths != null && selectionPaths.length == 1) {
String lastPathComponent = selectionPaths[0].getLastPathComponent().toString();
if (Constants.FULL_ACTIONS_MAP.containsKey(lastPathComponent)) {
if (isUpdate) {
// when only one child node is selected, enable this action
anusreelakshmi934 marked this conversation as resolved.
Show resolved Hide resolved
e.getPresentation().setEnabled(true);
} else {
// calls selected action
AnAction action = ActionManager.getInstance().getAction(Constants.FULL_ACTIONS_MAP.get(lastPathComponent));
action.actionPerformed(new AnActionEvent(null, DataManager.getInstance().getDataContext(libertyTree), e.getPlace(), e.getPresentation(), ActionManager.getInstance(), 0));
}
}
}
}
} else {
LOGGER.debug("Tree view not built, no valid projects to run Liberty dev actions on");
}
}
if (libertyTree == null) {
LOGGER.debug("Tree view not built, no valid projects to run Liberty dev actions on");
}
}
}

Expand All @@ -94,31 +108,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
action.actionPerformed(new AnActionEvent(null, e.getDataContext(), e.getPlace(), e.getPresentation(), ActionManager.getInstance(), 0));
}
} else {
// triggered through icon on tool window
ToolWindow libertyDevToolWindow = ToolWindowManager.getInstance(project).getToolWindow(Constants.LIBERTY_DEV_DASHBOARD_ID);

Content content = libertyDevToolWindow.getContentManager().findContent(LocalizedResourceUtil.getMessage("liberty.tool.window.display.name"));

JComponent libertyWindow = content.getComponent();

Component[] components = libertyWindow.getComponents();

for (Component comp : components) {
if (comp.getName() != null && comp.getName().equals(Constants.LIBERTY_TREE)) {
Tree libertyTree = (Tree) comp;
TreePath[] selectionPaths = libertyTree.getSelectionPaths();
if (selectionPaths != null && selectionPaths.length == 1) {
String lastPathComponent = selectionPaths[0].getLastPathComponent().toString();
if (Constants.FULL_ACTIONS_MAP.containsKey(lastPathComponent)) {
// calls selected action
anusreelakshmi934 marked this conversation as resolved.
Show resolved Hide resolved
AnAction action = ActionManager.getInstance().getAction(Constants.FULL_ACTIONS_MAP.get(lastPathComponent));
action.actionPerformed(new AnActionEvent(null, DataManager.getInstance().getDataContext(libertyTree), e.getPlace(), e.getPresentation(), ActionManager.getInstance(), 0));
}
}
} else {
LOGGER.debug("Tree view not built, no valid projects to run Liberty dev actions on");
}
}
handleLibertyTreeEvent(e, project, false);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 IBM Corporation.
* Copyright (c) 2020, 2024 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -41,6 +41,7 @@ public final class Constants {


public static final String LIBERTY_TREE = "LibertyTree";
public static final String LIBERTY_SCROLL_PANE = "LibertyScrollPane";

/**
* Constants for Data Context, passing information between the tree nodes and the Actions
Expand Down
Loading