1 package org.simantics.databoard.forms;
\r
3 import org.eclipse.jface.dialogs.Dialog;
\r
4 import org.eclipse.jface.dialogs.IDialogConstants;
\r
5 import org.eclipse.swt.SWT;
\r
6 import org.eclipse.swt.custom.ScrolledComposite;
\r
7 import org.eclipse.swt.layout.GridData;
\r
8 import org.eclipse.swt.layout.GridLayout;
\r
9 import org.eclipse.swt.widgets.Composite;
\r
10 import org.eclipse.swt.widgets.Control;
\r
11 import org.eclipse.swt.widgets.Shell;
\r
12 import org.simantics.databoard.accessor.error.AccessorConstructionException;
\r
13 import org.simantics.databoard.accessor.error.AccessorException;
\r
14 import org.simantics.databoard.binding.RecordBinding;
\r
15 import org.simantics.databoard.binding.error.BindingException;
\r
17 public class DataboardDialog extends Dialog {
\r
19 RecordBinding formBinding;
\r
20 Object initialValues;
\r
24 Composite composite;
\r
27 * Create dialog window
\r
29 * @param parentShell
\r
31 * @param formBinding
\r
32 * @param initialValues values according to formBinding or null
\r
34 public DataboardDialog(Shell parentShell, String title, RecordBinding formBinding, Object initialValues) {
\r
36 this.formBinding = formBinding;
\r
37 this.initialValues = initialValues;
\r
40 setBlockOnOpen(true);
\r
41 setShellStyle(SWT.RESIZE | SWT.TITLE | SWT.CLOSE | SWT.BORDER);
\r
45 protected void createButtonsForButtonBar(Composite parent) {
\r
46 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
\r
47 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
\r
51 protected Control createDialogArea(Composite parent) {
\r
52 ScrolledComposite scroll = new ScrolledComposite(parent, SWT.V_SCROLL);
\r
53 composite = new Composite(scroll, 0);
\r
54 scroll.setContent(composite);
\r
55 scroll.setExpandHorizontal(true);
\r
56 scroll.setExpandVertical(false);
\r
57 form = new DataboardForm();
\r
58 form.setFirstColumnWidth(0);
\r
59 form.addFields(composite, formBinding.type());
\r
61 composite.setLayout( new GridLayout(3, false) );
\r
62 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1));
\r
64 if ( initialValues != null ) {
\r
66 form.writeFields(composite, formBinding, initialValues);
\r
67 } catch (AccessorException e) {
\r
68 e.printStackTrace();
\r
69 } catch (BindingException e) {
\r
70 e.printStackTrace();
\r
71 } catch (AccessorConstructionException e) {
\r
72 e.printStackTrace();
\r
81 protected void configureShell(Shell newShell) {
\r
82 super.configureShell(newShell);
\r
83 newShell.setText(title);
\r
87 protected void okPressed() {
\r
89 result = formBinding.createDefault();
\r
90 form.readFields(composite, formBinding, result);
\r
91 } catch (BindingException e) {
\r
92 e.printStackTrace();
\r
94 } catch (AccessorConstructionException e) {
\r
95 e.printStackTrace();
\r
97 } catch (AccessorException e) {
\r
98 e.printStackTrace();
\r
105 protected void cancelPressed() {
\r
107 super.cancelPressed();
\r
110 public Object getResult() {
\r