1
|
|
|
package br.ufrj.ppgi.greco.kettle; |
2
|
|
|
|
3
|
|
|
import org.eclipse.swt.SWT; |
4
|
|
|
import org.eclipse.swt.events.FocusListener; |
5
|
|
|
import org.eclipse.swt.events.ModifyEvent; |
6
|
|
|
import org.eclipse.swt.events.ModifyListener; |
7
|
|
|
import org.eclipse.swt.events.SelectionAdapter; |
8
|
|
|
import org.eclipse.swt.events.SelectionEvent; |
9
|
|
|
import org.eclipse.swt.events.ShellAdapter; |
10
|
|
|
import org.eclipse.swt.events.ShellEvent; |
11
|
|
|
import org.eclipse.swt.graphics.Cursor; |
12
|
|
|
import org.eclipse.swt.graphics.Rectangle; |
13
|
|
|
import org.eclipse.swt.layout.FormAttachment; |
14
|
|
|
import org.eclipse.swt.layout.FormData; |
15
|
|
|
import org.eclipse.swt.layout.FormLayout; |
16
|
|
|
import org.eclipse.swt.widgets.Button; |
17
|
|
|
import org.eclipse.swt.widgets.Display; |
18
|
|
|
import org.eclipse.swt.widgets.Event; |
19
|
|
|
import org.eclipse.swt.widgets.FileDialog; |
20
|
|
|
import org.eclipse.swt.widgets.Label; |
21
|
|
|
import org.eclipse.swt.widgets.Listener; |
22
|
|
|
import org.eclipse.swt.widgets.Shell; |
23
|
|
|
import org.eclipse.swt.widgets.Text; |
24
|
|
|
import org.pentaho.di.core.Const; |
25
|
|
|
import org.pentaho.di.core.util.StringUtil; |
26
|
|
|
import org.pentaho.di.i18n.BaseMessages; |
27
|
|
|
import org.pentaho.di.trans.TransMeta; |
28
|
|
|
import org.pentaho.di.trans.step.BaseStepMeta; |
29
|
|
|
import org.pentaho.di.trans.step.StepDialogInterface; |
30
|
|
|
import org.pentaho.di.ui.core.widget.ComboVar; |
31
|
|
|
import org.pentaho.di.ui.core.widget.TextVar; |
32
|
|
|
import org.pentaho.di.ui.trans.step.BaseStepDialog; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Interface de usuario do step Annotator. |
36
|
|
|
* |
37
|
|
|
* @author Camila Carvalho Ferreira |
38
|
|
|
* |
39
|
|
|
*/ |
40
|
|
|
public class AnnotatorStepDialog extends BaseStepDialog implements StepDialogInterface { |
41
|
|
|
|
42
|
|
|
private static Class<?> PKG = AnnotatorStepMeta.class; |
43
|
|
|
|
44
|
|
|
private AnnotatorStepMeta input; |
45
|
|
|
private String dialogTitle; |
46
|
|
|
|
47
|
|
|
// Adicionar variaveis dos widgets |
48
|
|
|
private ComboVar wcSubject; |
49
|
|
|
private ComboVar wcPredicate; |
50
|
|
|
private ComboVar wcObject; |
51
|
|
|
private TextVar wtNTriple; |
52
|
|
|
private Label wlShape; |
53
|
|
|
private Label wlSubject; |
54
|
|
|
private Label wlObject; |
55
|
|
|
private Label wlPredicate; |
56
|
|
|
private Label wlNTriple; |
57
|
|
|
|
58
|
|
|
private Button wbBrowse; |
59
|
|
|
private Text wBrowse; |
60
|
|
|
|
61
|
|
|
private FormData fdlNTriple; |
62
|
|
|
private FormData fdtNTriple; |
63
|
|
|
private FormData fdlObject; |
64
|
|
|
private FormData fdcObject; |
65
|
|
|
private FormData fdlPredicate; |
66
|
|
|
private FormData fdcPredicate; |
67
|
|
|
private FormData fdlSubject; |
68
|
|
|
private FormData fdcSubject; |
69
|
|
|
private FormData fdlShape; |
70
|
|
|
private FormData fdbBrowse; |
71
|
|
|
private FormData fdBrowse; |
72
|
|
|
|
73
|
|
|
public AnnotatorStepDialog(Shell parent, Object stepMeta, TransMeta transMeta, String stepname) { |
74
|
|
|
super(parent, (BaseStepMeta) stepMeta, transMeta, stepname); |
75
|
|
|
|
76
|
|
|
input = (AnnotatorStepMeta) baseStepMeta; |
77
|
|
|
|
78
|
|
|
// Additional initialization here |
79
|
|
|
dialogTitle = BaseMessages.getString(PKG, "AnnotatorStep.Title"); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public String open() { |
83
|
|
|
|
84
|
|
|
Shell parent = getParent(); |
85
|
|
|
Display display = parent.getDisplay(); |
86
|
|
|
|
87
|
|
|
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX); |
88
|
|
|
props.setLook(shell); |
89
|
|
|
setShellImage(shell, input); |
90
|
|
|
|
91
|
|
|
// ModifyListener padrao |
92
|
|
|
ModifyListener lsMod = new ModifyListener() { |
93
|
|
|
public void modifyText(ModifyEvent e) { |
94
|
|
|
input.setChanged(); |
95
|
|
|
} |
96
|
|
|
}; |
97
|
|
|
|
98
|
|
|
boolean changed = input.hasChanged(); |
99
|
|
|
|
100
|
|
|
FormLayout formLayout = new FormLayout(); |
101
|
|
|
formLayout.marginWidth = Const.FORM_MARGIN; |
102
|
|
|
formLayout.marginHeight = Const.FORM_MARGIN; |
103
|
|
|
|
104
|
|
|
shell.setLayout(formLayout); |
105
|
|
|
|
106
|
|
|
shell.setText(dialogTitle); |
107
|
|
|
|
108
|
|
|
int middle = props.getMiddlePct(); |
109
|
|
|
int margin = Const.MARGIN; |
110
|
|
|
|
111
|
|
|
// Adiciona um label e um input text no topo do dialog shell |
112
|
|
|
wlStepname = new Label(shell, SWT.RIGHT); |
113
|
|
|
wlStepname.setText(BaseMessages.getString(PKG, "AnnotatorStep.StepNameField.Label")); |
114
|
|
|
props.setLook(wlStepname); |
115
|
|
|
fdlStepname = new FormData(); |
116
|
|
|
fdlStepname.left = new FormAttachment(0, 0); |
117
|
|
|
fdlStepname.right = new FormAttachment(middle, -margin); |
118
|
|
|
fdlStepname.top = new FormAttachment(0, margin); |
119
|
|
|
wlStepname.setLayoutData(fdlStepname); |
120
|
|
|
wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
121
|
|
|
wStepname.setText(stepname); |
122
|
|
|
props.setLook(wStepname); |
123
|
|
|
wStepname.addModifyListener(lsMod); |
124
|
|
|
fdStepname = new FormData(); |
125
|
|
|
fdStepname.left = new FormAttachment(middle, 0); |
126
|
|
|
fdStepname.top = new FormAttachment(0, margin); |
127
|
|
|
fdStepname.right = new FormAttachment(100, 0); |
128
|
|
|
wStepname.setLayoutData(fdStepname); |
129
|
|
|
|
130
|
|
|
// Adiciona label e combo do campo sujeito |
131
|
|
|
wlSubject = new Label(shell, SWT.RIGHT); |
132
|
|
|
wlSubject.setText(BaseMessages.getString(PKG, "AnnotatorStep.SubjectField.Label")); |
133
|
|
|
props.setLook(wlSubject); |
134
|
|
|
fdlSubject = new FormData(); |
135
|
|
|
fdlSubject.left = new FormAttachment(0, 0); |
136
|
|
|
fdlSubject.top = new FormAttachment(wStepname, margin); |
137
|
|
|
fdlSubject.right = new FormAttachment(middle, -margin); |
138
|
|
|
wlSubject.setLayoutData(fdlSubject); |
139
|
|
|
|
140
|
|
|
wcSubject = new ComboVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
141
|
|
|
props.setLook(wcSubject); |
142
|
|
|
wcSubject.addModifyListener(lsMod); |
143
|
|
|
fdcSubject = new FormData(); |
144
|
|
|
fdcSubject.left = new FormAttachment(middle, 0); |
145
|
|
|
fdcSubject.right = new FormAttachment(100, 0); |
146
|
|
|
fdcSubject.top = new FormAttachment(wStepname, margin); |
147
|
|
|
wcSubject.setLayoutData(fdcSubject); |
148
|
|
|
wcSubject.addFocusListener(new FocusListener() { |
149
|
|
|
public void focusLost(org.eclipse.swt.events.FocusEvent e) { |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public void focusGained(org.eclipse.swt.events.FocusEvent e) { |
153
|
|
|
Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); |
154
|
|
|
shell.setCursor(busy); |
155
|
|
|
BaseStepDialog.getFieldsFromPrevious(wcSubject, transMeta, stepMeta); |
156
|
|
|
shell.setCursor(null); |
157
|
|
|
busy.dispose(); |
158
|
|
|
} |
159
|
|
|
}); |
160
|
|
|
|
161
|
|
|
// Adiciona label e combo do campo predicado |
162
|
|
|
wlPredicate = new Label(shell, SWT.RIGHT); |
163
|
|
|
wlPredicate.setText(BaseMessages.getString(PKG, "AnnotatorStep.PredicateField.Label")); |
164
|
|
|
props.setLook(wlPredicate); |
165
|
|
|
fdlPredicate = new FormData(); |
166
|
|
|
fdlPredicate.left = new FormAttachment(0, 0); |
167
|
|
|
fdlPredicate.top = new FormAttachment(wcSubject, margin); |
168
|
|
|
fdlPredicate.right = new FormAttachment(middle, -margin); |
169
|
|
|
wlPredicate.setLayoutData(fdlPredicate); |
170
|
|
|
|
171
|
|
|
wcPredicate = new ComboVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
172
|
|
|
props.setLook(wcPredicate); |
173
|
|
|
wcPredicate.addModifyListener(lsMod); |
174
|
|
|
fdcPredicate = new FormData(); |
175
|
|
|
fdcPredicate.left = new FormAttachment(middle, 0); |
176
|
|
|
fdcPredicate.right = new FormAttachment(100, 0); |
177
|
|
|
fdcPredicate.top = new FormAttachment(wcSubject, margin); |
178
|
|
|
wcPredicate.setLayoutData(fdcPredicate); |
179
|
|
|
wcPredicate.addFocusListener(new FocusListener() { |
180
|
|
|
public void focusLost(org.eclipse.swt.events.FocusEvent e) { |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public void focusGained(org.eclipse.swt.events.FocusEvent e) { |
184
|
|
|
Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); |
185
|
|
|
shell.setCursor(busy); |
186
|
|
|
BaseStepDialog.getFieldsFromPrevious(wcPredicate, transMeta, stepMeta); |
187
|
|
|
shell.setCursor(null); |
188
|
|
|
busy.dispose(); |
189
|
|
|
} |
190
|
|
|
}); |
191
|
|
|
|
192
|
|
|
// Adiciona label e combo do campo objeto |
193
|
|
|
wlObject = new Label(shell, SWT.RIGHT); |
194
|
|
|
wlObject.setText(BaseMessages.getString(PKG, "AnnotatorStep.ObjectField.Label")); |
195
|
|
|
props.setLook(wlObject); |
196
|
|
|
fdlObject = new FormData(); |
197
|
|
|
fdlObject.left = new FormAttachment(0, 0); |
198
|
|
|
fdlObject.top = new FormAttachment(wcPredicate, margin); |
199
|
|
|
fdlObject.right = new FormAttachment(middle, -margin); |
200
|
|
|
wlObject.setLayoutData(fdlObject); |
201
|
|
|
|
202
|
|
|
wcObject = new ComboVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
203
|
|
|
props.setLook(wcObject); |
204
|
|
|
wcObject.addModifyListener(lsMod); |
205
|
|
|
fdcObject = new FormData(); |
206
|
|
|
fdcObject.left = new FormAttachment(middle, 0); |
207
|
|
|
fdcObject.right = new FormAttachment(100, 0); |
208
|
|
|
fdcObject.top = new FormAttachment(wcPredicate, margin); |
209
|
|
|
wcObject.setLayoutData(fdcObject); |
210
|
|
|
wcObject.addFocusListener(new FocusListener() { |
211
|
|
|
public void focusLost(org.eclipse.swt.events.FocusEvent e) { |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
public void focusGained(org.eclipse.swt.events.FocusEvent e) { |
215
|
|
|
Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); |
216
|
|
|
shell.setCursor(busy); |
217
|
|
|
BaseStepDialog.getFieldsFromPrevious(wcObject, transMeta, stepMeta); |
218
|
|
|
shell.setCursor(null); |
219
|
|
|
busy.dispose(); |
220
|
|
|
} |
221
|
|
|
}); |
222
|
|
|
|
223
|
|
|
// Adiciona label e text do campo saida |
224
|
|
|
wlNTriple = new Label(shell, SWT.RIGHT); |
225
|
|
|
wlNTriple.setText(BaseMessages.getString(PKG, "AnnotatorStep.NTripleField.Label")); //$NON-NLS-1$ |
226
|
|
|
props.setLook(wlNTriple); |
227
|
|
|
fdlNTriple = new FormData(); |
228
|
|
|
fdlNTriple.left = new FormAttachment(0, 0); |
229
|
|
|
fdlNTriple.right = new FormAttachment(middle, -margin); |
230
|
|
|
fdlNTriple.top = new FormAttachment(wcObject, margin); |
231
|
|
|
wlNTriple.setLayoutData(fdlNTriple); |
232
|
|
|
|
233
|
|
|
wtNTriple = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
234
|
|
|
wtNTriple.setText(""); //$NON-NLS-1$ |
235
|
|
|
props.setLook(wtNTriple); |
236
|
|
|
wtNTriple.addModifyListener(lsMod); |
237
|
|
|
fdtNTriple = new FormData(); |
238
|
|
|
fdtNTriple.left = new FormAttachment(middle, 0); |
239
|
|
|
fdtNTriple.top = new FormAttachment(wcObject, margin); |
240
|
|
|
fdtNTriple.right = new FormAttachment(100, 0); |
241
|
|
|
wtNTriple.setLayoutData(fdtNTriple); |
242
|
|
|
|
243
|
|
|
// Bottom buttons |
244
|
|
|
wOK = new Button(shell, SWT.PUSH); |
245
|
|
|
wOK.setText(BaseMessages.getString(PKG, "AnnotatorStep.Btn.OK")); //$NON-NLS-1$ |
246
|
|
|
wCancel = new Button(shell, SWT.PUSH); |
247
|
|
|
wCancel.setText(BaseMessages.getString(PKG, "AnnotatorStep.Btn.Cancel")); //$NON-NLS-1$ |
248
|
|
|
setButtonPositions(new Button[] { wOK, wCancel }, margin, wBrowse); |
249
|
|
|
|
250
|
|
|
wlShape = new Label(shell, SWT.RIGHT); |
251
|
|
|
wlShape.setText(BaseMessages.getString(PKG, "AnnotatorStep.MappingFile.Label")); |
252
|
|
|
props.setLook(wlShape); |
253
|
|
|
fdlShape = new FormData(); |
254
|
|
|
fdlShape.left = new FormAttachment(0, 0); |
255
|
|
|
fdlShape.top = new FormAttachment(wtNTriple, margin); |
256
|
|
|
fdlShape.right = new FormAttachment(middle, -margin); |
257
|
|
|
wlShape.setLayoutData(fdlShape); |
258
|
|
|
|
259
|
|
|
// Botoes para busca de arquivo |
260
|
|
|
wbBrowse = new Button(shell, SWT.PUSH | SWT.CENTER); |
261
|
|
|
props.setLook(wbBrowse); |
262
|
|
|
wbBrowse.setText(BaseMessages.getString(PKG, "AnnotatorStep.Btn.Browse")); |
263
|
|
|
fdbBrowse = new FormData(); |
264
|
|
|
fdbBrowse.right = new FormAttachment(100, 0); |
265
|
|
|
fdbBrowse.top = new FormAttachment(wtNTriple, margin); |
266
|
|
|
wbBrowse.setLayoutData(fdbBrowse); |
267
|
|
|
|
268
|
|
|
wBrowse = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
269
|
|
|
props.setLook(wBrowse); |
270
|
|
|
wBrowse.addModifyListener(lsMod); |
271
|
|
|
fdBrowse = new FormData(); |
272
|
|
|
fdBrowse.left = new FormAttachment(middle, 0); |
273
|
|
|
fdBrowse.right = new FormAttachment(wbBrowse, -margin); |
274
|
|
|
fdBrowse.top = new FormAttachment(wtNTriple, margin); |
275
|
|
|
wBrowse.setLayoutData(fdBrowse); |
276
|
|
|
|
277
|
|
|
// Add listeners |
278
|
|
|
lsCancel = new Listener() { |
279
|
|
|
public void handleEvent(Event e) { |
280
|
|
|
cancel(); |
281
|
|
|
} |
282
|
|
|
}; |
283
|
|
|
lsOK = new Listener() { |
284
|
|
|
public void handleEvent(Event e) { |
285
|
|
|
ok(); |
286
|
|
|
} |
287
|
|
|
}; |
288
|
|
|
|
289
|
|
|
wBrowse.addModifyListener(new ModifyListener() { |
290
|
|
|
public void modifyText(ModifyEvent arg0) { |
291
|
|
|
wBrowse.setToolTipText(transMeta.environmentSubstitute(wBrowse.getText())); |
292
|
|
|
} |
293
|
|
|
}); |
294
|
|
|
|
295
|
|
|
wbBrowse.addSelectionListener(new SelectionAdapter() { |
296
|
|
View Code Duplication |
public void widgetSelected(SelectionEvent e) { |
|
|
|
|
297
|
|
|
FileDialog dialog = new FileDialog(shell, SWT.OPEN); |
298
|
|
|
dialog.setFilterExtensions(new String[] { "*.xml;*.XML", "*" }); |
299
|
|
|
if (wBrowse.getText() != null) { |
300
|
|
|
dialog.setFileName(wBrowse.getText()); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
dialog.setFilterNames(new String[] { "Text files", "All files" }); |
304
|
|
|
|
305
|
|
|
if (dialog.open() != null) { |
306
|
|
|
String str = dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName(); |
307
|
|
|
wBrowse.setText(str); |
308
|
|
|
} |
309
|
|
|
} |
310
|
|
|
}); |
311
|
|
|
|
312
|
|
|
wCancel.addListener(SWT.Selection, lsCancel); |
313
|
|
|
wOK.addListener(SWT.Selection, lsOK); |
314
|
|
|
|
315
|
|
|
// It closes the window affirmatively when the user press enter in one |
316
|
|
|
// of the text input fields |
317
|
|
|
lsDef = new SelectionAdapter() { |
318
|
|
|
public void widgetDefaultSelected(SelectionEvent e) { |
319
|
|
|
ok(); |
320
|
|
|
} |
321
|
|
|
}; |
322
|
|
|
wStepname.addSelectionListener(lsDef); |
323
|
|
|
|
324
|
|
|
// Detect X or ALT-F4 or something that kills this window... |
325
|
|
|
shell.addShellListener(new ShellAdapter() { |
326
|
|
|
public void shellClosed(ShellEvent e) { |
327
|
|
|
cancel(); |
328
|
|
|
} |
329
|
|
|
}); |
330
|
|
|
|
331
|
|
|
// Populate the data of the controls |
332
|
|
|
getData(); |
333
|
|
|
|
334
|
|
|
// Set the shell size, based upon previous time... |
335
|
|
|
setSize(); |
336
|
|
|
|
337
|
|
|
// Alarga um pouco mais a janela |
338
|
|
|
Rectangle shellBounds = shell.getBounds(); |
339
|
|
|
shellBounds.width += 5; |
340
|
|
|
shellBounds.height += 5; |
341
|
|
|
shell.setBounds(shellBounds); |
342
|
|
|
|
343
|
|
|
input.setChanged(changed); |
344
|
|
|
|
345
|
|
|
shell.open(); |
346
|
|
|
while (!shell.isDisposed()) { |
347
|
|
|
if (!display.readAndDispatch()) |
348
|
|
|
display.sleep(); |
349
|
|
|
} |
350
|
|
|
return stepname; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
private void getData() { |
354
|
|
|
wStepname.selectAll(); |
355
|
|
|
|
356
|
|
|
wcSubject.setText(Const.NVL(input.getInputSubject(), "")); |
357
|
|
|
wcPredicate.setText(Const.NVL(input.getInputPredicate(), "")); |
358
|
|
|
wcObject.setText(Const.NVL(input.getInputObject(), "")); |
359
|
|
|
wtNTriple.setText(Const.NVL(input.getOutputNTriple(), "")); |
360
|
|
|
wBrowse.setText(input.getBrowseFilename()); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
protected void cancel() { |
364
|
|
|
stepname = null; |
365
|
|
|
input.setChanged(changed); |
366
|
|
|
dispose(); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
protected void ok() { |
370
|
|
|
if (StringUtil.isEmpty(wStepname.getText())) |
371
|
|
|
return; |
372
|
|
|
|
373
|
|
|
stepname = wStepname.getText(); // return value |
374
|
|
|
|
375
|
|
|
// Pegar dados da GUI e colocar no StepMeta |
376
|
|
|
input.setInputSubject(wcSubject.getText()); |
377
|
|
|
input.setInputPredicate(wcPredicate.getText()); |
378
|
|
|
input.setInputObject(wcObject.getText()); |
379
|
|
|
input.setOutputNTriple(wtNTriple.getText()); |
380
|
|
|
input.setBrowseFilename(wBrowse.getText()); |
381
|
|
|
|
382
|
|
|
// Fecha janela |
383
|
|
|
dispose(); |
384
|
|
|
} |
385
|
|
|
} |
386
|
|
|
|