Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorustieber2011-08-31 14:24:46 +0000
committerustieber2011-08-31 14:24:46 +0000
commitb3270366c51cdf00a97fb3d197375209f5c38687 (patch)
tree57729f9c9e83acdfab598e39225e5034db54a981 /target_explorer
parenta3fc1e9d53382a5557a7b93e347c2c97f17e4265 (diff)
downloadorg.eclipse.tcf-b3270366c51cdf00a97fb3d197375209f5c38687.tar.gz
org.eclipse.tcf-b3270366c51cdf00a97fb3d197375209f5c38687.tar.xz
org.eclipse.tcf-b3270366c51cdf00a97fb3d197375209f5c38687.zip
Target Explorer: Unify code for refreshing and selecting of views
Diffstat (limited to 'target_explorer')
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/wizards/NewTargetWizard.java23
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.views/META-INF/MANIFEST.MF4
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/ViewsUtil.java90
3 files changed, 100 insertions, 17 deletions
diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/wizards/NewTargetWizard.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/wizards/NewTargetWizard.java
index 646d43aa1..7888d40cb 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/wizards/NewTargetWizard.java
+++ b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/wizards/NewTargetWizard.java
@@ -13,7 +13,6 @@ import java.io.IOException;
import java.util.Map;
import org.eclipse.jface.dialogs.IMessageProvider;
-import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
@@ -28,13 +27,11 @@ import org.eclipse.tm.te.tcf.ui.internal.PeersPersistenceManager;
import org.eclipse.tm.te.tcf.ui.internal.model.Model;
import org.eclipse.tm.te.tcf.ui.internal.nls.Messages;
import org.eclipse.tm.te.tcf.ui.internal.wizards.pages.NewTargetWizardPage;
+import org.eclipse.tm.te.ui.views.ViewsUtil;
import org.eclipse.tm.te.ui.views.interfaces.IUIConstants;
import org.eclipse.tm.te.ui.wizards.AbstractWizard;
import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
/**
* New TCF target wizard implementation.
@@ -84,19 +81,13 @@ public class NewTargetWizard extends AbstractWizard implements INewWizard {
// Refresh the model now (must be executed within the TCF dispatch thread)
service.refresh();
- // Get the peer model node from the model
+ // Trigger a refresh of the viewer
+ ViewsUtil.refresh(IUIConstants.ID_EXPLORER);
+
+ // Get the peer model node from the model and select it in the tree
final IPeerModel peerNode = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(peerAttributes.get(IPeer.ATTR_ID));
- if (peerNode != null && PlatformUI.isWorkbenchRunning()) {
- PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
- public void run() {
- if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
- IViewReference reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findViewReference(IUIConstants.ID_EXPLORER);
- IWorkbenchPart part = reference != null ? reference.getPart(false) : null;
- ISelectionProvider selectionProvider = part != null && part.getSite() != null ? part.getSite().getSelectionProvider() : null;
- if (selectionProvider != null) selectionProvider.setSelection(new StructuredSelection(peerNode));
- }
- }
- });
+ if (peerNode != null) {
+ ViewsUtil.setSelection(IUIConstants.ID_EXPLORER, new StructuredSelection(peerNode));
}
}
});
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.views/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tm.te.ui.views/META-INF/MANIFEST.MF
index 57fd096a4..51eea76a9 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.ui.views/META-INF/MANIFEST.MF
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.views/META-INF/MANIFEST.MF
@@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
-Export-Package: org.eclipse.tm.te.ui.views.activator;x-internal:=true,
+Export-Package: org.eclipse.tm.te.ui.views,
+ org.eclipse.tm.te.ui.views.activator;x-internal:=true,
org.eclipse.tm.te.ui.views.editor,
org.eclipse.tm.te.ui.views.interfaces,
org.eclipse.tm.te.ui.views.internal;x-internal:=true,
@@ -24,5 +25,6 @@ Export-Package: org.eclipse.tm.te.ui.views.activator;x-internal:=true,
org.eclipse.tm.te.ui.views.internal.expressions;x-internal:=true,
org.eclipse.tm.te.ui.views.internal.extensions;x-internal:=true,
org.eclipse.tm.te.ui.views.internal.handler;x-internal:=true,
+ org.eclipse.tm.te.ui.views.internal.listeners;x-internal:=true,
org.eclipse.tm.te.ui.views.internal.nls;x-internal:=true,
org.eclipse.tm.te.ui.views.perspective
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
new file mode 100644
index 000000000..912ee6a0e
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/ViewsUtil.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.tm.te.ui.views;
+
+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.IViewReference;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.CommonNavigator;
+
+/**
+ * Target Explorer: Utility methods to deal with views.
+ */
+public class ViewsUtil {
+
+ /**
+ * Asynchronously refresh the view identified by the given id.
+ *
+ * @param id The view id. Must not be <code>null</code>.
+ */
+ public static void refresh(final String id) {
+ Assert.isNotNull(id);
+
+ // Create the runnable
+ Runnable runnable = new Runnable() {
+ public void run() {
+ // Check the active workbench window and active page instances
+ if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
+ // Get the view reference
+ IViewReference reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findViewReference(id);
+ // Get the view part from the reference, but do not restore it
+ IWorkbenchPart part = reference != null ? reference.getPart(false) : null;
+ // If the part is a common navigator, get the common viewer
+ Viewer viewer = part instanceof CommonNavigator ? ((CommonNavigator)part).getCommonViewer() : null;
+ // If not a common navigator, try to adapt to the viewer
+ if (viewer == null) viewer = part != null ? (Viewer)part.getAdapter(Viewer.class) : null;
+ // Refresh the viewer
+ if (viewer != null) viewer.refresh();
+ }
+ }
+ };
+
+ // Execute asynchronously
+ if (PlatformUI.isWorkbenchRunning()) {
+ PlatformUI.getWorkbench().getDisplay().asyncExec(runnable);
+ }
+ }
+
+ /**
+ * Asynchronously set the given selection to the view identified by the given id.
+ *
+ * @param id The view id. Must not be <code>null</code>.
+ * @param selection The selection or <code>null</code>.
+ */
+ public static void setSelection(final String id, final ISelection selection) {
+ Assert.isNotNull(id);
+
+ // Create the runnable
+ Runnable runnable = new Runnable() {
+ public void run() {
+ // Check the active workbench window and active page instances
+ if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
+ // Get the view reference
+ IViewReference reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findViewReference(id);
+ // Get the view part from the reference, but do not restore it
+ IWorkbenchPart part = reference != null ? reference.getPart(false) : null;
+ // Get the selection provider
+ ISelectionProvider selectionProvider = part != null && part.getSite() != null ? part.getSite().getSelectionProvider() : null;
+ // And apply the selection
+ if (selectionProvider != null) selectionProvider.setSelection(selection);
+ }
+ }
+ };
+
+ // Execute asynchronously
+ if (PlatformUI.isWorkbenchRunning()) {
+ PlatformUI.getWorkbench().getDisplay().asyncExec(runnable);
+ }
+ }
+}

Back to the top