changeset 3224:c7171e87154d

IdealGraphVisualizer: show a warning and ask the user whether to proceed before viewing a graph while the graph or its group is still being loaded. Opening such a graph can cause numerous problems and typically results in a NullPointerException or ConcurrentModificationException.
author Peter Hofer <peter.hofer@jku.at>
date Mon, 18 Jul 2011 13:30:37 +0200
parents a581e5d934a9
children 7610d0b83fd1
files src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/GraphNode.java src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/DiffGraphCookie.java src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphOpenCookie.java src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphRemoveCookie.java src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java
diffstat 6 files changed, 145 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/GraphNode.java	Mon Jul 18 11:35:16 2011 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/GraphNode.java	Mon Jul 18 13:30:37 2011 +0200
@@ -25,6 +25,8 @@
 
 import com.sun.hotspot.igv.coordinator.actions.DiffGraphAction;
 import com.sun.hotspot.igv.coordinator.actions.DiffGraphCookie;
+import com.sun.hotspot.igv.coordinator.actions.GraphOpenCookie;
+import com.sun.hotspot.igv.coordinator.actions.GraphRemoveCookie;
 import com.sun.hotspot.igv.coordinator.actions.RemoveCookie;
 import com.sun.hotspot.igv.data.InputGraph;
 import com.sun.hotspot.igv.data.Properties;
@@ -65,21 +67,11 @@
 
         if (viewer != null) {
             // Action for opening the graph
-            content.add(new OpenCookie() {
-
-                public void open() {
-                    viewer.view(graph);
-                }
-            });
+            content.add(new GraphOpenCookie(viewer, graph));
         }
 
         // Action for removing a graph
-        content.add(new RemoveCookie() {
-
-            public void remove() {
-                graph.getGroup().removeGraph(graph);
-            }
-        });
+        content.add(new GraphRemoveCookie(graph));
 
         // Action for diffing to the current graph
         content.add(new DiffGraphCookie(graph));
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/DiffGraphCookie.java	Mon Jul 18 11:35:16 2011 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/DiffGraphCookie.java	Mon Jul 18 13:30:37 2011 +0200
@@ -21,7 +21,6 @@
  * questions.
  *
  */
-
 package com.sun.hotspot.igv.coordinator.actions;
 
 import com.sun.hotspot.igv.data.InputGraph;
@@ -29,9 +28,11 @@
 import com.sun.hotspot.igv.data.services.InputGraphProvider;
 import com.sun.hotspot.igv.difference.Difference;
 import com.sun.hotspot.igv.util.LookupHistory;
+import org.openide.DialogDescriptor;
+import org.openide.DialogDisplayer;
+import org.openide.NotifyDescriptor;
 import org.openide.nodes.Node;
 import org.openide.util.Lookup;
-import org.openide.util.Utilities;
 
 /**
  *
@@ -39,19 +40,17 @@
  */
 public class DiffGraphCookie implements Node.Cookie {
 
-    private InputGraph a;
+    private InputGraph graph;
 
-    public DiffGraphCookie(InputGraph a) {
-        this.a = a;
+    public DiffGraphCookie(InputGraph graph) {
+        this.graph = graph;
     }
 
     private InputGraph getCurrentGraph() {
-        
-        InputGraphProvider graphProvider = LookupHistory.getLast(InputGraphProvider.class);//)Utilities.actionsGlobalContext().lookup(InputGraphProvider.class);
+        InputGraphProvider graphProvider = LookupHistory.getLast(InputGraphProvider.class);
         if (graphProvider != null) {
             return graphProvider.getGraph();
         }
-
         return null;
     }
 
@@ -60,11 +59,20 @@
     }
 
     public void openDiff() {
-        
+        InputGraph other = getCurrentGraph();
+
+        if (!graph.getGroup().isComplete() || !other.getGroup().isComplete()) {
+            String msg = "One of the graphs or the groups they belong to are still being loaded. Creating a diff now can cause problems. Do you want to continue?";
+            NotifyDescriptor desc = new NotifyDescriptor(msg, "Incomplete data", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE, null, NotifyDescriptor.NO_OPTION);
+
+            if (DialogDisplayer.getDefault().notify(desc) == DialogDescriptor.NO_OPTION) {
+                return;
+            }
+        }
+
         final GraphViewer viewer = Lookup.getDefault().lookup(GraphViewer.class);
-        InputGraph other = getCurrentGraph();
-        if(viewer != null) {
-            InputGraph diffGraph = Difference.createDiffGraph(other, a);
+        if (viewer != null) {
+            InputGraph diffGraph = Difference.createDiffGraph(other, graph);
             viewer.view(diffGraph);
         }
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphOpenCookie.java	Mon Jul 18 13:30:37 2011 +0200
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.sun.hotspot.igv.coordinator.actions;
+
+import com.sun.hotspot.igv.data.InputGraph;
+import com.sun.hotspot.igv.data.services.GraphViewer;
+import org.openide.DialogDescriptor;
+import org.openide.DialogDisplayer;
+import org.openide.NotifyDescriptor;
+import org.openide.cookies.OpenCookie;
+
+public class GraphOpenCookie implements OpenCookie {
+
+    private final GraphViewer viewer;
+    private final InputGraph graph;
+
+    public GraphOpenCookie(GraphViewer viewer, InputGraph graph) {
+        this.viewer = viewer;
+        this.graph = graph;
+    }
+
+    public void open() {
+        if (!graph.getGroup().isComplete()) {
+            String msg = "This graph or the group it belongs to is still being loaded. Opening this graph now can cause problems. Do you want to continue and open the graph?";
+            NotifyDescriptor desc = new NotifyDescriptor(msg, "Incomplete data", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE, null, NotifyDescriptor.NO_OPTION);
+
+            if (DialogDisplayer.getDefault().notify(desc) == DialogDescriptor.NO_OPTION) {
+                return;
+            }
+        }
+
+        viewer.view(graph);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphRemoveCookie.java	Mon Jul 18 13:30:37 2011 +0200
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.sun.hotspot.igv.coordinator.actions;
+
+import com.sun.hotspot.igv.data.InputGraph;
+import org.openide.DialogDescriptor;
+import org.openide.DialogDisplayer;
+import org.openide.NotifyDescriptor;
+
+public class GraphRemoveCookie implements RemoveCookie {
+
+    private final InputGraph graph;
+
+    public GraphRemoveCookie(InputGraph graph) {
+        this.graph = graph;
+    }
+
+    public void remove() {
+        if (!graph.getGroup().isComplete()) {
+            String msg = "This graph or the group it belongs to is still being loaded. Removing this graph now can cause problems. Do you want to continue and remove the graph?";
+            NotifyDescriptor desc = new NotifyDescriptor(msg, "Incomplete data", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE, null, NotifyDescriptor.NO_OPTION);
+
+            if (DialogDisplayer.getDefault().notify(desc) == DialogDescriptor.NO_OPTION) {
+                return;
+            }
+        }
+
+        graph.getGroup().removeGraph(graph);
+    }
+}
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java	Mon Jul 18 11:35:16 2011 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java	Mon Jul 18 13:30:37 2011 +0200
@@ -39,6 +39,7 @@
     private InputMethod method;
     private String assembly;
     private transient ChangedEvent<Group> changedEvent;
+    private transient boolean complete = true;
 
     public Group() {
         graphs = new ArrayList<InputGraph>();
@@ -49,6 +50,14 @@
         getProperties().setProperty("type", "");
     }
 
+    public void setComplete(boolean complete) {
+        this.complete = complete;
+    }
+
+    public boolean isComplete() {
+        return complete;
+    }
+
     public void fireChangedEvent() {
         changedEvent.fire();
     }
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java	Mon Jul 18 11:35:16 2011 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java	Mon Jul 18 13:30:37 2011 +0200
@@ -121,11 +121,10 @@
         @Override
         protected Group start() throws SAXException {
             Group group = new Group();
-            Parser.this.difference = false;
+            group.setComplete(false);
+            
             String differenceProperty = this.readAttribute(DIFFERENCE_PROPERTY);
-            if (differenceProperty != null && (differenceProperty.equals("1") || differenceProperty.equals("true"))) {
-                Parser.this.difference = true;
-            }
+            Parser.this.difference = (differenceProperty != null && (differenceProperty.equals("1") || differenceProperty.equals("true")));
 
             ParseMonitor monitor = getMonitor();
             if (monitor != null) {
@@ -137,8 +136,10 @@
 
         @Override
         protected void end(String text) throws SAXException {
+            Group group = getObject();
+            group.setComplete(true);
             if (groupCallback == null) {
-                getParentObject().addGroup(getObject());
+                getParentObject().addGroup(group);
             }
         }
     };