Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Schwarz2012-07-26 07:34:33 -0400
committerTobias Schwarz2012-07-26 07:34:33 -0400
commitff2ae5e35538a7153ac19890c124c09e3f1ba81c (patch)
tree8a2ecd75283a87f2e8715e73b3ec18946f108ee7
parentfbc0c803672ebcf2ddcb44805bc0c1a8fa9d6ab7 (diff)
downloadorg.eclipse.tcf-ff2ae5e35538a7153ac19890c124c09e3f1ba81c.tar.gz
org.eclipse.tcf-ff2ae5e35538a7153ac19890c124c09e3f1ba81c.tar.xz
org.eclipse.tcf-ff2ae5e35538a7153ac19890c124c09e3f1ba81c.zip
Target Explorer: reopen peer editor on eclipse startup
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/PeerModelFactory.java115
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/editor/EditorInput.java24
2 files changed, 88 insertions, 51 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/PeerModelFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/PeerModelFactory.java
index e47ff140b..830d4ff32 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/PeerModelFactory.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/PeerModelFactory.java
@@ -1,46 +1,69 @@
-/*******************************************************************************
- * 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.tcf.ui.internal.adapters;
-
-import java.util.Map;
-
-import org.eclipse.core.runtime.IAdaptable;
-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.ILocatorModelPeerNodeQueryService;
-import org.eclipse.tcf.te.tcf.locator.model.Model;
-import org.eclipse.ui.IElementFactory;
-import org.eclipse.ui.IMemento;
-
-/**
- * The element factory to create IPeerModel from a memento which is read
- * from an external persistent storage.
- */
-public class PeerModelFactory implements IElementFactory {
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
- */
- @Override
- public IAdaptable createElement(IMemento memento) {
- String peerId = memento.getString("peerId"); //$NON-NLS-1$
- Map<String, IPeerModel> map = (Map<String, IPeerModel>) Model.getModel().getAdapter(Map.class);
- IPeerModel node = map.get(peerId);
- // Make sure the remote services are up to date so
- // that content extension could correctly activated!
- if (node != null) {
- ILocatorModel model = node.getModel();
- ILocatorModelPeerNodeQueryService queryService = model.getService(ILocatorModelPeerNodeQueryService.class);
- queryService.queryRemoteServices(node);
- }
- return node;
- }
-}
+/*******************************************************************************
+ * 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.tcf.ui.internal.adapters;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.tcf.protocol.Protocol;
+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.ILocatorModelPeerNodeQueryService;
+import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService;
+import org.eclipse.tcf.te.tcf.locator.model.Model;
+import org.eclipse.tcf.te.ui.views.editor.EditorInput;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+
+/**
+ * The element factory to create an peer model editor input from a memento which is read
+ * from an external persistent storage and holds a peer id.
+ */
+public class PeerModelFactory implements IElementFactory {
+
+ protected boolean isModelRefreshed = false;
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public IAdaptable createElement(IMemento memento) {
+ String peerId = memento.getString("peerId"); //$NON-NLS-1$
+ // refresh the model
+ if (!isModelRefreshed) {
+ Protocol.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ ILocatorModelRefreshService service = Model.getModel().getService(ILocatorModelRefreshService.class);
+ if (service != null) {
+ service.refresh();
+ service.refreshStaticPeers();
+ }
+ isModelRefreshed = true;
+ }
+ });
+ }
+ // search the peerId in the models peers
+ IPeerModel[] peerModels = Model.getModel().getPeers();
+ IPeerModel node = null;
+ for (IPeerModel peerModel : peerModels) {
+ if (peerModel.getPeer().getID().equals(peerId)) {
+ node = peerModel;
+ break;
+ }
+ }
+
+ if (node != null) {
+ ILocatorModel model = node.getModel();
+ ILocatorModelPeerNodeQueryService queryService = model.getService(ILocatorModelPeerNodeQueryService.class);
+ queryService.queryRemoteServices(node);
+ }
+ return node != null ? new EditorInput(node) : null;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/editor/EditorInput.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/editor/EditorInput.java
index 470eeab8d..5764e1715 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/editor/EditorInput.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/editor/EditorInput.java
@@ -67,7 +67,7 @@ public final class EditorInput implements IEditorInput, IPersistableElement {
public boolean equals(Object obj) {
if (node != null && obj instanceof EditorInput) {
return node.equals(((EditorInput)obj).node)
- && (id != null ? id.equals(((EditorInput)obj).id) : ((EditorInput)obj).id == null);
+ && (id != null ? id.equals(((EditorInput)obj).id) : ((EditorInput)obj).id == null);
}
return super.equals(obj);
}
@@ -103,7 +103,9 @@ public final class EditorInput implements IEditorInput, IPersistableElement {
public String getName() {
if (name == null && node != null) {
ILabelProvider provider = node instanceof IAdaptable ? (ILabelProvider)((IAdaptable)node).getAdapter(ILabelProvider.class) : null;
- if (provider == null) provider = (ILabelProvider)Platform.getAdapterManager().getAdapter(node, ILabelProvider.class);
+ if (provider == null) {
+ provider = (ILabelProvider)Platform.getAdapterManager().getAdapter(node, ILabelProvider.class);
+ }
name = provider != null ? provider.getText(node) : node.toString();
}
@@ -117,7 +119,7 @@ public final class EditorInput implements IEditorInput, IPersistableElement {
*/
protected CommonViewer getViewer() {
if (PlatformUI.getWorkbench() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
- && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
+ && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart part = page.findView(IUIConstants.ID_EXPLORER);
if (part instanceof CommonNavigator) {
@@ -133,7 +135,9 @@ public final class EditorInput implements IEditorInput, IPersistableElement {
*/
@Override
public IPersistableElement getPersistable() {
- // We cannot persist this kind of editor input.
+ if (Platform.getAdapterManager().getAdapter(node, IPersistableElement.class) != null) {
+ return this;
+ }
return null;
}
@@ -142,6 +146,10 @@ public final class EditorInput implements IEditorInput, IPersistableElement {
*/
@Override
public String getFactoryId() {
+ IPersistableElement adapter = (IPersistableElement)Platform.getAdapterManager().getAdapter(node, IPersistableElement.class);
+ if (adapter != null) {
+ return adapter.getFactoryId();
+ }
return null;
}
@@ -150,6 +158,10 @@ public final class EditorInput implements IEditorInput, IPersistableElement {
*/
@Override
public void saveState(IMemento memento) {
+ IPersistableElement adapter = (IPersistableElement)Platform.getAdapterManager().getAdapter(node, IPersistableElement.class);
+ if (adapter != null) {
+ adapter.saveState(memento);
+ }
}
/* (non-Javadoc)
@@ -171,7 +183,9 @@ public final class EditorInput implements IEditorInput, IPersistableElement {
// If the adapter can be applied to the node instance, return the node
Object adapted = Platform.getAdapterManager().getAdapter(node, adapter);
- if (adapted != null) return adapted;
+ if (adapted != null) {
+ return adapted;
+ }
return Platform.getAdapterManager().getAdapter(this, adapter);
}

Back to the top