]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/AssignSymbolGroupsHandler.java
Allow simulation stop handling in Simantics/Sequences
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / actions / AssignSymbolGroupsHandler.java
1 package org.simantics.modeling.ui.actions;
2
3 import java.util.Collection;
4
5 import org.eclipse.core.commands.AbstractHandler;
6 import org.eclipse.core.commands.ExecutionEvent;
7 import org.eclipse.core.commands.ExecutionException;
8 import org.eclipse.jface.viewers.ISelection;
9 import org.eclipse.jface.viewers.IStructuredSelection;
10 import org.eclipse.ui.handlers.HandlerUtil;
11 import org.simantics.db.Resource;
12 import org.simantics.db.layer0.SelectionHints;
13 import org.simantics.db.layer0.adapter.ActionFactory;
14 import org.simantics.utils.ui.ISelectionUtils;
15
16 /**
17  * This class exists as a org.eclipse.ui.handler extension point counterpart for
18  * AssignSymbolGroup ActionFactory due to lack of multi-selection support in the
19  * modeled {@link ActionFactory} contributions.
20  * 
21  * @author Tuukka Lehtonen <tuukka.lehtonen@semantum.fi>
22  */
23 public class AssignSymbolGroupsHandler extends AbstractHandler {
24
25         public static Object handleStatic(Collection<Resource> res) throws ExecutionException {
26                 return executeImpl(res);
27         }
28         
29         @Override
30         public Object execute(ExecutionEvent event) throws ExecutionException {
31                 ISelection s = HandlerUtil.getCurrentSelection(event);
32                 if (!(s instanceof IStructuredSelection))
33                         return null;
34
35                 Collection<Resource> res = ISelectionUtils.getPossibleKeys(s, SelectionHints.KEY_MAIN, Resource.class);
36                 return executeImpl(res);
37         }
38         
39         private static Object executeImpl(Collection<Resource> res) throws ExecutionException {
40                 if (!res.isEmpty())
41                         new AssignSymbolGroup().assignGroups(res);
42                 return null;
43         }
44
45 }