summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-16 01:54:44 (EDT)
committerEike Stepper2007-07-16 01:54:44 (EDT)
commit3a0e48e40b977acc4a926166d545934e7f927bb5 (patch)
tree5b7c62cb846718b41b29044c7dcf6f55346001bf
parent8211c2e6149a8a09f5d5810c097e135fbdaa4c30 (diff)
downloadcdo-3a0e48e40b977acc4a926166d545934e7f927bb5.zip
cdo-3a0e48e40b977acc4a926166d545934e7f927bb5.tar.gz
cdo-3a0e48e40b977acc4a926166d545934e7f927bb5.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/HistoryCombo.java (renamed from plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/HistoryText.java)6
-rw-r--r--plugins/org.eclipse.net4j.util/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/History.java197
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/HistoryElement.java69
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/PreferenceHistory.java46
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryUtil.java35
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistory.java39
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryChangeEvent.java20
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryElement.java23
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ContainerUtil.java12
10 files changed, 446 insertions, 4 deletions
diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/HistoryText.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/HistoryCombo.java
index 92b1017..db74758 100644
--- a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/HistoryText.java
+++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/HistoryCombo.java
@@ -51,14 +51,14 @@ import org.eclipse.swt.widgets.Shell;
/**
* @author Eike Stepper
*/
-public class HistoryText extends Composite
+public class HistoryCombo extends Composite
{
private CCombo combo;
- public HistoryText(Composite parent, int style)
+ public HistoryCombo(Composite parent, int comboStyle)
{
super(parent, SWT.NONE);
- combo = new CCombo(this, style);
+ combo = new CCombo(this, comboStyle);
}
public CCombo getCombo()
diff --git a/plugins/org.eclipse.net4j.util/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.util/META-INF/MANIFEST.MF
index 41e1243..33b8887 100644
--- a/plugins/org.eclipse.net4j.util/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.util/META-INF/MANIFEST.MF
@@ -12,18 +12,21 @@ Import-Package: org.eclipse.core.runtime;resolution:=optional,
org.osgi.service.log;version="1.3.0";resolution:=optional,
org.osgi.util.tracker;version="1.3.0";resolution:=optional
Export-Package: org.eclipse.net4j.internal.util;version="0.8.0",
+ org.eclipse.net4j.internal.util.collection;version="0.8.0",
org.eclipse.net4j.internal.util.concurrent;version="0.8.0",
org.eclipse.net4j.internal.util.container;version="0.8.0",
org.eclipse.net4j.internal.util.container.delegate;version="0.8.0",
org.eclipse.net4j.internal.util.event;version="0.8.0",
org.eclipse.net4j.internal.util.factory;version="0.8.0",
org.eclipse.net4j.internal.util.lifecycle;version="0.8.0",
+ org.eclipse.net4j.internal.util.om;version="0.8.0",
org.eclipse.net4j.internal.util.om.log;version="0.8.0",
org.eclipse.net4j.internal.util.om.pref;version="0.8.0",
org.eclipse.net4j.internal.util.om.trace;version="0.8.0",
org.eclipse.net4j.internal.util.registry;version="0.8.0",
org.eclipse.net4j.internal.util.transaction;version="0.8.0",
org.eclipse.net4j.util;version="0.8.0",
+ org.eclipse.net4j.util.collection;version="0.8.0",
org.eclipse.net4j.util.concurrent;version="0.8.0",
org.eclipse.net4j.util.container;version="0.8.0",
org.eclipse.net4j.util.container.delegate;version="0.8.0",
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/History.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/History.java
new file mode 100644
index 0000000..50e08ef
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/History.java
@@ -0,0 +1,197 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.collection;
+
+import org.eclipse.net4j.internal.util.event.Notifier;
+import org.eclipse.net4j.util.collection.IHistory;
+import org.eclipse.net4j.util.collection.IHistoryChangeEvent;
+import org.eclipse.net4j.util.collection.IHistoryElement;
+import org.eclipse.net4j.util.event.INotifier;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public class History<T> extends Notifier implements IHistory<T>
+{
+ private List<IHistoryElement<T>> elements = new ArrayList(0);
+
+ private boolean loaded;
+
+ public History()
+ {
+ }
+
+ public List<IHistoryElement<T>> getElements()
+ {
+ lazyLoad();
+ return elements;
+ }
+
+ public void setElements(List<IHistoryElement<T>> newElements)
+ {
+ if (newElements == null)
+ {
+ newElements = new ArrayList(0);
+ }
+
+ if (!elements.equals(newElements))
+ {
+ elements = newElements;
+ changed();
+ }
+ }
+
+ public boolean isEmpty()
+ {
+ lazyLoad();
+ return elements.isEmpty();
+ }
+
+ public int size()
+ {
+ lazyLoad();
+ return elements.size();
+ }
+
+ public int indexOf(T data)
+ {
+ lazyLoad();
+ for (int i = 0; i < elements.size(); i++)
+ {
+ if (elements.get(i).getData().equals(data))
+ {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+ public IHistoryElement<T> get(int index)
+ {
+ lazyLoad();
+ return elements.get(index);
+ }
+
+ public boolean add(T data)
+ {
+ boolean changed = internalAdd(data);
+ if (changed)
+ {
+ changed();
+ }
+
+ return changed;
+ }
+
+ public IHistoryElement<T> remove(int index)
+ {
+ IHistoryElement<T> element = elements.remove(index);
+ if (element != null)
+ {
+ changed();
+ }
+
+ return element;
+ }
+
+ public boolean clear()
+ {
+ if (elements.isEmpty())
+ {
+ return false;
+ }
+
+ elements.clear();
+ changed();
+ return true;
+ }
+
+ public IHistoryElement<T>[] toArray()
+ {
+ lazyLoad();
+ return elements.toArray(new IHistoryElement[elements.size()]);
+ }
+
+ public T[] getData()
+ {
+ int size = elements.size();
+ Object[] array = new Object[size];
+ for (int i = 0; i < size; i++)
+ {
+ array[i] = elements.get(i).getData();
+ }
+
+ return (T[])array;
+ }
+
+ public Iterator<IHistoryElement<T>> iterator()
+ {
+ lazyLoad();
+ return elements.iterator();
+ }
+
+ public void dispose()
+ {
+ elements.clear();
+ }
+
+ protected IHistoryElement<T> createElement(T data)
+ {
+ return new HistoryElement(this, data);
+ }
+
+ protected void load()
+ {
+ }
+
+ protected void save()
+ {
+ }
+
+ protected final void changed()
+ {
+ save();
+ fireChangedEvent();
+ }
+
+ protected final boolean internalAdd(T data)
+ {
+ int index = indexOf(data);
+ IHistoryElement<T> element = index != -1 ? elements.remove(index) : createElement(data);
+ elements.add(0, element);
+ return index != 0;
+ }
+
+ private void lazyLoad()
+ {
+ if (!loaded)
+ {
+ loaded = true;
+ load();
+ }
+ }
+
+ private void fireChangedEvent()
+ {
+ fireEvent(new IHistoryChangeEvent()
+ {
+ public INotifier getSource()
+ {
+ return History.this;
+ }
+ });
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/HistoryElement.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/HistoryElement.java
new file mode 100644
index 0000000..268cb8c
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/HistoryElement.java
@@ -0,0 +1,69 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.collection;
+
+import org.eclipse.net4j.util.collection.IHistory;
+import org.eclipse.net4j.util.collection.IHistoryElement;
+
+/**
+ * @author Eike Stepper
+ */
+public class HistoryElement<T> implements IHistoryElement<T>
+{
+ private IHistory<IHistoryElement<T>> history;
+
+ private T data;
+
+ public HistoryElement(IHistory<IHistoryElement<T>> history, T data)
+ {
+ this.history = history;
+ this.data = data;
+ }
+
+ public IHistory getHistory()
+ {
+ return history;
+ }
+
+ public T getData()
+ {
+ return data;
+ }
+
+ public String getText()
+ {
+ return data.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof HistoryElement)
+ {
+ HistoryElement that = (HistoryElement)obj;
+ return this.history.equals(that.history) && this.data.equals(that.data);
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return history.hashCode() ^ data.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return getText();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/PreferenceHistory.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/PreferenceHistory.java
new file mode 100644
index 0000000..770ec23
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/PreferenceHistory.java
@@ -0,0 +1,46 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.collection;
+
+import org.eclipse.net4j.util.om.pref.OMPreference;
+
+/**
+ * @author Eike Stepper
+ */
+public class PreferenceHistory extends History<String>
+{
+ private OMPreference<String[]> preference;
+
+ public PreferenceHistory(OMPreference<String[]> preference)
+ {
+ this.preference = preference;
+ }
+
+ public OMPreference<String[]> getPreference()
+ {
+ return preference;
+ }
+
+ @Override
+ protected void load()
+ {
+ for (String data : preference.getValue())
+ {
+ internalAdd(data);
+ }
+ }
+
+ @Override
+ protected void save()
+ {
+ preference.setValue(getData());
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryUtil.java
new file mode 100644
index 0000000..8b6d8e5
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryUtil.java
@@ -0,0 +1,35 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.collection;
+
+import org.eclipse.net4j.internal.util.collection.History;
+import org.eclipse.net4j.internal.util.collection.PreferenceHistory;
+import org.eclipse.net4j.util.om.pref.OMPreference;
+
+/**
+ * @author Eike Stepper
+ */
+public final class HistoryUtil
+{
+ private HistoryUtil()
+ {
+ }
+
+ public static IHistory<String> createHistory()
+ {
+ return new History();
+ }
+
+ public static IHistory<String> createPreferenceHistory(OMPreference<String[]> preference)
+ {
+ return new PreferenceHistory(preference);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistory.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistory.java
new file mode 100644
index 0000000..3e05d75
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistory.java
@@ -0,0 +1,39 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.collection;
+
+import org.eclipse.net4j.util.event.INotifier;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IHistory<T> extends INotifier, Iterable<IHistoryElement<T>>
+{
+ public boolean isEmpty();
+
+ public int size();
+
+ public boolean clear();
+
+ public int indexOf(T data);
+
+ public boolean add(T data);
+
+ public IHistoryElement<T> remove(int index);
+
+ public IHistoryElement<T> get(int index);
+
+ public IHistoryElement<T>[] toArray();
+
+ public T[] getData();
+
+ public void dispose();
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryChangeEvent.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryChangeEvent.java
new file mode 100644
index 0000000..cc22465
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryChangeEvent.java
@@ -0,0 +1,20 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.collection;
+
+import org.eclipse.net4j.util.event.IEvent;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IHistoryChangeEvent extends IEvent
+{
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryElement.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryElement.java
new file mode 100644
index 0000000..a27af18
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryElement.java
@@ -0,0 +1,23 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.collection;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IHistoryElement<T>
+{
+ public IHistory getHistory();
+
+ public T getData();
+
+ public String getText();
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ContainerUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ContainerUtil.java
index 60010f2..de99b00 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ContainerUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ContainerUtil.java
@@ -21,7 +21,17 @@ public final class ContainerUtil
{
}
- public Object[] getElements(Object container)
+ public static boolean isEmpty(Object container)
+ {
+ if (container instanceof IContainer)
+ {
+ return ((IContainer)container).isEmpty();
+ }
+
+ return true;
+ }
+
+ public static Object[] getElements(Object container)
{
if (container instanceof IContainer)
{