Skip to content

Commit

Permalink
Merge pull request OpenLiberty#485 from anusreelakshmi934/bugfix/Open…
Browse files Browse the repository at this point in the history
…Liberty#175

Fixes OpenLiberty#175 Liberty tool window doesn't scroll
  • Loading branch information
anusreelakshmi934 authored Feb 13, 2024
2 parents 34aa606 + fb01600 commit b313401
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 45 deletions.
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;
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
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
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

0 comments on commit b313401

Please sign in to comment.