From: jsimomaa Date: Fri, 27 Jul 2018 07:02:50 +0000 (+0300) Subject: Add progress monitoring for DeleteHandler X-Git-Tag: v1.43.0~136^2~431^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=fe216008faa34a8db02d0c53fc97e71cb70f64c0;p=simantics%2Fplatform.git Add progress monitoring for DeleteHandler Current implementation does not give any hints when deleting e.g. 10000 resources gitlab #61 Change-Id: I7cd072f0adbfe02c9ee8f0e80350bec44a6e7c20 --- diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/DeleteHandler.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/DeleteHandler.java index 7fdd56947..5fa94ebc7 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/DeleteHandler.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/DeleteHandler.java @@ -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 connectionsToRemove = new HashSet(); Set touchedConnections = new HashSet(); @@ -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); } }