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