]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.team.ui/src/org/simantics/team/ui/CommentDialog.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.team.ui / src / org / simantics / team / ui / CommentDialog.java
diff --git a/bundles/org.simantics.team.ui/src/org/simantics/team/ui/CommentDialog.java b/bundles/org.simantics.team.ui/src/org/simantics/team/ui/CommentDialog.java
new file mode 100644 (file)
index 0000000..2f2471a
--- /dev/null
@@ -0,0 +1,79 @@
+package org.simantics.team.ui;\r
+\r
+import org.eclipse.jface.dialogs.Dialog;\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+/**\r
+ * Dialog for chart properties:\r
+ * \r
+ * Comment: \r
+ */\r
+public class CommentDialog extends Dialog {\r
+    public static class Data {\r
+        public boolean ok;\r
+        public final String title;\r
+        public String comment;\r
+        public Data(String title) {\r
+            this.title = title;\r
+        }\r
+    }\r
+    public static boolean openCommentDialog(final Data data)\r
+    throws DatabaseException {\r
+        final Display display = PlatformUI.getWorkbench().getDisplay();\r
+        display.syncExec(new Runnable() {\r
+            @Override\r
+            public void run() {\r
+                CommentDialog d =  new CommentDialog(display.getActiveShell(), data);\r
+                if (Dialog.OK != d.open())\r
+                    data.ok = false;\r
+                else\r
+                    data.ok = true;\r
+            }});\r
+        return data.ok;\r
+    }\r
+    Label lName;\r
+    Text tName;\r
+    Data data;\r
+    public CommentDialog(Shell parentShell, Data data) {\r
+        super(parentShell);\r
+        this.data = data;\r
+        setShellStyle(SWT.RESIZE | SWT.TITLE | SWT.CLOSE | SWT.BORDER);\r
+    }\r
+    @Override\r
+    protected Control createDialogArea(Composite parent) {\r
+        Composite c = (Composite) super.createDialogArea(parent);\r
+        GridLayoutFactory.fillDefaults().margins(8, 8).numColumns(9).applyTo(c);\r
+        GridDataFactory gd1 = GridDataFactory.fillDefaults().span(1, 1);\r
+        GridDataFactory gd2 = GridDataFactory.fillDefaults().grab(true, false).span(8, 1);\r
+        // Comment:\r
+        lName = new Label(c, 0);\r
+        lName.setText("Comment:");\r
+        gd1.applyTo(lName);\r
+        tName = new Text(c, SWT.BORDER);\r
+        tName.setEnabled(true);\r
+        if (null != data.comment)\r
+            tName.setText(data.comment);\r
+        gd2.applyTo(tName);\r
+        return c;\r
+    }\r
+    @Override\r
+    protected void okPressed() {\r
+        data.comment = tName.getText();\r
+        super.okPressed();\r
+    }\r
+    @Override\r
+    protected void configureShell(Shell newShell) {\r
+        super.configureShell(newShell);\r
+        newShell.setText(data.title);\r
+    }\r
+}\r