*** empty log message ***
diff --git a/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/IWorkbenchConstants.java b/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/IWorkbenchConstants.java
index f5e0b06..68c7068 100644
--- a/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/IWorkbenchConstants.java
+++ b/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/IWorkbenchConstants.java
@@ -133,4 +133,7 @@
public static final String TAG_PERSISTABLE = "persistable"; //$NON-NLS-1$
public static final String TAG_MRU_LIST = "mruList"; //$NON-NLS-1$
public static final String TAG_PERSPECTIVE_HISTORY = "perspHistory"; //$NON-NLS-1$
+ public static final String TAG_WORKING_SETS = "workingSets"; //$NON-NLS-1$
+ public static final String TAG_WORKING_SET = "workingSet"; //$NON-NLS-1$
+ public static final String TAG_ITEM = "item"; //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/Workbench.java
index 67c43f3..90e8603 100644
--- a/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/Workbench.java
+++ b/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/Workbench.java
@@ -647,6 +647,14 @@
* @see IPersistable
*/
public void restoreState(IMemento memento) {
+ IMemento workingSetsMemento = memento.getChild(IWorkbenchConstants.TAG_WORKING_SETS); //$NON-NLS-1$
+ if (workingSetsMemento != null) {
+ IWorkingSetRegistry workingSetRegistry = WorkbenchPlugin.getDefault().getWorkingSetRegistry();
+ if (workingSetRegistry instanceof WorkingSetRegistry) {
+ ((WorkingSetRegistry) workingSetRegistry).restoreState(workingSetsMemento);
+ }
+ }
+
// Read perspective history.
// This must be done before we recreate the windows, because it is
// consulted during the recreation.
@@ -732,6 +740,11 @@
getEditorHistory().saveState(memento.createChild(IWorkbenchConstants.TAG_MRU_LIST)); //$NON-NLS-1$
// Save perspective history.
getPerspectiveHistory().saveState(memento.createChild(IWorkbenchConstants.TAG_PERSPECTIVE_HISTORY)); //$NON-NLS-1$
+
+ IWorkingSetRegistry workingSetRegistry = WorkbenchPlugin.getDefault().getWorkingSetRegistry();
+ if (workingSetRegistry instanceof WorkingSetRegistry) {
+ ((WorkingSetRegistry) workingSetRegistry).saveState(memento.createChild(IWorkbenchConstants.TAG_WORKING_SETS)); //$NON-NLS-1$
+ }
}
/**
* Save the workbench UI in a persistence file.
diff --git a/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/WorkingSet.java b/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/WorkingSet.java
index a913c10..1ce4293 100644
--- a/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/WorkingSet.java
+++ b/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/WorkingSet.java
@@ -4,17 +4,17 @@
*/
package org.eclipse.ui.internal;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.*;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.util.*;
-import org.eclipse.ui.IWorkingSet;
-import org.eclipse.ui.IWorkingSetRegistry;
+import org.eclipse.ui.*;
import org.eclipse.ui.internal.model.WorkbenchWorkingSet;
import org.eclipse.ui.model.IWorkbenchAdapter;
-public class WorkingSet implements IWorkingSet, IAdaptable {
+public class WorkingSet implements IWorkingSet, IAdaptable, IPersistableElement {
+ private static final String FACTORY_ID = "org.eclipse.ui.internal.WorkingSetFactory";//$NON-NLS-1$
+
String name;
Set items; // of IAdaptable
private ListenerList propertyChangeListeners = new ListenerList();
@@ -57,27 +57,37 @@
public IAdaptable[] getItems() {
return (IAdaptable[]) items.toArray(new IAdaptable[items.size()]);
}
+ public String getFactoryId() {
+ return FACTORY_ID;
+ }
public int hashCode() {
return name.hashCode();
}
public void removePropertyChangeListener(IPropertyChangeListener listener) {
propertyChangeListeners.remove(listener);
}
+ public void saveState(IMemento memento) {
+ Iterator iterator = items.iterator();
+
+ memento.putString(IWorkbenchConstants.TAG_NAME, name);
+ while (iterator.hasNext()) {
+ IAdaptable adaptable = (IAdaptable) iterator.next();
+ IPersistableElement persistable = (IPersistableElement) adaptable.getAdapter(IPersistableElement.class);
+ if (persistable != null) {
+ IMemento itemMemento = memento.createChild(IWorkbenchConstants.TAG_ITEM);
+
+ itemMemento.putString(IWorkbenchConstants.TAG_FACTORY_ID, persistable.getFactoryId());
+ persistable.saveState(itemMemento);
+ }
+ }
+ }
/*
* Public for use by org.eclipse.ui.internal.dialogs.WorkingSetDialog.
*/
public void setItems(IAdaptable[] elements) {
setItems(elements, false);
- saveWorkingSets();
firePropertyChange(CHANGE_WORKING_SET_CONTENT_CHANGE, this, this);
}
- private void saveWorkingSets() {
- IWorkingSetRegistry registry = WorkbenchPlugin.getDefault().getWorkingSetRegistry();
- if (registry instanceof WorkingSetRegistry) {
- ((WorkingSetRegistry) registry).saveWorkingSets();
- }
- }
-
private void setItems(IAdaptable[] elements, boolean internal) {
Assert.isNotNull(elements, "IPath array must not be null"); //$NON-NLS-1$
items = new HashSet(elements.length);
@@ -85,9 +95,6 @@
Assert.isTrue(!items.contains(elements[i]), "elements must only contain each element once"); //$NON-NLS-1$
items.add(elements[i]);
}
- if (!internal) {
- saveWorkingSets();
- }
}
/*
* Public for use by org.eclipse.ui.internal.dialogs.WorkingSetDialog.
@@ -95,7 +102,6 @@
public void setName(String name) {
Assert.isNotNull(name, "name must not be null"); //$NON-NLS-1$
this.name = name;
- saveWorkingSets();
firePropertyChange(CHANGE_WORKING_SET_NAME_CHANGE, this, this);
}
//--- Persistency -----------------------------------------------
diff --git a/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/WorkingSetFactory.java b/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/WorkingSetFactory.java
new file mode 100644
index 0000000..9f7fc82
--- /dev/null
+++ b/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/WorkingSetFactory.java
@@ -0,0 +1,55 @@
+package org.eclipse.ui.internal;
+
+/*
+ * (c) Copyright IBM Corp. 2002.
+ * All Rights Reserved.
+ */
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+
+/**
+ * The WorkingSetFactory is used to recreate a WorkingSet object.
+ *
+ * @see IElementFactory
+ */
+public class WorkingSetFactory implements IElementFactory {
+
+/**
+ * @see IElementFactory
+ */
+public IAdaptable createElement(IMemento memento) {
+ String workingSetName = memento.getString(IWorkbenchConstants.TAG_NAME);
+
+ if (workingSetName == null)
+ return null;
+
+ IMemento[] itemMementos = memento.getChildren(IWorkbenchConstants.TAG_ITEM);
+ Set items = new HashSet();
+ for (int i = 0; i < itemMementos.length; i ++) {
+ IMemento itemMemento = itemMementos[i];
+ String factoryID = itemMemento.getString(IWorkbenchConstants.TAG_FACTORY_ID);
+
+ if (factoryID == null) {
+ WorkbenchPlugin.log("Unable to restore working set item - no factory ID.");//$NON-NLS-1$
+ continue;
+ }
+ IElementFactory factory = WorkbenchPlugin.getDefault().getElementFactory(factoryID);
+ if (factory == null) {
+ WorkbenchPlugin.log("Unable to restore working set item - cannot instantiate factory: " + factoryID);//$NON-NLS-1$
+ continue;
+ }
+ IAdaptable item = factory.createElement(itemMemento);
+ if (item == null) {
+ WorkbenchPlugin.log("Unable to restore working set item - cannot instantiate item: " + factoryID);//$NON-NLS-1$
+ continue;
+ }
+ items.add(item);
+ }
+ WorkingSet workingSet = new WorkingSet(workingSetName, (IAdaptable[]) items.toArray(new IAdaptable[items.size()]));
+ return workingSet;
+}
+}
diff --git a/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/WorkingSetRegistry.java b/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/WorkingSetRegistry.java
index 0e6abe3..c502490 100644
--- a/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/WorkingSetRegistry.java
+++ b/bundles/org.eclipse.ui/Eclipse UI/org/eclipse/ui/internal/WorkingSetRegistry.java
@@ -44,7 +44,6 @@
public void add(IWorkingSet workingSet) {
Assert.isTrue(!workingSets.contains(workingSet), "working set already registered"); //$NON-NLS-1$
workingSets.add(workingSet);
- saveWorkingSets();
firePropertyChange(CHANGE_WORKING_SET_ADD, null, workingSet);
}
public void addPropertyChangeListener(IPropertyChangeListener listener) {
@@ -127,7 +126,6 @@
*/
public void remove(IWorkingSet workingSet) {
workingSets.remove(workingSet);
- saveWorkingSets();
firePropertyChange(CHANGE_WORKING_SET_REMOVE, workingSet, null);
}
@@ -160,58 +158,61 @@
}
- //--- Persistency -----------------------------------------------
+ //--- Persistence -----------------------------------------------
- private void restore() {
-/* WorkingSetReader reader = null;
- IWorkingSet[] workingSets = null;
- try {
- File file = SearchPlugin.getDefault().getStateLocation().append(STORE_NAME).toFile();
- if (!file.exists())
- return;
- reader = new WorkingSetReader(new BufferedInputStream(new FileInputStream(file)));
- workingSets = reader.readXML();
- } catch (IOException ex) {
- String message = WorkingSetMessages.getFormattedString("WorkingSet.error.readingFile", ex.getMessage()); //$NON-NLS-1$
- ExceptionHandler.log(ex, message);
- } catch (SAXException ex) {
- String message = WorkingSetMessages.getFormattedString("WorkingSet.error.badXmlFormat", ex.getMessage()); //$NON-NLS-1$
- ExceptionHandler.log(ex, message);
- } finally {
- try {
- if (reader != null)
- reader.close();
- } catch (IOException ex) {
- String message = WorkingSetMessages.getFormattedString("WorkingSet.error.close", ex.getMessage()); //$NON-NLS-1$
- ExceptionHandler.log(ex, message);
+ public void restoreState(IMemento memento) {
+ IMemento [] workingSets = memento.getChildren(IWorkbenchConstants.TAG_WORKING_SET);
+
+ for (int i = 0; i < workingSets.length; i ++) {
+ IMemento workingSetMemento = workingSets[i];
+ String factoryID = workingSetMemento.getString(IWorkbenchConstants.TAG_FACTORY_ID);
+
+ if (factoryID == null) {
+ WorkbenchPlugin.log("Unable to restore working set - no factory ID.");//$NON-NLS-1$
+ continue;
}
+ IElementFactory factory = WorkbenchPlugin.getDefault().getElementFactory(factoryID);
+ if (factory == null) {
+ WorkbenchPlugin.log("Unable to restore working set - cannot instantiate factory: " + factoryID);//$NON-NLS-1$
+ continue;
+ }
+ IAdaptable input = factory.createElement(workingSetMemento);
+ if (input == null) {
+ WorkbenchPlugin.log("Unable to restore working set - cannot instantiate working set: " + factoryID);//$NON-NLS-1$
+ continue;
+ }
+ if ((input instanceof IWorkingSet) == false) {
+ WorkbenchPlugin.log("Unable to restore working set - element is not an IWorkingSet: " + factoryID);//$NON-NLS-1$
+ continue;
+ }
+ add((IWorkingSet) input);
}
- if (workingSets != null)
- for (int i = 0; i < workingSets.length; i++)
- WorkingSet.add(workingSets[i]);*/
}
/*
* For use by WorkingSet#setName/#setItems
*/
- public void saveWorkingSets() {
-/* WorkingSetWriter writer = null;
- try {
- File file = SearchPlugin.getDefault().getStateLocation().append(STORE_NAME).toFile();
- writer = new WorkingSetWriter(new BufferedOutputStream(new FileOutputStream(file)));
- writer.writeXML(SearchUI.getWorkingSets());
- } catch (IOException ex) {
- String message = WorkingSetMessages.getFormattedString("WorkingSet.error.readingFile", ex.getMessage()); //$NON-NLS-1$
- ExceptionHandler.log(ex, message);
- } finally {
- if (writer != null)
- try {
- writer.close();
- } catch (IOException ex) {
- String message = WorkingSetMessages.getFormattedString("WorkingSet.error.readingFile", ex.getMessage()); //$NON-NLS-1$
- ExceptionHandler.log(ex, message);
- }
- }*/
+ public void saveState(IMemento memento) {
+ Iterator iterator = workingSets.iterator();
+
+ while (iterator.hasNext()) {
+ IWorkingSet workingSet = (IWorkingSet) iterator.next();
+ IPersistableElement persistable = null;
+
+ if (workingSet instanceof IPersistableElement) {
+ persistable = (IPersistableElement) workingSet;
+ }
+ else
+ if (workingSet instanceof IAdaptable) {
+ persistable = (IPersistableElement) ((IAdaptable) workingSet).getAdapter(IPersistableElement.class);
+ }
+ if (persistable != null) {
+ IMemento workingSetMemento = memento.createChild(IWorkbenchConstants.TAG_WORKING_SET);
+
+ workingSetMemento.putString(IWorkbenchConstants.TAG_FACTORY_ID, persistable.getFactoryId());
+ persistable.saveState(workingSetMemento);
+ }
+ }
}
/**
* @see IResourceDeltaVisitor#visit(IResourceDelta)
diff --git a/bundles/org.eclipse.ui/plugin.xml b/bundles/org.eclipse.ui/plugin.xml
index c0c3250..374e7dd 100644
--- a/bundles/org.eclipse.ui/plugin.xml
+++ b/bundles/org.eclipse.ui/plugin.xml
@@ -332,6 +332,10 @@
class="org.eclipse.ui.internal.dialogs.WelcomeEditorInputFactory"
id="org.eclipse.ui.internal.dialogs.WelcomeEditorInputFactory">
</factory>
+ <factory
+ class="org.eclipse.ui.internal.WorkingSetFactory"
+ id="org.eclipse.ui.internal.WorkingSetFactory">
+ </factory>
</extension>
<extension
point="org.eclipse.ui.markerUpdaters">