4040import de .fraunhofer .iem .swan .assist .comm .*;
4141import de .fraunhofer .iem .swan .assist .data .JSONFileLoader ;
4242import de .fraunhofer .iem .swan .assist .data .MethodWrapper ;
43+ import de .fraunhofer .iem .swan .assist .ui .dialog .MethodDialog ;
4344import de .fraunhofer .iem .swan .assist .ui .dialog .SwanResultsDialog ;
4445import de .fraunhofer .iem .swan .assist .util .Constants ;
4546import de .fraunhofer .iem .swan .assist .util .Formatter ;
4647import de .fraunhofer .iem .swan .assist .util .PsiTraversal ;
4748import de .fraunhofer .iem .swan .data .Category ;
49+ import de .fraunhofer .iem .swan .data .Method ;
4850import javafx .util .Pair ;
4951import org .jetbrains .annotations .NotNull ;
5052
@@ -70,6 +72,7 @@ public class MethodListTree extends Tree {
7072
7173 /**
7274 * Initialises method list tree
75+ *
7376 * @param project Active project in IDE
7477 */
7578 public MethodListTree (Project project ) {
@@ -98,55 +101,62 @@ public void mouseClicked(MouseEvent e) {
98101 if ((SwingUtilities .isRightMouseButton (e ) || (e .isControlDown ()) && !isEmpty ())) {
99102
100103 DefaultMutableTreeNode node = (DefaultMutableTreeNode ) getLastSelectedPathComponent ();
101- Object object = node .getUserObject ();
102104
103- if (object instanceof MethodWrapper ) {
105+ if (node != null ) {
106+
107+ Object object = node .getUserObject ();
108+
109+ if (object instanceof MethodWrapper ) {
104110
105- MethodWrapper method = (MethodWrapper ) object ;
111+ MethodWrapper method = (MethodWrapper ) object ;
106112
107- RESTORE_METHOD = method .getUpdateOperation ().equals (Constants .METHOD_DELETED );
113+ RESTORE_METHOD = method .getUpdateOperation ().equals (Constants .METHOD_DELETED );
108114
109- ActionPopupMenu actionPopupMenu = ActionManager .getInstance ().createActionPopupMenu ("Method" , new MethodActionGroup (method ));
110- actionPopupMenu .getComponent ().show (e .getComponent (), e .getX (), e .getY ());
115+ ActionPopupMenu actionPopupMenu = ActionManager .getInstance ().createActionPopupMenu ("Method" , new MethodActionGroup (method ));
116+ actionPopupMenu .getComponent ().show (e .getComponent (), e .getX (), e .getY ());
117+ }
111118 }
112119
113120 } else if (e .getClickCount () == 2 ) {
114121
115122 DefaultMutableTreeNode node = (DefaultMutableTreeNode ) getLastSelectedPathComponent ();
116- Object object = node .getUserObject ();
123+ if (node != null ) {
124+ Object object = node .getUserObject ();
117125
118- if (object instanceof MethodWrapper ) {
126+ if (object instanceof MethodWrapper ) {
119127
120- MethodWrapper method = (MethodWrapper ) object ;
128+ MethodWrapper method = (MethodWrapper ) object ;
121129
122- //Get PSI element location
123- PsiFile [] files = FilenameIndex .getFilesByName (project , method .getFileName (), GlobalSearchScope .allScope (project ));
130+ //Get PSI element location
131+ PsiFile [] files = FilenameIndex .getFilesByName (project , method .getFileName (), GlobalSearchScope .allScope (project ));
124132
125- boolean methodFound = false ;
133+ boolean methodFound = false ;
126134
127- for (PsiFile file : files ) {
135+ for (PsiFile file : files ) {
128136
129- PsiJavaFile psiJavaFile = (PsiJavaFile ) file ;
137+ PsiJavaFile psiJavaFile = (PsiJavaFile ) file ;
130138
131- for (PsiClass psiClass : psiJavaFile .getClasses ()) {
132- for (PsiMethod psiMethod : psiClass .getMethods ()) {
139+ for (PsiClass psiClass : psiJavaFile .getClasses ()) {
140+ for (PsiMethod psiMethod : psiClass .getMethods ()) {
133141
134- if (Objects .equals (PsiTraversal .getMethodSignature (psiMethod ), method .getSignature (true ))) {
142+ if (Objects .equals (PsiTraversal .getMethodSignature (psiMethod ), method .getSignature (true ))) {
135143
136- methodFound = true ;
137- FileEditorManager .getInstance (project ).openFile (psiJavaFile .getVirtualFile (), true , true );
138- FileEditorManager .getInstance (project ).getSelectedTextEditor ().getCaretModel ().moveToOffset (psiMethod .getTextOffset ());
144+ methodFound = true ;
145+ FileEditorManager .getInstance (project ).openFile (psiJavaFile .getVirtualFile (), true , true );
146+ FileEditorManager .getInstance (project ).getSelectedTextEditor ().getCaretModel ().moveToOffset (psiMethod .getTextOffset ());
147+ }
139148 }
140149 }
141150 }
142- }
143151
144- if (!methodFound ) {
145- JBPopupFactory .getInstance ().createHtmlTextBalloonBuilder (resource .getString ("Messages.Error.MethodNotFound" ), MessageType .ERROR , null )
146- .createBalloon ()
147- .show (JBPopupFactory .getInstance ().guessBestPopupLocation ((JComponent ) e .getComponent ()), Balloon .Position .below );
152+ if (!methodFound ) {
153+ JBPopupFactory .getInstance ().createHtmlTextBalloonBuilder (resource .getString ("Messages.Error.MethodNotFound" ), MessageType .ERROR , null )
154+ .createBalloon ()
155+ .show (JBPopupFactory .getInstance ().guessBestPopupLocation ((JComponent ) e .getComponent ()), Balloon .Position .below );
156+ }
148157 }
149158 }
159+
150160 }
151161 }
152162 });
@@ -279,12 +289,11 @@ public void launchSwan(HashMap<String, String> values) {
279289 JSONFileLoader .setReloading (false );
280290 NotificationType notificationType = NotificationType .INFORMATION ;
281291
282- if (! values . get ( Constants . SWAN_OUTPUT_MESSAGE ). equals ( resource . getString ( "Messages.Notification.Success" ))) {
283- notificationType = NotificationType . ERROR ;
284- }
292+ String message = "<html>"
293+ + resource . getString ( "Messages.Notification.Completed" )
294+ + "<br><a href='logs'>View Logs</a> or <a href='load'>Load Changes</a></html>" ;
285295
286- String message = "<html>" + values .get (Constants .SWAN_OUTPUT_MESSAGE ) + "<br><a href='logs'>View Logs</a> or <a href='load'>Load Changes</a></html>" ;
287- Notifications .Bus .notify (new Notification (Constants .PLUGIN_GROUP_DISPLAY_ID , "Completed" , message , notificationType , new NotificationListener () {
296+ Notifications .Bus .notify (new Notification (Constants .PLUGIN_GROUP_DISPLAY_ID , resource .getString ("Messages.Notification.Title.Completed" ), message , notificationType , new NotificationListener () {
288297 @ Override
289298 public void hyperlinkUpdate (@ NotNull Notification notification , @ NotNull HyperlinkEvent hyperlinkEvent ) {
290299
@@ -305,6 +314,52 @@ public void hyperlinkUpdate(@NotNull Notification notification, @NotNull Hyperli
305314 }
306315 });
307316
317+
318+ //Update Tool Window to notify user that SWAN is running
319+ bus .connect ().subscribe (SuggestNotifier .START_SUGGEST_TOPIC , new SuggestNotifier () {
320+ @ Override
321+ public void setStartSuggestTopic () {
322+ JSONFileLoader .setReloading (true );
323+ Notifications .Bus .notify (new Notification (Constants .PLUGIN_GROUP_DISPLAY_ID , resource .getString ("Messages.Title.SuggestStarted" ), resource .getString ("Messages.Notification.SuggestStarted" ), NotificationType .INFORMATION ));
324+
325+ }
326+
327+ @ Override
328+ public void setEndSuggestTopic (Set <Method > values ) {
329+ JSONFileLoader .setReloading (false );
330+
331+ NotificationType notificationType = NotificationType .INFORMATION ;
332+
333+ String message = "<html>" + resource .getString ("Messages.Notification.Suggest.Successful" ) + "<br><a href='methods'>View methods</a></html>" ;
334+ Notifications .Bus .notify (new Notification (Constants .PLUGIN_GROUP_DISPLAY_ID , "Completed" , message , notificationType , new NotificationListener () {
335+ @ Override
336+ public void hyperlinkUpdate (@ NotNull Notification notification , @ NotNull HyperlinkEvent hyperlinkEvent ) {
337+
338+ if (hyperlinkEvent .getEventType () == HyperlinkEvent .EventType .ACTIVATED ) {
339+
340+ if (hyperlinkEvent .getDescription ().equals ("methods" )) {
341+
342+ HashMap <String ,MethodWrapper > suggestedMethods = new HashMap <>();
343+
344+ for (Method m : values ){
345+
346+ MethodWrapper methodWrapper = new MethodWrapper (m );
347+ methodWrapper .setStatus (MethodWrapper .MethodStatus .SUGGESTED );
348+
349+ suggestedMethods .put (methodWrapper .getSignature (true ), methodWrapper );
350+ }
351+
352+ MethodDialog dialog = new MethodDialog (suggestedMethods , (String )suggestedMethods .keySet ().toArray ()[0 ], project , JSONFileLoader .getCategories ());
353+ dialog .show ();
354+
355+
356+ }
357+ }
358+ }
359+ }));
360+ }
361+ });
362+
308363 //Connect to project bus and obtain filter for Method Tree
309364 bus .connect ().subscribe (FilterNotifier .FILTER_SELECTED_TOPIC , new FilterNotifier () {
310365 @ Override
@@ -379,6 +434,7 @@ private DefaultMutableTreeNode searchNode(DefaultMutableTreeNode root, String me
379434
380435 /**
381436 * Add new node to tree
437+ *
382438 * @param method New method to be added
383439 */
384440 private void addNode (MethodWrapper method ) {
@@ -390,6 +446,7 @@ private void addNode(MethodWrapper method) {
390446
391447 /**
392448 * Extracts categories from method and adds them to the DefaultMutableTreeNode node.
449+ *
393450 * @param method the method that is being added to the tree
394451 * @return the node object with the categories as children
395452 */
@@ -399,6 +456,7 @@ private DefaultMutableTreeNode addCategoriesToNode(MethodWrapper method) {
399456
400457 /**
401458 * Extracts categories from method and adds them to the DefaultMutableTreeNode node.
459+ *
402460 * @param node method to be added to tree
403461 * @param method the method that is being added to the tree
404462 * @return the node object with the categories as children
0 commit comments