comparison org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet023ConditionalVisibility.d @ 99:5d5bd660917f

build some databind snippets
author Frank Benoit <benoit@tionex.de>
date Wed, 22 Apr 2009 18:59:26 +0200
parents 6086085e153d
children
comparison
equal deleted inserted replaced
98:48d4ee626868 99:5d5bd660917f
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/ 10 ******************************************************************************/
11 11
12 package org.eclipse.jface.examples.databinding.snippets; 12 module org.eclipse.jface.examples.databinding.snippets.Snippet023ConditionalVisibility;
13
14 import java.lang.all;
13 15
14 import org.eclipse.core.databinding.observable.Realm; 16 import org.eclipse.core.databinding.observable.Realm;
15 import org.eclipse.jface.databinding.swt.ISWTObservableValue; 17 import org.eclipse.jface.databinding.swt.ISWTObservableValue;
16 import org.eclipse.jface.databinding.swt.SWTObservables; 18 import org.eclipse.jface.databinding.swt.SWTObservables;
17 import org.eclipse.jface.internal.databinding.provisional.swt.ControlUpdater; 19 import org.eclipse.jface.internal.databinding.provisional.swt.ControlUpdater;
30 /** 32 /**
31 * @since 3.2 33 * @since 3.2
32 * 34 *
33 */ 35 */
34 public class Snippet023ConditionalVisibility { 36 public class Snippet023ConditionalVisibility {
35 public static void main(String[] args) { 37 public static void main(String[] args) {
36 Display display = new Display(); 38 Display display = new Display();
37 final Shell shell = new Shell(display); 39 final Shell shell = new Shell(display);
38 shell.setLayout(new GridLayout(1, false)); 40 shell.setLayout(new GridLayout(1, false));
39 41
40 Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { 42 Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
41 public void run() { 43 public void run() {
42 new Snippet023ConditionalVisibility().createControls(shell); 44 new Snippet023ConditionalVisibility().createControls(shell);
43 } 45 }
44 }); 46 });
45 47
46 shell.pack(); 48 shell.pack();
47 shell.open(); 49 shell.open();
48 while (!shell.isDisposed()) { 50 while (!shell.isDisposed()) {
49 if (!display.readAndDispatch()) 51 if (!display.readAndDispatch())
50 display.sleep(); 52 display.sleep();
51 } 53 }
52 display.dispose(); 54 display.dispose();
53 } 55 }
54 56
55 Text text; 57 Text text;
56 Text toText; 58 Text toText;
57 Text fromText; 59 Text fromText;
58 60
59 /** 61 /**
60 * @param shell 62 * @param shell
61 */ 63 */
62 private void createControls(Shell shell) { 64 private void createControls(Shell shell) {
63 Composite composite = new Composite(shell, SWT.NONE); 65 Composite composite = new Composite(shell, SWT.NONE);
64 Group radioGroup = new Group(composite, SWT.NONE); 66 Group radioGroup = new Group(composite, SWT.NONE);
65 radioGroup.setText("Type"); 67 radioGroup.setText("Type");
66 Button textButton = new Button(radioGroup, SWT.RADIO); 68 Button textButton = new Button(radioGroup, SWT.RADIO);
67 textButton.setText("Text"); 69 textButton.setText("Text");
68 Button rangeButton = new Button(radioGroup, SWT.RADIO); 70 Button rangeButton = new Button(radioGroup, SWT.RADIO);
69 rangeButton.setText("Range"); 71 rangeButton.setText("Range");
70 GridLayoutFactory.swtDefaults().generateLayout(radioGroup); 72 GridLayoutFactory.swtDefaults().generateLayout(radioGroup);
71 73
72 final Composite oneOfTwo = new Composite(composite, SWT.NONE); 74 final Composite oneOfTwo = new Composite(composite, SWT.NONE);
73 final StackLayout stackLayout = new StackLayout(); 75 final StackLayout stackLayout = new StackLayout();
74 oneOfTwo.setLayout(stackLayout); 76 oneOfTwo.setLayout(stackLayout);
75 77
76 final Group rangeGroup = new Group(oneOfTwo, SWT.NONE); 78 final Group rangeGroup = new Group(oneOfTwo, SWT.NONE);
77 rangeGroup.setText("Range"); 79 rangeGroup.setText("Range");
78 Label fromLabel = new Label(rangeGroup, SWT.NONE); 80 Label fromLabel = new Label(rangeGroup, SWT.NONE);
79 fromLabel.setText("From:"); 81 fromLabel.setText("From:");
80 fromText = new Text(rangeGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); 82 fromText = new Text(rangeGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
81 83
82 Label toLabel = new Label(rangeGroup, SWT.NONE); 84 Label toLabel = new Label(rangeGroup, SWT.NONE);
83 toLabel.setText("To:"); 85 toLabel.setText("To:");
84 toText = new Text(rangeGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); 86 toText = new Text(rangeGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
85 GridLayoutFactory.swtDefaults().numColumns(2) 87 GridLayoutFactory.swtDefaults().numColumns(2)
86 .generateLayout(rangeGroup); 88 .generateLayout(rangeGroup);
87 89
88 final Group textGroup = new Group(oneOfTwo, SWT.NONE); 90 final Group textGroup = new Group(oneOfTwo, SWT.NONE);
89 textGroup.setText("Text"); 91 textGroup.setText("Text");
90 Label label = new Label(textGroup, SWT.NONE); 92 Label label = new Label(textGroup, SWT.NONE);
91 label.setText("Text:"); 93 label.setText("Text:");
92 text = new Text(textGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); 94 text = new Text(textGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
93 GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(textGroup); 95 GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(textGroup);
94 96
95 GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(composite); 97 GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(composite);
96 98
97 final ISWTObservableValue rangeSelected = SWTObservables 99 final ISWTObservableValue rangeSelected = SWTObservables
98 .observeSelection(rangeButton); 100 .observeSelection(rangeButton);
99 final ISWTObservableValue textSelected = SWTObservables 101 final ISWTObservableValue textSelected = SWTObservables
100 .observeSelection(textButton); 102 .observeSelection(textButton);
101 103
102 // Note that ControlUpdater is not API. 104 // Note that ControlUpdater is not API.
103 new ControlUpdater(oneOfTwo) { 105 new ControlUpdater(oneOfTwo) {
104 protected void updateControl() { 106 protected void updateControl() {
105 if (((Boolean) rangeSelected.getValue()).booleanValue()) { 107 if (((bool) rangeSelected.getValue()).booleanValue()) {
106 stackLayout.topControl = rangeGroup; 108 stackLayout.topControl = rangeGroup;
107 oneOfTwo.layout(); 109 oneOfTwo.layout();
108 } else if (((Boolean) textSelected.getValue()).booleanValue()) { 110 } else if (((bool) textSelected.getValue()).booleanValue()) {
109 stackLayout.topControl = textGroup; 111 stackLayout.topControl = textGroup;
110 oneOfTwo.layout(); 112 oneOfTwo.layout();
111 } 113 }
112 } 114 }
113 }; 115 };
114 } 116 }
115 } 117 }
118 void main( String[] args ){
119 Snippet023ConditionalVisibility.main(args);
120 }