-
Notifications
You must be signed in to change notification settings - Fork 49
/
VdbEditor.java
2620 lines (2338 loc) · 121 KB
/
VdbEditor.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.vdb.ui.editor;
import static org.teiid.core.designer.util.StringConstants.EMPTY_STRING;
import static org.teiid.designer.vdb.Vdb.Event.CLOSED;
import static org.teiid.designer.vdb.Vdb.Event.DATA_POLICY_ADDED;
import static org.teiid.designer.vdb.Vdb.Event.DATA_POLICY_REMOVED;
import static org.teiid.designer.vdb.Vdb.Event.ENTRY_SYNCHRONIZATION;
import static org.teiid.designer.vdb.Vdb.Event.MODEL_JNDI_NAME;
import static org.teiid.designer.vdb.Vdb.Event.MODEL_TRANSLATOR;
import static org.teiid.designer.vdb.ui.preferences.VdbPreferenceConstants.SYNCHRONIZE_WITHOUT_WARNING;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
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.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.custom.SashForm;
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.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.ui.part.EditorPart;
import org.osgi.service.prefs.BackingStoreException;
import org.teiid.core.designer.util.CoreStringUtil;
import org.teiid.core.designer.util.FileUtils;
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.core.util.VdbHelper.VdbFolders;
import org.teiid.designer.core.workspace.ModelUtil;
import org.teiid.designer.core.workspace.ResourceChangeUtilities;
import org.teiid.designer.ui.UiConstants;
import org.teiid.designer.ui.UiPlugin;
import org.teiid.designer.ui.common.graphics.GlobalUiColorManager;
import org.teiid.designer.ui.common.table.CheckBoxColumnProvider;
import org.teiid.designer.ui.common.table.DefaultTableProvider;
import org.teiid.designer.ui.common.table.TableAndToolBar;
import org.teiid.designer.ui.common.table.TextColumnProvider;
import org.teiid.designer.ui.common.util.UiUtil;
import org.teiid.designer.ui.common.util.WidgetFactory;
import org.teiid.designer.ui.common.util.WidgetUtil;
import org.teiid.designer.ui.common.viewsupport.UiBusyIndicator;
import org.teiid.designer.ui.common.widget.ButtonProvider;
import org.teiid.designer.ui.common.widget.DefaultContentProvider;
import org.teiid.designer.ui.common.widget.DefaultScrolledComposite;
import org.teiid.designer.ui.common.widget.Label;
import org.teiid.designer.ui.editors.ModelEditorManager;
import org.teiid.designer.ui.properties.extension.VdbFileDialogUtil;
import org.teiid.designer.ui.util.ErrorHandler;
import org.teiid.designer.ui.viewsupport.ModelIdentifier;
import org.teiid.designer.ui.viewsupport.ModelLabelProvider;
import org.teiid.designer.ui.viewsupport.ModelUtilities;
import org.teiid.designer.ui.viewsupport.ModelingResourceFilter;
import org.teiid.designer.vdb.Vdb;
import org.teiid.designer.vdb.VdbEntry;
import org.teiid.designer.vdb.VdbEntry.Synchronization;
import org.teiid.designer.vdb.VdbFileEntry;
import org.teiid.designer.vdb.VdbModelEntry;
import org.teiid.designer.vdb.VdbSchemaEntry;
import org.teiid.designer.vdb.VdbUtil;
import org.teiid.designer.vdb.XmiVdb;
import org.teiid.designer.vdb.connections.SourceHandlerExtensionManager;
import org.teiid.designer.vdb.ui.Messages;
import org.teiid.designer.vdb.ui.VdbUiConstants;
import org.teiid.designer.vdb.ui.VdbUiConstants.Images;
import org.teiid.designer.vdb.ui.VdbUiPlugin;
import org.teiid.designer.vdb.ui.editor.panels.DataRolesPanel;
import org.teiid.designer.vdb.ui.editor.panels.DescriptionPanel;
import org.teiid.designer.vdb.ui.editor.panels.ModelDetailsPanel;
import org.teiid.designer.vdb.ui.editor.panels.PropertiesPanel;
import org.teiid.designer.vdb.ui.editor.panels.UserDefinedPropertiesPanel;
import org.teiid.designer.vdb.ui.translators.TranslatorOverridesPanel;
/**
* @since 8.0
*/
public final class VdbEditor extends EditorPart implements IResourceChangeListener {
static final String MODEL_COLUMN_NAME = i18n("modelColumnName"); //$NON-NLS-1$
static final String SCHEMA_COLUMN_NAME = i18n("schemaColumnName"); //$NON-NLS-1$
static final String FILE_COLUMN_NAME = i18n("fileColumnName"); //$NON-NLS-1$
static final String PATH_COLUMN_NAME = i18n("pathColumnName"); //$NON-NLS-1$
static final String VDB_LOC_COLUMN_NAME = i18n("locationInVdbColumnName"); //$NON-NLS-1$
static final String SYNCHRONIZED_COLUMN_NAME = i18n("synchronizedColumnName"); //$NON-NLS-1$
static final String VISIBLE_COLUMN_NAME = i18n("visibleColumnName"); //$NON-NLS-1$;
static final String DESCRIPTION_COLUMN_NAME = i18n("descriptionColumnName"); //$NON-NLS-1$;
static final String SYNCHRONIZED_TOOLTIP = i18n("synchronizedTooltip"); //$NON-NLS-1$
static final String UNSYNCHRONIZED_TOOLTIP = i18n("unsynchronizedTooltip"); //$NON-NLS-1$
static final String SYNCHRONIZATION_NOT_APPLICABLE_TOOLTIP = i18n("synchronizationNotApplicableTooltip"); //$NON-NLS-1$
static final String VISIBLE_TOOLTIP = i18n("visibleTooltip"); //$NON-NLS-1$
static final String NOT_VISIBLE_TOOLTIP = i18n("notVisibleTooltip"); //$NON-NLS-1$
static final String ADD_MODEL_DIALOG_TITLE = i18n("addModelDialogTitle"); //$NON-NLS-1$
static final String ADD_MODEL_DIALOG_MESSAGE = i18n("addModelDialogMessage"); //$NON-NLS-1$
static final String ADD_FILE_DIALOG_TITLE = i18n("addFileDialogTitle"); //$NON-NLS-1$
static final String ADD_FILE_DIALOG_MESSAGE = i18n("addFileDialogMessage"); //$NON-NLS-1$
static final String ADD_FILE_DIALOG_INVALID_SELECTION_MESSAGE = i18n("addFileDialogInvalidSelectionMessage"); //$NON-NLS-1$
static final String ADD_FILE_DIALOG_NON_MODEL_SELECTED_MESSAGE = i18n("addFileDialogNonModelSelectedMessage"); //$NON-NLS-1$
static final String ADD_FILE_DIALOG_VDB_SOURCE_MODEL_SELECTED_MESSAGE = i18n("addFileDialogVdbSourceModelSelectedMessage"); //$NON-NLS-1$
static final String ADD_FILE_DIALOG_MODEL_WITH_SAME_NAME_EXISTS_SELECTED_MESSAGE = i18n("addFileDialogModelWithSameNameExistsSelectedMessage"); //$NON-NLS-1$
static final String CONFIRM_DIRTY_MODELS_DIALOG_TITLE = i18n("confirmDirtyModelsDialogTitle"); //$NON-NLS-1$
static final String CONFIRM_DIRTY_MODELS_DIALOG_MESSAGE= i18n("confirmDirtyModelsSynchronizeMessage"); //$NON-NLS-1$
static final String CONFIRM_DIALOG_TITLE = i18n("confirmDialogTitle"); //$NON-NLS-1$
static final String CONFIRM_SYNCHRONIZE_MESSAGE = i18n("confirmSynchronizeMessage"); //$NON-NLS-1$
static final String CONFIRM_SYNCHRONIZE_ALL_MESSAGE = i18n("confirmSynchronizeAllMessage"); //$NON-NLS-1$
static final String CONFIRM_REMOVE_MESSAGE = i18n("confirmRemoveMessage"); //$NON-NLS-1$
static final String CONFIRM_REMOVE_IMPORTED_BY_MESSAGE = i18n("confirmRemoveImportedByMessage"); //$NON-NLS-1$
static final String CONFIRM_OVERWRITE_USERFILE_MESSAGE = i18n("confirmOverwriteUserFileMessage"); //$NON-NLS-1$
static final String CONFIRM_OVERWRITE_UDFJAR_MESSAGE = i18n("confirmOverwriteUdfJarMessage"); //$NON-NLS-1$
static final String INFORM_DATA_ROLES_ON_ADD_MESSAGE = i18n("informDataRolesExistOnAddMessage"); //$NON-NLS-1$
static final String CANNOT_ADD_DUPLICATE_MODEL_NAME_TITLE = i18n("cannotAddDuplicateModelNameTitle"); //$NON-NLS-1$
static final String CANNOT_ADD_DUPLICATE_MODEL_NAME_MESSAGE = i18n("cannotAddDuplicateModelNameMessage"); //$NON-NLS-1$
static final String INVALID_INTEGER_INPUT_TITLE = i18n("invalidVdbVersionValueTitle"); //$NON-NLS-1$
static final String INVALID_INTEGER_INPUT_MESSAGE = i18n("invalidVdbVersionValueMessage"); //$NON-NLS-1$
static final int MODELS_PANEL_WIDTH_HINT = 300; // Models Panel Overall Width
static final int MODELS_PANEL_IMAGE_COL_WIDTH = 50; // Image Cols Width
static final int MODELS_PANEL_MODELNAME_COL_WIDTH_MIN = 200; // Min ModelName Width
// static final String WEB_SERVICES_VIEW_MODEL_URI = "http://www.metamatrix.com/metamodels/WebService"; //$NON-NLS-1$
static String i18n( final String id ) {
return VdbUiConstants.Util.getString(id);
}
private Vdb vdb;
Exception vdbLoadingException = null;
TableAndToolBar<VdbModelEntry> modelsGroup;
TableAndToolBar<VdbModelEntry> schemaGroup;
ModelDetailsPanel modelDetailsPanel;
TableAndToolBar<VdbEntry> otherFilesGroup;
TableAndToolBar<VdbEntry> udfJarsGroup;
private Button synchronizeAllButton;
Button showImportVdbsButton;
private Label validationDateTimeLabel;
private Label validationVersionLabel;
private PropertyChangeListener vdbListener;
private DataRolesPanel dataRolesPanel;
VdbDataRoleResolver dataRoleResolver;
TranslatorOverridesPanel pnlTranslatorOverrides;
@SuppressWarnings( "unused" )
private PropertiesPanel propertiesPanel;
@SuppressWarnings( "unused" )
private UserDefinedPropertiesPanel userDefinedPropertiesPanel;
DescriptionPanel descriptionPanel;
boolean disposed = false;
private final TextColumnProvider<VdbEntry> descriptionColumnProvider = new TextColumnProvider<VdbEntry>() {
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.ColumnProvider#getName()
*/
@Override
public String getName() {
return DESCRIPTION_COLUMN_NAME;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.ColumnProvider#getImage()
*/
@Override
public Image getImage() {
return null;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.ColumnProvider#getValue(java.lang.Object)
*/
@Override
public String getValue( final VdbEntry element ) {
return element.getDescription();
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.DefaultColumnProvider#isEditable(java.lang.Object)
*/
@Override
public boolean isEditable( final VdbEntry element ) {
return true;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.DefaultColumnProvider#setValue(java.lang.Object, java.lang.Object)
*/
@Override
public void setValue( final VdbEntry element,
final String value ) {
element.setDescription(value);
}
};
private final ModelLabelProvider modelLabelProvider = new ModelLabelProvider();
private final TextColumnProvider<VdbEntry> locationInVdbColumnProvider = new TextColumnProvider<VdbEntry>() {
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.ColumnProvider#getName()
*/
@Override
public String getName() {
return VDB_LOC_COLUMN_NAME;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.ColumnProvider#getImage()
*/
@Override
public Image getImage() {
return null;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.ColumnProvider#getValue(java.lang.Object)
*/
@Override
public String getValue( final VdbEntry element ) {
return element.getDirectory();
}
};
private final CheckBoxColumnProvider<VdbEntry> syncColumnProvider = new CheckBoxColumnProvider<VdbEntry>() {
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.ColumnProvider#getName()
*/
@Override
public String getName() {
return null;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.ColumnProvider#getImage()
*/
@Override
public Image getImage() {
return VdbUiPlugin.singleton.getImage(VdbUiConstants.Images.SYNCHRONIZE_MODELS_ICON);
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.DefaultColumnProvider#getToolTip(java.lang.Object)
*/
@Override
public String getToolTip( final VdbEntry element ) {
if (element.getSynchronization() == Synchronization.Synchronized) return SYNCHRONIZED_TOOLTIP;
if (element.getSynchronization() == Synchronization.NotSynchronized) return UNSYNCHRONIZED_TOOLTIP;
return SYNCHRONIZATION_NOT_APPLICABLE_TOOLTIP;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.ColumnProvider#getValue(java.lang.Object)
*/
@Override
public Boolean getValue( final VdbEntry element ) {
return element.getSynchronization() == Synchronization.Synchronized;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.DefaultColumnProvider#isEditable(java.lang.Object)
*/
@Override
public boolean isEditable( final VdbEntry element ) {
return element.getSynchronization() == Synchronization.NotSynchronized;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.DefaultColumnProvider#setValue(java.lang.Object, java.lang.Object)
*/
@Override
public void setValue( final VdbEntry element,
final Boolean value ) {
IPreferenceStore prefStore = VdbUiPlugin.singleton.getPreferenceStore();
// set value to true if preference not found
boolean showWarningDialog = "".equals(prefStore.getString(SYNCHRONIZE_WITHOUT_WARNING)) ? true //$NON-NLS-1$
: !prefStore.getBoolean(SYNCHRONIZE_WITHOUT_WARNING);
boolean synchronize = !showWarningDialog;
boolean okIfModelsDirty = true;
// check Workspace for Dirty Open Editors
Collection<IFile> iFiles = VdbUtil.getVdbModels(getVdb());
boolean askedQuestion = false;
for( IFile theFile : iFiles ) {
if( ModelEditorManager.isOpen(theFile) && ModelEditorManager.getModelEditorForFile(theFile, false).isDirty() ) {
askedQuestion = true;
boolean confirm = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(),
CONFIRM_DIRTY_MODELS_DIALOG_TITLE,
CONFIRM_DIRTY_MODELS_DIALOG_MESSAGE);
if (confirm) {
okIfModelsDirty = true;
} else {
okIfModelsDirty = false;
}
}
if( askedQuestion ) {
break;
}
}
boolean hasDataRoles = !getVdb().getDataRoles().isEmpty();
if (okIfModelsDirty && showWarningDialog) {
if( hasDataRoles ) {
MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(Display.getCurrent().getActiveShell(),
CONFIRM_DIALOG_TITLE,
CONFIRM_SYNCHRONIZE_MESSAGE,
VdbUiConstants.Util.getString("rememberMyDecision"), //$NON-NLS-1$
false,
null,
null);
if (dialog.getReturnCode() == IDialogConstants.OK_ID) {
synchronize = true;
// save preference
if (dialog.getToggleState()) {
try {
prefStore.setValue(SYNCHRONIZE_WITHOUT_WARNING, true);
VdbUiPlugin.singleton.getPreferences().flush();
} catch (BackingStoreException e) {
VdbUiConstants.Util.log(e);
}
}
}
} else {
synchronize = true;
}
}
if (okIfModelsDirty && synchronize) {
final Exception[] failureException = new Exception[1];
UiBusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
/**
* {@inheritDoc}
*
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
try {
element.synchronize();
} catch (Exception ex) {
failureException[0] = ex;
return;
}
dataRoleResolver.modelSynchronized(element);
VdbEditor.this.doSave(new NullProgressMonitor());
showImportVdbsButton.setEnabled(!getVdb().getImports().isEmpty());
}
});
if (failureException[0] != null)
ErrorHandler.toExceptionDialog(failureException[0]);
}
}
};
private final ISelectionStatusValidator validator = new ISelectionStatusValidator() {
/**
* {@inheritDoc}
*
* @see org.eclipse.ui.dialogs.ISelectionStatusValidator#validate(java.lang.Object[])
*/
@Override
public IStatus validate( final Object[] selection ) {
for (int ndx = selection.length; --ndx >= 0;)
if (selection[ndx] instanceof IContainer) return new Status(IStatus.ERROR, VdbUiConstants.PLUGIN_ID, 0,
ADD_FILE_DIALOG_INVALID_SELECTION_MESSAGE, null);
return new Status(IStatus.OK, VdbUiConstants.PLUGIN_ID, 0, EMPTY_STRING, null);
}
};
private final ISelectionStatusValidator modelSelectionValidator = new ISelectionStatusValidator() {
/**
* {@inheritDoc}
*
* @see org.eclipse.ui.dialogs.ISelectionStatusValidator#validate(java.lang.Object[])
*/
@Override
public IStatus validate( final Object[] selection ) {
for (int ndx = selection.length; --ndx >= 0;) {
Object obj = selection[ndx];
if (obj instanceof IContainer) {
return new Status(IStatus.ERROR, VdbUiConstants.PLUGIN_ID, 0, ADD_FILE_DIALOG_INVALID_SELECTION_MESSAGE, null);
} else if( obj instanceof IFile ) {
IFile file = (IFile)obj;
if ( !ModelUtilities.isModelFile(file) && !ModelUtil.isXsdFile(file) ) {
return new Status(IStatus.ERROR, VdbUiConstants.PLUGIN_ID, 0, ADD_FILE_DIALOG_NON_MODEL_SELECTED_MESSAGE, null);
}
if( ModelUtilities.isVdbSourceModel(file) ) {
}
// Check for duplicate model and/or user file names
if( !ModelUtil.isXsdFile(file) && VdbUtil.modelAlreadyExistsInVdb(FileUtils.getNameWithoutExtension(file), file.getFullPath(), getVdb()) ) {
return new Status(IStatus.ERROR, VdbUiConstants.PLUGIN_ID, 0,
ADD_FILE_DIALOG_MODEL_WITH_SAME_NAME_EXISTS_SELECTED_MESSAGE, null);
}
}
}
return new Status(IStatus.OK, VdbUiConstants.PLUGIN_ID, 0, EMPTY_STRING, null);
}
};
private final ISelectionStatusValidator schemaSelectionValidator = new ISelectionStatusValidator() {
/**
* {@inheritDoc}
*
* @see org.eclipse.ui.dialogs.ISelectionStatusValidator#validate(java.lang.Object[])
*/
@Override
public IStatus validate( final Object[] selection ) {
for (int ndx = selection.length; --ndx >= 0;) {
Object obj = selection[ndx];
if (obj instanceof IContainer) {
return new Status(IStatus.ERROR, VdbUiConstants.PLUGIN_ID, 0, ADD_FILE_DIALOG_INVALID_SELECTION_MESSAGE, null);
} else if( obj instanceof IFile ) {
IFile file = (IFile)obj;
if ( !ModelUtil.isXsdFile(file) ) {
return new Status(IStatus.ERROR, VdbUiConstants.PLUGIN_ID, 0, ADD_FILE_DIALOG_NON_MODEL_SELECTED_MESSAGE, null);
}
// Check for duplicate model and/or user file names
if( VdbUtil.modelAlreadyExistsInVdb(FileUtils.getNameWithoutExtension(file), file.getFullPath(), getVdb()) ) {
return new Status(IStatus.ERROR, VdbUiConstants.PLUGIN_ID, 0,
ADD_FILE_DIALOG_MODEL_WITH_SAME_NAME_EXISTS_SELECTED_MESSAGE, null); }
}
}
return new Status(IStatus.OK, VdbUiConstants.PLUGIN_ID, 0, EMPTY_STRING, null);
}
};
/**
* Method which adds models to the VDB.
*
* @param modelFiles
*/
public void addModels( final List<IFile> modelFiles ) {
try {
for (final IFile modelFile : modelFiles) {
vdb.addEntry(modelFile.getFullPath());
}
} catch (Exception ex) {
ErrorHandler.toExceptionDialog(ex);
}
modelsGroup.getTable().getViewer().refresh();
pnlTranslatorOverrides.refresh();
packModelsGroup();
showImportVdbsButton.setEnabled(!getVdb().getImports().isEmpty());
schemaGroup.getTable().getViewer().refresh();
udfJarsGroup.getTable().getViewer().refresh();
otherFilesGroup.getTable().getViewer().refresh();
}
/*
* Set the image cols to a fixed width, then use the remainder for Model Name column
*/
void packModelsGroup() {
// Set Image Col Widths
modelsGroup.getTable().getColumn(1).getColumn().setWidth(MODELS_PANEL_IMAGE_COL_WIDTH);
modelsGroup.getTable().getColumn(2).getColumn().setWidth(MODELS_PANEL_IMAGE_COL_WIDTH);
// Get Overall area width
Rectangle area = modelsGroup.getTable().getViewer().getTable().getClientArea();
int totalAreaWidth = area.width;
// Use the Minimum for ModelName Column
int col1Width = totalAreaWidth - MODELS_PANEL_IMAGE_COL_WIDTH - MODELS_PANEL_IMAGE_COL_WIDTH;
if(col1Width<MODELS_PANEL_MODELNAME_COL_WIDTH_MIN) col1Width=MODELS_PANEL_MODELNAME_COL_WIDTH_MIN;
modelsGroup.getTable().getColumn(0).getColumn().setWidth(col1Width);
}
private Composite createEditorBottom( Composite parent ) {
Composite pnlBottom = new Composite(parent, SWT.BORDER);
pnlBottom.setLayout(new GridLayout());
pnlBottom.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
CTabFolder tabFolder = WidgetFactory.createTabFolder(pnlBottom);
{ // roles tab
CTabItem rolesTab = new CTabItem(tabFolder, SWT.NONE);
rolesTab.setText(i18n("rolesTab")); //$NON-NLS-1$
rolesTab.setToolTipText(i18n("rolesTabToolTip")); //$NON-NLS-1$
Composite pnlRoles = new Composite(tabFolder, SWT.NONE);
pnlRoles.setLayout(new GridLayout());
pnlRoles.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
rolesTab.setControl(pnlRoles);
dataRolesPanel = new DataRolesPanel(pnlRoles, this);
}
{ // properties tab
CTabItem propertiesTab = new CTabItem(tabFolder, SWT.NONE);
propertiesTab.setText(i18n("propertiesTab")); //$NON-NLS-1$
propertiesTab.setToolTipText(i18n("propertiesTabToolTip")); //$NON-NLS-1$
Composite pnlProperties = new Composite(tabFolder, SWT.NONE);
pnlProperties.setLayout(new GridLayout());
pnlProperties.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
propertiesTab.setControl(pnlProperties);
propertiesPanel = new PropertiesPanel(pnlProperties, getVdb());
}
{ // properties tab
CTabItem tab = new CTabItem(tabFolder, SWT.NONE);
tab.setText(i18n("userDefinedPropertiesTab")); //$NON-NLS-1$
tab.setToolTipText(i18n("userDefinedPropertiesTabToolTip")); //$NON-NLS-1$
Composite pnlProperties = new Composite(tabFolder, SWT.NONE);
pnlProperties.setLayout(new GridLayout());
pnlProperties.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
tab.setControl(pnlProperties);
userDefinedPropertiesPanel = new UserDefinedPropertiesPanel(pnlProperties, getVdb());
}
{ // translator overrides tab
CTabItem translatorOverridesTab = new CTabItem(tabFolder, SWT.NONE);
translatorOverridesTab.setText(i18n("translatorOverridesTab")); //$NON-NLS-1$
translatorOverridesTab.setToolTipText(i18n("translatorOverridesTabToolTip")); //$NON-NLS-1$
pnlTranslatorOverrides = new TranslatorOverridesPanel(tabFolder, this.vdb);
translatorOverridesTab.setControl(pnlTranslatorOverrides);
}
tabFolder.setSelection(0);
return pnlBottom;
}
void addSelectionToVdb(VdbFolders vdbFolder, TableViewer tableViewer, String confirmOverwriteMessage) {
// userFile Selection Dialog
final Shell shell = Display.getCurrent().getActiveShell();
// Get the VDB Project
IProject vdbProject = getVdb().getSourceFile().getProject();
String fileStr = VdbFileDialogUtil.selectFile(shell, vdbProject, vdbFolder);
if(fileStr == null || fileStr.trim().isEmpty()) {
// Nothing selected so nothing to do
return;
}
// indicates if this is the first time models are being added
boolean firstTime = (tableViewer.getTable().getItemCount() == 0);
try {
// Add the VdbFileEntry for userFile to the VDB
IPath filePath = null;
File testFile = new File(fileStr);
if (testFile.exists()) {
// Absolute file path so not in the project
filePath = new Path(testFile.getAbsolutePath());
} else {
IFile file = vdbProject.getFile(new Path(fileStr));
if (file == null) {
// Cannot find the file in the project.
// Strange since its not on the file system nor in the project.
throw new Exception("File " + fileStr + " is not available to be added to the vdb"); //$NON-NLS-1$//$NON-NLS-2$
}
// Add the file through the file's project relative path since
// the project's path will be appended to it.
filePath = file.getProjectRelativePath();
}
String fileName = filePath.lastSegment();
// Check the selected file name against current entries. If duplicate name, prompt for overwrite
Collection<VdbEntry> currentFiles = getVdb().getEntries();
// Matching entry - prompt user for overwrite
if (entrySetContainsName(currentFiles, fileName)) {
// Prompt user whether to overwrite
if (ConfirmationDialog.confirm(new ConfirmationDialog(confirmOverwriteMessage))) {
// Find the matching entry
VdbEntry matchingEntry = null;
for (VdbEntry entry : currentFiles) {
String entryShortName = entry.getPathName();
if (entryShortName.equals(fileName)) {
matchingEntry = entry;
break;
}
}
// Remove the current entry
if (matchingEntry != null)
getVdb().removeEntry(matchingEntry);
// Add the selected file
getVdb().addEntry(filePath);
}
// No matching entries - safe to add the new entry
} else {
getVdb().addEntry(filePath);
}
} catch (Exception ex) {
ErrorHandler.toExceptionDialog(ex);
}
// refresh table from model
tableViewer.refresh();
// pack columns if first time a file is added
if (firstTime) {
WidgetUtil.pack(tableViewer);
}
}
void addSchemaToVdb(IStructuredSelection selection) {
final ViewerFilter filter = new ViewerFilter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object,
* java.lang.Object)
*/
@Override
public boolean select( final Viewer viewer, final Object parent, final Object element ) {
if (element instanceof IContainer) {
// Get the project for this container
IProject proj = ((IContainer)element).getProject();
// Get the VDB Project
IProject vdbProject = getVdb().getSourceFile().getProject();
// Can only add Models from the VDB Project
if(proj.isOpen() && proj.equals(vdbProject)) {
return true;
}
return false;
}
final IFile file = (IFile)element;
if (!ModelUtil.isXsdFile(file)) {
return false;
}
for (final VdbSchemaEntry schemaEntry : getVdb().getSchemaEntries())
if (file.equals(schemaEntry.findFileInWorkspace())) return false;
return true;
}
};
ModelingResourceFilter wsFilter = new ModelingResourceFilter(filter);
wsFilter.setShowHiddenProjects(false);
final Object[] schemas = WidgetUtil.showWorkspaceObjectSelectionDialog(ADD_FILE_DIALOG_TITLE,
ADD_FILE_DIALOG_MESSAGE,
true,
null,
wsFilter,
getModelSelectionValidator(),
getModelLabelProvider());
try {
// add the models
for (final Object schema : schemas) {
getVdb().addEntry(((IFile)schema).getFullPath());
}
} catch (Exception ex) {
ErrorHandler.toExceptionDialog(ex);
}
// refresh table from model
schemaGroup.getTable().getViewer().refresh();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private void createSchemaFilesControl( Composite parent ) {
final WorkbenchLabelProvider workbenchLabelProvider = new WorkbenchLabelProvider();
schemaGroup = new TableAndToolBar(parent, 1, new DefaultTableProvider<VdbSchemaEntry>() {
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.DefaultTableProvider#doubleClicked(java.lang.Object)
*/
@Override
public void doubleClicked( VdbSchemaEntry element ) {
openEditor(element);
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.TableProvider#getElements()
*/
@Override
public VdbSchemaEntry[] getElements() {
Set<VdbSchemaEntry> schemaEntries = getVdb().getSchemaEntries();
return schemaEntries.toArray(new VdbSchemaEntry[schemaEntries.size()]);
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.DefaultTableProvider#isDoubleClickSupported()
*/
@Override
public boolean isDoubleClickSupported() {
return false;
}
void openEditor( final VdbSchemaEntry entry ) {
try {
IDE.openEditor(UiUtil.getWorkbenchPage(), entry.findFileInWorkspace());
} catch (final Exception error) {
throw new RuntimeException(error);
}
}
}, new TextColumnProvider<VdbSchemaEntry>() {
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.DefaultColumnProvider#getImage(java.lang.Object)
*/
@Override
public Image getImage( final VdbSchemaEntry element ) {
return workbenchLabelProvider.getImage(element.findFileInWorkspace());
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.ColumnProvider#getImage()
*/
@Override
public Image getImage() {
return null;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.ColumnProvider#getName()
*/
@Override
public String getName() {
return SCHEMA_COLUMN_NAME;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.table.ColumnProvider#getValue(java.lang.Object)
*/
@Override
public String getValue( final VdbSchemaEntry element ) {
return element.getPathName();
}
}, this.locationInVdbColumnProvider, this.descriptionColumnProvider);
ButtonProvider addProvider = new ButtonProvider() {
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.widget.ButtonProvider#getImageDescriptor()
*/
@Override
public ImageDescriptor getImageDescriptor() {
return VdbUiPlugin.singleton.getImageDescriptor(Images.ADD_SCHEMA);
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.widget.ButtonProvider#getText()
*/
@Override
public String getText() {
return null;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.widget.ButtonProvider#getToolTip()
*/
@Override
public String getToolTip() {
return i18n("addSchemaToolTip"); //$NON-NLS-1$
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.widget.ButtonProvider#isEnabled(org.eclipse.jface.viewers.IStructuredSelection)
*/
@Override
public boolean isEnabled( IStructuredSelection selection ) {
return true;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.widget.ButtonProvider#selected(org.eclipse.jface.viewers.IStructuredSelection)
*/
@Override
public void selected( IStructuredSelection selection ) {
addSchemaToVdb(selection);
}
};
schemaGroup.add(addProvider);
ButtonProvider removeProvider = new ButtonProvider() {
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.widget.ButtonProvider#getImageDescriptor()
*/
@Override
public ImageDescriptor getImageDescriptor() {
return VdbUiPlugin.singleton.getImageDescriptor(Images.REMOVE_SCHEMA);
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.widget.ButtonProvider#getText()
*/
@Override
public String getText() {
return null;
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.widget.ButtonProvider#getToolTip()
*/
@Override
public String getToolTip() {
return i18n("removeSchemaToolTip"); //$NON-NLS-1$
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.widget.ButtonProvider#isEnabled(org.eclipse.jface.viewers.IStructuredSelection)
*/
@Override
public boolean isEnabled( IStructuredSelection selection ) {
return !selection.isEmpty();
}
/**
* {@inheritDoc}
*
* @see org.teiid.designer.ui.common.widget.ButtonProvider#selected(org.eclipse.jface.viewers.IStructuredSelection)
*/
@Override
public void selected( IStructuredSelection selection ) {
if (!ConfirmationDialog.confirm(CONFIRM_REMOVE_MESSAGE)) return;
final Set<VdbEntry> entries = new HashSet<VdbEntry>();
final Set<VdbEntry> importedBy = new HashSet<VdbEntry>();
for (final Object element : selection.toList()) {
entries.add((VdbEntry)element);
if (element instanceof VdbModelEntry)
importedBy.addAll(((VdbModelEntry)element).getImportedBy());
}
if (!importedBy.isEmpty())
importedBy.removeAll(entries);
if (!importedBy.isEmpty()) {
if (!ConfirmationDialog.confirm(new ConfirmationDialog(CONFIRM_REMOVE_IMPORTED_BY_MESSAGE) {
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.dialogs.MessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createCustomArea( final Composite parent ) {
final ListViewer viewer = new ListViewer(parent);
viewer.setContentProvider(new DefaultContentProvider());
viewer.setLabelProvider(new LabelProvider() {
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
*/
@Override
public String getText( final Object element ) {
return ((VdbEntry)element).getName().toString();
}
});
viewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
viewer.setInput(importedBy);
return viewer.getControl();
}
})) return;
entries.addAll(importedBy);
}
dataRoleResolver.modelEntriesRemoved(entries);
for (final VdbEntry entry : entries) {
getVdb().removeEntry(entry);
}
showImportVdbsButton.setEnabled(!getVdb().getImports().isEmpty());
}
};
schemaGroup.add(removeProvider);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private void createUdfJarsControl( Composite parent ) {
final WorkbenchLabelProvider workbenchLabelProvider = new WorkbenchLabelProvider();