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