?? jfacedatabinding7.java
字號:
package cn.com.chengang.databinding;
import java.util.Arrays;
import org.eclipse.jface.internal.databinding.provisional.DataBindingContext;
import org.eclipse.jface.internal.databinding.provisional.description.Property;
import org.eclipse.jface.internal.databinding.provisional.observable.list.WritableList;
import org.eclipse.jface.internal.databinding.provisional.swt.SWTProperties;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class JFaceDataBinding7 {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
// ---------創(chuàng)建窗口中的其他界面組件-------------
shell.setLayout(new RowLayout());
final People bean = new People();// 數(shù)據(jù)
Button button = new Button(shell, SWT.NONE);
button.setText("打印數(shù)據(jù)");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("---------------------------------");
System.out.println("name=" + bean.getName());
System.out.println("age=" + bean.getAge());
System.out.println("sex=" + bean.isSex());
System.out.println("interests=" + Arrays.toString(bean.getInterests().toArray()));
}
});
// 界面組件
Combo combo = new Combo(shell, SWT.BORDER);
// 綁定初始數(shù)據(jù)
DataBindingContext ctx = DataBindingContextFactory.createContext(shell);
WritableList ageList = new WritableList(String.class);
ageList.add("0");
ageList.add("10");
ageList.add("20");
ageList.add("30");
ctx.bind(new Property(combo, SWTProperties.ITEMS), ageList, null);
ageList.add("100"); // 以后還可以再加進新項,將實現(xiàn)反映到界面上
combo.remove("100");// 如果從界面刪除某項,ageList也會跟著刪除該項。
// 初選綁定
ctx.bind(new Property(combo, SWTProperties.SELECTION), new Property(bean, "age"), null);
// -----------------END------------------------
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -