KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > databinding > provisional > viewers > ViewersObservableFactory


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jface.internal.databinding.provisional.viewers;
12
13 import org.eclipse.jface.internal.databinding.internal.viewers.AbstractListViewerObservableCollectionWithLabels;
14 import org.eclipse.jface.internal.databinding.internal.viewers.StructuredViewerObservableValue;
15 import org.eclipse.jface.internal.databinding.internal.viewers.TableViewerObservableCollectionWithLabels;
16 import org.eclipse.jface.internal.databinding.provisional.description.Property;
17 import org.eclipse.jface.internal.databinding.provisional.factories.IObservableFactory;
18 import org.eclipse.jface.internal.databinding.provisional.observable.IObservable;
19 import org.eclipse.jface.viewers.AbstractListViewer;
20 import org.eclipse.jface.viewers.StructuredViewer;
21 import org.eclipse.jface.viewers.TableViewer;
22
23 /**
24  * A factory that supports binding to JFace viewers. This factory supports the
25  * following description objects:
26  * <ul>
27  * <li>{@link AbstractListViewer} - denotes the viewer's collection of elements</li>
28  * <li>{@link TableViewerDescription} - TODO describe</li>
29  * <li>org.eclipse.jface.databinding.PropertyDescription - depending on the
30  * property description's object and property ID:
31  * <ul>
32  * <li>object instanceof StructuredViewer, property ID is
33  * ViewersProperties.SINGLE_SELECTION - denoting the viewer's (single) selection</li>
34  * <li>object instanceof TableViewer, property ID is ViewersProperties.CONTENT</li>
35  * <li>object instanceof AbstractListViewer, property ID is
36  * ViewersProperties.CONTENT</li>
37  * </ul>
38  * </li>
39  * </ul>
40  * TODO complete the list
41  *
42  * @since 1.0
43  *
44  */

45 final public class ViewersObservableFactory implements IObservableFactory {
46
47     /**
48      * Create a factory that can create udatables for JFace viewers
49      */

50     public ViewersObservableFactory() {
51     }
52
53     /**
54      * @param updateTime.
55      * Update policy of DataBindingContext.TIME_EARLY or TIME_LATE.
56      * This is only a hint that some editable viewers may support
57      */

58     public ViewersObservableFactory(int updateTime) {
59     }
60
61     public IObservable createObservable(Object JavaDoc description) {
62         if (description instanceof Property) {
63             Object JavaDoc object = ((Property) description).getObject();
64             Object JavaDoc attribute = ((Property) description).getPropertyID();
65             if (object instanceof StructuredViewer
66                     && ViewersProperties.SINGLE_SELECTION.equals(attribute)) {
67                 return new StructuredViewerObservableValue(
68                         (StructuredViewer) object, (String JavaDoc) attribute);
69             } else if (object instanceof AbstractListViewer
70                     && ViewersProperties.SINGLE_SELECTION.equals(attribute))
71                 return new StructuredViewerObservableValue(
72                         (AbstractListViewer) object, (String JavaDoc) attribute);
73             else if (object instanceof AbstractListViewer
74                     && ViewersProperties.CONTENT.equals(attribute))
75                 return new AbstractListViewerObservableCollectionWithLabels(
76                         (AbstractListViewer) object);
77             else if (object instanceof TableViewer
78                     && ViewersProperties.CONTENT.equals(attribute)) {
79                 return new TableViewerObservableCollectionWithLabels(
80                         (TableViewer) object);
81             }
82         } else if (description instanceof AbstractListViewer) {
83             return new AbstractListViewerObservableCollectionWithLabels(
84                     (AbstractListViewer) description);
85         } else if (description instanceof TableViewer) {
86             return new TableViewerObservableCollectionWithLabels(
87                     (TableViewer) description);
88         }
89         return null;
90     }
91 }
92
Popular Tags