# HG changeset patch # User Frank Benoit # Date 1240419566 -7200 # Node ID 5d5bd660917fdee0667047d043f06e797e10433f # Parent 48d4ee62686853b09d60fbf851ac8dd801264665 build some databind snippets diff -r 48d4ee626868 -r 5d5bd660917f base/src/java/lang/Character.d --- a/base/src/java/lang/Character.d Wed Apr 22 07:30:21 2009 +0200 +++ b/base/src/java/lang/Character.d Wed Apr 22 18:59:26 2009 +0200 @@ -32,6 +32,18 @@ } return toUpperCase( darr[0] ); } + public static String toString(char c){ + implMissing(__FILE__, __LINE__ ); + return null; + } + public static String toString(wchar c){ + implMissing(__FILE__, __LINE__ ); + return null; + } + public static String toString(dchar c){ + implMissing(__FILE__, __LINE__ ); + return null; + } public static dchar toUpperCase( dchar c ){ version(Tango){ dchar[1] src; diff -r 48d4ee626868 -r 5d5bd660917f base/src/java/lang/Long.d --- a/base/src/java/lang/Long.d Wed Apr 22 07:30:21 2009 +0200 +++ b/base/src/java/lang/Long.d Wed Apr 22 18:59:26 2009 +0200 @@ -1,6 +1,7 @@ module java.lang.Long; import java.lang.util; +import java.lang.exceptions; import java.lang.Number; import java.lang.Class; @@ -40,8 +41,20 @@ return cast(double)value; } public static long parseLong(String s){ - implMissing( __FILE__, __LINE__ ); - return 0; + return parseLong( s, 10 ); + } + public static long parseLong(String s, int radix){ + version(Tango){ + try{ + return tango.text.convert.Integer.toLong( s, radix ); + } + catch( IllegalArgumentException e ){ + throw new NumberFormatException( e ); + } + } else { // Phobos + implMissing( __FILE__, __LINE__ ); + return 0; + } } public static String toString( double value ){ implMissing( __FILE__, __LINE__ ); diff -r 48d4ee626868 -r 5d5bd660917f base/src/java/lang/ThreadLocal.d --- a/base/src/java/lang/ThreadLocal.d Wed Apr 22 07:30:21 2009 +0200 +++ b/base/src/java/lang/ThreadLocal.d Wed Apr 22 18:59:26 2009 +0200 @@ -1,20 +1,22 @@ module java.lang.ThreadLocal; import java.lang.util; +static import tango.core.Thread; + class ThreadLocal{ + alias tango.core.Thread.ThreadLocal!(Object) TLSType; + TLSType tls; this(){ - implMissing(__FILE__, __LINE__); + tls = new TLSType( initialValue() ); } Object get(){ - implMissing(__FILE__, __LINE__); - return null; + return tls.val(); } protected Object initialValue(){ - implMissing(__FILE__, __LINE__); return null; } void set(Object value){ - implMissing(__FILE__, __LINE__); + return tls.val( value ); } } diff -r 48d4ee626868 -r 5d5bd660917f base/src/java/math/BigInteger.d --- a/base/src/java/math/BigInteger.d Wed Apr 22 07:30:21 2009 +0200 +++ b/base/src/java/math/BigInteger.d Wed Apr 22 18:59:26 2009 +0200 @@ -35,6 +35,7 @@ bi = BigInt( val ); } this(String val, int radix){ + getDwtLogger.error( __FILE__, __LINE__, "this({}, {})", val, radix ); if( radix is 10 ){ bi = BigInt( val ); } @@ -46,12 +47,15 @@ } } private this( BigInt v ){ + getDwtLogger.error( __FILE__, __LINE__, "this({})", v.toHex ); bi = v; } private this( BigInteger v ){ + getDwtLogger.error( __FILE__, __LINE__, "this({})", bi.toHex ); bi = v.bi; } private this( long v ){ + getDwtLogger.error( __FILE__, __LINE__, "this({})", v ); bi = BigInt(v); } BigInteger abs(){ @@ -75,6 +79,7 @@ return 0; } int bitLength(){ + getDwtLogger.error( __FILE__, __LINE__, "bitLength()" ); //implMissing(__FILE__, __LINE__ ); return 0; } @@ -135,8 +140,39 @@ return 0; } long longValue(){ - implMissing(__FILE__, __LINE__ ); - return 0; + getDwtLogger.error( __FILE__, __LINE__, "{}", bi.toHex ); + long res = 0; + auto txt = bi.toHex; + bool sign = false; + if( txt[0] is '-' ){ + sign = true; + txt = txt[1 .. $]; + } + int nibbles = 0; + foreach( uint idx, char c; txt ){ + if( c is '_' ) continue; + void addNibble( int v ){ + res <<= 4; + res |= v; + nibbles++; + } + if( c >= '0' && c <= '9' ) { + addNibble( c - '0' ); + } + else if( c >= 'a' && c <= 'f' ) { + addNibble( c - 'a' + 10 ); + } + else if( c >= 'A' && c <= 'F' ) { + addNibble( c - 'A' + 10 ); + } + else{ + getDwtLogger.error( __FILE__, __LINE__, "unknown char {} @{}", c, idx ); + } + } + if( nibbles > 16 ){ + getDwtLogger.error( __FILE__, __LINE__, "too much nibbles {}", nibbles ); + } + return res; } BigInteger max(BigInteger val){ implMissing(__FILE__, __LINE__ ); @@ -159,6 +195,7 @@ return null; } BigInteger multiply(BigInteger val){ + getDwtLogger.error( __FILE__, __LINE__, "multiply ({})", val.bi.toHex ); auto res = new BigInteger(this); res.bi *= val.bi; return res; diff -r 48d4ee626868 -r 5d5bd660917f base/src/java/text/AttributedCharacterIterator.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/src/java/text/AttributedCharacterIterator.d Wed Apr 22 18:59:26 2009 +0200 @@ -0,0 +1,54 @@ +module java.text.AttributedCharacterIterator; + +import java.text.CharacterIterator; +import java.util.Set; +import java.util.Map; +import java.lang.all; + +interface AttributedCharacterIterator : CharacterIterator { + static class Attribute { + static AttributedCharacterIterator.Attribute INPUT_METHOD_SEGMENT; + static AttributedCharacterIterator.Attribute LANGUAGE; + static AttributedCharacterIterator.Attribute READING; + + protected this(String name){ + implMissing(__FILE__, __LINE__); + } + + override equals_t opEquals(Object obj){ + implMissing(__FILE__, __LINE__); + return false; + } + + protected String getName(){ + implMissing(__FILE__, __LINE__); + return null; + } + + override hash_t toHash(){ + implMissing(__FILE__, __LINE__); + return 0; + } + + protected Object readResolve(){ + implMissing(__FILE__, __LINE__); + return null; + } + + String toString(){ + implMissing(__FILE__, __LINE__); + return null; + } + + } + Set getAllAttributeKeys(); + Object getAttribute(AttributedCharacterIterator.Attribute attribute); + Map getAttributes(); + int getRunLimit(); + int getRunLimit(AttributedCharacterIterator.Attribute attribute); + int getRunLimit(Set attributes); + int getRunStart(); + int getRunStart(AttributedCharacterIterator.Attribute attribute); + int getRunStart(Set attributes); +} + diff -r 48d4ee626868 -r 5d5bd660917f base/src/java/text/FieldPosition.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/src/java/text/FieldPosition.d Wed Apr 22 18:59:26 2009 +0200 @@ -0,0 +1,55 @@ +module java.text.FieldPosition; + +import java.lang.all; +// FIXME see dmd bug 2878 +//import java.text.Format; + +class FieldPosition { + //this(java.text.Format.Format.Field attribute){ + // implMissing(__FILE__, __LINE__); + //} + + //this(java.text.Format.Format.Field attribute, int fieldID){ + // implMissing(__FILE__, __LINE__); + //} + + this(int field){ + implMissing(__FILE__, __LINE__); + } + + override equals_t opEquals(Object obj){ + implMissing(__FILE__, __LINE__); + return false; + } + int getBeginIndex(){ + implMissing(__FILE__, __LINE__); + return 0; + } + int getEndIndex(){ + implMissing(__FILE__, __LINE__); + return 0; + } + int getField(){ + implMissing(__FILE__, __LINE__); + return 0; + } + //java.text.Format.Format.Field getFieldAttribute(){ + // implMissing(__FILE__, __LINE__); + // return null; + //} + override hash_t toHash(){ + implMissing(__FILE__, __LINE__); + return 0; + } + void setBeginIndex(int bi){ + implMissing(__FILE__, __LINE__); + } + void setEndIndex(int ei){ + implMissing(__FILE__, __LINE__); + } + String toString(){ + implMissing(__FILE__, __LINE__); + return null; + } +} + diff -r 48d4ee626868 -r 5d5bd660917f base/src/java/text/Format.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/src/java/text/Format.d Wed Apr 22 18:59:26 2009 +0200 @@ -0,0 +1,37 @@ +module java.text.Format; + +import java.lang.all; +import java.text.FieldPosition; +import java.text.AttributedCharacterIterator; +import java.text.ParsePosition; + +class Format { + static class Field{ + protected this( String name ){ + implMissing(__FILE__, __LINE__); + } + } + this(){ + implMissing(__FILE__, __LINE__); + } + Object clone(){ + implMissing(__FILE__, __LINE__); + return null; + } + String format(Object obj){ + implMissing(__FILE__, __LINE__); + return null; + } + abstract StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos); + AttributedCharacterIterator formatToCharacterIterator(Object obj){ + implMissing(__FILE__, __LINE__); + return null; + } + Object parseObject(String source){ + implMissing(__FILE__, __LINE__); + return null; + } + abstract Object parseObject(String source, ParsePosition pos); + +} + diff -r 48d4ee626868 -r 5d5bd660917f base/src/java/text/MessageFormat.d --- a/base/src/java/text/MessageFormat.d Wed Apr 22 07:30:21 2009 +0200 +++ b/base/src/java/text/MessageFormat.d Wed Apr 22 18:59:26 2009 +0200 @@ -1,16 +1,17 @@ module java.text.MessageFormat; import java.lang.all; +import java.text.Format; -class MessageFormat { +class MessageFormat : java.text.Format.Format { public static String format( String frmt, Object[] args... ){ switch( args.length ){ - case 0: return Format(frmt); - case 1: return Format(frmt, args[0]); - case 2: return Format(frmt, args[0], args[1]); - case 3: return Format(frmt, args[0], args[1], args[2]); - case 4: return Format(frmt, args[0], args[1], args[2], args[3]); - case 5: return Format(frmt, args[0], args[1], args[2], args[3], args[4]); + case 0: return java.lang.util.Format(frmt); + case 1: return java.lang.util.Format(frmt, args[0]); + case 2: return java.lang.util.Format(frmt, args[0], args[1]); + case 3: return java.lang.util.Format(frmt, args[0], args[1], args[2]); + case 4: return java.lang.util.Format(frmt, args[0], args[1], args[2], args[3]); + case 5: return java.lang.util.Format(frmt, args[0], args[1], args[2], args[3], args[4]); default: implMissing(__FILE__, __LINE__ ); } diff -r 48d4ee626868 -r 5d5bd660917f base/src/java/text/NumberFormat.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/src/java/text/NumberFormat.d Wed Apr 22 18:59:26 2009 +0200 @@ -0,0 +1,214 @@ +module java.text.NumberFormat; + +import java.lang.all; +import java.text.Format; +import java.text.FieldPosition; +import java.text.ParsePosition; +import java.util.Locale; +import java.util.Currency; + +class NumberFormat : java.text.Format.Format { + static int FRACTION_FIELD; + static int INTEGER_FIELD; + + static class Field : java.text.Format.Format.Field { + static NumberFormat.Field CURRENCY; + static NumberFormat.Field DECIMAL_SEPARATOR; + static NumberFormat.Field EXPONENT; + static NumberFormat.Field EXPONENT_SIGN; + static NumberFormat.Field EXPONENT_SYMBOL; + static NumberFormat.Field FRACTION; + static NumberFormat.Field GROUPING_SEPARATOR; + static NumberFormat.Field INTEGER; + static NumberFormat.Field PERCENT; + static NumberFormat.Field PERMILLE; + static NumberFormat.Field SIGN; + protected this(String name){ + implMissing(__FILE__, __LINE__); + super(name); + } + protected Object readResolve(){ + implMissing(__FILE__, __LINE__); + return null; + } + + } + + this(){ + implMissing(__FILE__, __LINE__); + } + + Object clone(){ + implMissing(__FILE__, __LINE__); + return null; + } + + bool equals(Object obj){ + implMissing(__FILE__, __LINE__); + return false; + } + + String format(double number){ + implMissing(__FILE__, __LINE__); + return null; + } + + abstract StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos){ + implMissing(__FILE__, __LINE__); + return null; + } + + String format(long number){ + implMissing(__FILE__, __LINE__); + return null; + } + + abstract StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos){ + implMissing(__FILE__, __LINE__); + return null; + } + + StringBuffer format(Object number, StringBuffer toAppendTo, FieldPosition pos){ + implMissing(__FILE__, __LINE__); + return null; + } + + static Locale[] getAvailableLocales(){ + implMissing(__FILE__, __LINE__); + return null; + } + + Currency getCurrency(){ + implMissing(__FILE__, __LINE__); + return null; + } + + static NumberFormat getCurrencyInstance(){ + implMissing(__FILE__, __LINE__); + return null; + } + + static NumberFormat getCurrencyInstance(Locale inLocale){ + implMissing(__FILE__, __LINE__); + return null; + } + + static NumberFormat getInstance(){ + implMissing(__FILE__, __LINE__); + return null; + } + static NumberFormat getInstance(Locale inLocale){ + implMissing(__FILE__, __LINE__); + return null; + } + + static NumberFormat getIntegerInstance(){ + implMissing(__FILE__, __LINE__); + return null; + } + + static NumberFormat getIntegerInstance(Locale inLocale){ + implMissing(__FILE__, __LINE__); + return null; + } + + int getMaximumFractionDigits(){ + implMissing(__FILE__, __LINE__); + return 0; + } + + int getMaximumIntegerDigits(){ + implMissing(__FILE__, __LINE__); + return 0; + } + + int getMinimumFractionDigits(){ + implMissing(__FILE__, __LINE__); + return 0; + } + + int getMinimumIntegerDigits(){ + implMissing(__FILE__, __LINE__); + return 0; + } + + static NumberFormat getNumberInstance(){ + implMissing(__FILE__, __LINE__); + return null; + } + + static NumberFormat getNumberInstance(Locale inLocale){ + implMissing(__FILE__, __LINE__); + return null; + } + + static NumberFormat getPercentInstance(){ + implMissing(__FILE__, __LINE__); + return null; + } + + static NumberFormat getPercentInstance(Locale inLocale){ + implMissing(__FILE__, __LINE__); + return null; + } + + int hashCode(){ + implMissing(__FILE__, __LINE__); + return 0; + } + + bool isGroupingUsed(){ + implMissing(__FILE__, __LINE__); + return false; + } + + bool isParseIntegerOnly(){ + implMissing(__FILE__, __LINE__); + return false; + } + + Number parse(String source){ + implMissing(__FILE__, __LINE__); + return null; + } + + abstract Number parse(String source, ParsePosition parsePosition){ + implMissing(__FILE__, __LINE__); + return null; + } + + Object parseObject(String source, ParsePosition pos){ + implMissing(__FILE__, __LINE__); + return null; + } + + void setCurrency(Currency currency){ + implMissing(__FILE__, __LINE__); + } + + void setGroupingUsed(bool newValue){ + implMissing(__FILE__, __LINE__); + } + + void setMaximumFractionDigits(int newValue){ + implMissing(__FILE__, __LINE__); + } + + void setMaximumIntegerDigits(int newValue){ + implMissing(__FILE__, __LINE__); + } + + void setMinimumFractionDigits(int newValue){ + implMissing(__FILE__, __LINE__); + } + + void setMinimumIntegerDigits(int newValue){ + implMissing(__FILE__, __LINE__); + } + + void setParseIntegerOnly(bool value){ + implMissing(__FILE__, __LINE__); + } + +} + diff -r 48d4ee626868 -r 5d5bd660917f base/src/java/util/AbstractMap.d --- a/base/src/java/util/AbstractMap.d Wed Apr 22 07:30:21 2009 +0200 +++ b/base/src/java/util/AbstractMap.d Wed Apr 22 18:59:26 2009 +0200 @@ -90,5 +90,24 @@ implMissing( __FILE__, __LINE__ ); return null; } -} + public int opApply (int delegate(ref Object value) dg){ + foreach( entry; entrySet() ){ + auto me = cast(Map.Entry)entry; + auto v = me.getValue(); + int res = dg( v ); + if( res ) return res; + } + return 0; + } + public int opApply (int delegate(ref Object key, ref Object value) dg){ + foreach( entry; entrySet() ){ + auto me = cast(Map.Entry)entry; + auto k = me.getKey(); + auto v = me.getValue(); + int res = dg( k, v ); + if( res ) return res; + } + return 0; + } + } diff -r 48d4ee626868 -r 5d5bd660917f base/src/java/util/AbstractSet.d --- a/base/src/java/util/AbstractSet.d Wed Apr 22 07:30:21 2009 +0200 +++ b/base/src/java/util/AbstractSet.d Wed Apr 22 18:59:26 2009 +0200 @@ -38,6 +38,14 @@ public String toString(){ return super.toString(); } // only for D - //public int opApply (int delegate(ref Object value) dg){ return super.opApply(dg); } + public int opApply (int delegate(ref Object value) dg){ + auto it = iterator(); + while( it.hasNext() ){ + auto v = it.next(); + int res = dg( v ); + if( res ) return res; + } + return 0; + } } diff -r 48d4ee626868 -r 5d5bd660917f base/src/java/util/Currency.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/src/java/util/Currency.d Wed Apr 22 18:59:26 2009 +0200 @@ -0,0 +1,46 @@ +module java.util.Currency; + +import java.lang.all; +import java.util.Locale; + +class Currency{ + + String getCurrencyCode(){ + implMissing(__FILE__, __LINE__); + return null; + } + + int getDefaultFractionDigits(){ + implMissing(__FILE__, __LINE__); + return 0; + } + + static Currency getInstance(Locale locale){ + implMissing(__FILE__, __LINE__); + return null; + } + + static Currency getInstance(String currencyCode){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getSymbol(){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getSymbol(Locale locale){ + implMissing(__FILE__, __LINE__); + return null; + } + + String toString(){ + implMissing(__FILE__, __LINE__); + return null; + } + + +} + + diff -r 48d4ee626868 -r 5d5bd660917f base/src/java/util/Locale.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/src/java/util/Locale.d Wed Apr 22 18:59:26 2009 +0200 @@ -0,0 +1,151 @@ +module java.util.Locale; + +import java.lang.all; + +class Locale : Cloneable { + static Locale CANADA; + static Locale CANADA_FRENCH; + static Locale CHINA; + static Locale CHINESE; + static Locale ENGLISH; + static Locale FRANCE; + static Locale FRENCH; + static Locale GERMAN; + static Locale GERMANY; + static Locale ITALIAN; + static Locale ITALY; + static Locale JAPAN; + static Locale JAPANESE;; + static Locale KOREA; + static Locale KOREAN; + static Locale PRC; + static Locale SIMPLIFIED_CHINESE; + static Locale TAIWAN; + static Locale TRADITIONAL_CHINESE; + static Locale UK; + static Locale US; + + this(String language){ + implMissing(__FILE__, __LINE__); + } + + this(String language, String country){ + implMissing(__FILE__, __LINE__); + } + + this(String language, String country, String variant){ + implMissing(__FILE__, __LINE__); + } + + Object clone(){ + implMissing(__FILE__, __LINE__); + return null; + } + + override equals_t opEquals(Object obj){ + implMissing(__FILE__, __LINE__); + return false; + } + + static Locale[] getAvailableLocales(){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getCountry(){ + implMissing(__FILE__, __LINE__); + return null; + } + + static Locale getDefault(){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getDisplayCountry(){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getDisplayCountry(Locale inLocale){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getDisplayLanguage(){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getDisplayLanguage(Locale inLocale){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getDisplayName(){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getDisplayName(Locale inLocale){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getDisplayVariant(){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getDisplayVariant(Locale inLocale){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getISO3Country(){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getISO3Language(){ + implMissing(__FILE__, __LINE__); + return null; + } + + static String[] getISOCountries(){ + implMissing(__FILE__, __LINE__); + return null; + } + + static String[] getISOLanguages(){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getLanguage(){ + implMissing(__FILE__, __LINE__); + return null; + } + + String getVariant(){ + implMissing(__FILE__, __LINE__); + return null; + } + + override hash_t toHash(){ + implMissing(__FILE__, __LINE__); + return 0; + } + + static void setDefault(Locale newLocale){ + implMissing(__FILE__, __LINE__); + } + + String toString(){ + implMissing(__FILE__, __LINE__); + return null; + } + +} + + diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Realm.d --- a/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Realm.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Realm.d Wed Apr 22 18:59:26 2009 +0200 @@ -78,10 +78,18 @@ */ public abstract class Realm { - private static ThreadLocal defaultRealm; - static this(){ - defaultRealm = new ThreadLocal(); + private static ThreadLocal defaultRealm_; + private static ThreadLocal defaultRealm(){ + if( defaultRealm_ is null ){ + synchronized{ + if( defaultRealm_ is null ){ + defaultRealm_ = new ThreadLocal(); + } + } + } + return defaultRealm_; } + this(){ workQueue = new Queue(); } diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/ComputedObservableMap.d --- a/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/ComputedObservableMap.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/ComputedObservableMap.d Wed Apr 22 18:59:26 2009 +0200 @@ -64,7 +64,7 @@ private Set fentrySet; private class EntrySet : AbstractSet { - public int opApply (int delegate(ref Object value) dg){ + public override int opApply (int delegate(ref Object value) dg){ return super.opApply(dg); } diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet001NestedSelectionWithCombo.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet001NestedSelectionWithCombo.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet001NestedSelectionWithCombo.d Wed Apr 22 18:59:26 2009 +0200 @@ -39,6 +39,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import org.eclipse.jface.viewers.Viewer; /** * Demonstrates nested selection.
* At the first level, user may select a person.
@@ -61,8 +62,11 @@ // Minimal JavaBeans support public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( + private PropertyChangeSupport propertyChangeSupport; + this(){ + propertyChangeSupport = new PropertyChangeSupport( this); + } public void addPropertyChangeListener(PropertyChangeListener listener) { propertyChangeSupport.addPropertyChangeListener(listener); @@ -114,7 +118,7 @@ public void setName(String name) { String oldValue = this.name; this.name = name; - firePropertyChange("name", oldValue, name); + firePropertyChange("name", stringcast(oldValue), stringcast(name)); } public String getCity() { @@ -124,7 +128,7 @@ public void setCity(String city) { String oldValue = this.city; this.city = city; - firePropertyChange("city", oldValue, city); + firePropertyChange("city", stringcast(oldValue), stringcast(city)); } } @@ -190,27 +194,27 @@ ListViewer peopleListViewer = new ListViewer(peopleList); IObservableMap attributeMap = BeansObservables.observeMap( Observables.staticObservableSet(realm, new HashSet( - viewModel.getPeople())), Class.formType!(Person), "name"); + viewModel.getPeople())), Class.fromType!(Person), "name"); peopleListViewer.setLabelProvider(new ObservableMapLabelProvider( attributeMap)); - peopleListViewer.setContentProvider(new ArrayContentProvider()); + peopleListViewer.setContentProvider(new ArrayContentProvider!(Object)()); peopleListViewer.setInput(viewModel.getPeople()); DataBindingContext dbc = new DataBindingContext(realm); IObservableValue selectedPerson = ViewersObservables - .observeSingleSelection(peopleListViewer); + .observeSingleSelection(cast(Viewer)peopleListViewer); dbc.bindValue(SWTObservables.observeText(name, SWT.Modify), - BeansObservables.observeDetailValue(selectedPerson, - "name", Class.fromType!(String))); + BeansObservables.observeDetailValue(realm, selectedPerson, + "name", Class.fromType!(String)), null, null); ComboViewer cityViewer = new ComboViewer(city); - cityViewer.setContentProvider(new ArrayContentProvider()); + cityViewer.setContentProvider(new ArrayContentProvider!(Object)()); cityViewer.setInput(viewModel.getCities()); IObservableValue citySelection = ViewersObservables - .observeSingleSelection(cityViewer); - dbc.bindValue(citySelection, BeansObservables.observeDetailValue( - selectedPerson, "city", Class.fromType!(String))); + .observeSingleSelection(cast(Viewer)cityViewer); + dbc.bindValue( citySelection, BeansObservables.observeDetailValue( realm, + selectedPerson, "city", Class.fromType!(String)), null, null); GridLayoutFactory.swtDefaults().applyTo(shell); // Open and return the Shell diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet002UpdateComboRetainSelection.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet002UpdateComboRetainSelection.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet002UpdateComboRetainSelection.d Wed Apr 22 18:59:26 2009 +0200 @@ -11,7 +11,9 @@ * Matthew Hall - bug 260329 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet002UpdateComboRetainSelection; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -37,6 +39,8 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; +import tango.io.Stdout; + /** * Shows how to bind a Combo so that when update its items, the selection is * retained if at all possible. @@ -45,29 +49,30 @@ */ public class Snippet002UpdateComboRetainSelection { public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); - - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - - // Print the results - System.out.println(viewModel.getText()); - } - }); - display.dispose(); + final Display display = new Display(); + Realm.runWithDefault(SWTObservables.getRealm(display), dgRunnable((Display display_) { + ViewModel viewModel = new ViewModel(); + Shell shell = (new View(viewModel)).createShell(); + + // The SWT event loop + while (!shell.isDisposed()) { + if (!display_.readAndDispatch()) { + display_.sleep(); + } + } + + // Print the results + Stdout.formatln( "{}", viewModel.getText()); + }, display)); + display.dispose(); } // Minimal JavaBeans support public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); + private PropertyChangeSupport propertyChangeSupport; + this(){ + propertyChangeSupport = new PropertyChangeSupport(this); + } public void addPropertyChangeListener(PropertyChangeListener listener) { propertyChangeSupport.addPropertyChangeListener(listener); @@ -91,11 +96,12 @@ } // The View's model--the root of our Model graph for this particular GUI. - public static class ViewModel extends AbstractModelObject { + public static class ViewModel : AbstractModelObject { private String text = "beef"; - private List choices = new ArrayList(); - { + private List choices; + this(){ + choices = new ArrayList(); choices.add("pork"); choices.add("beef"); choices.add("poultry"); @@ -109,7 +115,7 @@ public void setChoices(List choices) { List old = this.choices; this.choices = choices; - firePropertyChange("choices", old, choices); + firePropertyChange("choices", cast(Object)old, cast(Object)choices); } public String getText() { @@ -119,7 +125,7 @@ public void setText(String text) { String oldValue = this.text; this.text = text; - firePropertyChange("text", oldValue, text); + firePropertyChange("text", stringcast(oldValue), stringcast(text)); } } @@ -131,9 +137,21 @@ */ static int count; - public View(ViewModel viewModel) { + public this(ViewModel viewModel) { this.viewModel = viewModel; } + class ResetSelectionListener : SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + List newList = new ArrayList(); + newList.add("Chocolate"); + newList.add("Vanilla"); + newList.add("Mango Parfait"); + newList.add("beef"); + newList.add("Cheesecake"); + newList.add(Integer.toString(++count)); + viewModel.setChoices(newList); + } + } public Shell createShell() { // Build a UI @@ -143,29 +161,18 @@ Combo combo = new Combo(shell, SWT.BORDER | SWT.READ_ONLY); Button reset = new Button(shell, SWT.NULL); reset.setText("reset collection"); - reset.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - List newList = new ArrayList(); - newList.add("Chocolate"); - newList.add("Vanilla"); - newList.add("Mango Parfait"); - newList.add("beef"); - newList.add("Cheesecake"); - newList.add(Integer.toString(++count)); - viewModel.setChoices(newList); - } - }); + reset.addSelectionListener(new ResetSelectionListener()); // Print value out first - System.out.println(viewModel.getText()); + Stdout.formatln("{}", viewModel.getText()); DataBindingContext dbc = new DataBindingContext(); IObservableList list = MasterDetailObservables.detailList(BeansObservables.observeValue(viewModel, "choices"), getListDetailFactory(), - String.class); - dbc.bindList(SWTObservables.observeItems(combo), list); - dbc.bindValue(SWTObservables.observeText(combo), BeansObservables.observeValue(viewModel, "text")); + Class.fromType!(String)); + dbc.bindList(SWTObservables.observeItems(combo), list, null, null ); + dbc.bindValue(SWTObservables.observeText(combo), BeansObservables.observeValue(viewModel, "text"), null, null ); // Open and return the Shell shell.pack(); @@ -175,12 +182,17 @@ } private static IObservableFactory getListDetailFactory() { - return new IObservableFactory() { + return new class() IObservableFactory { public IObservable createObservable(Object target) { - WritableList list = WritableList.withElementType(String.class); - list.addAll((Collection) target); + WritableList list = WritableList.withElementType(Class.fromType!(String)); + list.addAll(cast(Collection) target); return list; } }; } } + +void main( String[] args ){ + Snippet002UpdateComboRetainSelection.main(args); +} + diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet003UpdateComboBindUsingViewer.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet003UpdateComboBindUsingViewer.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet003UpdateComboBindUsingViewer.d Wed Apr 22 18:59:26 2009 +0200 @@ -11,7 +11,9 @@ * Matthew Hall - bugs 260329, 260337 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet003UpdateComboBindUsingViewer; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -42,134 +44,139 @@ * @since 3.2 */ public class Snippet003UpdateComboBindUsingViewer { - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); + public static void main(String[] args) { + final Display display = new Display(); + Realm.runWithDefault(SWTObservables.getRealm(display), dgRunnable( (Display display_) { + ViewModel viewModel = new ViewModel(); + Shell shell = (new View(viewModel)).createShell(); - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - // Print the results - System.out.println(viewModel.getText()); - } - }); - display.dispose(); - } + // The SWT event loop + while (!shell.isDisposed()) { + if (!display_.readAndDispatch()) { + display_.sleep(); + } + } + // Print the results + Stdout.formatln("{}", viewModel.getText()); + }, display)); + display.dispose(); + } - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); + // Minimal JavaBeans support + public static abstract class AbstractModelObject { + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( + this); - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } + public void addPropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(listener); + } + + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(propertyName, + listener); + } - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } + public void removePropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(listener); + } - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } + public void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(propertyName, + listener); + } - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } + protected void firePropertyChange(String propertyName, Object oldValue, + Object newValue) { + propertyChangeSupport.firePropertyChange(propertyName, oldValue, + newValue); + } + } - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } + // The View's model--the root of our Model graph for this particular GUI. + public static class ViewModel : AbstractModelObject { + private String text = "beef"; - // The View's model--the root of our Model graph for this particular GUI. - public static class ViewModel extends AbstractModelObject { - private String text = "beef"; + private List choices; + this(){ + choices = new ArrayList(); + choices.add("pork"); + choices.add("beef"); + choices.add("poultry"); + choices.add("vegatables"); + } - private List choices = new ArrayList(); - { - choices.add("pork"); - choices.add("beef"); - choices.add("poultry"); - choices.add("vegatables"); - } + public List getChoices() { + return choices; + } - public List getChoices() { - return choices; - } + public void setChoices(List choices) { + this.choices = choices; + firePropertyChange("choices", null, null); + } - public void setChoices(List choices) { - this.choices = choices; - firePropertyChange("choices", null, null); - } + public String getText() { + return text; + } - public String getText() { - return text; - } + public void setText(String text) { + String oldValue = this.text; + this.text = text; + firePropertyChange("text", oldValue, text); + } + } - public void setText(String text) { - String oldValue = this.text; - this.text = text; - firePropertyChange("text", oldValue, text); - } - } + // The GUI view + static class View { + private ViewModel viewModel; - // The GUI view - static class View { - private ViewModel viewModel; - - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } - - public Shell createShell() { - // Build a UI - Shell shell = new Shell(Display.getCurrent()); - shell.setLayout(new RowLayout(SWT.VERTICAL)); + public this(ViewModel viewModel) { + this.viewModel = viewModel; + } + class ResetSelectionListener : SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + List newList = new ArrayList(); + newList.add("Chocolate"); + newList.add("Vanilla"); + newList.add("Mango Parfait"); + newList.add("beef"); + newList.add("Cheesecake"); + viewModel.setChoices(newList); + } + } - Combo combo = new Combo(shell, SWT.BORDER | SWT.READ_ONLY); - ComboViewer viewer = new ComboViewer(combo); - Button reset = new Button(shell, SWT.NULL); - reset.setText("reset collection"); - reset.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - List newList = new ArrayList(); - newList.add("Chocolate"); - newList.add("Vanilla"); - newList.add("Mango Parfait"); - newList.add("beef"); - newList.add("Cheesecake"); - viewModel.setChoices(newList); - } - }); + public Shell createShell() { + // Build a UI + Shell shell = new Shell(Display.getCurrent()); + shell.setLayout(new RowLayout(SWT.VERTICAL)); + + Combo combo = new Combo(shell, SWT.BORDER | SWT.READ_ONLY); + ComboViewer viewer = new ComboViewer(combo); + Button reset = new Button(shell, SWT.NULL); + reset.setText("reset collection"); + reset.addSelectionListener(new ResetSelectionListener()); + + // Print value out first + Stdout.formatln("{}", viewModel.getText()); - // Print value out first - System.out.println(viewModel.getText()); + DataBindingContext dbc = new DataBindingContext(); + ViewerSupport.bind(viewer, BeansObservables.observeList(viewModel, + "choices", Class.fromType!(String)), Properties + .selfValue(Class.fromType!(String))); - DataBindingContext dbc = new DataBindingContext(); - ViewerSupport.bind(viewer, BeansObservables.observeList(viewModel, - "choices", String.class), Properties - .selfValue(String.class)); + dbc.bindValue(ViewersObservables.observeSingleSelection(viewer), + BeansObservables.observeValue(viewModel, "text"), null, null); - dbc.bindValue(ViewersObservables.observeSingleSelection(viewer), - BeansObservables.observeValue(viewModel, "text")); + // Open and return the Shell + shell.pack(); + shell.open(); + return shell; + } + } +} - // Open and return the Shell - shell.pack(); - shell.open(); - return shell; - } - } +void main( String[] args ){ + Snippet003UpdateComboBindUsingViewer.main(args); } + diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet005MenuUpdater.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet005MenuUpdater.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet005MenuUpdater.d Wed Apr 22 18:59:26 2009 +0200 @@ -9,7 +9,9 @@ * IBM Corporation - initial API and implementation * Brad Reynolds - bug 116920 *******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet005MenuUpdater; + +import java.lang.all; import java.util.Date; import java.util.Iterator; @@ -24,62 +26,69 @@ import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; +import tango.io.Stdout; + /** */ public class Snippet005MenuUpdater { - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(display); + public static void main(String[] args) { + void add(Display d, WritableList menuItemStrings){ + Stdout.formatln("adding item"); + menuItemStrings.add(stringcast((new Date()).toString())); + d.timerExec(5000, dgRunnable( &add, d, menuItemStrings )); + } + final Display display = new Display(); + Realm.runWithDefault(SWTObservables.getRealm(display), dgRunnable( (Display display_) { + Shell shell = new Shell(display_); - final WritableList menuItemStrings = new WritableList(); - display.asyncExec(new Runnable() { - public void run() { - System.out.println("adding item"); - menuItemStrings.add(new Date().toString()); - display.timerExec(5000, this); - } - }); + final WritableList menuItemStrings = new WritableList(); + display_.asyncExec(dgRunnable( &add, display_, menuItemStrings)); - Menu bar = new Menu(shell, SWT.BAR); - shell.setMenuBar(bar); - MenuItem fileItem = new MenuItem(bar, SWT.CASCADE); - fileItem.setText("&Test Menu"); - final Menu submenu = new Menu(shell, SWT.DROP_DOWN); - fileItem.setMenu(submenu); - new MenuUpdater(submenu) { - protected void updateMenu() { - System.out.println("updating menu"); - MenuItem[] items = submenu.getItems(); - int itemIndex = 0; - for (Iterator it = menuItemStrings.iterator(); it - .hasNext();) { - MenuItem item; - if (itemIndex < items.length) { - item = items[itemIndex++]; - } else { - item = new MenuItem(submenu, SWT.NONE); - } - String string = (String) it.next(); - item.setText(string); - } - while (itemIndex < items.length) { - items[itemIndex++].dispose(); - } - } - }; + Menu bar = new Menu(shell, SWT.BAR); + shell.setMenuBar(bar); + MenuItem fileItem = new MenuItem(bar, SWT.CASCADE); + fileItem.setText("&Test Menu"); + final Menu submenu = new Menu(shell, SWT.DROP_DOWN); + fileItem.setMenu(submenu); + new class( submenu) MenuUpdater { + this( Menu m ){ + super(m); + } + protected void updateMenu() { + Stdout.formatln("updating menu"); + MenuItem[] items = submenu.getItems(); + int itemIndex = 0; + for (Iterator it = menuItemStrings.iterator(); it + .hasNext();) { + MenuItem item; + if (itemIndex < items.length) { + item = items[itemIndex++]; + } else { + item = new MenuItem(submenu, SWT.NONE); + } + String string = stringcast( it.next()); + item.setText(string); + } + while (itemIndex < items.length) { + items[itemIndex++].dispose(); + } + } + }; - shell.open(); + shell.open(); - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - display.dispose(); - } + // The SWT event loop + while (!shell.isDisposed()) { + if (!display_.readAndDispatch()) { + display_.sleep(); + } + } + }, display)); + display.dispose(); + } } + +void main( String[] args ){ + Snippet005MenuUpdater.main(args); +} + diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet006Spreadsheet.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet006Spreadsheet.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet006Spreadsheet.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,10 @@ * Brad Reynolds - bug 116920 *******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet006Spreadsheet; + +import java.lang.all; +import tango.io.Stdout; import java.text.NumberFormat; import java.text.ParseException; @@ -43,273 +46,313 @@ */ public class Snippet006Spreadsheet { - private static final int COUNTER_UPDATE_DELAY = 1000; + private static const int COUNTER_UPDATE_DELAY = 1000; - private static final int NUM_COLUMNS = 6; + private static const int NUM_COLUMNS = 6; - private static final int NUM_ROWS = 16; + private static const int NUM_ROWS = 16; - /** - * 0 for no output, 1 for some, 2 for more - */ - private static int DEBUG_LEVEL = 0; + /** + * 0 for no output, 1 for some, 2 for more + */ + private static int DEBUG_LEVEL = 0; - /** - * If true, there will be a automatic counter at B1. - */ - private static boolean FUNKY_COUNTER = false; + /** + * If true, there will be a automatic counter at B1. + */ + private static bool FUNKY_COUNTER = false; - /** - * // * If true, all formulas (except for row 1 and column A) will be the - * sum of the values of their left and top neighbouring cells. - */ - private static boolean FUNKY_FORMULAS = true; + /** + * // * If true, all formulas (except for row 1 and column A) will be the + * sum of the values of their left and top neighbouring cells. + */ + private static bool FUNKY_FORMULAS = true; + + static WritableValue[][] cellFormulas; + + static ComputedValue[][] cellValues; - static WritableValue[][] cellFormulas = new WritableValue[NUM_ROWS][NUM_COLUMNS]; - - static ComputedValue[][] cellValues = new ComputedValue[NUM_ROWS][NUM_COLUMNS]; + static this(){ + cellFormulas = new WritableValue[][](NUM_ROWS,NUM_COLUMNS); + cellValues = new ComputedValue[][](NUM_ROWS,NUM_COLUMNS); + } - static class ComputedCellValue extends ComputedValue { - private final IObservableValue cellFormula; + static class ComputedCellValue : ComputedValue { + private const IObservableValue cellFormula; - private boolean calculating; + private bool calculating; - ComputedCellValue(IObservableValue cellFormula) { - this.cellFormula = cellFormula; - } + this(IObservableValue cellFormula) { + this.cellFormula = cellFormula; + } - protected Object calculate() { - if (calculating) { - return "#cycle"; - } - try { - calculating = true; - return evaluate(cellFormula.getValue()); - } finally { - calculating = false; - } - } + protected Object calculate() { + if (calculating) { + return stringcast("#cycle"); + } + try { + calculating = true; + return evaluate(cellFormula.getValue()); + } finally { + calculating = false; + } + } - private Object evaluate(Object value) { - if (DEBUG_LEVEL >= 2) { - System.out.println("evaluating " + this + " ..."); - } - if (value == null) { - return ""; - } - try { - String s = (String) value; - if (!s.startsWith("=")) { - return s; - } - String addition = s.substring(1); - int indexOfPlus = addition.indexOf('+'); - String operand1 = addition.substring(0, indexOfPlus); - double value1 = eval(operand1); - String operand2 = addition.substring(indexOfPlus + 1); - double value2 = eval(operand2); - return NumberFormat.getNumberInstance().format(value1 + value2); - } catch (Exception ex) { - return ex.getMessage(); - } - } + private Object evaluate(Object value) { + if (DEBUG_LEVEL >= 2) { + Stdout.formatln("evaluating {} ...", this); + } + if (value is null) { + return stringcast(""); + } + try { + String s = stringcast( value ); + if (!s.startsWith("=")) { + return stringcast(s); + } + String addition = s.substring(1); + int indexOfPlus = addition.indexOf('+'); + String operand1 = addition.substring(0, indexOfPlus); + double value1 = eval(operand1); + String operand2 = addition.substring(indexOfPlus + 1); + double value2 = eval(operand2); + return stringcast(NumberFormat.getNumberInstance().format(value1 + value2)); + } catch (Exception ex) { + return stringcast(ex.msg); + } + } - /** - * @param s - * @return - * @throws ParseException - */ - private double eval(String s) throws ParseException { - if (s.length() == 0) { - return 0; - } - char character = s.charAt(0); - if (Character.isLetter(character)) { - character = Character.toLowerCase(character); - // reference to other cell - int columnIndex = character - 'a'; - int rowIndex = 0; - rowIndex = NumberFormat.getNumberInstance().parse( - s.substring(1)).intValue() - 1; - String value = (String) cellValues[rowIndex][columnIndex] - .getValue(); - return value.length() == 0 ? 0 : NumberFormat - .getNumberInstance().parse(value).doubleValue(); - } - return NumberFormat.getNumberInstance().parse(s).doubleValue(); - } - } - - protected static int counter; - - public static void main(String[] args) { + /** + * @param s + * @return + * @throws ParseException + */ + private double eval(String s) { + if (s.length() is 0) { + return 0; + } + dchar character = s.charAt(0); + if (Character.isLetter(character)) { + character = Character.toLowerCase(character); + // reference to other cell + int columnIndex = character - 'a'; + int rowIndex = 0; + rowIndex = NumberFormat.getNumberInstance().parse( + s.substring(1)).intValue() - 1; + String value = stringcast( cellValues[rowIndex][columnIndex] + .getValue()); + return value.length() is 0 ? 0 : NumberFormat + .getNumberInstance().parse(value).doubleValue(); + } + return NumberFormat.getNumberInstance().parse(s).doubleValue(); + } + } - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(display); - shell.setText("Data Binding Snippet 006"); - - final Table table = new Table(shell, SWT.BORDER | SWT.MULTI - | SWT.FULL_SELECTION | SWT.VIRTUAL); - table.setLinesVisible(true); - table.setHeaderVisible(true); + protected static int counter; + static class LocalTableUpdater : TableUpdater { + this( Table t, WritableList l ){ + super( t, l ); + } + protected void updateItem(int rowIndex, TableItem item, Object element) { + if (DEBUG_LEVEL >= 1) { + Stdout.formatln("updating row {}", rowIndex); + } + for (int j = 0; j < NUM_COLUMNS; j++) { + item.setText(j, stringcast( cellValues[rowIndex][j] + .getValue())); + } + } + } + static class CursorSelectionListener : SelectionAdapter { + TableCursor cursor; + Table table; + ControlEditor editor; - for (int i = 0; i < NUM_COLUMNS; i++) { - TableColumn tableColumn = new TableColumn(table, SWT.NONE); - tableColumn.setText(Character.toString((char) ('A' + i))); - tableColumn.setWidth(60); - } - WritableList list = new WritableList(); - for (int i = 0; i < NUM_ROWS; i++) { - list.add(new Object()); - for (int j = 0; j < NUM_COLUMNS; j++) { - cellFormulas[i][j] = new WritableValue(); - cellValues[i][j] = new ComputedCellValue( - cellFormulas[i][j]); - if (!FUNKY_FORMULAS || i == 0 || j == 0) { - cellFormulas[i][j].setValue(""); - } else { - cellFormulas[i][j].setValue("=" - + cellReference(i - 1, j) + "+" - + cellReference(i, j - 1)); - } - } - } + this(TableCursor c, Table t,ControlEditor e){ + cursor = c; + table = t; + editor = e; + } + // when the TableEditor is over a cell, select the + // corresponding row + // in + // the table + public void widgetSelected(SelectionEvent e) { + table.setSelection([ cursor.getRow() ]); + } - new TableUpdater(table, list) { - protected void updateItem(int rowIndex, TableItem item, Object element) { - if (DEBUG_LEVEL >= 1) { - System.out.println("updating row " + rowIndex); - } - for (int j = 0; j < NUM_COLUMNS; j++) { - item.setText(j, (String) cellValues[rowIndex][j] - .getValue()); - } - } - }; - - if (FUNKY_COUNTER) { - // counter in A1 - display.asyncExec(new Runnable() { - public void run() { - cellFormulas[0][1].setValue("" + counter++); - display.timerExec(COUNTER_UPDATE_DELAY, this); - } - }); - } - - // create a TableCursor to navigate around the table - final TableCursor cursor = new TableCursor(table, SWT.NONE); - // create an editor to edit the cell when the user hits "ENTER" - // while over a cell in the table - final ControlEditor editor = new ControlEditor(cursor); - editor.grabHorizontal = true; - editor.grabVertical = true; - - cursor.addSelectionListener(new SelectionAdapter() { - // when the TableEditor is over a cell, select the - // corresponding row - // in - // the table - public void widgetSelected(SelectionEvent e) { - table.setSelection(new TableItem[] { cursor.getRow() }); - } + // when the user hits "ENTER" in the TableCursor, pop up a + // text + // editor so that + // they can change the text of the cell + public void widgetDefaultSelected(SelectionEvent e) { + final Text text = new Text(cursor, SWT.NONE); + TableItem row = cursor.getRow(); + int rowIndex = table.indexOf(row); + int columnIndex = cursor.getColumn(); + text + .setText(stringcast( cellFormulas[rowIndex][columnIndex] + .getValue())); + text.addKeyListener(new TextKeyListener(table, cursor, text )); + editor.setEditor(text); + text.setFocus(); + } + } + static class TextKeyListener : KeyAdapter { + Table table; + TableCursor cursor; + Text text; + this(Table t, TableCursor c, Text t2){ + cursor = c; + table = t; + text = t2; + } + public void keyPressed(KeyEvent e) { + // close the text editor and copy the data over + // when the user hits "ENTER" + if (e.character is SWT.CR) { + TableItem row = cursor.getRow(); + int rowIndex = table.indexOf(row); + int columnIndex = cursor.getColumn(); + cellFormulas[rowIndex][columnIndex] + .setValue(stringcast(text.getText())); + text.dispose(); + } + // close the text editor when the user hits + // "ESC" + if (e.character is SWT.ESC) { + text.dispose(); + } + } + } + static class CursorKeyListener : KeyAdapter { + TableCursor cursor; + this(TableCursor c){ + cursor = c; + } + public void keyPressed(KeyEvent e) { + if (e.keyCode is SWT.MOD1 || e.keyCode is SWT.MOD2 + || (e.stateMask & SWT.MOD1) !is 0 + || (e.stateMask & SWT.MOD2) !is 0) { + cursor.setVisible(false); + } + } + } + static class TableKeyListener : KeyAdapter { + Table table; + TableCursor cursor; + this(Table t, TableCursor c){ + cursor = c; + table = t; + } + public void keyReleased(KeyEvent e) { + if (e.keyCode is SWT.MOD1 + && (e.stateMask & SWT.MOD2) !is 0) + return; + if (e.keyCode is SWT.MOD2 + && (e.stateMask & SWT.MOD1) !is 0) + return; + if (e.keyCode !is SWT.MOD1 + && (e.stateMask & SWT.MOD1) !is 0) + return; + if (e.keyCode !is SWT.MOD2 + && (e.stateMask & SWT.MOD2) !is 0) + return; - // when the user hits "ENTER" in the TableCursor, pop up a - // text - // editor so that - // they can change the text of the cell - public void widgetDefaultSelected(SelectionEvent e) { - final Text text = new Text(cursor, SWT.NONE); - TableItem row = cursor.getRow(); - int rowIndex = table.indexOf(row); - int columnIndex = cursor.getColumn(); - text - .setText((String) cellFormulas[rowIndex][columnIndex] - .getValue()); - text.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { - // close the text editor and copy the data over - // when the user hits "ENTER" - if (e.character == SWT.CR) { - TableItem row = cursor.getRow(); - int rowIndex = table.indexOf(row); - int columnIndex = cursor.getColumn(); - cellFormulas[rowIndex][columnIndex] - .setValue(text.getText()); - text.dispose(); - } - // close the text editor when the user hits - // "ESC" - if (e.character == SWT.ESC) { - text.dispose(); - } - } - }); - editor.setEditor(text); - text.setFocus(); - } - }); - // Hide the TableCursor when the user hits the "MOD1" or "MOD2" - // key. - // This alows the user to select multiple items in the table. - cursor.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { - if (e.keyCode == SWT.MOD1 || e.keyCode == SWT.MOD2 - || (e.stateMask & SWT.MOD1) != 0 - || (e.stateMask & SWT.MOD2) != 0) { - cursor.setVisible(false); - } - } - }); - // Show the TableCursor when the user releases the "MOD2" or - // "MOD1" key. - // This signals the end of the multiple selection task. - table.addKeyListener(new KeyAdapter() { - public void keyReleased(KeyEvent e) { - if (e.keyCode == SWT.MOD1 - && (e.stateMask & SWT.MOD2) != 0) - return; - if (e.keyCode == SWT.MOD2 - && (e.stateMask & SWT.MOD1) != 0) - return; - if (e.keyCode != SWT.MOD1 - && (e.stateMask & SWT.MOD1) != 0) - return; - if (e.keyCode != SWT.MOD2 - && (e.stateMask & SWT.MOD2) != 0) - return; + TableItem[] selection = table.getSelection(); + TableItem row = (selection.length is 0) ? table + .getItem(table.getTopIndex()) : selection[0]; + table.showItem(row); + cursor.setSelection(row, 0); + cursor.setVisible(true); + cursor.setFocus(); + } + } + public static void main(String[] args) { + + final Display display = new Display(); + Realm.runWithDefault(SWTObservables.getRealm(display), dgRunnable( (Display display_) { + Shell shell = new Shell(display_); + shell.setText("Data Binding Snippet 006"); + + final Table table = new Table(shell, SWT.BORDER | SWT.MULTI + | SWT.FULL_SELECTION | SWT.VIRTUAL); + table.setLinesVisible(true); + table.setHeaderVisible(true); + + for (int i = 0; i < NUM_COLUMNS; i++) { + TableColumn tableColumn = new TableColumn(table, SWT.NONE); + tableColumn.setText(Character.toString(cast(char) ('A' + i))); + tableColumn.setWidth(60); + } + WritableList list = new WritableList(); + for (int i = 0; i < NUM_ROWS; i++) { + list.add(new Object()); + for (int j = 0; j < NUM_COLUMNS; j++) { + cellFormulas[i][j] = new WritableValue(); + cellValues[i][j] = new ComputedCellValue( + cellFormulas[i][j]); + if (!FUNKY_FORMULAS || i is 0 || j is 0) { + cellFormulas[i][j].setValue(stringcast("")); + } else { + cellFormulas[i][j].setValue(stringcast("=" + ~ cellReference(i - 1, j) ~ "+" + ~ cellReference(i, j - 1))); + } + } + } + + new LocalTableUpdater( table, list ); - TableItem[] selection = table.getSelection(); - TableItem row = (selection.length == 0) ? table - .getItem(table.getTopIndex()) : selection[0]; - table.showItem(row); - cursor.setSelection(row, 0); - cursor.setVisible(true); - cursor.setFocus(); - } - }); + if (FUNKY_COUNTER) { + // counter in A1 + display_.asyncExec(dgRunnable(&output, display_)); + } - GridLayoutFactory.fillDefaults().generateLayout(shell); - shell.setSize(400, 300); - shell.open(); + // create a TableCursor to navigate around the table + final TableCursor cursor = new TableCursor(table, SWT.NONE); + // create an editor to edit the cell when the user hits "ENTER" + // while over a cell in the table + final ControlEditor editor = new ControlEditor(cursor); + editor.grabHorizontal = true; + editor.grabVertical = true; + + cursor.addSelectionListener(new CursorSelectionListener( cursor, table, editor )); + // Hide the TableCursor when the user hits the "MOD1" or "MOD2" + // key. + // This alows the user to select multiple items in the table. + cursor.addKeyListener(new CursorKeyListener(cursor) ); + // Show the TableCursor when the user releases the "MOD2" or + // "MOD1" key. + // This signals the end of the multiple selection task. + table.addKeyListener(new TableKeyListener(table, cursor)); - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - display.dispose(); - } + GridLayoutFactory.fillDefaults().generateLayout(shell); + shell.setSize(400, 300); + shell.open(); - private static String cellReference(int rowIndex, int columnIndex) { - String cellReference = "" + ((char) ('A' + columnIndex)) - + (rowIndex + 1); - return cellReference; - } + // The SWT event loop + while (!shell.isDisposed()) { + if (!display_.readAndDispatch()) { + display_.sleep(); + } + } + }, display)); + display.dispose(); + } + private void output( Display display ){ + cellFormulas[0][1].setValue(stringcast(Format("{}", counter++))); + display.timerExec(COUNTER_UPDATE_DELAY, dgRunnable( &output, display )); + } + + private static String cellReference(int rowIndex, int columnIndex) { + String cellReference = Format("{}{}", (cast(char) ('A' + columnIndex)) + , (rowIndex + 1)); + return cellReference; + } } + +void main( String[] args ){ + Snippet006Spreadsheet.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet007ColorLabelProvider.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet007ColorLabelProvider.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet007ColorLabelProvider.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * IBM Corporation - see bug 137934 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet007ColorLabelProvider; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -48,173 +50,177 @@ * @since 3.2 */ public class Snippet007ColorLabelProvider { - /** - * @param args - */ - public static void main(String[] args) { - final List persons = new ArrayList(); - persons.add(new Person("Fiona Apple", Person.FEMALE)); - persons.add(new Person("Elliot Smith", Person.MALE)); - persons.add(new Person("Diana Krall", Person.FEMALE)); - persons.add(new Person("David Gilmour", Person.MALE)); + /** + * @param args + */ + public static void main(String[] args) { + final List persons = new ArrayList(); + persons.add(new Person("Fiona Apple", Person.FEMALE)); + persons.add(new Person("Elliot Smith", Person.MALE)); + persons.add(new Person("Diana Krall", Person.FEMALE)); + persons.add(new Person("David Gilmour", Person.MALE)); - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(display); - shell.setText("Gender Bender"); - shell.setLayout(new GridLayout()); + final Display display = new Display(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + Shell shell = new Shell(display); + shell.setText("Gender Bender"); + shell.setLayout(new GridLayout()); - Table table = new Table(shell, SWT.SINGLE | SWT.H_SCROLL - | SWT.V_SCROLL | SWT.BORDER); - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - table.setLayoutData(gridData); - table.setHeaderVisible(true); - table.setLinesVisible(true); - TableColumn column = new TableColumn(table, SWT.NONE); - column.setText("No"); - column.setWidth(20); - column = new TableColumn(table, SWT.NONE); - column.setText("Name"); - column.setWidth(100); - final TableViewer viewer = new TableViewer(table); + Table table = new Table(shell, SWT.SINGLE | SWT.H_SCROLL + | SWT.V_SCROLL | SWT.BORDER); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + table.setLayoutData(gridData); + table.setHeaderVisible(true); + table.setLinesVisible(true); + TableColumn column = new TableColumn(table, SWT.NONE); + column.setText("No"); + column.setWidth(20); + column = new TableColumn(table, SWT.NONE); + column.setText("Name"); + column.setWidth(100); + final TableViewer viewer = new TableViewer(table); - IObservableList observableList = Observables - .staticObservableList(persons); - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); + IObservableList observableList = Observables + .staticObservableList(persons); + ObservableListContentProvider contentProvider = new ObservableListContentProvider(); + + viewer.setContentProvider(contentProvider); - viewer.setContentProvider(contentProvider); + // this does not have to correspond to the columns in the table, + // we just list all attributes that affect the table content. + IObservableMap[] attributes = BeansObservables.observeMaps( + contentProvider.getKnownElements(), Person.class, + new String[] { "name", "gender" }); - // this does not have to correspond to the columns in the table, - // we just list all attributes that affect the table content. - IObservableMap[] attributes = BeansObservables.observeMaps( - contentProvider.getKnownElements(), Person.class, - new String[] { "name", "gender" }); + class ColorLabelProvider extends ObservableMapLabelProvider + implements ITableColorProvider { + Color male = display.getSystemColor(SWT.COLOR_BLUE); - class ColorLabelProvider extends ObservableMapLabelProvider - implements ITableColorProvider { - Color male = display.getSystemColor(SWT.COLOR_BLUE); + Color female = new Color(display, 255, 192, 203); - Color female = new Color(display, 255, 192, 203); - - ColorLabelProvider(IObservableMap[] attributes) { - super(attributes); - } + ColorLabelProvider(IObservableMap[] attributes) { + super(attributes); + } - // to drive home the point that attributes does not have to - // match - // the columns - // in the table, we change the column text as follows: - public String getColumnText(Object element, int index) { - if (index == 0) { - return Integer - .toString(persons.indexOf(element) + 1); - } - return ((Person) element).getName(); - } + // to drive home the point that attributes does not have to + // match + // the columns + // in the table, we change the column text as follows: + public String getColumnText(Object element, int index) { + if (index == 0) { + return Integer + .toString(persons.indexOf(element) + 1); + } + return ((Person) element).getName(); + } + + public Color getBackground(Object element, int index) { + return null; + } - public Color getBackground(Object element, int index) { - return null; - } + public Color getForeground(Object element, int index) { + if (index == 0) + return null; + Person person = (Person) element; + return (person.getGender() == Person.MALE) ? male + : female; + } - public Color getForeground(Object element, int index) { - if (index == 0) - return null; - Person person = (Person) element; - return (person.getGender() == Person.MALE) ? male - : female; - } + public void dispose() { + super.dispose(); + female.dispose(); + } + } + viewer.setLabelProvider(new ColorLabelProvider(attributes)); - public void dispose() { - super.dispose(); - female.dispose(); - } - } - viewer.setLabelProvider(new ColorLabelProvider(attributes)); + viewer.setInput(observableList); - viewer.setInput(observableList); - - table.getColumn(0).pack(); + table.getColumn(0).pack(); - Button button = new Button(shell, SWT.PUSH); - button.setText("Toggle Gender"); - button.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent arg0) { - StructuredSelection selection = (StructuredSelection) viewer - .getSelection(); - if (selection != null && !selection.isEmpty()) { - Person person = (Person) selection - .getFirstElement(); - person - .setGender((person.getGender() == Person.MALE) ? Person.FEMALE - : Person.MALE); - } - } - }); + Button button = new Button(shell, SWT.PUSH); + button.setText("Toggle Gender"); + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent arg0) { + StructuredSelection selection = (StructuredSelection) viewer + .getSelection(); + if (selection != null && !selection.isEmpty()) { + Person person = (Person) selection + .getFirstElement(); + person + .setGender((person.getGender() == Person.MALE) ? Person.FEMALE + : Person.MALE); + } + } + }); + + shell.setSize(300, 400); + shell.open(); - shell.setSize(300, 400); - shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } + }); + display.dispose(); + } - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - display.dispose(); - } + static class Person { + static final int MALE = 0; + + static final int FEMALE = 1; - static class Person { - static final int MALE = 0; + private String name; - static final int FEMALE = 1; + private int gender; - private String name; - - private int gender; + private PropertyChangeSupport changeSupport = new PropertyChangeSupport( + this); - private PropertyChangeSupport changeSupport = new PropertyChangeSupport( - this); - - Person(String name, int gender) { - this.name = name; - this.gender = gender; - } + Person(String name, int gender) { + this.name = name; + this.gender = gender; + } - /** - * Returns the name. Method declared public to satisfy Java bean - * conventions - * - * @return the name - */ - public String getName() { - return name; - } + /** + * Returns the name. Method declared public to satisfy Java bean + * conventions + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param listener + */ + public void addPropertyChangeListener(PropertyChangeListener listener) { + changeSupport.addPropertyChangeListener(listener); + } - /** - * @param listener - */ - public void addPropertyChangeListener(PropertyChangeListener listener) { - changeSupport.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); - } + public void removePropertyChangeListener(PropertyChangeListener listener) { + changeSupport.removePropertyChangeListener(listener); + } - /** - * Returns the gender. Method declared public to satisfy Java bean - * conventions - * - * @return the gender - */ - public int getGender() { - return gender; - } + /** + * Returns the gender. Method declared public to satisfy Java bean + * conventions + * + * @return the gender + */ + public int getGender() { + return gender; + } - void setGender(int gender) { - changeSupport.firePropertyChange("gender", this.gender, - this.gender = gender); - } - } + void setGender(int gender) { + changeSupport.firePropertyChange("gender", this.gender, + this.gender = gender); + } + } } + +void main( String[] args ){ + Snippet007ColorLabelProvider.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet008ComputedValue.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet008ComputedValue.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet008ComputedValue.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * Matthew Hall - bug 260329 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet008ComputedValue; + +import java.lang.all; import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.UpdateValueStrategy; @@ -37,133 +39,137 @@ * @since 3.2 */ public class Snippet008ComputedValue { - /** - * @param args - */ - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); + /** + * @param args + */ + public static void main(String[] args) { + final Display display = new Display(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); - final UI ui = new UI(shell); - final Data data = new Data(); + final UI ui = new UI(shell); + final Data data = new Data(); - // Bind the UI to the Data. - DataBindingContext dbc = new DataBindingContext(); - dbc.bindValue(SWTObservables.observeText(ui.firstName, - SWT.Modify), data.firstName); - dbc.bindValue(SWTObservables.observeText(ui.lastName, - SWT.Modify), data.lastName); + // Bind the UI to the Data. + DataBindingContext dbc = new DataBindingContext(); + dbc.bindValue(SWTObservables.observeText(ui.firstName, + SWT.Modify), data.firstName); + dbc.bindValue(SWTObservables.observeText(ui.lastName, + SWT.Modify), data.lastName); - // Construct the formatted name observable. - FormattedName formattedName = new FormattedName(data.firstName, - data.lastName); + // Construct the formatted name observable. + FormattedName formattedName = new FormattedName(data.firstName, + data.lastName); - // Bind the formatted name Text to the formatted name - // observable. - dbc.bindValue(SWTObservables.observeText(ui.formattedName, - SWT.None), formattedName, new UpdateValueStrategy(false, UpdateValueStrategy.POLICY_NEVER), null); + // Bind the formatted name Text to the formatted name + // observable. + dbc.bindValue(SWTObservables.observeText(ui.formattedName, + SWT.None), formattedName, new UpdateValueStrategy(false, UpdateValueStrategy.POLICY_NEVER), null); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - display.dispose(); - } + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } + }); + display.dispose(); + } - /** - * Creates the formatted name on change of the first or last name - * observables. - *

- * The key to understanding ComputedValue is understanding that it knows of - * the observables that are queried without being told. This is done with - * {@link ObservableTracker} voodoo. When calculate() is invoked - * ObservableTracker records the observables that are - * queried. It then exposes those observables and ComputedValue - * can listen to changes in those objects and react accordingly. - *

- * - * @since 3.2 - */ - static class FormattedName extends ComputedValue { - private IObservableValue firstName; + /** + * Creates the formatted name on change of the first or last name + * observables. + *

+ * The key to understanding ComputedValue is understanding that it knows of + * the observables that are queried without being told. This is done with + * {@link ObservableTracker} voodoo. When calculate() is invoked + * ObservableTracker records the observables that are + * queried. It then exposes those observables and ComputedValue + * can listen to changes in those objects and react accordingly. + *

+ * + * @since 3.2 + */ + static class FormattedName extends ComputedValue { + private IObservableValue firstName; - private IObservableValue lastName; + private IObservableValue lastName; - FormattedName(IObservableValue firstName, IObservableValue lastName) { - this.firstName = firstName; - this.lastName = lastName; - } + FormattedName(IObservableValue firstName, IObservableValue lastName) { + this.firstName = firstName; + this.lastName = lastName; + } - protected Object calculate() { - String lastName = (String) this.lastName.getValue(); - String firstName = (String) this.firstName.getValue(); - lastName = (lastName != null && lastName.length() > 0) ? lastName - : "[Last Name]"; - firstName = (firstName != null && firstName.length() > 0) ? firstName - : "[First Name]"; + protected Object calculate() { + String lastName = (String) this.lastName.getValue(); + String firstName = (String) this.firstName.getValue(); + lastName = (lastName != null && lastName.length() > 0) ? lastName + : "[Last Name]"; + firstName = (firstName != null && firstName.length() > 0) ? firstName + : "[First Name]"; - StringBuffer buffer = new StringBuffer(); - buffer.append(lastName).append(", ").append(firstName); + StringBuffer buffer = new StringBuffer(); + buffer.append(lastName).append(", ").append(firstName); + + return buffer.toString(); + } + } - return buffer.toString(); - } - } + static class Data { + final WritableValue firstName; - static class Data { - final WritableValue firstName; + final WritableValue lastName; - final WritableValue lastName; + Data() { + firstName = new WritableValue("", String.class); + lastName = new WritableValue("", String.class); + } + } - Data() { - firstName = new WritableValue("", String.class); - lastName = new WritableValue("", String.class); - } - } + /** + * Composite that creates the UI. + * + * @since 3.2 + */ + static class UI extends Composite { + final Text firstName; - /** - * Composite that creates the UI. - * - * @since 3.2 - */ - static class UI extends Composite { - final Text firstName; + final Text lastName; - final Text lastName; + final Text formattedName; + + UI(Composite parent) { + super(parent, SWT.NONE); - final Text formattedName; + GridLayoutFactory.swtDefaults().numColumns(2).applyTo(this); - UI(Composite parent) { - super(parent, SWT.NONE); + new Label(this, SWT.NONE).setText("First Name:"); + new Label(this, SWT.NONE).setText("Last Name"); - GridLayoutFactory.swtDefaults().numColumns(2).applyTo(this); - - new Label(this, SWT.NONE).setText("First Name:"); - new Label(this, SWT.NONE).setText("Last Name"); + GridDataFactory gdf = GridDataFactory.swtDefaults().align(SWT.FILL, + SWT.FILL).grab(true, false); + firstName = new Text(this, SWT.BORDER); + gdf.applyTo(firstName); - GridDataFactory gdf = GridDataFactory.swtDefaults().align(SWT.FILL, - SWT.FILL).grab(true, false); - firstName = new Text(this, SWT.BORDER); - gdf.applyTo(firstName); + lastName = new Text(this, SWT.BORDER); + gdf.applyTo(lastName); - lastName = new Text(this, SWT.BORDER); - gdf.applyTo(lastName); + gdf = GridDataFactory.swtDefaults().span(2, 1).grab(true, false) + .align(SWT.FILL, SWT.BEGINNING); + Label label = new Label(this, SWT.NONE); + label.setText("Formatted Name:"); + gdf.applyTo(label); - gdf = GridDataFactory.swtDefaults().span(2, 1).grab(true, false) - .align(SWT.FILL, SWT.BEGINNING); - Label label = new Label(this, SWT.NONE); - label.setText("Formatted Name:"); - gdf.applyTo(label); + formattedName = new Text(this, SWT.BORDER); + formattedName.setEditable(false); + gdf.applyTo(formattedName); + } + } +} - formattedName = new Text(this, SWT.BORDER); - formattedName.setEditable(false); - gdf.applyTo(formattedName); - } - } +void main( String[] args ){ + Snippet008ComputedValue.main(args); } diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet009TableViewer.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet009TableViewer.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet009TableViewer.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * Matthew Hall - bug 260337 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet009TableViewer; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -34,135 +36,139 @@ * Demonstrates binding a TableViewer to a collection. */ public class Snippet009TableViewer { - public static void main(String[] args) { - final Display display = Display.getDefault(); + public static void main(String[] args) { + final Display display = Display.getDefault(); - // In an RCP application, the threading Realm will be set for you - // automatically by the Workbench. In an SWT application, you can do - // this once, wrpping your binding method call. - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { + // In an RCP application, the threading Realm will be set for you + // automatically by the Workbench. In an SWT application, you can do + // this once, wrpping your binding method call. + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); + ViewModel viewModel = new ViewModel(); + Shell shell = new View(viewModel).createShell(); - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - } + // The SWT event loop + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + }); + } - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); + // Minimal JavaBeans support + public static abstract class AbstractModelObject { + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( + this); - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } + public void addPropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(listener); + } - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(propertyName, + listener); + } - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } + public void removePropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(listener); + } - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } + public void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(propertyName, + listener); + } - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } + protected void firePropertyChange(String propertyName, Object oldValue, + Object newValue) { + propertyChangeSupport.firePropertyChange(propertyName, oldValue, + newValue); + } + } - // The data model class. This is normally a persistent class of some sort. - static class Person extends AbstractModelObject { - // A property... - String name = "John Smith"; + // The data model class. This is normally a persistent class of some sort. + static class Person extends AbstractModelObject { + // A property... + String name = "John Smith"; - public Person(String name) { - this.name = name; - } + public Person(String name) { + this.name = name; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - String oldValue = this.name; - this.name = name; - firePropertyChange("name", oldValue, name); - } - } + public void setName(String name) { + String oldValue = this.name; + this.name = name; + firePropertyChange("name", oldValue, name); + } + } - // The View's model--the root of our Model graph for this particular GUI. - // - // Typically each View class has a corresponding ViewModel class. - // The ViewModel is responsible for getting the objects to edit from the - // data access tier. Since this snippet doesn't have any persistent objects - // ro retrieve, this ViewModel just instantiates a model object to edit. - static class ViewModel { - // The model to bind - private List people = new LinkedList(); - { - people.add(new Person("Steve Northover")); - people.add(new Person("Grant Gayed")); - people.add(new Person("Veronika Irvine")); - people.add(new Person("Mike Wilson")); - people.add(new Person("Christophe Cornu")); - people.add(new Person("Lynne Kues")); - people.add(new Person("Silenio Quarti")); - } + // The View's model--the root of our Model graph for this particular GUI. + // + // Typically each View class has a corresponding ViewModel class. + // The ViewModel is responsible for getting the objects to edit from the + // data access tier. Since this snippet doesn't have any persistent objects + // ro retrieve, this ViewModel just instantiates a model object to edit. + static class ViewModel { + // The model to bind + private List people = new LinkedList(); + { + people.add(new Person("Steve Northover")); + people.add(new Person("Grant Gayed")); + people.add(new Person("Veronika Irvine")); + people.add(new Person("Mike Wilson")); + people.add(new Person("Christophe Cornu")); + people.add(new Person("Lynne Kues")); + people.add(new Person("Silenio Quarti")); + } - public List getPeople() { - return people; - } - } + public List getPeople() { + return people; + } + } - // The GUI view - static class View { - private ViewModel viewModel; - private Table committers; + // The GUI view + static class View { + private ViewModel viewModel; + private Table committers; - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } + public View(ViewModel viewModel) { + this.viewModel = viewModel; + } - public Shell createShell() { - // Build a UI - Display display = Display.getDefault(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - committers = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); - committers.setLinesVisible(true); - TableColumn column = new TableColumn(committers, SWT.NONE); + public Shell createShell() { + // Build a UI + Display display = Display.getDefault(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + committers = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); + committers.setLinesVisible(true); + TableColumn column = new TableColumn(committers, SWT.NONE); - // Set up data binding. - TableViewer peopleViewer = new TableViewer(committers); - ViewerSupport.bind(peopleViewer, new WritableList(viewModel - .getPeople(), Person.class), BeanProperties.value( - Person.class, "name")); + // Set up data binding. + TableViewer peopleViewer = new TableViewer(committers); + ViewerSupport.bind(peopleViewer, new WritableList(viewModel + .getPeople(), Person.class), BeanProperties.value( + Person.class, "name")); - column.pack(); + column.pack(); - // Open and return the Shell - shell.setSize(100, 300); - shell.open(); - return shell; - } - } + // Open and return the Shell + shell.setSize(100, 300); + shell.open(); + return shell; + } + } } + +void main( String[] args ){ + Snippet009TableViewer.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet010MasterDetail.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet010MasterDetail.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet010MasterDetail.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * Matthew Hall - bug 260329 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet010MasterDetail; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -36,72 +38,75 @@ * be displayed in a Text widget. */ public class Snippet010MasterDetail { - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(display); - shell.setLayout(new GridLayout()); + public static void main(String[] args) { + final Display display = new Display(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + Shell shell = new Shell(display); + shell.setLayout(new GridLayout()); - Person[] persons = new Person[] { new Person("Me"), - new Person("Myself"), new Person("I") }; + Person[] persons = new Person[] { new Person("Me"), + new Person("Myself"), new Person("I") }; - ListViewer viewer = new ListViewer(shell); - viewer.setContentProvider(new ArrayContentProvider()); - viewer.setInput(persons); + ListViewer viewer = new ListViewer(shell); + viewer.setContentProvider(new ArrayContentProvider()); + viewer.setInput(persons); - Text name = new Text(shell, SWT.BORDER | SWT.READ_ONLY); + Text name = new Text(shell, SWT.BORDER | SWT.READ_ONLY); - // 1. Observe changes in selection. - IObservableValue selection = ViewersObservables - .observeSingleSelection(viewer); + // 1. Observe changes in selection. + IObservableValue selection = ViewersObservables + .observeSingleSelection(viewer); - // 2. Observe the name property of the current selection. - IObservableValue detailObservable = BeansObservables - .observeDetailValue(selection, "name", String.class); + // 2. Observe the name property of the current selection. + IObservableValue detailObservable = BeansObservables + .observeDetailValue(selection, "name", String.class); - // 3. Bind the Text widget to the name detail (selection's - // name). - new DataBindingContext().bindValue(SWTObservables.observeText( - name, SWT.None), detailObservable, - new UpdateValueStrategy(false, - UpdateValueStrategy.POLICY_NEVER), null); + // 3. Bind the Text widget to the name detail (selection's + // name). + new DataBindingContext().bindValue(SWTObservables.observeText( + name, SWT.None), detailObservable, + new UpdateValueStrategy(false, + UpdateValueStrategy.POLICY_NEVER), null); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - display.dispose(); - } + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } + }); + display.dispose(); + } - public static class Person { - private String name; - private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this); + public static class Person { + private String name; + private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this); - Person(String name) { - this.name = name; - } + Person(String name) { + this.name = name; + } - public void addPropertyChangeListener(PropertyChangeListener listener) { - changeSupport.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); - } - - /** - * @return Returns the name. - */ - public String getName() { - return name; - } + public void addPropertyChangeListener(PropertyChangeListener listener) { + changeSupport.addPropertyChangeListener(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + changeSupport.removePropertyChangeListener(listener); + } + + /** + * @return Returns the name. + */ + public String getName() { + return name; + } - public String toString() { - return name; - } - } + public String toString() { + return name; + } + } } +void main( String[] args ){ + Snippet010MasterDetail.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet011ValidateMultipleBindingsSnippet.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet011ValidateMultipleBindingsSnippet.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet011ValidateMultipleBindingsSnippet.d Wed Apr 22 18:59:26 2009 +0200 @@ -9,7 +9,9 @@ * Brad Reynolds - initial API and implementation ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet011ValidateMultipleBindingsSnippet; + +import java.lang.all; import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.UpdateValueStrategy; @@ -37,93 +39,96 @@ * @author Brad Reynolds */ public class Snippet011ValidateMultipleBindingsSnippet { - public static void main(String[] args) { - Realm.runWithDefault(SWTObservables.getRealm(Display.getDefault()), - new Runnable() { - public void run() { - Snippet011ValidateMultipleBindingsSnippet.run(); - } - }); - } + public static void main(String[] args) { + Realm.runWithDefault(SWTObservables.getRealm(Display.getDefault()), + new Runnable() { + public void run() { + Snippet011ValidateMultipleBindingsSnippet.run(); + } + }); + } - private static void run() { - Shell shell = new Shell(); + private static void run() { + Shell shell = new Shell(); - View view = new View(shell); - final Model model = new Model(); + View view = new View(shell); + final Model model = new Model(); - DataBindingContext dbc = new DataBindingContext(); - dbc.bindValue(SWTObservables.observeText(view.text1, SWT.Modify), - model.value1, new UpdateValueStrategy() - .setAfterConvertValidator(new CrossFieldValidator( - model.value2)), null); - dbc.bindValue(SWTObservables.observeText(view.text2, SWT.Modify), - model.value2, new UpdateValueStrategy() - .setAfterConvertValidator(new CrossFieldValidator( - model.value1)), null); + DataBindingContext dbc = new DataBindingContext(); + dbc.bindValue(SWTObservables.observeText(view.text1, SWT.Modify), + model.value1, new UpdateValueStrategy() + .setAfterConvertValidator(new CrossFieldValidator( + model.value2)), null); + dbc.bindValue(SWTObservables.observeText(view.text2, SWT.Modify), + model.value2, new UpdateValueStrategy() + .setAfterConvertValidator(new CrossFieldValidator( + model.value1)), null); - // DEBUG - print to show value change - model.value1.addValueChangeListener(new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - System.out.println("Value 1: " + model.value1.getValue()); - } - }); + // DEBUG - print to show value change + model.value1.addValueChangeListener(new IValueChangeListener() { + public void handleValueChange(ValueChangeEvent event) { + System.out.println("Value 1: " + model.value1.getValue()); + } + }); - // DEBUG - print to show value change - model.value2.addValueChangeListener(new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - System.out.println("Value 2: " + model.value2.getValue()); - } - }); + // DEBUG - print to show value change + model.value2.addValueChangeListener(new IValueChangeListener() { + public void handleValueChange(ValueChangeEvent event) { + System.out.println("Value 2: " + model.value2.getValue()); + } + }); - shell.pack(); - shell.open(); - Display display = shell.getDisplay(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } + shell.pack(); + shell.open(); + Display display = shell.getDisplay(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } - /** - * @since 3.2 - * - */ - private static final class CrossFieldValidator implements IValidator { - /** - * - */ - private final IObservableValue other; + /** + * @since 3.2 + * + */ + private static final class CrossFieldValidator implements IValidator { + /** + * + */ + private final IObservableValue other; + + /** + * @param model + */ + private CrossFieldValidator(IObservableValue other) { + this.other = other; + } - /** - * @param model - */ - private CrossFieldValidator(IObservableValue other) { - this.other = other; - } + public IStatus validate(Object value) { + if (!value.equals(other.getValue())) { + return ValidationStatus.ok(); + } + return ValidationStatus.error("values cannot be the same"); + } + } - public IStatus validate(Object value) { - if (!value.equals(other.getValue())) { - return ValidationStatus.ok(); - } - return ValidationStatus.error("values cannot be the same"); - } - } + static class Model { + WritableValue value1 = new WritableValue(); + WritableValue value2 = new WritableValue(); + } - static class Model { - WritableValue value1 = new WritableValue(); - WritableValue value2 = new WritableValue(); - } + static class View { + Text text1; + Text text2; - static class View { - Text text1; - Text text2; - - View(Composite composite) { - composite.setLayout(new GridLayout(2, true)); - text1 = new Text(composite, SWT.BORDER); - text2 = new Text(composite, SWT.BORDER); - } - } + View(Composite composite) { + composite.setLayout(new GridLayout(2, true)); + text1 = new Text(composite, SWT.BORDER); + text2 = new Text(composite, SWT.BORDER); + } + } } +void main( String[] args ){ + Snippet011ValidateMultipleBindingsSnippet.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet012CompositeUpdater.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet012CompositeUpdater.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet012CompositeUpdater.d Wed Apr 22 18:59:26 2009 +0200 @@ -9,7 +9,9 @@ * IBM Corporation - initial API and implementation ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet012CompositeUpdater; + +import java.lang.all; import java.util.Timer; import java.util.TimerTask; @@ -36,77 +38,80 @@ */ public class Snippet012CompositeUpdater { - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(display); + public static void main(String[] args) { + final Display display = new Display(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + Shell shell = new Shell(display); - final WritableList list = new WritableList(); + final WritableList list = new WritableList(); - Button button = new Button(shell, SWT.PUSH); - button.setText("add"); - button.addSelectionListener(new SelectionAdapter() { - public void widgetSelected( - org.eclipse.swt.events.SelectionEvent e) { - list.add(0, new Counter()); - } - }); + Button button = new Button(shell, SWT.PUSH); + button.setText("add"); + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected( + org.eclipse.swt.events.SelectionEvent e) { + list.add(0, new Counter()); + } + }); - final Composite composite = new Composite(shell, SWT.None); + final Composite composite = new Composite(shell, SWT.None); - new CompositeUpdater(composite, list) { - protected Widget createWidget(int index) { - Label label = new Label(composite, SWT.BORDER); - //requestLayout(label); - return label; - } + new CompositeUpdater(composite, list) { + protected Widget createWidget(int index) { + Label label = new Label(composite, SWT.BORDER); + //requestLayout(label); + return label; + } - protected void updateWidget(Widget widget, Object element) { - ((Label) widget).setText(((Counter) element).getValue() - + ""); - requestLayout((Label)widget); - } - }; - GridLayoutFactory.fillDefaults().numColumns(10).generateLayout(composite); + protected void updateWidget(Widget widget, Object element) { + ((Label) widget).setText(((Counter) element).getValue() + + ""); + requestLayout((Label)widget); + } + }; + GridLayoutFactory.fillDefaults().numColumns(10).generateLayout(composite); - GridDataFactory.fillDefaults().grab(true, true).applyTo( - composite); + GridDataFactory.fillDefaults().grab(true, true).applyTo( + composite); - GridLayoutFactory.fillDefaults().generateLayout(shell); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - display.dispose(); - } + GridLayoutFactory.fillDefaults().generateLayout(shell); + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } + }); + display.dispose(); + } - static Timer timer = new Timer(true); + static Timer timer = new Timer(true); + + static class Counter extends WritableValue { + Counter() { + super(new Integer(0), Integer.class); + scheduleIncrementTask(); + } - static class Counter extends WritableValue { - Counter() { - super(new Integer(0), Integer.class); - scheduleIncrementTask(); - } - - private void scheduleIncrementTask() { - timer.schedule(new TimerTask() { - public void run() { - // we have to get onto the realm (UI thread) to perform the - // increment - getRealm().asyncExec(new Runnable() { - public void run() { - Integer currentVal = (Integer) getValue(); - setValue(new Integer(currentVal.intValue() + 1)); - } - }); - scheduleIncrementTask(); - } - }, 1000); - } - } + private void scheduleIncrementTask() { + timer.schedule(new TimerTask() { + public void run() { + // we have to get onto the realm (UI thread) to perform the + // increment + getRealm().asyncExec(new Runnable() { + public void run() { + Integer currentVal = (Integer) getValue(); + setValue(new Integer(currentVal.intValue() + 1)); + } + }); + scheduleIncrementTask(); + } + }, 1000); + } + } } +void main( String[] args ){ + Snippet012CompositeUpdater.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet013TableViewerEditing.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet013TableViewerEditing.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet013TableViewerEditing.d Wed Apr 22 18:59:26 2009 +0200 @@ -11,7 +11,9 @@ * Matthew Hall - bugs 260329, 260337 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet013TableViewerEditing; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -46,191 +48,194 @@ * Demonstrates binding a TableViewer to a collection using the 3.3 Viewer APIs. */ public class Snippet013TableViewerEditing { - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); + public static void main(String[] args) { + final Display display = new Display(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + ViewModel viewModel = new ViewModel(); + Shell shell = new View(viewModel).createShell(); - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - } + // The SWT event loop + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + }); + } - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); + // Minimal JavaBeans support + public static abstract class AbstractModelObject { + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( + this); - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } + public void addPropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(listener); + } - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(propertyName, + listener); + } - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } + public void removePropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(listener); + } - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } + public void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(propertyName, + listener); + } - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } + protected void firePropertyChange(String propertyName, Object oldValue, + Object newValue) { + propertyChangeSupport.firePropertyChange(propertyName, oldValue, + newValue); + } + } - // The data model class. This is normally a persistent class of some sort. - static class Person extends AbstractModelObject { - // A property... - String name = "John Smith"; + // The data model class. This is normally a persistent class of some sort. + static class Person extends AbstractModelObject { + // A property... + String name = "John Smith"; - public Person(String name) { - this.name = name; - } + public Person(String name) { + this.name = name; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - String oldValue = this.name; - this.name = name; - firePropertyChange("name", oldValue, name); - } - } + public void setName(String name) { + String oldValue = this.name; + this.name = name; + firePropertyChange("name", oldValue, name); + } + } - // The View's model--the root of our Model graph for this particular GUI. - // - // Typically each View class has a corresponding ViewModel class. - // The ViewModel is responsible for getting the objects to edit from the - // data access tier. Since this snippet doesn't have any persistent objects - // ro retrieve, this ViewModel just instantiates a model object to edit. - static class ViewModel { - // The model to bind - private List people = new LinkedList(); - { - people.add(new Person("Steve Northover")); - people.add(new Person("Grant Gayed")); - people.add(new Person("Veronika Irvine")); - people.add(new Person("Mike Wilson")); - people.add(new Person("Christophe Cornu")); - people.add(new Person("Lynne Kues")); - people.add(new Person("Silenio Quarti")); - } + // The View's model--the root of our Model graph for this particular GUI. + // + // Typically each View class has a corresponding ViewModel class. + // The ViewModel is responsible for getting the objects to edit from the + // data access tier. Since this snippet doesn't have any persistent objects + // ro retrieve, this ViewModel just instantiates a model object to edit. + static class ViewModel { + // The model to bind + private List people = new LinkedList(); + { + people.add(new Person("Steve Northover")); + people.add(new Person("Grant Gayed")); + people.add(new Person("Veronika Irvine")); + people.add(new Person("Mike Wilson")); + people.add(new Person("Christophe Cornu")); + people.add(new Person("Lynne Kues")); + people.add(new Person("Silenio Quarti")); + } - public List getPeople() { - return people; - } - } + public List getPeople() { + return people; + } + } - /** - * Editing support that uses JFace Data Binding to control the editing - * lifecycle. The standard EditingSupport get/setValue(...) lifecycle is not - * used. - * - * @since 3.3 - */ - private static class InlineEditingSupport extends - ObservableValueEditingSupport { - private CellEditor cellEditor; + /** + * Editing support that uses JFace Data Binding to control the editing + * lifecycle. The standard EditingSupport get/setValue(...) lifecycle is not + * used. + * + * @since 3.3 + */ + private static class InlineEditingSupport extends + ObservableValueEditingSupport { + private CellEditor cellEditor; - /** - * @param viewer - * @param dbc - */ - public InlineEditingSupport(ColumnViewer viewer, DataBindingContext dbc) { + /** + * @param viewer + * @param dbc + */ + public InlineEditingSupport(ColumnViewer viewer, DataBindingContext dbc) { - super(viewer, dbc); - cellEditor = new TextCellEditor((Composite) viewer.getControl()); - } + super(viewer, dbc); + cellEditor = new TextCellEditor((Composite) viewer.getControl()); + } - protected CellEditor getCellEditor(Object element) { - return cellEditor; - } + protected CellEditor getCellEditor(Object element) { + return cellEditor; + } - protected IObservableValue doCreateCellEditorObservable( - CellEditor cellEditor) { + protected IObservableValue doCreateCellEditorObservable( + CellEditor cellEditor) { - return SWTObservables.observeText(cellEditor.getControl(), - SWT.Modify); - } + return SWTObservables.observeText(cellEditor.getControl(), + SWT.Modify); + } - protected IObservableValue doCreateElementObservable(Object element, - ViewerCell cell) { - return BeansObservables.observeValue(element, "name"); - } - } + protected IObservableValue doCreateElementObservable(Object element, + ViewerCell cell) { + return BeansObservables.observeValue(element, "name"); + } + } - // The GUI view - static class View { - private ViewModel viewModel; - private Table committers; - private Label selectedCommitter; + // The GUI view + static class View { + private ViewModel viewModel; + private Table committers; + private Label selectedCommitter; - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } + public View(ViewModel viewModel) { + this.viewModel = viewModel; + } - public Shell createShell() { - // Build a UI - Display display = Display.getDefault(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout(SWT.VERTICAL)); - committers = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); - committers.setLinesVisible(true); + public Shell createShell() { + // Build a UI + Display display = Display.getDefault(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout(SWT.VERTICAL)); + committers = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); + committers.setLinesVisible(true); - selectedCommitter = new Label(shell, SWT.NONE); - // Set up data binding. In an RCP application, the threading - // Realm - // will be set for you automatically by the Workbench. In an SWT - // application, you can do this once, wrpping your binding - // method call. - DataBindingContext bindingContext = new DataBindingContext(); - bindGUI(bindingContext); + selectedCommitter = new Label(shell, SWT.NONE); + // Set up data binding. In an RCP application, the threading + // Realm + // will be set for you automatically by the Workbench. In an SWT + // application, you can do this once, wrpping your binding + // method call. + DataBindingContext bindingContext = new DataBindingContext(); + bindGUI(bindingContext); - // Open and return the Shell - shell.setSize(100, 300); - shell.open(); - return shell; - } + // Open and return the Shell + shell.setSize(100, 300); + shell.open(); + return shell; + } - protected void bindGUI(DataBindingContext bindingContext) { - // Since we're using a JFace Viewer, we do first wrap our Table... - TableViewer peopleViewer = new TableViewer(committers); - TableViewerColumn column = new TableViewerColumn(peopleViewer, - SWT.NONE); - column.setEditingSupport(new InlineEditingSupport(peopleViewer, - bindingContext)); - column.getColumn().setWidth(100); + protected void bindGUI(DataBindingContext bindingContext) { + // Since we're using a JFace Viewer, we do first wrap our Table... + TableViewer peopleViewer = new TableViewer(committers); + TableViewerColumn column = new TableViewerColumn(peopleViewer, + SWT.NONE); + column.setEditingSupport(new InlineEditingSupport(peopleViewer, + bindingContext)); + column.getColumn().setWidth(100); - // Bind viewer to model - ViewerSupport.bind(peopleViewer, new WritableList(viewModel - .getPeople(), Person.class), BeanProperties.value( - Person.class, "name")); + // Bind viewer to model + ViewerSupport.bind(peopleViewer, new WritableList(viewModel + .getPeople(), Person.class), BeanProperties.value( + Person.class, "name")); - // bind selectedCommitter label to the name of the current selection - IObservableValue selection = ViewersObservables - .observeSingleSelection(peopleViewer); - bindingContext.bindValue(SWTObservables - .observeText(selectedCommitter), BeansObservables - .observeDetailValue(selection, "name", String.class)); - } - } + // bind selectedCommitter label to the name of the current selection + IObservableValue selection = ViewersObservables + .observeSingleSelection(peopleViewer); + bindingContext.bindValue(SWTObservables + .observeText(selectedCommitter), BeansObservables + .observeDetailValue(selection, "name", String.class)); + } + } } +void main( String[] args ){ + Snippet013TableViewerEditing.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet014WizardDialog.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet014WizardDialog.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet014WizardDialog.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * Matthew Hall - bug 260329 *******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet014WizardDialog; + +import java.lang.all; import java.util.Date; @@ -42,120 +44,123 @@ */ public class Snippet014WizardDialog { - static class FirstWizardPage extends WizardPage { - private final class SingleDigitValidator implements IValidator { - public IStatus validate(Object value) { - Integer i = (Integer) value; - if (i == null) { - return ValidationStatus - .info("Please enter a value."); - } - if (i.intValue() < 0 || i.intValue() > 9) { - return ValidationStatus - .error("Value must be between 0 and 9."); - } - return ValidationStatus.ok(); - } - } + static class FirstWizardPage extends WizardPage { + private final class SingleDigitValidator implements IValidator { + public IStatus validate(Object value) { + Integer i = (Integer) value; + if (i == null) { + return ValidationStatus + .info("Please enter a value."); + } + if (i.intValue() < 0 || i.intValue() > 9) { + return ValidationStatus + .error("Value must be between 0 and 9."); + } + return ValidationStatus.ok(); + } + } - protected FirstWizardPage() { - super("First", "First Page", ImageDescriptor - .createFromImage(new Image(Display.getDefault(), 16, 16))); - } + protected FirstWizardPage() { + super("First", "First Page", ImageDescriptor + .createFromImage(new Image(Display.getDefault(), 16, 16))); + } - public void createControl(Composite parent) { - DataBindingContext dbc = new DataBindingContext(); - WizardPageSupport.create(this, dbc); - Composite composite = new Composite(parent, SWT.NONE); - Label label = new Label(composite, SWT.NONE); - label.setText("Enter a number between 0 and 9:"); - Text text = new Text(composite, SWT.BORDER); - - dbc.bindValue( - SWTObservables.observeText(text, SWT.Modify), - ((SampleWizard) getWizard()).getModel().intValue, - new UpdateValueStrategy().setAfterConvertValidator(new SingleDigitValidator()), - null); - - GridLayoutFactory.swtDefaults().numColumns(2).generateLayout( - composite); - setControl(composite); - } - } + public void createControl(Composite parent) { + DataBindingContext dbc = new DataBindingContext(); + WizardPageSupport.create(this, dbc); + Composite composite = new Composite(parent, SWT.NONE); + Label label = new Label(composite, SWT.NONE); + label.setText("Enter a number between 0 and 9:"); + Text text = new Text(composite, SWT.BORDER); + + dbc.bindValue( + SWTObservables.observeText(text, SWT.Modify), + ((SampleWizard) getWizard()).getModel().intValue, + new UpdateValueStrategy().setAfterConvertValidator(new SingleDigitValidator()), + null); + + GridLayoutFactory.swtDefaults().numColumns(2).generateLayout( + composite); + setControl(composite); + } + } - static class SecondWizardPage extends WizardPage { - protected SecondWizardPage() { - super("Second", "Second Page", ImageDescriptor - .createFromImage(new Image(Display.getDefault(), 16, 16))); - } + static class SecondWizardPage extends WizardPage { + protected SecondWizardPage() { + super("Second", "Second Page", ImageDescriptor + .createFromImage(new Image(Display.getDefault(), 16, 16))); + } - public void createControl(Composite parent) { - DataBindingContext dbc = new DataBindingContext(); - WizardPageSupport.create(this, dbc); - Composite composite = new Composite(parent, SWT.NONE); - Label label = new Label(composite, SWT.NONE); - label.setText("Enter a date:"); - Text text = new Text(composite, SWT.BORDER); - - dbc.bindValue( - SWTObservables.observeText(text, SWT.Modify), - ((SampleWizard) getWizard()).getModel().dateValue); + public void createControl(Composite parent) { + DataBindingContext dbc = new DataBindingContext(); + WizardPageSupport.create(this, dbc); + Composite composite = new Composite(parent, SWT.NONE); + Label label = new Label(composite, SWT.NONE); + label.setText("Enter a date:"); + Text text = new Text(composite, SWT.BORDER); + + dbc.bindValue( + SWTObservables.observeText(text, SWT.Modify), + ((SampleWizard) getWizard()).getModel().dateValue); - GridLayoutFactory.swtDefaults().numColumns(2).generateLayout( - composite); - setControl(composite); - } - } + GridLayoutFactory.swtDefaults().numColumns(2).generateLayout( + composite); + setControl(composite); + } + } - static class SampleWizardModel { - IObservableValue intValue = new WritableValue(null, Integer.class); - IObservableValue dateValue = new WritableValue(null, Date.class); - } + static class SampleWizardModel { + IObservableValue intValue = new WritableValue(null, Integer.class); + IObservableValue dateValue = new WritableValue(null, Date.class); + } - static class SampleWizard extends Wizard { + static class SampleWizard extends Wizard { - private SampleWizardModel model = new SampleWizardModel(); + private SampleWizardModel model = new SampleWizardModel(); - public void addPages() { - addPage(new FirstWizardPage()); - addPage(new SecondWizardPage()); - } + public void addPages() { + addPage(new FirstWizardPage()); + addPage(new SecondWizardPage()); + } - public SampleWizardModel getModel() { - return model; - } - - public String getWindowTitle() { - return "Data Binding Snippet014"; - } + public SampleWizardModel getModel() { + return model; + } + + public String getWindowTitle() { + return "Data Binding Snippet014"; + } - public boolean performFinish() { - return true; - } + public bool performFinish() { + return true; + } - } + } - public static void main(String[] args) { - Display display = new Display(); + public static void main(String[] args) { + Display display = new Display(); - // note that the "runWithDefault" will be done for you if you are using - // the - // Workbench as opposed to just JFace/SWT. - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - IWizard wizard = new SampleWizard(); - WizardDialog dialog = new WizardDialog(null, wizard); - dialog.open(); - // The SWT event loop - Display display = Display.getCurrent(); - while (dialog.getShell() != null - && !dialog.getShell().isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - } + // note that the "runWithDefault" will be done for you if you are using + // the + // Workbench as opposed to just JFace/SWT. + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + IWizard wizard = new SampleWizard(); + WizardDialog dialog = new WizardDialog(null, wizard); + dialog.open(); + // The SWT event loop + Display display = Display.getCurrent(); + while (dialog.getShell() != null + && !dialog.getShell().isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + }); + } } +void main( String[] args ){ + Snippet014WizardDialog.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet015DelayTextModifyEvents.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet015DelayTextModifyEvents.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet015DelayTextModifyEvents.d Wed Apr 22 18:59:26 2009 +0200 @@ -4,11 +4,13 @@ * accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Matthew Hall - initial API and implementation (bug 180746) - * Boris Bokowski, IBM - initial API and implementation + * Matthew Hall - initial API and implementation (bug 180746) + * Boris Bokowski, IBM - initial API and implementation * Matthew Hall - bugs 260329, 264286 ***********************************************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet015DelayTextModifyEvents; + +import java.lang.all; import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.observable.Observables; @@ -34,86 +36,89 @@ public class Snippet015DelayTextModifyEvents { - private static void createControls(Shell shell) { - final Label field1 = createLabel(shell, SWT.NONE, "Field 1 "); + private static void createControls(Shell shell) { + final Label field1 = createLabel(shell, SWT.NONE, "Field 1 "); - Text text1 = new Text(shell, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).hint(200, SWT.DEFAULT) - .applyTo(text1); - createLabel(shell, SWT.NONE, "200ms delay"); + Text text1 = new Text(shell, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).hint(200, SWT.DEFAULT) + .applyTo(text1); + createLabel(shell, SWT.NONE, "200ms delay"); - final Label field2 = createLabel(shell, SWT.NONE, "Field 2 "); + final Label field2 = createLabel(shell, SWT.NONE, "Field 2 "); - Text text2 = new Text(shell, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).hint(200, SWT.DEFAULT) - .applyTo(text2); + Text text2 = new Text(shell, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).hint(200, SWT.DEFAULT) + .applyTo(text2); - createLabel(shell, SWT.NONE, "1000ms delay"); + createLabel(shell, SWT.NONE, "1000ms delay"); - final ISWTObservableValue delayed1 = WidgetProperties.text(SWT.Modify) - .observeDelayed(200, text1); - final ISWTObservableValue delayed2 = WidgetProperties.text(SWT.Modify) - .observeDelayed(1000, text2); + final ISWTObservableValue delayed1 = WidgetProperties.text(SWT.Modify) + .observeDelayed(200, text1); + final ISWTObservableValue delayed2 = WidgetProperties.text(SWT.Modify) + .observeDelayed(1000, text2); - // (In a real application,you would want to dispose the resource manager - // when you are done with it) - ResourceManager resourceManager = new LocalResourceManager( - JFaceResources.getResources()); - final Font shellFont = shell.getFont(); - final Font italicFont = resourceManager.createFont(FontDescriptor - .createFrom(shellFont).setStyle(SWT.ITALIC)); + // (In a real application,you would want to dispose the resource manager + // when you are done with it) + ResourceManager resourceManager = new LocalResourceManager( + JFaceResources.getResources()); + final Font shellFont = shell.getFont(); + final Font italicFont = resourceManager.createFont(FontDescriptor + .createFrom(shellFont).setStyle(SWT.ITALIC)); - final IObservableValue stale1 = Observables.observeStale(delayed1); - new ControlUpdater(field2) { - protected void updateControl() { - boolean stale = ((Boolean) stale1.getValue()).booleanValue(); - field2.setFont(stale ? italicFont : shellFont); - } - }; + final IObservableValue stale1 = Observables.observeStale(delayed1); + new ControlUpdater(field2) { + protected void updateControl() { + bool stale = ((bool) stale1.getValue()).booleanValue(); + field2.setFont(stale ? italicFont : shellFont); + } + }; - final IObservableValue stale2 = Observables.observeStale(delayed2); - new ControlUpdater(field1) { - protected void updateControl() { - boolean stale = ((Boolean) stale2.getValue()).booleanValue(); - field1.setFont(stale ? italicFont : shellFont); - } - }; + final IObservableValue stale2 = Observables.observeStale(delayed2); + new ControlUpdater(field1) { + protected void updateControl() { + bool stale = ((bool) stale2.getValue()).booleanValue(); + field1.setFont(stale ? italicFont : shellFont); + } + }; - String info = "Pending changes are applied immediately if the observed control loses focus"; - GridDataFactory.fillDefaults().span(3, 1).applyTo( - createLabel(shell, SWT.WRAP, info)); + String info = "Pending changes are applied immediately if the observed control loses focus"; + GridDataFactory.fillDefaults().span(3, 1).applyTo( + createLabel(shell, SWT.WRAP, info)); - DataBindingContext dbc = new DataBindingContext(); + DataBindingContext dbc = new DataBindingContext(); - dbc.bindValue(delayed1, delayed2); - } + dbc.bindValue(delayed1, delayed2); + } - private static Label createLabel(Composite parent, int style, String text) { - Label label = new Label(parent, style); - label.setText(text); - return label; - } + private static Label createLabel(Composite parent, int style, String text) { + Label label = new Label(parent, style); + label.setText(text); + return label; + } - public static void main(String[] args) { - final Display display = new Display(); + public static void main(String[] args) { + final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(); - shell.setLayout(new GridLayout(3, false)); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + Shell shell = new Shell(); + shell.setLayout(new GridLayout(3, false)); - createControls(shell); + createControls(shell); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) - if (!display.readAndDispatch()) - display.sleep(); - } + shell.pack(); + shell.open(); + while (!shell.isDisposed()) + if (!display.readAndDispatch()) + display.sleep(); + } - }); + }); - display.dispose(); - } + display.dispose(); + } } +void main( String[] args ){ + Snippet015DelayTextModifyEvents.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet016TableUpdater.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet016TableUpdater.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet016TableUpdater.d Wed Apr 22 18:59:26 2009 +0200 @@ -9,7 +9,9 @@ * IBM Corporation - initial API and implementation ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet016TableUpdater; + +import java.lang.all; import org.eclipse.core.databinding.observable.Realm; import org.eclipse.core.databinding.observable.list.WritableList; @@ -28,59 +30,62 @@ * */ public class Snippet016TableUpdater { - public static void main(String[] args) { - final Display display = new Display(); + public static void main(String[] args) { + final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - final Shell shell = createShell(display); - GridLayoutFactory.fillDefaults().generateLayout(shell); - shell.open(); - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - } + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + final Shell shell = createShell(display); + GridLayoutFactory.fillDefaults().generateLayout(shell); + shell.open(); + // The SWT event loop + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + }); + } - static class Stuff { - private WritableValue counter = new WritableValue(new Integer(1), Integer.class); + static class Stuff { + private WritableValue counter = new WritableValue(new Integer(1), Integer.class); - public Stuff(final Display display) { - display.timerExec(1000, new Runnable() { - public void run() { - counter.setValue(new Integer(1 + ((Integer) counter - .getValue()).intValue())); - display.timerExec(1000, this); - } - }); - } - - public String toString() { - return counter.getValue().toString(); - } - } + public Stuff(final Display display) { + display.timerExec(1000, new Runnable() { + public void run() { + counter.setValue(new Integer(1 + ((Integer) counter + .getValue()).intValue())); + display.timerExec(1000, this); + } + }); + } + + public String toString() { + return counter.getValue().toString(); + } + } - protected static Shell createShell(final Display display) { - Shell shell = new Shell(); - Table t = new Table(shell, SWT.VIRTUAL); - final WritableList list = new WritableList(); - new TableUpdater(t, list) { + protected static Shell createShell(final Display display) { + Shell shell = new Shell(); + Table t = new Table(shell, SWT.VIRTUAL); + final WritableList list = new WritableList(); + new TableUpdater(t, list) { - protected void updateItem(int index, TableItem item, Object element) { - item.setText(element.toString()); - } - }; - display.timerExec(2000, new Runnable() { - public void run() { - list.add(new Stuff(display)); - display.timerExec(2000, this); - } - }); - return shell; - } + protected void updateItem(int index, TableItem item, Object element) { + item.setText(element.toString()); + } + }; + display.timerExec(2000, new Runnable() { + public void run() { + list.add(new Stuff(display)); + display.timerExec(2000, this); + } + }); + return shell; + } } +void main( String[] args ){ + Snippet016TableUpdater.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet017TableViewerWithDerivedColumns.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet017TableViewerWithDerivedColumns.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet017TableViewerWithDerivedColumns.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * Matthew Hall - bugs 260329, 260337 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet017TableViewerWithDerivedColumns; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -44,237 +46,240 @@ * Demonstrates binding a TableViewer to a collection. */ public class Snippet017TableViewerWithDerivedColumns { - public static void main(String[] args) { - final Display display = new Display(); + public static void main(String[] args) { + final Display display = new Display(); - // Set up data binding. In an RCP application, the threading Realm - // will be set for you automatically by the Workbench. In an SWT - // application, you can do this once, wrapping your binding - // method call. - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); + // Set up data binding. In an RCP application, the threading Realm + // will be set for you automatically by the Workbench. In an SWT + // application, you can do this once, wrapping your binding + // method call. + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + ViewModel viewModel = new ViewModel(); + Shell shell = new View(viewModel).createShell(); - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - } + // The SWT event loop + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + }); + } - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); + // Minimal JavaBeans support + public static abstract class AbstractModelObject { + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( + this); - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } + public void addPropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(listener); + } - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(propertyName, + listener); + } - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } + public void removePropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(listener); + } - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } + public void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(propertyName, + listener); + } - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } + protected void firePropertyChange(String propertyName, Object oldValue, + Object newValue) { + propertyChangeSupport.firePropertyChange(propertyName, oldValue, + newValue); + } + } - private static Person UNKNOWN = new Person("unknown", null, null); + private static Person UNKNOWN = new Person("unknown", null, null); - // The data model class. This is normally a persistent class of some sort. - static class Person extends AbstractModelObject { - // A property... - String name = "Donald Duck"; - Person mother; - Person father; + // The data model class. This is normally a persistent class of some sort. + static class Person extends AbstractModelObject { + // A property... + String name = "Donald Duck"; + Person mother; + Person father; - public Person(String name, Person mother, Person father) { - this.name = name; - this.mother = mother; - this.father = father; - } + public Person(String name, Person mother, Person father) { + this.name = name; + this.mother = mother; + this.father = father; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - String oldValue = this.name; - this.name = name; - firePropertyChange("name", oldValue, name); - } + public void setName(String name) { + String oldValue = this.name; + this.name = name; + firePropertyChange("name", oldValue, name); + } - public Person getMother() { - return mother; - } + public Person getMother() { + return mother; + } - public void setMother(Person mother) { - firePropertyChange("mother", this.mother, this.mother = mother); - } + public void setMother(Person mother) { + firePropertyChange("mother", this.mother, this.mother = mother); + } - public Person getFather() { - return father; - } + public Person getFather() { + return father; + } - public void setFather(Person father) { - firePropertyChange("father", this.father, this.father = father); - } + public void setFather(Person father) { + firePropertyChange("father", this.father, this.father = father); + } - public String toString() { - return name; - } - } + public String toString() { + return name; + } + } - // The View's model--the root of our Model graph for this particular GUI. - // - // Typically each View class has a corresponding ViewModel class. - // The ViewModel is responsible for getting the objects to edit from the - // data access tier. Since this snippet doesn't have any persistent objects - // ro retrieve, this ViewModel just instantiates a model object to edit. - static class ViewModel { - // The model to bind - private IObservableList people = new WritableList(); - { - Person fergus = new Person("Fergus McDuck", UNKNOWN, UNKNOWN); - Person downy = new Person("Downy O'Drake", UNKNOWN, UNKNOWN); - Person scrooge = new Person("Scrooge McDuck", downy, fergus); - Person hortense = new Person("Hortense McDuck", downy, fergus); - Person quackmore = new Person("Quackmore Duck", UNKNOWN, UNKNOWN); - Person della = new Person("Della Duck", hortense, quackmore); - Person donald = new Person("Donald Duck", hortense, quackmore); - donald.setFather(quackmore); - donald.setMother(hortense); - della.setFather(quackmore); - della.setMother(hortense); - hortense.setMother(downy); - hortense.setFather(fergus); - scrooge.setMother(downy); - scrooge.setFather(fergus); - people.add(UNKNOWN); - people.add(downy); - people.add(fergus); - people.add(scrooge); - people.add(quackmore); - people.add(hortense); - people.add(della); - people.add(donald); - } + // The View's model--the root of our Model graph for this particular GUI. + // + // Typically each View class has a corresponding ViewModel class. + // The ViewModel is responsible for getting the objects to edit from the + // data access tier. Since this snippet doesn't have any persistent objects + // ro retrieve, this ViewModel just instantiates a model object to edit. + static class ViewModel { + // The model to bind + private IObservableList people = new WritableList(); + { + Person fergus = new Person("Fergus McDuck", UNKNOWN, UNKNOWN); + Person downy = new Person("Downy O'Drake", UNKNOWN, UNKNOWN); + Person scrooge = new Person("Scrooge McDuck", downy, fergus); + Person hortense = new Person("Hortense McDuck", downy, fergus); + Person quackmore = new Person("Quackmore Duck", UNKNOWN, UNKNOWN); + Person della = new Person("Della Duck", hortense, quackmore); + Person donald = new Person("Donald Duck", hortense, quackmore); + donald.setFather(quackmore); + donald.setMother(hortense); + della.setFather(quackmore); + della.setMother(hortense); + hortense.setMother(downy); + hortense.setFather(fergus); + scrooge.setMother(downy); + scrooge.setFather(fergus); + people.add(UNKNOWN); + people.add(downy); + people.add(fergus); + people.add(scrooge); + people.add(quackmore); + people.add(hortense); + people.add(della); + people.add(donald); + } - public IObservableList getPeople() { - return people; - } - } + public IObservableList getPeople() { + return people; + } + } - // The GUI view - static class View { - private ViewModel viewModel; - private Table duckFamily; - private Text nameText; - private Combo motherCombo; - private Combo fatherCombo; + // The GUI view + static class View { + private ViewModel viewModel; + private Table duckFamily; + private Text nameText; + private Combo motherCombo; + private Combo fatherCombo; - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } + public View(ViewModel viewModel) { + this.viewModel = viewModel; + } - public Shell createShell() { - // Build a UI - Display display = Display.getDefault(); - Shell shell = new Shell(display); - duckFamily = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); - duckFamily.setHeaderVisible(true); - GridDataFactory.defaultsFor(duckFamily).span(2, 1).applyTo( - duckFamily); - createColumn("Name"); - createColumn("Mother"); - createColumn("Father"); - createColumn("Grandmother"); - duckFamily.setLinesVisible(true); + public Shell createShell() { + // Build a UI + Display display = Display.getDefault(); + Shell shell = new Shell(display); + duckFamily = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); + duckFamily.setHeaderVisible(true); + GridDataFactory.defaultsFor(duckFamily).span(2, 1).applyTo( + duckFamily); + createColumn("Name"); + createColumn("Mother"); + createColumn("Father"); + createColumn("Grandmother"); + duckFamily.setLinesVisible(true); - new Label(shell, SWT.NONE).setText("Name:"); - nameText = new Text(shell, SWT.BORDER); - GridDataFactory.defaultsFor(nameText).grab(true, false).applyTo( - nameText); + new Label(shell, SWT.NONE).setText("Name:"); + nameText = new Text(shell, SWT.BORDER); + GridDataFactory.defaultsFor(nameText).grab(true, false).applyTo( + nameText); - new Label(shell, SWT.NONE).setText("Mother:"); - motherCombo = new Combo(shell, SWT.READ_ONLY); + new Label(shell, SWT.NONE).setText("Mother:"); + motherCombo = new Combo(shell, SWT.READ_ONLY); - new Label(shell, SWT.NONE).setText("Father:"); - fatherCombo = new Combo(shell, SWT.READ_ONLY); + new Label(shell, SWT.NONE).setText("Father:"); + fatherCombo = new Combo(shell, SWT.READ_ONLY); - DataBindingContext bindingContext = new DataBindingContext(); - bindGUI(bindingContext); + DataBindingContext bindingContext = new DataBindingContext(); + bindGUI(bindingContext); - GridLayoutFactory.swtDefaults().numColumns(2).applyTo(shell); - // Open and return the Shell - shell.setSize(500, 300); - shell.open(); - return shell; - } + GridLayoutFactory.swtDefaults().numColumns(2).applyTo(shell); + // Open and return the Shell + shell.setSize(500, 300); + shell.open(); + return shell; + } - private void createColumn(String string) { - final TableColumn column = new TableColumn(duckFamily, SWT.NONE); - column.setWidth(100); - column.setText(string); - } + private void createColumn(String string) { + final TableColumn column = new TableColumn(duckFamily, SWT.NONE); + column.setWidth(100); + column.setText(string); + } - protected void bindGUI(DataBindingContext bindingContext) { - // Since we're using a JFace Viewer, we do first wrap our Table... - TableViewer peopleViewer = new TableViewer(duckFamily); - peopleViewer.addFilter(new ViewerFilter() { - public boolean select(Viewer viewer, Object parentElement, - Object element) { - return element != UNKNOWN; - } - }); + protected void bindGUI(DataBindingContext bindingContext) { + // Since we're using a JFace Viewer, we do first wrap our Table... + TableViewer peopleViewer = new TableViewer(duckFamily); + peopleViewer.addFilter(new ViewerFilter() { + public bool select(Viewer viewer, Object parentElement, + Object element) { + return element != UNKNOWN; + } + }); - // Bind viewers to model - ViewerSupport.bind(peopleViewer, viewModel.getPeople(), - BeanProperties.values(new String[] { "name", "mother.name", - "father.name", "mother.mother.name" })); + // Bind viewers to model + ViewerSupport.bind(peopleViewer, viewModel.getPeople(), + BeanProperties.values(new String[] { "name", "mother.name", + "father.name", "mother.mother.name" })); - // Bind viewer selection to detail fields - IObservableValue selection = ViewersObservables - .observeSingleSelection(peopleViewer); - bindingContext.bindValue(SWTObservables.observeText(nameText, - SWT.Modify), BeansObservables.observeDetailValue(selection, - "name", String.class)); + // Bind viewer selection to detail fields + IObservableValue selection = ViewersObservables + .observeSingleSelection(peopleViewer); + bindingContext.bindValue(SWTObservables.observeText(nameText, + SWT.Modify), BeansObservables.observeDetailValue(selection, + "name", String.class)); - ComboViewer mothercomboViewer = new ComboViewer(motherCombo); - ViewerSupport.bind(mothercomboViewer, viewModel.getPeople(), - BeanProperties.value("name")); - bindingContext.bindValue(ViewersObservables - .observeSingleSelection(mothercomboViewer), - BeansObservables.observeDetailValue(selection, "mother", - Person.class)); + ComboViewer mothercomboViewer = new ComboViewer(motherCombo); + ViewerSupport.bind(mothercomboViewer, viewModel.getPeople(), + BeanProperties.value("name")); + bindingContext.bindValue(ViewersObservables + .observeSingleSelection(mothercomboViewer), + BeansObservables.observeDetailValue(selection, "mother", + Person.class)); - ComboViewer fatherComboViewer = new ComboViewer(fatherCombo); - ViewerSupport.bind(fatherComboViewer, viewModel.getPeople(), - BeanProperties.value("name")); - bindingContext.bindValue(ViewersObservables - .observeSingleSelection(fatherComboViewer), - BeansObservables.observeDetailValue(selection, "father", - Person.class)); - } - } + ComboViewer fatherComboViewer = new ComboViewer(fatherCombo); + ViewerSupport.bind(fatherComboViewer, viewModel.getPeople(), + BeanProperties.value("name")); + bindingContext.bindValue(ViewersObservables + .observeSingleSelection(fatherComboViewer), + BeansObservables.observeDetailValue(selection, "father", + Person.class)); + } + } } +void main( String[] args ){ + Snippet017TableViewerWithDerivedColumns.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet018CheckboxTableViewerCheckedSelection.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet018CheckboxTableViewerCheckedSelection.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet018CheckboxTableViewerCheckedSelection.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * Matthew Hall - bugs 260329, 260337 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet018CheckboxTableViewerCheckedSelection; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -59,304 +61,307 @@ * Snippet 018: Binding to the checked elements in a CheckboxTableViewer. */ public class Snippet018CheckboxTableViewerCheckedSelection { - public static void main(String[] args) { - // The SWT event loop - final Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - ViewModel viewModel = createSampleModel(); + public static void main(String[] args) { + // The SWT event loop + final Display display = Display.getDefault(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + ViewModel viewModel = createSampleModel(); - Shell shell = new View(viewModel).createShell(); - shell.open(); - while (!shell.isDisposed()) - if (!display.readAndDispatch()) - display.sleep(); - } - }); - display.dispose(); - } + Shell shell = new View(viewModel).createShell(); + shell.open(); + while (!shell.isDisposed()) + if (!display.readAndDispatch()) + display.sleep(); + } + }); + display.dispose(); + } - private static ViewModel createSampleModel() { - ViewModel viewModel = new ViewModel(); + private static ViewModel createSampleModel() { + ViewModel viewModel = new ViewModel(); - Person stan = createPerson("Stan"); - Person kyle = createPerson("Kyle"); - Person eric = createPerson("Eric"); - Person kenny = createPerson("Kenny"); - Person wendy = createPerson("Wendy"); - Person butters = createPerson("Butters"); + Person stan = createPerson("Stan"); + Person kyle = createPerson("Kyle"); + Person eric = createPerson("Eric"); + Person kenny = createPerson("Kenny"); + Person wendy = createPerson("Wendy"); + Person butters = createPerson("Butters"); - setFriends(stan, new Person[] { kyle, eric, kenny, wendy }); - setFriends(kyle, new Person[] { stan, eric, kenny }); - setFriends(eric, new Person[] { eric }); - setFriends(kenny, new Person[] { stan, kyle, eric }); - setFriends(wendy, new Person[] { stan }); - setFriends(butters, new Person[0]); + setFriends(stan, new Person[] { kyle, eric, kenny, wendy }); + setFriends(kyle, new Person[] { stan, eric, kenny }); + setFriends(eric, new Person[] { eric }); + setFriends(kenny, new Person[] { stan, kyle, eric }); + setFriends(wendy, new Person[] { stan }); + setFriends(butters, new Person[0]); - Person[] people = new Person[] { stan, kyle, eric, kenny, wendy, - butters }; - viewModel.setPeople(Arrays.asList(people)); - return viewModel; - } + Person[] people = new Person[] { stan, kyle, eric, kenny, wendy, + butters }; + viewModel.setPeople(Arrays.asList(people)); + return viewModel; + } - private static Person createPerson(String name) { - Person person = new Person(); - person.setName(name); - return person; - } + private static Person createPerson(String name) { + Person person = new Person(); + person.setName(name); + return person; + } - private static void setFriends(Person person, Person[] friends) { - person.setFriends(new HashSet(Arrays.asList(friends))); - } + private static void setFriends(Person person, Person[] friends) { + person.setFriends(new HashSet(Arrays.asList(friends))); + } - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); + // Minimal JavaBeans support + public static abstract class AbstractModelObject { + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( + this); - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } + public void addPropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(listener); + } - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(propertyName, + listener); + } - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } + public void removePropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(listener); + } - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } + public void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(propertyName, + listener); + } - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } + protected void firePropertyChange(String propertyName, Object oldValue, + Object newValue) { + propertyChangeSupport.firePropertyChange(propertyName, oldValue, + newValue); + } + } - // The data model class. - static class Person extends AbstractModelObject { - private String name; - private Set friends = new HashSet(); + // The data model class. + static class Person extends AbstractModelObject { + private String name; + private Set friends = new HashSet(); - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - firePropertyChange("name", this.name, this.name = name); - } + public void setName(String name) { + firePropertyChange("name", this.name, this.name = name); + } - public Set getFriends() { - return new HashSet(friends); - } + public Set getFriends() { + return new HashSet(friends); + } - public void setFriends(Set friends) { - firePropertyChange("friends", this.friends, - this.friends = new HashSet(friends)); - } + public void setFriends(Set friends) { + firePropertyChange("friends", this.friends, + this.friends = new HashSet(friends)); + } - public String toString() { - return name; - } - } + public String toString() { + return name; + } + } - // The View's model--the root of our Model graph for this particular GUI. - // - // Typically each View class has a corresponding ViewModel class. - // - // The ViewModel is responsible for getting the objects to edit from the - // data access tier. Since this snippet doesn't have any persistent objects - // to retrieve, this ViewModel just instantiates a model object to edit. - static class ViewModel extends AbstractModelObject { - private List people = new ArrayList(); + // The View's model--the root of our Model graph for this particular GUI. + // + // Typically each View class has a corresponding ViewModel class. + // + // The ViewModel is responsible for getting the objects to edit from the + // data access tier. Since this snippet doesn't have any persistent objects + // to retrieve, this ViewModel just instantiates a model object to edit. + static class ViewModel extends AbstractModelObject { + private List people = new ArrayList(); - public List getPeople() { - return new ArrayList(people); - } + public List getPeople() { + return new ArrayList(people); + } - public void setPeople(List people) { - firePropertyChange("people", this.people, - this.people = new ArrayList(people)); - } - } + public void setPeople(List people) { + firePropertyChange("people", this.people, + this.people = new ArrayList(people)); + } + } - // The GUI view - static class View { - private ViewModel viewModel; + // The GUI view + static class View { + private ViewModel viewModel; - private Shell shell; + private Shell shell; - private Button addPersonButton; - private Button removePersonButton; - private TableViewer peopleViewer; - private Text personName; - private CheckboxTableViewer friendsViewer; + private Button addPersonButton; + private Button removePersonButton; + private TableViewer peopleViewer; + private Text personName; + private CheckboxTableViewer friendsViewer; - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } + public View(ViewModel viewModel) { + this.viewModel = viewModel; + } - public Shell createShell() { - // Build a UI - final Display display = Display.getCurrent(); - shell = new Shell(display); + public Shell createShell() { + // Build a UI + final Display display = Display.getCurrent(); + shell = new Shell(display); + + createUI(shell); - createUI(shell); - - // Bind UI - bindUI(); + // Bind UI + bindUI(); - // Open and return the Shell - shell.setSize(shell.computeSize(400, SWT.DEFAULT)); - shell.open(); - return shell; - } + // Open and return the Shell + shell.setSize(shell.computeSize(400, SWT.DEFAULT)); + shell.open(); + return shell; + } + + private void createUI(Shell shell) { + shell.setText("Binding checked elements in CheckboxTableViewer"); + shell.setLayout(new GridLayout(2, false)); + + new Label(shell, SWT.NONE).setText("People"); - private void createUI(Shell shell) { - shell.setText("Binding checked elements in CheckboxTableViewer"); - shell.setLayout(new GridLayout(2, false)); - - new Label(shell, SWT.NONE).setText("People"); + Composite buttons = new Composite(shell, SWT.NONE); + GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo( + buttons); + GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(true) + .applyTo(buttons); + addPersonButton = new Button(buttons, SWT.PUSH); + addPersonButton.setText("Add"); + GridDataFactory.fillDefaults().applyTo(addPersonButton); + removePersonButton = new Button(buttons, SWT.PUSH); + removePersonButton.setText("Remove"); + GridDataFactory.fillDefaults().applyTo(removePersonButton); - Composite buttons = new Composite(shell, SWT.NONE); - GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo( - buttons); - GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(true) - .applyTo(buttons); - addPersonButton = new Button(buttons, SWT.PUSH); - addPersonButton.setText("Add"); - GridDataFactory.fillDefaults().applyTo(addPersonButton); - removePersonButton = new Button(buttons, SWT.PUSH); - removePersonButton.setText("Remove"); - GridDataFactory.fillDefaults().applyTo(removePersonButton); + Composite peopleComposite = new Composite(shell, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo( + peopleComposite); + TableColumnLayout peopleColumnLayout = new TableColumnLayout(); + peopleComposite.setLayout(peopleColumnLayout); + + peopleViewer = new TableViewer(peopleComposite, SWT.SINGLE + | SWT.BORDER | SWT.FULL_SELECTION); - Composite peopleComposite = new Composite(shell, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo( - peopleComposite); - TableColumnLayout peopleColumnLayout = new TableColumnLayout(); - peopleComposite.setLayout(peopleColumnLayout); + Table peopleTable = peopleViewer.getTable(); + peopleTable.setHeaderVisible(true); + peopleTable.setLinesVisible(true); - peopleViewer = new TableViewer(peopleComposite, SWT.SINGLE - | SWT.BORDER | SWT.FULL_SELECTION); + TableColumn nameColumn = new TableColumn(peopleTable, SWT.NONE); + nameColumn.setText("Name"); + peopleColumnLayout.setColumnData(nameColumn, + new ColumnWeightData(1)); - Table peopleTable = peopleViewer.getTable(); - peopleTable.setHeaderVisible(true); - peopleTable.setLinesVisible(true); + TableColumn friendsColumn = new TableColumn(peopleTable, SWT.NONE); + friendsColumn.setText("Friends"); + peopleColumnLayout.setColumnData(friendsColumn, + new ColumnWeightData(3)); - TableColumn nameColumn = new TableColumn(peopleTable, SWT.NONE); - nameColumn.setText("Name"); - peopleColumnLayout.setColumnData(nameColumn, - new ColumnWeightData(1)); + new Label(shell, SWT.NONE).setText("Name"); + + personName = new Text(shell, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false) + .applyTo(personName); - TableColumn friendsColumn = new TableColumn(peopleTable, SWT.NONE); - friendsColumn.setText("Friends"); - peopleColumnLayout.setColumnData(friendsColumn, - new ColumnWeightData(3)); + new Label(shell, SWT.NONE).setText("Friends"); - new Label(shell, SWT.NONE).setText("Name"); - - personName = new Text(shell, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false) - .applyTo(personName); + Composite friendsComposite = new Composite(shell, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo( + friendsComposite); + TableColumnLayout friendsColumnLayout = new TableColumnLayout(); + friendsComposite.setLayout(friendsColumnLayout); - new Label(shell, SWT.NONE).setText("Friends"); + friendsViewer = CheckboxTableViewer.newCheckList(friendsComposite, + SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); - Composite friendsComposite = new Composite(shell, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, true).applyTo( - friendsComposite); - TableColumnLayout friendsColumnLayout = new TableColumnLayout(); - friendsComposite.setLayout(friendsColumnLayout); - - friendsViewer = CheckboxTableViewer.newCheckList(friendsComposite, - SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); + Table friendsTable = friendsViewer.getTable(); + friendsTable.setHeaderVisible(true); + friendsTable.setLinesVisible(true); + TableColumn friendNameColumn = new TableColumn(friendsTable, + SWT.NONE); + friendNameColumn.setText("Name"); + friendsColumnLayout.setColumnData(friendNameColumn, + new ColumnWeightData(1)); - Table friendsTable = friendsViewer.getTable(); - friendsTable.setHeaderVisible(true); - friendsTable.setLinesVisible(true); - TableColumn friendNameColumn = new TableColumn(friendsTable, - SWT.NONE); - friendNameColumn.setText("Name"); - friendsColumnLayout.setColumnData(friendNameColumn, - new ColumnWeightData(1)); + GridDataFactory.fillDefaults().grab(true, true).applyTo( + friendsViewer.getTable()); + } - GridDataFactory.fillDefaults().grab(true, true).applyTo( - friendsViewer.getTable()); - } + private void bindUI() { + DataBindingContext dbc = new DataBindingContext(); - private void bindUI() { - DataBindingContext dbc = new DataBindingContext(); - - final IObservableList people = BeansObservables.observeList(Realm - .getDefault(), viewModel, "people"); + final IObservableList people = BeansObservables.observeList(Realm + .getDefault(), viewModel, "people"); - addPersonButton.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - InputDialog dlg = new InputDialog(shell, "Add Person", - "Enter name:", "", new IInputValidator() { - public String isValid(String newText) { - if (newText == null - || newText.length() == 0) - return "Name cannot be empty"; - return null; - } - }); - if (dlg.open() == Window.OK) { - Person person = new Person(); - person.setName(dlg.getValue()); - people.add(person); - peopleViewer.setSelection(new StructuredSelection( - person)); - } - } - }); + addPersonButton.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + InputDialog dlg = new InputDialog(shell, "Add Person", + "Enter name:", "", new IInputValidator() { + public String isValid(String newText) { + if (newText == null + || newText.length() == 0) + return "Name cannot be empty"; + return null; + } + }); + if (dlg.open() == Window.OK) { + Person person = new Person(); + person.setName(dlg.getValue()); + people.add(person); + peopleViewer.setSelection(new StructuredSelection( + person)); + } + } + }); - removePersonButton.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - IStructuredSelection selected = (IStructuredSelection) peopleViewer - .getSelection(); - if (selected.isEmpty()) - return; - Person person = (Person) selected.getFirstElement(); - if (MessageDialog.openConfirm(shell, "Remove person", - "Remove " + person.getName() + "?")) - people.remove(person); - } - }); + removePersonButton.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + IStructuredSelection selected = (IStructuredSelection) peopleViewer + .getSelection(); + if (selected.isEmpty()) + return; + Person person = (Person) selected.getFirstElement(); + if (MessageDialog.openConfirm(shell, "Remove person", + "Remove " + person.getName() + "?")) + people.remove(person); + } + }); - ViewerSupport.bind(peopleViewer, people, BeanProperties.values( - Person.class, new String[] { "name", "friends" })); + ViewerSupport.bind(peopleViewer, people, BeanProperties.values( + Person.class, new String[] { "name", "friends" })); - final IObservableValue selectedPerson = ViewersObservables - .observeSingleSelection(peopleViewer); + final IObservableValue selectedPerson = ViewersObservables + .observeSingleSelection(peopleViewer); - IObservableValue personSelected = new ComputedValue(Boolean.TYPE) { - protected Object calculate() { - return Boolean.valueOf(selectedPerson.getValue() != null); - } - }; - dbc.bindValue(SWTObservables.observeEnabled(removePersonButton), - personSelected); - dbc.bindValue(SWTObservables.observeEnabled(friendsViewer - .getTable()), personSelected); + IObservableValue personSelected = new ComputedValue(bool.TYPE) { + protected Object calculate() { + return bool.valueOf(selectedPerson.getValue() != null); + } + }; + dbc.bindValue(SWTObservables.observeEnabled(removePersonButton), + personSelected); + dbc.bindValue(SWTObservables.observeEnabled(friendsViewer + .getTable()), personSelected); - dbc.bindValue(SWTObservables.observeText(personName, SWT.Modify), - BeansObservables.observeDetailValue(selectedPerson, "name", - String.class)); + dbc.bindValue(SWTObservables.observeText(personName, SWT.Modify), + BeansObservables.observeDetailValue(selectedPerson, "name", + String.class)); - ViewerSupport.bind(friendsViewer, people, BeanProperties.value( - Person.class, "name")); + ViewerSupport.bind(friendsViewer, people, BeanProperties.value( + Person.class, "name")); - dbc.bindSet(ViewersObservables.observeCheckedElements( - friendsViewer, Person.class), BeansObservables - .observeDetailSet(selectedPerson, "friends", Person.class)); - } - } -} \ No newline at end of file + dbc.bindSet(ViewersObservables.observeCheckedElements( + friendsViewer, Person.class), BeansObservables + .observeDetailSet(selectedPerson, "friends", Person.class)); + } + } +} +void main( String[] args ){ + Snippet018CheckboxTableViewerCheckedSelection.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet019TreeViewerWithListFactory.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet019TreeViewerWithListFactory.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet019TreeViewerWithListFactory.d Wed Apr 22 18:59:26 2009 +0200 @@ -9,7 +9,9 @@ * IBM Corporation - initial API and implementation * Matthew Hall - bugs 260329, 260337 *******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet019TreeViewerWithListFactory; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -46,281 +48,284 @@ public class Snippet019TreeViewerWithListFactory { - private Button pasteButton; - private Button copyButton; - private Shell shell; - private Button addChildBeanButton; - private Button removeBeanButton; - private TreeViewer beanViewer; - private Tree tree; - private Text beanText; - private DataBindingContext m_bindingContext; + private Button pasteButton; + private Button copyButton; + private Shell shell; + private Button addChildBeanButton; + private Button removeBeanButton; + private TreeViewer beanViewer; + private Tree tree; + private Text beanText; + private DataBindingContext m_bindingContext; + + private Bean input = createBean("input"); + private IObservableValue clipboard; - private Bean input = createBean("input"); - private IObservableValue clipboard; + /** + * Launch the application + * + * @param args + */ + public static void main(String[] args) { + Display display = Display.getDefault(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + try { + Snippet019TreeViewerWithListFactory window = new Snippet019TreeViewerWithListFactory(); + window.open(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } - /** - * Launch the application - * - * @param args - */ - public static void main(String[] args) { - Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - try { - Snippet019TreeViewerWithListFactory window = new Snippet019TreeViewerWithListFactory(); - window.open(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } + /** + * Open the window + */ + public void open() { + final Display display = Display.getDefault(); + createContents(); + shell.open(); + shell.layout(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } - /** - * Open the window - */ - public void open() { - final Display display = Display.getDefault(); - createContents(); - shell.open(); - shell.layout(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } + /** + * Create contents of the window + */ + protected void createContents() { + shell = new Shell(); + final GridLayout gridLayout_1 = new GridLayout(); + gridLayout_1.numColumns = 2; + shell.setLayout(gridLayout_1); + shell.setSize(535, 397); + shell.setText("SWT Application"); - /** - * Create contents of the window - */ - protected void createContents() { - shell = new Shell(); - final GridLayout gridLayout_1 = new GridLayout(); - gridLayout_1.numColumns = 2; - shell.setLayout(gridLayout_1); - shell.setSize(535, 397); - shell.setText("SWT Application"); + final Composite group = new Composite(shell, SWT.NONE); + final RowLayout rowLayout = new RowLayout(); + rowLayout.marginTop = 0; + rowLayout.marginRight = 0; + rowLayout.marginLeft = 0; + rowLayout.marginBottom = 0; + rowLayout.pack = false; + group.setLayout(rowLayout); + group + .setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, + 2, 1)); - final Composite group = new Composite(shell, SWT.NONE); - final RowLayout rowLayout = new RowLayout(); - rowLayout.marginTop = 0; - rowLayout.marginRight = 0; - rowLayout.marginLeft = 0; - rowLayout.marginBottom = 0; - rowLayout.pack = false; - group.setLayout(rowLayout); - group - .setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, - 2, 1)); + final Button addRootButton = new Button(group, SWT.NONE); + addRootButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + List list = input.getList(); + Bean root = createBean("root"); + list.add(root); + input.setList(list); + + beanViewer.setSelection(new StructuredSelection(root)); + beanText.selectAll(); + beanText.setFocus(); + } + }); + addRootButton.setText("Add Root"); - final Button addRootButton = new Button(group, SWT.NONE); - addRootButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - List list = input.getList(); - Bean root = createBean("root"); - list.add(root); - input.setList(list); + addChildBeanButton = new Button(group, SWT.NONE); + addChildBeanButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + Bean parent = getSelectedBean(); + List list = new ArrayList(parent.getList()); + Bean child = createBean("child"); + list.add(child); + parent.setList(list); - beanViewer.setSelection(new StructuredSelection(root)); - beanText.selectAll(); - beanText.setFocus(); - } - }); - addRootButton.setText("Add Root"); - - addChildBeanButton = new Button(group, SWT.NONE); - addChildBeanButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - Bean parent = getSelectedBean(); - List list = new ArrayList(parent.getList()); - Bean child = createBean("child"); - list.add(child); - parent.setList(list); + beanViewer.setSelection(new StructuredSelection(child)); + beanText.selectAll(); + beanText.setFocus(); + } + }); + addChildBeanButton.setText("Add Child"); - beanViewer.setSelection(new StructuredSelection(child)); - beanText.selectAll(); - beanText.setFocus(); - } - }); - addChildBeanButton.setText("Add Child"); + removeBeanButton = new Button(group, SWT.NONE); + removeBeanButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + TreeItem selectedItem = beanViewer.getTree().getSelection()[0]; + TreeItem parentItem = selectedItem.getParentItem(); + Bean parent; + int index; + if (parentItem == null) { + parent = input; + index = beanViewer.getTree().indexOf(selectedItem); + } else { + parent = (Bean) parentItem.getData(); + index = parentItem.indexOf(selectedItem); + } - removeBeanButton = new Button(group, SWT.NONE); - removeBeanButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - TreeItem selectedItem = beanViewer.getTree().getSelection()[0]; - TreeItem parentItem = selectedItem.getParentItem(); - Bean parent; - int index; - if (parentItem == null) { - parent = input; - index = beanViewer.getTree().indexOf(selectedItem); - } else { - parent = (Bean) parentItem.getData(); - index = parentItem.indexOf(selectedItem); - } + List list = new ArrayList(parent.getList()); + list.remove(index); + parent.setList(list); + } + }); + removeBeanButton.setText("Remove"); - List list = new ArrayList(parent.getList()); - list.remove(index); - parent.setList(list); - } - }); - removeBeanButton.setText("Remove"); + copyButton = new Button(group, SWT.NONE); + copyButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + clipboard.setValue(getSelectedBean()); + } + }); + copyButton.setText("Copy"); - copyButton = new Button(group, SWT.NONE); - copyButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - clipboard.setValue(getSelectedBean()); - } - }); - copyButton.setText("Copy"); + pasteButton = new Button(group, SWT.NONE); + pasteButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + Bean copy = (Bean) clipboard.getValue(); + if (copy == null) + return; + Bean parent = getSelectedBean(); + if (parent == null) + parent = input; - pasteButton = new Button(group, SWT.NONE); - pasteButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - Bean copy = (Bean) clipboard.getValue(); - if (copy == null) - return; - Bean parent = getSelectedBean(); - if (parent == null) - parent = input; + List list = new ArrayList(parent.getList()); + list.add(copy); + parent.setList(list); - List list = new ArrayList(parent.getList()); - list.add(copy); - parent.setList(list); + beanViewer.setSelection(new StructuredSelection(copy)); + beanText.selectAll(); + beanText.setFocus(); + } + }); + pasteButton.setText("Paste"); - beanViewer.setSelection(new StructuredSelection(copy)); - beanText.selectAll(); - beanText.setFocus(); - } - }); - pasteButton.setText("Paste"); + final Button refreshButton = new Button(group, SWT.NONE); + refreshButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + beanViewer.refresh(); + } + }); + refreshButton.setText("Refresh"); - final Button refreshButton = new Button(group, SWT.NONE); - refreshButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - beanViewer.refresh(); - } - }); - refreshButton.setText("Refresh"); + beanViewer = new TreeViewer(shell, SWT.FULL_SELECTION | SWT.BORDER); + beanViewer.setUseHashlookup(true); + tree = beanViewer.getTree(); + tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); - beanViewer = new TreeViewer(shell, SWT.FULL_SELECTION | SWT.BORDER); - beanViewer.setUseHashlookup(true); - tree = beanViewer.getTree(); - tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + final Label itemNameLabel = new Label(shell, SWT.NONE); + itemNameLabel.setText("Item Name"); - final Label itemNameLabel = new Label(shell, SWT.NONE); - itemNameLabel.setText("Item Name"); + beanText = new Text(shell, SWT.BORDER); + final GridData gd_beanValue = new GridData(SWT.FILL, SWT.CENTER, true, + false); + beanText.setLayoutData(gd_beanValue); + m_bindingContext = initDataBindings(); + // + initExtraBindings(m_bindingContext); + } - beanText = new Text(shell, SWT.BORDER); - final GridData gd_beanValue = new GridData(SWT.FILL, SWT.CENTER, true, - false); - beanText.setLayoutData(gd_beanValue); - m_bindingContext = initDataBindings(); - // - initExtraBindings(m_bindingContext); - } - - private static Bean createBean(String name) { - return new Bean(name); - } + private static Bean createBean(String name) { + return new Bean(name); + } - protected DataBindingContext initDataBindings() { - IObservableValue treeViewerSelectionObserveSelection = ViewersObservables - .observeSingleSelection(beanViewer); - IObservableValue textTextObserveWidget = SWTObservables.observeText( - beanText, SWT.Modify); - IObservableValue treeViewerValueObserveDetailValue = BeansObservables - .observeDetailValue(treeViewerSelectionObserveSelection, - "text", String.class); - // - // - DataBindingContext bindingContext = new DataBindingContext(); - // - bindingContext.bindValue(textTextObserveWidget, - treeViewerValueObserveDetailValue); - // - return bindingContext; - } + protected DataBindingContext initDataBindings() { + IObservableValue treeViewerSelectionObserveSelection = ViewersObservables + .observeSingleSelection(beanViewer); + IObservableValue textTextObserveWidget = SWTObservables.observeText( + beanText, SWT.Modify); + IObservableValue treeViewerValueObserveDetailValue = BeansObservables + .observeDetailValue(treeViewerSelectionObserveSelection, + "text", String.class); + // + // + DataBindingContext bindingContext = new DataBindingContext(); + // + bindingContext.bindValue(textTextObserveWidget, + treeViewerValueObserveDetailValue); + // + return bindingContext; + } + + private Bean getSelectedBean() { + IStructuredSelection selection = (IStructuredSelection) beanViewer + .getSelection(); + if (selection.isEmpty()) + return null; + return (Bean) selection.getFirstElement(); + } - private Bean getSelectedBean() { - IStructuredSelection selection = (IStructuredSelection) beanViewer - .getSelection(); - if (selection.isEmpty()) - return null; - return (Bean) selection.getFirstElement(); - } + private void initExtraBindings(DataBindingContext dbc) { + final IObservableValue beanViewerSelection = ViewersObservables + .observeSingleSelection(beanViewer); + IObservableValue beanSelected = new ComputedValue(bool.TYPE) { + protected Object calculate() { + return bool.valueOf(beanViewerSelection.getValue() != null); + } + }; + dbc.bindValue(SWTObservables.observeEnabled(addChildBeanButton), + beanSelected); + dbc.bindValue(SWTObservables.observeEnabled(removeBeanButton), + beanSelected); - private void initExtraBindings(DataBindingContext dbc) { - final IObservableValue beanViewerSelection = ViewersObservables - .observeSingleSelection(beanViewer); - IObservableValue beanSelected = new ComputedValue(Boolean.TYPE) { - protected Object calculate() { - return Boolean.valueOf(beanViewerSelection.getValue() != null); - } - }; - dbc.bindValue(SWTObservables.observeEnabled(addChildBeanButton), - beanSelected); - dbc.bindValue(SWTObservables.observeEnabled(removeBeanButton), - beanSelected); + clipboard = new WritableValue(); + dbc.bindValue(SWTObservables.observeEnabled(copyButton), beanSelected); + dbc.bindValue(SWTObservables.observeEnabled(pasteButton), + new ComputedValue(bool.TYPE) { + protected Object calculate() { + return bool.valueOf(clipboard.getValue() != null); + } + }); - clipboard = new WritableValue(); - dbc.bindValue(SWTObservables.observeEnabled(copyButton), beanSelected); - dbc.bindValue(SWTObservables.observeEnabled(pasteButton), - new ComputedValue(Boolean.TYPE) { - protected Object calculate() { - return Boolean.valueOf(clipboard.getValue() != null); - } - }); + ViewerSupport.bind(beanViewer, input, BeanProperties.list("list", + Bean.class), BeanProperties.value(Bean.class, "text")); + } - ViewerSupport.bind(beanViewer, input, BeanProperties.list("list", - Bean.class), BeanProperties.value(Bean.class, "text")); - } + static class Bean { + /* package */PropertyChangeSupport changeSupport = new PropertyChangeSupport( + this); + private String text; + private List list; - static class Bean { - /* package */PropertyChangeSupport changeSupport = new PropertyChangeSupport( - this); - private String text; - private List list; + public Bean(String text) { + this.text = text; + list = new ArrayList(); + } - public Bean(String text) { - this.text = text; - list = new ArrayList(); - } + public void addPropertyChangeListener(PropertyChangeListener listener) { + changeSupport.addPropertyChangeListener(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + changeSupport.removePropertyChangeListener(listener); + } - public void addPropertyChangeListener(PropertyChangeListener listener) { - changeSupport.addPropertyChangeListener(listener); - } + public String getText() { + return text; + } - public void removePropertyChangeListener(PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); - } - - public String getText() { - return text; - } + public void setText(String value) { + changeSupport.firePropertyChange("text", this.text, + this.text = value); + } - public void setText(String value) { - changeSupport.firePropertyChange("text", this.text, - this.text = value); - } - - public List getList() { - if (list == null) - return null; - return new ArrayList(list); - } + public List getList() { + if (list == null) + return null; + return new ArrayList(list); + } - public void setList(List list) { - if (list != null) - list = new ArrayList(list); - changeSupport.firePropertyChange("list", this.list, - this.list = list); - } + public void setList(List list) { + if (list != null) + list = new ArrayList(list); + changeSupport.firePropertyChange("list", this.list, + this.list = list); + } - public boolean hasListeners(String propertyName) { - return changeSupport.hasListeners(propertyName); - } - } + public bool hasListeners(String propertyName) { + return changeSupport.hasListeners(propertyName); + } + } } +void main( String[] args ){ + Snippet019TreeViewerWithListFactory.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet020TreeViewerWithSetFactory.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet020TreeViewerWithSetFactory.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet020TreeViewerWithSetFactory.d Wed Apr 22 18:59:26 2009 +0200 @@ -9,7 +9,9 @@ * IBM Corporation - initial API and implementation * Matthew Hall - bugs 260329, 260337 *******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet020TreeViewerWithSetFactory; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -47,279 +49,282 @@ public class Snippet020TreeViewerWithSetFactory { - private Button pasteButton; - private Button copyButton; - private Shell shell; - private Button addChildBeanButton; - private Button removeBeanButton; - private TreeViewer beanViewer; - private Tree tree; - private Text beanText; - private DataBindingContext m_bindingContext; + private Button pasteButton; + private Button copyButton; + private Shell shell; + private Button addChildBeanButton; + private Button removeBeanButton; + private TreeViewer beanViewer; + private Tree tree; + private Text beanText; + private DataBindingContext m_bindingContext; - private Bean input = createBean("input"); - private IObservableValue clipboard; - static int counter = 0; + private Bean input = createBean("input"); + private IObservableValue clipboard; + static int counter = 0; - /** - * Launch the application - * - * @param args - */ - public static void main(String[] args) { - Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - try { - Snippet020TreeViewerWithSetFactory window = new Snippet020TreeViewerWithSetFactory(); - window.open(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } + /** + * Launch the application + * + * @param args + */ + public static void main(String[] args) { + Display display = Display.getDefault(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + try { + Snippet020TreeViewerWithSetFactory window = new Snippet020TreeViewerWithSetFactory(); + window.open(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } - /** - * Open the window - */ - public void open() { - final Display display = Display.getDefault(); - createContents(); - shell.open(); - shell.layout(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } + /** + * Open the window + */ + public void open() { + final Display display = Display.getDefault(); + createContents(); + shell.open(); + shell.layout(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } - /** - * Create contents of the window - */ - protected void createContents() { - shell = new Shell(); - final GridLayout gridLayout_1 = new GridLayout(); - gridLayout_1.numColumns = 2; - shell.setLayout(gridLayout_1); - shell.setSize(535, 397); - shell.setText("SWT Application"); + /** + * Create contents of the window + */ + protected void createContents() { + shell = new Shell(); + final GridLayout gridLayout_1 = new GridLayout(); + gridLayout_1.numColumns = 2; + shell.setLayout(gridLayout_1); + shell.setSize(535, 397); + shell.setText("SWT Application"); - final Composite group = new Composite(shell, SWT.NONE); - final RowLayout rowLayout = new RowLayout(); - rowLayout.marginTop = 0; - rowLayout.marginRight = 0; - rowLayout.marginLeft = 0; - rowLayout.marginBottom = 0; - rowLayout.pack = false; - group.setLayout(rowLayout); - group - .setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, - 2, 1)); + final Composite group = new Composite(shell, SWT.NONE); + final RowLayout rowLayout = new RowLayout(); + rowLayout.marginTop = 0; + rowLayout.marginRight = 0; + rowLayout.marginLeft = 0; + rowLayout.marginBottom = 0; + rowLayout.pack = false; + group.setLayout(rowLayout); + group + .setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, + 2, 1)); - final Button addRootButton = new Button(group, SWT.NONE); - addRootButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - Set set = input.getSet(); - Bean root = createBean("root"); - set.add(root); - input.setSet(set); + final Button addRootButton = new Button(group, SWT.NONE); + addRootButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + Set set = input.getSet(); + Bean root = createBean("root"); + set.add(root); + input.setSet(set); - beanViewer.setSelection(new StructuredSelection(root)); - beanText.selectAll(); - beanText.setFocus(); - } - }); - addRootButton.setText("Add Root"); + beanViewer.setSelection(new StructuredSelection(root)); + beanText.selectAll(); + beanText.setFocus(); + } + }); + addRootButton.setText("Add Root"); - addChildBeanButton = new Button(group, SWT.NONE); - addChildBeanButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - Bean parent = getSelectedBean(); - Set set = new HashSet(parent.getSet()); - Bean child = createBean("child" + (counter++)); - set.add(child); - parent.setSet(set); + addChildBeanButton = new Button(group, SWT.NONE); + addChildBeanButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + Bean parent = getSelectedBean(); + Set set = new HashSet(parent.getSet()); + Bean child = createBean("child" + (counter++)); + set.add(child); + parent.setSet(set); - // beanViewer.setSelection(new StructuredSelection(parent)); - // beanText.selectAll(); - // beanText.setFocus(); - } - }); - addChildBeanButton.setText("Add Child"); + // beanViewer.setSelection(new StructuredSelection(parent)); + // beanText.selectAll(); + // beanText.setFocus(); + } + }); + addChildBeanButton.setText("Add Child"); - removeBeanButton = new Button(group, SWT.NONE); - removeBeanButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - TreeItem selectedItem = beanViewer.getTree().getSelection()[0]; - Bean bean = (Bean) selectedItem.getData(); - TreeItem parentItem = selectedItem.getParentItem(); - Bean parent; - if (parentItem == null) - parent = input; - else - parent = (Bean) parentItem.getData(); + removeBeanButton = new Button(group, SWT.NONE); + removeBeanButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + TreeItem selectedItem = beanViewer.getTree().getSelection()[0]; + Bean bean = (Bean) selectedItem.getData(); + TreeItem parentItem = selectedItem.getParentItem(); + Bean parent; + if (parentItem == null) + parent = input; + else + parent = (Bean) parentItem.getData(); - Set set = new HashSet(parent.getSet()); - set.remove(bean); - parent.setSet(set); - } - }); - removeBeanButton.setText("Remove"); + Set set = new HashSet(parent.getSet()); + set.remove(bean); + parent.setSet(set); + } + }); + removeBeanButton.setText("Remove"); - copyButton = new Button(group, SWT.NONE); - copyButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - clipboard.setValue(getSelectedBean()); - } - }); - copyButton.setText("Copy"); + copyButton = new Button(group, SWT.NONE); + copyButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + clipboard.setValue(getSelectedBean()); + } + }); + copyButton.setText("Copy"); - pasteButton = new Button(group, SWT.NONE); - pasteButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - Bean copy = (Bean) clipboard.getValue(); - if (copy == null) - return; - Bean parent = getSelectedBean(); - if (parent == null) - parent = input; + pasteButton = new Button(group, SWT.NONE); + pasteButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + Bean copy = (Bean) clipboard.getValue(); + if (copy == null) + return; + Bean parent = getSelectedBean(); + if (parent == null) + parent = input; - Set set = new HashSet(parent.getSet()); - set.add(copy); - parent.setSet(set); + Set set = new HashSet(parent.getSet()); + set.add(copy); + parent.setSet(set); - beanViewer.setSelection(new StructuredSelection(copy)); - beanText.selectAll(); - beanText.setFocus(); - } - }); - pasteButton.setText("Paste"); + beanViewer.setSelection(new StructuredSelection(copy)); + beanText.selectAll(); + beanText.setFocus(); + } + }); + pasteButton.setText("Paste"); - final Button refreshButton = new Button(group, SWT.NONE); - refreshButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - beanViewer.refresh(); - } - }); - refreshButton.setText("Refresh"); + final Button refreshButton = new Button(group, SWT.NONE); + refreshButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + beanViewer.refresh(); + } + }); + refreshButton.setText("Refresh"); - beanViewer = new TreeViewer(shell, SWT.FULL_SELECTION | SWT.BORDER); - beanViewer.setUseHashlookup(true); - beanViewer.setComparator(new ViewerComparator()); - tree = beanViewer.getTree(); - tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + beanViewer = new TreeViewer(shell, SWT.FULL_SELECTION | SWT.BORDER); + beanViewer.setUseHashlookup(true); + beanViewer.setComparator(new ViewerComparator()); + tree = beanViewer.getTree(); + tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); - final Label itemNameLabel = new Label(shell, SWT.NONE); - itemNameLabel.setText("Item Name"); + final Label itemNameLabel = new Label(shell, SWT.NONE); + itemNameLabel.setText("Item Name"); - beanText = new Text(shell, SWT.BORDER); - final GridData gd_beanValue = new GridData(SWT.FILL, SWT.CENTER, true, - false); - beanText.setLayoutData(gd_beanValue); - m_bindingContext = initDataBindings(); - // - initExtraBindings(m_bindingContext); - } + beanText = new Text(shell, SWT.BORDER); + final GridData gd_beanValue = new GridData(SWT.FILL, SWT.CENTER, true, + false); + beanText.setLayoutData(gd_beanValue); + m_bindingContext = initDataBindings(); + // + initExtraBindings(m_bindingContext); + } - private static Bean createBean(String name) { - return new Bean(name); - } + private static Bean createBean(String name) { + return new Bean(name); + } - protected DataBindingContext initDataBindings() { - IObservableValue treeViewerSelectionObserveSelection = ViewersObservables - .observeSingleSelection(beanViewer); - IObservableValue textTextObserveWidget = SWTObservables.observeText( - beanText, SWT.Modify); - IObservableValue treeViewerValueObserveDetailValue = BeansObservables - .observeDetailValue(treeViewerSelectionObserveSelection, - "text", String.class); - // - // - DataBindingContext bindingContext = new DataBindingContext(); - // - bindingContext.bindValue(textTextObserveWidget, - treeViewerValueObserveDetailValue); - // - return bindingContext; - } + protected DataBindingContext initDataBindings() { + IObservableValue treeViewerSelectionObserveSelection = ViewersObservables + .observeSingleSelection(beanViewer); + IObservableValue textTextObserveWidget = SWTObservables.observeText( + beanText, SWT.Modify); + IObservableValue treeViewerValueObserveDetailValue = BeansObservables + .observeDetailValue(treeViewerSelectionObserveSelection, + "text", String.class); + // + // + DataBindingContext bindingContext = new DataBindingContext(); + // + bindingContext.bindValue(textTextObserveWidget, + treeViewerValueObserveDetailValue); + // + return bindingContext; + } - private Bean getSelectedBean() { - IStructuredSelection selection = (IStructuredSelection) beanViewer - .getSelection(); - if (selection.isEmpty()) - return null; - return (Bean) selection.getFirstElement(); - } + private Bean getSelectedBean() { + IStructuredSelection selection = (IStructuredSelection) beanViewer + .getSelection(); + if (selection.isEmpty()) + return null; + return (Bean) selection.getFirstElement(); + } - private void initExtraBindings(DataBindingContext dbc) { - final IObservableValue beanViewerSelection = ViewersObservables - .observeSingleSelection(beanViewer); - IObservableValue beanSelected = new ComputedValue(Boolean.TYPE) { - protected Object calculate() { - return Boolean.valueOf(beanViewerSelection.getValue() != null); - } - }; - dbc.bindValue(SWTObservables.observeEnabled(addChildBeanButton), - beanSelected); - dbc.bindValue(SWTObservables.observeEnabled(removeBeanButton), - beanSelected); + private void initExtraBindings(DataBindingContext dbc) { + final IObservableValue beanViewerSelection = ViewersObservables + .observeSingleSelection(beanViewer); + IObservableValue beanSelected = new ComputedValue(bool.TYPE) { + protected Object calculate() { + return bool.valueOf(beanViewerSelection.getValue() != null); + } + }; + dbc.bindValue(SWTObservables.observeEnabled(addChildBeanButton), + beanSelected); + dbc.bindValue(SWTObservables.observeEnabled(removeBeanButton), + beanSelected); - clipboard = new WritableValue(); - dbc.bindValue(SWTObservables.observeEnabled(copyButton), beanSelected); - dbc.bindValue(SWTObservables.observeEnabled(pasteButton), - new ComputedValue(Boolean.TYPE) { - protected Object calculate() { - return Boolean.valueOf(clipboard.getValue() != null); - } - }); + clipboard = new WritableValue(); + dbc.bindValue(SWTObservables.observeEnabled(copyButton), beanSelected); + dbc.bindValue(SWTObservables.observeEnabled(pasteButton), + new ComputedValue(bool.TYPE) { + protected Object calculate() { + return bool.valueOf(clipboard.getValue() != null); + } + }); - ViewerSupport.bind(beanViewer, input, BeanProperties.set("set", - Bean.class), BeanProperties.value(Bean.class, "text")); - } + ViewerSupport.bind(beanViewer, input, BeanProperties.set("set", + Bean.class), BeanProperties.value(Bean.class, "text")); + } - static class Bean { - /* package */PropertyChangeSupport changeSupport = new PropertyChangeSupport( - this); - private String text; - private Set set; + static class Bean { + /* package */PropertyChangeSupport changeSupport = new PropertyChangeSupport( + this); + private String text; + private Set set; + + public Bean(String text) { + this.text = text; + set = new HashSet(); + } - public Bean(String text) { - this.text = text; - set = new HashSet(); - } + public void addPropertyChangeListener(PropertyChangeListener listener) { + changeSupport.addPropertyChangeListener(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + changeSupport.removePropertyChangeListener(listener); + } - public void addPropertyChangeListener(PropertyChangeListener listener) { - changeSupport.addPropertyChangeListener(listener); - } + public String getText() { + return text; + } - public void removePropertyChangeListener(PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); - } - - public String getText() { - return text; - } + public void setText(String value) { + changeSupport.firePropertyChange("text", this.text, + this.text = value); + } - public void setText(String value) { - changeSupport.firePropertyChange("text", this.text, - this.text = value); - } - - public Set getSet() { - if (set == null) - return null; - return new HashSet(set); - } + public Set getSet() { + if (set == null) + return null; + return new HashSet(set); + } - public void setSet(Set set) { - if (set != null) - set = new HashSet(set); - changeSupport.firePropertyChange("set", this.set, this.set = set); - } + public void setSet(Set set) { + if (set != null) + set = new HashSet(set); + changeSupport.firePropertyChange("set", this.set, this.set = set); + } - public boolean hasListeners(String propertyName) { - return changeSupport.hasListeners(propertyName); - } - } -} \ No newline at end of file + public bool hasListeners(String propertyName) { + return changeSupport.hasListeners(propertyName); + } + } +} +void main( String[] args ){ + Snippet020TreeViewerWithSetFactory.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet021MultiFieldValidation.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet021MultiFieldValidation.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet021MultiFieldValidation.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * Matthew Hall - bug 260329 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet021MultiFieldValidation; + +import java.lang.all; import java.util.ArrayList; import java.util.Iterator; @@ -55,303 +57,306 @@ */ public class Snippet021MultiFieldValidation extends WizardPage { - private List list_1; - private List list; - private Button addAddendButton; - private Button removeAddendButton; - private Text sumModelValue; - private Text field2ModelValue; - private Text field1ModelValue; - private Text sumTarget; - private Text field2Target; - private Text field1Target; - private ListViewer addendsTarget; - private ListViewer addendsModelValue; + private List list_1; + private List list; + private Button addAddendButton; + private Button removeAddendButton; + private Text sumModelValue; + private Text field2ModelValue; + private Text field1ModelValue; + private Text sumTarget; + private Text field2Target; + private Text field1Target; + private ListViewer addendsTarget; + private ListViewer addendsModelValue; - /** - * Create the wizard - */ - public Snippet021MultiFieldValidation() { - super("snippet021"); - setTitle("Snippet 021 - Multi-field Validators"); - setDescription("Enter values which satisfy the cross-field constraints"); - } + /** + * Create the wizard + */ + public Snippet021MultiFieldValidation() { + super("snippet021"); + setTitle("Snippet 021 - Multi-field Validators"); + setDescription("Enter values which satisfy the cross-field constraints"); + } - /** - * Create contents of the wizard - * - * @param parent - */ - public void createControl(Composite parent) { - Composite container = new Composite(parent, SWT.NULL); - final GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - container.setLayout(gridLayout); - // - setControl(container); + /** + * Create contents of the wizard + * + * @param parent + */ + public void createControl(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + final GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 2; + container.setLayout(gridLayout); + // + setControl(container); - final Group bothEvenOrGroup = new Group(container, SWT.NONE); - bothEvenOrGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, - false)); - bothEvenOrGroup.setText("Numbers must be both even or both odd"); - final GridLayout gridLayout_1 = new GridLayout(); - gridLayout_1.numColumns = 3; - bothEvenOrGroup.setLayout(gridLayout_1); - new Label(bothEvenOrGroup, SWT.NONE); + final Group bothEvenOrGroup = new Group(container, SWT.NONE); + bothEvenOrGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, + false)); + bothEvenOrGroup.setText("Numbers must be both even or both odd"); + final GridLayout gridLayout_1 = new GridLayout(); + gridLayout_1.numColumns = 3; + bothEvenOrGroup.setLayout(gridLayout_1); + new Label(bothEvenOrGroup, SWT.NONE); - final Label targetLabel = new Label(bothEvenOrGroup, SWT.NONE); - targetLabel.setText("Target"); + final Label targetLabel = new Label(bothEvenOrGroup, SWT.NONE); + targetLabel.setText("Target"); - final Label modelLabel = new Label(bothEvenOrGroup, SWT.NONE); - modelLabel.setText("Model"); + final Label modelLabel = new Label(bothEvenOrGroup, SWT.NONE); + modelLabel.setText("Model"); - final Label field1Label = new Label(bothEvenOrGroup, SWT.NONE); - field1Label.setText("Field 1"); + final Label field1Label = new Label(bothEvenOrGroup, SWT.NONE); + field1Label.setText("Field 1"); - field1Target = new Text(bothEvenOrGroup, SWT.BORDER); - final GridData gd_field1Target = new GridData(SWT.FILL, SWT.CENTER, - true, false); - field1Target.setLayoutData(gd_field1Target); + field1Target = new Text(bothEvenOrGroup, SWT.BORDER); + final GridData gd_field1Target = new GridData(SWT.FILL, SWT.CENTER, + true, false); + field1Target.setLayoutData(gd_field1Target); - field1ModelValue = new Text(bothEvenOrGroup, SWT.READ_ONLY | SWT.BORDER); - final GridData gd_field1ModelValue = new GridData(SWT.FILL, SWT.CENTER, - true, false); - field1ModelValue.setLayoutData(gd_field1ModelValue); + field1ModelValue = new Text(bothEvenOrGroup, SWT.READ_ONLY | SWT.BORDER); + final GridData gd_field1ModelValue = new GridData(SWT.FILL, SWT.CENTER, + true, false); + field1ModelValue.setLayoutData(gd_field1ModelValue); - final Label field2Label = new Label(bothEvenOrGroup, SWT.NONE); - field2Label.setText("Field 2"); + final Label field2Label = new Label(bothEvenOrGroup, SWT.NONE); + field2Label.setText("Field 2"); - field2Target = new Text(bothEvenOrGroup, SWT.BORDER); - final GridData gd_field2Target = new GridData(SWT.FILL, SWT.CENTER, - true, false); - field2Target.setLayoutData(gd_field2Target); + field2Target = new Text(bothEvenOrGroup, SWT.BORDER); + final GridData gd_field2Target = new GridData(SWT.FILL, SWT.CENTER, + true, false); + field2Target.setLayoutData(gd_field2Target); - field2ModelValue = new Text(bothEvenOrGroup, SWT.READ_ONLY | SWT.BORDER); - final GridData gd_field2ModelValue = new GridData(SWT.FILL, SWT.CENTER, - true, false); - field2ModelValue.setLayoutData(gd_field2ModelValue); + field2ModelValue = new Text(bothEvenOrGroup, SWT.READ_ONLY | SWT.BORDER); + final GridData gd_field2ModelValue = new GridData(SWT.FILL, SWT.CENTER, + true, false); + field2ModelValue.setLayoutData(gd_field2ModelValue); - final Group sumOfAllGroup = new Group(container, SWT.NONE); - sumOfAllGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, - true)); - sumOfAllGroup.setText("Addends must add up to sum"); - final GridLayout gridLayout_2 = new GridLayout(); - gridLayout_2.numColumns = 3; - sumOfAllGroup.setLayout(gridLayout_2); - new Label(sumOfAllGroup, SWT.NONE); + final Group sumOfAllGroup = new Group(container, SWT.NONE); + sumOfAllGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, + true)); + sumOfAllGroup.setText("Addends must add up to sum"); + final GridLayout gridLayout_2 = new GridLayout(); + gridLayout_2.numColumns = 3; + sumOfAllGroup.setLayout(gridLayout_2); + new Label(sumOfAllGroup, SWT.NONE); - final Label targetLabel_1 = new Label(sumOfAllGroup, SWT.NONE); - targetLabel_1.setText("Target"); + final Label targetLabel_1 = new Label(sumOfAllGroup, SWT.NONE); + targetLabel_1.setText("Target"); - final Label modelLabel_1 = new Label(sumOfAllGroup, SWT.NONE); - modelLabel_1.setText("Model"); + final Label modelLabel_1 = new Label(sumOfAllGroup, SWT.NONE); + modelLabel_1.setText("Model"); - final Label expectedSumLabel = new Label(sumOfAllGroup, SWT.NONE); - expectedSumLabel.setText("Sum"); + final Label expectedSumLabel = new Label(sumOfAllGroup, SWT.NONE); + expectedSumLabel.setText("Sum"); - sumTarget = new Text(sumOfAllGroup, SWT.BORDER); - final GridData gd_sumTarget = new GridData(SWT.FILL, SWT.CENTER, true, - false); - sumTarget.setLayoutData(gd_sumTarget); + sumTarget = new Text(sumOfAllGroup, SWT.BORDER); + final GridData gd_sumTarget = new GridData(SWT.FILL, SWT.CENTER, true, + false); + sumTarget.setLayoutData(gd_sumTarget); - sumModelValue = new Text(sumOfAllGroup, SWT.READ_ONLY | SWT.BORDER); - final GridData gd_sumModelValue = new GridData(SWT.FILL, SWT.CENTER, - true, false); - sumModelValue.setLayoutData(gd_sumModelValue); + sumModelValue = new Text(sumOfAllGroup, SWT.READ_ONLY | SWT.BORDER); + final GridData gd_sumModelValue = new GridData(SWT.FILL, SWT.CENTER, + true, false); + sumModelValue.setLayoutData(gd_sumModelValue); - final Label addendsLabel = new Label(sumOfAllGroup, SWT.NONE); - addendsLabel.setText("Addends"); + final Label addendsLabel = new Label(sumOfAllGroup, SWT.NONE); + addendsLabel.setText("Addends"); - addendsTarget = new ListViewer(sumOfAllGroup, SWT.V_SCROLL | SWT.BORDER); - list_1 = addendsTarget.getList(); - list_1 - .setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, - 2)); + addendsTarget = new ListViewer(sumOfAllGroup, SWT.V_SCROLL | SWT.BORDER); + list_1 = addendsTarget.getList(); + list_1 + .setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, + 2)); - addendsModelValue = new ListViewer(sumOfAllGroup, SWT.V_SCROLL - | SWT.BORDER); - list = addendsModelValue.getList(); - list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 2)); + addendsModelValue = new ListViewer(sumOfAllGroup, SWT.V_SCROLL + | SWT.BORDER); + list = addendsModelValue.getList(); + list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 2)); - final Composite composite = new Composite(sumOfAllGroup, SWT.NONE); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); - final GridLayout gridLayout_3 = new GridLayout(); - gridLayout_3.marginWidth = 0; - gridLayout_3.marginHeight = 0; - composite.setLayout(gridLayout_3); + final Composite composite = new Composite(sumOfAllGroup, SWT.NONE); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + final GridLayout gridLayout_3 = new GridLayout(); + gridLayout_3.marginWidth = 0; + gridLayout_3.marginHeight = 0; + composite.setLayout(gridLayout_3); - addAddendButton = new Button(composite, SWT.NONE); - addAddendButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, - false)); - addAddendButton.setText("Add"); + addAddendButton = new Button(composite, SWT.NONE); + addAddendButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, + false)); + addAddendButton.setText("Add"); - removeAddendButton = new Button(composite, SWT.NONE); - removeAddendButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, - false, false)); - removeAddendButton.setText("Remove"); + removeAddendButton = new Button(composite, SWT.NONE); + removeAddendButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, + false, false)); + removeAddendButton.setText("Remove"); - bindUI(); - } + bindUI(); + } - private void bindUI() { - DataBindingContext dbc = new DataBindingContext(); + private void bindUI() { + DataBindingContext dbc = new DataBindingContext(); - bindEvensAndOddsGroup(dbc); - bindSumAndAddendsGroup(dbc); + bindEvensAndOddsGroup(dbc); + bindSumAndAddendsGroup(dbc); - WizardPageSupport.create(this, dbc); - } + WizardPageSupport.create(this, dbc); + } - private void bindEvensAndOddsGroup(DataBindingContext dbc) { - IObservableValue targetField1 = SWTObservables.observeText( - field1Target, SWT.Modify); - final IObservableValue middleField1 = new WritableValue(null, - Integer.TYPE); - dbc.bindValue(targetField1, middleField1); + private void bindEvensAndOddsGroup(DataBindingContext dbc) { + IObservableValue targetField1 = SWTObservables.observeText( + field1Target, SWT.Modify); + final IObservableValue middleField1 = new WritableValue(null, + Integer.TYPE); + dbc.bindValue(targetField1, middleField1); - IObservableValue targetField2 = SWTObservables.observeText( - field2Target, SWT.Modify); - final IObservableValue middleField2 = new WritableValue(null, - Integer.TYPE); - dbc.bindValue(targetField2, middleField2); + IObservableValue targetField2 = SWTObservables.observeText( + field2Target, SWT.Modify); + final IObservableValue middleField2 = new WritableValue(null, + Integer.TYPE); + dbc.bindValue(targetField2, middleField2); - MultiValidator validator = new MultiValidator() { - protected IStatus validate() { - Integer field1 = (Integer) middleField1.getValue(); - Integer field2 = (Integer) middleField2.getValue(); - if (Math.abs(field1.intValue()) % 2 != Math.abs(field2 - .intValue()) % 2) - return ValidationStatus - .error("Fields 1 and 2 must be both even or both odd"); - return null; - } - }; - dbc.addValidationStatusProvider(validator); + MultiValidator validator = new MultiValidator() { + protected IStatus validate() { + Integer field1 = (Integer) middleField1.getValue(); + Integer field2 = (Integer) middleField2.getValue(); + if (Math.abs(field1.intValue()) % 2 != Math.abs(field2 + .intValue()) % 2) + return ValidationStatus + .error("Fields 1 and 2 must be both even or both odd"); + return null; + } + }; + dbc.addValidationStatusProvider(validator); - IObservableValue modelField1 = new WritableValue(new Integer(1), - Integer.TYPE); - IObservableValue modelField2 = new WritableValue(new Integer(4), - Integer.TYPE); - dbc.bindValue(validator.observeValidatedValue(middleField1), - modelField1); - dbc.bindValue(validator.observeValidatedValue(middleField2), - modelField2); + IObservableValue modelField1 = new WritableValue(new Integer(1), + Integer.TYPE); + IObservableValue modelField2 = new WritableValue(new Integer(4), + Integer.TYPE); + dbc.bindValue(validator.observeValidatedValue(middleField1), + modelField1); + dbc.bindValue(validator.observeValidatedValue(middleField2), + modelField2); - dbc.bindValue(SWTObservables.observeText(field1ModelValue, SWT.Modify), - modelField1); - dbc.bindValue(SWTObservables.observeText(field2ModelValue, SWT.Modify), - modelField2); - } + dbc.bindValue(SWTObservables.observeText(field1ModelValue, SWT.Modify), + modelField1); + dbc.bindValue(SWTObservables.observeText(field2ModelValue, SWT.Modify), + modelField2); + } - private void bindSumAndAddendsGroup(DataBindingContext dbc) { - IObservableValue targetSum = SWTObservables.observeText(sumTarget, - SWT.Modify); - final IObservableValue middleSum = new WritableValue(null, Integer.TYPE); - dbc.bindValue(targetSum, middleSum); + private void bindSumAndAddendsGroup(DataBindingContext dbc) { + IObservableValue targetSum = SWTObservables.observeText(sumTarget, + SWT.Modify); + final IObservableValue middleSum = new WritableValue(null, Integer.TYPE); + dbc.bindValue(targetSum, middleSum); - final IObservableList targetAddends = new WritableList(new ArrayList(), - Integer.TYPE); - addendsTarget.setContentProvider(new ObservableListContentProvider()); - addendsTarget.setInput(targetAddends); + final IObservableList targetAddends = new WritableList(new ArrayList(), + Integer.TYPE); + addendsTarget.setContentProvider(new ObservableListContentProvider()); + addendsTarget.setInput(targetAddends); - addAddendButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - InputDialog dialog = new InputDialog(getShell(), - "Input addend", "Enter an integer addend", "0", - new IInputValidator() { - public String isValid(String newText) { - try { - Integer.valueOf(newText); - return null; - } catch (NumberFormatException e) { - return "Enter a number between " - + Integer.MIN_VALUE + " and " - + Integer.MAX_VALUE; - } - } - }); - if (dialog.open() == Window.OK) { - targetAddends.add(Integer.valueOf(dialog.getValue())); - } - } - }); + addAddendButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent e) { + InputDialog dialog = new InputDialog(getShell(), + "Input addend", "Enter an integer addend", "0", + new IInputValidator() { + public String isValid(String newText) { + try { + Integer.valueOf(newText); + return null; + } catch (NumberFormatException e) { + return "Enter a number between " + + Integer.MIN_VALUE + " and " + + Integer.MAX_VALUE; + } + } + }); + if (dialog.open() == Window.OK) { + targetAddends.add(Integer.valueOf(dialog.getValue())); + } + } + }); - removeAddendButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - IStructuredSelection selection = (IStructuredSelection) addendsTarget - .getSelection(); - if (!selection.isEmpty()) - targetAddends.remove(selection.getFirstElement()); - } - }); + removeAddendButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + IStructuredSelection selection = (IStructuredSelection) addendsTarget + .getSelection(); + if (!selection.isEmpty()) + targetAddends.remove(selection.getFirstElement()); + } + }); - IObservableValue modelSum = new WritableValue(new Integer(5), - Integer.TYPE); - dbc.bindValue(SWTObservables.observeText(sumModelValue, SWT.Modify), - modelSum); + IObservableValue modelSum = new WritableValue(new Integer(5), + Integer.TYPE); + dbc.bindValue(SWTObservables.observeText(sumModelValue, SWT.Modify), + modelSum); - IObservableList modelAddends = new WritableList(new ArrayList(), - Integer.TYPE); + IObservableList modelAddends = new WritableList(new ArrayList(), + Integer.TYPE); - MultiValidator validator = new MultiValidator() { - protected IStatus validate() { - Integer sum = (Integer) middleSum.getValue(); - int actualSum = 0; - for (Iterator iterator = targetAddends.iterator(); iterator - .hasNext();) { - actualSum += ((Integer) iterator.next()).intValue(); - } - if (sum.intValue() != actualSum) - return ValidationStatus.error("Sum of addends is " - + actualSum + ", expecting " + sum); - return ValidationStatus.ok(); - } - }; - dbc.addValidationStatusProvider(validator); + MultiValidator validator = new MultiValidator() { + protected IStatus validate() { + Integer sum = (Integer) middleSum.getValue(); + int actualSum = 0; + for (Iterator iterator = targetAddends.iterator(); iterator + .hasNext();) { + actualSum += ((Integer) iterator.next()).intValue(); + } + if (sum.intValue() != actualSum) + return ValidationStatus.error("Sum of addends is " + + actualSum + ", expecting " + sum); + return ValidationStatus.ok(); + } + }; + dbc.addValidationStatusProvider(validator); - addendsModelValue - .setContentProvider(new ObservableListContentProvider()); - addendsModelValue.setInput(modelAddends); + addendsModelValue + .setContentProvider(new ObservableListContentProvider()); + addendsModelValue.setInput(modelAddends); - dbc.bindValue(validator.observeValidatedValue(middleSum), modelSum); - dbc.bindList(validator.observeValidatedList(targetAddends), - modelAddends); - } + dbc.bindValue(validator.observeValidatedValue(middleSum), modelSum); + dbc.bindList(validator.observeValidatedList(targetAddends), + modelAddends); + } + + static class MultiFieldValidationWizard extends Wizard { + public void addPages() { + addPage(new Snippet021MultiFieldValidation()); + } - static class MultiFieldValidationWizard extends Wizard { - public void addPages() { - addPage(new Snippet021MultiFieldValidation()); - } + public String getWindowTitle() { + return "Snippet 021 - Multi-field Validation"; + } - public String getWindowTitle() { - return "Snippet 021 - Multi-field Validation"; - } + public bool performFinish() { + return true; + } + } - public boolean performFinish() { - return true; - } - } + public static void main(String[] args) { + Display display = new Display(); - public static void main(String[] args) { - Display display = new Display(); - - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - IWizard wizard = new MultiFieldValidationWizard(); - WizardDialog dialog = new WizardDialog(null, wizard); - dialog.open(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + IWizard wizard = new MultiFieldValidationWizard(); + WizardDialog dialog = new WizardDialog(null, wizard); + dialog.open(); - // The SWT event loop - Display display = Display.getCurrent(); - while (dialog.getShell() != null - && !dialog.getShell().isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); + // The SWT event loop + Display display = Display.getCurrent(); + while (dialog.getShell() != null + && !dialog.getShell().isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + }); - display.dispose(); - } + display.dispose(); + } } +void main( String[] args ){ + Snippet021MultiFieldValidation.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet022ComputedListCombo.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet022ComputedListCombo.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet022ComputedListCombo.d Wed Apr 22 18:59:26 2009 +0200 @@ -9,7 +9,9 @@ * IBM Corporation - initial API and implementation ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet022ComputedListCombo; + +import java.lang.all; import java.util.ArrayList; import java.util.Iterator; @@ -39,100 +41,103 @@ * */ public class Snippet022ComputedListCombo { - private static WritableList model; + private static WritableList model; - public static void main(String[] args) { - Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new GridLayout(1, false)); + public static void main(String[] args) { + Display display = new Display(); + final Shell shell = new Shell(display); + shell.setLayout(new GridLayout(1, false)); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Snippet022ComputedListCombo snippet = new Snippet022ComputedListCombo(); - snippet.createModel(); - snippet.createControls(shell); - } - }); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + Snippet022ComputedListCombo snippet = new Snippet022ComputedListCombo(); + snippet.createModel(); + snippet.createControls(shell); + } + }); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } - /** - * - */ - protected void createModel() { - model = new WritableList(); - model.add(new Thing("Alice", true, false)); - model.add(new Thing("Beth", true, false)); - model.add(new Thing("Cathy", true, false)); - model.add(new Thing("Arthur", false, true)); - model.add(new Thing("Bob", false, true)); - model.add(new Thing("Curtis", false, true)); - model.add(new Thing("Snail", true, true)); - model.add(new Thing("Nail", false, false)); - } + /** + * + */ + protected void createModel() { + model = new WritableList(); + model.add(new Thing("Alice", true, false)); + model.add(new Thing("Beth", true, false)); + model.add(new Thing("Cathy", true, false)); + model.add(new Thing("Arthur", false, true)); + model.add(new Thing("Bob", false, true)); + model.add(new Thing("Curtis", false, true)); + model.add(new Thing("Snail", true, true)); + model.add(new Thing("Nail", false, false)); + } - /** - * @param shell - */ - protected void createControls(Shell shell) { - Composite composite = new Composite(shell, SWT.NONE); - Group group = new Group(composite, SWT.NONE); - group.setText("Filter"); - Button male = new Button(group, SWT.CHECK); - male.setText("Male"); - Button female = new Button(group, SWT.CHECK); - female.setText("Female"); - final IObservableValue femaleObservable = SWTObservables - .observeSelection(female); - final IObservableValue maleObservable = SWTObservables - .observeSelection(male); - Combo combo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); - GridDataFactory.defaultsFor(combo).align(SWT.BEGINNING, SWT.BEGINNING) - .applyTo(combo); - ComboViewer viewer = new ComboViewer(combo); - viewer.setContentProvider(new ObservableListContentProvider()); - // We should really have an out-of-the box filtered list... - IObservableList filteredList = new ComputedList() { - protected List calculate() { - ArrayList result = new ArrayList(); - for (Iterator it = model.iterator(); it.hasNext();) { - Thing thing = (Thing) it.next(); - if (((Boolean) femaleObservable.getValue()).booleanValue() - && !thing.female) - continue; - if (((Boolean) maleObservable.getValue()).booleanValue() - && !thing.male) - continue; - result.add(thing); - } - return result; - } - }; - viewer.setInput(filteredList); - GridLayoutFactory.swtDefaults().applyTo(group); - GridLayoutFactory.swtDefaults().applyTo(composite); - } + /** + * @param shell + */ + protected void createControls(Shell shell) { + Composite composite = new Composite(shell, SWT.NONE); + Group group = new Group(composite, SWT.NONE); + group.setText("Filter"); + Button male = new Button(group, SWT.CHECK); + male.setText("Male"); + Button female = new Button(group, SWT.CHECK); + female.setText("Female"); + final IObservableValue femaleObservable = SWTObservables + .observeSelection(female); + final IObservableValue maleObservable = SWTObservables + .observeSelection(male); + Combo combo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); + GridDataFactory.defaultsFor(combo).align(SWT.BEGINNING, SWT.BEGINNING) + .applyTo(combo); + ComboViewer viewer = new ComboViewer(combo); + viewer.setContentProvider(new ObservableListContentProvider()); + // We should really have an out-of-the box filtered list... + IObservableList filteredList = new ComputedList() { + protected List calculate() { + ArrayList result = new ArrayList(); + for (Iterator it = model.iterator(); it.hasNext();) { + Thing thing = (Thing) it.next(); + if (((bool) femaleObservable.getValue()).booleanValue() + && !thing.female) + continue; + if (((bool) maleObservable.getValue()).booleanValue() + && !thing.male) + continue; + result.add(thing); + } + return result; + } + }; + viewer.setInput(filteredList); + GridLayoutFactory.swtDefaults().applyTo(group); + GridLayoutFactory.swtDefaults().applyTo(composite); + } - static class Thing { - String name; - boolean male; - boolean female; + static class Thing { + String name; + bool male; + bool female; - public Thing(String name, boolean female, boolean male) { - this.name = name; - this.female = female; - this.male = male; - } + public Thing(String name, bool female, bool male) { + this.name = name; + this.female = female; + this.male = male; + } - public String toString() { - return name; - } - } + public String toString() { + return name; + } + } } +void main( String[] args ){ + Snippet022ComputedListCombo.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet023ConditionalVisibility.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet023ConditionalVisibility.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet023ConditionalVisibility.d Wed Apr 22 18:59:26 2009 +0200 @@ -9,7 +9,9 @@ * IBM Corporation - initial API and implementation ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet023ConditionalVisibility; + +import java.lang.all; import org.eclipse.core.databinding.observable.Realm; import org.eclipse.jface.databinding.swt.ISWTObservableValue; @@ -32,84 +34,87 @@ * */ public class Snippet023ConditionalVisibility { - public static void main(String[] args) { - Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new GridLayout(1, false)); + public static void main(String[] args) { + Display display = new Display(); + final Shell shell = new Shell(display); + shell.setLayout(new GridLayout(1, false)); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - new Snippet023ConditionalVisibility().createControls(shell); - } - }); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + new Snippet023ConditionalVisibility().createControls(shell); + } + }); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } - Text text; - Text toText; - Text fromText; + Text text; + Text toText; + Text fromText; - /** - * @param shell - */ - private void createControls(Shell shell) { - Composite composite = new Composite(shell, SWT.NONE); - Group radioGroup = new Group(composite, SWT.NONE); - radioGroup.setText("Type"); - Button textButton = new Button(radioGroup, SWT.RADIO); - textButton.setText("Text"); - Button rangeButton = new Button(radioGroup, SWT.RADIO); - rangeButton.setText("Range"); - GridLayoutFactory.swtDefaults().generateLayout(radioGroup); + /** + * @param shell + */ + private void createControls(Shell shell) { + Composite composite = new Composite(shell, SWT.NONE); + Group radioGroup = new Group(composite, SWT.NONE); + radioGroup.setText("Type"); + Button textButton = new Button(radioGroup, SWT.RADIO); + textButton.setText("Text"); + Button rangeButton = new Button(radioGroup, SWT.RADIO); + rangeButton.setText("Range"); + GridLayoutFactory.swtDefaults().generateLayout(radioGroup); - final Composite oneOfTwo = new Composite(composite, SWT.NONE); - final StackLayout stackLayout = new StackLayout(); - oneOfTwo.setLayout(stackLayout); + final Composite oneOfTwo = new Composite(composite, SWT.NONE); + final StackLayout stackLayout = new StackLayout(); + oneOfTwo.setLayout(stackLayout); - final Group rangeGroup = new Group(oneOfTwo, SWT.NONE); - rangeGroup.setText("Range"); - Label fromLabel = new Label(rangeGroup, SWT.NONE); - fromLabel.setText("From:"); - fromText = new Text(rangeGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); + final Group rangeGroup = new Group(oneOfTwo, SWT.NONE); + rangeGroup.setText("Range"); + Label fromLabel = new Label(rangeGroup, SWT.NONE); + fromLabel.setText("From:"); + fromText = new Text(rangeGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); - Label toLabel = new Label(rangeGroup, SWT.NONE); - toLabel.setText("To:"); - toText = new Text(rangeGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); - GridLayoutFactory.swtDefaults().numColumns(2) - .generateLayout(rangeGroup); + Label toLabel = new Label(rangeGroup, SWT.NONE); + toLabel.setText("To:"); + toText = new Text(rangeGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); + GridLayoutFactory.swtDefaults().numColumns(2) + .generateLayout(rangeGroup); - final Group textGroup = new Group(oneOfTwo, SWT.NONE); - textGroup.setText("Text"); - Label label = new Label(textGroup, SWT.NONE); - label.setText("Text:"); - text = new Text(textGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); - GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(textGroup); + final Group textGroup = new Group(oneOfTwo, SWT.NONE); + textGroup.setText("Text"); + Label label = new Label(textGroup, SWT.NONE); + label.setText("Text:"); + text = new Text(textGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); + GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(textGroup); + + GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(composite); - GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(composite); - - final ISWTObservableValue rangeSelected = SWTObservables - .observeSelection(rangeButton); - final ISWTObservableValue textSelected = SWTObservables - .observeSelection(textButton); + final ISWTObservableValue rangeSelected = SWTObservables + .observeSelection(rangeButton); + final ISWTObservableValue textSelected = SWTObservables + .observeSelection(textButton); - // Note that ControlUpdater is not API. - new ControlUpdater(oneOfTwo) { - protected void updateControl() { - if (((Boolean) rangeSelected.getValue()).booleanValue()) { - stackLayout.topControl = rangeGroup; - oneOfTwo.layout(); - } else if (((Boolean) textSelected.getValue()).booleanValue()) { - stackLayout.topControl = textGroup; - oneOfTwo.layout(); - } - } - }; - } + // Note that ControlUpdater is not API. + new ControlUpdater(oneOfTwo) { + protected void updateControl() { + if (((bool) rangeSelected.getValue()).booleanValue()) { + stackLayout.topControl = rangeGroup; + oneOfTwo.layout(); + } else if (((bool) textSelected.getValue()).booleanValue()) { + stackLayout.topControl = textGroup; + oneOfTwo.layout(); + } + } + }; + } } +void main( String[] args ){ + Snippet023ConditionalVisibility.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet024SelectObservableValue.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet024SelectObservableValue.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet024SelectObservableValue.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * Matthew Hall - bug 260329 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet024SelectObservableValue; + +import java.lang.all; import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.observable.Realm; @@ -34,90 +36,93 @@ * @since 3.2 */ public class Snippet024SelectObservableValue { - protected Shell shell; + protected Shell shell; - public static void main(String[] args) { - final Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - try { - Snippet024SelectObservableValue window = new Snippet024SelectObservableValue(); - window.open(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } + public static void main(String[] args) { + final Display display = Display.getDefault(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + try { + Snippet024SelectObservableValue window = new Snippet024SelectObservableValue(); + window.open(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } - public void open() { - final Display display = Display.getDefault(); - createContents(); - shell.open(); - shell.layout(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } + public void open() { + final Display display = Display.getDefault(); + createContents(); + shell.open(); + shell.layout(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } - protected void createContents() { - shell = new Shell(); - shell.setSize(400, 300); - shell.setLayout(new GridLayout(2, true)); - shell.setText("Snippet024SelectObservableValue"); + protected void createContents() { + shell = new Shell(); + shell.setSize(400, 300); + shell.setLayout(new GridLayout(2, true)); + shell.setText("Snippet024SelectObservableValue"); - final ListViewer listViewer = new ListViewer(shell, SWT.BORDER); - listViewer.setContentProvider(new ArrayContentProvider()); - listViewer.getList().setLayoutData( - new GridData(SWT.FILL, SWT.FILL, true, true)); + final ListViewer listViewer = new ListViewer(shell, SWT.BORDER); + listViewer.setContentProvider(new ArrayContentProvider()); + listViewer.getList().setLayoutData( + new GridData(SWT.FILL, SWT.FILL, true, true)); - final Group group = new Group(shell, SWT.NONE); - group.setText("Radio Group"); - group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - group.setLayout(new GridLayout()); + final Group group = new Group(shell, SWT.NONE); + group.setText("Radio Group"); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + group.setLayout(new GridLayout()); - // Data Binding - Color[] colors = Color.values(); + // Data Binding + Color[] colors = Color.values(); - listViewer.setInput(colors); - IViewerObservableValue listViewerSelection = ViewersObservables - .observeSingleSelection(listViewer); + listViewer.setInput(colors); + IViewerObservableValue listViewerSelection = ViewersObservables + .observeSingleSelection(listViewer); - SelectObservableValue radioGroup = new SelectObservableValue(); - for (int i = 0; i < colors.length; i++) { - Button button = new Button(group, SWT.RADIO); - button.setText(colors[i].toString()); - radioGroup.addOption(colors[i], SWTObservables - .observeSelection(button)); - } + SelectObservableValue radioGroup = new SelectObservableValue(); + for (int i = 0; i < colors.length; i++) { + Button button = new Button(group, SWT.RADIO); + button.setText(colors[i].toString()); + radioGroup.addOption(colors[i], SWTObservables + .observeSelection(button)); + } - DataBindingContext dbc = new DataBindingContext(); - dbc.bindValue(radioGroup, listViewerSelection); - } + DataBindingContext dbc = new DataBindingContext(); + dbc.bindValue(radioGroup, listViewerSelection); + } - public static class Color { - public static final Color RED = new Color("Red"); - public static final Color ORANGE = new Color("Orange"); - public static final Color YELLOW = new Color("Yellow"); - public static final Color GREEN = new Color("Green"); - public static final Color BLUE = new Color("Blue"); - public static final Color INDIGO = new Color("Indigo"); - public static final Color VIOLET = new Color("Violet"); + public static class Color { + public static final Color RED = new Color("Red"); + public static final Color ORANGE = new Color("Orange"); + public static final Color YELLOW = new Color("Yellow"); + public static final Color GREEN = new Color("Green"); + public static final Color BLUE = new Color("Blue"); + public static final Color INDIGO = new Color("Indigo"); + public static final Color VIOLET = new Color("Violet"); - private final String name; + private final String name; - private Color(String name) { - this.name = name; - } + private Color(String name) { + this.name = name; + } + + public String toString() { + return name; + } - public String toString() { - return name; - } - - public static Color[] values() { - return new Color[] { RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, - VIOLET }; - } - } + public static Color[] values() { + return new Color[] { RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, + VIOLET }; + } + } } +void main( String[] args ){ + Snippet024SelectObservableValue.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet025TableViewerWithPropertyDerivedColumns.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet025TableViewerWithPropertyDerivedColumns.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet025TableViewerWithPropertyDerivedColumns.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * Matthew Hall - bug 195222, 261843, 260337 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet025TableViewerWithPropertyDerivedColumns; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -44,229 +46,232 @@ * Demonstrates binding a TableViewer to a collection. */ public class Snippet025TableViewerWithPropertyDerivedColumns { - public static void main(String[] args) { - final Display display = new Display(); + public static void main(String[] args) { + final Display display = new Display(); - // Set up data binding. In an RCP application, the threading Realm - // will be set for you automatically by the Workbench. In an SWT - // application, you can do this once, wrapping your binding - // method call. - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); + // Set up data binding. In an RCP application, the threading Realm + // will be set for you automatically by the Workbench. In an SWT + // application, you can do this once, wrapping your binding + // method call. + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + ViewModel viewModel = new ViewModel(); + Shell shell = new View(viewModel).createShell(); - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - } + // The SWT event loop + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + }); + } - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); + // Minimal JavaBeans support + public static abstract class AbstractModelObject { + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( + this); - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } + public void addPropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(listener); + } - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(propertyName, + listener); + } - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } + public void removePropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(listener); + } - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } + public void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(propertyName, + listener); + } - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } + protected void firePropertyChange(String propertyName, Object oldValue, + Object newValue) { + propertyChangeSupport.firePropertyChange(propertyName, oldValue, + newValue); + } + } - private static Person UNKNOWN = new Person("unknown", null, null); + private static Person UNKNOWN = new Person("unknown", null, null); - // The data model class. This is normally a persistent class of some sort. - static class Person extends AbstractModelObject { - // A property... - String name = "Donald Duck"; - Person mother; - Person father; + // The data model class. This is normally a persistent class of some sort. + static class Person extends AbstractModelObject { + // A property... + String name = "Donald Duck"; + Person mother; + Person father; - public Person(String name, Person mother, Person father) { - this.name = name; - this.mother = mother; - this.father = father; - } + public Person(String name, Person mother, Person father) { + this.name = name; + this.mother = mother; + this.father = father; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - firePropertyChange("name", this.name, this.name = name); - } + public void setName(String name) { + firePropertyChange("name", this.name, this.name = name); + } - public Person getMother() { - return mother; - } + public Person getMother() { + return mother; + } - public void setMother(Person mother) { - firePropertyChange("mother", this.mother, this.mother = mother); - } + public void setMother(Person mother) { + firePropertyChange("mother", this.mother, this.mother = mother); + } - public Person getFather() { - return father; - } + public Person getFather() { + return father; + } - public void setFather(Person father) { - firePropertyChange("father", this.father, this.father = father); - } - } + public void setFather(Person father) { + firePropertyChange("father", this.father, this.father = father); + } + } - // The View's model--the root of our Model graph for this particular GUI. - // - // Typically each View class has a corresponding ViewModel class. - // The ViewModel is responsible for getting the objects to edit from the - // data access tier. Since this snippet doesn't have any persistent objects - // ro retrieve, this ViewModel just instantiates a model object to edit. - static class ViewModel { - // The model to bind - private IObservableList people = new WritableList(); - { - Person fergus = new Person("Fergus McDuck", UNKNOWN, UNKNOWN); - Person downy = new Person("Downy O'Drake", UNKNOWN, UNKNOWN); - Person scrooge = new Person("Scrooge McDuck", downy, fergus); - Person hortense = new Person("Hortense McDuck", downy, fergus); - Person quackmore = new Person("Quackmore Duck", UNKNOWN, UNKNOWN); - Person della = new Person("Della Duck", hortense, quackmore); - Person donald = new Person("Donald Duck", hortense, quackmore); - people.add(UNKNOWN); - people.add(downy); - people.add(fergus); - people.add(scrooge); - people.add(quackmore); - people.add(hortense); - people.add(della); - people.add(donald); - } + // The View's model--the root of our Model graph for this particular GUI. + // + // Typically each View class has a corresponding ViewModel class. + // The ViewModel is responsible for getting the objects to edit from the + // data access tier. Since this snippet doesn't have any persistent objects + // ro retrieve, this ViewModel just instantiates a model object to edit. + static class ViewModel { + // The model to bind + private IObservableList people = new WritableList(); + { + Person fergus = new Person("Fergus McDuck", UNKNOWN, UNKNOWN); + Person downy = new Person("Downy O'Drake", UNKNOWN, UNKNOWN); + Person scrooge = new Person("Scrooge McDuck", downy, fergus); + Person hortense = new Person("Hortense McDuck", downy, fergus); + Person quackmore = new Person("Quackmore Duck", UNKNOWN, UNKNOWN); + Person della = new Person("Della Duck", hortense, quackmore); + Person donald = new Person("Donald Duck", hortense, quackmore); + people.add(UNKNOWN); + people.add(downy); + people.add(fergus); + people.add(scrooge); + people.add(quackmore); + people.add(hortense); + people.add(della); + people.add(donald); + } + + public IObservableList getPeople() { + return people; + } + } - public IObservableList getPeople() { - return people; - } - } + // The GUI view + static class View { + private ViewModel viewModel; + private Table duckFamily; + private Text nameText; + private Combo motherCombo; + private Combo fatherCombo; - // The GUI view - static class View { - private ViewModel viewModel; - private Table duckFamily; - private Text nameText; - private Combo motherCombo; - private Combo fatherCombo; - - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } + public View(ViewModel viewModel) { + this.viewModel = viewModel; + } - public Shell createShell() { - // Build a UI - Display display = Display.getDefault(); - Shell shell = new Shell(display); - duckFamily = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); - duckFamily.setHeaderVisible(true); - GridDataFactory.defaultsFor(duckFamily).span(2, 1).applyTo( - duckFamily); - createColumn("Name"); - createColumn("Mother"); - createColumn("Father"); - createColumn("Maternal Grandmother"); - createColumn("Maternal Grandfather"); - createColumn("Paternal Grandmother"); - createColumn("Paternal Grandfather"); + public Shell createShell() { + // Build a UI + Display display = Display.getDefault(); + Shell shell = new Shell(display); + duckFamily = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); + duckFamily.setHeaderVisible(true); + GridDataFactory.defaultsFor(duckFamily).span(2, 1).applyTo( + duckFamily); + createColumn("Name"); + createColumn("Mother"); + createColumn("Father"); + createColumn("Maternal Grandmother"); + createColumn("Maternal Grandfather"); + createColumn("Paternal Grandmother"); + createColumn("Paternal Grandfather"); - duckFamily.setLinesVisible(true); + duckFamily.setLinesVisible(true); + + new Label(shell, SWT.NONE).setText("Name:"); + nameText = new Text(shell, SWT.BORDER); + GridDataFactory.defaultsFor(nameText).grab(true, false).applyTo( + nameText); - new Label(shell, SWT.NONE).setText("Name:"); - nameText = new Text(shell, SWT.BORDER); - GridDataFactory.defaultsFor(nameText).grab(true, false).applyTo( - nameText); + new Label(shell, SWT.NONE).setText("Mother:"); + motherCombo = new Combo(shell, SWT.READ_ONLY); + + new Label(shell, SWT.NONE).setText("Father:"); + fatherCombo = new Combo(shell, SWT.READ_ONLY); - new Label(shell, SWT.NONE).setText("Mother:"); - motherCombo = new Combo(shell, SWT.READ_ONLY); + DataBindingContext bindingContext = new DataBindingContext(); + bindGUI(bindingContext); - new Label(shell, SWT.NONE).setText("Father:"); - fatherCombo = new Combo(shell, SWT.READ_ONLY); - - DataBindingContext bindingContext = new DataBindingContext(); - bindGUI(bindingContext); + GridLayoutFactory.swtDefaults().numColumns(2).applyTo(shell); + // Open and return the Shell + shell.setSize(800, 300); + shell.open(); + return shell; + } - GridLayoutFactory.swtDefaults().numColumns(2).applyTo(shell); - // Open and return the Shell - shell.setSize(800, 300); - shell.open(); - return shell; - } + private void createColumn(String string) { + final TableColumn column = new TableColumn(duckFamily, SWT.NONE); + column.setText(string); + column.pack(); + if (column.getWidth() < 100) + column.setWidth(100); + } - private void createColumn(String string) { - final TableColumn column = new TableColumn(duckFamily, SWT.NONE); - column.setText(string); - column.pack(); - if (column.getWidth() < 100) - column.setWidth(100); - } + protected void bindGUI(DataBindingContext dbc) { + // Since we're using a JFace Viewer, we do first wrap our Table... + TableViewer peopleViewer = new TableViewer(duckFamily); + peopleViewer.addFilter(new ViewerFilter() { + public bool select(Viewer viewer, Object parentElement, + Object element) { + return element != UNKNOWN; + } + }); - protected void bindGUI(DataBindingContext dbc) { - // Since we're using a JFace Viewer, we do first wrap our Table... - TableViewer peopleViewer = new TableViewer(duckFamily); - peopleViewer.addFilter(new ViewerFilter() { - public boolean select(Viewer viewer, Object parentElement, - Object element) { - return element != UNKNOWN; - } - }); + ViewerSupport.bind(peopleViewer, viewModel.getPeople(), + BeanProperties.values(Person.class, new String[] { "name", + "mother.name", "father.name", "mother.mother.name", + "mother.father.name", "father.mother.name", + "father.father.name" })); - ViewerSupport.bind(peopleViewer, viewModel.getPeople(), - BeanProperties.values(Person.class, new String[] { "name", - "mother.name", "father.name", "mother.mother.name", - "mother.father.name", "father.mother.name", - "father.father.name" })); + IObservableValue masterSelection = ViewerProperties + .singleSelection().observe(peopleViewer); - IObservableValue masterSelection = ViewerProperties - .singleSelection().observe(peopleViewer); + dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(nameText), + BeanProperties.value(Person.class, "name").observeDetail( + masterSelection)); + + ComboViewer mothercomboViewer = new ComboViewer(motherCombo); + ViewerSupport.bind(mothercomboViewer, viewModel.getPeople(), + BeanProperties.value(Person.class, "name")); - dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(nameText), - BeanProperties.value(Person.class, "name").observeDetail( - masterSelection)); + dbc.bindValue(ViewerProperties.singleSelection().observe( + mothercomboViewer), BeanProperties.value(Person.class, + "mother").observeDetail(masterSelection)); - ComboViewer mothercomboViewer = new ComboViewer(motherCombo); - ViewerSupport.bind(mothercomboViewer, viewModel.getPeople(), - BeanProperties.value(Person.class, "name")); + ComboViewer fatherComboViewer = new ComboViewer(fatherCombo); + ViewerSupport.bind(fatherComboViewer, viewModel.getPeople(), + BeanProperties.value(Person.class, "name")); - dbc.bindValue(ViewerProperties.singleSelection().observe( - mothercomboViewer), BeanProperties.value(Person.class, - "mother").observeDetail(masterSelection)); - - ComboViewer fatherComboViewer = new ComboViewer(fatherCombo); - ViewerSupport.bind(fatherComboViewer, viewModel.getPeople(), - BeanProperties.value(Person.class, "name")); - - dbc.bindValue(ViewerProperties.singleSelection().observe( - fatherComboViewer), BeanProperties.value(Person.class, - "father").observeDetail(masterSelection)); - } - } + dbc.bindValue(ViewerProperties.singleSelection().observe( + fatherComboViewer), BeanProperties.value(Person.class, + "father").observeDetail(masterSelection)); + } + } } +void main( String[] args ){ + Snippet025TableViewerWithPropertyDerivedColumns.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet026AnonymousBeanProperties.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet026AnonymousBeanProperties.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet026AnonymousBeanProperties.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * Matthew Hall - bugs 261843, 260337, 265561 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet026AnonymousBeanProperties; + +import java.lang.all; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -56,345 +58,348 @@ * */ public class Snippet026AnonymousBeanProperties { - private ComboViewer statusViewer; - private Combo combo; - private Text nameText; - private TreeViewer contactViewer; + private ComboViewer statusViewer; + private Combo combo; + private Text nameText; + private TreeViewer contactViewer; - public static void main(String[] args) { - Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - try { - Snippet026AnonymousBeanProperties window = new Snippet026AnonymousBeanProperties(); - window.open(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } + public static void main(String[] args) { + Display display = new Display(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + try { + Snippet026AnonymousBeanProperties window = new Snippet026AnonymousBeanProperties(); + window.open(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } - private ApplicationModel model; - private Shell shell; - private Tree tree; + private ApplicationModel model; + private Shell shell; + private Tree tree; - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); + // Minimal JavaBeans support + public static abstract class AbstractModelObject { + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( + this); - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } + public void addPropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(listener); + } - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(propertyName, + listener); + } - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } + public void removePropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(listener); + } - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } + public void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(propertyName, + listener); + } - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } + protected void firePropertyChange(String propertyName, Object oldValue, + Object newValue) { + propertyChangeSupport.firePropertyChange(propertyName, oldValue, + newValue); + } + } - public static class ContactGroup extends AbstractModelObject implements - Comparable { - private String name; - private Set contacts = new TreeSet(); + public static class ContactGroup extends AbstractModelObject implements + Comparable { + private String name; + private Set contacts = new TreeSet(); - ContactGroup(String name) { - this.name = checkNull(name); - } + ContactGroup(String name) { + this.name = checkNull(name); + } - private String checkNull(String string) { - if (string == null) - throw new NullPointerException(); - return string; - } + private String checkNull(String string) { + if (string == null) + throw new NullPointerException(); + return string; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - firePropertyChange("name", this.name, this.name = checkNull(name)); - } + public void setName(String name) { + firePropertyChange("name", this.name, this.name = checkNull(name)); + } - public Set getContacts() { - return new TreeSet(contacts); - } + public Set getContacts() { + return new TreeSet(contacts); + } - public void addContact(Contact contact) { - Set oldValue = getContacts(); - contacts.add(contact); - Set newValue = getContacts(); - firePropertyChange("contacts", oldValue, newValue); - } + public void addContact(Contact contact) { + Set oldValue = getContacts(); + contacts.add(contact); + Set newValue = getContacts(); + firePropertyChange("contacts", oldValue, newValue); + } - public void removeContact(Contact contact) { - Set oldValue = getContacts(); - contacts.remove(contact); - Set newValue = getContacts(); - firePropertyChange("contacts", oldValue, newValue); - } + public void removeContact(Contact contact) { + Set oldValue = getContacts(); + contacts.remove(contact); + Set newValue = getContacts(); + firePropertyChange("contacts", oldValue, newValue); + } - public int compareTo(Object o) { - ContactGroup that = (ContactGroup) o; - return this.name.compareTo(that.name); - } - } + public int compareTo(Object o) { + ContactGroup that = (ContactGroup) o; + return this.name.compareTo(that.name); + } + } - public static class Contact extends AbstractModelObject implements - Comparable { - private String name; - private String status; + public static class Contact extends AbstractModelObject implements + Comparable { + private String name; + private String status; - private String checkNull(String string) { - if (string == null) - throw new NullPointerException(); - return string; - } + private String checkNull(String string) { + if (string == null) + throw new NullPointerException(); + return string; + } - public Contact(String name, String status) { - this.name = checkNull(name); - this.status = checkNull(status); - } + public Contact(String name, String status) { + this.name = checkNull(name); + this.status = checkNull(status); + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - firePropertyChange("name", this.name, this.name = checkNull(name)); - } + public void setName(String name) { + firePropertyChange("name", this.name, this.name = checkNull(name)); + } - public String getStatus() { - return status; - } + public String getStatus() { + return status; + } - public void setStatus(String status) { - firePropertyChange("status", this.status, - this.status = checkNull(status)); - } + public void setStatus(String status) { + firePropertyChange("status", this.status, + this.status = checkNull(status)); + } - public int compareTo(Object o) { - Contact that = (Contact) o; - int result = this.name.compareTo(that.name); - if (result == 0) - result = this.status.compareTo(that.status); - return result; - } - } + public int compareTo(Object o) { + Contact that = (Contact) o; + int result = this.name.compareTo(that.name); + if (result == 0) + result = this.status.compareTo(that.status); + return result; + } + } - public static class ApplicationModel extends AbstractModelObject { - private Set groups = new TreeSet(); + public static class ApplicationModel extends AbstractModelObject { + private Set groups = new TreeSet(); - public Set getGroups() { - return new TreeSet(groups); - } + public Set getGroups() { + return new TreeSet(groups); + } - public void setGroups(Set groups) { - Set oldValue = getGroups(); - this.groups = new TreeSet(groups); - Set newValue = getGroups(); - firePropertyChange("groups", oldValue, newValue); - } - } + public void setGroups(Set groups) { + Set oldValue = getGroups(); + this.groups = new TreeSet(groups); + Set newValue = getGroups(); + firePropertyChange("groups", oldValue, newValue); + } + } - /** - * Set property for the "contacts" property of a ContactGroup. Since - * ContactGroup does not have a setContacts() method we have to write our - * own property to apply set changes incrementally through the addContact - * and removeContact methods. - */ - public static class ContactGroupContactsProperty extends SimpleSetProperty { - public Object getElementType() { - return Contact.class; - } + /** + * Set property for the "contacts" property of a ContactGroup. Since + * ContactGroup does not have a setContacts() method we have to write our + * own property to apply set changes incrementally through the addContact + * and removeContact methods. + */ + public static class ContactGroupContactsProperty extends SimpleSetProperty { + public Object getElementType() { + return Contact.class; + } - protected Set doGetSet(Object source) { - if (source == null) - return Collections.EMPTY_SET; - return ((ContactGroup) source).getContacts(); - } + protected Set doGetSet(Object source) { + if (source == null) + return Collections.EMPTY_SET; + return ((ContactGroup) source).getContacts(); + } - protected void doSetSet(Object source, Set set, SetDiff diff) { - ContactGroup group = (ContactGroup) source; - for (Iterator it = diff.getRemovals().iterator(); it.hasNext();) { - Contact contact = (Contact) it.next(); - group.removeContact(contact); - } - for (Iterator it = diff.getAdditions().iterator(); it.hasNext();) { - Contact contact = (Contact) it.next(); - group.addContact(contact); - } - } + protected void doSetSet(Object source, Set set, SetDiff diff) { + ContactGroup group = (ContactGroup) source; + for (Iterator it = diff.getRemovals().iterator(); it.hasNext();) { + Contact contact = (Contact) it.next(); + group.removeContact(contact); + } + for (Iterator it = diff.getAdditions().iterator(); it.hasNext();) { + Contact contact = (Contact) it.next(); + group.addContact(contact); + } + } - public INativePropertyListener adaptListener( - final ISimplePropertyListener listener) { - return new Listener(this, listener); - } + public INativePropertyListener adaptListener( + final ISimplePropertyListener listener) { + return new Listener(this, listener); + } - private class Listener extends NativePropertyListener implements - PropertyChangeListener { - Listener(IProperty property, ISimplePropertyListener listener) { - super(property, listener); - } + private class Listener extends NativePropertyListener implements + PropertyChangeListener { + Listener(IProperty property, ISimplePropertyListener listener) { + super(property, listener); + } - public void propertyChange(PropertyChangeEvent evt) { - fireChange(evt.getSource(), null); - } + public void propertyChange(PropertyChangeEvent evt) { + fireChange(evt.getSource(), null); + } - protected void doAddTo(Object source) { - ((ContactGroup) source).addPropertyChangeListener("contacts", - this); - } + protected void doAddTo(Object source) { + ((ContactGroup) source).addPropertyChangeListener("contacts", + this); + } - protected void doRemoveFrom(Object source) { - ((ContactGroup) source).removePropertyChangeListener( - "contacts", this); - } - } - } + protected void doRemoveFrom(Object source) { + ((ContactGroup) source).removePropertyChangeListener( + "contacts", this); + } + } + } - public void open() { - model = createDefaultModel(); + public void open() { + model = createDefaultModel(); - final Display display = Display.getDefault(); - createContents(); - bindUI(); - shell.open(); - shell.layout(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } + final Display display = Display.getDefault(); + createContents(); + bindUI(); + shell.open(); + shell.layout(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } + + private static final String[] statuses = new String[] { "Online", "Idle", + "Busy", "Offline" }; - private static final String[] statuses = new String[] { "Online", "Idle", - "Busy", "Offline" }; + /** + * @return + */ + private ApplicationModel createDefaultModel() { + ContactGroup swtGroup = new ContactGroup("SWT"); + swtGroup.addContact(new Contact("Steve Northover", "Busy")); + swtGroup.addContact(new Contact("Grant Gayed", "Online")); + swtGroup.addContact(new Contact("Veronika Irvine", "Offline")); + swtGroup.addContact(new Contact("Mike Wilson", "Online")); + swtGroup.addContact(new Contact("Christophe Cornu", "Idle")); + swtGroup.addContact(new Contact("Lynne Kues", "Online")); + swtGroup.addContact(new Contact("Silenio Quarti", "Idle")); - /** - * @return - */ - private ApplicationModel createDefaultModel() { - ContactGroup swtGroup = new ContactGroup("SWT"); - swtGroup.addContact(new Contact("Steve Northover", "Busy")); - swtGroup.addContact(new Contact("Grant Gayed", "Online")); - swtGroup.addContact(new Contact("Veronika Irvine", "Offline")); - swtGroup.addContact(new Contact("Mike Wilson", "Online")); - swtGroup.addContact(new Contact("Christophe Cornu", "Idle")); - swtGroup.addContact(new Contact("Lynne Kues", "Online")); - swtGroup.addContact(new Contact("Silenio Quarti", "Idle")); + ContactGroup jdbGroup = new ContactGroup("JFace Data Binding"); + jdbGroup.addContact(new Contact("Boris Bokowski", "Online")); + jdbGroup.addContact(new Contact("Matthew Hall", "Idle")); - ContactGroup jdbGroup = new ContactGroup("JFace Data Binding"); - jdbGroup.addContact(new Contact("Boris Bokowski", "Online")); - jdbGroup.addContact(new Contact("Matthew Hall", "Idle")); + Set groups = new TreeSet(); + groups.add(swtGroup); + groups.add(jdbGroup); + ApplicationModel model = new ApplicationModel(); + model.setGroups(groups); - Set groups = new TreeSet(); - groups.add(swtGroup); - groups.add(jdbGroup); - ApplicationModel model = new ApplicationModel(); - model.setGroups(groups); + return model; + } - return model; - } + /** + * Create contents of the window + */ + protected void createContents() { + shell = new Shell(); + shell.setSize(379, 393); + shell.setText("Snippet026AnonymousBeanProperties"); + final GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 4; + shell.setLayout(gridLayout); - /** - * Create contents of the window - */ - protected void createContents() { - shell = new Shell(); - shell.setSize(379, 393); - shell.setText("Snippet026AnonymousBeanProperties"); - final GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 4; - shell.setLayout(gridLayout); + contactViewer = new TreeViewer(shell, SWT.BORDER); + tree = contactViewer.getTree(); + tree.setHeaderVisible(true); + tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1)); - contactViewer = new TreeViewer(shell, SWT.BORDER); - tree = contactViewer.getTree(); - tree.setHeaderVisible(true); - tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1)); + final TreeColumn nameColumn = new TreeColumn(tree, SWT.NONE); + nameColumn.setWidth(163); + nameColumn.setText("Name"); - final TreeColumn nameColumn = new TreeColumn(tree, SWT.NONE); - nameColumn.setWidth(163); - nameColumn.setText("Name"); + final TreeColumn newColumnTreeColumn = new TreeColumn(tree, SWT.NONE); + newColumnTreeColumn.setWidth(100); + newColumnTreeColumn.setText("Status"); - final TreeColumn newColumnTreeColumn = new TreeColumn(tree, SWT.NONE); - newColumnTreeColumn.setWidth(100); - newColumnTreeColumn.setText("Status"); - - final Label nameLabel = new Label(shell, SWT.NONE); - nameLabel.setText("Name"); + final Label nameLabel = new Label(shell, SWT.NONE); + nameLabel.setText("Name"); - nameText = new Text(shell, SWT.BORDER); - final GridData gd_nameText = new GridData(SWT.FILL, SWT.CENTER, true, - false); - nameText.setLayoutData(gd_nameText); + nameText = new Text(shell, SWT.BORDER); + final GridData gd_nameText = new GridData(SWT.FILL, SWT.CENTER, true, + false); + nameText.setLayoutData(gd_nameText); - final Label statusLabel = new Label(shell, SWT.NONE); - statusLabel.setLayoutData(new GridData()); - statusLabel.setText("Status"); + final Label statusLabel = new Label(shell, SWT.NONE); + statusLabel.setLayoutData(new GridData()); + statusLabel.setText("Status"); - statusViewer = new ComboViewer(shell, SWT.READ_ONLY); - combo = statusViewer.getCombo(); - combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - } + statusViewer = new ComboViewer(shell, SWT.READ_ONLY); + combo = statusViewer.getCombo(); + combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + } - private void bindUI() { - ISetProperty treeChildrenProperty = new DelegatingSetProperty() { - ISetProperty modelGroups = BeanProperties.set( - ApplicationModel.class, "groups"); - ISetProperty groupContacts = BeanProperties.set(ContactGroup.class, - "contacts"); + private void bindUI() { + ISetProperty treeChildrenProperty = new DelegatingSetProperty() { + ISetProperty modelGroups = BeanProperties.set( + ApplicationModel.class, "groups"); + ISetProperty groupContacts = BeanProperties.set(ContactGroup.class, + "contacts"); - protected ISetProperty doGetDelegate(Object source) { - if (source instanceof ApplicationModel) - return modelGroups; - if (source instanceof ContactGroup) - return groupContacts; - return null; - } - }; + protected ISetProperty doGetDelegate(Object source) { + if (source instanceof ApplicationModel) + return modelGroups; + if (source instanceof ContactGroup) + return groupContacts; + return null; + } + }; - ViewerSupport.bind(contactViewer, model, treeChildrenProperty, - BeanProperties.values(new String[] { "name", "status" })); + ViewerSupport.bind(contactViewer, model, treeChildrenProperty, + BeanProperties.values(new String[] { "name", "status" })); - contactViewer.expandAll(); + contactViewer.expandAll(); - final IObservableValue selection = ViewerProperties.singleSelection() - .observe(contactViewer); + final IObservableValue selection = ViewerProperties.singleSelection() + .observe(contactViewer); - DataBindingContext dbc = new DataBindingContext(); + DataBindingContext dbc = new DataBindingContext(); - dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(nameText), - BeanProperties.value("name").observeDetail(selection)); + dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(nameText), + BeanProperties.value("name").observeDetail(selection)); - statusViewer.setContentProvider(new ArrayContentProvider()); - statusViewer.setInput(statuses); + statusViewer.setContentProvider(new ArrayContentProvider()); + statusViewer.setInput(statuses); - dbc.bindValue(ViewerProperties.singleSelection().observe(statusViewer), - BeanProperties.value("status").observeDetail(selection)); + dbc.bindValue(ViewerProperties.singleSelection().observe(statusViewer), + BeanProperties.value("status").observeDetail(selection)); - dbc.bindValue(WidgetProperties.enabled().observe( - statusViewer.getControl()), new ComputedValue() { - protected Object calculate() { - return Boolean.valueOf(selection.getValue() instanceof Contact); - } - }); - } + dbc.bindValue(WidgetProperties.enabled().observe( + statusViewer.getControl()), new ComputedValue() { + protected Object calculate() { + return bool.valueOf(selection.getValue() instanceof Contact); + } + }); + } } +void main( String[] args ){ + Snippet026AnonymousBeanProperties.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet027ExternalValidator.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet027ExternalValidator.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet027ExternalValidator.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * Boris Bokowski, IBM - minor changes ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet027ExternalValidator; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -44,219 +46,222 @@ */ public class Snippet027ExternalValidator extends WizardPage { - private Text nameValue; - private Text emailValue; - private Text phoneNumberValue; + private Text nameValue; + private Text emailValue; + private Text phoneNumberValue; - private Contact contact; + private Contact contact; - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); + // Minimal JavaBeans support + public static abstract class AbstractModelObject { + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( + this); - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } + public void addPropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(listener); + } - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(propertyName, + listener); + } - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } + public void removePropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(listener); + } - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } + public void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(propertyName, + listener); + } - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } + protected void firePropertyChange(String propertyName, Object oldValue, + Object newValue) { + propertyChangeSupport.firePropertyChange(propertyName, oldValue, + newValue); + } + } - static class Contact extends AbstractModelObject { - String name; - String email; - String phoneNumber; + static class Contact extends AbstractModelObject { + String name; + String email; + String phoneNumber; - public Contact(String name, String email, String number) { - this.name = name; - this.email = email; - this.phoneNumber = number; - } + public Contact(String name, String email, String number) { + this.name = name; + this.email = email; + this.phoneNumber = number; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - String oldValue = this.name; - this.name = name; - firePropertyChange("name", oldValue, name); - } + public void setName(String name) { + String oldValue = this.name; + this.name = name; + firePropertyChange("name", oldValue, name); + } - public String getEmail() { - return email; - } + public String getEmail() { + return email; + } - public void setEmail(String email) { - String oldValue = this.email; - this.email = email; - firePropertyChange("email", oldValue, email); - } + public void setEmail(String email) { + String oldValue = this.email; + this.email = email; + firePropertyChange("email", oldValue, email); + } - public String getPhoneNumber() { - return phoneNumber; - } + public String getPhoneNumber() { + return phoneNumber; + } - public void setPhoneNumber(String number) { - String oldValue = this.phoneNumber; - this.phoneNumber = number; - firePropertyChange("phoneNumber", oldValue, number); - } + public void setPhoneNumber(String number) { + String oldValue = this.phoneNumber; + this.phoneNumber = number; + firePropertyChange("phoneNumber", oldValue, number); + } - public IStatus validate() { - if (name.indexOf(' ') == -1) { - return ValidationStatus - .error("Please enter both first and last name separated by a space."); - } - if (email.indexOf('@') == -1) { - return ValidationStatus - .error("Please enter a valid email address containing '@'."); - } - if (!phoneNumber.startsWith("+")) { - return ValidationStatus - .error("Please enter the phone number in international format starting with '+'."); - } - return Status.OK_STATUS; - } + public IStatus validate() { + if (name.indexOf(' ') == -1) { + return ValidationStatus + .error("Please enter both first and last name separated by a space."); + } + if (email.indexOf('@') == -1) { + return ValidationStatus + .error("Please enter a valid email address containing '@'."); + } + if (!phoneNumber.startsWith("+")) { + return ValidationStatus + .error("Please enter the phone number in international format starting with '+'."); + } + return Status.OK_STATUS; + } - } + } - /** - * Create the wizard - */ - public Snippet027ExternalValidator() { - super("snippet024"); - setTitle("Snippet 024 - External Validation"); - setDescription("Please enter contact details."); - } + /** + * Create the wizard + */ + public Snippet027ExternalValidator() { + super("snippet024"); + setTitle("Snippet 024 - External Validation"); + setDescription("Please enter contact details."); + } - /** - * Create contents of the wizard - * - * @param parent - */ - public void createControl(Composite parent) { - Composite container = new Composite(parent, SWT.NULL); - final GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - container.setLayout(gridLayout); - setControl(container); + /** + * Create contents of the wizard + * + * @param parent + */ + public void createControl(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + final GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 2; + container.setLayout(gridLayout); + setControl(container); - final Label nameLabel = new Label(container, SWT.NONE); - nameLabel.setText("Name"); + final Label nameLabel = new Label(container, SWT.NONE); + nameLabel.setText("Name"); - nameValue = new Text(container, SWT.BORDER); - final GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); - nameValue.setLayoutData(gd); + nameValue = new Text(container, SWT.BORDER); + final GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); + nameValue.setLayoutData(gd); - final Label emailLabel = new Label(container, SWT.NONE); - emailLabel.setText("Email"); + final Label emailLabel = new Label(container, SWT.NONE); + emailLabel.setText("Email"); - emailValue = new Text(container, SWT.BORDER); - emailValue.setLayoutData(gd); + emailValue = new Text(container, SWT.BORDER); + emailValue.setLayoutData(gd); - final Label phoneLabel = new Label(container, SWT.NONE); - phoneLabel.setText("Phone"); + final Label phoneLabel = new Label(container, SWT.NONE); + phoneLabel.setText("Phone"); - phoneNumberValue = new Text(container, SWT.BORDER); - phoneNumberValue.setLayoutData(gd); + phoneNumberValue = new Text(container, SWT.BORDER); + phoneNumberValue.setLayoutData(gd); - contact = new Contact("BorisBokowski", "boris.at.somecompany.com", - "1-123-456-7890"); + contact = new Contact("BorisBokowski", "boris.at.somecompany.com", + "1-123-456-7890"); - bindUI(); - } + bindUI(); + } - private void bindUI() { - DataBindingContext dbc = new DataBindingContext(); + private void bindUI() { + DataBindingContext dbc = new DataBindingContext(); - final IObservableValue name = BeansObservables.observeValue(contact, - "name"); - dbc.bindValue(SWTObservables.observeText(nameValue, SWT.Modify), name, - null, null); + final IObservableValue name = BeansObservables.observeValue(contact, + "name"); + dbc.bindValue(SWTObservables.observeText(nameValue, SWT.Modify), name, + null, null); - final IObservableValue email = BeansObservables.observeValue(contact, - "email"); - dbc.bindValue(SWTObservables.observeText(emailValue, SWT.Modify), - email, null, null); + final IObservableValue email = BeansObservables.observeValue(contact, + "email"); + dbc.bindValue(SWTObservables.observeText(emailValue, SWT.Modify), + email, null, null); - final IObservableValue phone = BeansObservables.observeValue(contact, - "phoneNumber"); - dbc.bindValue(SWTObservables.observeText(phoneNumberValue, SWT.Modify), - phone, null, null); + final IObservableValue phone = BeansObservables.observeValue(contact, + "phoneNumber"); + dbc.bindValue(SWTObservables.observeText(phoneNumberValue, SWT.Modify), + phone, null, null); - MultiValidator validator = new MultiValidator() { - protected IStatus validate() { + MultiValidator validator = new MultiValidator() { + protected IStatus validate() { - // Everything accessed here will trigger re-validation. - name.getValue(); - email.getValue(); - phone.getValue(); + // Everything accessed here will trigger re-validation. + name.getValue(); + email.getValue(); + phone.getValue(); - System.out.println("Validating..."); + System.out.println("Validating..."); - return contact.validate(); - } - }; - dbc.addValidationStatusProvider(validator); + return contact.validate(); + } + }; + dbc.addValidationStatusProvider(validator); - WizardPageSupport.create(this, dbc); - } + WizardPageSupport.create(this, dbc); + } - static class ExternalValidationWizard extends Wizard { - public void addPages() { - addPage(new Snippet027ExternalValidator()); - } + static class ExternalValidationWizard extends Wizard { + public void addPages() { + addPage(new Snippet027ExternalValidator()); + } - public String getWindowTitle() { - return "Snippet 024 - External Validation"; - } + public String getWindowTitle() { + return "Snippet 024 - External Validation"; + } - public boolean performFinish() { - return true; - } - } + public bool performFinish() { + return true; + } + } - public static void main(String[] args) { - Display display = new Display(); + public static void main(String[] args) { + Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - IWizard wizard = new ExternalValidationWizard(); - WizardDialog dialog = new WizardDialog(null, wizard); - dialog.open(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + IWizard wizard = new ExternalValidationWizard(); + WizardDialog dialog = new WizardDialog(null, wizard); + dialog.open(); - // The SWT event loop - Display display = Display.getCurrent(); - while (dialog.getShell() != null - && !dialog.getShell().isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); + // The SWT event loop + Display display = Display.getCurrent(); + while (dialog.getShell() != null + && !dialog.getShell().isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + }); - display.dispose(); - } -} \ No newline at end of file + display.dispose(); + } +} +void main( String[] args ){ + Snippet027ExternalValidator.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet028DuplexingObservableValue.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet028DuplexingObservableValue.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet028DuplexingObservableValue.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * Matthew Hall - bugs 262407, 260337 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet028DuplexingObservableValue; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -42,256 +44,259 @@ * */ public class Snippet028DuplexingObservableValue { - protected Shell shell; - private TableViewer viewer; - private Table table; - private Text releaseDate; - private Text title; - private Text director; - private Text writer; + protected Shell shell; + private TableViewer viewer; + private Table table; + private Text releaseDate; + private Text title; + private Text director; + private Text writer; - /** - * Launch the application - * - * @param args - */ - public static void main(String[] args) { - try { - Snippet028DuplexingObservableValue window = new Snippet028DuplexingObservableValue(); - window.open(); - } catch (Exception e) { - e.printStackTrace(); - } - } + /** + * Launch the application + * + * @param args + */ + public static void main(String[] args) { + try { + Snippet028DuplexingObservableValue window = new Snippet028DuplexingObservableValue(); + window.open(); + } catch (Exception e) { + e.printStackTrace(); + } + } - /** - * Open the window - */ - public void open() { - final Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - createContents(); - shell.open(); - shell.layout(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - } + /** + * Open the window + */ + public void open() { + final Display display = Display.getDefault(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + createContents(); + shell.open(); + shell.layout(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } + }); + } - protected void createContents() { - shell = new Shell(); - shell.setSize(509, 375); - shell.setText("Snippet028DuplexingObservableValue.java"); - final GridLayout gridLayout = new GridLayout(); - gridLayout.makeColumnsEqualWidth = true; - gridLayout.numColumns = 4; - shell.setLayout(gridLayout); + protected void createContents() { + shell = new Shell(); + shell.setSize(509, 375); + shell.setText("Snippet028DuplexingObservableValue.java"); + final GridLayout gridLayout = new GridLayout(); + gridLayout.makeColumnsEqualWidth = true; + gridLayout.numColumns = 4; + shell.setLayout(gridLayout); - viewer = new TableViewer(shell, SWT.FULL_SELECTION | SWT.MULTI - | SWT.BORDER); - table = viewer.getTable(); - table.setLinesVisible(true); - table.setHeaderVisible(true); - table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1)); + viewer = new TableViewer(shell, SWT.FULL_SELECTION | SWT.MULTI + | SWT.BORDER); + table = viewer.getTable(); + table.setLinesVisible(true); + table.setHeaderVisible(true); + table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1)); - final TableColumn newColumnTableColumn_1 = new TableColumn(table, - SWT.NONE); - newColumnTableColumn_1.setWidth(120); - newColumnTableColumn_1.setText("Movie"); + final TableColumn newColumnTableColumn_1 = new TableColumn(table, + SWT.NONE); + newColumnTableColumn_1.setWidth(120); + newColumnTableColumn_1.setText("Movie"); + + final TableColumn newColumnTableColumn = new TableColumn(table, + SWT.NONE); - final TableColumn newColumnTableColumn = new TableColumn(table, - SWT.NONE); + newColumnTableColumn.setWidth(120); + newColumnTableColumn.setText("Release Date"); - newColumnTableColumn.setWidth(120); - newColumnTableColumn.setText("Release Date"); + final TableColumn newColumnTableColumn_2 = new TableColumn(table, + SWT.NONE); + newColumnTableColumn_2.setWidth(120); + newColumnTableColumn_2.setText("Director"); - final TableColumn newColumnTableColumn_2 = new TableColumn(table, - SWT.NONE); - newColumnTableColumn_2.setWidth(120); - newColumnTableColumn_2.setText("Director"); + final TableColumn newColumnTableColumn_3 = new TableColumn(table, + SWT.NONE); + newColumnTableColumn_3.setWidth(120); + newColumnTableColumn_3.setText("Writer"); - final TableColumn newColumnTableColumn_3 = new TableColumn(table, - SWT.NONE); - newColumnTableColumn_3.setWidth(120); - newColumnTableColumn_3.setText("Writer"); + final Label movieLabel = new Label(shell, SWT.NONE); + movieLabel.setText("Movie"); - final Label movieLabel = new Label(shell, SWT.NONE); - movieLabel.setText("Movie"); + final Label directorLabel = new Label(shell, SWT.NONE); + directorLabel.setLayoutData(new GridData()); + directorLabel.setText("Release Date"); - final Label directorLabel = new Label(shell, SWT.NONE); - directorLabel.setLayoutData(new GridData()); - directorLabel.setText("Release Date"); + final Label producerLabel = new Label(shell, SWT.NONE); + producerLabel.setText("Director"); - final Label producerLabel = new Label(shell, SWT.NONE); - producerLabel.setText("Director"); + final Label scoreLabel = new Label(shell, SWT.NONE); + scoreLabel.setText("Writer"); - final Label scoreLabel = new Label(shell, SWT.NONE); - scoreLabel.setText("Writer"); + title = new Text(shell, SWT.BORDER); + final GridData gd_title = new GridData(SWT.FILL, SWT.CENTER, true, + false); + title.setLayoutData(gd_title); - title = new Text(shell, SWT.BORDER); - final GridData gd_title = new GridData(SWT.FILL, SWT.CENTER, true, - false); - title.setLayoutData(gd_title); + releaseDate = new Text(shell, SWT.BORDER); + final GridData gd_releaseDate = new GridData(SWT.FILL, SWT.CENTER, + true, false); + releaseDate.setLayoutData(gd_releaseDate); - releaseDate = new Text(shell, SWT.BORDER); - final GridData gd_releaseDate = new GridData(SWT.FILL, SWT.CENTER, - true, false); - releaseDate.setLayoutData(gd_releaseDate); + director = new Text(shell, SWT.BORDER); + final GridData gd_director = new GridData(SWT.FILL, SWT.CENTER, true, + false); + director.setLayoutData(gd_director); - director = new Text(shell, SWT.BORDER); - final GridData gd_director = new GridData(SWT.FILL, SWT.CENTER, true, - false); - director.setLayoutData(gd_director); + writer = new Text(shell, SWT.BORDER); + final GridData gd_writer = new GridData(SWT.FILL, SWT.CENTER, true, + false); + writer.setLayoutData(gd_writer); - writer = new Text(shell, SWT.BORDER); - final GridData gd_writer = new GridData(SWT.FILL, SWT.CENTER, true, - false); - writer.setLayoutData(gd_writer); + bindUI(); + } - bindUI(); - } + // Minimal JavaBeans support + public static abstract class AbstractModelObject { + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( + this); - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); + public void addPropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(listener); + } - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(propertyName, + listener); + } - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } + public void removePropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(listener); + } - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } + public void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(propertyName, + listener); + } - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } + protected void firePropertyChange(String propertyName, Object oldValue, + Object newValue) { + propertyChangeSupport.firePropertyChange(propertyName, oldValue, + newValue); + } + } - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } - - public static class MovieInfo extends AbstractModelObject { - private String title; - private String releaseDate; - private String director; - private String writer; + public static class MovieInfo extends AbstractModelObject { + private String title; + private String releaseDate; + private String director; + private String writer; - public MovieInfo(String title, String releaseDate, String director, - String writer) { - this.title = title; - this.releaseDate = releaseDate; - this.director = director; - this.writer = writer; - } + public MovieInfo(String title, String releaseDate, String director, + String writer) { + this.title = title; + this.releaseDate = releaseDate; + this.director = director; + this.writer = writer; + } - public String getTitle() { - return title; - } + public String getTitle() { + return title; + } - public void setTitle(String title) { - firePropertyChange("title", this.title, this.title = title); - } + public void setTitle(String title) { + firePropertyChange("title", this.title, this.title = title); + } - public String getReleaseDate() { - return releaseDate; - } + public String getReleaseDate() { + return releaseDate; + } - public void setReleaseDate(String releaseDate) { - firePropertyChange("releaseDate", this.releaseDate, - this.releaseDate = releaseDate); - } + public void setReleaseDate(String releaseDate) { + firePropertyChange("releaseDate", this.releaseDate, + this.releaseDate = releaseDate); + } - public String getDirector() { - return director; - } + public String getDirector() { + return director; + } - public void setDirector(String director) { - firePropertyChange("director", this.director, - this.director = director); - } + public void setDirector(String director) { + firePropertyChange("director", this.director, + this.director = director); + } + + public String getWriter() { + return writer; + } - public String getWriter() { - return writer; - } + public void setWriter(String writer) { + firePropertyChange("writer", this.writer, this.writer = writer); + } + } - public void setWriter(String writer) { - firePropertyChange("writer", this.writer, this.writer = writer); - } - } + private void bindUI() { + IObservableList movies = new WritableList(); + movies.add(new MovieInfo("007: Quantum of Solace", "October 31, 2008", + "Marc Forster", "Robert Wade")); + movies.add(new MovieInfo("Batman Begins", "June 15, 2005", + "Christopher Nolan", "David S. Goyer")); + movies.add(new MovieInfo("Cloverfield", "January 18, 2008", + "Matt Reeves", "Drew Goddard")); + movies.add(new MovieInfo("The Dark Knight", "July 18, 2008", + "Christopher Nolan", "David S. Goyer")); + movies.add(new MovieInfo("Finding Nemo", "May 30, 2003", + "Andrew Stanton", "Andrew Stanton")); + movies.add(new MovieInfo("Get Smart", "June 20, 2008", "Peter Segal", + "Tom J. Astle")); + movies.add(new MovieInfo( + "Indiana Jones and the Kingdom of the Crystal Skull", + "May 22, 2008", "Steven Spielberg", "Drunken Lemurs")); + movies.add(new MovieInfo("Iron Man", "May 2, 2008", "Jon Favreau", + "Mark Fergus")); + movies.add(new MovieInfo("Raiders of the Lost Ark", "June 12, 1981", + "Steven Spielberg", "George Lucas")); + movies.add(new MovieInfo("Valkyrie", "December 25, 2008", + "Bryan Singer", "Christopher McQuarrie")); + movies.add(new MovieInfo("Wall-E", "June 27, 2008", "Andrew Stanton", + "Andrew Stanton")); + movies.add(new MovieInfo("Wanted", "June 27, 2008", + "Timur Bekmambetov", "Michael Brandt")); - private void bindUI() { - IObservableList movies = new WritableList(); - movies.add(new MovieInfo("007: Quantum of Solace", "October 31, 2008", - "Marc Forster", "Robert Wade")); - movies.add(new MovieInfo("Batman Begins", "June 15, 2005", - "Christopher Nolan", "David S. Goyer")); - movies.add(new MovieInfo("Cloverfield", "January 18, 2008", - "Matt Reeves", "Drew Goddard")); - movies.add(new MovieInfo("The Dark Knight", "July 18, 2008", - "Christopher Nolan", "David S. Goyer")); - movies.add(new MovieInfo("Finding Nemo", "May 30, 2003", - "Andrew Stanton", "Andrew Stanton")); - movies.add(new MovieInfo("Get Smart", "June 20, 2008", "Peter Segal", - "Tom J. Astle")); - movies.add(new MovieInfo( - "Indiana Jones and the Kingdom of the Crystal Skull", - "May 22, 2008", "Steven Spielberg", "Drunken Lemurs")); - movies.add(new MovieInfo("Iron Man", "May 2, 2008", "Jon Favreau", - "Mark Fergus")); - movies.add(new MovieInfo("Raiders of the Lost Ark", "June 12, 1981", - "Steven Spielberg", "George Lucas")); - movies.add(new MovieInfo("Valkyrie", "December 25, 2008", - "Bryan Singer", "Christopher McQuarrie")); - movies.add(new MovieInfo("Wall-E", "June 27, 2008", "Andrew Stanton", - "Andrew Stanton")); - movies.add(new MovieInfo("Wanted", "June 27, 2008", - "Timur Bekmambetov", "Michael Brandt")); + ViewerSupport.bind(viewer, movies, BeanProperties.values( + MovieInfo.class, new String[] { "title", "releaseDate", + "director", "writer" })); + + // Select Batman Begins and The Dark Knight, which have the same + // director and writer + viewer.setSelection(new StructuredSelection(new Object[] { + movies.get(1), movies.get(3) })); + + DataBindingContext dbc = new DataBindingContext(); - ViewerSupport.bind(viewer, movies, BeanProperties.values( - MovieInfo.class, new String[] { "title", "releaseDate", - "director", "writer" })); - - // Select Batman Begins and The Dark Knight, which have the same - // director and writer - viewer.setSelection(new StructuredSelection(new Object[] { - movies.get(1), movies.get(3) })); - - DataBindingContext dbc = new DataBindingContext(); - - IObservableList selections = ViewerProperties.multipleSelection() - .observe(viewer); - dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(title), - DuplexingObservableValue.withDefaults(BeanProperties.value( - "title").observeDetail(selections), "", - "")); - dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(releaseDate), - DuplexingObservableValue.withDefaults(BeanProperties.value( - "releaseDate").observeDetail(selections), "", - "")); - dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(director), - DuplexingObservableValue.withDefaults(BeanProperties.value( - "director").observeDetail(selections), "", - "")); - dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(writer), - DuplexingObservableValue.withDefaults(BeanProperties.value( - "writer").observeDetail(selections), "", - "")); - } + IObservableList selections = ViewerProperties.multipleSelection() + .observe(viewer); + dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(title), + DuplexingObservableValue.withDefaults(BeanProperties.value( + "title").observeDetail(selections), "", + "")); + dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(releaseDate), + DuplexingObservableValue.withDefaults(BeanProperties.value( + "releaseDate").observeDetail(selections), "", + "")); + dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(director), + DuplexingObservableValue.withDefaults(BeanProperties.value( + "director").observeDetail(selections), "", + "")); + dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(writer), + DuplexingObservableValue.withDefaults(BeanProperties.value( + "writer").observeDetail(selections), "", + "")); + } } +void main( String[] args ){ + Snippet028DuplexingObservableValue.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet029TreeViewerMultiListProperty.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet029TreeViewerMultiListProperty.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet029TreeViewerMultiListProperty.d Wed Apr 22 18:59:26 2009 +0200 @@ -10,7 +10,9 @@ * Matthew Hall - bugs 262407, 260337 ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet029TreeViewerMultiListProperty; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -38,220 +40,223 @@ * */ public class Snippet029TreeViewerMultiListProperty { - protected Shell shell; - private TreeViewer viewer; + protected Shell shell; + private TreeViewer viewer; - /** - * Launch the application - * - * @param args - */ - public static void main(String[] args) { - try { - Snippet029TreeViewerMultiListProperty window = new Snippet029TreeViewerMultiListProperty(); - window.open(); - } catch (Exception e) { - e.printStackTrace(); - } - } + /** + * Launch the application + * + * @param args + */ + public static void main(String[] args) { + try { + Snippet029TreeViewerMultiListProperty window = new Snippet029TreeViewerMultiListProperty(); + window.open(); + } catch (Exception e) { + e.printStackTrace(); + } + } - /** - * Open the window - */ - public void open() { - final Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - createContents(); - shell.open(); - shell.layout(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - } + /** + * Open the window + */ + public void open() { + final Display display = Display.getDefault(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + createContents(); + shell.open(); + shell.layout(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } + }); + } - protected void createContents() { - shell = new Shell(); - shell.setSize(509, 375); - shell.setText("Snippet028DuplexingObservableValue.java"); - final GridLayout gridLayout = new GridLayout(); - gridLayout.makeColumnsEqualWidth = true; - gridLayout.numColumns = 4; - shell.setLayout(new FillLayout()); + protected void createContents() { + shell = new Shell(); + shell.setSize(509, 375); + shell.setText("Snippet028DuplexingObservableValue.java"); + final GridLayout gridLayout = new GridLayout(); + gridLayout.makeColumnsEqualWidth = true; + gridLayout.numColumns = 4; + shell.setLayout(new FillLayout()); - viewer = new TreeViewer(shell, SWT.FULL_SELECTION | SWT.MULTI - | SWT.BORDER); + viewer = new TreeViewer(shell, SWT.FULL_SELECTION | SWT.MULTI + | SWT.BORDER); - bindUI(); - } + bindUI(); + } - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); + // Minimal JavaBeans support + public static abstract class AbstractModelObject { + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( + this); - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } + public void addPropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(listener); + } - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(propertyName, + listener); + } - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } + public void removePropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(listener); + } - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } + public void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(propertyName, + listener); + } - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } + protected void firePropertyChange(String propertyName, Object oldValue, + Object newValue) { + propertyChangeSupport.firePropertyChange(propertyName, oldValue, + newValue); + } + } - public static class Catalog extends AbstractModelObject { - private String name; - private List catalogs = new ArrayList(); - private List items = new ArrayList(); + public static class Catalog extends AbstractModelObject { + private String name; + private List catalogs = new ArrayList(); + private List items = new ArrayList(); - public Catalog(String name) { - this.name = name; - } + public Catalog(String name) { + this.name = name; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - firePropertyChange("name", this.name, this.name = name); - } + public void setName(String name) { + firePropertyChange("name", this.name, this.name = name); + } - public List getCatalogs() { - return catalogs; - } + public List getCatalogs() { + return catalogs; + } - public void setCatalogs(List catalogs) { - firePropertyChange("catalogs", this.catalogs, - this.catalogs = catalogs); - } + public void setCatalogs(List catalogs) { + firePropertyChange("catalogs", this.catalogs, + this.catalogs = catalogs); + } - public List getItems() { - return items; - } + public List getItems() { + return items; + } - public void setItems(List items) { - firePropertyChange("items", this.items, this.items = items); - } - } + public void setItems(List items) { + firePropertyChange("items", this.items, this.items = items); + } + } - public static class CatalogItem extends AbstractModelObject { - private String name; + public static class CatalogItem extends AbstractModelObject { + private String name; - public CatalogItem(String name) { - this.name = name; - } + public CatalogItem(String name) { + this.name = name; + } + + public String getName() { + return name; + } - public String getName() { - return name; - } + public void setName(String name) { + firePropertyChange("name", this.name, this.name = name); + } + } - public void setName(String name) { - firePropertyChange("name", this.name, this.name = name); - } - } + private void bindUI() { + List items; - private void bindUI() { - List items; + Catalog fruits = new Catalog("Fruits"); + items = new ArrayList(); + items.add(new CatalogItem("Apple")); + items.add(new CatalogItem("Orange")); + fruits.setCatalogs(items); - Catalog fruits = new Catalog("Fruits"); - items = new ArrayList(); - items.add(new CatalogItem("Apple")); - items.add(new CatalogItem("Orange")); - fruits.setCatalogs(items); + Catalog vegetables = new Catalog("Vegetables"); + items = new ArrayList(); + items.add(new CatalogItem("Peas")); + items.add(new CatalogItem("Carrots")); + items.add(new CatalogItem("Potatoes")); + vegetables.setItems(items); - Catalog vegetables = new Catalog("Vegetables"); - items = new ArrayList(); - items.add(new CatalogItem("Peas")); - items.add(new CatalogItem("Carrots")); - items.add(new CatalogItem("Potatoes")); - vegetables.setItems(items); + Catalog foods = new Catalog("Foods"); + items = new ArrayList(); + items.add(fruits); + items.add(vegetables); + foods.setCatalogs(items); - Catalog foods = new Catalog("Foods"); - items = new ArrayList(); - items.add(fruits); - items.add(vegetables); - foods.setCatalogs(items); + items = new ArrayList(); + items.add(new CatalogItem("Own Hand")); + foods.setItems(items); - items = new ArrayList(); - items.add(new CatalogItem("Own Hand")); - foods.setItems(items); + Catalog catalog = new Catalog("Main Catalog"); + items = new ArrayList(); + items.add(foods); + catalog.setCatalogs(items); - Catalog catalog = new Catalog("Main Catalog"); - items = new ArrayList(); - items.add(foods); - catalog.setCatalogs(items); + IListProperty childrenProperty = new MultiListProperty( + new IListProperty[] { BeanProperties.list("catalogs"), + BeanProperties.list("items") }); - IListProperty childrenProperty = new MultiListProperty( - new IListProperty[] { BeanProperties.list("catalogs"), - BeanProperties.list("items") }); + ObservableListTreeContentProvider contentProvider = new ObservableListTreeContentProvider( + childrenProperty.listFactory(), null); + viewer.setContentProvider(contentProvider); - ObservableListTreeContentProvider contentProvider = new ObservableListTreeContentProvider( - childrenProperty.listFactory(), null); - viewer.setContentProvider(contentProvider); + ObservableMapLabelProvider labelProvider = new ObservableMapLabelProvider( + BeanProperties.value("name").observeDetail( + contentProvider.getKnownElements())) { + Image catalogImage = createCatalogImage(); + Image catalogItemImage = createCatalogItemImage(); - ObservableMapLabelProvider labelProvider = new ObservableMapLabelProvider( - BeanProperties.value("name").observeDetail( - contentProvider.getKnownElements())) { - Image catalogImage = createCatalogImage(); - Image catalogItemImage = createCatalogItemImage(); + public Image getImage(Object element) { + if (element instanceof Catalog) + return catalogImage; + if (element instanceof CatalogItem) + return catalogItemImage; + return super.getImage(element); + } - public Image getImage(Object element) { - if (element instanceof Catalog) - return catalogImage; - if (element instanceof CatalogItem) - return catalogItemImage; - return super.getImage(element); - } + public void dispose() { + catalogImage.dispose(); + catalogItemImage.dispose(); + super.dispose(); + } - public void dispose() { - catalogImage.dispose(); - catalogItemImage.dispose(); - super.dispose(); - } - - private Image createCatalogImage() { - Display display = Display.getCurrent(); - Image catalogImage = new Image(display, 12, 12); - GC gc = new GC(catalogImage); - gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); - gc.fillArc(1, 1, 10, 10, 0, 360); - gc.dispose(); - return catalogImage; - } + private Image createCatalogImage() { + Display display = Display.getCurrent(); + Image catalogImage = new Image(display, 12, 12); + GC gc = new GC(catalogImage); + gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); + gc.fillArc(1, 1, 10, 10, 0, 360); + gc.dispose(); + return catalogImage; + } - private Image createCatalogItemImage() { - Display display = Display.getCurrent(); - Image catalogImage = new Image(display, 12, 12); - GC gc = new GC(catalogImage); - gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); - gc.fillPolygon(new int[] { 1, 10, 5, 1, 6, 1, 10, 10, 1, 10 }); - gc.dispose(); - return catalogImage; - } - }; - viewer.setLabelProvider(labelProvider); + private Image createCatalogItemImage() { + Display display = Display.getCurrent(); + Image catalogImage = new Image(display, 12, 12); + GC gc = new GC(catalogImage); + gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); + gc.fillPolygon(new int[] { 1, 10, 5, 1, 6, 1, 10, 10, 1, 10 }); + gc.dispose(); + return catalogImage; + } + }; + viewer.setLabelProvider(labelProvider); - viewer.setInput(catalog); - } + viewer.setInput(catalog); + } } +void main( String[] args ){ + Snippet029TreeViewerMultiListProperty.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet030DateAndTimeObservableValue.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet030DateAndTimeObservableValue.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet030DateAndTimeObservableValue.d Wed Apr 22 18:59:26 2009 +0200 @@ -9,7 +9,9 @@ * Matthew Hall - initial API and implementation (bug 169876) ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet030DateAndTimeObservableValue; + +import java.lang.all; import java.util.Date; @@ -37,110 +39,113 @@ * */ public class Snippet030DateAndTimeObservableValue { - protected Shell shell; - private Text modelText; - private DateTime date; - private DateTime calendar; - private DateTime time; - private Button syncTime; + protected Shell shell; + private Text modelText; + private DateTime date; + private DateTime calendar; + private DateTime time; + private Button syncTime; - /** - * Launch the application - * - * @param args - */ - public static void main(String[] args) { - try { - Snippet030DateAndTimeObservableValue window = new Snippet030DateAndTimeObservableValue(); - window.open(); - } catch (Exception e) { - e.printStackTrace(); - } - } + /** + * Launch the application + * + * @param args + */ + public static void main(String[] args) { + try { + Snippet030DateAndTimeObservableValue window = new Snippet030DateAndTimeObservableValue(); + window.open(); + } catch (Exception e) { + e.printStackTrace(); + } + } - /** - * Open the window - */ - public void open() { - final Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - createContents(); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - } + /** + * Open the window + */ + public void open() { + final Display display = Display.getDefault(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + createContents(); + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } + }); + } - protected void createContents() { - shell = new Shell(); - GridLayout layout = new GridLayout(); - layout.numColumns = 3; - shell.setLayout(layout); - shell.setText("Snippet030DateAndTimeObservableValue.java"); + protected void createContents() { + shell = new Shell(); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + shell.setLayout(layout); + shell.setText("Snippet030DateAndTimeObservableValue.java"); - new Label(shell, SWT.NONE).setText("Model date + time"); - modelText = new Text(shell, SWT.BORDER); - modelText.setEditable(false); - modelText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, - 2, 1)); + new Label(shell, SWT.NONE).setText("Model date + time"); + modelText = new Text(shell, SWT.BORDER); + modelText.setEditable(false); + modelText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, + 2, 1)); - new Label(shell, SWT.NONE).setText("Target date (SWT.DATE)"); - date = new DateTime(shell, SWT.DATE | SWT.BORDER); - date.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, - 1)); + new Label(shell, SWT.NONE).setText("Target date (SWT.DATE)"); + date = new DateTime(shell, SWT.DATE | SWT.BORDER); + date.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, + 1)); - new Label(shell, SWT.NONE).setText("Target date (SWT.CALENDAR)"); - calendar = new DateTime(shell, SWT.CALENDAR); - calendar.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, - 2, 1)); + new Label(shell, SWT.NONE).setText("Target date (SWT.CALENDAR)"); + calendar = new DateTime(shell, SWT.CALENDAR); + calendar.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, + 2, 1)); - new Label(shell, SWT.NONE).setText("Target time"); - time = new DateTime(shell, SWT.TIME | SWT.BORDER); + new Label(shell, SWT.NONE).setText("Target time"); + time = new DateTime(shell, SWT.TIME | SWT.BORDER); - syncTime = new Button(shell, SWT.CHECK); - syncTime.setLayoutData(new GridData()); - syncTime.setText("Sync with system time"); + syncTime = new Button(shell, SWT.CHECK); + syncTime.setLayoutData(new GridData()); + syncTime.setText("Sync with system time"); - bindUI(); - } + bindUI(); + } - private void bindUI() { - DataBindingContext dbc = new DataBindingContext(); + private void bindUI() { + DataBindingContext dbc = new DataBindingContext(); - IObservableValue model = WritableValue.withValueType(Date.class); - model.setValue(new Date()); + IObservableValue model = WritableValue.withValueType(Date.class); + model.setValue(new Date()); - dbc.bindValue(WidgetProperties.text().observe(modelText), model); + dbc.bindValue(WidgetProperties.text().observe(modelText), model); - final IObservableValue timeSelection = WidgetProperties.selection() - .observe(time); + final IObservableValue timeSelection = WidgetProperties.selection() + .observe(time); - dbc.bindValue(new DateAndTimeObservableValue(WidgetProperties - .selection().observe(date), timeSelection), model); - dbc.bindValue(new DateAndTimeObservableValue(WidgetProperties - .selection().observe(calendar), timeSelection), model); + dbc.bindValue(new DateAndTimeObservableValue(WidgetProperties + .selection().observe(date), timeSelection), model); + dbc.bindValue(new DateAndTimeObservableValue(WidgetProperties + .selection().observe(calendar), timeSelection), model); - syncTime.addListener(SWT.Selection, new Listener() { - Runnable runnable = new Runnable() { - public void run() { - if (syncTime.getSelection()) { - timeSelection.setValue(new Date()); - Display.getCurrent().timerExec(100, this); - } - } - }; + syncTime.addListener(SWT.Selection, new Listener() { + Runnable runnable = new Runnable() { + public void run() { + if (syncTime.getSelection()) { + timeSelection.setValue(new Date()); + Display.getCurrent().timerExec(100, this); + } + } + }; - public void handleEvent(Event event) { - time.setEnabled(!syncTime.getSelection()); - if (syncTime.getSelection()) { - runnable.run(); - } - } - }); - } + public void handleEvent(Event event) { + time.setEnabled(!syncTime.getSelection()); + if (syncTime.getSelection()) { + runnable.run(); + } + } + }); + } } +void main( String[] args ){ + Snippet030DateAndTimeObservableValue.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet031JFaceObservable.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet031JFaceObservable.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet031JFaceObservable.d Wed Apr 22 18:59:26 2009 +0200 @@ -9,7 +9,9 @@ * IBM Corporation - initial API and implementation ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet031JFaceObservable; + +import java.lang.all; import org.eclipse.core.commands.common.EventManager; import org.eclipse.core.databinding.DataBindingContext; @@ -28,115 +30,118 @@ public class Snippet031JFaceObservable { - public static final String NAME_PROPERTY = "name_property"; + public static final String NAME_PROPERTY = "name_property"; - public static void main(String[] args) { - Display display = new Display(); - final ViewModel viewModel = new ViewModel(); + public static void main(String[] args) { + Display display = new Display(); + final ViewModel viewModel = new ViewModel(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - final Shell shell = new View(viewModel).createShell(); - // The SWT event loop - Display display = Display.getCurrent(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - // Print the results - System.out.println("person.getName() = " - + viewModel.getPerson().getName()); - } + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + final Shell shell = new View(viewModel).createShell(); + // The SWT event loop + Display display = Display.getCurrent(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + }); + // Print the results + System.out.println("person.getName() = " + + viewModel.getPerson().getName()); + } - // The data model class. This is normally a persistent class of some sort. - // - // In this example, we extend the EventManager class - // to manage our listeners and we fire a property change - // event when the object state changes. - public static class Person extends EventManager { - // A property... - String name = "HelloWorld"; + // The data model class. This is normally a persistent class of some sort. + // + // In this example, we extend the EventManager class + // to manage our listeners and we fire a property change + // event when the object state changes. + public static class Person extends EventManager { + // A property... + String name = "HelloWorld"; - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - fireChange(new PropertyChangeEvent(this, NAME_PROPERTY, this.name, - this.name = name)); - } + public void setName(String name) { + fireChange(new PropertyChangeEvent(this, NAME_PROPERTY, this.name, + this.name = name)); + } - public void addPropertyChangeListener(IPropertyChangeListener listener) { - addListenerObject(listener); - } + public void addPropertyChangeListener(IPropertyChangeListener listener) { + addListenerObject(listener); + } - public void removePropertyChangeListener( - IPropertyChangeListener listener) { - removeListenerObject(listener); - } + public void removePropertyChangeListener( + IPropertyChangeListener listener) { + removeListenerObject(listener); + } - private void fireChange(PropertyChangeEvent event) { - final Object[] list = getListeners(); - for (int i = 0; i < list.length; ++i) { - ((IPropertyChangeListener) list[i]).propertyChange(event); - } - } + private void fireChange(PropertyChangeEvent event) { + final Object[] list = getListeners(); + for (int i = 0; i < list.length; ++i) { + ((IPropertyChangeListener) list[i]).propertyChange(event); + } + } - } + } - // The View's model--the root of our Model graph for this particular GUI. - // - // Typically each View class has a corresponding ViewModel class. - // The ViewModel is responsible for getting the objects to edit from the - // DAO. Since this snippet doesn't have any persistent objects to - // retrieve, this ViewModel just instantiates a model object to edit. - static class ViewModel { - // The model to bind - private Person person = new Person(); + // The View's model--the root of our Model graph for this particular GUI. + // + // Typically each View class has a corresponding ViewModel class. + // The ViewModel is responsible for getting the objects to edit from the + // DAO. Since this snippet doesn't have any persistent objects to + // retrieve, this ViewModel just instantiates a model object to edit. + static class ViewModel { + // The model to bind + private Person person = new Person(); - public Person getPerson() { - return person; - } - } + public Person getPerson() { + return person; + } + } - // The GUI view - static class View { - private ViewModel viewModel; - private Text name; + // The GUI view + static class View { + private ViewModel viewModel; + private Text name; - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } + public View(ViewModel viewModel) { + this.viewModel = viewModel; + } - public Shell createShell() { - // Build a UI - Display display = Display.getDefault(); - Shell shell = new Shell(display); - shell.setLayout(new RowLayout(SWT.VERTICAL)); - name = new Text(shell, SWT.BORDER); + public Shell createShell() { + // Build a UI + Display display = Display.getDefault(); + Shell shell = new Shell(display); + shell.setLayout(new RowLayout(SWT.VERTICAL)); + name = new Text(shell, SWT.BORDER); - // Bind it - DataBindingContext bindingContext = new DataBindingContext(); - Person person = viewModel.getPerson(); + // Bind it + DataBindingContext bindingContext = new DataBindingContext(); + Person person = viewModel.getPerson(); - IValueProperty nameProperty = JFaceProperties.value(Person.class, - "name", NAME_PROPERTY); + IValueProperty nameProperty = JFaceProperties.value(Person.class, + "name", NAME_PROPERTY); - bindingContext.bindValue(SWTObservables.observeText(name, - SWT.Modify), nameProperty.observe(person), null, null); + bindingContext.bindValue(SWTObservables.observeText(name, + SWT.Modify), nameProperty.observe(person), null, null); - Label label = new Label(shell, SWT.NONE); - bindingContext.bindValue(SWTObservables.observeText(label), - nameProperty.observe(person), null, null); + Label label = new Label(shell, SWT.NONE); + bindingContext.bindValue(SWTObservables.observeText(label), + nameProperty.observe(person), null, null); - // Open and return the Shell - shell.pack(); - shell.open(); - return shell; - } - } + // Open and return the Shell + shell.pack(); + shell.open(); + return shell; + } + } } +void main( String[] args ){ + Snippet031JFaceObservable.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet032TableViewerColumnEditing.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet032TableViewerColumnEditing.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet032TableViewerColumnEditing.d Wed Apr 22 18:59:26 2009 +0200 @@ -12,7 +12,9 @@ * Heiko Ahlig - bug 267712 *******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet032TableViewerColumnEditing; + +import java.lang.all; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -51,205 +53,208 @@ * Demonstrates binding a TableViewer with multiple columns to a collection. */ public class Snippet032TableViewerColumnEditing { - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); + public static void main(String[] args) { + final Display display = new Display(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + ViewModel viewModel = new ViewModel(); + Shell shell = new View(viewModel).createShell(); - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - } + // The SWT event loop + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + }); + } - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); + // Minimal JavaBeans support + public static abstract class AbstractModelObject { + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( + this); - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } + public void addPropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(listener); + } - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(propertyName, + listener); + } - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } + public void removePropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(listener); + } - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } + public void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(propertyName, + listener); + } - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } + protected void firePropertyChange(String propertyName, Object oldValue, + Object newValue) { + propertyChangeSupport.firePropertyChange(propertyName, oldValue, + newValue); + } + } - // The data model class. This is normally a persistent class of some sort. - static class Person extends AbstractModelObject { - // A property... - String name; - String firstName; + // The data model class. This is normally a persistent class of some sort. + static class Person extends AbstractModelObject { + // A property... + String name; + String firstName; - public Person(String firstName, String name) { - this.name = name; - this.firstName = firstName; - } + public Person(String firstName, String name) { + this.name = name; + this.firstName = firstName; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - firePropertyChange("name", this.name, this.name = name); - } + public void setName(String name) { + firePropertyChange("name", this.name, this.name = name); + } - public String getFirstName() { - return firstName; - } + public String getFirstName() { + return firstName; + } - public void setFirstName(String firstName) { - firePropertyChange("firstName", this.firstName, - this.firstName = firstName); - } - } + public void setFirstName(String firstName) { + firePropertyChange("firstName", this.firstName, + this.firstName = firstName); + } + } - // The View's model--the root of our Model graph for this particular GUI. - // - // Typically each View class has a corresponding ViewModel class. - // The ViewModel is responsible for getting the objects to edit from the - // data access tier. Since this snippet doesn't have any persistent objects - // ro retrieve, this ViewModel just instantiates a model object to edit. - static class ViewModel { - // The model to bind - private List people = new LinkedList(); - { - people.add(new Person("Dave", "Orme")); - people.add(new Person("Gili", "Mendel")); - people.add(new Person("Joe", "Winchester")); - people.add(new Person("Boris", "Bokowski")); - people.add(new Person("Brad", "Reynolds")); - people.add(new Person("Matthew", "Hall")); - } + // The View's model--the root of our Model graph for this particular GUI. + // + // Typically each View class has a corresponding ViewModel class. + // The ViewModel is responsible for getting the objects to edit from the + // data access tier. Since this snippet doesn't have any persistent objects + // ro retrieve, this ViewModel just instantiates a model object to edit. + static class ViewModel { + // The model to bind + private List people = new LinkedList(); + { + people.add(new Person("Dave", "Orme")); + people.add(new Person("Gili", "Mendel")); + people.add(new Person("Joe", "Winchester")); + people.add(new Person("Boris", "Bokowski")); + people.add(new Person("Brad", "Reynolds")); + people.add(new Person("Matthew", "Hall")); + } - public List getPeople() { - return people; - } - } + public List getPeople() { + return people; + } + } - // The GUI view - static class View { - private ViewModel viewModel; - private Table committers; - private Label selectedCommitterName; - private Label selectedCommitterFirstName; + // The GUI view + static class View { + private ViewModel viewModel; + private Table committers; + private Label selectedCommitterName; + private Label selectedCommitterFirstName; - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } + public View(ViewModel viewModel) { + this.viewModel = viewModel; + } - public Shell createShell() { - // Build a UI - Display display = Display.getDefault(); - Shell shell = new Shell(display); - shell.setLayout(new GridLayout(2, true)); - committers = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); - committers.setLinesVisible(true); - committers.setHeaderVisible(true); - GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); - layoutData.horizontalSpan = 2; - committers.setLayoutData(layoutData); + public Shell createShell() { + // Build a UI + Display display = Display.getDefault(); + Shell shell = new Shell(display); + shell.setLayout(new GridLayout(2, true)); + committers = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); + committers.setLinesVisible(true); + committers.setHeaderVisible(true); + GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); + layoutData.horizontalSpan = 2; + committers.setLayoutData(layoutData); - GridData fieldLayoutData = new GridData(SWT.FILL, SWT.BEGINNING, - true, false); - selectedCommitterName = new Label(shell, SWT.NONE); - selectedCommitterName.setLayoutData(fieldLayoutData); + GridData fieldLayoutData = new GridData(SWT.FILL, SWT.BEGINNING, + true, false); + selectedCommitterName = new Label(shell, SWT.NONE); + selectedCommitterName.setLayoutData(fieldLayoutData); - selectedCommitterFirstName = new Label(shell, SWT.NONE); - selectedCommitterFirstName.setLayoutData(fieldLayoutData); + selectedCommitterFirstName = new Label(shell, SWT.NONE); + selectedCommitterFirstName.setLayoutData(fieldLayoutData); - DataBindingContext bindingContext = new DataBindingContext(); - bindGUI(bindingContext); + DataBindingContext bindingContext = new DataBindingContext(); + bindGUI(bindingContext); - // Open and return the Shell - shell.setSize(250, 300); - shell.open(); - return shell; - } + // Open and return the Shell + shell.setSize(250, 300); + shell.open(); + return shell; + } - protected void bindGUI(DataBindingContext bindingContext) { - // Since we're using a JFace Viewer, we do first wrap our Table... - TableViewer peopleViewer = new TableViewer(committers); + protected void bindGUI(DataBindingContext bindingContext) { + // Since we're using a JFace Viewer, we do first wrap our Table... + TableViewer peopleViewer = new TableViewer(committers); - TableViewerColumn columnName = new TableViewerColumn(peopleViewer, - SWT.NONE); - columnName.getColumn().setText("Name"); - columnName.getColumn().setWidth(100); + TableViewerColumn columnName = new TableViewerColumn(peopleViewer, + SWT.NONE); + columnName.getColumn().setText("Name"); + columnName.getColumn().setWidth(100); - TableViewerColumn columnFirstName = new TableViewerColumn( - peopleViewer, SWT.NONE); - columnFirstName.getColumn().setText("FirstName"); - columnFirstName.getColumn().setWidth(100); + TableViewerColumn columnFirstName = new TableViewerColumn( + peopleViewer, SWT.NONE); + columnFirstName.getColumn().setText("FirstName"); + columnFirstName.getColumn().setWidth(100); - // Bind viewer to model - IBeanValueProperty propName = BeanProperties.value(Person.class, - "name"); - IBeanValueProperty propFirstname = BeanProperties.value( - Person.class, "firstName"); + // Bind viewer to model + IBeanValueProperty propName = BeanProperties.value(Person.class, + "name"); + IBeanValueProperty propFirstname = BeanProperties.value( + Person.class, "firstName"); - IValueProperty cellEditorControlText = CellEditorProperties - .control().value(WidgetProperties.text()); + IValueProperty cellEditorControlText = CellEditorProperties + .control().value(WidgetProperties.text()); - columnName.setEditingSupport(ObservableValueEditingSupport.create( - peopleViewer, bindingContext, - new TextCellEditor(committers), cellEditorControlText, - propName)); - columnFirstName.setEditingSupport(ObservableValueEditingSupport - .create(peopleViewer, bindingContext, new TextCellEditor( - committers), cellEditorControlText, propFirstname)); + columnName.setEditingSupport(ObservableValueEditingSupport.create( + peopleViewer, bindingContext, + new TextCellEditor(committers), cellEditorControlText, + propName)); + columnFirstName.setEditingSupport(ObservableValueEditingSupport + .create(peopleViewer, bindingContext, new TextCellEditor( + committers), cellEditorControlText, propFirstname)); - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - peopleViewer.setContentProvider(contentProvider); + ObservableListContentProvider contentProvider = new ObservableListContentProvider(); + peopleViewer.setContentProvider(contentProvider); - // Bind the LabelProviders to the model and columns - IObservableMap[] result = Properties.observeEach(contentProvider - .getKnownElements(), new IBeanValueProperty[] { propName, - propFirstname }); + // Bind the LabelProviders to the model and columns + IObservableMap[] result = Properties.observeEach(contentProvider + .getKnownElements(), new IBeanValueProperty[] { propName, + propFirstname }); - columnName.setLabelProvider(new ObservableMapCellLabelProvider( - result[0])); - columnFirstName - .setLabelProvider(new ObservableMapCellLabelProvider( - result[1])); + columnName.setLabelProvider(new ObservableMapCellLabelProvider( + result[0])); + columnFirstName + .setLabelProvider(new ObservableMapCellLabelProvider( + result[1])); - peopleViewer.setInput(new WritableList(viewModel.getPeople(), - Person.class)); + peopleViewer.setInput(new WritableList(viewModel.getPeople(), + Person.class)); - // bind selectedCommitter labels to the name and forname of the - // current selection - IObservableValue selection = ViewersObservables - .observeSingleSelection(peopleViewer); - bindingContext.bindValue(SWTObservables - .observeText(selectedCommitterName), BeansObservables - .observeDetailValue(selection, "name", String.class)); - bindingContext.bindValue(SWTObservables - .observeText(selectedCommitterFirstName), BeansObservables - .observeDetailValue(selection, "firstName", String.class)); - } - } + // bind selectedCommitter labels to the name and forname of the + // current selection + IObservableValue selection = ViewersObservables + .observeSingleSelection(peopleViewer); + bindingContext.bindValue(SWTObservables + .observeText(selectedCommitterName), BeansObservables + .observeDetailValue(selection, "name", String.class)); + bindingContext.bindValue(SWTObservables + .observeText(selectedCommitterFirstName), BeansObservables + .observeDetailValue(selection, "firstName", String.class)); + } + } } +void main( String[] args ){ + Snippet032TableViewerColumnEditing.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet033CrossValidationControlDecoration.d --- a/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet033CrossValidationControlDecoration.d Wed Apr 22 07:30:21 2009 +0200 +++ b/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet033CrossValidationControlDecoration.d Wed Apr 22 18:59:26 2009 +0200 @@ -9,7 +9,9 @@ * Matthew Hall - initial API and implementation (bug 268472) ******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; +module org.eclipse.jface.examples.databinding.snippets.Snippet033CrossValidationControlDecoration; + +import java.lang.all; import java.util.Date; @@ -38,114 +40,117 @@ * */ public class Snippet033CrossValidationControlDecoration { - protected Shell shell; - private DateTime startDate; - private DateTime endDate; + protected Shell shell; + private DateTime startDate; + private DateTime endDate; - /** - * Launch the application - * - * @param args - */ - public static void main(String[] args) { - try { - Snippet033CrossValidationControlDecoration window = new Snippet033CrossValidationControlDecoration(); - window.open(); - } catch (Exception e) { - e.printStackTrace(); - } - } + /** + * Launch the application + * + * @param args + */ + public static void main(String[] args) { + try { + Snippet033CrossValidationControlDecoration window = new Snippet033CrossValidationControlDecoration(); + window.open(); + } catch (Exception e) { + e.printStackTrace(); + } + } - /** - * Open the window - */ - public void open() { - final Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - createContents(); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - } + /** + * Open the window + */ + public void open() { + final Display display = Display.getDefault(); + Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { + public void run() { + createContents(); + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } + }); + } - protected void createContents() { - shell = new Shell(); - GridLayout layout = new GridLayout(); - layout.numColumns = 4; - shell.setLayout(layout); - shell.setText("Snippet033CrossValidationControlDecoration.java"); + protected void createContents() { + shell = new Shell(); + GridLayout layout = new GridLayout(); + layout.numColumns = 4; + shell.setLayout(layout); + shell.setText("Snippet033CrossValidationControlDecoration.java"); - final Label label = new Label(shell, SWT.NONE); - label.setLayoutData(new GridData()); - label.setText("Start date"); - startDate = new DateTime(shell, SWT.CALENDAR); - final GridData gd_startDate = new GridData(); - gd_startDate.horizontalIndent = 10; - startDate.setLayoutData(gd_startDate); + final Label label = new Label(shell, SWT.NONE); + label.setLayoutData(new GridData()); + label.setText("Start date"); + startDate = new DateTime(shell, SWT.CALENDAR); + final GridData gd_startDate = new GridData(); + gd_startDate.horizontalIndent = 10; + startDate.setLayoutData(gd_startDate); - final Label startDateLabel = new Label(shell, SWT.NONE); - startDateLabel.setLayoutData(new GridData()); - startDateLabel.setText("End date"); - endDate = new DateTime(shell, SWT.CALENDAR); - final GridData gd_endDate = new GridData(); - gd_endDate.horizontalIndent = 10; - endDate.setLayoutData(gd_endDate); + final Label startDateLabel = new Label(shell, SWT.NONE); + startDateLabel.setLayoutData(new GridData()); + startDateLabel.setText("End date"); + endDate = new DateTime(shell, SWT.CALENDAR); + final GridData gd_endDate = new GridData(); + gd_endDate.horizontalIndent = 10; + endDate.setLayoutData(gd_endDate); - bindUI(); - } + bindUI(); + } - private void bindUI() { - IObservableValue startDateObservable = WidgetProperties.selection() - .observe(startDate); - IObservableValue endDateObservable = WidgetProperties.selection() - .observe(endDate); + private void bindUI() { + IObservableValue startDateObservable = WidgetProperties.selection() + .observe(startDate); + IObservableValue endDateObservable = WidgetProperties.selection() + .observe(endDate); - ControlDecorationSupport.create(new DateRangeValidator( - startDateObservable, endDateObservable, - "Start date must be on or before end date"), SWT.LEFT - | SWT.CENTER); + ControlDecorationSupport.create(new DateRangeValidator( + startDateObservable, endDateObservable, + "Start date must be on or before end date"), SWT.LEFT + | SWT.CENTER); - // Customize the decoration's description text and image - ControlDecorationUpdater decorationUpdater = new ControlDecorationUpdater() { - protected String getDescriptionText(IStatus status) { - return "ERROR: " + super.getDescriptionText(status); - } + // Customize the decoration's description text and image + ControlDecorationUpdater decorationUpdater = new ControlDecorationUpdater() { + protected String getDescriptionText(IStatus status) { + return "ERROR: " + super.getDescriptionText(status); + } - protected Image getImage(IStatus status) { - return status.isOK() ? null : Display.getCurrent() - .getSystemImage(SWT.ICON_ERROR); - } - }; - ControlDecorationSupport.create(new DateRangeValidator(Observables - .constantObservableValue(new Date()), startDateObservable, - "Choose a starting date later than today"), SWT.LEFT | SWT.TOP, - (Composite) null, decorationUpdater); - } + protected Image getImage(IStatus status) { + return status.isOK() ? null : Display.getCurrent() + .getSystemImage(SWT.ICON_ERROR); + } + }; + ControlDecorationSupport.create(new DateRangeValidator(Observables + .constantObservableValue(new Date()), startDateObservable, + "Choose a starting date later than today"), SWT.LEFT | SWT.TOP, + (Composite) null, decorationUpdater); + } - private static class DateRangeValidator extends MultiValidator { - private final IObservableValue start; - private final IObservableValue end; - private final String errorMessage; + private static class DateRangeValidator extends MultiValidator { + private final IObservableValue start; + private final IObservableValue end; + private final String errorMessage; - public DateRangeValidator(IObservableValue start, IObservableValue end, - String errorMessage) { - this.start = start; - this.end = end; - this.errorMessage = errorMessage; - } + public DateRangeValidator(IObservableValue start, IObservableValue end, + String errorMessage) { + this.start = start; + this.end = end; + this.errorMessage = errorMessage; + } - protected IStatus validate() { - Date startDate = (Date) start.getValue(); - Date endDate = (Date) end.getValue(); - if (startDate.compareTo(endDate) > 0) - return ValidationStatus.error(errorMessage); - return ValidationStatus.ok(); - } - } + protected IStatus validate() { + Date startDate = (Date) start.getValue(); + Date endDate = (Date) end.getValue(); + if (startDate.compareTo(endDate) > 0) + return ValidationStatus.error(errorMessage); + return ValidationStatus.ok(); + } + } } +void main( String[] args ){ + Snippet033CrossValidationControlDecoration.main(args); +} diff -r 48d4ee626868 -r 5d5bd660917f rakefile --- a/rakefile Wed Apr 22 07:30:21 2009 +0200 +++ b/rakefile Wed Apr 22 18:59:26 2009 +0200 @@ -79,7 +79,6 @@ "org.eclipse.core.commands", "org.eclipse.core.databinding", "org.eclipse.core.databinding.beans", - "org.eclipse.core.databinding.observable", "org.eclipse.core.jobs" ] LIBNAMES_JFACE = [ "org.eclipse.jface" ] @@ -446,22 +445,35 @@ LIBNAMES_ICU snps_exclude = [] allsnippets = FileList[ File.join(BASEPATH, SRCPATH, "**/*.d" )] + rmlistadd = true if args.explicit_snp != nil - snpname = args.explicit_snp - puts "Building jfacesnippets[#{snpname}]" - buildApp( BASEPATH, SRCPATH, "res", "", PREFIX, args.explicit_snp, nil, libnames ) - else + rmlist = FileList.new allsnippets.each do | snp | - if snp =~ /.*[\\\/](\w+)\.d$/ - snpname = $1 - puts "Building jfacesnippets[#{snpname}]" - if !snps_exclude.include? snpname - buildApp( BASEPATH, SRCPATH, "res", "", PREFIX, snpname, nil, libnames ) - end - else + until snp =~ /.*[\\\/](\w+)\.d$/ puts snp raise "Name does not match #{snp}" end + if $1 == args.explicit_snp + rmlistadd = false + end + if rmlistadd + rmlist << snp + end + end + end + rmlist.each do | snp | + allsnippets.exclude snp + end + allsnippets.each do | snp | + if snp =~ /.*[\\\/](\w+)\.d$/ + snpname = $1 + puts "Building bindsnippets[#{snpname}]" + if !snps_exclude.include? snpname + buildApp( BASEPATH, SRCPATH, "res", "", PREFIX, snpname, nil, libnames ) + end + else + puts snp + raise "Name does not match #{snp}" end end end