Skip to content

Commit 89b9eea

Browse files
committed
Add new action to expand/collapse tree
1 parent ff1f049 commit 89b9eea

File tree

8 files changed

+71
-1
lines changed

8 files changed

+71
-1
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package de.fraunhofer.iem.swan.assist.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnAction;
4+
import com.intellij.openapi.actionSystem.AnActionEvent;
5+
import com.intellij.openapi.application.ApplicationManager;
6+
import com.intellij.util.messages.MessageBus;
7+
import de.fraunhofer.iem.swan.assist.comm.ExpandNotifier;
8+
import de.fraunhofer.iem.swan.assist.data.JSONFileLoader;
9+
import de.fraunhofer.iem.swan.assist.ui.MethodListTree;
10+
import icons.PluginIcons;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
/**
14+
* @author Oshando Johnson on 2020-01-07
15+
*/
16+
public class ExpandAllAction extends AnAction {
17+
18+
@Override
19+
public void actionPerformed(@NotNull AnActionEvent e) {
20+
21+
MessageBus messageBus = ApplicationManager.getApplication().getMessageBus();
22+
ExpandNotifier publisher = messageBus.syncPublisher(ExpandNotifier.EXPAND_COLLAPSE_LIST);
23+
publisher.expandTree(true);
24+
25+
}
26+
27+
/**
28+
* Controls whether the action is enabled or disabled
29+
* @param event source event
30+
*/
31+
@Override
32+
public void update(@NotNull AnActionEvent event) {
33+
34+
//Disable/Enable action button
35+
if (JSONFileLoader.isFileSelected())
36+
event.getPresentation().setEnabled(true);
37+
else
38+
event.getPresentation().setEnabled(false);
39+
40+
41+
//Disable/Enable action button
42+
if (MethodListTree.TREE_EXPANDED){
43+
event.getPresentation().setIcon(PluginIcons.COLLAPSE);
44+
event.getPresentation().setText("Collapse Tree");
45+
} else{
46+
event.getPresentation().setIcon(PluginIcons.EXPAND);
47+
event.getPresentation().setText("Expand Tree");
48+
}
49+
}
50+
51+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package de.fraunhofer.iem.swan.assist.comm;
2+
3+
import com.intellij.util.messages.Topic;
4+
5+
/**
6+
* @author Oshando Johnson on 2020-01-07
7+
*/
8+
public interface ExpandNotifier {
9+
10+
Topic<ExpandNotifier> EXPAND_COLLAPSE_LIST = Topic.create("Expand list", ExpandNotifier.class);
11+
12+
void expandTree(boolean expand);
13+
}

swan_assist/src/main/java/icons/PluginIcons.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public interface PluginIcons {
2424
Icon ADD_METHOD_ACTION = IconLoader.getIcon("/icons/add.png");
2525
Icon EXPORT_ACTION = IconLoader.getIcon("/icons/export.png");
2626
Icon SUGGEST_ACTION = IconLoader.getIcon("/icons/suggest.png");
27+
Icon EXPAND = IconLoader.getIcon("/icons/expand.png");
28+
Icon COLLAPSE = IconLoader.getIcon("/icons/collapse.png");
2729

2830
Icon SOURCE = IconLoader.getIcon("/icons/sou.png");
2931
Icon SANITIZER = IconLoader.getIcon("/icons/san.png");
@@ -34,6 +36,5 @@ public interface PluginIcons {
3436
Icon CWE = IconLoader.getIcon("/icons/cwe.png");
3537
Icon DEFAULT = IconLoader.getIcon("/icons/default.png");
3638

37-
3839
Icon SELECTED = IconLoader.getIcon("/icons/selected.png");
3940
}

swan_assist/src/main/resources/META-INF/plugin.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
text="Filter Methods"
4949
popup="true" icon="PluginIcons.FILTER_ACTION">
5050
</group>
51+
<action id="SWAN_Assist.ExpandAll" class="de.fraunhofer.iem.swan.assist.actions.ExpandAllAction"
52+
text="Expand All"
53+
icon="PluginIcons.EXPAND"
54+
description="Expand or collapse the method tree">
55+
</action>
5156
<separator/>
5257

5358
<action id="SWAN_Assist.LaunchSWANAction"
452 Bytes
Loading
811 Bytes
Loading
485 Bytes
Loading
1.07 KB
Loading

0 commit comments

Comments
 (0)