Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anusreelakshmi934 committed Jan 25, 2024
1 parent a2e4932 commit 86eb7e9
Showing 1 changed file with 25 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,40 @@ 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;
}
getLibertyTree(e, project, true);
}

private static void getLibertyTree(@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 instanceof JBScrollPane && comp.getName() != null && comp.getName().equals(Constants.LIBERTY_SCROLL_PANE)) {
JBScrollPane scrollPane = (JBScrollPane) comp;
if (scrollPane.getViewport().getView() instanceof Tree) {
Tree libertyTree = (Tree) scrollPane.getViewport().getView();

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();
// 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)) {
if (isUpdate) {
e.getPresentation().setEnabled(true);
} else {
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 @@ -97,33 +107,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 instanceof JBScrollPane && comp.getName() != null && comp.getName().equals(Constants.LIBERTY_SCROLL_PANE)) {
JBScrollPane scrollPane = (JBScrollPane) comp;
if (scrollPane.getViewport().getView() instanceof Tree) {
Tree libertyTree = (Tree) scrollPane.getViewport().getView();
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");
}
}
getLibertyTree(e, project, false);
}
}
}

0 comments on commit 86eb7e9

Please sign in to comment.