]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.team.ui/src/org/simantics/team/ui/CommentDialog.java
2f2471abde707226177533515d27251381e90f25
[simantics/platform.git] / bundles / org.simantics.team.ui / src / org / simantics / team / ui / CommentDialog.java
1 package org.simantics.team.ui;\r
2 \r
3 import org.eclipse.jface.dialogs.Dialog;\r
4 import org.eclipse.jface.layout.GridDataFactory;\r
5 import org.eclipse.jface.layout.GridLayoutFactory;\r
6 import org.eclipse.swt.SWT;\r
7 import org.eclipse.swt.widgets.Composite;\r
8 import org.eclipse.swt.widgets.Control;\r
9 import org.eclipse.swt.widgets.Display;\r
10 import org.eclipse.swt.widgets.Label;\r
11 import org.eclipse.swt.widgets.Shell;\r
12 import org.eclipse.swt.widgets.Text;\r
13 import org.eclipse.ui.PlatformUI;\r
14 import org.simantics.db.exception.DatabaseException;\r
15 \r
16 /**\r
17  * Dialog for chart properties:\r
18  * \r
19  * Comment: \r
20  */\r
21 public class CommentDialog extends Dialog {\r
22     public static class Data {\r
23         public boolean ok;\r
24         public final String title;\r
25         public String comment;\r
26         public Data(String title) {\r
27             this.title = title;\r
28         }\r
29     }\r
30     public static boolean openCommentDialog(final Data data)\r
31     throws DatabaseException {\r
32         final Display display = PlatformUI.getWorkbench().getDisplay();\r
33         display.syncExec(new Runnable() {\r
34             @Override\r
35             public void run() {\r
36                 CommentDialog d =  new CommentDialog(display.getActiveShell(), data);\r
37                 if (Dialog.OK != d.open())\r
38                     data.ok = false;\r
39                 else\r
40                     data.ok = true;\r
41             }});\r
42         return data.ok;\r
43     }\r
44     Label lName;\r
45     Text tName;\r
46     Data data;\r
47     public CommentDialog(Shell parentShell, Data data) {\r
48         super(parentShell);\r
49         this.data = data;\r
50         setShellStyle(SWT.RESIZE | SWT.TITLE | SWT.CLOSE | SWT.BORDER);\r
51     }\r
52     @Override\r
53     protected Control createDialogArea(Composite parent) {\r
54         Composite c = (Composite) super.createDialogArea(parent);\r
55         GridLayoutFactory.fillDefaults().margins(8, 8).numColumns(9).applyTo(c);\r
56         GridDataFactory gd1 = GridDataFactory.fillDefaults().span(1, 1);\r
57         GridDataFactory gd2 = GridDataFactory.fillDefaults().grab(true, false).span(8, 1);\r
58         // Comment:\r
59         lName = new Label(c, 0);\r
60         lName.setText("Comment:");\r
61         gd1.applyTo(lName);\r
62         tName = new Text(c, SWT.BORDER);\r
63         tName.setEnabled(true);\r
64         if (null != data.comment)\r
65             tName.setText(data.comment);\r
66         gd2.applyTo(tName);\r
67         return c;\r
68     }\r
69     @Override\r
70     protected void okPressed() {\r
71         data.comment = tName.getText();\r
72         super.okPressed();\r
73     }\r
74     @Override\r
75     protected void configureShell(Shell newShell) {\r
76         super.configureShell(newShell);\r
77         newShell.setText(data.title);\r
78     }\r
79 }\r