我想在Jface WizardPage中實現一個簡單的主細節場景: WizardPage將有一個包含一些名字的表格,在表格底部選擇一行包含文本/標籤的WizardPage會根據表中所選內容的細節進行更新。如何在JFace 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插件
我試圖將上面的例子集成到WizardPage的createControl()方法中。但它不工作,我不確定在哪裏創建JFace嚮導場景中的Display和Shell對象(我是SWT/JFace的新手)。我不知道如何以及在哪裏「處理」適當的對象。 Display和Shell是否內部創建並在JFace嚮導中處理?我在createControl()方法內部嘗試了Display.getDefault()和getShell()方法,但它不是一個正確的地方。仍在搜索示例,展示如何將這個集成到Jface嚮導中。任何幫助是可觀的! – vag
嗯,我也試過在主表上的addSelectionChangedListener,但這是第一次更新細節表,並且以後的選擇更改不會更新細節表。 – vag