Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Schwarz2013-09-18 08:25:59 -0400
committerTobias Schwarz2013-09-18 08:25:59 -0400
commit4132ecd1177c47c1e8dc8c69b0a05659425c5ea2 (patch)
treea046293d05e7a1cd66b9015c42ec742b9356109a /target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui
parent473797305d4243ba76c3921a9a214d7c34b47ff9 (diff)
downloadorg.eclipse.tcf-4132ecd1177c47c1e8dc8c69b0a05659425c5ea2.tar.gz
org.eclipse.tcf-4132ecd1177c47c1e8dc8c69b0a05659425c5ea2.tar.xz
org.eclipse.tcf-4132ecd1177c47c1e8dc8c69b0a05659425c5ea2.zip
Target Explorer: use part listener to set default connection
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/actions/AbstractPeerTypeToolbarAction.java16
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/activator/UIPlugin.java35
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/AbstractConfigurationEditorPage.java18
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/OverviewEditorPage.java9
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/listeners/WorkbenchPartListener.java99
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/listeners/WorkbenchWindowListener.java28
6 files changed, 161 insertions, 44 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/actions/AbstractPeerTypeToolbarAction.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/actions/AbstractPeerTypeToolbarAction.java
index 297d0842e..e3e7256ae 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/actions/AbstractPeerTypeToolbarAction.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/actions/AbstractPeerTypeToolbarAction.java
@@ -40,11 +40,9 @@ 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.persistence.history.HistoryManager;
-import org.eclipse.tcf.te.runtime.services.ServiceManager;
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.services.ILocatorModelLookupService;
-import org.eclipse.tcf.te.tcf.locator.interfaces.services.ISelectionService;
import org.eclipse.tcf.te.tcf.locator.model.Model;
import org.eclipse.tcf.te.tcf.ui.dialogs.AgentSelectionDialog;
import org.eclipse.tcf.te.ui.views.editor.EditorInput;
@@ -265,11 +263,6 @@ public abstract class AbstractPeerTypeToolbarAction extends Action implements IA
}
catch (PartInitException e) {
}
- HistoryManager.getInstance().add(getPeerTypeId(), peerModel.getPeerId());
- ISelectionService selService = ServiceManager.getInstance().getService(ISelectionService.class);
- if (selService != null) {
- selService.setDefaultSelection(peerModel);
- }
}
};
if (labelProvider != null) {
@@ -328,15 +321,6 @@ public abstract class AbstractPeerTypeToolbarAction extends Action implements IA
}
catch (PartInitException e) {
}
- if (((IStructuredSelection)selection).getFirstElement() instanceof IPeerModel) {
- IPeerModel peerModel = (IPeerModel)((IStructuredSelection)selection).getFirstElement();
- HistoryManager.getInstance().add(getPeerTypeId(), peerModel.getPeerId());
- ISelectionService selService = ServiceManager.getInstance().getService(ISelectionService.class);
- if (selService != null) {
- selService.setDefaultSelection(peerModel);
- }
-
- }
}
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/activator/UIPlugin.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/activator/UIPlugin.java
index 6cf60cd4f..67d20d3a6 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/activator/UIPlugin.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/activator/UIPlugin.java
@@ -17,6 +17,7 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.core.async.AsyncCallbackCollector;
import org.eclipse.tcf.te.runtime.concurrent.util.ExecutorsUtil;
@@ -34,9 +35,12 @@ import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
import org.eclipse.tcf.te.tcf.locator.interfaces.services.IStepperServiceOperations;
import org.eclipse.tcf.te.tcf.locator.model.Model;
import org.eclipse.tcf.te.tcf.ui.internal.ImageConsts;
+import org.eclipse.tcf.te.tcf.ui.listeners.WorkbenchWindowListener;
import org.eclipse.tcf.te.ui.jface.images.AbstractImageDescriptor;
+import org.eclipse.ui.IWindowListener;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchListener;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -53,6 +57,10 @@ public class UIPlugin extends AbstractUIPlugin {
// Reference to the workbench listener
/* default */ final ListenerList listeners = new ListenerList();
+
+ // The global window listener instance
+ private IWindowListener windowListener;
+
/**
* Constructor.
*/
@@ -193,15 +201,40 @@ public class UIPlugin extends AbstractUIPlugin {
}
};
PlatformUI.getWorkbench().addWorkbenchListener(listener);
+
+ if (windowListener == null && PlatformUI.getWorkbench() != null) {
+ windowListener = new WorkbenchWindowListener();
+ PlatformUI.getWorkbench().addWindowListener(windowListener);
+ activateContexts();
+ }
}
+ void activateContexts() {
+ if (Display.getCurrent() != null) {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window != null && windowListener != null) windowListener.windowOpened(window);
+ }
+ else {
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable(){
+ @Override
+ public void run() {
+ activateContexts();
+ }});
+ }
+ }
+
/* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
- plugin = null;
if (listener != null) { PlatformUI.getWorkbench().removeWorkbenchListener(listener); listener = null; }
+ if (windowListener != null && PlatformUI.getWorkbench() != null) {
+ PlatformUI.getWorkbench().removeWindowListener(windowListener);
+ windowListener = null;
+ }
+
+ plugin = null;
super.stop(context);
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/AbstractConfigurationEditorPage.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/AbstractConfigurationEditorPage.java
index f308c722c..97de115ca 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/AbstractConfigurationEditorPage.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/AbstractConfigurationEditorPage.java
@@ -16,7 +16,6 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.tcf.protocol.Protocol;
-import org.eclipse.tcf.te.runtime.persistence.history.HistoryManager;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.runtime.services.interfaces.ISimulatorService;
@@ -24,7 +23,6 @@ import org.eclipse.tcf.te.runtime.statushandler.StatusHandlerUtil;
import org.eclipse.tcf.te.runtime.utils.StatusHelper;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService;
-import org.eclipse.tcf.te.tcf.locator.interfaces.services.ISelectionService;
import org.eclipse.tcf.te.tcf.ui.help.IContextHelpIds;
import org.eclipse.tcf.te.tcf.ui.nls.Messages;
import org.eclipse.tcf.te.tcf.ui.sections.SimulatorTypeSelectionSection;
@@ -53,24 +51,8 @@ public abstract class AbstractConfigurationEditorPage extends AbstractCustomForm
return;
}
super.setInput(input);
- if (getEditorInputNode() instanceof IPeerModel) {
- // save history to reopen the editor on eclipse startup
- HistoryManager.getInstance().add(getHistoryId(), ((IPeerModel)getEditorInputNode()).getPeerId());
- ISelectionService selService = ServiceManager.getInstance().getService(ISelectionService.class);
- if (selService != null) {
- selService.setDefaultSelection((IPeerModel)getEditorInputNode());
- }
- }
}
- /**
- * Returns the history id to use to save the editor to the
- * history manager.
- *
- * @return The history id. Never <code>null</code>.
- */
- protected abstract String getHistoryId();
-
/* (non-Javadoc)
* @see org.eclipse.tcf.te.ui.views.editor.pages.AbstractCustomFormToolkitEditorPage#hasApplyAction()
*/
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/OverviewEditorPage.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/OverviewEditorPage.java
index 1cc1aaf7c..3375c572c 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/OverviewEditorPage.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/OverviewEditorPage.java
@@ -19,15 +19,12 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.tcf.protocol.Protocol;
-import org.eclipse.tcf.te.runtime.persistence.history.HistoryManager;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.runtime.statushandler.StatusHandlerUtil;
import org.eclipse.tcf.te.runtime.utils.StatusHelper;
-import org.eclipse.tcf.te.tcf.core.interfaces.IPeerType;
import org.eclipse.tcf.te.tcf.locator.ScannerRunnable;
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.activator.UIPlugin;
import org.eclipse.tcf.te.tcf.ui.editor.sections.AttributesSection;
import org.eclipse.tcf.te.tcf.ui.editor.sections.GeneralInformationSection;
@@ -179,12 +176,6 @@ public class OverviewEditorPage extends AbstractCustomFormToolkitEditorPage {
}
super.setInput(input);
if (getEditorInputNode() instanceof IPeerModel) {
- // save history to reopen the editor on eclipse startup
- HistoryManager.getInstance().add(IPeerType.TYPE_GENERIC, ((IPeerModel)getEditorInputNode()).getPeerId());
- ISelectionService selService = ServiceManager.getInstance().getService(ISelectionService.class);
- if (selService != null) {
- selService.setDefaultSelection((IPeerModel)getEditorInputNode());
- }
// Invoke the scanner runnable
ScannerRunnable runnable = new ScannerRunnable(null, ((IPeerModel)getEditorInputNode()));
Protocol.invokeLater(runnable);
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
new file mode 100644
index 000000000..bdc37eb35
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/listeners/WorkbenchPartListener.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 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.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.ui.views.interfaces.IUIConstants;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.IWorkbenchPartReference;
+
+/**
+ * The part listener implementation. Takes care of
+ * activation and deactivation of key binding contexts.
+ */
+public class WorkbenchPartListener implements IPartListener2 {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partBroughtToTop(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ @Override
+ public void partBroughtToTop(IWorkbenchPartReference partRef) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ @Override
+ public void partOpened(IWorkbenchPartReference partRef) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ @Override
+ public void partClosed(IWorkbenchPartReference partRef) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partVisible(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ @Override
+ public void partVisible(IWorkbenchPartReference partRef) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partHidden(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ @Override
+ public void partHidden(IWorkbenchPartReference partRef) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partActivated(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ @Override
+ public void partActivated(IWorkbenchPartReference partRef) {
+ if (IUIConstants.ID_EDITOR.equals(partRef.getId())) {
+ if (partRef instanceof IEditorReference) {
+ IEditorPart part = (IEditorPart)partRef.getPart(false);
+ 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);
+ }
+
+ }
+ }
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partDeactivated(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ @Override
+ public void partDeactivated(IWorkbenchPartReference partRef) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partInputChanged(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ @Override
+ public void partInputChanged(IWorkbenchPartReference partRef) {
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/listeners/WorkbenchWindowListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/listeners/WorkbenchWindowListener.java
new file mode 100644
index 000000000..06d8b97d4
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/listeners/WorkbenchWindowListener.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 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.listeners;
+
+import org.eclipse.tcf.te.ui.views.listeners.AbstractWindowListener;
+import org.eclipse.ui.IPartListener2;
+
+/**
+ * The window listener implementation. Takes care of the
+ * management of the global listeners per workbench window.
+ */
+public class WorkbenchWindowListener extends AbstractWindowListener {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.views.listeners.AbstractWindowListener#createPartListener()
+ */
+ @Override
+ protected IPartListener2 createPartListener() {
+ return new WorkbenchPartListener();
+ }
+}

Back to the top