import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
+import java.util.function.Consumer;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.simantics.db.layer0.adapter.Remover;
import org.simantics.db.layer0.exception.CannotRemoveException;
import org.simantics.db.layer0.util.RemoverUtil;
-import org.simantics.diagram.adapter.ElementFactoryUtil;
import org.simantics.diagram.content.ConnectionUtil;
import org.simantics.diagram.content.EdgeResource;
import org.simantics.diagram.internal.Activator;
-import org.simantics.diagram.synchronization.ISynchronizationContext;
import org.simantics.diagram.synchronization.graph.RemoveBranchpoint;
import org.simantics.diagram.synchronization.graph.RemoveElement;
import org.simantics.diagram.ui.DiagramModelHints;
if (ss.isEmpty())
return true;
- if (delete(d, ss)) {
+ if (delete(d, ss,
+ ex -> {
+ if (ex instanceof CannotRemoveException) {
+ ShowMessage.showInformation("Delete Selection Was Denied", ex.getLocalizedMessage());
+ }
+ },
+ error -> {
+ error(error);
+ }
+ )) {
sel.clear(0);
}
return false;
}
- public boolean delete(final IDiagram d, Collection<IElement> ss) {
- TimeLogger.resetTimeAndLog(getClass(), "delete");
+ public static boolean delete(final IDiagram d, Collection<IElement> ss, Consumer<Exception> exceptionListener, Consumer<String> errorListener) {
+ TimeLogger.resetTimeAndLog(DeleteHandler.class, "delete");
Topology topology = d.getDiagramClass().getAtMostOneItemOfClass(Topology.class);
RelationshipHandler erh = d.getDiagramClass().getAtMostOneItemOfClass(RelationshipHandler.class);
// Try to work with cases where the model is somewhat corrupt.
if (begin != null && end != null) {
if (PickFilter.FILTER_BRANCH_POINT.accept(begin.node) && PickFilter.FILTER_BRANCH_POINT.accept(end.node)) {
- error("Deletion of branch point connecting edges is not allowed. Must be connected to a node terminal.");
+ if (errorListener != null) {
+ errorListener.accept("Deletion of branch point connecting edges is not allowed. Must be connected to a node terminal.");
+ }
return false;
}
}
System.out.println("\t\t" + e);
}
- final IDiagram diagram = this.diagram;
- final ISynchronizationContext syncContext = ElementFactoryUtil.getContextChecked(diagram);
-
new DatabaseJob("Delete selection") {
@Override
protected IStatus run(IProgressMonitor monitor) {
delete(monitor);
return Status.OK_STATUS;
} catch (CannotRemoveException e) {
- ShowMessage.showInformation("Delete Selection Was Denied", e.getLocalizedMessage());
+ if (exceptionListener != null) exceptionListener.accept(e);
return new Status(IStatus.CANCEL, Activator.PLUGIN_ID, e.getLocalizedMessage(), e);
} catch (DatabaseException e) {
+ if (exceptionListener != null) exceptionListener.accept(e);
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unexpected error in delete.", e);
} finally {
- error(null);
+ if (errorListener != null) {
+ errorListener.accept(null);
+ }
monitor.done();
}
}