我想在 Jface WizardPage 中实现一个简单的主从场景: WizardPage 将有一个带有一些名称的表,在选择表中的一行后,包含文本/标签的 WizardPage 的底部将更新为与选择相对应的详细信息在表中。
我搜索了互联网,只找到了作为 SWT 应用程序运行的示例:http: //dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding /snippets/Snippet010MasterDetail.java?view=markup
1 /*******************************************************************************
2 * Copyright (c) 2007, 2009 Brad Reynolds 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 * Brad Reynolds - initial API and implementation
10 * Matthew Hall - bug 260329
11 ******************************************************************************/
12
13 package org.eclipse.jface.examples.databinding.snippets;
14
15 import java.beans.PropertyChangeListener;
16 import java.beans.PropertyChangeSupport;
17
18 import org.eclipse.core.databinding.DataBindingContext;
19 import org.eclipse.core.databinding.UpdateValueStrategy;
20 import org.eclipse.core.databinding.beans.BeansObservables;
21 import org.eclipse.core.databinding.observable.Realm;
22 import org.eclipse.core.databinding.observable.value.IObservableValue;
23 import org.eclipse.jface.databinding.swt.SWTObservables;
24 import org.eclipse.jface.databinding.viewers.ViewersObservables;
25 import org.eclipse.jface.viewers.ArrayContentProvider;
26 import org.eclipse.jface.viewers.ListViewer;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.layout.GridLayout;
29 import org.eclipse.swt.widgets.Display;
30 import org.eclipse.swt.widgets.Shell;
31 import org.eclipse.swt.widgets.Text;
32
33 /**
34 * Snippet that displays a simple master detail use case. A list of persons is
35 * displayed in a list and upon selection the name of the selected person will
36 * be displayed in a Text widget.
37 */
38 public class Snippet010MasterDetail {
39 public static void main(String[] args) {
40 final Display display = new Display();
41 Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
42 public void run() {
43 Shell shell = new Shell(display);
44 shell.setLayout(new GridLayout());
45
46 Person[] persons = new Person[] { new Person("Me"),
47 new Person("Myself"), new Person("I") };
48
49 ListViewer viewer = new ListViewer(shell);
50 viewer.setContentProvider(new ArrayContentProvider());
51 viewer.setInput(persons);
52
53 Text name = new Text(shell, SWT.BORDER | SWT.READ_ONLY);
54
55 // 1. Observe changes in selection.
56 IObservableValue selection = ViewersObservables
57 .observeSingleSelection(viewer);
58
59 // 2. Observe the name property of the current selection.
60 IObservableValue detailObservable = BeansObservables
61 .observeDetailValue(selection, "name", String.class);
62
63 // 3. Bind the Text widget to the name detail (selection's
64 // name).
65 new DataBindingContext().bindValue(SWTObservables.observeText(
66 name, SWT.None), detailObservable,
67 new UpdateValueStrategy(false,
68 UpdateValueStrategy.POLICY_NEVER), null);
69
70 shell.open();
71 while (!shell.isDisposed()) {
72 if (!display.readAndDispatch())
73 display.sleep();
74 }
75 }
76 });
77 display.dispose();
78 }
79
80 public static class Person {
81 private String name;
82 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
83
84 Person(String name) {
85 this.name = name;
86 }
87
88 public void addPropertyChangeListener(PropertyChangeListener listener) {
89 changeSupport.addPropertyChangeListener(listener);
90 }
91
92 public void removePropertyChangeListener(PropertyChangeListener listener) {
93 changeSupport.removePropertyChangeListener(listener);
94 }
95
96 /**
97 * @return Returns the name.
98 */
99 public String getName() {
100 return name;
101 }
102
103 public String toString() {
104 return name;
105 }
106 }
107 }
如何将其集成到 JFace 向导中?这个向导应该作为 Eclipse 插件运行