|
1
|
|
|
package br.ufrj.ppgi.greco.kettle; |
|
2
|
|
|
|
|
3
|
|
|
import java.util.ArrayList; |
|
4
|
|
|
import java.util.List; |
|
5
|
|
|
|
|
6
|
|
|
import org.eclipse.swt.SWT; |
|
7
|
|
|
import org.eclipse.swt.events.ModifyEvent; |
|
8
|
|
|
import org.eclipse.swt.events.ModifyListener; |
|
9
|
|
|
import org.eclipse.swt.events.SelectionAdapter; |
|
10
|
|
|
import org.eclipse.swt.events.SelectionEvent; |
|
11
|
|
|
import org.eclipse.swt.events.SelectionListener; |
|
12
|
|
|
import org.eclipse.swt.events.ShellAdapter; |
|
13
|
|
|
import org.eclipse.swt.events.ShellEvent; |
|
14
|
|
|
import org.eclipse.swt.layout.FormAttachment; |
|
15
|
|
|
import org.eclipse.swt.layout.FormData; |
|
16
|
|
|
import org.eclipse.swt.layout.FormLayout; |
|
17
|
|
|
import org.eclipse.swt.widgets.Button; |
|
18
|
|
|
import org.eclipse.swt.widgets.Control; |
|
19
|
|
|
import org.eclipse.swt.widgets.Display; |
|
20
|
|
|
import org.eclipse.swt.widgets.Event; |
|
21
|
|
|
import org.eclipse.swt.widgets.Group; |
|
22
|
|
|
import org.eclipse.swt.widgets.Label; |
|
23
|
|
|
import org.eclipse.swt.widgets.Listener; |
|
24
|
|
|
import org.eclipse.swt.widgets.Shell; |
|
25
|
|
|
import org.eclipse.swt.widgets.Text; |
|
26
|
|
|
import org.pentaho.di.core.Const; |
|
27
|
|
|
import org.pentaho.di.core.exception.KettleStepException; |
|
28
|
|
|
import org.pentaho.di.core.row.RowMetaInterface; |
|
29
|
|
|
import org.pentaho.di.core.row.ValueMetaInterface; |
|
30
|
|
|
import org.pentaho.di.core.util.StringUtil; |
|
31
|
|
|
import org.pentaho.di.i18n.BaseMessages; |
|
32
|
|
|
import org.pentaho.di.trans.TransMeta; |
|
33
|
|
|
import org.pentaho.di.trans.step.BaseStepMeta; |
|
34
|
|
|
import org.pentaho.di.trans.step.StepDialogInterface; |
|
35
|
|
|
import org.pentaho.di.ui.core.widget.ComboVar; |
|
36
|
|
|
import org.pentaho.di.ui.core.widget.TextVar; |
|
37
|
|
|
import org.pentaho.di.ui.trans.step.BaseStepDialog; |
|
38
|
|
|
|
|
39
|
|
|
import br.ufrj.ppgi.greco.kettle.plugin.tools.swthelper.SwtHelper; |
|
40
|
|
|
|
|
41
|
|
|
public class SparqlUpdateInsertStepDialog extends BaseStepDialog implements StepDialogInterface { |
|
42
|
|
|
|
|
43
|
|
|
private static Class<?> PKG = SparqlUpdateInsertStepMeta.class; |
|
44
|
|
|
|
|
45
|
|
|
private SparqlUpdateInsertStepMeta input; |
|
46
|
|
|
private SwtHelper swthlp; |
|
47
|
|
|
private String dialogTitle; |
|
48
|
|
|
|
|
49
|
|
|
private TextVar wGraphUri; |
|
50
|
|
|
private ComboVar wRdfFieldName; |
|
51
|
|
|
private Button wClearGraph; |
|
52
|
|
|
private TextVar wEndpointUrl; |
|
53
|
|
|
private TextVar wUserName; |
|
54
|
|
|
private TextVar wPassword; |
|
55
|
|
|
private TextVar wStatusCode; |
|
56
|
|
|
private TextVar wStatusMsg; |
|
57
|
|
|
|
|
58
|
|
|
public SparqlUpdateInsertStepDialog(Shell parent, Object stepMeta, TransMeta transMeta, String stepname) { |
|
59
|
|
|
super(parent, (BaseStepMeta) stepMeta, transMeta, stepname); |
|
60
|
|
|
|
|
61
|
|
|
input = (SparqlUpdateInsertStepMeta) baseStepMeta; |
|
62
|
|
|
swthlp = new SwtHelper(transMeta, this.props); |
|
63
|
|
|
|
|
64
|
|
|
dialogTitle = BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Title"); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public String open() { |
|
68
|
|
|
Shell parent = getParent(); |
|
69
|
|
|
Display display = parent.getDisplay(); |
|
70
|
|
|
|
|
71
|
|
|
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX); |
|
72
|
|
|
props.setLook(shell); |
|
73
|
|
|
setShellImage(shell, input); |
|
74
|
|
|
|
|
75
|
|
|
ModifyListener lsMod = new ModifyListener() { |
|
76
|
|
|
|
|
77
|
|
|
public void modifyText(ModifyEvent e) { |
|
78
|
|
|
// TODO Auto-generated method stub |
|
79
|
|
|
input.setChanged(); |
|
80
|
|
|
} |
|
81
|
|
|
}; |
|
82
|
|
|
boolean changed = input.hasChanged(); |
|
83
|
|
|
|
|
84
|
|
|
FormLayout formLayout = new FormLayout(); |
|
85
|
|
|
formLayout.marginWidth = Const.FORM_MARGIN; |
|
86
|
|
|
formLayout.marginHeight = Const.FORM_MARGIN; |
|
87
|
|
|
|
|
88
|
|
|
shell.setLayout(formLayout); |
|
89
|
|
|
|
|
90
|
|
|
shell.setText(this.dialogTitle); |
|
91
|
|
|
|
|
92
|
|
|
int middle = props.getMiddlePct(); |
|
93
|
|
|
int margin = Const.MARGIN; |
|
94
|
|
|
|
|
95
|
|
|
// Adiciona um label e um input text no topo do dialog shell |
|
96
|
|
|
wlStepname = new Label(shell, SWT.RIGHT); |
|
97
|
|
|
wlStepname.setText(BaseMessages.getString(PKG, "SparqlUpdateOutputStep.StepNameField.Label")); |
|
98
|
|
|
props.setLook(wlStepname); |
|
99
|
|
|
|
|
100
|
|
|
fdlStepname = new FormData(); |
|
101
|
|
|
fdlStepname.left = new FormAttachment(0, 0); |
|
102
|
|
|
fdlStepname.right = new FormAttachment(middle, -margin); |
|
103
|
|
|
fdlStepname.top = new FormAttachment(0, margin); |
|
104
|
|
|
wlStepname.setLayoutData(fdlStepname); |
|
105
|
|
|
|
|
106
|
|
|
wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
|
107
|
|
|
wStepname.setText(stepname); |
|
108
|
|
|
props.setLook(wStepname); |
|
109
|
|
|
|
|
110
|
|
|
wStepname.addModifyListener(lsMod); |
|
111
|
|
|
fdStepname = new FormData(); |
|
112
|
|
|
fdStepname.left = new FormAttachment(middle, 0); |
|
113
|
|
|
fdStepname.top = new FormAttachment(0, margin); |
|
114
|
|
|
fdStepname.right = new FormAttachment(100, 0); |
|
115
|
|
|
wStepname.setLayoutData(fdStepname); |
|
116
|
|
|
Control lastControl = wStepname; |
|
117
|
|
|
|
|
118
|
|
|
// Adiciona |
|
119
|
|
|
Group wGroup1 = swthlp.appendGroup(shell, lastControl, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Graph")); |
|
120
|
|
|
{ |
|
121
|
|
|
wRdfFieldName = swthlp.appendComboVarRow(wGroup1, null, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Graph.NTriples"), lsMod); |
|
122
|
|
|
wRdfFieldName.setItems(this.getFields(ValueMetaInterface.TYPE_STRING)); |
|
123
|
|
|
wGraphUri = swthlp.appendTextVarRow(wGroup1, wRdfFieldName, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Graph.URI"), lsMod); |
|
124
|
|
|
wClearGraph = swthlp.appendCheckboxRow(wGroup1, wGraphUri, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Graph.Drop"), |
|
125
|
|
|
new SelectionListener() { |
|
126
|
|
|
|
|
127
|
|
|
public void widgetSelected(SelectionEvent arg0) { |
|
128
|
|
|
input.setChanged(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public void widgetDefaultSelected(SelectionEvent arg0) { |
|
132
|
|
|
input.setChanged(); |
|
133
|
|
|
} |
|
134
|
|
|
}); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
Group wGroup2 = swthlp.appendGroup(shell, wGroup1, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Connection")); |
|
138
|
|
|
{ |
|
139
|
|
|
wEndpointUrl = swthlp.appendTextVarRow(wGroup2, null, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Connection.Endpoint"), lsMod); |
|
140
|
|
|
|
|
141
|
|
|
wUserName = swthlp.appendTextVarRow(wGroup2, wEndpointUrl, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Connection.User"), lsMod); |
|
142
|
|
|
|
|
143
|
|
|
wPassword = swthlp.appendTextVarRow(wGroup2, wUserName, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Connection.Password"), lsMod, true); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
Group wGroup3 = swthlp.appendGroup(shell, wGroup2, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Output")); |
|
147
|
|
|
{ |
|
148
|
|
|
wStatusCode = swthlp.appendTextVarRow(wGroup3, null, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Output.StatusCode"), lsMod); |
|
149
|
|
|
wStatusMsg = swthlp.appendTextVarRow(wGroup3, wStatusCode, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Output.StatusMessage"), lsMod); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
lastControl = wGroup3; |
|
153
|
|
|
|
|
154
|
|
|
// Some buttons |
|
155
|
|
|
wOK = new Button(shell, SWT.PUSH); |
|
156
|
|
|
wOK.setText(BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Btn.OK")); //$NON-NLS-1$ |
|
157
|
|
|
wCancel = new Button(shell, SWT.PUSH); |
|
158
|
|
|
wCancel.setText(BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Btn.Cancel")); //$NON-NLS-1$ |
|
159
|
|
|
|
|
160
|
|
|
setButtonPositions(new Button[] { wOK, wCancel }, margin, lastControl); |
|
161
|
|
|
|
|
162
|
|
|
// Add listeners |
|
163
|
|
|
lsCancel = new Listener() { |
|
164
|
|
|
public void handleEvent(Event e) { |
|
165
|
|
|
cancel(); |
|
166
|
|
|
} |
|
167
|
|
|
}; |
|
168
|
|
|
lsOK = new Listener() { |
|
169
|
|
|
public void handleEvent(Event e) { |
|
170
|
|
|
ok(); |
|
171
|
|
|
} |
|
172
|
|
|
}; |
|
173
|
|
|
|
|
174
|
|
|
wCancel.addListener(SWT.Selection, lsCancel); |
|
175
|
|
|
wOK.addListener(SWT.Selection, lsOK); |
|
176
|
|
|
|
|
177
|
|
|
lsDef = new SelectionAdapter() { |
|
178
|
|
|
public void widgetDefaultSelected(SelectionEvent e) { |
|
179
|
|
|
ok(); |
|
180
|
|
|
} |
|
181
|
|
|
}; |
|
182
|
|
|
|
|
183
|
|
|
wStepname.addSelectionListener(lsDef); |
|
184
|
|
|
wRdfFieldName.addSelectionListener(lsDef); |
|
185
|
|
|
wGraphUri.addSelectionListener(lsDef); |
|
186
|
|
|
wEndpointUrl.addSelectionListener(lsDef); |
|
187
|
|
|
wUserName.addSelectionListener(lsDef); |
|
188
|
|
|
wPassword.addSelectionListener(lsDef); |
|
189
|
|
|
|
|
190
|
|
|
// Detect X or ALT-F4 or something that kills this window... |
|
191
|
|
|
shell.addShellListener(new ShellAdapter() { |
|
192
|
|
|
public void shellClosed(ShellEvent e) { |
|
193
|
|
|
cancel(); |
|
194
|
|
|
} |
|
195
|
|
|
}); |
|
196
|
|
|
|
|
197
|
|
|
// Populate the data of the controls |
|
198
|
|
|
getData(); |
|
199
|
|
|
|
|
200
|
|
|
// Set the shell size, based upon previous time... |
|
201
|
|
|
setSize(); |
|
202
|
|
|
|
|
203
|
|
|
input.setChanged(changed); |
|
204
|
|
|
|
|
205
|
|
|
shell.open(); |
|
206
|
|
|
while (!shell.isDisposed()) { |
|
207
|
|
|
if (!display.readAndDispatch()) |
|
208
|
|
|
display.sleep(); |
|
209
|
|
|
} |
|
210
|
|
|
return stepname; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
private void getData() { |
|
214
|
|
|
wStepname.selectAll(); |
|
215
|
|
|
|
|
216
|
|
|
try { |
|
217
|
|
|
wRdfFieldName.setText(Const.NVL(input.getRdfContentFieldName(), "")); |
|
218
|
|
|
wGraphUri.setText(Const.NVL(input.getGraphUriValue(), "")); |
|
219
|
|
|
wClearGraph.setSelection(input.getClearGraph()); |
|
220
|
|
|
wEndpointUrl.setText(Const.NVL(input.getEndpointUrl(), "")); |
|
221
|
|
|
wUserName.setText(Const.NVL(input.getUsername(), "")); |
|
222
|
|
|
wPassword.setText(Const.NVL(input.getPassword(), "")); |
|
223
|
|
|
wStatusCode.setText(Const.NVL(input.getResultCodeFieldName(), "")); |
|
224
|
|
|
wStatusMsg.setText(Const.NVL(input.getResultMessageFieldName(), "")); |
|
225
|
|
|
} catch (NullPointerException e) { |
|
226
|
|
|
|
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
protected void cancel() { |
|
231
|
|
|
stepname = null; |
|
232
|
|
|
input.setChanged(changed); |
|
233
|
|
|
dispose(); |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
protected void ok() { |
|
237
|
|
|
if (StringUtil.isEmpty(wStepname.getText())) |
|
238
|
|
|
return; |
|
239
|
|
|
|
|
240
|
|
|
stepname = wStepname.getText(); // return value |
|
241
|
|
|
|
|
242
|
|
|
try { |
|
243
|
|
|
input.setRdfContentFieldName(wRdfFieldName.getText()); |
|
244
|
|
|
input.setGraphUriValue(wGraphUri.getText()); |
|
245
|
|
|
input.setClearGraph(wClearGraph.getSelection()); |
|
246
|
|
|
input.setEndpointUrl(wEndpointUrl.getText()); |
|
247
|
|
|
input.setUsername(wUserName.getText()); |
|
248
|
|
|
input.setPassword(wPassword.getText()); |
|
249
|
|
|
input.setResultCodeFieldName(wStatusCode.getText()); |
|
250
|
|
|
input.setResultMessageFieldName(wStatusMsg.getText()); |
|
251
|
|
|
} catch (NullPointerException e) { |
|
252
|
|
|
|
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
dispose(); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
View Code Duplication |
private String[] getFields(int type) { |
|
|
|
|
|
|
259
|
|
|
|
|
260
|
|
|
List<String> result = new ArrayList<String>(); |
|
261
|
|
|
|
|
262
|
|
|
try { |
|
263
|
|
|
RowMetaInterface inRowMeta = this.transMeta.getPrevStepFields(stepname); |
|
264
|
|
|
|
|
265
|
|
|
List<ValueMetaInterface> fields = inRowMeta.getValueMetaList(); |
|
266
|
|
|
|
|
267
|
|
|
for (ValueMetaInterface field : fields) { |
|
268
|
|
|
if (field.getType() == type || type == -1) |
|
269
|
|
|
result.add(field.getName()); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
} catch (KettleStepException e) { |
|
273
|
|
|
e.printStackTrace(); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
return result.toArray(new String[result.size()]); |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
|