Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2012-10-19 12:52:11 +0000
committerUwe Stieber2012-10-19 12:52:11 +0000
commit1c30112b32f7b9fc055b5d950f5c47890d0b2a76 (patch)
treec6726c0596a1107a94ea1e8ac1b2b09311fb117f /target_explorer
parenta232abf9f70c0262a62b1a217f686c01e7fcd174 (diff)
downloadorg.eclipse.tcf-1c30112b32f7b9fc055b5d950f5c47890d0b2a76.tar.gz
org.eclipse.tcf-1c30112b32f7b9fc055b5d950f5c47890d0b2a76.tar.xz
org.eclipse.tcf-1c30112b32f7b9fc055b5d950f5c47890d0b2a76.zip
Target Explorer: Added custom selection service source provider
Diffstat (limited to 'target_explorer')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/expressions/SelectionSourceProvider.java185
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/listeners/WorkbenchWindowListener.java19
2 files changed, 204 insertions, 0 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/expressions/SelectionSourceProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/expressions/SelectionSourceProvider.java
new file mode 100644
index 000000000..527a1c090
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/expressions/SelectionSourceProvider.java
@@ -0,0 +1,185 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems, Inc. and others. 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.views.expressions;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants;
+import org.eclipse.ui.AbstractSourceProvider;
+import org.eclipse.ui.INullSelectionListener;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.IWindowListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.services.IServiceLocator;
+
+/**
+ * Selection service source provider implementation.
+ */
+public class SelectionSourceProvider extends AbstractSourceProvider implements INullSelectionListener, IWindowListener {
+
+ /**
+ * Source name identifying the System Manager view selection.
+ */
+ public static final String systemManagerViewSelectionName = "systemManagerViewSelection"; //$NON-NLS-1$
+
+ /**
+ * Source name identifying the Debug View view selection.
+ */
+ public static final String debugViewSelectionName = "debugViewSelection"; //$NON-NLS-1$
+
+ // The internal list of provided source names
+ private final static String[] PROVIDED_SOURCE_NAMES = { systemManagerViewSelectionName, debugViewSelectionName };
+
+ /**
+ * Debug view identifier (value <code>"org.eclipse.debug.ui.DebugView"</code>).
+ * @see IDebugUIConstants
+ */
+ private static final String ID_DEBUG_VIEW = "org.eclipse.debug.ui.DebugView"; //$NON-NLS-1$
+
+ // The map containing the cached selections
+ private final Map<String, ISelection> cache = new HashMap<String, ISelection>();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.AbstractSourceProvider#initialize(org.eclipse.ui.services.IServiceLocator)
+ */
+ @Override
+ public void initialize(IServiceLocator locator) {
+ super.initialize(locator);
+
+ // Register the source provider with the selection service
+ if (PlatformUI.getWorkbench() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
+ windowOpened(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.ISourceProvider#dispose()
+ */
+ @Override
+ public void dispose() {
+ // Unregister the source provider from the selection service
+ if (PlatformUI.getWorkbench() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
+ windowClosed(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.ISourceProvider#getProvidedSourceNames()
+ */
+ @Override
+ public String[] getProvidedSourceNames() {
+ return PROVIDED_SOURCE_NAMES;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.ISourceProvider#getCurrentState()
+ */
+ @Override
+ public Map getCurrentState() {
+ Map<String, Object> state = new HashMap<String, Object>();
+
+ ISelection selection = cache.get(IUIConstants.ID_EXPLORER);
+ state.put(systemManagerViewSelectionName, selection != null ? selection : IEvaluationContext.UNDEFINED_VARIABLE);
+
+ selection = cache.get(ID_DEBUG_VIEW);
+ state.put(debugViewSelectionName, selection != null ? selection : IEvaluationContext.UNDEFINED_VARIABLE);
+
+ return state;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
+ */
+ @Override
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ String partId = part != null ? part.getSite().getId() : null;
+ if (!IUIConstants.ID_EXPLORER.equals(partId) || ID_DEBUG_VIEW.equals(partId)) {
+ return;
+ }
+
+ // Update the cached selection
+ if (selection != null) cache.put(partId, selection);
+ else cache.remove(partId);
+
+ // Fire the source changed notification
+ fireSourceChanged(ISources.ACTIVE_CURRENT_SELECTION, IUIConstants.ID_EXPLORER.equals(partId) ? systemManagerViewSelectionName : debugViewSelectionName,
+ selection != null ? selection : IEvaluationContext.UNDEFINED_VARIABLE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow)
+ */
+ @Override
+ public void windowActivated(IWorkbenchWindow window) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.IWorkbenchWindow)
+ */
+ @Override
+ public void windowDeactivated(IWorkbenchWindow window) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow)
+ */
+ @Override
+ public void windowClosed(IWorkbenchWindow window) {
+ // Remove ourself as selection listener
+ if (window != null && window.getSelectionService() != null) {
+ ISelectionService service = window.getSelectionService();
+ service.removePostSelectionListener(IUIConstants.ID_EXPLORER, this);
+ service.removePostSelectionListener(ID_DEBUG_VIEW, this);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow)
+ */
+ @Override
+ public void windowOpened(IWorkbenchWindow window) {
+ // A new workbench window opened. We have to register
+ // ourself as selection listener if not done
+ if (window != null && window.getSelectionService() != null) {
+ // Get the selection service
+ ISelectionService service = window.getSelectionService();
+
+ // Unregister the source provider first, just in case to
+ // avoid the listener to be registered multiple time
+ service.removePostSelectionListener(IUIConstants.ID_EXPLORER, this);
+ service.removePostSelectionListener(ID_DEBUG_VIEW, this);
+
+ // Register the source provider now as post selection listener
+ service.addPostSelectionListener(IUIConstants.ID_EXPLORER, this);
+ service.addPostSelectionListener(ID_DEBUG_VIEW, this);
+
+ // Initialize the selections
+ ISelection selection = service.getSelection(IUIConstants.ID_EXPLORER);
+ if (selection != null) cache.put(IUIConstants.ID_EXPLORER, selection);
+ else cache.remove(IUIConstants.ID_EXPLORER);
+
+ fireSourceChanged(ISources.ACTIVE_CURRENT_SELECTION, systemManagerViewSelectionName,
+ selection != null ? selection : IEvaluationContext.UNDEFINED_VARIABLE);
+
+ selection = service.getSelection(ID_DEBUG_VIEW);
+ if (selection != null) cache.put(ID_DEBUG_VIEW, selection);
+ else cache.remove(ID_DEBUG_VIEW);
+
+ fireSourceChanged(ISources.ACTIVE_CURRENT_SELECTION, debugViewSelectionName,
+ selection != null ? selection : IEvaluationContext.UNDEFINED_VARIABLE);
+ }
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/listeners/WorkbenchWindowListener.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/listeners/WorkbenchWindowListener.java
index 6807b89aa..60c8314e7 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/listeners/WorkbenchWindowListener.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/listeners/WorkbenchWindowListener.java
@@ -9,11 +9,14 @@
*******************************************************************************/
package org.eclipse.tcf.te.ui.views.listeners;
+import org.eclipse.tcf.te.ui.views.expressions.SelectionSourceProvider;
import org.eclipse.ui.IPartService;
import org.eclipse.ui.IWindowListener;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.services.IEvaluationService;
/**
* The window listener implementation. Takes care of the
@@ -24,13 +27,24 @@ public class WorkbenchWindowListener implements IWindowListener {
private final WorkbenchPartListener partListener = new WorkbenchPartListener();
// The global perspective listener instance
private final WorkbenchPerspectiveListener perspectiveListener = new WorkbenchPerspectiveListener();
+ // The global selection service source provider
+ private final SelectionSourceProvider sourceProvider = new SelectionSourceProvider();
+ /**
+ * Constructor
+ */
+ public WorkbenchWindowListener() {
+ // Register the source provider with the evaluation service
+ IEvaluationService service = (IEvaluationService)PlatformUI.getWorkbench().getService(IEvaluationService.class);
+ if (service != null) service.addSourceProvider(sourceProvider);
+ }
/* (non-Javadoc)
* @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow)
*/
@Override
public void windowActivated(IWorkbenchWindow window) {
+ sourceProvider.windowActivated(window);
}
/* (non-Javadoc)
@@ -38,6 +52,7 @@ public class WorkbenchWindowListener implements IWindowListener {
*/
@Override
public void windowDeactivated(IWorkbenchWindow window) {
+ sourceProvider.windowDeactivated(window);
}
/* (non-Javadoc)
@@ -45,6 +60,8 @@ public class WorkbenchWindowListener implements IWindowListener {
*/
@Override
public void windowClosed(IWorkbenchWindow window) {
+ sourceProvider.windowClosed(window);
+
// On close, remove all global listeners from the window
if (window != null) {
if (window.getPartService() != null) {
@@ -59,6 +76,8 @@ public class WorkbenchWindowListener implements IWindowListener {
*/
@Override
public void windowOpened(IWorkbenchWindow window) {
+ sourceProvider.windowOpened(window);
+
// On open, register all global listener to the window
if (window != null) {
if (window.getPartService() != null) {

Back to the top