1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.connect.ui.parts;
17
18 import org.argeo.eclipse.ui.EclipseUiUtils;
19 import org.eclipse.jface.dialogs.MessageDialog;
20 import org.eclipse.jface.dialogs.TrayDialog;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.events.ModifyEvent;
23 import org.eclipse.swt.events.ModifyListener;
24 import org.eclipse.swt.graphics.Point;
25 import org.eclipse.swt.layout.GridData;
26 import org.eclipse.swt.layout.GridLayout;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29 import org.eclipse.swt.widgets.Label;
30 import org.eclipse.swt.widgets.Shell;
31 import org.eclipse.swt.widgets.Text;
32
33
34
35
36
37 public class AskTitleDescriptionDialog extends TrayDialog {
38 private static final long serialVersionUID = -1965274702044063832L;
39
40 private Text titleTxt;
41 private Text descTxt;
42
43 private String title;
44 private String desc;
45
46 private final String windowTitle;
47
48
49
50
51
52 public AskTitleDescriptionDialog(Shell parentShell, String windowTitle) {
53 super(parentShell);
54 this.windowTitle = windowTitle;
55 }
56
57 public AskTitleDescriptionDialog(Shell parentShell, String windowTitle, String defaultTitle, String defaultDesc) {
58 super(parentShell);
59 this.windowTitle = windowTitle;
60 title = defaultTitle;
61 desc = defaultDesc;
62 }
63
64 protected Control createDialogArea(Composite parent) {
65
66 Composite dialogarea = (Composite) super.createDialogArea(parent);
67 dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
68 dialogarea.setLayout(new GridLayout(2, false));
69
70
71 titleTxt = createLT(dialogarea, "Title");
72 if (EclipseUiUtils.notEmpty(title))
73 titleTxt.setText(title);
74 titleTxt.setMessage("Please provide a title");
75 titleTxt.addModifyListener(new ModifyListener() {
76 private static final long serialVersionUID = 1L;
77
78 @Override
79 public void modifyText(ModifyEvent event) {
80 title = titleTxt.getText();
81 }
82 });
83
84
85 Label lbl = new Label(dialogarea, SWT.RIGHT);
86 lbl.setText("Description");
87 lbl.setFont(EclipseUiUtils.getBoldFont(dialogarea));
88 lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
89 descTxt = new Text(dialogarea, SWT.MULTI | SWT.WRAP | SWT.BORDER);
90 descTxt.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
91 if (EclipseUiUtils.notEmpty(desc))
92 descTxt.setText(desc);
93 descTxt.setMessage("... and optionally a description");
94 descTxt.addModifyListener(new ModifyListener() {
95 private static final long serialVersionUID = 1L;
96
97 @Override
98 public void modifyText(ModifyEvent event) {
99 desc = descTxt.getText();
100 }
101 });
102 parent.pack();
103 return dialogarea;
104 }
105
106 public String getTitle() {
107 return title;
108 }
109
110 public String getDescription() {
111 return desc;
112 }
113
114
115
116
117
118
119 protected boolean performFinish() {
120
121 String msg = null;
122
123 if (EclipseUiUtils.isEmpty(title) || title.length() < 2)
124 msg = "Please enter a title that is at list two (2) valid charaters long.";
125 if (msg != null) {
126 MessageDialog.openError(getShell(), "Non valid information", msg);
127 return false;
128 }
129
130 return true;
131 }
132
133
134 @Override
135 protected void okPressed() {
136 if (performFinish())
137 super.okPressed();
138 }
139
140 protected Point getInitialSize() {
141 return new Point(400, 250);
142 }
143
144 protected void configureShell(Shell shell) {
145 super.configureShell(shell);
146 shell.setText(windowTitle);
147 }
148
149
150
151 protected Text createLT(Composite parent, String label) {
152 Label lbl = new Label(parent, SWT.RIGHT);
153 lbl.setText(label);
154 lbl.setFont(EclipseUiUtils.getBoldFont(parent));
155 lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
156 Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
157 text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
158 return text;
159 }
160 }