001: /*
002: * Created on May 15, 2004
003: */
004: package net.charabia.jsmoothgen.application.swtgui;
005:
006: import java.util.Iterator;
007: import java.util.List;
008: import java.util.Vector;
009:
010: import net.charabia.jsmoothgen.skeleton.SkeletonProperty;
011:
012: import org.eclipse.jface.dialogs.Dialog;
013: import org.eclipse.swt.SWT;
014: import org.eclipse.swt.layout.GridData;
015: import org.eclipse.swt.layout.GridLayout;
016: import org.eclipse.swt.widgets.Button;
017: import org.eclipse.swt.widgets.Composite;
018: import org.eclipse.swt.widgets.Control;
019: import org.eclipse.swt.widgets.Group;
020: import org.eclipse.swt.widgets.Text;
021:
022: /**
023: * @author Dumon
024: */
025: public class SkeletonPropertiesDialog extends Dialog {
026: private Text text;
027: private Button check;
028: private List controls = new Vector();
029: private SkeletonPage page;
030: private JSmoothApplication app;
031:
032: public SkeletonPropertiesDialog(SkeletonPage page) {
033: super (page.getApplication().getShell());
034: this .page = page;
035: }
036:
037: protected Control createDialogArea(Composite parent) {
038: Composite cmpDlgArea = new Composite(parent, SWT.NONE);
039: cmpDlgArea.setLayout(new GridLayout());
040:
041: SkeletonProperty[] props = page.getApplication()
042: .getSkeletonProperties();
043: for (int i = 0; i < props.length; i++) {
044: System.out.println("[DEBUG] Loading skeleton property: "
045: + props[i].getIdName() + "=" + props[i].getValue());
046: }
047:
048: for (int i = 0; i < props.length; i++) {
049: Control c = createPropertyControl(cmpDlgArea, props[i]);
050: c.setData(props[i]);
051: controls.add(c);
052: }
053:
054: return cmpDlgArea;
055: }
056:
057: private Control createPropertyControl(Composite wParent,
058: SkeletonProperty prop) {
059: Group group = null;
060: GridData grid = null;
061: if (prop.getType().equals(SkeletonProperty.TYPE_STRING)) {
062: group = new Group(wParent, SWT.NONE);
063: grid = new GridData(GridData.FILL);
064: grid.widthHint = 400;
065: group.setLayoutData(grid);
066: group.setLayout(new GridLayout());
067: group.setText(prop.getLabel());
068:
069: text = new Text(group, SWT.SINGLE | SWT.BORDER);
070: grid = new GridData(GridData.FILL_BOTH);
071: text.setLayoutData(grid);
072: text.setText(prop.getValue());
073:
074: return text;
075: } else if (prop.getType()
076: .equals(SkeletonProperty.TYPE_TEXTAREA)) {
077: group = new Group(wParent, SWT.NONE);
078: grid = new GridData(GridData.FILL);
079: grid.widthHint = 400;
080: grid.heightHint = 100;
081: group.setLayoutData(grid);
082: group.setLayout(new GridLayout());
083: group.setText(prop.getLabel());
084:
085: text = new Text(group, SWT.MULTI | SWT.BORDER
086: | SWT.H_SCROLL | SWT.V_SCROLL);
087: grid = new GridData(GridData.FILL_BOTH);
088: text.setLayoutData(grid);
089: text.setText(prop.getValue());
090:
091: return text;
092: } else if (prop.getType().equals(SkeletonProperty.TYPE_BOOLEAN)) {
093: Button chk = new Button(wParent, SWT.CHECK);
094: chk.setText(prop.getLabel());
095: chk.setSelection("1".equals(prop.getValue()));
096:
097: return chk;
098: } else {
099: throw new UnsupportedOperationException(
100: "Unknown skeleton property type.");
101: }
102: }
103:
104: protected void okPressed() {
105: Iterator it = controls.iterator();
106:
107: JSmoothApplication app = page.getApplication();
108: Control ctrl = null;
109: String value = null;
110: SkeletonProperty prop = null;
111: while (it.hasNext()) {
112: ctrl = (Control) it.next();
113: prop = (SkeletonProperty) ctrl.getData();
114: if (prop.getType().equals(SkeletonProperty.TYPE_STRING)) {
115: value = ((Text) ctrl).getText();
116: prop.setValue(value);
117: } else if (prop.getType().equals(
118: SkeletonProperty.TYPE_TEXTAREA)) {
119: value = ((Text) ctrl).getText();
120: prop.setValue(value);
121: } else if (prop.getType().equals(
122: SkeletonProperty.TYPE_BOOLEAN)) {
123: boolean b = ((Button) ctrl).getSelection();
124: value = (b == true) ? "1" : "0";
125: prop.setValue(value);
126: }
127: app.setSkeletonProperty(prop);
128: }
129:
130: super.okPressed();
131: }
132:
133: }
|