X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fcontributions%2FChangeMappingTypeHandler.java;h=a2c02532c4b3f84c23065e27ca7f068a414e6534;hb=440c2b11fd49be2feb9edd39b931306b824b8aba;hp=1f94833507ad557226f249d02740347d995e6eab;hpb=a0809b57d402e300f8b5001527e99c89f974bddb;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/ChangeMappingTypeHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/ChangeMappingTypeHandler.java index 1f948335..a2c02532 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/ChangeMappingTypeHandler.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/ChangeMappingTypeHandler.java @@ -47,6 +47,7 @@ import org.simantics.db.exception.ServiceException; import org.simantics.db.exception.ValidationException; import org.simantics.db.layer0.SelectionHints; import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.Read; import org.simantics.district.network.ontology.DistrictNetworkResource; import org.simantics.district.network.ui.function.Functions; import org.simantics.district.network.ui.internal.Activator; @@ -60,36 +61,29 @@ public class ChangeMappingTypeHandler { @CanExecute public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) { -// List elements = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class); -// if (elements.size() < 1) -// return false; -// try { -// return Simantics.getSession().syncRequest(new Read() { -// -// @Override -// public Boolean perform(ReadGraph graph) throws DatabaseException { -// Layer0 L0 = Layer0.getInstance(graph); -// Resource instanceOf = null; -// for (Resource element : elements) { -// if (instanceOf == null) { -// instanceOf = graph.getSingleObject(element, L0.InstanceOf); -// } else { -// Resource currentInstanceOf = graph.getSingleObject(element, L0.InstanceOf); -// if (!currentInstanceOf.equals(instanceOf)) { -// return false; -// } -// } -// } -// return true; -// } -// }); -// } catch (DatabaseException e) { -// e.printStackTrace(); -// return false; -// } - return true; + List elements = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class); + if (elements.size() < 1) + return false; + try { + return Simantics.getSession().syncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + for (Resource selection : elements) { + if (!graph.isInstanceOf(selection, DN.Element)) { + return false; + } + } + return true; + } + }); + } catch (DatabaseException e) { + LOGGER.error("Could not evaluate if mapping can be changed for selection {}", elements, e); + return false; + } } - + @Execute public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) Object selection) { final List elements = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class); @@ -189,18 +183,12 @@ public class ChangeMappingTypeHandler { private Map> possibleMappings = new HashMap<>(); - private Resource defaultVertexMapping; - protected SelectMappingDialog(Shell parentShell, CompletableFuture>> elements) { super(parentShell); this.elements = elements; setTitle("Change mappings"); } - public Resource getDefaultVertexMapping() { - return defaultVertexMapping; - } - @Override protected Control createDialogArea(Composite parent) { composite = (Composite) super.createDialogArea(parent);