/
PreviewDataInputDialog.java
270 lines (213 loc) · 8.42 KB
/
PreviewDataInputDialog.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
package org.teiid.designer.runtime.ui.preview;
import java.util.Properties;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.source.VerticalRuler;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.teiid.designer.runtime.ui.DqpUiConstants;
import org.teiid.designer.runtime.ui.Messages;
import org.teiid.designer.transformation.ui.editors.sqleditor.SqlTextViewer;
import org.teiid.designer.ui.common.graphics.ColorManager;
import org.teiid.designer.ui.common.util.WidgetFactory;
import org.teiid.designer.ui.explorer.ModelExplorerLabelProvider;
public class PreviewDataInputDialog extends TitleAreaDialog implements DqpUiConstants {
private EObject previewableEObject;
private ILabelProvider labelProvider = new ModelExplorerLabelProvider();
// Table SQL Text Tab Controls
private SqlTextViewer sqlTextViewer;
private Document sqlDocument;
private TabItem sqlTab;
private TabItem vdbXmlTab;
private StyledText xmlContentsBox;
Properties designerProperties;
private Font monospaceFont;
String sqlText;
String dynVdbXml;
/**
* @since 5.5.3
*/
public PreviewDataInputDialog(Shell parentShell, String initialSQL, String dynVdbXml) {
super(parentShell);
setShellStyle(getShellStyle() | SWT.RESIZE);
this.sqlText = initialSQL;
this.dynVdbXml = dynVdbXml;
}
/**
* @since 5.5.3
*/
public PreviewDataInputDialog(Shell parentShell, Properties properties, String initialSQL, String dynVdbXml) {
this(parentShell, initialSQL, dynVdbXml);
this.designerProperties = properties;
}
/**
* @see org.eclipse.jface.dialogs.Dialog#close()
* @since 5.5.3
*/
@Override
public boolean close() {
if (this.labelProvider != null) {
this.labelProvider.dispose();
}
return super.close();
}
/**
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
* @since 5.5.3
*/
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setText("Custom Preview Data"); //$NON-NLS-1$
}
/**
* @see org.eclipse.jface.dialogs.Dialog#createButtonBar(org.eclipse.swt.widgets.Composite)
* @since 5.5.3
*/
@Override
protected Control createButtonBar(Composite parent) {
Control buttonBar = super.createButtonBar(parent);
getButton(OK).setEnabled(true);
// set the first selection so that initial validation state is set
// (doing it here since the selection handler uses OK
// button)
return buttonBar;
}
/**
* @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
* @since 5.5.3
*/
@Override
protected Control createDialogArea(Composite parent) {
monospaceFont(parent);
Composite pnlOuter = (Composite) super.createDialogArea(parent);
GridLayoutFactory.fillDefaults().numColumns(1).margins(10, 10).applyTo(pnlOuter);
GridDataFactory.fillDefaults().grab(true, true).applyTo(pnlOuter);
// set title
setTitle(Messages.PreviewDataInputDialog_title);
setMessage(Messages.PreviewDataInputDialog_initialMessage);
TabFolder folder = createTabFolder(pnlOuter);
createSQLTab(folder);
createVdbXmlTabTab(folder);
return pnlOuter;
}
@Override
protected Control createContents(Composite parent) {
Control control = super.createContents(parent);
return control;
}
public EObject getPreviewableEObject() {
return this.previewableEObject;
}
protected TabFolder createTabFolder(Composite parent) {
TabFolder tabFolder = new TabFolder(parent, SWT.TOP | SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, true).applyTo(tabFolder);
return tabFolder;
}
/*
* Create the SQL Tab
*/
private void createSQLTab( TabFolder folderParent ) {
Composite thePanel = createSQLPanel(folderParent);
this.sqlTab = new TabItem(folderParent, SWT.NONE);
this.sqlTab.setControl(thePanel);
this.sqlTab.setText(Messages.PreviewDataInputDialog_previewSqlLabel);
}
/*
* Create the SQL Display tab panel
*/
private Composite createSQLPanel( Composite parent ) {
Composite thePanel = WidgetFactory.createPanel(parent, SWT.NONE, 1, 1);
GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(thePanel);
GridDataFactory.fillDefaults().grab(true, true).applyTo(thePanel);
createSqlGroup(thePanel);
return thePanel;
}
/*
* The SQL Display area portion of the SQL Tab
*/
private void createSqlGroup( Composite parent ) {
Group textTableOptionsGroup = WidgetFactory.createGroup(parent, Messages.PreviewDataInputDialog_sqlQueryLabel, SWT.NONE, 2, 1);
GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(textTableOptionsGroup);
ColorManager colorManager = new ColorManager();
int styles = SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.FULL_SELECTION ;
sqlTextViewer = new SqlTextViewer(textTableOptionsGroup, new VerticalRuler(0), styles, colorManager);
sqlDocument = new Document();
sqlTextViewer.setInput(sqlDocument);
sqlTextViewer.getTextWidget().setFont(monospaceFont);
sqlTextViewer.getTextWidget().addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
sqlText = sqlTextViewer.getTextWidget().getText();
}
});
sqlTextViewer.setEditable(true);
sqlDocument.set(this.sqlText);
GridDataFactory.fillDefaults().grab(true, true).applyTo(sqlTextViewer.getControl());
}
public String getSQL() {
return sqlText;
}
/*
* Create the SQL Tab
*/
private void createVdbXmlTabTab( TabFolder folderParent ) {
Composite thePanel = createVdbXmlPanel(folderParent);
this.vdbXmlTab = new TabItem(folderParent, SWT.NONE);
this.vdbXmlTab.setControl(thePanel);
this.vdbXmlTab.setText(Messages.PreviewDataInputDialog_previewXMLLabel);
}
/*
* Create the SQL Display tab panel
*/
private Composite createVdbXmlPanel( Composite parent ) {
Composite thePanel = WidgetFactory.createPanel(parent, SWT.NONE, 1, 1);
GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(thePanel);
GridDataFactory.fillDefaults().grab(true, true).applyTo(thePanel);
createXMLDisplayGroup(thePanel);
return thePanel;
}
/*
* Create the Group containing the DDL Contents (not editable)
*/
private void createXMLDisplayGroup(Composite parent) {
Group theGroup = WidgetFactory.createGroup(parent, Messages.PreviewDataInputDialog_previewDynamicVdbXmlTabLabel, GridData.FILL_BOTH, 1);
GridLayoutFactory.fillDefaults().numColumns(1).equalWidth(false).margins(10, 10).applyTo(theGroup);
GridDataFactory.fillDefaults().grab(true, true).applyTo(theGroup);
xmlContentsBox = new StyledText(theGroup, SWT.READ_ONLY | SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
GridDataFactory.fillDefaults().grab(true, true).hint(400, 300).applyTo(xmlContentsBox);
xmlContentsBox.setEditable(false);
xmlContentsBox.setFont(monospaceFont);
xmlContentsBox.setText(this.dynVdbXml);
}
private Font monospaceFont(Composite composite) {
if (monospaceFont == null) {
monospaceFont = new Font(composite.getDisplay(), "Monospace", 12, SWT.NORMAL); //$NON-NLS-1$
composite.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (monospaceFont == null)
return;
monospaceFont.dispose();
}
});
}
return monospaceFont;
}
}