[Jiemamy-notify] commit [1950] [SPEC-9] の対応が必須。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 9月 24日 (水) 02:07:37 JST


Revision: 1950
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=jiemamy&view=rev&rev=1950
Author:   shin1
Date:     2008-09-24 02:07:37 +0900 (Wed, 24 Sep 2008)

Log Message:
-----------
[SPEC-9]の対応が必須。

Modified Paths:
--------------
    artemis/trunk/org.jiemamy.spec.event/META-INF/MANIFEST.MF

Added Paths:
-----------
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ModelChangeEvent.java
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ModelChangeListener.java
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/Observable.java
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ObservableCollectionChangeEvent.java
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ObservableCollectionChangeListener.java
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableList.java
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableMap.java
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableSet.java
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/model/
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/model/RootModelChangeListener.java
    artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/model/RootModelChangeSupport.java


-------------- next part --------------
Modified: artemis/trunk/org.jiemamy.spec.event/META-INF/MANIFEST.MF
===================================================================
--- artemis/trunk/org.jiemamy.spec.event/META-INF/MANIFEST.MF	2008-09-23 16:55:08 UTC (rev 1949)
+++ artemis/trunk/org.jiemamy.spec.event/META-INF/MANIFEST.MF	2008-09-23 17:07:37 UTC (rev 1950)
@@ -7,3 +7,4 @@
 Bundle-Vendor: Jiemamy Project
 Eclipse-BuddyPolicy: registered
 Eclipse-LazyStart: false
+Require-Bundle: org.jiemamy.spec.core

Added: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ModelChangeEvent.java
===================================================================
--- artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ModelChangeEvent.java	                        (rev 0)
+++ artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ModelChangeEvent.java	2008-09-23 17:07:37 UTC (rev 1950)
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. Created on 2008/06/09
+ * 
+ * This file is part of Jiemamy-core.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.jiemamy.spec.event;
+
+import java.lang.reflect.Field;
+import java.util.EventObject;
+
+/**
+ * モデル変更イベント。
+ * 
+ * DOCME JiemamyChangeEventみたいな名称が適切?(必ずしもModel用とは限らない?)
+ * 
+ * @author daisuke
+ */
+ @ SuppressWarnings("serial")
+public class ModelChangeEvent extends EventObject {
+	
+	/** 変更されたフィールド */
+	protected transient Field field;
+	
+
+	/**
+	 * コンストラクタ。
+	 * @category instance creation
+	 */
+	public ModelChangeEvent() {
+		super(null);
+	}
+	
+	/**
+	 * コンストラクタ。
+	 * @param source イベントが発生したオブジェクト
+	 * @param field 変更されたフィールド
+	 * @category instance creation
+	 */
+	public ModelChangeEvent(Observable source, Field field) {
+		super(source);
+		this.field = field;
+	}
+	
+	/**
+	 * 変更されたフィールドを取得する。
+	 * @return 変更されたフィールド
+	 */
+	public Field getField() {
+		return field;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public String toString() {
+		return getClass().getName() + "[source=" + source + ", field=" + field + "]";
+	}
+}


Property changes on: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ModelChangeEvent.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ModelChangeListener.java
===================================================================
--- artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ModelChangeListener.java	                        (rev 0)
+++ artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ModelChangeListener.java	2008-09-23 17:07:37 UTC (rev 1950)
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. Created on 2008/06/09
+ * 
+ * This file is part of Jiemamy-core.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.jiemamy.spec.event;
+
+import java.util.EventListener;
+
+/**
+ * モデルの変更に対するリスナ。
+ * 
+ * <p>{@link Observable}なインスタンスを監視することができる。</p>
+ * 
+ * @author daisuke
+ */
+public interface ModelChangeListener extends EventListener {
+	
+	/**
+	 * モデルのフィールドが変更された際にコールされるメソッド。
+	 * @param e 変更されたモデルとフィールドを表す{@link ModelChangeEvent}
+	 */
+	void modelChanged(ModelChangeEvent e);
+	
+}


Property changes on: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ModelChangeListener.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/Observable.java
===================================================================
--- artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/Observable.java	                        (rev 0)
+++ artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/Observable.java	2008-09-23 17:07:37 UTC (rev 1950)
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. Created on 2008/07/27
+ * 
+ * This file is part of Jiemamy.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.jiemamy.spec.event;
+
+import java.lang.reflect.Field;
+
+/**
+ * ModelChangeListenerが監視可能な対象を表現する。
+ * @author shin1
+ */
+public interface Observable {
+	
+	/**
+	 * モデルの変更リスナーを追加する。
+	 * @param listener 追加するリスナー
+	 */
+	void addModelChangeListener(ModelChangeListener listener);
+	
+	/**
+	 * リスナーにモデルの変更を通知する。
+	 * @param field 変更されたフィールド
+	 */
+	void fireModelChange(Field field);
+	
+	/**
+	 * モデルの変更リスナーを削除する。
+	 * @param listener 削除するリスナー
+	 */
+	void removeModelChangeListener(ModelChangeListener listener);
+}


Property changes on: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/Observable.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ObservableCollectionChangeEvent.java
===================================================================
--- artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ObservableCollectionChangeEvent.java	                        (rev 0)
+++ artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ObservableCollectionChangeEvent.java	2008-09-23 17:07:37 UTC (rev 1950)
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. Created on 2008/06/29
+ * 
+ * This file is part of Jiemamy.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.jiemamy.spec.event;
+
+import java.util.Collection;
+
+/**
+ * {@link Observable}のCollectionが発火する変更Event。
+ * @param <C> Collectionの実装Class (e.g. java.util.Map, java.util.List)
+ * @param <M> Collectionに保持するClass (e.g. AbstractColumnModel)
+ * @author shin1ogawa
+ */
+public class ObservableCollectionChangeEvent<C, M> {
+	
+	/** 発生したEventの種類 */
+	private Timing timing;
+	
+	/** Eventが発生した対象の{@link Collection} */
+	private C collection;
+	
+	/** {@link #collection}に対する操作が行われた{@link Observable} */
+	private M model;
+	
+	/** {@link #collection}に対する操作の対象Index */
+	private int index;
+	
+
+	/**
+	 * コンストラクタ。
+	 * @param timing イベントが発生したタイミングを表す
+	 * @param collection Eventが発生した対象の{@link Collection}
+	 * @param index {@link #collection}に対する操作の対象Index
+	 * @param model {@link #collection}に対する操作が行われた{@link Observable}
+	 * @category instance creation
+	 */
+	public ObservableCollectionChangeEvent(Timing timing, C collection, int index, M model) {
+		this.timing = timing;
+		this.collection = collection;
+		this.index = index;
+		this.model = model;
+	}
+	
+	/**
+	 * Eventが発生した対象の{@link Collection}を取得する。
+	 * @return Eventが発生した対象の{@link Collection}
+	 */
+	public C getCollection() {
+		return collection;
+	}
+	
+	/**
+	 * {@link #collection}に対する操作の対象Indexを取得する。
+	 * @return {@link #collection}に対する操作の対象Index
+	 */
+	public int getIndex() {
+		return index;
+	}
+	
+	/**
+	 * {@link #collection}に対する操作が行われた{@link Observable}を取得する。
+	 * @return {@link #collection}に対する操作が行われた{@link Observable}
+	 */
+	public M getModel() {
+		return model;
+	}
+	
+	/**
+	 * 発生したEventの種類を取得する。
+	 * @return 発生したEventの種類
+	 */
+	public Timing getTiming() {
+		return timing;
+	}
+	
+	/**
+	 * Eventが発生した対象の{@link Collection}を設定する。
+	 * @param collection Eventが発生した対象の{@link Collection}
+	 */
+	public void setCollection(C collection) {
+		this.collection = collection;
+	}
+	
+	/**
+	 * {@link #collection}に対する操作の対象Indexを設定する。
+	 * @param index {@link #collection}に対する操作の対象Index
+	 */
+	public void setIndex(int index) {
+		this.index = index;
+	}
+	
+	/**
+	 * {@link #collection}に対する操作が行われた{@link Observable}を設定する。
+	 * @param model {@link #collection}に対する操作が行われた{@link Observable}
+	 */
+	public void setModel(M model) {
+		this.model = model;
+	}
+	
+	/**
+	 * 発生したEventの種類を設定する。
+	 * @param timing 発生したEventの種類
+	 */
+	public void setTiming(Timing timing) {
+		this.timing = timing;
+	}
+	
+
+	/**
+	 * 発生したEventの種類。どのタイミングか?を意味する。
+	 * 
+	 * @see ObservableCollectionChangeEvent#getTiming()
+	 * @see ObservableCollectionChangeEvent#setTiming(org.jiemamy.spec.event.ObservableCollectionChangeEvent.Timing)
+	 * @author shin1ogawa
+	 */
+	public enum Timing {
+		/** 追加される前 */
+		BEFORE_ADD,
+
+		/** 追加された後 */
+		AFTER_ADD,
+
+		/** 削除される前 */
+		BEFORE_REMOVE,
+
+		/** 削除された後 */
+		AFTER_REMOVE,
+
+		/** 要素として保持しているModelの{@link ModelChangeEvent}を把握した */
+		COLLECTION_CHANGED,
+
+		/** 要素として保持しているModel自体が入れ替えられる前 */
+		BEFORE_SET,
+
+		/** 要素として保持しているModel自体が入れ替えられた後 */
+		AFTER_SET
+	}
+	
+}


Property changes on: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ObservableCollectionChangeEvent.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ObservableCollectionChangeListener.java
===================================================================
--- artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ObservableCollectionChangeListener.java	                        (rev 0)
+++ artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ObservableCollectionChangeListener.java	2008-09-23 17:07:37 UTC (rev 1950)
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. Created on 2008/06/29
+ * 
+ * This file is part of Jiemamy.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.jiemamy.spec.event;
+
+/**
+ * {@link Observable}のCollectionに対する変更のリスナ。
+ * @param <C> Listの実装Class
+ * @param <M> Listに保持するModelClass (ColumnModelなど)
+ * @author shin1ogawa
+ */
+public interface ObservableCollectionChangeListener<C, M> {
+	
+	/**
+	 * ModelのCollectionに対して何らかの操作が行われた事の通知。
+	 * @param event {@link ObservableCollectionChangeEvent}
+	 */
+	void collectionChanged(ObservableCollectionChangeEvent<C, M> event);
+}


Property changes on: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/ObservableCollectionChangeListener.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableList.java
===================================================================
--- artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableList.java	                        (rev 0)
+++ artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableList.java	2008-09-23 17:07:37 UTC (rev 1950)
@@ -0,0 +1,448 @@
+/*
+ * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. Created on 2008/06/29
+ * 
+ * This file is part of Jiemamy.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.jiemamy.spec.event.collectionimpl;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.jiemamy.spec.event.ModelChangeEvent;
+import org.jiemamy.spec.event.ModelChangeListener;
+import org.jiemamy.spec.event.Observable;
+import org.jiemamy.spec.event.ObservableCollectionChangeEvent;
+import org.jiemamy.spec.event.ObservableCollectionChangeListener;
+
+/**
+ * {@link ObservableCollectionChangeEvent}を通知する{@link List}の実装。。
+ * add/remove等の更新系メソッド全てで{@link ObservableCollectionChangeEvent}を通知する。
+ * また、保持する要素が{@link Observable}の場合は、要素の{@link ModelChangeEvent}も監視し、
+ * {@link ObservableCollectionChangeEvent}にラップして通知する。
+ * 
+ * @param <T> 保持する要素の型.
+ * @author shin1ogawa
+ */
+ @ SuppressWarnings("serial")
+public class ObservableList<T> extends AbstractList<T> implements List<T> {
+	
+	/**
+	 * Listの実装をdecorateした{@link ObservableList}を返す。
+	 * @param <T>
+	 * @param list
+	 * @return {@link ObservableList}
+	 */
+	public static <T>ObservableList<T> decorate(List<T> list) {
+		return new ObservableList<T>(list);
+	}
+	
+
+	private transient List<ObservableCollectionChangeListener<List<T>, T>> listeners =
+			new ArrayList<ObservableCollectionChangeListener<List<T>, T>>();
+	
+	private transient ModelChangeListener modelChangeListener;
+	
+	private List<T> list;
+	
+
+	/**
+	 * コンストラクタ。
+	 * Listの実装を指定しない場合は{@link java.util.ArrayList}を使用する。
+	 * @category instance creation
+	 */
+	public ObservableList() {
+		this.list = new ArrayList<T>();
+		modelChangeListener = new ModelChangeListenerImpl(this);
+	}
+	
+	/**
+	 * コンストラクタ。
+	 * @param list 使用するListの実装
+	 * @category instance creation
+	 */
+	public ObservableList(List<T> list) {
+		this.list = list;
+		modelChangeListener = new ModelChangeListenerImpl(this);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void add(int index, T element) {
+		fireChange(new ObservableCollectionChangeEvent<List<T>, T>(ObservableCollectionChangeEvent.Timing.BEFORE_ADD,
+				this, index, element));
+		list.add(index, element);
+		// 要素に対する監視を開始する。
+		if (element instanceof Observable) {
+			Observable observable = (Observable) element;
+			observable.addModelChangeListener(modelChangeListener);
+		}
+		fireChange(new ObservableCollectionChangeEvent<List<T>, T>(ObservableCollectionChangeEvent.Timing.AFTER_ADD,
+				this, index, element));
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public boolean add(T o) {
+		int index = list.size();
+		fireChange(new ObservableCollectionChangeEvent<List<T>, T>(ObservableCollectionChangeEvent.Timing.BEFORE_ADD,
+				this, index, o));
+		boolean result = list.add(o);
+		// 要素に対する監視を開始する。
+		if (o instanceof Observable) {
+			Observable observable = (Observable) o;
+			observable.addModelChangeListener(modelChangeListener);
+		}
+		fireChange(new ObservableCollectionChangeEvent<List<T>, T>(ObservableCollectionChangeEvent.Timing.AFTER_ADD,
+				this, index, o));
+		return result;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public boolean addAll(Collection<? extends T> c) {
+		if (c != null && c.size() > 0) {
+			// add(T)に展開する。
+			for (T element : c) {
+				add(element);
+			}
+			return true;
+		} else {
+			return false;
+		}
+	}
+	
+	/**
+	 * Listの実装のaddAll()を直接呼び出す訳ではなく、{@link #add(Object)}に展開する。
+	 * {@inheritDoc}
+	 */
+	@Override
+	public boolean addAll(int index, Collection<? extends T> collection) {
+		if (collection != null && collection.size() > 0) {
+			for (T element : collection) {
+				add(index++, element);
+			}
+			return true;
+		} else {
+			return false;
+		}
+	}
+	
+	/**
+	 * Eventを監視するListenerを追加する。
+	 * @param l {@link ObservableCollectionChangeListener}
+	 */
+	public void addListener(ObservableCollectionChangeListener<List<T>, T> l) {
+		// FIXME lazy instance creationせずに済む方法はないか?
+		if (listeners == null) {
+			listeners = new ArrayList<ObservableCollectionChangeListener<List<T>, T>>();
+		}
+		listeners.add(l);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void clear() {
+		int index = 0;
+		// Eventを通知するために一旦別のListへ格納し直す。
+		ArrayList<T> removedList = new ArrayList<T>(list.size());
+		Iterator<T> iterator = list.iterator();
+		while (iterator.hasNext()) {
+			T element = iterator.next();
+			fireChange(new ObservableCollectionChangeEvent<List<T>, T>(
+					ObservableCollectionChangeEvent.Timing.BEFORE_REMOVE, this, index, element));
+			removedList.add(element);
+			index++;
+		}
+		list.clear();
+		iterator = removedList.iterator();
+		index = 0;
+		while (iterator.hasNext()) {
+			T element = iterator.next();
+			fireChange(new ObservableCollectionChangeEvent<List<T>, T>(
+					ObservableCollectionChangeEvent.Timing.AFTER_REMOVE, this, index, element));
+			index++;
+		}
+		removedList.clear(); // 用済みなので破棄する。
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public boolean contains(Object o) {
+		return list.contains(o);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public boolean containsAll(Collection<?> c) {
+		return list.containsAll(c);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public T get(int index) {
+		return list.get(index);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public int indexOf(Object o) {
+		return list.indexOf(o);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public boolean isEmpty() {
+		return list.isEmpty();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public Iterator<T> iterator() {
+		return list.iterator();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public int lastIndexOf(Object o) {
+		return list.lastIndexOf(o);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public ListIterator<T> listIterator() {
+		return list.listIterator();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public ListIterator<T> listIterator(int index) {
+		return list.listIterator(index);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public T remove(int index) {
+		T element = list.get(index);
+		fireChange(new ObservableCollectionChangeEvent<List<T>, T>(
+				ObservableCollectionChangeEvent.Timing.BEFORE_REMOVE, this, index, element));
+		T result = list.remove(index);
+		// 要素に対する監視をやめる。
+		if (element instanceof Observable) {
+			((Observable) element).removeModelChangeListener(modelChangeListener);
+		}
+		fireChange(new ObservableCollectionChangeEvent<List<T>, T>(ObservableCollectionChangeEvent.Timing.AFTER_REMOVE,
+				this, index, result));
+		return result;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 * THINK 指定された要素の存在チェックは行わずにbeforeRemoveを発生させる事になるが?
+	 */
+	@Override
+	@SuppressWarnings("unchecked")
+	public boolean remove(Object o) {
+		int index = list.indexOf(o);
+		fireChange(new ObservableCollectionChangeEvent<List<T>, T>(
+				ObservableCollectionChangeEvent.Timing.BEFORE_REMOVE, this, index, (T) o));
+		boolean result = list.remove(o);
+		// 要素に対する監視をやめる。
+		if (o instanceof Observable) {
+			((Observable) o).removeModelChangeListener(modelChangeListener);
+		}
+		fireChange(new ObservableCollectionChangeEvent<List<T>, T>(ObservableCollectionChangeEvent.Timing.AFTER_REMOVE,
+				this, index, (T) o));
+		return result;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public boolean removeAll(Collection<?> c) {
+		List<Object> removeList = new ArrayList<Object>();
+		Iterator<?> iterator = iterator();
+		while (iterator.hasNext()) {
+			Object next = iterator.next();
+			if (c.contains(next)) {
+				removeList.add(next);
+			}
+		}
+		if (!removeList.isEmpty()) {
+			for (Object o : removeList) {
+				remove(o);
+			}
+			removeList.clear();
+			return true;
+		} else {
+			return false;
+		}
+	}
+	
+	/**
+	 * Eventの監視をやめたいListenerを削除する。
+	 * @param l
+	 */
+	public void removeListener(ObservableCollectionChangeListener<List<T>, T> l) {
+		listeners.remove(l);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public boolean retainAll(Collection<?> c) {
+		return list.retainAll(c);
+	}
+	
+	/**
+	 * {@link ObservableCollectionChangeEvent}は以下の法則で通知する。
+	 * <ol>
+	 * <li>BEFORE_SET:元々indexの位置に存在していた要素</li>
+	 * <li>AFTER_SET:新しくindexの位置に設定された要素</li>
+	 * </ol>
+	 * @see java.util.ArrayList#set(int, java.lang.Object)
+	 * @param index
+	 * @param element
+	 * @return T
+	 */
+	@Override
+	public T set(int index, T element) {
+		T oldElement = list.get(index);
+		fireChange(new ObservableCollectionChangeEvent<List<T>, T>(ObservableCollectionChangeEvent.Timing.BEFORE_SET,
+				this, index, oldElement));
+		T result = list.set(index, element);
+		fireChange(new ObservableCollectionChangeEvent<List<T>, T>(ObservableCollectionChangeEvent.Timing.AFTER_SET,
+				this, index, element));
+		return result;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public int size() {
+		return list.size();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public List<T> subList(int fromIndex, int toIndex) {
+		return list.subList(fromIndex, toIndex);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public Object[] toArray() {
+		return list.toArray();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public <U>U[] toArray(U[] a) {
+		return list.toArray(a);
+	}
+	
+	@Override
+	protected void removeRange(int fromIndex, int toIndex) {
+		for (int i = fromIndex; i <= toIndex; i++) {
+			// #remove(int)に展開する。
+			remove(i);
+		}
+	}
+	
+	/**
+	 * 全てのObserver({@link #listeners})に対してEventを通知する。
+	 * @param event
+	 */
+	private void fireChange(ObservableCollectionChangeEvent<List<T>, T> event) {
+		// FIXME lazy instance creationせずに済む方法はないか?
+		if (listeners == null) {
+			listeners = new ArrayList<ObservableCollectionChangeListener<List<T>, T>>();
+		}
+		
+		for (ObservableCollectionChangeListener<List<T>, T> listener : listeners) {
+			listener.collectionChanged(event);
+		}
+	}
+	
+
+	/**
+	 * 要素に対する変更を監視する。
+	 * Eventを受けた場合は<code>ModelCollectionChangeEvent.Timing.modelChanged</code>
+	 * という種類の{@link ModelChangeEvent}として通知する。
+	 * 
+	 * @author shin1ogawa
+	 */
+	class ModelChangeListenerImpl implements ModelChangeListener {
+		
+		private List<T> list;
+		
+
+		/**
+		 * コンストラクタ。
+		 * @param list
+		 * @category instance creation
+		 */
+		public ModelChangeListenerImpl(List<T> list) {
+			this.list = list;
+		}
+		
+		/**
+		 * {@inheritDoc}
+		 */
+		@SuppressWarnings("unchecked")
+		public void modelChanged(ModelChangeEvent e) {
+			int index = this.list.indexOf(e.getSource());
+			fireChange(new ObservableCollectionChangeEvent<List<T>, T>(
+					ObservableCollectionChangeEvent.Timing.COLLECTION_CHANGED, list, index, (T) e.getSource()));
+		}
+	}
+}


Property changes on: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableList.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableMap.java
===================================================================
--- artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableMap.java	                        (rev 0)
+++ artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableMap.java	2008-09-23 17:07:37 UTC (rev 1950)
@@ -0,0 +1,274 @@
+/*
+ * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others.
+ * Created on 2008/07/03
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.spec.event.collectionimpl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jiemamy.spec.event.ModelChangeEvent;
+import org.jiemamy.spec.event.ModelChangeListener;
+import org.jiemamy.spec.event.Observable;
+import org.jiemamy.spec.event.ObservableCollectionChangeEvent;
+import org.jiemamy.spec.event.ObservableCollectionChangeListener;
+
+/**
+ * {@link ObservableCollectionChangeEvent}を通知する{@link Map}の実装。。
+ * put/remove等の更新系メソッド全てで{@link ObservableCollectionChangeEvent}を通知する。
+ * また、保持する要素のModelChangeEventも把握し{@link ObservableCollectionChangeEvent}にラップして通知する。
+ * 
+ * @author shin1ogawa
+ * @param <K> Keyとして使用する型
+ * @param <V> Valueとして使用する型
+ */
+ @ SuppressWarnings("serial")
+public class ObservableMap<K, V> implements Map<K, V> {
+	
+	/**
+	 * Mapの実装をdecorateした{@link ObservableList}を返す。
+	 * @param <K>
+	 * @param <V>
+	 * @param map
+	 * @return {@link ObservableMap}
+	 */
+	public static <K, V>ObservableMap<K, V> decorate(Map<K, V> map) {
+		return new ObservableMap<K, V>(map);
+	}
+	
+
+	transient List<ObservableCollectionChangeListener<Map<K, V>, V>> listeners =
+			new ArrayList<ObservableCollectionChangeListener<Map<K, V>, V>>();
+	
+	transient ModelChangeListener modelChangeListener;
+	
+	private Map<K, V> map;
+	
+
+	/**
+	 * コンストラクタ。
+	 * Mapの実装を指定しない場合は{@link HashMap}を使用する。
+	 * @category instance creation
+	 */
+	public ObservableMap() {
+		this.map = new HashMap<K, V>();
+		modelChangeListener = new ModelChangeListenerImpl(this);
+	}
+	
+	/**
+	 * コンストラクタ。
+	 * @param map 使用するMapの実装
+	 * @category instance creation
+	 */
+	public ObservableMap(Map<K, V> map) {
+		this.map = map;
+		modelChangeListener = new ModelChangeListenerImpl(this);
+	}
+	
+	/**
+	 * Eventを監視するListenerを追加する。
+	 * @param l {@link ObservableCollectionChangeListener}
+	 */
+	public void addListener(ObservableCollectionChangeListener<Map<K, V>, V> l) {
+		// FIXME lazy instance creationせずに済む方法はないか?
+		if (listeners == null) {
+			listeners = new ArrayList<ObservableCollectionChangeListener<Map<K, V>, V>>();
+		}
+		listeners.add(l);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public void clear() {
+		ArrayList<V> removedList = new ArrayList<V>(size());
+		int index = 0;
+		for (V value : map.values()) {
+			fireChange(new ObservableCollectionChangeEvent<Map<K, V>, V>(
+					ObservableCollectionChangeEvent.Timing.BEFORE_REMOVE, this, index++, value));
+			removedList.add(value);
+		}
+		map.clear();
+		index = 0;
+		for (V value : removedList) {
+			fireChange(new ObservableCollectionChangeEvent<Map<K, V>, V>(
+					ObservableCollectionChangeEvent.Timing.AFTER_REMOVE, this, index++, value));
+			if (value instanceof Observable) {
+				Observable abstractModel = (Observable) value;
+				abstractModel.removeModelChangeListener(modelChangeListener);
+			}
+		}
+		removedList.clear();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean containsKey(Object key) {
+		return map.containsKey(key);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean containsValue(Object value) {
+		return map.containsValue(value);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public Set<java.util.Map.Entry<K, V>> entrySet() {
+		return map.entrySet();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public V get(Object key) {
+		return map.get(key);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean isEmpty() {
+		return map.isEmpty();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public Set<K> keySet() {
+		return map.keySet();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public V put(K key, V value) {
+		int index = size() - 1;
+		fireChange(new ObservableCollectionChangeEvent<Map<K, V>, V>(ObservableCollectionChangeEvent.Timing.BEFORE_ADD,
+				this, index, value));
+		V result = map.put(key, value);
+		if (value instanceof Observable) {
+			Observable abstractModel = (Observable) value;
+			abstractModel.addModelChangeListener(modelChangeListener);
+		}
+		fireChange(new ObservableCollectionChangeEvent<Map<K, V>, V>(ObservableCollectionChangeEvent.Timing.AFTER_ADD,
+				this, index, value));
+		return result;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public void putAll(Map<? extends K, ? extends V> m) {
+		// put(K, V)に展開する。
+		if (m != null && m.size() > 0) {
+			for (Map.Entry<? extends K, ? extends V> e : m.entrySet()) {
+				put(e.getKey(), e.getValue());
+			}
+		}
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public V remove(Object key) {
+//		int index = map.indexOf(key);
+		int index = -1;
+		fireChange(new ObservableCollectionChangeEvent<Map<K, V>, V>(
+				ObservableCollectionChangeEvent.Timing.BEFORE_REMOVE, this, index, get(key)));
+		V result = map.remove(key);
+		fireChange(new ObservableCollectionChangeEvent<Map<K, V>, V>(
+				ObservableCollectionChangeEvent.Timing.AFTER_REMOVE, this, index, result));
+		if (result instanceof Observable) {
+			Observable abstractModel = (Observable) result;
+			abstractModel.removeModelChangeListener(modelChangeListener);
+		}
+		return result;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public int size() {
+		return map.size();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public Collection<V> values() {
+		return map.values();
+	}
+	
+	/**
+	 * 全てのObserver({@link #listeners})に対してEventを通知する。
+	 * THINK かなり内部的なclassなので、このclassのfireChange()はprivateでも良いのではないか?
+	 * @param event
+	 */
+	private void fireChange(ObservableCollectionChangeEvent<Map<K, V>, V> event) {
+		// FIXME lazy instance creationせずに済む方法はないか?
+		if (listeners == null) {
+			listeners = new ArrayList<ObservableCollectionChangeListener<Map<K, V>, V>>();
+		}
+		for (ObservableCollectionChangeListener<Map<K, V>, V> listener : listeners) {
+			listener.collectionChanged(event);
+		}
+	}
+	
+
+	/**
+	 * 要素に対する変更を監視する。
+	 * Eventを受けた場合は<code>ModelCollectionChangeEvent.Timing.modelChanged</code>
+	 * という種類の{@link ModelChangeEvent}として通知する。
+	 * 
+	 * @author shin1ogawa
+	 */
+	class ModelChangeListenerImpl implements ModelChangeListener {
+		
+		Map<K, V> list;
+		
+
+		/**
+		 * コンストラクタ。
+		 * @param list
+		 * @category instance creation
+		 */
+		public ModelChangeListenerImpl(Map<K, V> list) {
+			this.list = list;
+		}
+		
+		/**
+		 * {@inheritDoc}
+		 */
+		@SuppressWarnings("unchecked")
+		public void modelChanged(ModelChangeEvent e) {
+//			int index = indexOf(e.getSource());
+			int index = -1;
+			fireChange(new ObservableCollectionChangeEvent<Map<K, V>, V>(
+					ObservableCollectionChangeEvent.Timing.COLLECTION_CHANGED, list, index, (V) e.getSource()));
+		}
+	}
+	
+}


Property changes on: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableMap.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableSet.java
===================================================================
--- artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableSet.java	                        (rev 0)
+++ artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableSet.java	2008-09-23 17:07:37 UTC (rev 1950)
@@ -0,0 +1,299 @@
+/*
+ * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others.
+ * Created on 2008/07/28
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.spec.event.collectionimpl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.jiemamy.spec.event.ModelChangeEvent;
+import org.jiemamy.spec.event.ModelChangeListener;
+import org.jiemamy.spec.event.Observable;
+import org.jiemamy.spec.event.ObservableCollectionChangeEvent;
+import org.jiemamy.spec.event.ObservableCollectionChangeListener;
+
+/**
+ * {@link ObservableCollectionChangeEvent}を通知する{@link java.util.Set}の実装。。
+ * add/remove等の更新系メソッド全てで{@link ObservableCollectionChangeEvent}を通知する。
+ * また、保持する要素が{@link Observable}の場合は、要素の{@link ModelChangeEvent}も監視し、
+ * {@link ObservableCollectionChangeEvent}にラップして通知する。
+ * 
+ * @param <T> 保持する要素の型.
+ * @author shin1ogawa
+ */
+public class ObservableSet<T> implements Set<T> {
+	
+	/**
+	 * Setの実装をdecorateした{@link ObservableSet}を返す。
+	 * @param <T>
+	 * @param set
+	 * @return {@link ObservableList}
+	 */
+	public static <T>ObservableSet<T> decorate(Set<T> set) {
+		return new ObservableSet<T>(set);
+	}
+	
+
+	private Set<T> set;
+	
+	private transient List<ObservableCollectionChangeListener<Set<T>, T>> listeners =
+			new ArrayList<ObservableCollectionChangeListener<Set<T>, T>>();
+	
+	private transient ModelChangeListener modelChangeListener;
+	
+
+	/**
+	 * コンストラクタ。
+	 * Setの実装を指定しない場合は{@link HashSet}を使用する。
+	 * @category instance creation
+	 */
+	public ObservableSet() {
+		this.set = new HashSet<T>();
+		modelChangeListener = new ModelChangeListenerImpl(this);
+	}
+	
+	/**
+	 * コンストラクタ。
+	 * @param set 使用するSetの実装
+	 * @category instance creation
+	 */
+	public ObservableSet(Set<T> set) {
+		this.set = set;
+		modelChangeListener = new ModelChangeListenerImpl(this);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean add(T o) {
+		int index = -1;
+		fireChange(new ObservableCollectionChangeEvent<Set<T>, T>(ObservableCollectionChangeEvent.Timing.BEFORE_ADD,
+				this, index, o));
+		// 要素に対する監視を開始する。
+		boolean result = set.add(o);
+		if (o instanceof Observable) {
+			Observable observable = (Observable) o;
+			observable.addModelChangeListener(modelChangeListener);
+		}
+		fireChange(new ObservableCollectionChangeEvent<Set<T>, T>(ObservableCollectionChangeEvent.Timing.AFTER_ADD,
+				this, index, o));
+		return result;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean addAll(Collection<? extends T> c) {
+		if (c != null && c.size() > 0) {
+			// add(T)に展開する。
+			for (T element : c) {
+				add(element);
+			}
+			return true;
+		} else {
+			return false;
+		}
+	}
+	
+	/**
+	 * Eventを監視するListenerを追加する。
+	 * @param l {@link ObservableCollectionChangeListener}
+	 */
+	public void addListener(ObservableCollectionChangeListener<Set<T>, T> l) {
+		listeners.add(l);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public void clear() {
+		int index = -1;
+		// Eventを通知するために一旦別のListへ格納し直す。
+		ArrayList<T> removedList = new ArrayList<T>(set.size());
+		Iterator<T> iterator = set.iterator();
+		while (iterator.hasNext()) {
+			T element = iterator.next();
+			fireChange(new ObservableCollectionChangeEvent<Set<T>, T>(
+					ObservableCollectionChangeEvent.Timing.BEFORE_REMOVE, this, index, element));
+			removedList.add(element);
+		}
+		set.clear();
+		iterator = removedList.iterator();
+		index = 0;
+		while (iterator.hasNext()) {
+			T element = iterator.next();
+			fireChange(new ObservableCollectionChangeEvent<Set<T>, T>(
+					ObservableCollectionChangeEvent.Timing.AFTER_REMOVE, this, index, element));
+			index++;
+		}
+		removedList.clear(); // 用済みなので破棄する。
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean contains(Object o) {
+		return set.contains(o);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean containsAll(Collection<?> c) {
+		return set.containsAll(c);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean isEmpty() {
+		return set.isEmpty();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public Iterator<T> iterator() {
+		return set.iterator();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@SuppressWarnings("unchecked")
+	public boolean remove(Object o) {
+		int index = -1;
+		fireChange(new ObservableCollectionChangeEvent<Set<T>, T>(ObservableCollectionChangeEvent.Timing.BEFORE_REMOVE,
+				this, index, (T) o));
+		boolean result = set.remove(o);
+		// 要素に対する監視をやめる。
+		if (o instanceof Observable) {
+			Observable observable = (Observable) o;
+			observable.removeModelChangeListener(modelChangeListener);
+		}
+		fireChange(new ObservableCollectionChangeEvent<Set<T>, T>(ObservableCollectionChangeEvent.Timing.AFTER_REMOVE,
+				this, index, (T) o));
+		return result;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean removeAll(Collection<?> c) {
+		List<Object> removeList = new ArrayList<Object>();
+		Iterator<?> iterator = iterator();
+		while (iterator.hasNext()) {
+			Object next = iterator.next();
+			if (c.contains(next)) {
+				removeList.add(next);
+			}
+		}
+		if (!removeList.isEmpty()) {
+			for (Object o : removeList) {
+				remove(o);
+			}
+			removeList.clear();
+			return true;
+		} else {
+			return false;
+		}
+	}
+	
+	/**
+	 * Eventの監視をやめたいListenerを削除する。
+	 * @param l
+	 */
+	public void removeListener(ObservableCollectionChangeListener<Set<T>, T> l) {
+		listeners.remove(l);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean retainAll(Collection<?> c) {
+		return set.retainAll(c);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public int size() {
+		return set.size();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public Object[] toArray() {
+		return set.toArray();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public <U>U[] toArray(U[] a) {
+		return set.toArray(a);
+	}
+	
+	/**
+	 * 全てのObserver({@link #listeners})に対してEventを通知する。
+	 * @param event
+	 */
+	private void fireChange(ObservableCollectionChangeEvent<Set<T>, T> event) {
+		for (ObservableCollectionChangeListener<Set<T>, T> listener : listeners) {
+			listener.collectionChanged(event);
+		}
+	}
+	
+
+	/**
+	 * 要素に対する変更を監視する。
+	 * Eventを受けた場合は<code>ModelCollectionChangeEvent.Timing.modelChanged</code>
+	 * という種類の{@link ModelChangeEvent}として通知する。
+	 * 
+	 * @author shin1ogawa
+	 */
+	class ModelChangeListenerImpl implements ModelChangeListener {
+		
+		private Set<T> set;
+		
+
+		/**
+		 * コンストラクタ。
+		 * @param set
+		 * @category instance creation
+		 */
+		public ModelChangeListenerImpl(Set<T> set) {
+			this.set = set;
+		}
+		
+		/**
+		 * {@inheritDoc}
+		 */
+		@SuppressWarnings("unchecked")
+		public void modelChanged(ModelChangeEvent e) {
+			int index = -1;
+			fireChange(new ObservableCollectionChangeEvent<Set<T>, T>(
+					ObservableCollectionChangeEvent.Timing.COLLECTION_CHANGED, set, index, (T) e.getSource()));
+		}
+	}
+}


Property changes on: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/collectionimpl/ObservableSet.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/model/RootModelChangeListener.java
===================================================================
--- artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/model/RootModelChangeListener.java	                        (rev 0)
+++ artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/model/RootModelChangeListener.java	2008-09-23 17:07:37 UTC (rev 1950)
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. Created on 2008/06/29
+ * 
+ * This file is part of Jiemamy.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.jiemamy.spec.event.model;
+
+import java.util.List;
+
+import org.jiemamy.spec.event.ObservableCollectionChangeEvent;
+import org.jiemamy.spec.model.DomainModel;
+import org.jiemamy.spec.model.RootModel;
+import org.jiemamy.spec.model.dataset.InsertDataSetModel;
+import org.jiemamy.spec.model.presentation.DiagramPresentationModel;
+import org.jiemamy.spec.util.ModelChangeListener;
+
+/**
+ * RootModel用のListener
+ * 
+ * @author shin1ogawa
+ */
+public interface RootModelChangeListener extends ModelChangeListener {
+	
+	/**
+	 * {@link RootModel}が保持する{@link DiagramPresentationModel}のCollectionに対する変更を処理する。
+	 * 
+	 * @param event
+	 */
+	void diagramPresentationCollectionChange(
+			ObservableCollectionChangeEvent<List<DiagramPresentationModel>, DiagramPresentationModel> event);
+	
+	/**
+	 * {@link RootModel}が保持する{@link DomainModel}のCollectionに対する変更を処理する。
+	 * 
+	 * @param event
+	 */
+	void domainCollectionChange(ObservableCollectionChangeEvent<List<DomainModel>, DomainModel> event);
+	
+	/**
+	 * {@link RootModel}が保持する{@link InsertDataSetModel}のCollectionに対する変更を処理する。
+	 * 
+	 * @param event
+	 */
+	void insertDataSetCollectionChange(
+			ObservableCollectionChangeEvent<List<InsertDataSetModel>, InsertDataSetModel> event);
+	
+}


Property changes on: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/model/RootModelChangeListener.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/model/RootModelChangeSupport.java
===================================================================
--- artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/model/RootModelChangeSupport.java	                        (rev 0)
+++ artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/model/RootModelChangeSupport.java	2008-09-23 17:07:37 UTC (rev 1950)
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. Created on 2008/07/02
+ * 
+ * This file is part of Jiemamy.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.jiemamy.spec.event.model;
+
+
+/**
+ * Event関連の処理をModel内に直接記述するとModelのSourceの可読性が低くなるため、RootModelからそれらを引き受ける。
+ * 
+ * @author shin1ogawa
+ */
+public interface RootModelChangeSupport {
+	
+	/**
+	 * RootModel自身のEventを監視するListenerを追加する。
+	 * 
+	 * @param l {@link RootModelChangeListener}
+	 * @see #removeRootModelChangeListener(RootModelChangeListener)
+	 */
+	void addRootModelChangeListener(RootModelChangeListener l);
+	
+	/**
+	 * RootModel自身のEventを監視するListenerを削除する。
+	 * 
+	 * @param l {@link RootModelChangeListener}
+	 * @see #addRootModelChangeListener(RootModelChangeListener)
+	 */
+	void removeRootModelChangeListener(RootModelChangeListener l);
+}


Property changes on: artemis/trunk/org.jiemamy.spec.event/src/main/java/org/jiemamy/spec/event/model/RootModelChangeSupport.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain


Jiemamy-notify メーリングリストの案内
Back to archive index