From 6c3710b2f22199b463d0341d86ca48406ad63f6b Mon Sep 17 00:00:00 2001 From: Uwe Stieber Date: Thu, 19 Sep 2013 14:48:47 +0200 Subject: Target Explorer: Rename ISelectionService to IDefaultContextService --- .../ActiveConnectionStatusTrimControl.java | 121 ------------ .../controls/DefaultContextStatusTrimControl.java | 117 +++++++++++ .../ui/internal/preferences/IPreferenceKeys.java | 4 +- .../preferences/PreferencesInitializer.java | 4 +- .../internal/services/DefaultContextService.java | 214 +++++++++++++++++++++ .../tcf/ui/internal/services/SelectionService.java | 214 --------------------- .../te/tcf/ui/listeners/WorkbenchPartListener.java | 9 +- .../org/eclipse/tcf/te/tcf/ui/nls/Messages.java | 4 +- .../eclipse/tcf/te/tcf/ui/nls/Messages.properties | 4 +- 9 files changed, 342 insertions(+), 349 deletions(-) delete mode 100644 target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/controls/ActiveConnectionStatusTrimControl.java create mode 100644 target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/controls/DefaultContextStatusTrimControl.java create mode 100644 target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/services/DefaultContextService.java delete mode 100644 target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/services/SelectionService.java (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf') diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/controls/ActiveConnectionStatusTrimControl.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/controls/ActiveConnectionStatusTrimControl.java deleted file mode 100644 index 7e1ba2408..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/controls/ActiveConnectionStatusTrimControl.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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.tcf.ui.controls; - -import java.util.EventObject; -import java.util.concurrent.atomic.AtomicReference; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Text; -import org.eclipse.tcf.te.runtime.events.ChangeEvent; -import org.eclipse.tcf.te.runtime.events.EventManager; -import org.eclipse.tcf.te.runtime.interfaces.events.IEventListener; -import org.eclipse.tcf.te.runtime.services.ServiceManager; -import org.eclipse.tcf.te.runtime.services.interfaces.IUIService; -import org.eclipse.tcf.te.runtime.services.interfaces.delegates.ILabelProviderDelegate; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.ISelectionService; -import org.eclipse.tcf.te.tcf.ui.nls.Messages; -import org.eclipse.tcf.te.ui.swt.SWTControlUtil; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.menus.WorkbenchWindowControlContribution; - -/** - * Default selection status bar trim control implementation. - */ -public class ActiveConnectionStatusTrimControl extends WorkbenchWindowControlContribution implements IEventListener { - Text text = null; - - /* (non-Javadoc) - * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite) - */ - @Override - protected Control createControl(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.marginHeight = 0; layout.marginWidth = 0; - panel.setLayout(layout); - - text = new Text(panel, SWT.SINGLE | SWT.READ_ONLY); - GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, true); - gd.minimumWidth = 120; - text.setLayoutData(gd); - text.setForeground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); - text.setToolTipText(Messages.ActiveConnectionStatusTrimControl_tooltip); - - ISelectionService service = ServiceManager.getInstance().getService(ISelectionService.class); - if (service != null) { - IPeerModel peerModel = service.getDefaultSelection(null); - final AtomicReference selected = new AtomicReference(); - - if (peerModel != null) { - IUIService uiService = ServiceManager.getInstance().getService(peerModel, IUIService.class); - ILabelProviderDelegate delegate = uiService != null ? uiService.getDelegate(peerModel, ILabelProviderDelegate.class) : null; - if (delegate == null) { - ILabelProvider provider = (ILabelProvider)Platform.getAdapterManager().getAdapter(peerModel, ILabelProvider.class); - if (provider instanceof ILabelProviderDelegate) { - delegate = (ILabelProviderDelegate)provider; - } - } - String label = delegate != null ? delegate.getText(peerModel) : peerModel.getName(); - selected.set(NLS.bind(Messages.ActiveConnectionStatusTrimControl_label, label)); - } - - SWTControlUtil.setText(text, selected.get()); - } - - // Register as listener to the selection service - EventManager.getInstance().addEventListener(this, ChangeEvent.class, ISelectionService.class); - - return panel; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.action.ContributionItem#dispose() - */ - @Override - public void dispose() { - // Remove ourself as listener - EventManager.getInstance().removeEventListener(this); - - super.dispose(); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.runtime.interfaces.events.IEventListener#eventFired(java.util.EventObject) - */ - @Override - public void eventFired(EventObject event) { - if (event.getSource() instanceof ISelectionService) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - getParent().update(true); - } - }); - } - } - - /* (non-Javadoc) - * @see org.eclipse.jface.action.ContributionItem#isDynamic() - */ - @Override - public boolean isDynamic() { - return true; - } -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/controls/DefaultContextStatusTrimControl.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/controls/DefaultContextStatusTrimControl.java new file mode 100644 index 000000000..f777257d0 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/controls/DefaultContextStatusTrimControl.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2013 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.tcf.ui.controls; + +import java.util.EventObject; +import java.util.concurrent.atomic.AtomicReference; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Text; +import org.eclipse.tcf.te.runtime.events.ChangeEvent; +import org.eclipse.tcf.te.runtime.events.EventManager; +import org.eclipse.tcf.te.runtime.interfaces.events.IEventListener; +import org.eclipse.tcf.te.runtime.services.ServiceManager; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.IDefaultContextService; +import org.eclipse.tcf.te.tcf.ui.nls.Messages; +import org.eclipse.tcf.te.ui.swt.SWTControlUtil; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.menus.WorkbenchWindowControlContribution; + +/** + * Default context status bar trim control implementation. + */ +public class DefaultContextStatusTrimControl extends WorkbenchWindowControlContribution implements IEventListener { + /* default */ Text text = null; + + /* (non-Javadoc) + * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createControl(Composite parent) { + Composite panel = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; layout.marginWidth = 0; + panel.setLayout(layout); + + text = new Text(panel, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); + text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + text.setForeground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); + text.setToolTipText(Messages.DefaultContextStatusTrimControl_tooltip); + + String selected = ""; //$NON-NLS-1$ + + IDefaultContextService service = ServiceManager.getInstance().getService(IDefaultContextService.class); + if (service != null) { + IPeerModel peerModel = service.getDefaultContext(null); + if (peerModel != null) { + selected = NLS.bind(Messages.DefaultContextStatusTrimControl_label, peerModel.getName()); + } + } + + text.setText(selected); + + // Register as listener to the selection service + EventManager.getInstance().addEventListener(this, ChangeEvent.class, IDefaultContextService.class); + + return panel; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.action.ContributionItem#dispose() + */ + @Override + public void dispose() { + // Remove ourself as listener + EventManager.getInstance().removeEventListener(this); + + super.dispose(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.interfaces.events.IEventListener#eventFired(java.util.EventObject) + */ + @Override + public void eventFired(EventObject event) { + if (event.getSource() instanceof IDefaultContextService) { + final AtomicReference selected = new AtomicReference(""); //$NON-NLS-1$ + + IDefaultContextService service = (IDefaultContextService)event.getSource(); + IPeerModel peerModel = service.getDefaultContext(null); + if (peerModel != null) { + selected.set(NLS.bind(Messages.DefaultContextStatusTrimControl_label, peerModel.getName())); + } + + Runnable runnable = new Runnable() { + + @Override + public void run() { + SWTControlUtil.setText(text, selected.get()); + getParent().update(true); + } + }; + + PlatformUI.getWorkbench().getDisplay().asyncExec(runnable); + } + } + + /* (non-Javadoc) + * @see org.eclipse.jface.action.ContributionItem#isDynamic() + */ + @Override + public boolean isDynamic() { + return true; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/preferences/IPreferenceKeys.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/preferences/IPreferenceKeys.java index 6bb9094f5..e6713f0f0 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/preferences/IPreferenceKeys.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/preferences/IPreferenceKeys.java @@ -34,7 +34,7 @@ public interface IPreferenceKeys { public static final String PREF_ACTIVATE_CURRENT_USER_FILTER = PREFIX + "model.currentUserFilter.activate"; //$NON-NLS-1$ /** - * Preference key to access the flag to enable the active connection status bar trim area. + * Preference key to access the flag to enable the default context status bar trim area. */ - public static final String PREF_ACTIVE_CONNECTION_TRIM_AREA_ENABLE = PREFIX + "feature.statusbar.trim.activeconnection.enable"; //$NON-NLS-1$ + public static final String PREF_DEFAULT_CONTEXT_TRIM_AREA_ENABLE = PREFIX + "feature.statusbar.trim.defaultcontext.enable"; //$NON-NLS-1$ } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/preferences/PreferencesInitializer.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/preferences/PreferencesInitializer.java index df410dc86..53fe6036f 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/preferences/PreferencesInitializer.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/preferences/PreferencesInitializer.java @@ -37,7 +37,7 @@ public class PreferencesInitializer extends AbstractPreferenceInitializer { store.setDefault(IPreferenceKeys.PREF_HIDE_VALUEADDS, true); // [Hidden] Activate current user filter: default off store.setDefault(IPreferenceKeys.PREF_ACTIVATE_CURRENT_USER_FILTER, false); - // [Hidden] Enable active connection status bar trim area: default off - store.setDefault(IPreferenceKeys.PREF_ACTIVE_CONNECTION_TRIM_AREA_ENABLE, false); + // [Hidden] Enable default context status bar trim area: default off + store.setDefault(IPreferenceKeys.PREF_DEFAULT_CONTEXT_TRIM_AREA_ENABLE, false); } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/services/DefaultContextService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/services/DefaultContextService.java new file mode 100644 index 000000000..545268c8f --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/services/DefaultContextService.java @@ -0,0 +1,214 @@ +/******************************************************************************* + * Copyright (c) 2013 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.tcf.ui.internal.services; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.runtime.events.ChangeEvent; +import org.eclipse.tcf.te.runtime.events.EventManager; +import org.eclipse.tcf.te.runtime.persistence.history.HistoryManager; +import org.eclipse.tcf.te.runtime.services.AbstractService; +import org.eclipse.tcf.te.tcf.core.interfaces.IPeerType; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProperties; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.IDefaultContextService; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService; +import org.eclipse.tcf.te.tcf.locator.model.Model; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.navigator.CommonNavigator; + +/** + * Default context service implementation. + */ +public class DefaultContextService extends AbstractService implements IDefaultContextService { + + /** + * Part id: System Management view + */ + private static final String PART_ID_TE_VIEW = "org.eclipse.tcf.te.ui.views.View"; //$NON-NLS-1$ + + /** + * Constructor. + */ + public DefaultContextService() { + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IDefaultContextService#getCandidates(java.lang.Object, org.eclipse.tcf.te.tcf.locator.interfaces.services.IDefaultContextService.IContextFilter) + */ + @Override + public IPeerModel[] getCandidates(Object currentSelection, IContextFilter filter) { + List candidates = new ArrayList(); + + // add given selection first + if (currentSelection instanceof IStructuredSelection) { + addCandidates((IStructuredSelection)currentSelection, filter, candidates); + } + + // add default selection + addCandidates(getDefaultSelections(filter), filter, candidates); + + // add active editor + addCandidates(getEditorSelection(), filter, candidates); + + // add system management selection + addCandidates(getPartSelection(PART_ID_TE_VIEW), filter, candidates); + + return candidates.toArray(new IPeerModel[candidates.size()]); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IDefaultContextService#setDefaultContext(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel) + */ + @Override + public void setDefaultContext(final IPeerModel peerModel) { + if (peerModel != null) { + HistoryManager.getInstance().add(getClass().getName(), peerModel.getPeerId()); + EventManager.getInstance().fireEvent(new ChangeEvent(this, ChangeEvent.ID_ADDED, peerModel, peerModel)); + + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window != null && window.getActivePage() != null) { + IViewPart view = window.getActivePage().findView(PART_ID_TE_VIEW); + if (view instanceof CommonNavigator) { + ((CommonNavigator)view).getCommonViewer().refresh(); + } + } + + final AtomicReference type = new AtomicReference(); + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + type.set(peerModel.getPeer().getAttributes().get((IPeerModelProperties.PROP_TYPE))); + } + }); + HistoryManager.getInstance().add(type.get() != null ? type.get() : IPeerType.TYPE_GENERIC, peerModel.getPeerId()); + } + else { + HistoryManager.getInstance().clear(getClass().getName()); + EventManager.getInstance().fireEvent(new ChangeEvent(this, ChangeEvent.ID_REMOVED, null, null)); + } + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IDefaultContextService#getDefaultContext(org.eclipse.tcf.te.tcf.locator.interfaces.services.IDefaultContextService.IContextFilter) + */ + @Override + public IPeerModel getDefaultContext(IContextFilter filter) { + for (String peerId : HistoryManager.getInstance().getHistory(getClass().getName())) { + IPeerModel peerModel = addCandidate(getPeerModel(peerId), filter, null); + if (peerModel != null) { + return peerModel; + } + } + + return null; + } + + + private IPeerModel addCandidate(IPeerModel peerModel, IContextFilter filter, List candidates) { + if (peerModel != null && (filter == null || filter.select(peerModel))) { + if (candidates != null && !candidates.contains(peerModel)) { + candidates.add(peerModel); + } + return peerModel; + } + + return null; + } + + private void addCandidates(IStructuredSelection selection, IContextFilter filter, List candidates) { + if (selection != null) { + Iterator it = selection.iterator(); + while (it.hasNext()) { + addCandidate((IPeerModel)Platform.getAdapterManager().getAdapter(it.next(), IPeerModel.class), filter, candidates); + } + } + } + + private void addCandidates(IPeerModel[] peerModels, IContextFilter filter, List candidates) { + for (IPeerModel peerModel : peerModels) { + addCandidate(peerModel, filter, candidates); + } + } + + private IPeerModel[] getDefaultSelections(IContextFilter filter) { + List candidates = new ArrayList(); + + for (String peerId : HistoryManager.getInstance().getHistory(getClass().getName())) { + addCandidate(getPeerModel(peerId), filter, candidates); + } + + return candidates.toArray(new IPeerModel[candidates.size()]); + } + + private IPeerModel getPeerModel(final String peerId) { + if (peerId != null) { + final AtomicReference peerModel = new AtomicReference(); + + Runnable runnable = new Runnable() { + @Override + public void run() { + ILocatorModel model = Model.getModel(); + Assert.isNotNull(model); + peerModel.set(model.getService(ILocatorModelLookupService.class).lkupPeerModelById(peerId)); + } + }; + + if (Protocol.isDispatchThread()) { + runnable.run(); + } + else { + Protocol.invokeAndWait(runnable); + } + + return peerModel.get(); + } + + return null; + } + + private IStructuredSelection getEditorSelection() { + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window != null && window.getActivePage() != null && window.getActivePage().getActiveEditor() != null) { + return new StructuredSelection(window.getActivePage().getActiveEditor().getEditorInput()); + } + return null; + } + + private IStructuredSelection getPartSelection(String partId) { + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window != null && window.getActivePage() != null) { + ISelection sel = null; + if (partId != null) { + sel = window.getActivePage().getSelection(partId); + } + else { + sel = window.getActivePage().getSelection(); + } + + if (sel instanceof IStructuredSelection) { + return (IStructuredSelection)sel; + } + } + return null; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/services/SelectionService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/services/SelectionService.java deleted file mode 100644 index 4e1476701..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/services/SelectionService.java +++ /dev/null @@ -1,214 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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.tcf.ui.internal.services; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.atomic.AtomicReference; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.te.runtime.events.ChangeEvent; -import org.eclipse.tcf.te.runtime.events.EventManager; -import org.eclipse.tcf.te.runtime.persistence.history.HistoryManager; -import org.eclipse.tcf.te.runtime.services.AbstractService; -import org.eclipse.tcf.te.tcf.core.interfaces.IPeerType; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProperties; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.ISelectionService; -import org.eclipse.tcf.te.tcf.locator.model.Model; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.navigator.CommonNavigator; - -/** - * Selection service implementation. - */ -public class SelectionService extends AbstractService implements ISelectionService { - - /** - * Part id: System Manager view - */ - private static final String PART_ID_TE_VIEW = "org.eclipse.tcf.te.ui.views.View"; //$NON-NLS-1$ - - /** - * Constructor. - */ - public SelectionService() { - } - - /* (non-Javadoc) - * @see com.windriver.te.tcf.core.interfaces.services.ISelectionService#getCandidates(java.lang.Object, com.windriver.te.tcf.core.interfaces.services.ISelectionService.ISelectionFilter) - */ - @Override - public IPeerModel[] getCandidates(Object currentSelection, ISelectionFilter filter) { - List candidates = new ArrayList(); - - // add given selection first - if (currentSelection instanceof IStructuredSelection) { - addCandidates((IStructuredSelection)currentSelection, filter, candidates); - } - - // add default selection - addCandidates(getDefaultSelections(filter), filter, candidates); - - // add active editor - addCandidates(getEditorSelection(), filter, candidates); - - // add system management selection - addCandidates(getPartSelection(PART_ID_TE_VIEW), filter, candidates); - - return candidates.toArray(new IPeerModel[candidates.size()]); - } - - /* (non-Javadoc) - * @see com.windriver.te.tcf.core.interfaces.services.ISelectionService#setDefaultSelection(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel) - */ - @Override - public void setDefaultSelection(final IPeerModel peerModel) { - if (peerModel != null) { - HistoryManager.getInstance().add(getClass().getName(), peerModel.getPeerId()); - EventManager.getInstance().fireEvent(new ChangeEvent(this, ChangeEvent.ID_ADDED, peerModel, peerModel)); - - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window != null && window.getActivePage() != null) { - IViewPart view = window.getActivePage().findView(PART_ID_TE_VIEW); - if (view instanceof CommonNavigator) { - ((CommonNavigator)view).getCommonViewer().refresh(); - } - } - - final AtomicReference type = new AtomicReference(); - Protocol.invokeAndWait(new Runnable() { - @Override - public void run() { - type.set(peerModel.getPeer().getAttributes().get((IPeerModelProperties.PROP_TYPE))); - } - }); - HistoryManager.getInstance().add(type.get() != null ? type.get() : IPeerType.TYPE_GENERIC, peerModel.getPeerId()); - } - else { - HistoryManager.getInstance().clear(getClass().getName()); - EventManager.getInstance().fireEvent(new ChangeEvent(this, ChangeEvent.ID_REMOVED, null, null)); - } - } - - /* (non-Javadoc) - * @see com.windriver.te.tcf.core.interfaces.services.ISelectionService#getDefaultSelection(com.windriver.te.tcf.core.interfaces.services.ISelectionService.ISelectionFilter) - */ - @Override - public IPeerModel getDefaultSelection(ISelectionFilter filter) { - for (String peerId : HistoryManager.getInstance().getHistory(getClass().getName())) { - IPeerModel peerModel = addCandidate(getPeerModel(peerId), filter, null); - if (peerModel != null) { - return peerModel; - } - } - - return null; - } - - - private IPeerModel addCandidate(IPeerModel peerModel, ISelectionFilter filter, List candidates) { - if (peerModel != null && (filter == null || filter.select(peerModel))) { - if (candidates != null && !candidates.contains(peerModel)) { - candidates.add(peerModel); - } - return peerModel; - } - - return null; - } - - private void addCandidates(IStructuredSelection selection, ISelectionFilter filter, List candidates) { - if (selection != null) { - Iterator it = selection.iterator(); - while (it.hasNext()) { - addCandidate((IPeerModel)Platform.getAdapterManager().getAdapter(it.next(), IPeerModel.class), filter, candidates); - } - } - } - - private void addCandidates(IPeerModel[] peerModels, ISelectionFilter filter, List candidates) { - for (IPeerModel peerModel : peerModels) { - addCandidate(peerModel, filter, candidates); - } - } - - private IPeerModel[] getDefaultSelections(ISelectionFilter filter) { - List candidates = new ArrayList(); - - for (String peerId : HistoryManager.getInstance().getHistory(getClass().getName())) { - addCandidate(getPeerModel(peerId), filter, candidates); - } - - return candidates.toArray(new IPeerModel[candidates.size()]); - } - - private IPeerModel getPeerModel(final String peerId) { - if (peerId != null) { - final AtomicReference peerModel = new AtomicReference(); - - Runnable runnable = new Runnable() { - @Override - public void run() { - ILocatorModel model = Model.getModel(); - Assert.isNotNull(model); - peerModel.set(model.getService(ILocatorModelLookupService.class).lkupPeerModelById(peerId)); - } - }; - - if (Protocol.isDispatchThread()) { - runnable.run(); - } - else { - Protocol.invokeAndWait(runnable); - } - - return peerModel.get(); - } - - return null; - } - - private IStructuredSelection getEditorSelection() { - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window != null && window.getActivePage() != null && window.getActivePage().getActiveEditor() != null) { - return new StructuredSelection(window.getActivePage().getActiveEditor().getEditorInput()); - } - return null; - } - - private IStructuredSelection getPartSelection(String partId) { - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window != null && window.getActivePage() != null) { - ISelection sel = null; - if (partId != null) { - sel = window.getActivePage().getSelection(partId); - } - else { - sel = window.getActivePage().getSelection(); - } - - if (sel instanceof IStructuredSelection) { - return (IStructuredSelection)sel; - } - } - return null; - } -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/listeners/WorkbenchPartListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/listeners/WorkbenchPartListener.java index bdc37eb35..6348635ae 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/listeners/WorkbenchPartListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/listeners/WorkbenchPartListener.java @@ -12,7 +12,7 @@ package org.eclipse.tcf.te.tcf.ui.listeners; import org.eclipse.core.runtime.Platform; import org.eclipse.tcf.te.runtime.services.ServiceManager; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.ISelectionService; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.IDefaultContextService; import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorReference; @@ -71,11 +71,8 @@ public class WorkbenchPartListener implements IPartListener2 { if (part != null) { IPeerModel peerModel = (IPeerModel)Platform.getAdapterManager().getAdapter(part.getEditorInput(), IPeerModel.class); if (peerModel != null) { - ISelectionService selService = ServiceManager.getInstance().getService(ISelectionService.class); - if (selService != null) { - selService.setDefaultSelection(peerModel); - } - + IDefaultContextService service = ServiceManager.getInstance().getService(IDefaultContextService.class); + if (service != null) service.setDefaultContext(peerModel); } } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java index 7561219f7..67da4c3dc 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java @@ -240,6 +240,6 @@ public class Messages extends NLS { public static String PeerImportWizardPage_overwriteDialog_message; public static String PeerImportWizardPage_overwriteDialogToggle_message; - public static String ActiveConnectionStatusTrimControl_label; - public static String ActiveConnectionStatusTrimControl_tooltip; + public static String DefaultContextStatusTrimControl_label; + public static String DefaultContextStatusTrimControl_tooltip; } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties index 7178b5bd6..398981ce8 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties @@ -199,6 +199,6 @@ PeerImportWizardPage_overwrite_button=Overwrite existing configuration(s) withou PeerImportWizardPage_overwriteDialog_message=The configuration ''{0}'' already exists. Do you want to overwrite it? PeerImportWizardPage_overwriteDialogToggle_message=Remember my decision -ActiveConnectionStatusTrimControl_label={0} -ActiveConnectionStatusTrimControl_tooltip=Most recently used connection +DefaultContextStatusTrimControl_label={0} +DefaultContextStatusTrimControl_tooltip=Most recently used context -- cgit v1.2.3