X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.debug.ui%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fui%2Finternal%2FSearchResourceHandler.java;h=bf36166452ff9de727d8fa5fdb4b11f00cb1f68f;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=3fb4013d8f7690516481e43ab0e0c358f753b966;hpb=0a314ce9afeeac53b4d4653125cf56cb99be7976;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/SearchResourceHandler.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/SearchResourceHandler.java index 3fb4013d8..bf3616645 100644 --- a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/SearchResourceHandler.java +++ b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/SearchResourceHandler.java @@ -1,84 +1,84 @@ -/******************************************************************************* - * Copyright (c) 2007, 2016 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - * Semantum Oy - refactoring (#6855) - *******************************************************************************/ -package org.simantics.debug.ui.internal; - -import java.util.function.BiConsumer; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.action.IAction; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.handlers.HandlerUtil; -import org.simantics.Simantics; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.Session; -import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.debug.ui.ResourceSearch; -import org.simantics.debug.ui.SearchResourceDialog; -import org.simantics.ui.workbench.action.ChooseActionRequest; -import org.simantics.utils.Container; -import org.simantics.utils.ui.SWTUtils; -import org.simantics.utils.ui.action.IPriorityAction; -import org.simantics.utils.ui.workbench.WorkbenchUtils; - -public class SearchResourceHandler extends AbstractHandler { - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - Shell shell = HandlerUtil.getActiveShellChecked(event); - Session session = Simantics.getSession(); - SearchResourceDialog rld = new SearchResourceDialog(session, false, shell, "Open Resource"); - rld.setResourceFilter(ResourceSearch.FILTER_ALL); - rld.setBlockOnOpen(true); - rld.open(); - if (rld.getResult() == null) - return null; - - String currentPerspectiveId = WorkbenchUtils.getCurrentPerspectiveId(); - - for (Object o : rld.getResult()) { - @SuppressWarnings("unchecked") - Container rc = (Container) o; - openPreferredEditor(shell, session, rc.get(), currentPerspectiveId); - } - - return null; - } - - private static void openPreferredEditor(Shell parent, Session s, Resource r, String defaultPerspective) { - findActions(s, r, defaultPerspective, (resourceName, actions) -> { - SWTUtils.asyncExec(parent, () -> { - IAction action = ChooseActionRequest.chooseAction(parent, actions, resourceName); - if (action != null) - action.run(); - }); - }); - } - - private static void findActions(Session s, Resource r, String defaultPerspective, BiConsumer consumer) { - s.asyncRequest(new ReadRequest() { - @Override - public void run(ReadGraph g) throws DatabaseException { - String resourceName = NameUtils.getSafeName(g, r); - IPriorityAction[] actions = ChooseActionRequest.findActions(g, r, defaultPerspective); - if (actions != null) - consumer.accept(resourceName, actions); - } - }); - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2016 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + * Semantum Oy - refactoring (#6855) + *******************************************************************************/ +package org.simantics.debug.ui.internal; + +import java.util.function.BiConsumer; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.action.IAction; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.debug.ui.ResourceSearch; +import org.simantics.debug.ui.SearchResourceDialog; +import org.simantics.ui.workbench.action.ChooseActionRequest; +import org.simantics.utils.Container; +import org.simantics.utils.ui.SWTUtils; +import org.simantics.utils.ui.action.IPriorityAction; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +public class SearchResourceHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + Shell shell = HandlerUtil.getActiveShellChecked(event); + Session session = Simantics.getSession(); + SearchResourceDialog rld = new SearchResourceDialog(session, false, shell, "Open Resource"); + rld.setResourceFilter(ResourceSearch.FILTER_ALL); + rld.setBlockOnOpen(true); + rld.open(); + if (rld.getResult() == null) + return null; + + String currentPerspectiveId = WorkbenchUtils.getCurrentPerspectiveId(); + + for (Object o : rld.getResult()) { + @SuppressWarnings("unchecked") + Container rc = (Container) o; + openPreferredEditor(shell, session, rc.get(), currentPerspectiveId); + } + + return null; + } + + private static void openPreferredEditor(Shell parent, Session s, Resource r, String defaultPerspective) { + findActions(s, r, defaultPerspective, (resourceName, actions) -> { + SWTUtils.asyncExec(parent, () -> { + IAction action = ChooseActionRequest.chooseAction(parent, actions, resourceName); + if (action != null) + action.run(); + }); + }); + } + + private static void findActions(Session s, Resource r, String defaultPerspective, BiConsumer consumer) { + s.asyncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + String resourceName = NameUtils.getSafeName(g, r); + IPriorityAction[] actions = ChooseActionRequest.findActions(g, r, defaultPerspective); + if (actions != null) + consumer.accept(resourceName, actions); + } + }); + } + +}