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