Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarin Wright2008-01-29 11:40:35 -0500
committerDarin Wright2008-01-29 11:40:35 -0500
commit4b9dbb4d4b21576f44062ef9a12cd6495ee3755c (patch)
treecd34c5db4a55a5c8855029719d1a936777203a80
parent66fbc197a05c15c438887d40eeec73efefd59df1 (diff)
downloadeclipse.platform.debug-4b9dbb4d4b21576f44062ef9a12cd6495ee3755c.tar.gz
eclipse.platform.debug-4b9dbb4d4b21576f44062ef9a12cd6495ee3755c.tar.xz
eclipse.platform.debug-4b9dbb4d4b21576f44062ef9a12cd6495ee3755c.zip
Bug 213069 - Extend PresentationContext to save and restore properties
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/InternalTreeModelViewer.java16
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/PresentationContext.java93
2 files changed, 107 insertions, 2 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/InternalTreeModelViewer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/InternalTreeModelViewer.java
index 2aefae5b0..f57d42587 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/InternalTreeModelViewer.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/InternalTreeModelViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation and others.
+ * Copyright (c) 2006, 2008 IBM Corporation 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
@@ -809,6 +809,13 @@ public class InternalTreeModelViewer extends TreeViewer {
}
}
}
+ // save presentation context properties
+ IPresentationContext context = getPresentationContext();
+ if (context instanceof PresentationContext) {
+ PresentationContext pc = (PresentationContext) context;
+ pc.saveProperites(memento);
+
+ }
}
/**
@@ -863,6 +870,13 @@ public class InternalTreeModelViewer extends TreeViewer {
fColumnOrder.put(id, order);
}
}
+ // restore presentation context properties
+ // save presentation context properties
+ IPresentationContext context = getPresentationContext();
+ if (context instanceof PresentationContext) {
+ PresentationContext pc = (PresentationContext) context;
+ pc.initProperties(memento);
+ }
}
/**
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/PresentationContext.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/PresentationContext.java
index 368701179..3e5c190fd 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/PresentationContext.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/PresentationContext.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 IBM Corporation 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
@@ -7,17 +7,24 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Wind River Systems - added saving and restoring properties
*******************************************************************************/
package org.eclipse.debug.internal.ui.viewers.model.provisional;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.PlatformUI;
/**
* Presentation context.
@@ -28,6 +35,12 @@ import org.eclipse.jface.util.SafeRunnable;
*/
public class PresentationContext implements IPresentationContext {
+ private static final String PRESENTATION_CONTEXT_PROPERTIES = "PRESENTATION_CONTEXT_PROPERTIES"; //$NON-NLS-1$
+ private static final String BOOLEAN = "BOOLEAN"; //$NON-NLS-1$
+ private static final String STRING = "STRING"; //$NON-NLS-1$
+ private static final String INTEGER = "INTEGER"; //$NON-NLS-1$
+ private static final String PERSISTABLE = "PERSISTABLE"; //$NON-NLS-1$
+
private String fId;
private ListenerList fListeners = new ListenerList();
private Map fProperties = new HashMap();
@@ -131,6 +144,84 @@ public class PresentationContext implements IPresentationContext {
}
}
+ /**
+ * Restores the presentation context properties from the given memento.
+ * @param memento Memento to restore from.
+ */
+ public void initProperties(IMemento memento) {
+ IMemento presentationMemento = null;
+
+ IMemento[] mementos = memento.getChildren(PRESENTATION_CONTEXT_PROPERTIES);
+ for (int i = 0; i < mementos.length; i++) {
+ if (getId().equals(mementos[i].getID())) {
+ presentationMemento = mementos[i];
+ break;
+ }
+ }
+
+ if (presentationMemento != null) {
+ IMemento[] stringProperties = presentationMemento.getChildren(STRING);
+ for (int i = 0; i < stringProperties.length; i++) {
+ fProperties.put(stringProperties[i].getID(), stringProperties[i].getString(STRING));
+ }
+
+ IMemento[] integerMementos = presentationMemento.getChildren(INTEGER);
+ for (int i = 0; i < integerMementos.length; i++) {
+ fProperties.put(integerMementos[i].getID(), integerMementos[i].getInteger(INTEGER));
+ }
+
+ IMemento[] booleanMementos = presentationMemento.getChildren(BOOLEAN);
+ for (int i = 0; i < booleanMementos.length; i++) {
+ fProperties.put(booleanMementos[i].getID(), booleanMementos[i].getBoolean(BOOLEAN));
+ }
+
+ IMemento[] persistableMementos = presentationMemento.getChildren(PERSISTABLE);
+ for (int i = 0; i < persistableMementos.length; i++) {
+ String factoryID = persistableMementos[i].getString(PERSISTABLE);
+ if (factoryID != null) {
+ IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryID);
+ if (factory != null) {
+ Object element = factory.createElement(persistableMementos[i]);
+ if (element != null) {
+ fProperties.put(persistableMementos[i].getID(), element);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Saves the current presentation context properties to the given memento.
+ * @param memento Memento to save to.
+ */
+ public void saveProperites(IMemento memento) {
+ if (fProperties.size() == 0) {
+ return;
+ }
+
+ IMemento properties = memento.createChild(PRESENTATION_CONTEXT_PROPERTIES, getId());
+ Iterator iterator = fProperties.entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry entry = (Entry) iterator.next();
+ if (entry.getValue() instanceof String) {
+ IMemento value = properties.createChild(STRING, (String)entry.getKey());
+ value.putString(STRING, (String)entry.getValue());
+ } else if (entry.getValue() instanceof Integer) {
+ IMemento value = properties.createChild(INTEGER, (String)entry.getKey());
+ value.putInteger(INTEGER, ((Integer)entry.getValue()).intValue());
+ } else if (entry.getValue() instanceof Boolean) {
+ IMemento value = properties.createChild(BOOLEAN, (String)entry.getKey());
+ value.putBoolean(BOOLEAN, ((Boolean)entry.getValue()).booleanValue());
+ } else if (entry.getValue() instanceof IPersistableElement) {
+ IPersistableElement persistable = (IPersistableElement)entry.getValue();
+ IMemento value = properties.createChild(PERSISTABLE, (String)entry.getKey());
+ value.putString(PERSISTABLE, persistable.getFactoryId());
+ persistable.saveState(value);
+ }
+ }
+ }
+
private boolean isEqual(Object a, Object b) {
if (a == null) {
return b == null;

Back to the top