Skip to content

Commit 176d658

Browse files
committed
Add tooltips for method categories and improve data representation
1 parent 4ad65c0 commit 176d658

File tree

6 files changed

+66
-91
lines changed

6 files changed

+66
-91
lines changed

swan_assist/src/de/fraunhofer/iem/swan/assist/data/JSONFileLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class JSONFileLoader {
2323
static public final int RESTORED_METHOD = 2;
2424
static private boolean reloadingSwan = false;
2525

26+
2627
//Get configuration file location
2728
public static void setConfigurationFile(String path) {
2829

swan_assist/src/de/fraunhofer/iem/swan/assist/ui/CategoryRenderer.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import javax.swing.*;
99
import java.awt.*;
10+
import java.util.ResourceBundle;
1011

1112
/**
1213
* Rendering options for a category show in the list.
@@ -27,8 +28,17 @@ public Component getListCellRendererComponent(JList<? extends Category> list, Ca
2728
setForeground(JBColor.BLACK);
2829
}
2930

31+
if (category.isCwe()) {
32+
33+
ResourceBundle resourceBundle = ResourceBundle.getBundle("dialog_messages");
34+
35+
setText("<html>" + Formatter.toTitleCase(category.toString()) + " <font color='gray'>" + resourceBundle.getString(category.toString() + ".Name") + "</font></html>");
36+
setToolTipText("<html>" + "<b>" + Formatter.toTitleCase(category.toString()) + "</b> " + resourceBundle.getString(category.toString() + ".FullName") + "</html>");
37+
} else {
38+
setText(Formatter.toTitleCase(category.toString()));
39+
}
40+
3041
setIcon(IconUtils.getIcon(category.toString()));
31-
setText(Formatter.toTitleCase(category.toString()));
3242
setBorder(BorderFactory.createEmptyBorder(3, 4, 2, 0));
3343
setOpaque(true);
3444

swan_assist/src/de/fraunhofer/iem/swan/assist/ui/MethodListTree.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
import com.intellij.ui.treeStructure.Tree;
2727
import com.intellij.util.messages.MessageBus;
2828
import de.fraunhofer.iem.swan.assist.actions.method.MethodActionGroup;
29-
import de.fraunhofer.iem.swan.assist.comm.FileSelectedNotifier;
30-
import de.fraunhofer.iem.swan.assist.comm.FilterNotifier;
31-
import de.fraunhofer.iem.swan.assist.comm.MethodNotifier;
32-
import de.fraunhofer.iem.swan.assist.comm.SwanNotifier;
29+
import de.fraunhofer.iem.swan.assist.comm.*;
3330
import de.fraunhofer.iem.swan.assist.data.JSONFileLoader;
3431
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
3532
import de.fraunhofer.iem.swan.assist.ui.dialog.SwanResultsDialog;
@@ -190,17 +187,28 @@ public void afterAction(MethodWrapper newMethod) {
190187

191188
break;
192189
case JSONFileLoader.NEW_METHOD:
193-
DefaultMutableTreeNode root = (DefaultMutableTreeNode) getModel().getRoot();
194-
DefaultMutableTreeNode newMethodNode = new DefaultMutableTreeNode(newMethod);
195190

196-
treeModel.insertNodeInto(addCategoriesToNode(newMethodNode, newMethod), root, root.getChildCount());
191+
addNode(newMethod);
197192
break;
198193
}
199194

200195
DaemonCodeAnalyzer.getInstance(project).restart();
201196
}
202197
});
203198

199+
bus.connect().subscribe(SuggestedNotifier.METHOD_SUGGESTED_TOPIC, new SuggestedNotifier() {
200+
@Override
201+
public void afterAction(ArrayList<MethodWrapper> methods) {
202+
203+
System.out.println("n=mi get "+methods.size());
204+
for(MethodWrapper method: methods){
205+
JSONFileLoader.addMethod(method);
206+
addNode(method);
207+
}
208+
DaemonCodeAnalyzer.getInstance(project).restart();
209+
}
210+
});
211+
204212
//Connect to project bus and obtain method that was deleted
205213
bus.connect().subscribe(MethodNotifier.METHOD_REMOVED_TOPIC, new MethodNotifier() {
206214
@Override
@@ -334,6 +342,13 @@ private DefaultMutableTreeNode searchNode(DefaultMutableTreeNode root, String me
334342
return null;
335343
}
336344

345+
private void addNode(MethodWrapper method){
346+
DefaultMutableTreeNode root = (DefaultMutableTreeNode) getModel().getRoot();
347+
DefaultMutableTreeNode newMethodNode = new DefaultMutableTreeNode(method);
348+
349+
treeModel.insertNodeInto(addCategoriesToNode(newMethodNode, method), root, root.getChildCount());
350+
}
351+
337352
/**
338353
* Extracts categories from method and adds them to the DefaultMutableTreeNode node.
339354
*

swan_assist/src/de/fraunhofer/iem/swan/assist/ui/MethodTreeRenderer.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package de.fraunhofer.iem.swan.assist.ui;
22

33
import com.intellij.ui.JBColor;
4-
import de.fraunhofer.iem.swan.assist.data.InfoBank;
54
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
65
import de.fraunhofer.iem.swan.assist.util.Constants;
76
import de.fraunhofer.iem.swan.assist.util.Formatter;
8-
import de.fraunhofer.iem.swan.data.CWE;
97
import de.fraunhofer.iem.swan.data.Category;
108
import icons.IconUtils;
119

1210
import javax.swing.*;
1311
import javax.swing.tree.DefaultMutableTreeNode;
1412
import javax.swing.tree.TreeCellRenderer;
1513
import java.awt.*;
16-
import java.util.ArrayList;
14+
import java.util.ResourceBundle;
1715

1816
/**
1917
* Rendering options for a method in the list.
@@ -39,7 +37,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean
3937
if (object instanceof MethodWrapper) {
4038

4139
MethodWrapper method = (MethodWrapper) object;
42-
text.setText("<html>" + Formatter.trimProperty(method.getMethodName(false)) + " ( ) <font color='gray'>" + Formatter.trimProperty(method.getReturnType(false)) + "</font></html>");
40+
text.setText("<html><font color='gray'>" + Formatter.trimProperty(method.getReturnType(false)) + "</font> <b>" + Formatter.trimProperty(method.getMethodName(false)) + "</b> ( )</html>");
4341
text.setIcon(IconUtils.getNodeIcon(method.getTypesList(false)));
4442

4543
if (method.getUpdateOperation() != null && method.getUpdateOperation().equals(Constants.METHOD_ADDED) && !selected)
@@ -54,7 +52,14 @@ else if (method.getUpdateOperation() != null && method.getUpdateOperation().equa
5452
Category category = (Category) object;
5553

5654
text.setIcon(IconUtils.getIcon(category.toString()));
57-
text.setText(category.toString());
55+
56+
if (category.isCwe()) {
57+
58+
ResourceBundle resourceBundle = ResourceBundle.getBundle("dialog_messages");
59+
text.setText("<html>" + category.toString() + " <font color='gray'>" + resourceBundle.getString(category.toString() + ".Name") + "</font></html>");
60+
text.setToolTipText("<html>" + "<b>" + category.toString() + "</b> " + resourceBundle.getString(category.toString() + ".FullName") + "</html>");
61+
} else
62+
text.setText(category.toString());
5863
} else {
5964

6065
text.setText(value.toString());

swan_assist/src/de/fraunhofer/iem/swan/assist/ui/dialog/MethodPropertiesDialog.form

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.fraunhofer.iem.swan.assist.ui.dialog.MethodPropertiesDialog">
3-
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
3+
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="10" left="10" bottom="10" right="10"/>
55
<constraints>
6-
<xy x="48" y="54" width="960" height="297"/>
6+
<xy x="511" y="54" width="497" height="280"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
@@ -16,52 +16,24 @@
1616
<properties/>
1717
<border type="none"/>
1818
<children>
19-
<splitpane id="7b244">
19+
<scrollpane id="4d5e7">
2020
<constraints>
21-
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
22-
<preferred-size width="376" height="314"/>
21+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
22+
<preferred-size width="500" height="250"/>
2323
</grid>
2424
</constraints>
25-
<properties>
26-
<dividerLocation value="150"/>
27-
<dividerSize value="8"/>
28-
<orientation value="0"/>
29-
</properties>
30-
<border type="empty"/>
25+
<properties/>
26+
<border type="none"/>
3127
<children>
32-
<scrollpane id="9394f">
33-
<constraints>
34-
<splitpane position="left"/>
35-
</constraints>
36-
<properties/>
37-
<border type="none" title-resource-bundle="dialog_messages" title-key="Properties.Category"/>
38-
<children>
39-
<component id="d92bd" class="javax.swing.JTable" binding="table">
40-
<constraints/>
41-
<properties/>
42-
</component>
43-
</children>
44-
</scrollpane>
45-
<scrollpane id="a301d">
46-
<constraints>
47-
<splitpane position="right"/>
48-
</constraints>
49-
<properties/>
50-
<border type="none"/>
51-
<children>
52-
<component id="c3da5" class="javax.swing.JTextPane" binding="description">
53-
<constraints/>
54-
<properties>
55-
<contentType value="text/html"/>
56-
<editable value="false"/>
57-
<font swing-font="Label.font"/>
58-
<text value="&lt;html&gt;&#10; &lt;head&gt;&#10; &#10; &lt;/head&gt;&#10; &lt;body&gt;&#10; &lt;p style=&quot;margin-top: 0&quot;&gt;&#10; Nothing to show,&#10; &lt;/p&gt;&#10; &lt;/body&gt;&#10;&lt;/html&gt;&#10;"/>
59-
</properties>
60-
</component>
61-
</children>
62-
</scrollpane>
28+
<component id="e9d57" class="com.intellij.ui.table.JBTable" binding="table">
29+
<constraints/>
30+
<properties>
31+
<fillsViewportHeight value="true"/>
32+
<striped value="true"/>
33+
</properties>
34+
</component>
6335
</children>
64-
</splitpane>
36+
</scrollpane>
6537
</children>
6638
</grid>
6739
</children>

swan_assist/src/de/fraunhofer/iem/swan/assist/ui/dialog/MethodPropertiesDialog.java

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22

33
import com.intellij.openapi.project.Project;
44
import com.intellij.openapi.ui.DialogWrapper;
5-
import de.fraunhofer.iem.swan.assist.data.InfoBank;
5+
import com.intellij.ui.table.JBTable;
66
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
7-
import de.fraunhofer.iem.swan.assist.util.Constants;
8-
import de.fraunhofer.iem.swan.data.CWE;
97
import org.apache.commons.lang3.StringUtils;
108
import org.jetbrains.annotations.Nullable;
119

1210
import javax.swing.*;
13-
import javax.swing.event.ListSelectionEvent;
14-
import javax.swing.event.ListSelectionListener;
1511
import javax.swing.table.DefaultTableModel;
1612
import javax.swing.table.TableModel;
17-
import java.util.ArrayList;
1813
import java.util.ResourceBundle;
1914

2015
/**
@@ -25,16 +20,15 @@
2520

2621
public class MethodPropertiesDialog extends DialogWrapper {
2722
private JPanel contentPane;
28-
private JTable table;
29-
private JTextPane description;
23+
private JBTable table;
3024

3125
public MethodPropertiesDialog(Project project, MethodWrapper method) {
3226

3327
super(project);
3428

3529
ResourceBundle resourceBundle = ResourceBundle.getBundle("dialog_messages");
3630
//Table Columns
37-
Object[] columnNames = {resourceBundle.getString("Properties.Category"),resourceBundle.getString("Properties.Value") };
31+
Object[] columnNames = {resourceBundle.getString("Properties.Category"), resourceBundle.getString("Properties.Value") };
3832
//Table data
3933
Object[][] values = {{resourceBundle.getString("Properties.Return"), method.getReturnType(true)},
4034
{resourceBundle.getString("Properties.Method"), method.getMethodName(true)},
@@ -50,34 +44,12 @@ public MethodPropertiesDialog(Project project, MethodWrapper method) {
5044
TableModel tableModel = new DefaultTableModel(values, columnNames);
5145

5246
table.setModel(tableModel);
47+
table.getColumnModel().getColumn(0).setMinWidth(10);
48+
table.getColumnModel().getColumn(1).setMinWidth(300);
49+
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
5350

54-
//TODO show description in textArea or description field
55-
//description.setContentType("text/html");
56-
description.setBorder(null);
57-
//description.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 13));
58-
description.setOpaque(true);
59-
60-
setTitle(resourceBundle.getString("Properties.Title"));
6151
init();
62-
63-
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
64-
public void valueChanged(ListSelectionEvent event) {
65-
66-
if (table.getValueAt(table.getSelectedRow(), 0).toString().contains(Constants.FILTER_CWE)) {
67-
68-
InfoBank info = new InfoBank();
69-
ArrayList<CWE> cwe = info.getCWEDetails(table.getValueAt(table.getSelectedRow(), 1).toString());
70-
71-
StringBuilder cweDescription = new StringBuilder();
72-
73-
for (CWE entry : cwe) {
74-
cweDescription.append("<b>CWE" + entry.getId() + " " + entry.getName() + "</b><p><b>Description: </b>" + entry.getShortName() + "</p>");
75-
}
76-
77-
description.setText("<html>" + cweDescription + "</html>");
78-
}
79-
}
80-
});
52+
setTitle(resourceBundle.getString("Properties.Title"));
8153
}
8254

8355
@Nullable

0 commit comments

Comments
 (0)