Skip to content

Commit

Permalink
Terminal issue fix, collapse/expand fix, execute task fix (eclipse#16)
Browse files Browse the repository at this point in the history
* Terminal issue fix, collapse/expand fix, execute task fix

Signed-off-by: Kathryn Kodama <kathryn.s.kodama@gmail.com>

* fixed action maps

Signed-off-by: Kathryn Kodama <kathryn.s.kodama@gmail.com>
  • Loading branch information
kathrynkodama authored Jul 29, 2020
1 parent f646d6d commit 7b9f00f
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 55 deletions.
39 changes: 20 additions & 19 deletions src/main/java/io/openliberty/tools/intellij/LibertyExplorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.Project;
Expand All @@ -12,8 +13,7 @@
import com.intellij.ui.DoubleClickListener;
import com.intellij.ui.PopupHandler;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.ui.treeStructure.actions.CollapseAllAction;
import com.intellij.ui.treeStructure.actions.ExpandAllAction;
import io.openliberty.tools.intellij.actions.LibertyToolbarActionGroup;
import io.openliberty.tools.intellij.util.*;
import org.jetbrains.annotations.NotNull;

Expand All @@ -28,35 +28,34 @@
import java.util.ArrayList;
import java.util.HashMap;

import com.intellij.openapi.diagnostic.Logger;

public class LibertyExplorer extends SimpleToolWindowPanel {
private static Logger log;

public LibertyExplorer(@NotNull Project project) {
super(true, true);
log = Logger.getInstance(LibertyExplorer.class);

// create ActionToolBar
final ActionManager actionManager = ActionManager.getInstance();
DefaultActionGroup actionGroup = new DefaultActionGroup("DefaultActionGroup", false);
actionGroup.add(ActionManager.getInstance().getAction("io.openliberty.tools.intellij.actions.RefreshLibertyToolbar"));
actionGroup.addSeparator();
actionGroup.add(ActionManager.getInstance().getAction("io.openliberty.tools.intellij.actions.ExecuteLibertyDevTask"));

// build tree
Tree tree = buildTree(project, getBackground());

if (tree != null) {
actionGroup.addSeparator();
actionGroup.add(new CollapseAllAction(tree));
actionGroup.add(new ExpandAllAction(tree));
setContent(tree);
this.setContent(tree);
}

ActionToolbar actionToolbar = actionManager.createActionToolbar(ActionPlaces.UNKNOWN, actionGroup, true);
ActionToolbar actionToolbar = buildActionToolbar(tree);
this.setToolbar(actionToolbar.getComponent());
}

public static ActionToolbar buildActionToolbar(Tree tree) {
// create ActionToolBar
final ActionManager actionManager = ActionManager.getInstance();
LibertyToolbarActionGroup libertyActionGroup = new LibertyToolbarActionGroup(tree);

ActionToolbar actionToolbar = actionManager.createActionToolbar(ActionPlaces.UNKNOWN, libertyActionGroup, true);
actionToolbar.setOrientation(SwingConstants.HORIZONTAL);
actionToolbar.setShowSeparatorTitles(true);
this.setToolbar(actionToolbar.getComponent());
actionToolbar.getComponent().setName(Constants.LIBERTY_ACTION_TOOLBAR);
return actionToolbar;
}

/**
Expand All @@ -66,6 +65,8 @@ public LibertyExplorer(@NotNull Project project) {
* @return Tree object of all valid Liberty Gradle and Liberty Maven projects
*/
public static Tree buildTree(Project project, Color backgroundColor) {
DefaultMutableTreeNode top = new DefaultMutableTreeNode("Root node");

ArrayList<PsiFile> mavenBuildFiles = null;
ArrayList<PsiFile> gradleBuildFiles = null;
ArrayList<String> projectNames = new ArrayList<String>();
Expand All @@ -79,8 +80,6 @@ public static Tree buildTree(Project project, Color backgroundColor) {
return null;
}

DefaultMutableTreeNode top = new DefaultMutableTreeNode("Root node");

for (PsiFile file : mavenBuildFiles) {
String projectName = null;
VirtualFile virtualFile = file.getVirtualFile();
Expand Down Expand Up @@ -264,6 +263,8 @@ ActionPlaces.UNKNOWN, new Presentation(),
newRenderer.setBackgroundNonSelectionColor(backgroundColor);

tree.setCellRenderer(newRenderer);

treeDataProvider.setTreeOnRefresh(tree);
return tree;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public void actionPerformed(@NotNull AnActionEvent e) {

JComponent libertyWindow = content.getComponent();

libertyWindow.list();
Component[] components = libertyWindow.getComponents();

for (Component comp : components) {
Expand All @@ -54,7 +53,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
if (selectionPaths != null && selectionPaths.length == 1) {
// if one node is selected confirm that you would like to execute that task
String lastPathComponent = selectionPaths[0].getLastPathComponent().toString();
if (Constants.ACTIONS_MAP.containsKey(lastPathComponent)) {
if (Constants.getFullActionMap().containsKey(lastPathComponent)) {
// verify user would like to execute this action
final String projectName = (String) e.getDataContext().getData(Constants.LIBERTY_PROJECT_NAME);
boolean confirm = ConfirmationDialog.requestForConfirmation(
Expand All @@ -64,7 +63,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
, Constants.libertyIcon_40);
if (confirm) {
// calls action
AnAction action = ActionManager.getInstance().getAction(Constants.ACTIONS_MAP.get(lastPathComponent));
AnAction action = ActionManager.getInstance().getAction(Constants.getFullActionMap().get(lastPathComponent));
action.actionPerformed(new AnActionEvent(null,
DataManager.getInstance().getDataContext(libertyTree),
ActionPlaces.UNKNOWN, new Presentation(),
Expand All @@ -85,24 +84,12 @@ ActionPlaces.UNKNOWN, new Presentation(),

private void chooseActionToExecute(Tree libertyTree) {
// if 0 or multiple nodes are selected display all possible nodes and allow users to select talk
String[] keyArray = Constants.ACTIONS_MAP.keySet().toArray(new String[Constants.ACTIONS_MAP.keySet().size()]);

int taskSelected = Messages.showChooseDialog("Choose a Liberty Dev task to execute"
, "Execute Liberty Dev Task"
, keyArray, keyArray[0]
, Constants.libertyIcon_40);
if (taskSelected == -1) {
return; // -1 indicates users cancelled dialog
}

String task = keyArray[taskSelected];

HashMap<String, ArrayList<Object>> map = (HashMap<String, ArrayList<Object>>) DataManager.getInstance()
.getDataContext(libertyTree).getData(Constants.LIBERTY_PROJECT_MAP);
String[] projectNamesArr = map.keySet().toArray(new String[map.keySet().size()]);

int projectSelected = Messages.showChooseDialog(
"Choose a project to execute Liberty Dev " + task
"Choose a project to execute a Liberty Dev task on"
, "Choose a project"
, projectNamesArr, projectNamesArr[0]
, Constants.libertyIcon_40);
Expand All @@ -116,10 +103,29 @@ private void chooseActionToExecute(Tree libertyTree) {
ArrayList<Object> settings = map.get(project);
VirtualFile file = (VirtualFile) settings.get(0);
String projectType = (String) settings.get(1);

HashMap<String, String> actionsMap = new HashMap<String, String>();
if (projectType.equals(Constants.LIBERTY_GRADLE_PROJECT)) {
actionsMap = Constants.getGradleMap();
} else if (projectType.equals(Constants.LIBERTY_MAVEN_PROJECT)) {
actionsMap = Constants.getMavenMap();
}
String[] keyArray = actionsMap.keySet().toArray(new String[actionsMap.keySet().size()]);

int taskSelected = Messages.showChooseDialog("Choose a Liberty Dev task to execute on " + project
, "Execute Liberty Dev Task"
, keyArray, keyArray[0]
, Constants.libertyIcon_40);
if (taskSelected == -1) {
return; // -1 indicates users cancelled dialog
}

String task = keyArray[taskSelected];

treeDataProvider.saveData(file, project, projectType);

// execute selected task on selected project
AnAction action = ActionManager.getInstance().getAction(Constants.ACTIONS_MAP.get(task));
AnAction action = ActionManager.getInstance().getAction(actionsMap.get(task));
action.actionPerformed(new AnActionEvent(null,
DataManager.getInstance().getDataContext(libertyTree),
ActionPlaces.UNKNOWN, new Presentation(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.openliberty.tools.intellij.actions;

import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.ui.treeStructure.actions.CollapseAllAction;
import com.intellij.ui.treeStructure.actions.ExpandAllAction;
import io.openliberty.tools.intellij.util.Constants;

public class LibertyToolbarActionGroup extends DefaultActionGroup {

private CollapseAllAction collapseAction;
private ExpandAllAction expandAction;
private Tree tree;

public LibertyToolbarActionGroup(Tree tree) {
super("LibertyActionToolBar", false);
this.tree = tree;
final ActionManager actionManager = ActionManager.getInstance();
add(actionManager.getAction("io.openliberty.tools.intellij.actions.RefreshLibertyToolbar"));
addSeparator();
add(actionManager.getAction("io.openliberty.tools.intellij.actions.ExecuteLibertyDevTask"));
addSeparator();

this.collapseAction = new CollapseAllAction(tree);
this.expandAction = new ExpandAllAction(tree);
add(this.collapseAction);
add(this.expandAction);
}

@Override
public void update(AnActionEvent event) {
// Enable/disable depending on whether user is editing...
Tree updatedTree = (Tree) event.getDataContext().getData(Constants.LIBERTY_DASHBOARD_TREE);

if (updatedTree != null && updatedTree != this.tree) {
remove(this.collapseAction);
remove(this.expandAction);
CollapseAllAction newCollapseAction = new CollapseAllAction(updatedTree);
ExpandAllAction newExpandAction = new ExpandAllAction(updatedTree);
add(newCollapseAction);
add(newExpandAction);
this.collapseAction = newCollapseAction;
this.expandAction = newExpandAction;
this.tree = updatedTree;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.openliberty.tools.intellij.actions;

import com.intellij.ide.DataManager;
import com.intellij.ide.projectView.ProjectView;
import com.intellij.openapi.actionSystem.ActionToolbar;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.diagnostic.Logger;
Expand All @@ -8,10 +11,11 @@
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import com.intellij.ui.treeStructure.Tree;
import org.jetbrains.annotations.NotNull;
import io.openliberty.tools.intellij.LibertyExplorer;
import io.openliberty.tools.intellij.util.Constants;
import io.openliberty.tools.intellij.util.LibertyProjectUtil;
import io.openliberty.tools.intellij.util.TreeDataProvider;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;
Expand All @@ -25,30 +29,49 @@ public void update(@NotNull AnActionEvent e) {

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Logger log = Logger.getInstance(RefreshLibertyToolbar.class);;
Logger log = Logger.getInstance(RefreshLibertyToolbar.class);


final Project project = LibertyProjectUtil.getProject(e.getDataContext());
if (project == null) {
log.debug("Unable to refresh Liberty toolbar, could not resolve project");
return;
}
ProjectView.getInstance(project).refresh();

ToolWindow libertyDevToolWindow = ToolWindowManager.getInstance(project).getToolWindow(Constants.LIBERTY_DEV_DASHBOARD_ID);

Content content = libertyDevToolWindow.getContentManager().findContent("Projects");

JComponent libertyWindow = content.getComponent();

libertyWindow.list();
Component[] components = libertyWindow.getComponents();

Component existingTree = null;
Component existingActionToolbar = null;
for (Component comp: components) {
if (comp.getName() != null && comp.getName().equals(Constants.LIBERTY_TREE)) {
Tree tree = LibertyExplorer.buildTree(project, content.getComponent().getBackground());
content.getComponent().remove(comp);
content.getComponent().add(tree);
existingTree = comp;
}
if (comp.getName() != null && comp.getName().equals(Constants.LIBERTY_ACTION_TOOLBAR)) {
existingActionToolbar = comp;
}
}

if (existingTree != null && existingActionToolbar != null) {
Tree tree = LibertyExplorer.buildTree(project, content.getComponent().getBackground());

ActionToolbar actionToolbar = (ActionToolbar) existingActionToolbar;

libertyWindow.remove(existingTree);
libertyWindow.add(tree, BorderLayout.CENTER);
libertyWindow.revalidate();
libertyWindow.repaint();

TreeDataProvider treeDataProvider = (TreeDataProvider) DataManager.getDataProvider(tree);
treeDataProvider.setTreeOnRefresh(tree);
actionToolbar.updateActionsImmediately();
actionToolbar.setShowSeparatorTitles(true);
}
}
}
31 changes: 26 additions & 5 deletions src/main/java/io/openliberty/tools/intellij/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import javax.swing.*;
import java.util.HashMap;
import java.util.Map;

public final class Constants {
public static final String LIBERTY_DEV_DASHBOARD_ID = "Liberty Dev Dashboard";
Expand Down Expand Up @@ -36,6 +35,8 @@ public final class Constants {
public static final String LIBERTY_PROJECT_NAME = "LIBERTY_PROJECT_NAME";
public static final String LIBERTY_PROJECT_TYPE = "LIBERTY_PROJECT_TYPE";
public static final String LIBERTY_PROJECT_MAP = "LIBERTY_PROJECT_MAP";
public static final String LIBERTY_DASHBOARD_TREE = "LIBERTY_DASHBOARD_TREE";
public static final String LIBERTY_ACTION_TOOLBAR = "LIBERTY_ACTION_TOOLBAR";

/**
* Constants for Action IDs
Expand All @@ -50,16 +51,36 @@ public final class Constants {
public static final String VIEW_GRADLE_CONFIG_ACTION_ID = "io.openliberty.tools.intellij.actions.ViewGradleConfig";
public static final String VIEW_EFFECTIVE_POM_ACTION_ID = "io.openliberty.tools.intellij.actions.ViewEffectivePom";

public static final Map<String, String> ACTIONS_MAP = new HashMap<String, String>() {
private static HashMap<String, String> CORE_ACTIONS_MAP = new HashMap<String, String>() {
{
put(LIBERTY_DEV_START, LIBERTY_DEV_START_ACTION_ID);
put(LIBERTY_DEV_STOP, LIBERTY_DEV_STOP_ACTION_ID);
put(LIBERTY_DEV_CUSTOM_START, LIBERTY_DEV_CUSTOM_START_ACTION_ID);
put(LIBERTY_DEV_TESTS, LIBERTY_DEV_TESTS_ACTION_ID);
put(VIEW_UNIT_TEST_REPORT, VIEW_UNIT_TEST_REPORT_ACTION_ID);
put(VIEW_INTEGRATION_TEST_REPORT, VIEW_INTEGRATION_TEST_REPORT_ACTION_ID);
put(VIEW_GRADLE_TEST_REPORT, VIEW_GRADLE_TEST_REPORT_ACTION_ID);
}
};

public static HashMap<String, String> getFullActionMap() {
HashMap<String, String> fullActionsMap = new HashMap<String, String>();
fullActionsMap.putAll(CORE_ACTIONS_MAP);
fullActionsMap.put(VIEW_UNIT_TEST_REPORT, VIEW_UNIT_TEST_REPORT_ACTION_ID);
fullActionsMap.put(VIEW_INTEGRATION_TEST_REPORT, VIEW_INTEGRATION_TEST_REPORT_ACTION_ID);
fullActionsMap.put(VIEW_GRADLE_TEST_REPORT, VIEW_GRADLE_TEST_REPORT_ACTION_ID);
return fullActionsMap;
}

public static HashMap<String, String> getMavenMap() {
HashMap<String, String> mavenActionsMap = new HashMap<String, String>();
mavenActionsMap.putAll(CORE_ACTIONS_MAP);
mavenActionsMap.put(VIEW_UNIT_TEST_REPORT, VIEW_UNIT_TEST_REPORT_ACTION_ID);
mavenActionsMap.put(VIEW_INTEGRATION_TEST_REPORT, VIEW_INTEGRATION_TEST_REPORT_ACTION_ID);
return mavenActionsMap;
}

public static HashMap<String, String> getGradleMap() {
HashMap<String, String> gradleActionsMap = new HashMap<String, String>();
gradleActionsMap.putAll(CORE_ACTIONS_MAP);
gradleActionsMap.put(VIEW_GRADLE_TEST_REPORT, VIEW_GRADLE_TEST_REPORT_ACTION_ID);
return gradleActionsMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import com.intellij.terminal.JBTerminalWidget;
import com.intellij.ui.content.Content;
import com.sun.istack.Nullable;
import org.jetbrains.plugins.terminal.AbstractTerminalRunner;
import org.jetbrains.plugins.terminal.ShellTerminalWidget;
import org.jetbrains.plugins.terminal.TerminalTabState;
import org.jetbrains.plugins.terminal.TerminalView;
import org.jetbrains.plugins.terminal.*;

import java.util.ArrayList;
import java.util.Objects;
Expand Down Expand Up @@ -64,11 +61,11 @@ public static ShellTerminalWidget getTerminalWidget(Project project, String proj
} else if (createWidget) {
// create a new terminal tab
TerminalView terminalView = TerminalView.getInstance(project);
AbstractTerminalRunner terminalRunner = terminalView.getTerminalRunner();
LocalTerminalDirectRunner terminalRun = new LocalTerminalDirectRunner(project);
TerminalTabState tabState = new TerminalTabState();
tabState.myTabName = projectName;
tabState.myWorkingDirectory = project.getBasePath();
terminalView.createNewSession(terminalRunner, tabState);
terminalView.createNewSession(terminalRun, tabState);
return getTerminalWidget(terminalWindow, projectName);
}
return null;
Expand Down
Loading

0 comments on commit 7b9f00f

Please sign in to comment.