/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * Copyright (c) 2007, 2016 Association for Decentralized Information Management\r
* in Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* VTT Technical Research Centre of Finland - initial API and implementation\r
+ * Semantum Oy - refactoring (#6855)\r
*******************************************************************************/\r
package org.simantics.debug.ui.internal;\r
\r
+import java.util.function.BiConsumer;\r
+\r
import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.eclipse.core.commands.ExecutionException;\r
import org.eclipse.jface.action.IAction;\r
-import org.eclipse.swt.widgets.Display;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.ui.handlers.HandlerUtil;\r
import org.simantics.Simantics;\r
import org.simantics.debug.ui.SearchResourceDialog;\r
import org.simantics.ui.workbench.action.ChooseActionRequest;\r
import org.simantics.utils.Container;\r
+import org.simantics.utils.ui.SWTUtils;\r
import org.simantics.utils.ui.action.IPriorityAction;\r
import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
\r
Shell shell = HandlerUtil.getActiveShellChecked(event);\r
Session session = Simantics.getSession();\r
SearchResourceDialog rld = new SearchResourceDialog(session, false, shell, "Open Resource");\r
- rld.setResourceFilter(ResourceSearch.FILTER_RELATIONS);\r
+ rld.setResourceFilter(ResourceSearch.FILTER_ALL);\r
rld.setBlockOnOpen(true);\r
rld.open();\r
if (rld.getResult() == null)\r
for (Object o : rld.getResult()) {\r
@SuppressWarnings("unchecked")\r
Container<Resource> rc = (Container<Resource>) o;\r
- openPreferredEditor(session, rc.get(), currentPerspectiveId);\r
+ openPreferredEditor(shell, session, rc.get(), currentPerspectiveId);\r
}\r
\r
return null;\r
}\r
\r
- void openPreferredEditor(Session s, final Resource r, final String defaultPerspective) {\r
+ private static void openPreferredEditor(Shell parent, Session s, Resource r, String defaultPerspective) {\r
+ findActions(s, r, defaultPerspective, (resourceName, actions) -> {\r
+ SWTUtils.asyncExec(parent, () -> {\r
+ IAction action = ChooseActionRequest.chooseAction(parent, actions, resourceName);\r
+ if (action != null)\r
+ action.run();\r
+ });\r
+ });\r
+ }\r
\r
+ private static void findActions(Session s, Resource r, String defaultPerspective, BiConsumer<String, IPriorityAction[]> consumer) {\r
s.asyncRequest(new ReadRequest() {\r
-\r
- String resourceName;\r
- IPriorityAction[] actions;\r
-\r
@Override\r
public void run(ReadGraph g) throws DatabaseException {\r
- resourceName = NameUtils.getSafeName(g, r);\r
- actions = ChooseActionRequest.findActions(g, r, defaultPerspective);\r
- if (actions == null)\r
- return;\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- IAction action = ChooseActionRequest.chooseAction(null, actions, resourceName);\r
- if (action == null)\r
- return;\r
- action.run();\r
- }\r
- });\r
+ String resourceName = NameUtils.getSafeName(g, r);\r
+ IPriorityAction[] actions = ChooseActionRequest.findActions(g, r, defaultPerspective);\r
+ if (actions != null)\r
+ consumer.accept(resourceName, actions);\r
}\r
-\r
});\r
-\r
}\r
\r
}\r