Skip to content

Commit 179a4db

Browse files
committed
Update UI to support suggesting methods
1 parent a5448f2 commit 179a4db

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

swan_assist/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repositories {
1414

1515
dependencies {
1616
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
17-
compile group:'de.upb.cs.swt', name: 'swan_core', version: '1.3.0'
17+
compile group:'de.upb.cs.swt', name: 'swan_core', version: '1.2.1'
1818
compile group: 'ca.mcgill.sable', name: 'soot', version: '3.3.0'
1919
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.5'
2020
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.5'

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public class MethodListTree extends Tree {
6969
private String currentFile;
7070
public static ArrayList<Pair<String, String>> TREE_FILTERS;
7171
public static boolean RESTORE_METHOD;
72+
public static Set<String> suggestedMethodsList;
7273
private Project project;
7374
private ResourceBundle resource;
7475

@@ -96,6 +97,9 @@ public MethodListTree(Project project) {
9697
RESTORE_METHOD = false;
9798
currentFile = "";
9899

100+
101+
suggestedMethodsList = new HashSet<>();
102+
99103
addMouseListener(new MouseAdapter() {
100104
@Override
101105
public void mouseClicked(MouseEvent e) {
@@ -241,12 +245,26 @@ public void addNewExistingMethod(MethodWrapper newMethod) {
241245
}
242246

243247
@Override
244-
public void afterAction(ArrayList<MethodWrapper> methods) {
248+
public void afterSuggestAction(ArrayList<MethodWrapper> methods) {
249+
250+
HashMap<String, MethodWrapper> suggestedMethods = new HashMap<>();
245251

246252
for (MethodWrapper method : methods) {
247253
JSONFileLoader.addMethod(method);
248254
addNode(method);
255+
suggestedMethods.put(method.getSignature(true), method);
249256
}
257+
258+
TrainingFileManager trainingFileManager = new TrainingFileManager(project);
259+
260+
if(trainingFileManager.exportNew(suggestedMethods, PropertiesComponent.getInstance(project).getValue(Constants.SWAN_OUTPUT_DIR))){
261+
262+
PropertiesComponent.getInstance(project).setValue(Constants.TRAIN_FILE_SUGGESTED,trainingFileManager.getTrainingFile());
263+
264+
NotificationType notificationType = NotificationType.INFORMATION;
265+
Notifications.Bus.notify(new Notification(Constants.PLUGIN_GROUP_DISPLAY_ID, resource.getString("Messages.Title.Suggest.NewTrainingFile"), PropertiesComponent.getInstance(project).getValue(Constants.TRAIN_FILE_SUGGESTED), notificationType));
266+
}
267+
250268
DaemonCodeAnalyzer.getInstance(project).restart();
251269
}
252270

swan_assist/src/main/java/de/fraunhofer/iem/swan/assist/ui/dialog/MethodDialog.form

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<grid id="e3588" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1212
<margin top="0" left="0" bottom="0" right="0"/>
1313
<constraints>
14-
<grid row="1" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
14+
<grid row="1" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
15+
<minimum-size width="300" height="-1"/>
16+
</grid>
1517
</constraints>
1618
<properties/>
1719
<border type="none"/>

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.intellij.openapi.ui.popup.JBPopupFactory;
1515
import com.intellij.util.messages.MessageBus;
1616
import de.fraunhofer.iem.swan.assist.comm.MethodNotifier;
17-
import de.fraunhofer.iem.swan.assist.comm.SuggestedNotifier;
1817
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
1918
import de.fraunhofer.iem.swan.assist.ui.CategoryRenderer;
2019
import de.fraunhofer.iem.swan.data.Category;
@@ -283,8 +282,8 @@ protected void doOKAction() {
283282
if (categorySelected) {
284283
MessageBus messageBus = project.getMessageBus();
285284

286-
SuggestedNotifier publisher = messageBus.syncPublisher(SuggestedNotifier.METHOD_SUGGESTED_TOPIC);
287-
publisher.afterAction(new ArrayList<>(methods.values()));
285+
MethodNotifier publisher = messageBus.syncPublisher(MethodNotifier.ADD_UPDATE_DELETE_METHOD);
286+
publisher.afterSuggestAction(new ArrayList<>(methods.values()));
288287
super.doOKAction();
289288
}
290289
} else if (method.getCategories().size() == 0) {
@@ -294,8 +293,8 @@ protected void doOKAction() {
294293
//Notify Summary Tool window that new method was added
295294
MessageBus messageBus = project.getMessageBus();
296295

297-
MethodNotifier publisher = messageBus.syncPublisher(MethodNotifier.METHOD_UPDATED_ADDED_TOPIC);
298-
publisher.afterAction(method);
296+
MethodNotifier publisher = messageBus.syncPublisher(MethodNotifier.ADD_UPDATE_DELETE_METHOD);
297+
publisher.addNewExistingMethod(method);
299298

300299
super.doOKAction();
301300
}

0 commit comments

Comments
 (0)