Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Chen2012-04-26 07:02:25 +0000
committerWilliam Chen2012-04-26 07:02:25 +0000
commit82e89995ffde3d8891ded211fa584292db0594db (patch)
treec4ce331060d46c0eabbc85c96419eeb79ed5e48c /target_explorer/plugins
parent7a397ced698cebb4d14e3ef6a7747ee9fd1c5cd3 (diff)
downloadorg.eclipse.tcf-82e89995ffde3d8891ded211fa584292db0594db.tar.gz
org.eclipse.tcf-82e89995ffde3d8891ded211fa584292db0594db.tar.xz
org.eclipse.tcf-82e89995ffde3d8891ded211fa584292db0594db.zip
Target Explorer: Bug fix #375940: Target Explorer view does not remember
the expanded nodes.
Diffstat (limited to 'target_explorer/plugins')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/url/TcfURLConnection.java13
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.xml27
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/activator/UIPlugin.java25
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/interfaces/preferences/IPreferenceKeys.java20
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeAdapterFactory.java9
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeFactory.java53
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/PersistableNode.java52
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/preferences/PreferencePage.java21
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/preferences/PreferencesInitializer.java11
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.java1
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.properties1
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/plugin.xml7
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetAdapterFactory.java46
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetComparer.java52
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/src/org/eclipse/tcf/te/ui/views/workingsets/actions/WorkingSetActionProvider.java11
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml22
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/AbstractCategory.java34
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/CategoryFactory.java34
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/interfaces/IPersistableExpandingState.java36
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/View.java13
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewExpandingState.java118
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewViewerComparer.java68
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/adapters/PeerModelAdapterFactory.java45
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/adapters/PeerModelFactory.java36
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/adapters/PersistablePeerModel.java47
25 files changed, 751 insertions, 51 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/url/TcfURLConnection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/url/TcfURLConnection.java
index 304a79680..887d6a898 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/url/TcfURLConnection.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/url/TcfURLConnection.java
@@ -15,6 +15,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
+import java.util.Map;
import org.eclipse.core.runtime.Assert;
import org.eclipse.osgi.util.NLS;
@@ -104,15 +105,13 @@ public class TcfURLConnection extends URLConnection {
* @param peerId The target peer's ID.
* @return The peer with this ID or null if not found.
*/
- private IPeer findPeer(String peerId) {
+ @SuppressWarnings("unchecked")
+ private IPeer findPeer(String peerId) {
IPeer peer = Protocol.getLocator().getPeers().get(peerId);
if(peer == null) {
- IPeerModel[] peerModels = Model.getModel().getPeers();
- for(IPeerModel peerModel : peerModels) {
- if(peerId.equals(peerModel.getPeerId())) {
- return peerModel.getPeer();
- }
- }
+ Map<String, IPeerModel> map = (Map<String, IPeerModel>) Model.getModel().getAdapter(Map.class);
+ IPeerModel peerNode = map.get(peerId);
+ if(peerNode != null) peer = peerNode.getPeer();
}
return peer;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.xml
index e5325aa3d..3ba90eb79 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.xml
@@ -1669,6 +1669,16 @@
<adapter
type="org.eclipse.tcf.te.ui.views.interfaces.handler.IDeleteHandlerDelegate">
</adapter>
+ <adapter
+ type="org.eclipse.ui.IPersistableElement">
+ </adapter>
+ </factory>
+ <factory
+ adaptableType="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"
+ class="org.eclipse.tcf.te.tcf.filesystem.ui.internal.adapters.ViewerInputAdapterFactory">
+ <adapter
+ type="org.eclipse.tcf.te.core.interfaces.IViewerInput">
+ </adapter>
</factory>
</extension>
@@ -1863,16 +1873,6 @@
</filterContribution>
</extension>
<extension
- point="org.eclipse.core.runtime.adapters">
- <factory
- adaptableType="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"
- class="org.eclipse.tcf.te.tcf.filesystem.ui.internal.adapters.ViewerInputAdapterFactory">
- <adapter
- type="org.eclipse.tcf.te.core.interfaces.IViewerInput">
- </adapter>
- </factory>
- </extension>
- <extension
point="org.eclipse.ui.views.properties.tabbed.propertyTabs">
<propertyTabs
contributorId="org.eclipse.tcf.te.ui">
@@ -1951,5 +1951,12 @@
tab="org.eclipse.tcf.te.tcf.filesystem.propertytab.advanced">
</propertySection>
</propertySections>
+ </extension>
+ <extension
+ point="org.eclipse.ui.elementFactories">
+ <factory
+ class="org.eclipse.tcf.te.tcf.filesystem.ui.internal.adapters.FSTreeNodeFactory"
+ id="org.eclipse.tcf.te.tcf.filesystem.ui.nodeFactory">
+ </factory>
</extension>
</plugin>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/activator/UIPlugin.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/activator/UIPlugin.java
index 7cbb8ca07..38fd4514b 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/activator/UIPlugin.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/activator/UIPlugin.java
@@ -20,11 +20,11 @@ import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.tcf.te.tcf.filesystem.ui.interfaces.preferences.IPreferenceKeys;
import org.eclipse.tcf.te.tcf.filesystem.ui.internal.ImageConsts;
import org.eclipse.tcf.te.tcf.filesystem.ui.internal.autosave.SaveAllListener;
import org.eclipse.tcf.te.tcf.filesystem.ui.internal.autosave.SaveListener;
import org.eclipse.tcf.te.tcf.filesystem.ui.internal.operations.FsClipboard;
-import org.eclipse.tcf.te.tcf.filesystem.ui.internal.preferences.PreferencePage;
import org.eclipse.tcf.te.ui.jface.images.AbstractImageDescriptor;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.PlatformUI;
@@ -35,7 +35,7 @@ import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
-public class UIPlugin extends AbstractUIPlugin {
+public class UIPlugin extends AbstractUIPlugin implements IPreferenceKeys {
// The shared instance of this plug-in.
private static UIPlugin plugin;
// The listener which listens to command "SAVE" and synchronize the local file with the target.
@@ -201,10 +201,21 @@ public class UIPlugin extends AbstractUIPlugin {
*/
public static boolean isAutoSaving() {
IPreferenceStore preferenceStore = getDefault().getPreferenceStore();
- boolean autoSaving = preferenceStore.getBoolean(PreferencePage.PREF_AUTOSAVING);
+ boolean autoSaving = preferenceStore.getBoolean(PREF_AUTOSAVING);
return autoSaving;
}
-
+
+ /**
+ * If the option of "expanded_persisted" is set to on.
+ *
+ * @return true if the expanded state should be persisted or else false.
+ */
+ public static boolean isExpandedPersisted() {
+ IPreferenceStore preferenceStore = getDefault().getPreferenceStore();
+ boolean persisted = preferenceStore.getBoolean(PREF_EXPANDED_PERSISTED);
+ return persisted;
+ }
+
/**
* If the option of "in-place editor" is set to on.
*
@@ -212,7 +223,7 @@ public class UIPlugin extends AbstractUIPlugin {
*/
public static boolean isInPlaceEditor() {
IPreferenceStore preferenceStore = getDefault().getPreferenceStore();
- boolean inPlaceEditor = preferenceStore.getBoolean(PreferencePage.PREF_RENAMING_IN_PLACE_EDITOR);
+ boolean inPlaceEditor = preferenceStore.getBoolean(PREF_RENAMING_IN_PLACE_EDITOR);
return inPlaceEditor;
}
@@ -223,7 +234,7 @@ public class UIPlugin extends AbstractUIPlugin {
*/
public static boolean isCopyPermission() {
IPreferenceStore preferenceStore = getDefault().getPreferenceStore();
- boolean copyPermission = preferenceStore.getBoolean(PreferencePage.PREF_COPY_PERMISSION);
+ boolean copyPermission = preferenceStore.getBoolean(PREF_COPY_PERMISSION);
return copyPermission;
}
@@ -234,7 +245,7 @@ public class UIPlugin extends AbstractUIPlugin {
*/
public static boolean isCopyOwnership() {
IPreferenceStore preferenceStore = getDefault().getPreferenceStore();
- boolean copyOwnership = preferenceStore.getBoolean(PreferencePage.PREF_COPY_OWNERSHIP);
+ boolean copyOwnership = preferenceStore.getBoolean(PREF_COPY_OWNERSHIP);
return copyOwnership;
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/interfaces/preferences/IPreferenceKeys.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/interfaces/preferences/IPreferenceKeys.java
index 69792d607..0a26c18ec 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/interfaces/preferences/IPreferenceKeys.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/interfaces/preferences/IPreferenceKeys.java
@@ -23,4 +23,24 @@ public interface IPreferenceKeys {
* explorer details editor will be activated and visible to the user.
*/
public final String PREF_FEATURE_ENABLE_EDITOR_CONTENT_CONTRIBUTION = PREFIX + "feature.editor.content.enable"; //$NON-NLS-1$
+ // The preference key to access the option of auto saving
+ public static final String PREF_AUTOSAVING = "PrefAutoSaving"; //$NON-NLS-1$
+ // The default value of the option of auto saving.
+ public static final boolean DEFAULT_AUTOSAVING = true;
+ // The preference key to access the option using in-place editor during renaming.
+ public static final String PREF_RENAMING_IN_PLACE_EDITOR = "PrefRenamingInPlaceEditor"; //$NON-NLS-1$
+ // The default value of the option using in-place editor during renaming.
+ public static final boolean DEFAULT_RENAMING_IN_PLACE_EDITOR = true;
+ // The preference key to access the option of copy permission when copying files.
+ public static final String PREF_COPY_PERMISSION = "PrefCopyPermission"; //$NON-NLS-1$
+ // The default value of the option of copy permission.
+ public static final boolean DEFAULT_COPY_PERMISSION = true;
+ // The preference key to access the option of copy ownership when copying files.
+ public static final String PREF_COPY_OWNERSHIP = "PrefCopyOwnership"; //$NON-NLS-1$
+ // The default value of the option of copy ownership
+ public static final boolean DEFAULT_COPY_OWNERSHIP = true;
+ // The preference key to access the option that if expanded nodes should be persisted
+ public static final String PREF_EXPANDED_PERSISTED = "PrefExpandedPersisted"; //$NON-NLS-1$
+ // The default value of the option that if expanded nodes should be persisted
+ public static final boolean DEFAULT_EXPANDED_PERSISTED = true;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeAdapterFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeAdapterFactory.java
index a498c8357..7b53d0681 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeAdapterFactory.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeAdapterFactory.java
@@ -17,10 +17,12 @@ import java.util.Map;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
+import org.eclipse.tcf.te.tcf.filesystem.ui.activator.UIPlugin;
import org.eclipse.tcf.te.tcf.filesystem.ui.internal.columns.FSTreeElementLabelProvider;
import org.eclipse.tcf.te.ui.views.interfaces.handler.IDeleteHandlerDelegate;
import org.eclipse.tcf.te.ui.views.interfaces.handler.IRefreshHandlerDelegate;
import org.eclipse.ui.IActionFilter;
+import org.eclipse.ui.IPersistableElement;
/**
* The adapter factory of <code>FSTreeNode</code> over <code>IActionFilter</code>
@@ -45,8 +47,8 @@ public class FSTreeNodeAdapterFactory implements IAdapterFactory {
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if(adaptableObject instanceof FSTreeNode) {
+ FSTreeNode node = (FSTreeNode) adaptableObject;
if(adapterType == IActionFilter.class) {
- FSTreeNode node = (FSTreeNode) adaptableObject;
NodeStateFilter filter = filters.get(node);
if(filter == null){
filter = new NodeStateFilter(node);
@@ -63,6 +65,9 @@ public class FSTreeNodeAdapterFactory implements IAdapterFactory {
else if(adapterType == IDeleteHandlerDelegate.class) {
return deleteDelegate;
}
+ else if(adapterType == IPersistableElement.class && UIPlugin.isExpandedPersisted()) {
+ return new PersistableNode(node);
+ }
}
return null;
}
@@ -72,6 +77,6 @@ public class FSTreeNodeAdapterFactory implements IAdapterFactory {
*/
@Override
public Class[] getAdapterList() {
- return new Class[] { IActionFilter.class, ILabelProvider.class, IRefreshHandlerDelegate.class, IDeleteHandlerDelegate.class };
+ return new Class[] { IActionFilter.class, ILabelProvider.class, IRefreshHandlerDelegate.class, IDeleteHandlerDelegate.class, IPersistableElement.class };
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeFactory.java
new file mode 100644
index 000000000..2786d555d
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeFactory.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.filesystem.ui.internal.adapters;
+
+import java.util.Map;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.IOpExecutor;
+import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.NullOpExecutor;
+import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpParsePath;
+import org.eclipse.tcf.te.tcf.filesystem.core.model.FSModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.tcf.locator.model.Model;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+
+/**
+ * The element factory for FSTreeNode used to restore FSTreeNodes persisted
+ * for expanded states.
+ */
+public class FSTreeNodeFactory 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> peerMap = (Map<String, IPeerModel>) Model.getModel().getAdapter(Map.class);
+ IPeerModel peerModel = peerMap.get(peerId);
+ if(peerModel != null) {
+ String path = memento.getString("path"); //$NON-NLS-1$
+ if(path == null) {
+ return FSModel.getFSModel(peerModel).getRoot();
+ }
+ OpParsePath op = new OpParsePath(peerModel, path);
+ IOpExecutor executor = new NullOpExecutor();
+ IStatus status = executor.execute(op);
+ if(status.isOK()) {
+ return op.getResult();
+ }
+ }
+ return null;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/PersistableNode.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/PersistableNode.java
new file mode 100644
index 000000000..22aa43cd1
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/PersistableNode.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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.filesystem.ui.internal.adapters;
+
+import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * The adapter class of FSTreeNode for IPersistableElement, used to
+ * persist an FSTreeNode.
+ */
+public class PersistableNode implements IPersistableElement {
+ // The node to be persisted.
+ private FSTreeNode node;
+ /**
+ * Create an instance.
+ *
+ * @param node The node to be persisted.
+ */
+ public PersistableNode(FSTreeNode node) {
+ this.node = node;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public void saveState(IMemento memento) {
+ memento.putString("peerId", node.peerNode.getPeerId()); //$NON-NLS-1$
+ String path = null;
+ if (!node.isSystemRoot()) path = node.getLocation();
+ if (path != null) memento.putString("path", path); //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IPersistableElement#getFactoryId()
+ */
+ @Override
+ public String getFactoryId() {
+ return "org.eclipse.tcf.te.tcf.filesystem.ui.nodeFactory"; //$NON-NLS-1$
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/preferences/PreferencePage.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/preferences/PreferencePage.java
index 6206db5e3..9fba52217 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/preferences/PreferencePage.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/preferences/PreferencePage.java
@@ -14,6 +14,7 @@ import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.tcf.te.tcf.filesystem.ui.activator.UIPlugin;
+import org.eclipse.tcf.te.tcf.filesystem.ui.interfaces.preferences.IPreferenceKeys;
import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
@@ -23,23 +24,7 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
* the TCF File System Explorer.
*
*/
-public class PreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
- // The preference key to access the option of auto saving
- public static final String PREF_AUTOSAVING = "PrefAutoSaving"; //$NON-NLS-1$
- // The default value of the option of auto saving.
- public static final boolean DEFAULT_AUTOSAVING = true;
- // The preference key to access the option using in-place editor during renaming.
- public static final String PREF_RENAMING_IN_PLACE_EDITOR = "PrefRenamingInPlaceEditor"; //$NON-NLS-1$
- // The default value of the option using in-place editor during renaming.
- public static final boolean DEFAULT_RENAMING_IN_PLACE_EDITOR = true;
- // The preference key to access the option of copy permission when copying files.
- public static final String PREF_COPY_PERMISSION = "PrefCopyPermission"; //$NON-NLS-1$
- // The default value of the option of copy permission.
- public static final boolean DEFAULT_COPY_PERMISSION = true;
- // The preference key to access the option of copy ownership when copying files.
- public static final String PREF_COPY_OWNERSHIP = "PrefCopyOwnership"; //$NON-NLS-1$
- // The default value of the option of copy ownership
- public static final boolean DEFAULT_COPY_OWNERSHIP = true;
+public class PreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage, IPreferenceKeys {
/***
* Create a preference page for Target Explorer File System Explorer.
@@ -64,6 +49,8 @@ public class PreferencePage extends FieldEditorPreferencePage implements IWorkbe
addField(copyPermission);
BooleanFieldEditor copyOwnership = new BooleanFieldEditor(PREF_COPY_OWNERSHIP, Messages.PreferencePage_CopyOwnershipText, getFieldEditorParent());
addField(copyOwnership);
+ BooleanFieldEditor persistExpanded = new BooleanFieldEditor(PREF_EXPANDED_PERSISTED, Messages.PreferencePage_PersistExpanded, getFieldEditorParent());
+ addField(persistExpanded);
}
/* (non-Javadoc)
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/preferences/PreferencesInitializer.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/preferences/PreferencesInitializer.java
index 935e02b9e..ada956d66 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/preferences/PreferencesInitializer.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/preferences/PreferencesInitializer.java
@@ -20,7 +20,7 @@ import org.eclipse.tcf.te.tcf.filesystem.ui.interfaces.preferences.IPreferenceKe
/**
* The bundle's preference initializer implementation.
*/
-public class PreferencesInitializer extends AbstractPreferenceInitializer {
+public class PreferencesInitializer extends AbstractPreferenceInitializer implements IPreferenceKeys {
/**
* Constructor.
@@ -41,9 +41,10 @@ public class PreferencesInitializer extends AbstractPreferenceInitializer {
prefs.putBoolean(IPreferenceKeys.PREF_FEATURE_ENABLE_EDITOR_CONTENT_CONTRIBUTION, true);
}
IPreferenceStore preferenceStore = UIPlugin.getDefault().getPreferenceStore();
- preferenceStore.setDefault(PreferencePage.PREF_AUTOSAVING, PreferencePage.DEFAULT_AUTOSAVING);
- preferenceStore.setDefault(PreferencePage.PREF_RENAMING_IN_PLACE_EDITOR, PreferencePage.DEFAULT_RENAMING_IN_PLACE_EDITOR);
- preferenceStore.setDefault(PreferencePage.PREF_COPY_PERMISSION, PreferencePage.DEFAULT_COPY_PERMISSION);
- preferenceStore.setDefault(PreferencePage.PREF_COPY_OWNERSHIP, PreferencePage.DEFAULT_COPY_OWNERSHIP);
+ preferenceStore.setDefault(PREF_AUTOSAVING, DEFAULT_AUTOSAVING);
+ preferenceStore.setDefault(PREF_RENAMING_IN_PLACE_EDITOR, DEFAULT_RENAMING_IN_PLACE_EDITOR);
+ preferenceStore.setDefault(PREF_COPY_PERMISSION, DEFAULT_COPY_PERMISSION);
+ preferenceStore.setDefault(PREF_COPY_OWNERSHIP, DEFAULT_COPY_OWNERSHIP);
+ preferenceStore.setDefault(PREF_EXPANDED_PERSISTED, DEFAULT_EXPANDED_PERSISTED);
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.java
index 8e659d1d6..e91a0cac8 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.java
@@ -289,6 +289,7 @@ public class Messages extends NLS {
public static String PreferencePage_AutoSavingText;
public static String PreferencePage_CopyOwnershipText;
public static String PreferencePage_CopyPermissionText;
+ public static String PreferencePage_PersistExpanded;
public static String PreferencePage_RenamingOptionText;
public static String TargetSelectionPage_Description;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.properties
index e149108a3..20e9f6843 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.properties
@@ -206,6 +206,7 @@ StateManager_UpdateFailureTitle=Update Failure
PreferencePage_AutoSavingText=Automatically upload files to targets upon saving
PreferencePage_CopyOwnershipText=Copy source UID and GID when copying files
PreferencePage_CopyPermissionText=Copy source permissions when copying files
+PreferencePage_PersistExpanded=Remember expanded directories
PreferencePage_RenamingOptionText=Use In-place Editor when renaming a file/folder
TargetSelectionPage_Description=Please select the target where the new file/folder is created.
TargetSelectionPage_Targets=Targets:
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/plugin.xml
index 41a3187e3..7a7232e25 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/plugin.xml
@@ -15,6 +15,13 @@
class="org.eclipse.tcf.te.ui.views.workingsets.WorkingSetElementHolderAdapterFactory">
<adapter type="org.eclipse.tcf.te.runtime.interfaces.workingsets.IWorkingSetElement"/>
</factory>
+ <factory
+ adaptableType="org.eclipse.ui.IWorkingSet"
+ class="org.eclipse.tcf.te.ui.views.workingsets.WorkingSetAdapterFactory">
+ <adapter
+ type="org.eclipse.jface.viewers.IElementComparer">
+ </adapter>
+ </factory>
</extension>
<!-- Common Navigator contributions -->
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetAdapterFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetAdapterFactory.java
new file mode 100644
index 000000000..a6a9720df
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetAdapterFactory.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.workingsets;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jface.viewers.IElementComparer;
+import org.eclipse.ui.IWorkingSet;
+
+/**
+ * The adapter factory to adapt a working set to IElementComparer, which
+ * customize the comparison during restoring expanding state.
+ */
+public class WorkingSetAdapterFactory implements IAdapterFactory {
+ // The adapter list.
+ private static Class<?>[] adapters = {IElementComparer.class};
+ // The adapted IElementComparer of a working set.
+ private static IElementComparer wsComparer = new WorkingSetComparer();
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
+ */
+ @Override
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if(adaptableObject instanceof IWorkingSet && IElementComparer.class.equals(adapterType)) {
+ return wsComparer;
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+ */
+ @Override
+ public Class[] getAdapterList() {
+ return adapters;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetComparer.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetComparer.java
new file mode 100644
index 000000000..249a05b5d
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetComparer.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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.workingsets;
+
+import org.eclipse.jface.viewers.IElementComparer;
+import org.eclipse.ui.IWorkingSet;
+
+/**
+ * The element comparer implementation of a working set which only
+ * compares name and id instead of the default behavior of its equals
+ * method, which compares sub working sets as well.
+ */
+public class WorkingSetComparer implements IElementComparer {
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IElementComparer#equals(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object a, Object b) {
+ if(a instanceof IWorkingSet && b instanceof IWorkingSet) {
+ IWorkingSet aws = (IWorkingSet) a;
+ IWorkingSet bws = (IWorkingSet) b;
+ String aName = aws.getName();
+ String aId = aws.getId();
+ String bName = bws.getName();
+ String bId = bws.getId();
+ return _equals(aName, bName) && _equals(aId, bId);
+ }
+ return _equals(a, b);
+ }
+
+ private boolean _equals(Object a, Object b) {
+ return a == null ? b == null : a.equals(b);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IElementComparer#hashCode(java.lang.Object)
+ */
+ @Override
+ public int hashCode(Object element) {
+ return element == null ? 0 : element.hashCode();
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/src/org/eclipse/tcf/te/ui/views/workingsets/actions/WorkingSetActionProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/src/org/eclipse/tcf/te/ui/views/workingsets/actions/WorkingSetActionProvider.java
index f67d12ad1..0f92a14fc 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/src/org/eclipse/tcf/te/ui/views/workingsets/actions/WorkingSetActionProvider.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views.workingsets/src/org/eclipse/tcf/te/ui/views/workingsets/actions/WorkingSetActionProvider.java
@@ -9,6 +9,7 @@
*******************************************************************************/
package org.eclipse.tcf.te.ui.views.workingsets.actions;
+import org.eclipse.tcf.te.ui.views.interfaces.IPersistableExpandingState;
import org.eclipse.tcf.te.ui.views.workingsets.WorkingSetsContentProvider;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IMemento;
@@ -76,6 +77,11 @@ public class WorkingSetActionProvider extends CommonActionProvider {
showWorkingSets = showWorkingSetsInt == null || showWorkingSetsInt.intValue() == 1;
extensionStateModel.setBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS, showWorkingSets);
workingSetActionGroup.setShowTopLevelWorkingSets(showWorkingSets);
+ // Restore the expanded state only after the working set mode is set!
+ IPersistableExpandingState state = (IPersistableExpandingState)viewer.getCommonNavigator().getAdapter(IPersistableExpandingState.class);
+ if(state != null) {
+ state.restoreExpandingState(memento);
+ }
} else {
showWorkingSets = false;
@@ -96,6 +102,11 @@ public class WorkingSetActionProvider extends CommonActionProvider {
if (memento != null) {
int showWorkingSets = extensionStateModel.getBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS) ? 1 : 0;
memento.putInteger(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS, showWorkingSets);
+ // Save the expanding state of the common viewer.
+ IPersistableExpandingState state = (IPersistableExpandingState)viewer.getCommonNavigator().getAdapter(IPersistableExpandingState.class);
+ if (state != null) {
+ state.saveExpandingState(memento);
+ }
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml
index cf9f95f10..6c0854e7a 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml
@@ -512,5 +512,25 @@
<extension point="org.eclipse.core.runtime.preferences">
<initializer class="org.eclipse.tcf.te.ui.views.internal.preferences.PreferencesInitializer"/>
</extension>
-
+ <extension
+ point="org.eclipse.ui.elementFactories">
+ <factory
+ class="org.eclipse.tcf.te.ui.views.categories.CategoryFactory"
+ id="org.eclipse.tcf.te.ui.views.categoryFactory">
+ </factory>
+ <factory
+ class="org.eclipse.tcf.te.ui.views.internal.adapters.PeerModelFactory"
+ id="org.eclipse.tcf.te.ui.views.peerFactory">
+ </factory>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.adapters">
+ <factory
+ adaptableType="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"
+ class="org.eclipse.tcf.te.ui.views.internal.adapters.PeerModelAdapterFactory">
+ <adapter
+ type="org.eclipse.ui.IPersistableElement">
+ </adapter>
+ </factory>
+ </extension>
</plugin>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/AbstractCategory.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/AbstractCategory.java
index ef3664e5c..8e040a2da 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/AbstractCategory.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/AbstractCategory.java
@@ -17,12 +17,14 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.tcf.te.runtime.extensions.ExecutableExtension;
import org.eclipse.tcf.te.runtime.interfaces.IDisposable;
import org.eclipse.tcf.te.ui.views.interfaces.ICategory;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.plugin.AbstractUIPlugin;
/**
* Abstract main view category node implementation.
*/
-public abstract class AbstractCategory extends ExecutableExtension implements ICategory, IDisposable {
+public abstract class AbstractCategory extends ExecutableExtension implements ICategory, IDisposable, IPersistableElement {
// The category image / image descriptor
private ImageDescriptor descriptor = null;
private Image image = null;
@@ -54,6 +56,36 @@ public abstract class AbstractCategory extends ExecutableExtension implements IC
}
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class)
+ */
+ @Override
+ public Object getAdapter(Class adapter) {
+ if(adapter == IPersistableElement.class) {
+ return this;
+ }
+ return super.getAdapter(adapter);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public void saveState(IMemento memento) {
+ memento.putString("id", this.getId()); //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IPersistableElement#getFactoryId()
+ */
+ @Override
+ public String getFactoryId() {
+ return "org.eclipse.tcf.te.ui.views.categoryFactory"; //$NON-NLS-1$
+ }
+
/* (non-Javadoc)
* @see org.eclipse.tcf.te.runtime.interfaces.IDisposable#dispose()
*/
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/CategoryFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/CategoryFactory.java
new file mode 100644
index 000000000..bb278adba
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/CategoryFactory.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * 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.categories;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.tcf.te.ui.views.extensions.CategoriesExtensionPointManager;
+import org.eclipse.tcf.te.ui.views.interfaces.ICategory;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+/**
+ * The element factory for a category.
+ */
+public class CategoryFactory implements IElementFactory {
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public IAdaptable createElement(IMemento memento) {
+ String id = memento.getString("id"); //$NON-NLS-1$
+ ICategory category = CategoriesExtensionPointManager.getInstance().getCategory(id, false);
+ Assert.isNotNull(category);
+ Assert.isTrue(category instanceof IAdaptable);
+ return (IAdaptable)category;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/interfaces/IPersistableExpandingState.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/interfaces/IPersistableExpandingState.java
new file mode 100644
index 000000000..f8c7b15b7
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/interfaces/IPersistableExpandingState.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.interfaces;
+
+import org.eclipse.ui.IMemento;
+
+/**
+ * The interface to define the API to save and restore
+ * the persisted states of a common viewer.
+ * @see ViewExpandingState
+ */
+public interface IPersistableExpandingState {
+
+ /**
+ * Restore the expanding state of this common viewer using
+ * the state persisted in the memento.
+ *
+ * @param memento The memento that persists the expanding state.
+ */
+ public void restoreExpandingState(IMemento memento);
+
+ /**
+ * Save the expanding state of this common viewer to
+ * the memento.
+ *
+ * @param memento The memento to persist the expanding state.
+ */
+ public void saveExpandingState(IMemento memento);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/View.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/View.java
index a0d24ddaa..993ef19ed 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/View.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/View.java
@@ -29,6 +29,7 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.tcf.te.ui.trees.TreeViewerEditorActivationStrategy;
import org.eclipse.tcf.te.ui.views.activator.UIPlugin;
+import org.eclipse.tcf.te.ui.views.interfaces.IPersistableExpandingState;
import org.eclipse.tcf.te.ui.views.interfaces.IRoot;
import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants;
import org.eclipse.ui.IAggregateWorkingSet;
@@ -51,7 +52,7 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
* <p>
* The view is based on the Eclipse Common Navigator framework.
*/
-public class View extends CommonNavigator implements ITabbedPropertySheetPageContributor{
+public class View extends CommonNavigator implements ITabbedPropertySheetPageContributor {
// The view root mode
private int rootMode = IUIConstants.MODE_NORMAL;
@@ -61,6 +62,9 @@ public class View extends CommonNavigator implements ITabbedPropertySheetPageCon
*/
private String workingSetLabel;
+ // The state used to persisted the expanded nodes of the navigator tree.
+ private IPersistableExpandingState expandingState;
+
/**
* Constructor.
*/
@@ -132,6 +136,7 @@ public class View extends CommonNavigator implements ITabbedPropertySheetPageCon
@Override
protected CommonViewer createCommonViewerObject(Composite parent) {
ViewViewer viewer = new ViewViewer(getViewSite().getId(), parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ viewer.setComparer(new ViewViewerComparer());
// Define an editor activation strategy for the common viewer so as to be invoked only programmatically.
ColumnViewerEditorActivationStrategy activationStrategy = new TreeViewerEditorActivationStrategy(getSite().getId(), viewer);
TreeViewerEditor.create(viewer, null, activationStrategy, ColumnViewerEditor.DEFAULT);
@@ -248,6 +253,12 @@ public class View extends CommonNavigator implements ITabbedPropertySheetPageCon
if(adapter == IPropertySheetPage.class) {
return new TabbedPropertySheetPage(this);
}
+ else if(adapter == IPersistableExpandingState.class) {
+ if(expandingState == null) {
+ expandingState = new ViewExpandingState(getCommonViewer());
+ }
+ return expandingState;
+ }
return super.getAdapter(adapter);
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewExpandingState.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewExpandingState.java
new file mode 100644
index 000000000..1f0babb28
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewExpandingState.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * 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.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.viewers.IElementComparer;
+import org.eclipse.tcf.te.ui.views.interfaces.IPersistableExpandingState;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.CommonViewer;
+
+/**
+ * The class used to save and restore the expanding states of
+ * a common viewer in a navigator.
+ */
+public class ViewExpandingState implements IPersistableExpandingState {
+ // The common viewer whose expanding state is to be persisted.
+ private CommonViewer viewer;
+ /**
+ * The constructor.
+ */
+ public ViewExpandingState(CommonViewer viewer) {
+ this.viewer = viewer;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.views.interfaces.IPersistableState#restoreExpandingState(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public void restoreExpandingState(IMemento memento) {
+ IMemento memExpand = memento.getChild("expanded-elements"); //$NON-NLS-1$
+ if(memExpand != null) {
+ IMemento[] memElements = memExpand.getChildren("element"); //$NON-NLS-1$
+ List<Object> elements = new ArrayList<Object>();
+ for(IMemento memElement : memElements) {
+ Object element = restoreElement(memElement);
+ if(element != null) {
+ elements.add(element);
+ }
+ }
+ IElementComparer comparer = viewer.getComparer();
+ if(comparer instanceof ViewViewerComparer) {
+ ((ViewViewerComparer)comparer).setByDefault(false);
+ }
+ viewer.setExpandedElements(elements.toArray());
+ if(comparer instanceof ViewViewerComparer) {
+ ((ViewViewerComparer)comparer).setByDefault(true);
+ }
+ }
+ }
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.views.interfaces.IPersistableState#saveExpandingState(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public void saveExpandingState(IMemento memento) {
+ Object[] elements = viewer.getVisibleExpandedElements(); // Do not remember invisible expanded elements.
+ if(elements != null && elements.length > 0) {
+ IMemento memExpand = memento.createChild("expanded-elements"); //$NON-NLS-1$
+ for(Object element : elements) {
+ if(element instanceof IAdaptable) {
+ saveElement(memExpand, (IAdaptable)element);
+ }
+ }
+ }
+ }
+
+ /**
+ * Restore an element from the element memento.
+ *
+ * @param memElement The element memento.
+ * @return an element if it succeeds.
+ */
+ private IAdaptable restoreElement(IMemento memElement) {
+ String factoryId = memElement.getString("factoryId"); //$NON-NLS-1$
+ if(factoryId != null) {
+ IElementFactory eFactory = PlatformUI.getWorkbench().getElementFactory(factoryId);
+ if(eFactory != null) {
+ return eFactory.createElement(memElement);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Save an element to an element memento under the expanding
+ * elements memento.
+ *
+ * @param memExpand The expanding memento.
+ * @param element The element to save.
+ */
+ private void saveElement(IMemento memExpand, IAdaptable element) {
+ IPersistableElement persistable = (IPersistableElement) element.getAdapter(IPersistableElement.class);
+ if(persistable == null) {
+ persistable = (IPersistableElement) Platform.getAdapterManager().getAdapter(element, IPersistableElement.class);
+ }
+ if(persistable != null) {
+ String factoryId = persistable.getFactoryId();
+ IMemento memElement = memExpand.createChild("element"); //$NON-NLS-1$
+ memElement.putString("factoryId", factoryId); //$NON-NLS-1$
+ persistable.saveState(memElement);
+ }
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewViewerComparer.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewViewerComparer.java
new file mode 100644
index 000000000..ab94ce2a9
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewViewerComparer.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * 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.internal;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.viewers.IElementComparer;
+
+/**
+ * The comparer implementation for ViewViewer in order customize
+ * the comparison of tree nodes.
+ */
+public class ViewViewerComparer implements IElementComparer {
+ // If the current comparison is by default.
+ private boolean byDefault;
+
+ /**
+ * Constructor
+ */
+ public ViewViewerComparer() {
+ byDefault = true;
+ }
+
+ /**
+ * Set if the current comparison should follow default one.
+ *
+ * @param value The new value.
+ */
+ public void setByDefault(boolean value) {
+ byDefault = value;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IElementComparer#equals(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object a, Object b) {
+ if(a == b) return true;
+ if(byDefault) {
+ return a.equals(b);
+ }
+ IElementComparer comparer = (IElementComparer) Platform.getAdapterManager().getAdapter(a, IElementComparer.class);
+ if(comparer == null) {
+ comparer = (IElementComparer) Platform.getAdapterManager().getAdapter(b, IElementComparer.class);
+ }
+ if(comparer != null) {
+ return comparer.equals(a, b);
+ }
+ return a.equals(b);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IElementComparer#hashCode(java.lang.Object)
+ */
+ @Override
+ public int hashCode(Object element) {
+ if(element != null) return element.hashCode();
+ return 0;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/adapters/PeerModelAdapterFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/adapters/PeerModelAdapterFactory.java
new file mode 100644
index 000000000..545b273dd
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/adapters/PeerModelAdapterFactory.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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.internal.adapters;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.ui.IPersistableElement;
+/**
+ * The adapter factory to adapt an IPeerModel to an IPersistableElement.
+ */
+public class PeerModelAdapterFactory implements IAdapterFactory {
+ // The adapter list.
+ private static Class<?>[] adapters = {IPersistableElement.class};
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
+ */
+ @Override
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if(adaptableObject instanceof IPeerModel) {
+ IPeerModel peerModel = (IPeerModel) adaptableObject;
+ if(IPersistableElement.class.equals(adapterType)) {
+ return new PersistablePeerModel(peerModel);
+ }
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+ */
+ @Override
+ public Class[] getAdapterList() {
+ return adapters;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/adapters/PeerModelFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/adapters/PeerModelFactory.java
new file mode 100644
index 000000000..4a560efb5
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/adapters/PeerModelFactory.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.internal.adapters;
+
+import java.util.Map;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+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);
+ return map.get(peerId);
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/adapters/PersistablePeerModel.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/adapters/PersistablePeerModel.java
new file mode 100644
index 000000000..bbffbedcf
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/adapters/PersistablePeerModel.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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.internal.adapters;
+
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * The persistable element implementation for an IPeerModel.
+ */
+public class PersistablePeerModel implements IPersistableElement {
+ // The peer model to be persisted.
+ private IPeerModel peerModel;
+
+ /**
+ * Constructor
+ */
+ public PersistablePeerModel(IPeerModel peerModel) {
+ this.peerModel = peerModel;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public void saveState(IMemento memento) {
+ memento.putString("peerId", peerModel.getPeerId()); //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IPersistableElement#getFactoryId()
+ */
+ @Override
+ public String getFactoryId() {
+ return "org.eclipse.tcf.te.ui.views.peerFactory"; //$NON-NLS-1$
+ }
+}

Back to the top