+ return currents;
+ }
+ }, new Procedure<Map<NamedResource, Collection<NamedResource>>>() {
+
+ @Override
+ public void execute(Map<NamedResource, Collection<NamedResource>> results) {
+ result.complete(results);
+ }
+
+ @Override
+ public void exception(Throwable t) {
+ LOGGER.error("Could not compute mappings for selection {}", elements, t);
+ result.completeExceptionally(t);
+ }
+ });
+
+ UIJob uiJob = new UIJob("Change mappings..") {
+
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ SelectMappingDialog dialog = new SelectMappingDialog(getDisplay().getActiveShell(), result);
+ if (dialog.open() != Dialog.OK)
+ return Status.OK_STATUS;
+
+ Map<Resource, Collection<NamedResource>> results = dialog.getResults();
+ Job job = new DatabaseJob("Join selected vertices") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ Simantics.getSession().syncRequest(new WriteRequest() {
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+
+ for (Map.Entry<Resource, Collection<NamedResource>> entry : results.entrySet()) {
+ Resource newMapping = entry.getKey();
+ Collection<NamedResource> elements = entry.getValue();
+ for (NamedResource element : elements) {
+ graph.deny(element.getResource(), DN.HasMapping);
+ graph.claim(element.getResource(), DN.HasMapping, newMapping);
+ }
+ }
+ }
+ });
+ } catch (DatabaseException e) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e);
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setUser(true);
+ job.schedule();