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