Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2011-11-09 04:41:21 -0500
committerUwe Stieber2011-11-09 04:43:55 -0500
commit7c07cd8f9ae8bf7ff6b5a5601667f8c5eb41bbea (patch)
treee4399e278e51e0f8c0df503c54bdc7b03c324f78
parentfb72ace086be4ea719a6fa541ef7818796b498f3 (diff)
downloadorg.eclipse.tcf-7c07cd8f9ae8bf7ff6b5a5601667f8c5eb41bbea.tar.gz
org.eclipse.tcf-7c07cd8f9ae8bf7ff6b5a5601667f8c5eb41bbea.tar.xz
org.eclipse.tcf-7c07cd8f9ae8bf7ff6b5a5601667f8c5eb41bbea.zip
Target Explorer: Added helper to open the properties on a given selection
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/ViewsUtil.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/ViewsUtil.java b/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/ViewsUtil.java
index 5e4f93fca..4da52265b 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/ViewsUtil.java
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/ViewsUtil.java
@@ -9,13 +9,20 @@
*******************************************************************************/
package org.eclipse.tm.te.ui.views;
+import java.util.Collections;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.expressions.EvaluationContext;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ui.ISources;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.navigator.CommonNavigator;
/**
@@ -106,4 +113,43 @@ public class ViewsUtil {
PlatformUI.getWorkbench().getDisplay().asyncExec(runnable);
}
}
+
+ /**
+ * Opens the properties editor or dialog on the given selection.
+ *
+ * @param selection The selection. Must be not <code>null</code>.
+ */
+ public static void openProperties(final ISelection selection) {
+ Assert.isNotNull(selection);
+
+ // Create the runnable
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ ICommandService service = (ICommandService)PlatformUI.getWorkbench().getAdapter(ICommandService.class);
+ if (service != null) {
+ final Command command = service.getCommand("org.eclipse.ui.file.properties"); //$NON-NLS-1$
+ if (command != null && command.isDefined()) {
+ // Construct the application context
+ EvaluationContext context = new EvaluationContext(null, selection);
+ // Apply the selection to the "activeMenuSelection" and "selection" variable too
+ context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
+ context.addVariable(ISources.ACTIVE_MENU_SELECTION_NAME, selection);
+ context.addVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
+ // Construct the execution event
+ ExecutionEvent execEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, context);
+ // And execute the event
+ try {
+ command.executeWithChecks(execEvent);
+ } catch (Exception e) { /* ignored on purpose */ }
+ }
+ }
+ }
+ };
+
+ // Execute asynchronously
+ if (PlatformUI.isWorkbenchRunning()) {
+ PlatformUI.getWorkbench().getDisplay().asyncExec(runnable);
+ }
+ }
}

Back to the top