X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Factions%2FAssignSymbolGroupsHandler.java;h=59e9d8c0701ab4ebad0a5209bb784ad2dcb01a8f;hb=refs%2Fchanges%2F77%2F1977%2F1;hp=0a4a5765c079a8684843a99c5cb89ba15caeba63;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/AssignSymbolGroupsHandler.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/AssignSymbolGroupsHandler.java index 0a4a5765c..59e9d8c07 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/AssignSymbolGroupsHandler.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/AssignSymbolGroupsHandler.java @@ -1,38 +1,45 @@ -package org.simantics.modeling.ui.actions; - -import java.util.Collection; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.handlers.HandlerUtil; -import org.simantics.db.Resource; -import org.simantics.db.layer0.SelectionHints; -import org.simantics.db.layer0.adapter.ActionFactory; -import org.simantics.utils.ui.ISelectionUtils; - -/** - * This class exists as a org.eclipse.ui.handler extension point counterpart for - * AssignSymbolGroup ActionFactory due to lack of multi-selection support in the - * modeled {@link ActionFactory} contributions. - * - * @author Tuukka Lehtonen - */ -public class AssignSymbolGroupsHandler extends AbstractHandler { - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - ISelection s = HandlerUtil.getCurrentSelection(event); - if (!(s instanceof IStructuredSelection)) - return null; - - Collection res = ISelectionUtils.getPossibleKeys(s, SelectionHints.KEY_MAIN, Resource.class); - if (!res.isEmpty()) - new AssignSymbolGroup().assignGroups(res); - - return null; - } - -} +package org.simantics.modeling.ui.actions; + +import java.util.Collection; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.db.Resource; +import org.simantics.db.layer0.SelectionHints; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.utils.ui.ISelectionUtils; + +/** + * This class exists as a org.eclipse.ui.handler extension point counterpart for + * AssignSymbolGroup ActionFactory due to lack of multi-selection support in the + * modeled {@link ActionFactory} contributions. + * + * @author Tuukka Lehtonen + */ +public class AssignSymbolGroupsHandler extends AbstractHandler { + + public static Object handleStatic(Collection res) throws ExecutionException { + return executeImpl(res); + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection s = HandlerUtil.getCurrentSelection(event); + if (!(s instanceof IStructuredSelection)) + return null; + + Collection res = ISelectionUtils.getPossibleKeys(s, SelectionHints.KEY_MAIN, Resource.class); + return executeImpl(res); + } + + private static Object executeImpl(Collection res) throws ExecutionException { + if (!res.isEmpty()) + new AssignSymbolGroup().assignGroups(res); + return null; + } + +}