1 package org.simantics.district.network.ui.contributions;
5 import javax.inject.Named;
7 import org.eclipse.e4.core.di.annotations.CanExecute;
8 import org.eclipse.e4.core.di.annotations.Execute;
9 import org.eclipse.e4.ui.services.IServiceConstants;
10 import org.eclipse.jface.viewers.ISelection;
11 import org.simantics.Simantics;
12 import org.simantics.db.ReadGraph;
13 import org.simantics.db.Resource;
14 import org.simantics.db.exception.DatabaseException;
15 import org.simantics.db.layer0.SelectionHints;
16 import org.simantics.db.request.Read;
17 import org.simantics.district.network.ontology.DistrictNetworkResource;
18 import org.simantics.utils.ui.ISelectionUtils;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public class CopyDistrictVertexHandler {
24 private static final Logger LOGGER = LoggerFactory.getLogger(CopyDistrictVertexHandler.class);
25 static List<Resource> elements;
26 static boolean cut = true;
29 public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
30 List<Resource> elements = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
31 if (elements.size() != 1)
34 return Simantics.getSession().syncRequest(new Read<Boolean>() {
37 public Boolean perform(ReadGraph graph) throws DatabaseException {
38 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
39 for (Resource selection : elements) {
40 if (!graph.isInstanceOf(selection, DN.Element)) {
47 } catch (DatabaseException e) {
48 LOGGER.error("Could not evaluate if mapping can be changed for selection {}", elements, e);
54 public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) Object selection) {
55 final List<Resource> elements = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
56 // we store these to a static variable for pasting.. maybe not the best solution
57 CopyDistrictVertexHandler.elements = elements;
58 //CopyDistrictVertexHandler.cut = cut != null && !cut.isEmpty();