01: /*
02: * Created on May 13, 2004
03: */
04: package net.charabia.jsmoothgen.application.swtgui;
05:
06: import java.util.Arrays;
07:
08: import net.charabia.jsmoothgen.application.JSmoothModelBean;
09: import net.charabia.jsmoothgen.application.swtgui.resources.JSmoothResources;
10:
11: import org.eclipse.jface.dialogs.Dialog;
12: import org.eclipse.swt.SWT;
13: import org.eclipse.swt.events.SelectionAdapter;
14: import org.eclipse.swt.events.SelectionEvent;
15: import org.eclipse.swt.layout.GridData;
16: import org.eclipse.swt.layout.GridLayout;
17: import org.eclipse.swt.widgets.Button;
18: import org.eclipse.swt.widgets.Combo;
19: import org.eclipse.swt.widgets.Composite;
20: import org.eclipse.swt.widgets.Control;
21: import org.eclipse.swt.widgets.Label;
22:
23: /**
24: * @author Dumon
25: */
26: public final class SkeletonPage extends JSmoothPage {
27: // Widgets
28: private Dialog propsDialog;
29: private Combo skelcombo;
30:
31: private JSmoothApplication js;
32: private String[] skeletons;
33:
34: public SkeletonPage(JSmoothApplication js) {
35: super (js);
36: }
37:
38: public Control createPageArea(Composite parent) {
39: Composite top = new Composite(parent, SWT.NONE);
40: top.setLayout(new GridLayout(3, false));
41:
42: Label label = new Label(top, SWT.NONE);
43: label.setText("Skeleton:");
44:
45: skelcombo = new Combo(top, SWT.READ_ONLY);
46: GridData grid = new GridData(GridData.FILL);
47: grid.widthHint = 120;
48: skelcombo.setLayoutData(grid);
49:
50: loadSkeleton(getApplication().getInitialSkeletonName());
51: skelcombo.addSelectionListener(new SelectionAdapter() {
52: public void widgetSelected(SelectionEvent e) {
53: setSkeletonName(skelcombo.getText());
54: }
55: });
56:
57: Button button = new Button(top, SWT.PUSH);
58: grid = new GridData(GridData.FILL);
59: grid.widthHint = 120;
60: button.setLayoutData(grid);
61: button.setText("Properties...");
62: button.addSelectionListener(new SelectionAdapter() {
63: public void widgetSelected(SelectionEvent e) {
64: (new SkeletonPropertiesDialog(SkeletonPage.this ))
65: .open();
66: }
67: });
68:
69: return top;
70: }
71:
72: public void setSkeletonName(String name) {
73: System.out.println("[DEBUG] Setting skeleton name: " + name);
74: JSmoothModelBean jsmodel = getApplication().getModelBean();
75: jsmodel.setSkeletonName(name);
76: getApplication().setSkeletonProperties(
77: getApplication().getInititalSkeletonProperties());
78: }
79:
80: protected void configureResources() {
81: setImage(JSmoothResources.IMG_SWITCHER_SKELETON_PAGE);
82: setToolTip("Skeleton");
83: }
84:
85: private void loadSkeleton(String skelname) {
86: String[] skeletons = getApplication().getAllSkeletonNames();
87: skelcombo.setItems(skeletons);
88: System.out.println("[DEBUG] Loading skeleton : " + skelname);
89: int index = Arrays.binarySearch(skeletons, skelname);
90: skelcombo.select(index);
91: }
92:
93: public void load() {
94: loadSkeleton(getApplication().getModelBean().getSkeletonName());
95: }
96: }
|