*******************************************************************************/
package org.simantics.sysdyn.ui.browser.actions.remove;
+import java.util.Collection;
+import java.util.Map;
+
+import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.PossibleIndexRoot;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.indexing.IndexUtils;
import org.simantics.db.layer0.adapter.impl.AbstractRemover;
import org.simantics.db.layer0.adapter.impl.EntityRemover;
import org.simantics.layer0.Layer0;
import org.simantics.sysdyn.SysdynResource;
/**
- *
+ *
* @author Miro Eklund
*
*/
public class ModuleSymbolRemover extends AbstractRemover {
public ModuleSymbolRemover(Resource resource) {
- super(resource);
+ super(resource);
+ }
+
+ @Override
+ public String canRemove(ReadGraph graph, Map<Object, Object> aux) throws DatabaseException {
+ Resource model = graph.syncRequest(new PossibleIndexRoot(resource));
+ if(model == null) return null;
+ Collection<Resource> symbolsInUse = IndexUtils.findByType(graph, model, resource);
+ if(symbolsInUse.isEmpty()) return null;
+ return "Module you are attemping to delete is use in the model.";
}
-
+
@Override
public void remove(WriteGraph g) throws DatabaseException {
- g.markUndoPoint();
-
- Layer0 L0 = Layer0.getInstance(g);
- SysdynResource sr = SysdynResource.getInstance(g);
-
- //We need to remove the Module object, not just the symbol.
- //Thus, if the resource is the symbol, find the parent Module first
- if(g.isInstanceOf(resource, sr.ModuleSymbol)) {
- Resource module = g.getPossibleObject(resource, L0.PartOf);
- if(module != null) {
- EntityRemover.remove(g, module, false); //Remove Module instead - was of type ModuleSymbol
- } else {
- EntityRemover.remove(g, resource, false);
- }
- } else {
- EntityRemover.remove(g, resource, false); //Remove resource - not of type ModuleSymbol
- }
+ g.markUndoPoint();
+
+ Layer0 L0 = Layer0.getInstance(g);
+ SysdynResource sr = SysdynResource.getInstance(g);
+
+ //We need to remove the Module object, not just the symbol.
+ //Thus, if the resource is the symbol, find the parent Module first
+ if(g.isInstanceOf(resource, sr.ModuleSymbolType)) {
+ Resource module = g.getPossibleObject(resource, L0.PartOf);
+ if(module != null) {
+ EntityRemover.remove(g, module, false); //Remove Module instead - was of type ModuleSymbol
+ } else {
+ EntityRemover.remove(g, resource, false);
+ }
+ } else {
+ EntityRemover.remove(g, resource, false); //Remove resource - not of type ModuleSymbol
+ }
}
@Override