From 19d630e8a8d2265c5b6784b85ea1009c662559e8 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Sat, 28 Oct 2017 02:29:37 +0300 Subject: [PATCH] Minor cleanup for performing default actions refs #7575 Change-Id: I3bac53c06c89d5f1794876c365a0ea15e621dab2 --- .../ui/scl/expressions/SCLExpressionView.java | 13 ++-------- .../ui/workbench/action/DefaultActions.java | 12 +++++++++ .../action/PerformDefaultAction.java | 26 ++++++++++++++----- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/expressions/SCLExpressionView.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/expressions/SCLExpressionView.java index d9bf77e47..eeea9d586 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/expressions/SCLExpressionView.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/expressions/SCLExpressionView.java @@ -17,7 +17,6 @@ import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; import org.eclipse.jface.viewers.ColumnWeightData; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; @@ -40,8 +39,7 @@ import org.simantics.Simantics; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.modeling.ui.Activator; -import org.simantics.ui.workbench.action.ChooseActionRequest; -import org.simantics.utils.ui.workbench.WorkbenchUtils; +import org.simantics.ui.workbench.action.DefaultActions; public class SCLExpressionView extends ViewPart { @@ -169,14 +167,7 @@ public class SCLExpressionView extends ViewPart { } private static void openResource(Shell shell, Resource resource) { - try { - ISelection input = new StructuredSelection(resource); - String perspectiveId = WorkbenchUtils.getCurrentPerspectiveId(); - // Try the doubleClick-extensions - Simantics.getSession().asyncRequest(new ChooseActionRequest(shell, input, perspectiveId, false, true)); - } catch (NumberFormatException e) { - return; - } + DefaultActions.performDefaultAction(shell, new StructuredSelection(resource)); } @Override diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/DefaultActions.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/DefaultActions.java index 9f5bba95d..12995f177 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/DefaultActions.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/DefaultActions.java @@ -1,5 +1,6 @@ package org.simantics.ui.workbench.action; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; @@ -62,4 +63,15 @@ public final class DefaultActions { session.asyncRequest(new ChooseActionRequest(shell, null, input, WorkbenchUtils.getCurrentPerspectiveId(), rememberAction, alwaysAsk, neverPromptForAction)); } + /** + * Perform a default workbench action on the specified input object using + * {@link ChooseActionRequest} from the current thread. The current thread + * must be the SWT UI thread. + * + * @param control the control contained + */ + public static void performDefaultAction(Control control, Object input) { + new PerformDefaultAction("Perform Default Action", control, input).run(); + } + } diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/PerformDefaultAction.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/PerformDefaultAction.java index 22164e504..30af51d92 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/PerformDefaultAction.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/PerformDefaultAction.java @@ -1,6 +1,6 @@ /******************************************************************************* - * Copyright (c) 2012 Association for Decentralized Information Management in - * Industry THTH ry. + * Copyright (c) 2012, 2017 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 @@ -11,14 +11,17 @@ *******************************************************************************/ package org.simantics.ui.workbench.action; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.Action; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; -import org.simantics.db.Resource; +import org.simantics.db.common.procedure.adapter.ProcedureAdapter; import org.simantics.ui.SimanticsUI; +import org.simantics.ui.internal.Activator; import org.simantics.utils.ui.workbench.WorkbenchUtils; /** @@ -27,12 +30,12 @@ import org.simantics.utils.ui.workbench.WorkbenchUtils; public class PerformDefaultAction extends Action { private Control control; - private Resource component; + private Object input; - public PerformDefaultAction(String name, Control control, Resource component) { + public PerformDefaultAction(String name, Control control, Object input) { super(name); this.control = control; - this.component = component; + this.input = input; } @Override @@ -47,7 +50,16 @@ public class PerformDefaultAction extends Action { if (window != null) shell = window.getShell(); } - SimanticsUI.getSession().asyncRequest(new ChooseActionRequest(shell, control, component, perspectiveId)); + SimanticsUI.getSession().asyncRequest( + new ChooseActionRequest(shell, control, input, perspectiveId), + new ProcedureAdapter() { + @Override + public void exception(Throwable t) { + Activator.getDefault().getLog().log( + new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "Failed to choose action for input " + input + ", see exception for details.", t)); + } + }); } } \ No newline at end of file -- 2.43.2