]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Add progress monitoring for DeleteHandler 59/1959/1
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 27 Jul 2018 07:02:50 +0000 (10:02 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Fri, 27 Jul 2018 07:02:50 +0000 (10:02 +0300)
Current implementation does not give any hints when deleting e.g. 10000
resources

gitlab #61

Change-Id: I7cd072f0adbfe02c9ee8f0e80350bec44a6e7c20

bundles/org.simantics.diagram/src/org/simantics/diagram/handler/DeleteHandler.java

index 7fdd56947ad726f0284c165237b093968b6c2b57..5fa94ebc7a2787d1c9b3a51db9fe508ef04106dc 100644 (file)
@@ -22,6 +22,7 @@ import java.util.Set;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
 import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.swt.widgets.Display;
 import org.simantics.DatabaseJob;
@@ -286,6 +287,7 @@ public class DeleteHandler extends AbstractDiagramParticipant {
             }
 
             private void delete(IProgressMonitor monitor) throws DatabaseException {
+                SubMonitor subMonitor = SubMonitor.convert(monitor, 4);
                 Simantics.getSession().syncRequest(new WriteRequest() {
                     Set<Resource> connectionsToRemove = new HashSet<Resource>();
                     Set<Resource> touchedConnections = new HashSet<Resource>();
@@ -296,7 +298,9 @@ public class DeleteHandler extends AbstractDiagramParticipant {
                         graph.markUndoPoint();
 
                         ConnectionUtil cu = new ConnectionUtil(graph);
-
+                        SubMonitor edgeElementMonitor = subMonitor.split(2); // Consume 50 % of the monitor
+                        edgeElementMonitor.setWorkRemaining(edges.size() + elements.size()); // set work remaining to size of edges and elements
+                        edgeElementMonitor.setTaskName("Removing edges");
                         // Remove edges
                         for (IElement edge : edges) {
                             ConnectionEntity ce = edge.getHint(ElementHints.KEY_CONNECTION_ENTITY);
@@ -308,8 +312,9 @@ public class DeleteHandler extends AbstractDiagramParticipant {
                             if (obj instanceof EdgeResource) {
                                 cu.remove((EdgeResource) obj);
                             }
+                            edgeElementMonitor.worked(1);
                         }
-
+                        edgeElementMonitor.setTaskName("Removing elements");
                         // Remove elements
                         for (IElement element : elements) {
                             ConnectionHandler ch = element.getElementClass().getAtMostOneItemOfClass(ConnectionHandler.class);
@@ -343,8 +348,11 @@ public class DeleteHandler extends AbstractDiagramParticipant {
                                     }
                                 }
                             }
+                            edgeElementMonitor.worked(1);
                         }
-
+                        SubMonitor connectionsMonitor = subMonitor.split(1); // Consume 50 % of the monitor
+                        connectionsMonitor.setWorkRemaining(touchedConnections.size()); // set work remaining to size of edges and elements
+                        connectionsMonitor.setTaskName("Pruning connectors");
                         // Check all touched connections to see if they are empty.
                         for (Resource connection : touchedConnections) {
                             int removedConnectors = cu.removeUnusedConnectors(connection);
@@ -363,13 +371,17 @@ public class DeleteHandler extends AbstractDiagramParticipant {
                             if (connectors < 2) {
                                 connectionsToRemove.add(connection);
                             }
+                            connectionsMonitor.worked(1);
                         }
-
+                        SubMonitor connectionsMonitor2 = subMonitor.split(1); // Consume 50 % of the monitor
+                        connectionsMonitor2.setWorkRemaining(connectionsToRemove.size()); // set work remaini
+                        connectionsMonitor2.setTaskName("Removing leftover connections");
                         // Remove selected/left-over empty connections
                         for (Resource connection : connectionsToRemove) {
                             if (DEBUG_DELETE)
                                 System.out.println("REMOVING CONNECTION: " + connection);
                             RemoveElement.removeElement(graph, (Resource)d.getHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE), connection);
+                            connectionsMonitor2.worked(1);
                         }
                     }