Mercurial > projects > dwt2
comparison org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet023ConditionalVisibility.d @ 90:6086085e153d
Added databinding snippets. unmodified java sources.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 19 Apr 2009 11:33:55 +0200 |
parents | |
children | 5d5bd660917f |
comparison
equal
deleted
inserted
replaced
89:0ca1aee7decf | 90:6086085e153d |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 ******************************************************************************/ | |
11 | |
12 package org.eclipse.jface.examples.databinding.snippets; | |
13 | |
14 import org.eclipse.core.databinding.observable.Realm; | |
15 import org.eclipse.jface.databinding.swt.ISWTObservableValue; | |
16 import org.eclipse.jface.databinding.swt.SWTObservables; | |
17 import org.eclipse.jface.internal.databinding.provisional.swt.ControlUpdater; | |
18 import org.eclipse.jface.layout.GridLayoutFactory; | |
19 import org.eclipse.swt.SWT; | |
20 import org.eclipse.swt.custom.StackLayout; | |
21 import org.eclipse.swt.layout.GridLayout; | |
22 import org.eclipse.swt.widgets.Button; | |
23 import org.eclipse.swt.widgets.Composite; | |
24 import org.eclipse.swt.widgets.Display; | |
25 import org.eclipse.swt.widgets.Group; | |
26 import org.eclipse.swt.widgets.Label; | |
27 import org.eclipse.swt.widgets.Shell; | |
28 import org.eclipse.swt.widgets.Text; | |
29 | |
30 /** | |
31 * @since 3.2 | |
32 * | |
33 */ | |
34 public class Snippet023ConditionalVisibility { | |
35 public static void main(String[] args) { | |
36 Display display = new Display(); | |
37 final Shell shell = new Shell(display); | |
38 shell.setLayout(new GridLayout(1, false)); | |
39 | |
40 Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { | |
41 public void run() { | |
42 new Snippet023ConditionalVisibility().createControls(shell); | |
43 } | |
44 }); | |
45 | |
46 shell.pack(); | |
47 shell.open(); | |
48 while (!shell.isDisposed()) { | |
49 if (!display.readAndDispatch()) | |
50 display.sleep(); | |
51 } | |
52 display.dispose(); | |
53 } | |
54 | |
55 Text text; | |
56 Text toText; | |
57 Text fromText; | |
58 | |
59 /** | |
60 * @param shell | |
61 */ | |
62 private void createControls(Shell shell) { | |
63 Composite composite = new Composite(shell, SWT.NONE); | |
64 Group radioGroup = new Group(composite, SWT.NONE); | |
65 radioGroup.setText("Type"); | |
66 Button textButton = new Button(radioGroup, SWT.RADIO); | |
67 textButton.setText("Text"); | |
68 Button rangeButton = new Button(radioGroup, SWT.RADIO); | |
69 rangeButton.setText("Range"); | |
70 GridLayoutFactory.swtDefaults().generateLayout(radioGroup); | |
71 | |
72 final Composite oneOfTwo = new Composite(composite, SWT.NONE); | |
73 final StackLayout stackLayout = new StackLayout(); | |
74 oneOfTwo.setLayout(stackLayout); | |
75 | |
76 final Group rangeGroup = new Group(oneOfTwo, SWT.NONE); | |
77 rangeGroup.setText("Range"); | |
78 Label fromLabel = new Label(rangeGroup, SWT.NONE); | |
79 fromLabel.setText("From:"); | |
80 fromText = new Text(rangeGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); | |
81 | |
82 Label toLabel = new Label(rangeGroup, SWT.NONE); | |
83 toLabel.setText("To:"); | |
84 toText = new Text(rangeGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); | |
85 GridLayoutFactory.swtDefaults().numColumns(2) | |
86 .generateLayout(rangeGroup); | |
87 | |
88 final Group textGroup = new Group(oneOfTwo, SWT.NONE); | |
89 textGroup.setText("Text"); | |
90 Label label = new Label(textGroup, SWT.NONE); | |
91 label.setText("Text:"); | |
92 text = new Text(textGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); | |
93 GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(textGroup); | |
94 | |
95 GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(composite); | |
96 | |
97 final ISWTObservableValue rangeSelected = SWTObservables | |
98 .observeSelection(rangeButton); | |
99 final ISWTObservableValue textSelected = SWTObservables | |
100 .observeSelection(textButton); | |
101 | |
102 // Note that ControlUpdater is not API. | |
103 new ControlUpdater(oneOfTwo) { | |
104 protected void updateControl() { | |
105 if (((Boolean) rangeSelected.getValue()).booleanValue()) { | |
106 stackLayout.topControl = rangeGroup; | |
107 oneOfTwo.layout(); | |
108 } else if (((Boolean) textSelected.getValue()).booleanValue()) { | |
109 stackLayout.topControl = textGroup; | |
110 oneOfTwo.layout(); | |
111 } | |
112 } | |
113 }; | |
114 } | |
115 } |