/
TeiidMetadataImportSourcePage.java
1677 lines (1419 loc) · 57.7 KB
/
TeiidMetadataImportSourcePage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.teiid.designer.transformation.ui.wizards.file;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.IProfileListener;
import org.eclipse.datatools.connectivity.ProfileManager;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.dialogs.FilteredList.FilterMatcher;
import org.eclipse.ui.internal.misc.StringMatcher;
import org.teiid.core.designer.util.CoreStringUtil;
import org.teiid.core.designer.util.I18nUtil;
import org.teiid.core.designer.util.StringConstants;
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.core.util.URLHelper;
import org.teiid.designer.core.workspace.DotProjectUtils;
import org.teiid.designer.core.workspace.ModelResource;
import org.teiid.designer.core.workspace.ModelUtil;
import org.teiid.designer.core.workspace.ModelWorkspaceException;
import org.teiid.designer.core.workspace.ModelWorkspaceItem;
import org.teiid.designer.core.workspace.ModelWorkspaceManager;
import org.teiid.designer.datatools.connection.ConnectionInfoHelper;
import org.teiid.designer.datatools.connection.IConnectionInfoHelper;
import org.teiid.designer.datatools.profiles.flatfile.IFlatFileProfileConstants;
import org.teiid.designer.datatools.profiles.xml.IXmlProfileConstants;
import org.teiid.designer.datatools.ui.actions.EditConnectionProfileAction;
import org.teiid.designer.datatools.ui.dialogs.NewTeiidFilteredCPWizard;
import org.teiid.designer.metamodels.relational.Procedure;
import org.teiid.designer.transformation.ui.UiConstants;
import org.teiid.designer.transformation.ui.UiPlugin;
import org.teiid.designer.transformation.ui.wizards.xmlfile.TeiidXmlFileInfo;
import org.teiid.designer.ui.common.InternalUiConstants;
import org.teiid.designer.ui.common.product.ProductCustomizerMgr;
import org.teiid.designer.ui.common.table.TableViewerBuilder;
import org.teiid.designer.ui.common.util.WidgetFactory;
import org.teiid.designer.ui.common.util.WidgetUtil;
import org.teiid.designer.ui.common.util.WizardUtil;
import org.teiid.designer.ui.common.viewsupport.FileSystemLabelProvider;
import org.teiid.designer.ui.common.widget.DefaultScrolledComposite;
import org.teiid.designer.ui.common.wizard.AbstractWizardPage;
import org.teiid.designer.ui.explorer.ModelExplorerContentProvider;
import org.teiid.designer.ui.explorer.ModelExplorerLabelProvider;
import org.teiid.designer.ui.viewsupport.ModelIdentifier;
import org.teiid.designer.ui.viewsupport.ModelNameUtil;
import org.teiid.designer.ui.viewsupport.ModelObjectUtilities;
import org.teiid.designer.ui.viewsupport.ModelProjectSelectionStatusValidator;
import org.teiid.designer.ui.viewsupport.ModelResourceSelectionValidator;
import org.teiid.designer.ui.viewsupport.ModelUtilities;
import org.teiid.designer.ui.viewsupport.ModelWorkspaceViewerFilter;
import org.teiid.designer.ui.viewsupport.ModelingResourceFilter;
/**
* @since 8.0
*/
public class TeiidMetadataImportSourcePage extends AbstractWizardPage implements
UiConstants, InternalUiConstants.Widgets,
CoreStringUtil.Constants {
// ===========================================================================================================================
// Constants
private static final String I18N_PREFIX = I18nUtil.getPropertyPrefix(TeiidMetadataImportSourcePage.class);
private static final String TITLE = getString("title"); //$NON-NLS-1$
private static final String INITIAL_MESSAGE = getString("initialMessage"); //$NON-NLS-1$
private static final String FLAT_FILE_SOURCE_LABEL = getString("sourceLabel"); //$NON-NLS-1$
private static final String NEW_BUTTON = "New..."; //Util.getString("Widgets.newLabel"); //$NON-NLS-1$
private static final String EDIT_BUTTON = "Edit..."; //Util.getString("Widgets.editLabel"); //$NON-NLS-1$
private static final String INVALID_PAGE_MESSAGE = getString("invalidPageMessage"); //$NON-NLS-1$
// PROPERTY VALUES FROM FLAT FILE CP:
// INCLTYPELINE=NO
// INCLCOLUMNNAME=YES
// HOME=/home/blafond/TestDesignerFolder/FlatFileData/employee-data
// TRAILNULLCOLS=NO
// DELIMTYPE=COMMA
// CHARSET=UTF-8
private static final String HOME = "HOME"; //$NON-NLS-1$
private static final String URI = "URI"; //$NON-NLS-1$
private static final String INCLTYPELINE = "INCLTYPELINE"; //$NON-NLS-1$
private static final String INCLCOLUMNNAME = "INCLCOLUMNNAME"; //$NON-NLS-1$
private static final String VALUE_YES = "YES"; //$NON-NLS-1$
private static final String VALUE_COMMA = "COMMA"; //$NON-NLS-1$
private static final String CHARSET = "CHARSET"; //$NON-NLS-1$
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static final String DOT_XML = ".XML"; //$NON-NLS-1$
private static final String FILTER_INIT = "*.*"; //$NON-NLS-1$
private static final String DOT_TXT_LOWER = ".txt"; //$NON-NLS-1$
private static final String GET_TEXT_FILES = "getTextFiles"; //$NON-NLS-1$
private static final String ODA_FLAT_FILE_ID = "org.eclipse.datatools.connectivity.oda.flatfile"; //$NON-NLS-1$
private static final String FLAT_FILE_URL_ID = IFlatFileProfileConstants.FILE_URL_CONNECTION_PROFILE_ID;
//private static final String SCHEMA_LIST_PROPERTY_KEY = "SCHEMAFILELIST"; //$NON-NLS-1$
private static final String FILE_LIST_PROPERTY_KEY = "FILELIST"; //$NON-NLS-1$ //home/blafond/TestDesignerFolder/example files/xml/employee_info.xml
private static final String UNKNOWN_FOLDER = getString("unknownFolderText"); //$NON-NLS-1$
private static String getString(final String id) {
return Util.getString(I18N_PREFIX + id);
}
private ILabelProvider srcLabelProvider;
private Combo srcCombo;
private Text dataFileFolderText;
private Text fileFilterText;
private Button editCPButton;
private TableViewerBuilder fileViewer;
private DataFolderContentProvider fileContentProvider;
private TableViewerColumn fileNameColumn;
private Text sourceModelContainerText;
private Text sourceModelFileText;
private Text sourceHelpText;
private IPath sourceModelFilePath;
private Text selectedFileText;
private ProfileManager profileManager = ProfileManager.getInstance();
private Collection<IConnectionProfile> connectionProfiles;
private TeiidMetadataImportInfo info;
final private ConnectionProfileInfo profileInfo = new ConnectionProfileInfo();
boolean creatingControl = false;
boolean synchronizing = false;
boolean processingChecks = false;
IStatus fileParsingStatus;
IConnectionInfoHelper connectionInfoHelper;
static String[] TEXT_FILE_EXTENSIONS = {
"TXT", "CSV", "TSV" //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
};
/**
* @param info the TeiidMetadataImportInfo
* @since 4.0
*/
public TeiidMetadataImportSourcePage(TeiidMetadataImportInfo info) {
this(null, info);
}
/**
* @param selection the selection
* @param info the TeiidMetadataImportInfo
* @since 4.0
*/
public TeiidMetadataImportSourcePage(Object selection, TeiidMetadataImportInfo info) {
super(TeiidMetadataImportSourcePage.class.getSimpleName(), TITLE);
// Set page incomplete initially
this.info = info;
setPageComplete(false);
setImageDescriptor(UiPlugin.getDefault().getImageDescriptor(Images.IMPORT_TEIID_METADATA));
this.connectionInfoHelper = new ConnectionInfoHelper();
}
@Override
public void createControl(Composite parent) {
final Composite hostPanel = new Composite(parent, SWT.NONE);
hostPanel.setLayout(new GridLayout(1, false));
hostPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
// Create page
DefaultScrolledComposite scrolledComposite = new DefaultScrolledComposite(hostPanel);
hostPanel.setLayout(new GridLayout(1, false));
hostPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
final Composite mainPanel = scrolledComposite.getPanel();
mainPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
mainPanel.setLayout(new GridLayout(1, false));
setControl(mainPanel);
// Add widgets to page
createProfileGroup(mainPanel);
createFolderContentsListGroup(mainPanel);
createSourceModelGroup(mainPanel);
scrolledComposite.sizeScrolledPanel();
setControl(hostPanel);
setMessage(INITIAL_MESSAGE);
}
private void createProfileGroup(Composite parent) {
// ---------------------------------------------------------------------------
// ----------- Connection Profile SOURCE Panel
// ---------------------------------
// ---------------------------------------------------------------------------
Group profileGroup = WidgetFactory.createGroup(parent, FLAT_FILE_SOURCE_LABEL, SWT.NONE, 2, 3);
profileGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
refreshConnectionProfiles();
this.srcLabelProvider = new LabelProvider() {
@Override
public String getText(final Object source) {
return ((IConnectionProfile) source).getName();
}
};
this.srcCombo = WidgetFactory.createCombo(profileGroup, SWT.READ_ONLY,
GridData.FILL_HORIZONTAL, (ArrayList) this.connectionProfiles,
null, // this.src,
this.srcLabelProvider, true);
this.srcCombo.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
profileSelectionChanged();
fileViewer.refresh();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
});
this.srcCombo.setVisibleItemCount(10);
WidgetFactory.createButton(profileGroup, NEW_BUTTON).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent event) {
createNewConnectionProfile();
}
});
editCPButton = WidgetFactory.createButton(profileGroup, EDIT_BUTTON);
editCPButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent event) {
editConnectionProfile();
}
});
editCPButton.setEnabled(false);
}
/**
* Method to create List box control group for displaying current zip file
* project list.
*
*
* @param parent
* @since 4.2
*/
private void createFolderContentsListGroup(Composite parent) {
String groupLabel = getString("folderContentsGroup"); //$NON-NLS-1$
if (!info.isFlatFileLocalMode()) {
groupLabel = getString("folderXmlContentsGroup"); //$NON-NLS-1$
}
Group folderContentsGroup = WidgetFactory.createGroup(parent, groupLabel, SWT.FILL, 3, 2);
GridData gd_1 = new GridData(GridData.FILL_BOTH);
gd_1.heightHint = 180;
gd_1.widthHint = 400;
folderContentsGroup.setLayoutData(gd_1);
Label locationLabel = new Label(folderContentsGroup, SWT.NONE);
locationLabel.setText(getString("folderLocation")); //$NON-NLS-1$
dataFileFolderText = new Text(folderContentsGroup, SWT.BORDER | SWT.SINGLE);
dataFileFolderText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
dataFileFolderText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE));
dataFileFolderText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
dataFileFolderText.setEditable(false);
Label fileFilterLabel = new Label(folderContentsGroup, SWT.NONE);
fileFilterLabel.setText(getString("fileFilterLabel")); //$NON-NLS-1$
createFilterTextBox(folderContentsGroup);
createFileTableViewer(folderContentsGroup);
Label selectedFileLabel = new Label(folderContentsGroup, SWT.NONE);
selectedFileLabel.setText(getString("selectedXmlFile")); //$NON-NLS-1$
selectedFileText = new Text(folderContentsGroup, SWT.BORDER | SWT.SINGLE);
selectedFileText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
selectedFileText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE));
selectedFileText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
selectedFileText.setEditable(false);
}
/**
* Creates Text Widget for Filter string entry
* @param parent the parent composite.
*/
protected void createFilterTextBox( Composite parent ) {
fileFilterText = new Text(parent, SWT.BORDER);
GridData data = new GridData();
data.grabExcessVerticalSpace = false;
data.grabExcessHorizontalSpace = true;
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.BEGINNING;
fileFilterText.setLayoutData(data);
fileFilterText.setFont(parent.getFont());
// Initial filter text is empty
fileFilterText.setText(FILTER_INIT);
setImportInfoFileFilter(FILTER_INIT);
Listener listener = new Listener() {
@Override
public void handleEvent( Event e ) {
for( TeiidMetadataFileInfo fileInfo : info.getFileInfos()) {
fileInfo.setDoProcess(false);
}
for( TableItem item : fileViewer.getTable().getItems()) {
item.setChecked(false);
}
String filterText = fileFilterText.getText();
// Set filter on import info
setImportInfoFileFilter(filterText);
// Update content provider, then refresh viewer
fileContentProvider.setFilterString(filterText);
fileViewer.refresh();
synchronizeUI();
validatePage();
}
};
fileFilterText.addListener(SWT.Modify, listener);
}
private void setImportInfoFileFilter(String filterText) {
this.info.setFileFilterText(filterText);
}
private void createFileTableViewer(Composite parent) {
this.fileViewer = new TableViewerBuilder(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.CHECK );
GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 160).span(2, SWT.DEFAULT).applyTo(fileViewer.getTableComposite());
fileContentProvider = new DataFolderContentProvider();
fileContentProvider.setFilterString(FILTER_INIT);
this.fileViewer.getTableViewer().setSorter(new ViewerSorter());
this.fileViewer.setContentProvider(fileContentProvider);
this.fileViewer.setLabelProvider(new FileSystemLabelProvider());
// Check events can occur separate from selection events.
// In this case move the selected node.
// Also trigger selection of node in model.
this.fileViewer.getTable().addSelectionListener(
new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
if( processingChecks ) {
return;
}
processingChecks = true;
if (e.detail == SWT.CHECK) {
TableItem tableItem = (TableItem) e.item;
boolean wasChecked = tableItem.getChecked();
if (tableItem.getData() instanceof File) {
fileViewer.getTable().setSelection(new TableItem[] { tableItem });
if (info.isFlatFileLocalMode()) {
if( wasChecked ) {
for( TableItem item : fileViewer.getTable().getItems()) {
if( item != tableItem ) {
item.setChecked(false);
}
}
}
info.setDoProcess((File) tableItem.getData(), wasChecked);
} else {
if( wasChecked ) {
for( TableItem item : fileViewer.getTable().getItems()) {
if( item != tableItem ) {
item.setChecked(false);
}
}
}
info.setDoProcessXml((File) tableItem.getData(), wasChecked);
}
}
if( wasChecked ) {
TeiidMetadataFileInfo fileInfo = info.getCheckedFileInfo();
if( fileInfo != null ) {
if( profileInfo.columnsInFirstLine ) {
if( profileInfo.includeTypeLine ) {
fileInfo.setFirstDataRow(3);
} else {
fileInfo.setFirstDataRow(2);
}
}
}
}
}
processingChecks = false;
synchronizeUI();
validatePage();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
// create columns
fileNameColumn = this.fileViewer.createColumn(SWT.LEFT, 100, 40, false);
fileNameColumn.getColumn().setText(getString("dataFileNameColumn")); //$NON-NLS-1$
fileNameColumn.setLabelProvider(new DataFileContentColumnLabelProvider());
}
private void createSourceModelGroup(Composite parent) {
Group sourceGroup = WidgetFactory.createGroup(parent, getString("sourceModelDefinitionGroup"), SWT.NONE, 1, 3); //$NON-NLS-1$
sourceGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label locationLabel = new Label(sourceGroup, SWT.NULL);
locationLabel.setText(getString("location")); //$NON-NLS-1$
sourceModelContainerText = new Text(sourceGroup, SWT.BORDER | SWT.SINGLE);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
sourceModelContainerText.setLayoutData(gridData);
sourceModelContainerText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
sourceModelContainerText.setEditable(false);
Button browseButton = new Button(sourceGroup, SWT.PUSH);
gridData = new GridData();
browseButton.setLayoutData(gridData);
browseButton.setText(getString("browse")); //$NON-NLS-1$
browseButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
handleSourceModelLocationBrowse();
}
});
Label fileLabel = new Label(sourceGroup, SWT.NULL);
fileLabel.setText(getString("name")); //$NON-NLS-1$
sourceModelFileText = new Text(sourceGroup, SWT.BORDER | SWT.SINGLE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
sourceModelFileText.setLayoutData(gridData);
sourceModelFileText.addModifyListener(new ModifyListener() {
@Override
public void modifyText( ModifyEvent e ) {
handleSourceModelTextChanged();
}
});
browseButton = new Button(sourceGroup, SWT.PUSH);
gridData = new GridData();
browseButton.setLayoutData(gridData);
browseButton.setText(getString("browse")); //$NON-NLS-1$
browseButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
handleSourceModelBrowse();
}
});
new Label(sourceGroup, SWT.NONE);
Group helpGroup = WidgetFactory.createGroup(sourceGroup, getString("modelStatus"), SWT.NONE | SWT.BORDER_DASH,2); //$NON-NLS-1$
helpGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
{
sourceHelpText = new Text(helpGroup, SWT.WRAP | SWT.READ_ONLY);
sourceHelpText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
sourceHelpText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE));
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.heightHint = 35;
gd.horizontalSpan=3;
sourceHelpText.setLayoutData(gd);
}
}
void profileSelectionChanged() {
if (this.srcCombo.getSelectionIndex() > -1) {
String cpName = this.srcCombo.getItem(this.srcCombo.getSelectionIndex());
for (IConnectionProfile profile : this.connectionProfiles) {
if (profile.getName().equalsIgnoreCase(cpName)) {
setConnectionProfile(profile);
Properties props = profile.getBaseProperties();
setDataFolderLocation(props);
String charset = (String) props.get(CHARSET);
if (charset != null) {
this.profileInfo.charset = charset;
}
clearFileListViewer();
loadFileListViewer();
if( !this.info.getFileInfos().isEmpty() ) {
// Check for FIRST LINE FOR COLUMNS
String firstLineHasColumns = (String) props.get(INCLCOLUMNNAME);
if( firstLineHasColumns != null ) {
this.profileInfo.columnsInFirstLine = firstLineHasColumns.equalsIgnoreCase(VALUE_YES);
}
String secondLineDatatypes = (String) props.get(INCLTYPELINE);
if( secondLineDatatypes != null ) {
this.profileInfo.includeTypeLine = secondLineDatatypes.equalsIgnoreCase(VALUE_YES);
}
String delimiterType = (String) props.get(INCLTYPELINE);
if( delimiterType != null ) {
this.profileInfo.delimiterType = delimiterType;
}
for( TeiidMetadataFileInfo nextInfo : this.info.getFileInfos() ) {
nextInfo.setCharSet(this.profileInfo.charset);
nextInfo.setIncludeTypeLine(this.profileInfo.includeTypeLine);
}
}
break;
}
}
} else {
setConnectionProfile(null);
}
synchronizeUI();
validatePage();
this.editCPButton.setEnabled(getConnectionProfile() != null);
}
private void setDataFolderLocation(Properties profileBaseProps) {
if(profileBaseProps!=null) {
String home = (String) profileBaseProps.get(HOME);
if (home != null) {
this.profileInfo.home = home;
String location = home;
if (location.length() > 60) {
int len = location.length();
location = "..." + location.substring(len - 60, len); //$NON-NLS-1$
}
this.dataFileFolderText.setText(location);
this.dataFileFolderText.setToolTipText(home);
} else {
String uri = (String) profileBaseProps.get(URI);
if( uri != null ) {
String location = null;
File aFile = new File(uri);
if(aFile.exists() && aFile.isFile()) {
File parentDir = aFile.getParentFile();
if(parentDir!=null && parentDir.exists() && parentDir.isDirectory()) {
location = parentDir.getAbsolutePath();
this.profileInfo.home = location;
}
}
if(location==null) {
this.dataFileFolderText.setText(UNKNOWN_FOLDER);
this.dataFileFolderText.setToolTipText(getString("unknownFolderTooltip")); //$NON-NLS-1$
} else {
this.dataFileFolderText.setText(location);
this.dataFileFolderText.setToolTipText(location);
}
} else {
String url = (String) profileBaseProps.get(IFlatFileProfileConstants.URL_PROP_ID);
if( url != null ) {
String location = url;
if (location.length() > 60) {
int len = location.length();
location = "..." + location.substring(len - 60, len); //$NON-NLS-1$
}
this.dataFileFolderText.setText(location);
this.dataFileFolderText.setToolTipText(url);
} else {
this.dataFileFolderText.setText(EMPTY_STRING);
this.dataFileFolderText.setToolTipText(EMPTY_STRING);
}
}
}
} else {
this.dataFileFolderText.setText(EMPTY_STRING);
this.dataFileFolderText.setToolTipText(EMPTY_STRING);
}
}
private void setConnectionProfile(IConnectionProfile profile) {
if(profile==null) {
this.fileViewer.setInput(null);
clearFileListViewer();
}
this.info.setConnectionProfile(profile);
}
private IConnectionProfile getConnectionProfile() {
return this.info.getConnectionProfile();
}
private void clearFileListViewer() {
this.info.clearXmlFileInfos();
this.info.clearFileInfos();
fileViewer.getTableViewer().remove(fileViewer.getTable().getItems());
}
private void loadFileListViewer() {
if (getConnectionProfile() != null) {
if( this.info.isFlatFileLocalMode() ) {
File folder = getFolderForConnectionProfile();
File file = getFileForConnectionProfile();
if (hasExistingFileOrFolder(file,folder)) {
fileParsingStatus = Status.OK_STATUS;
if(file!=null && file.exists() && file.isFile()) {
TeiidMetadataFileInfo fileInfo = this.info.getFileInfo(file);
if (fileInfo == null) {
fileInfo = new TeiidMetadataFileInfo(file);
this.info.addFileInfo(fileInfo);
}
fileInfo.setIsUrl(false);
fileViewer.setInput(file);
fileViewer.getTable().select(0);
fileViewer.getTable().getItem(0).setChecked(true);
info.setDoProcess(fileInfo.getDataFile(), true);
} else {
fileViewer.setInput(folder);
}
TableItem[] items = fileViewer.getTable().getItems();
for (TableItem item : items) {
Object data = item.getData();
if (data != null && data instanceof File) {
File theFile = (File) data;
if (!theFile.isDirectory()) {
TeiidMetadataFileInfo fileInfo = this.info.getFileInfo(theFile);
if (fileInfo == null || !fileInfo.getCharset().equals(this.profileInfo.charset)) {
this.info.addFileInfo(new TeiidMetadataFileInfo(theFile, this.profileInfo.charset));
}
//this.info.validate();
}
}
}
for (TableColumn column : this.fileViewer.getTable()
.getColumns()) {
column.setWidth(column.getWidth() + 4);
}
// Unrecognized selection in CP
} else {
this.fileViewer.setInput(null);
this.dataFileFolderText.setText(UNKNOWN_FOLDER);
this.dataFileFolderText.setToolTipText(getString("unknownFolderTooltip")); //$NON-NLS-1$
}
// -----------------------------
// FlatFile Remote Mode
// -----------------------------
} else {
String urlString = getUrlStringForConnectionProfile();
if( urlString != null && urlString.trim().length() > 0 ) {
File theFile = null;
// Clears the viewer
// This will be the case if No XML is defined and URL version exists OR if nothing is defined in CP
fileViewer.setInput("no input"); //$NON-NLS-1$
//
URL newUrl = null;
try {
newUrl = URLHelper.buildURL(urlString);
} catch (MalformedURLException e) {
Util.log(e);
MessageDialog.openError(this.getShell(),
getString("malformedUrlErrorTitle"), //$NON-NLS-1$
UiConstants.Util.getString("malformedUrlErrorMessage", urlString, e.getMessage())); //$NON-NLS-1$
}
if( newUrl != null ) {
boolean resolved = true;
try {
resolved = URLHelper.resolveUrl(newUrl);
} catch (Exception e) {
resolved = false;
}
if( resolved ) {
try {
String filePath = formatPath(newUrl);
theFile = URLHelper.createFileFromUrl(newUrl, CoreStringUtil.createFileName(filePath), DOT_TXT_LOWER);
} catch (MalformedURLException theException) {
Util.log(theException);
} catch (IOException theException) {
Util.log(theException);
}
}
}
if( theFile != null && theFile.exists() ) {
fileParsingStatus = Status.OK_STATUS;
TeiidMetadataFileInfo fileInfo = this.info.getFileInfo(theFile);
if (fileInfo == null) {
fileInfo = new TeiidMetadataFileInfo(theFile);
this.info.addFileInfo(fileInfo);
}
fileInfo.setIsUrl(true);
fileInfo.setFileUrl(urlString);
fileInfo.setCharSet(this.profileInfo.charset);
fileViewer.setInput(theFile);
fileViewer.getTable().select(0);
fileViewer.getTable().getItem(0).setChecked(true);
info.setDoProcess(fileInfo.getDataFile(), true);
}
} else {
fileViewer.setInput(null);
MessageDialog.openError(this.getShell(),
getString("invalidXmlConnectionProfileTitle"), //$NON-NLS-1$
getString("invalidXmlConnectionProfileMessage")); //$NON-NLS-1$
}
}
}
}
private boolean hasExistingFileOrFolder(File theFile, File theFolder) {
if (theFolder != null && theFolder.exists() && theFolder.isDirectory()) {
return true;
}
if (theFile != null && theFile.exists() && theFile.isFile()) {
return true;
}
return false;
}
/**
* If the path begins with a "/", we need to strip off since this will be changed to an underscore and create an invalid model
* name. Also, we need to remove any periods.
*
* @param newUrl the file url
* @return filePath - reformatted string used for generating the new file name
*/
public static String formatPath( URL newUrl ) {
String filePath = newUrl.getPath();
/*
* If the path begins with a "/", we need to strip off since this will
* be changed to an underscore and create an invalid model name.
*/
while (filePath.startsWith("/")) { //$NON-NLS-1$
filePath = filePath.substring(1);
}
int dotLocation = filePath.indexOf("."); //$NON-NLS-1$
if (dotLocation > -1) {
filePath = filePath.substring(0, dotLocation);
}
return filePath;
}
private File getFolderForConnectionProfile() {
if (getConnectionProfile() != null) {
Properties props = getConnectionProfile().getBaseProperties();
// For folder definition, the HOME property will be set
String home = (String) props.get(HOME);
if (home != null) {
return new File(home);
}
// Home property not set - look for individual URI
String fileURI = (String) props.get(URI);
if(fileURI != null) {
File aFile = new File(fileURI);
if(aFile.exists() && aFile.isFile()) {
return aFile.getParentFile();
}
}
}
return null;
}
private File getFileForConnectionProfile() {
if (getConnectionProfile() != null) {
Properties props = getConnectionProfile().getBaseProperties();
String fileListValue = (String) props.get(FILE_LIST_PROPERTY_KEY);
if (fileListValue != null) {
return new File(fileListValue);
}
String fileUriValue = (String) props.get(URI);
if(fileUriValue != null) {
File uriFile = new File(fileUriValue);
if(uriFile.exists() && uriFile.isFile()) {
return uriFile;
}
}
}
return null;
}
private String getUrlStringForConnectionProfile() {
if (getConnectionProfile() != null) {
Properties props = getConnectionProfile().getBaseProperties();
String fileListValue = (String) props.get(FILE_LIST_PROPERTY_KEY);
if (fileListValue != null) {
return fileListValue;
}
String url = (String) props.get(IFlatFileProfileConstants.URL_PROP_ID);
if(url != null) {
return url;
}
}
return null;
}
void createNewConnectionProfile() {
INewWizard wiz = null;
if( this.info.isFlatFileLocalMode() ) {
wiz = new NewTeiidFilteredCPWizard(ODA_FLAT_FILE_ID);
} else {
wiz = new NewTeiidFilteredCPWizard(FLAT_FILE_URL_ID);
}
WizardDialog wizardDialog = new WizardDialog(Display.getCurrent().getActiveShell(), wiz);
wizardDialog.setBlockOnOpen(true);
CPListener listener = new CPListener();
ProfileManager.getInstance().addProfileListener(listener);
if (wizardDialog.open() == Window.OK) {
refreshConnectionProfiles();
resetCPComboItems();
setConnectionProfile(listener.getChangedProfile());
selectProfile(listener.getChangedProfile());
}
ProfileManager.getInstance().removeProfileListener(listener);
}
void selectProfile(IConnectionProfile profile) {
int index = 0;
for (String item : this.srcCombo.getItems()) {
if (item != null && item.equalsIgnoreCase(profile.getName())) {
this.srcCombo.select(index);
profileSelectionChanged();
break;
}
index++;
}
}
void resetCPComboItems() {
if (this.srcCombo != null) {
WidgetUtil.setComboItems(this.srcCombo,
this.connectionProfiles, this.srcLabelProvider,
true);
}
}
void editConnectionProfile() {
if (getConnectionProfile() != null) {
IConnectionProfile currentProfile = getConnectionProfile();
EditConnectionProfileAction action = new EditConnectionProfileAction(getShell(), currentProfile);
CPListener listener = new CPListener();
ProfileManager.getInstance().addProfileListener(listener);
action.run();
// Update the Combo Box
if (action.wasFinished()) {
setConnectionProfile(listener.getChangedProfile());
this.refreshConnectionProfiles();
WidgetUtil.setComboItems(this.srcCombo,
this.connectionProfiles,
this.srcLabelProvider, true);
WidgetUtil.setComboText(this.srcCombo, getConnectionProfile(),this.srcLabelProvider);
selectConnectionProfile(currentProfile.getName());
ProfileManager.getInstance().removeProfileListener(listener);
profileSelectionChanged();
} else {
// Remove the listener if the dialog is canceled
ProfileManager.getInstance().removeProfileListener(listener);
}
}
}
/**
* Uses the standard container selection dialog to choose the new value for the container field.
*/
void handleSourceModelLocationBrowse() {
final IContainer folder = WidgetUtil.showFolderSelectionDialog(ModelerCore.getWorkspace().getRoot(),
new ModelingResourceFilter(),
new ModelProjectSelectionStatusValidator());
if (folder != null && sourceModelContainerText != null) {
this.info.setSourceModelLocation(folder.getFullPath().makeRelative());
this.sourceModelFilePath = this.info.getSourceModelLocation();
this.info.setTargetProject(folder.getProject());
this.sourceModelContainerText.setText(this.info.getSourceModelLocation().makeRelative().toString());
} else {
this.info.setSourceModelLocation(new Path(StringConstants.EMPTY_STRING));
this.sourceModelContainerText.setText(StringConstants.EMPTY_STRING);
}
if( this.sourceModelFileText.getText() != null && this.sourceModelFileText.getText().length() > -1 ) {
this.info.setSourceModelExists(sourceModelExists());
}
validatePage();
}
void handleSourceModelBrowse() {
final Object[] selections = WidgetUtil.
showWorkspaceObjectSelectionDialog(getString("selectSourceModelTitle"), //$NON-NLS-1$
getString("selectSourceModelMessage"), //$NON-NLS-1$
false,
null,
sourceModelFilter,
new ModelResourceSelectionValidator(false),
new ModelExplorerLabelProvider(),
new ModelExplorerContentProvider() );
if (selections != null && selections.length == 1 && sourceModelFileText != null) {
if( selections[0] instanceof IFile) {
IFile modelFile = (IFile)selections[0];
IPath folderPath = modelFile.getFullPath().removeLastSegments(1);
String modelName = modelFile.getFullPath().lastSegment();