|
1
|
|
|
package br.ufrj.ppgi.greco.kettle; |
|
2
|
|
|
|
|
3
|
|
|
import org.apache.jena.riot.Lang; |
|
4
|
|
|
import org.apache.jena.riot.RDFLanguages; |
|
5
|
|
|
import org.eclipse.swt.SWT; |
|
6
|
|
|
import org.eclipse.swt.custom.CTabFolder; |
|
7
|
|
|
import org.eclipse.swt.custom.CTabItem; |
|
8
|
|
|
import org.eclipse.swt.events.ModifyEvent; |
|
9
|
|
|
import org.eclipse.swt.events.ModifyListener; |
|
10
|
|
|
import org.eclipse.swt.events.SelectionAdapter; |
|
11
|
|
|
import org.eclipse.swt.events.SelectionEvent; |
|
12
|
|
|
import org.eclipse.swt.events.SelectionListener; |
|
13
|
|
|
import org.eclipse.swt.events.ShellAdapter; |
|
14
|
|
|
import org.eclipse.swt.events.ShellEvent; |
|
15
|
|
|
import org.eclipse.swt.layout.FormAttachment; |
|
16
|
|
|
import org.eclipse.swt.layout.FormData; |
|
17
|
|
|
import org.eclipse.swt.layout.FormLayout; |
|
18
|
|
|
import org.eclipse.swt.widgets.Button; |
|
19
|
|
|
import org.eclipse.swt.widgets.Composite; |
|
20
|
|
|
import org.eclipse.swt.widgets.Control; |
|
21
|
|
|
import org.eclipse.swt.widgets.Display; |
|
22
|
|
|
import org.eclipse.swt.widgets.Event; |
|
23
|
|
|
import org.eclipse.swt.widgets.FileDialog; |
|
24
|
|
|
import org.eclipse.swt.widgets.Label; |
|
25
|
|
|
import org.eclipse.swt.widgets.Listener; |
|
26
|
|
|
import org.eclipse.swt.widgets.MessageBox; |
|
27
|
|
|
import org.eclipse.swt.widgets.Shell; |
|
28
|
|
|
import org.eclipse.swt.widgets.Text; |
|
29
|
|
|
import org.pentaho.di.core.Const; |
|
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.ui.core.widget.ColumnInfo; |
|
34
|
|
|
import org.pentaho.di.ui.core.widget.TableView; |
|
35
|
|
|
import org.pentaho.di.ui.core.widget.TextVar; |
|
36
|
|
|
import org.pentaho.di.ui.trans.step.BaseStepDialog; |
|
37
|
|
|
|
|
38
|
|
|
import org.apache.jena.ontology.OntClass; |
|
39
|
|
|
import org.apache.jena.ontology.OntModelSpec; |
|
40
|
|
|
import org.apache.jena.ontology.OntProperty; |
|
41
|
|
|
import org.apache.jena.rdf.model.ModelFactory; |
|
42
|
|
|
|
|
43
|
|
|
import br.ufrj.ppgi.greco.kettle.owlutils.LOVApiV2; |
|
44
|
|
|
import br.ufrj.ppgi.greco.kettle.owlutils.LOVAttributes; |
|
45
|
|
|
import br.ufrj.ppgi.greco.kettle.plugin.tools.datatable.DataTable; |
|
46
|
|
|
import br.ufrj.ppgi.greco.kettle.plugin.tools.swthelper.SwtHelper; |
|
47
|
|
|
|
|
48
|
|
|
import org.pentaho.di.trans.step.BaseStepMeta; |
|
49
|
|
|
import org.pentaho.di.trans.step.StepDialogInterface; |
|
50
|
|
|
|
|
51
|
|
|
import java.io.File; |
|
52
|
|
|
import java.nio.file.Paths; |
|
53
|
|
|
import java.util.ArrayList; |
|
54
|
|
|
import java.util.Collection; |
|
55
|
|
|
import java.util.Iterator; |
|
56
|
|
|
import java.util.List; |
|
57
|
|
|
import java.util.logging.Level; |
|
58
|
|
|
import java.util.regex.Pattern; |
|
59
|
|
|
import java.util.logging.*; |
|
60
|
|
|
|
|
61
|
|
|
public class OwlInputStepDialog extends BaseStepDialog implements StepDialogInterface { |
|
62
|
|
|
|
|
63
|
|
|
private static Class<?> PKG = OwlInputStepMeta.class; |
|
64
|
|
|
|
|
65
|
|
|
private OwlInputStepMeta meta; |
|
66
|
|
|
|
|
67
|
|
|
private static final Logger log = Logger.getLogger(OwlInputStep.class.getName()); |
|
68
|
|
|
|
|
69
|
|
|
private String dialogTitle; |
|
70
|
|
|
private TextVar wHelloFieldName; |
|
71
|
|
|
private TableView wTable; |
|
72
|
|
|
private TableView wVocabTable; |
|
73
|
|
|
|
|
74
|
|
|
private Button wKeepInputFields; |
|
75
|
|
|
private TextVar wOntologyOutputFieldName; |
|
76
|
|
|
private TextVar wURIOutputFieldName; |
|
77
|
|
|
|
|
78
|
|
|
private SwtHelper swthlp; |
|
79
|
|
|
|
|
80
|
|
|
public OwlInputStepDialog(Shell parent, Object in, TransMeta transMeta, String sname) { |
|
81
|
|
|
super(parent, (BaseStepMeta) in, transMeta, sname); |
|
82
|
|
|
meta = (OwlInputStepMeta) in; |
|
83
|
|
|
swthlp = new SwtHelper(transMeta, this.props); |
|
84
|
|
|
|
|
85
|
|
|
dialogTitle = BaseMessages.getString(PKG, "OwlInputStep.Title"); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
private Control buildContents(Control lastControl, ModifyListener defModListener) { |
|
89
|
|
|
CTabFolder wTabFolder = swthlp.appendTabFolder(shell, lastControl, 90); |
|
90
|
|
|
CTabItem item = new CTabItem(wTabFolder, SWT.NONE); |
|
91
|
|
|
item.setText(BaseMessages.getString(PKG, "OwlInputStep.Tab.Owl")); |
|
92
|
|
|
Composite cpt = swthlp.appendComposite(wTabFolder, lastControl); |
|
93
|
|
|
wHelloFieldName = swthlp.appendTextVarRow(cpt, null, BaseMessages.getString(PKG, "OwlInputStep.Tab.Owl.Input"), defModListener); |
|
94
|
|
|
Composite btnRow = swthlp.appendButtonsRow(cpt, wHelloFieldName, |
|
95
|
|
|
new String[] { BaseMessages.getString(PKG, "OwlInputStep.Tab.Owl.Add"), BaseMessages.getString(PKG, "OwlInputStep.Tab.Owl.Openfile") }, new SelectionListener[] { new SelectionListener() { |
|
96
|
|
|
public void widgetSelected(SelectionEvent arg0) { |
|
97
|
|
|
widgetDefaultSelected(arg0); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public void widgetDefaultSelected(SelectionEvent arg0) { |
|
101
|
|
|
addUri(); |
|
102
|
|
|
meta.setChanged(true); |
|
103
|
|
|
} |
|
104
|
|
|
}, new SelectionListener() { |
|
105
|
|
|
public void widgetSelected(SelectionEvent arg0) { |
|
106
|
|
|
widgetDefaultSelected(arg0); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public void widgetDefaultSelected(SelectionEvent arg0) { |
|
110
|
|
|
loadFile(); |
|
111
|
|
|
meta.setChanged(true); |
|
112
|
|
|
} |
|
113
|
|
|
} }); |
|
114
|
|
|
ColumnInfo[] columns = new ColumnInfo[] { |
|
115
|
|
|
new ColumnInfo(BaseMessages.getString(PKG, "OwlInputStep.Tab.Owl.ColumnA"), ColumnInfo.COLUMN_TYPE_TEXT), |
|
116
|
|
|
new ColumnInfo(BaseMessages.getString(PKG, "OwlInputStep.Tab.Owl.ColumnB"), ColumnInfo.COLUMN_TYPE_TEXT), |
|
117
|
|
|
new ColumnInfo(BaseMessages.getString(PKG, "OwlInputStep.Tab.Owl.ColumnC"), ColumnInfo.COLUMN_TYPE_TEXT) }; |
|
118
|
|
|
wTable = swthlp.appendTableView(cpt, btnRow, columns, defModListener, 98); |
|
119
|
|
|
item.setControl(cpt); |
|
120
|
|
|
|
|
121
|
|
|
item = new CTabItem(wTabFolder, SWT.NONE); |
|
122
|
|
|
item.setText(BaseMessages.getString(PKG, "OwlInputStep.Tab.Select")); |
|
123
|
|
|
cpt = swthlp.appendComposite(wTabFolder, lastControl); |
|
124
|
|
|
Composite vocabBtn = swthlp.appendButtonsRow(cpt, wHelloFieldName, |
|
125
|
|
|
new String[] { BaseMessages.getString(PKG, "OwlInputStep.Tab.Select.Load"), BaseMessages.getString(PKG, "OwlInputStep.Tab.Select.Clear") }, new SelectionListener[] { new SelectionListener() { |
|
126
|
|
|
public void widgetSelected(SelectionEvent arg0) { |
|
127
|
|
|
widgetDefaultSelected(arg0); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public void widgetDefaultSelected(SelectionEvent arg0) { |
|
131
|
|
|
load(); |
|
132
|
|
|
meta.setChanged(true); |
|
133
|
|
|
} |
|
134
|
|
|
}, new SelectionListener() { |
|
135
|
|
|
public void widgetSelected(SelectionEvent arg0) { |
|
136
|
|
|
widgetDefaultSelected(arg0); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public void widgetDefaultSelected(SelectionEvent arg0) { |
|
140
|
|
|
wVocabTable.clearAll(); |
|
141
|
|
|
meta.setChanged(true); |
|
142
|
|
|
} |
|
143
|
|
|
} }); |
|
144
|
|
|
columns = new ColumnInfo[] { |
|
145
|
|
|
new ColumnInfo(BaseMessages.getString(PKG, "OwlInputStep.Tab.Select.ColumnA"), ColumnInfo.COLUMN_TYPE_TEXT), |
|
146
|
|
|
new ColumnInfo(BaseMessages.getString(PKG, "OwlInputStep.Tab.Select.ColumnB"), ColumnInfo.COLUMN_TYPE_TEXT), |
|
147
|
|
|
new ColumnInfo(BaseMessages.getString(PKG, "OwlInputStep.Tab.Select.ColumnC"), ColumnInfo.COLUMN_TYPE_TEXT), |
|
148
|
|
|
new ColumnInfo(BaseMessages.getString(PKG, "OwlInputStep.Tab.Select.ColumnD"), ColumnInfo.COLUMN_TYPE_TEXT) }; |
|
149
|
|
|
wVocabTable = swthlp.appendTableView(cpt, vocabBtn, columns, defModListener, 98); |
|
150
|
|
|
item.setControl(cpt); |
|
151
|
|
|
|
|
152
|
|
|
item = new CTabItem(wTabFolder, SWT.NONE); |
|
153
|
|
|
item.setText(BaseMessages.getString(PKG, "OwlInputStep.Tab.Output")); |
|
154
|
|
|
cpt = swthlp.appendComposite(wTabFolder, lastControl); |
|
155
|
|
|
wKeepInputFields = swthlp.appendCheckboxRow(cpt, null, BaseMessages.getString(PKG, "OwlInputStep.Tab.Output.KeepInputFields"), |
|
156
|
|
|
new SelectionListener() { |
|
157
|
|
|
public void widgetDefaultSelected(SelectionEvent arg0) { |
|
158
|
|
|
widgetSelected(arg0); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
public void widgetSelected(SelectionEvent e) { |
|
162
|
|
|
meta.setChanged(true); |
|
163
|
|
|
} |
|
164
|
|
|
}); |
|
165
|
|
|
wOntologyOutputFieldName = swthlp.appendTextVarRow(cpt, wKeepInputFields, BaseMessages.getString(PKG, "OwlInputStep.Tab.Output.PrefixField"), defModListener); |
|
166
|
|
|
wURIOutputFieldName = swthlp.appendTextVarRow(cpt, wOntologyOutputFieldName, BaseMessages.getString(PKG, "OwlInputStep.Tab.Output.VocabularyField"), defModListener); |
|
167
|
|
|
item.setControl(cpt); |
|
168
|
|
|
|
|
169
|
|
|
wTabFolder.setSelection(0); |
|
170
|
|
|
return wTabFolder; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
private void load(){ |
|
174
|
|
|
wVocabTable.clearAll(); |
|
175
|
|
|
|
|
176
|
|
|
for (int k = 0; k < wTable.getItemCount(); k++) { |
|
177
|
|
|
String ontoField = wTable.getItem(k, 1); |
|
178
|
|
|
String owlFile = getOwlFile(wTable.getItem(k, 2)); |
|
179
|
|
|
try { |
|
180
|
|
|
meta.model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); |
|
181
|
|
|
meta.model.read(owlFile); |
|
182
|
|
|
} catch (Exception eox) { |
|
183
|
|
|
Collection<Lang> registeredLanguages = RDFLanguages.getRegisteredLanguages(); |
|
184
|
|
|
for (Lang c : registeredLanguages) { |
|
185
|
|
|
try { |
|
186
|
|
|
meta.model.read(owlFile, c.getName()); |
|
187
|
|
|
break; |
|
188
|
|
|
} catch (Exception e) { |
|
189
|
|
|
this.logBasic("File could not be read as " + c.getName() + ": " + e.getMessage()); |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
if (!meta.model.isEmpty()) { |
|
195
|
|
|
for (Iterator<OntClass> i = meta.model.listClasses(); i.hasNext();) { |
|
196
|
|
|
OntClass cls = i.next(); |
|
197
|
|
|
if (cls.getLocalName() != null) { |
|
198
|
|
|
this.insertRow(wVocabTable, new String[] {ontoField.trim(), cls.getURI(), "rdf:type", "rdfs:class"}); |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
for (Iterator<OntProperty> j = meta.model.listAllOntProperties(); j.hasNext();) { |
|
203
|
|
|
OntProperty proper = j.next(); |
|
204
|
|
|
if (proper.getLocalName() != null) { |
|
205
|
|
|
this.insertRow(wVocabTable, new String[] {ontoField.trim(), proper.getURI(), "rdf:type", "rdfs:property"}); |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Verifies whether src is an actual file or and URI. |
|
214
|
|
|
* If the String src is a file, return it's valid path |
|
215
|
|
|
* else return the URI |
|
216
|
|
|
* |
|
217
|
|
|
* @param src the original file path |
|
218
|
|
|
* @return a valid file path or an URI |
|
219
|
|
|
*/ |
|
220
|
|
|
private String getOwlFile(String src) { |
|
221
|
|
|
File file = new File(src); |
|
222
|
|
|
if (!file.isDirectory()){ |
|
223
|
|
|
file = file.getParentFile(); |
|
224
|
|
|
} |
|
225
|
|
|
if (file.exists()){ |
|
226
|
|
|
return Paths.get(src).toUri().toString(); |
|
227
|
|
|
}else { |
|
228
|
|
|
return src; |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
|
|
233
|
|
|
// The will close the window affirmatively when the user press Enter in one |
|
234
|
|
|
// of these text input fields |
|
235
|
|
|
private void addSelectionListenerToControls(SelectionAdapter lsDef) { |
|
236
|
|
|
wOntologyOutputFieldName.addSelectionListener(lsDef); |
|
237
|
|
|
wURIOutputFieldName.addSelectionListener(lsDef); |
|
238
|
|
|
wHelloFieldName.addSelectionListener(lsDef); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
public String open() { |
|
242
|
|
|
|
|
243
|
|
|
Shell parent = getParent(); |
|
244
|
|
|
Display display = parent.getDisplay(); |
|
245
|
|
|
|
|
246
|
|
|
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX); |
|
247
|
|
|
props.setLook(shell); |
|
248
|
|
|
setShellImage(shell, meta); |
|
249
|
|
|
|
|
250
|
|
|
ModifyListener lsMod = new ModifyListener() { |
|
251
|
|
|
|
|
252
|
|
|
public void modifyText(ModifyEvent e) { |
|
253
|
|
|
meta.setChanged(); |
|
254
|
|
|
} |
|
255
|
|
|
}; |
|
256
|
|
|
|
|
257
|
|
|
changed = meta.hasChanged(); |
|
258
|
|
|
|
|
259
|
|
|
FormLayout formLayout = new FormLayout(); |
|
260
|
|
|
formLayout.marginWidth = Const.FORM_MARGIN; |
|
261
|
|
|
formLayout.marginHeight = Const.FORM_MARGIN; |
|
262
|
|
|
|
|
263
|
|
|
shell.setLayout(formLayout); |
|
264
|
|
|
|
|
265
|
|
|
shell.setText(this.dialogTitle); |
|
266
|
|
|
|
|
267
|
|
|
int middle = props.getMiddlePct(); |
|
268
|
|
|
int margin = Const.MARGIN; |
|
269
|
|
|
|
|
270
|
|
|
wlStepname = new Label(shell, SWT.RIGHT); |
|
271
|
|
|
wlStepname.setText(BaseMessages.getString(PKG, "OwlInputStep.StepNameField.Label")); |
|
272
|
|
|
props.setLook(wlStepname); |
|
273
|
|
|
|
|
274
|
|
|
fdlStepname = new FormData(); |
|
275
|
|
|
fdlStepname.left = new FormAttachment(0, 0); |
|
276
|
|
|
fdlStepname.top = new FormAttachment(0, margin); |
|
277
|
|
|
fdlStepname.right = new FormAttachment(middle, -margin); |
|
278
|
|
|
wlStepname.setLayoutData(fdlStepname); |
|
279
|
|
|
|
|
280
|
|
|
wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
|
281
|
|
|
wStepname.setText(stepname); |
|
282
|
|
|
props.setLook(wStepname); |
|
283
|
|
|
|
|
284
|
|
|
wStepname.addModifyListener(lsMod); |
|
285
|
|
|
fdStepname = new FormData(); |
|
286
|
|
|
fdStepname.left = new FormAttachment(middle, 0); |
|
287
|
|
|
fdStepname.top = new FormAttachment(0, margin); |
|
288
|
|
|
fdStepname.right = new FormAttachment(100, 0); |
|
289
|
|
|
wStepname.setLayoutData(fdStepname); |
|
290
|
|
|
Control lastControl = wStepname; |
|
291
|
|
|
|
|
292
|
|
|
lastControl = buildContents(lastControl, lsMod); |
|
293
|
|
|
|
|
294
|
|
|
wOK = new Button(shell, SWT.PUSH); |
|
295
|
|
|
wOK.setText(BaseMessages.getString(PKG, "OwlInputStep.Btn.OK")); |
|
296
|
|
|
wCancel = new Button(shell, SWT.PUSH); |
|
297
|
|
|
wCancel.setText(BaseMessages.getString(PKG, "OwlInputStep.Btn.Cancel")); |
|
298
|
|
|
setButtonPositions(new Button[] { wOK, wCancel }, margin, lastControl); |
|
299
|
|
|
|
|
300
|
|
|
lsCancel = new Listener() { |
|
301
|
|
|
public void handleEvent(Event e) { |
|
302
|
|
|
cancel(); |
|
303
|
|
|
} |
|
304
|
|
|
}; |
|
305
|
|
|
lsOK = new Listener() { |
|
306
|
|
|
public void handleEvent(Event e) { |
|
307
|
|
|
ok(); |
|
308
|
|
|
} |
|
309
|
|
|
}; |
|
310
|
|
|
|
|
311
|
|
|
wCancel.addListener(SWT.Selection, lsCancel); |
|
312
|
|
|
wOK.addListener(SWT.Selection, lsOK); |
|
313
|
|
|
|
|
314
|
|
|
lsDef = new SelectionAdapter() { |
|
315
|
|
|
public void widgetDefaultSelected(SelectionEvent e) { |
|
316
|
|
|
ok(); |
|
317
|
|
|
} |
|
318
|
|
|
}; |
|
319
|
|
|
|
|
320
|
|
|
wStepname.addSelectionListener(lsDef); |
|
321
|
|
|
addSelectionListenerToControls(lsDef); |
|
322
|
|
|
|
|
323
|
|
|
shell.addShellListener(new ShellAdapter() { |
|
324
|
|
|
public void shellClosed(ShellEvent e) { |
|
325
|
|
|
cancel(); |
|
326
|
|
|
} |
|
327
|
|
|
}); |
|
328
|
|
|
|
|
329
|
|
|
setSize(); |
|
330
|
|
|
|
|
331
|
|
|
populateDialog(); |
|
332
|
|
|
|
|
333
|
|
|
meta.setChanged(changed); |
|
334
|
|
|
|
|
335
|
|
|
shell.open(); |
|
336
|
|
|
while (!shell.isDisposed()) { |
|
337
|
|
|
if (!display.readAndDispatch()) |
|
338
|
|
|
display.sleep(); |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
return stepname; |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
private void populateDialog() { |
|
345
|
|
|
wStepname.selectAll(); |
|
346
|
|
|
DataTable<String> dtable = meta.getMapTable(); |
|
347
|
|
|
DataTable<String>.RowFactory rf = getRowFactoryRead(dtable); |
|
348
|
|
|
for (int i = 0; i < dtable.size(); i++) { |
|
349
|
|
|
wTable.add(dtable.getRowRange(i, rf).getRow()); |
|
350
|
|
|
} |
|
351
|
|
|
wTable.remove(0); |
|
352
|
|
|
meta.setMapTable(dtable); |
|
353
|
|
|
|
|
354
|
|
|
dtable = meta.getVocabTable(); |
|
355
|
|
|
rf = getRowFactoryRead(dtable); |
|
356
|
|
|
for (int i = 0; i < dtable.size(); i++) { |
|
357
|
|
|
wVocabTable.add(dtable.getRowRange(i, rf).getRow()); |
|
358
|
|
|
} |
|
359
|
|
|
wVocabTable.remove(0); |
|
360
|
|
|
meta.setVocabTable(dtable); |
|
361
|
|
|
|
|
362
|
|
|
wKeepInputFields.setSelection(meta.isKeepInputFields()); |
|
363
|
|
|
wOntologyOutputFieldName.setText(Const.NVL(meta.getOntologyOutputFieldName(), "")); |
|
364
|
|
|
wURIOutputFieldName.setText(Const.NVL(meta.getUriOutputFieldName(), "")); |
|
365
|
|
|
|
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
private void cancel() { |
|
369
|
|
|
stepname = null; |
|
370
|
|
|
meta.setChanged(changed); |
|
371
|
|
|
dispose(); |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
private void ok() { |
|
375
|
|
|
if (StringUtil.isEmpty(wStepname.getText())) |
|
376
|
|
|
return; |
|
377
|
|
|
|
|
378
|
|
|
stepname = wStepname.getText(); |
|
379
|
|
|
|
|
380
|
|
|
DataTable<String> table = getDataTable(); |
|
381
|
|
|
DataTable<String>.RowFactory rf = getRowFactoryWrite(table); |
|
382
|
|
|
for (int i = 0; i < wTable.getItemCount(); i++) { |
|
383
|
|
|
table.add(rf.newRow(wTable.getItem(i)).getFullRow()); |
|
384
|
|
|
} |
|
385
|
|
|
meta.setMapTable(table); |
|
386
|
|
|
|
|
387
|
|
|
table = this.getDataTableVocab(); |
|
388
|
|
|
rf = this.getRowFactoryWriteVocab(table); |
|
389
|
|
|
for (int i = 0; i < wVocabTable.getItemCount(); i++) { |
|
390
|
|
|
table.add(rf.newRow(wVocabTable.getItem(i)).getFullRow()); |
|
391
|
|
|
} |
|
392
|
|
|
meta.setVocabTable(table); |
|
393
|
|
|
|
|
394
|
|
|
meta.setKeepInputFields(wKeepInputFields.getSelection()); |
|
395
|
|
|
meta.setOntologyOutputFieldName(wOntologyOutputFieldName.getText()); |
|
396
|
|
|
meta.setUriOutputFieldName(wURIOutputFieldName.getText()); |
|
397
|
|
|
dispose(); |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
private DataTable<String> getDataTable() { |
|
401
|
|
|
return new DataTable<String>(OwlInputStepMeta.Field.MAP_TABLE.name(), |
|
402
|
|
|
OwlInputStepMeta.Field.MAP_TABLE_ONTOLOGY_NAME.name(), |
|
403
|
|
|
OwlInputStepMeta.Field.MAP_TABLE_ONTOLOGY_URI.name(), |
|
404
|
|
|
OwlInputStepMeta.Field.MAP_TABLE_ONTOLOGY_DESCRIPTION.name()); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
private DataTable<String>.RowFactory getRowFactoryWrite(DataTable<String> table) { |
|
408
|
|
|
return table.newRowFactory(OwlInputStepMeta.Field.MAP_TABLE_ONTOLOGY_NAME.name(), |
|
409
|
|
|
OwlInputStepMeta.Field.MAP_TABLE_ONTOLOGY_URI.name(), |
|
410
|
|
|
OwlInputStepMeta.Field.MAP_TABLE_ONTOLOGY_DESCRIPTION.name()); |
|
411
|
|
|
} |
|
412
|
|
|
|
|
413
|
|
|
private DataTable<String> getDataTableVocab() { |
|
414
|
|
|
return new DataTable<String>(OwlInputStepMeta.Field.VOCAB_TABLE.name(), |
|
415
|
|
|
OwlInputStepMeta.Field.VOCAB_TABLE_PREFIX.name(), |
|
416
|
|
|
OwlInputStepMeta.Field.VOCAB_TABLE_URI.name(), |
|
417
|
|
|
OwlInputStepMeta.Field.VOCAB_TABLE_PROPERTY.name(), |
|
418
|
|
|
OwlInputStepMeta.Field.VOCAB_TABLE_TYPE.name()); |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
private DataTable<String>.RowFactory getRowFactoryWriteVocab(DataTable<String> table) { |
|
422
|
|
|
return table.newRowFactory(OwlInputStepMeta.Field.VOCAB_TABLE_PREFIX.name(), |
|
423
|
|
|
OwlInputStepMeta.Field.VOCAB_TABLE_URI.name(), |
|
424
|
|
|
OwlInputStepMeta.Field.VOCAB_TABLE_PROPERTY.name(), |
|
425
|
|
|
OwlInputStepMeta.Field.VOCAB_TABLE_TYPE.name()); |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
private DataTable<String>.RowFactory getRowFactoryRead(DataTable<String> table) { |
|
429
|
|
|
List<String> header = new ArrayList<String>(); |
|
430
|
|
|
header.addAll(table.getHeader()); |
|
431
|
|
|
return table.newRowFactory(header.toArray(new String[0])); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
private void loadFile() { |
|
435
|
|
|
try { |
|
436
|
|
|
FileDialog dialog = new FileDialog(shell, SWT.OPEN); |
|
437
|
|
|
dialog.setText(BaseMessages.getString(PKG, "OwlInputStep.AddOwl")); |
|
438
|
|
|
dialog.open(); |
|
439
|
|
|
String[] row = { dialog.getFileName(), dialog.getFilterPath() + "/" + dialog.getFileName(), |
|
440
|
|
|
BaseMessages.getString(PKG, "OwlInputStep.OwlDescription") }; |
|
441
|
|
|
this.insertRow(wTable, row); |
|
442
|
|
|
} catch (Exception e) { |
|
443
|
|
|
log.log(Level.SEVERE, e.toString(), e); |
|
444
|
|
|
} |
|
445
|
|
|
|
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
private void addUri() { |
|
449
|
|
|
String data = wHelloFieldName.getText().trim(); |
|
450
|
|
|
wHelloFieldName.setText(data); |
|
451
|
|
|
if (data.equals("")) { |
|
452
|
|
|
MessageBox dialog = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK); |
|
453
|
|
|
dialog.setText(BaseMessages.getString(PKG, "OwlInputStep.OwlDialog")); |
|
454
|
|
|
dialog.setMessage(BaseMessages.getString(PKG, "OwlInputStep.OwlError")); |
|
455
|
|
|
|
|
456
|
|
|
dialog.open(); |
|
457
|
|
|
} else { |
|
458
|
|
|
Pattern pat = Pattern.compile("^http.*"); |
|
459
|
|
|
pat.matcher(wHelloFieldName.getText()); |
|
460
|
|
|
|
|
461
|
|
|
LOVAttributes attributes = null; |
|
462
|
|
|
|
|
463
|
|
|
try { |
|
464
|
|
|
attributes = LOVApiV2.vocabularySearch(wHelloFieldName.getText().trim()); |
|
465
|
|
|
} catch (Exception e) { |
|
466
|
|
|
e.printStackTrace(); |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
if (attributes != null && !attributes.isEmpty()) { |
|
470
|
|
|
String[] row = { attributes.getPrefix(), attributes.getURI(), attributes.getDescription() }; |
|
471
|
|
|
this.insertRow(wTable, row); |
|
472
|
|
|
} else { |
|
473
|
|
|
MessageBox dialog = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK); |
|
474
|
|
|
dialog.setText(BaseMessages.getString(PKG, "OwlInputStep.OwlDialog")); |
|
475
|
|
|
dialog.setMessage(BaseMessages.getString(PKG, "OwlInputStep.OwlError")); |
|
476
|
|
|
|
|
477
|
|
|
dialog.open(); |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
} |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
private void insertRow(TableView tvTable, String[] row) { |
|
484
|
|
|
if (tvTable.table.getItem(0).getText(1).equals("")) { |
|
485
|
|
|
for (int i = 0; i < row.length; i++) |
|
486
|
|
|
tvTable.table.getItem(0).setText(i + 1, row[i]); |
|
487
|
|
|
} else { |
|
488
|
|
|
tvTable.add(row); |
|
489
|
|
|
} |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
} |
|
493
|
|
|
|