-
Notifications
You must be signed in to change notification settings - Fork 49
/
EditColumnDialog.java
286 lines (248 loc) · 8.4 KB
/
EditColumnDialog.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
/*
* 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.editors;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.query.proc.ITeiidXmlColumnInfo;
import org.teiid.designer.relational.model.RelationalColumn;
import org.teiid.designer.transformation.ui.Messages;
import org.teiid.designer.transformation.ui.UiConstants;
import org.teiid.designer.transformation.ui.UiPlugin;
import org.teiid.designer.type.IDataTypeManagerService;
import org.teiid.designer.ui.common.util.WidgetFactory;
/**
*
*/
public class EditColumnDialog extends TitleAreaDialog {
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
// =============================================================
// Instance variables
// =============================================================
RelationalColumn column;
// =============================================================
// Constructors
// =============================================================
/**
*
* @param parent
* the parent shell
* @param resultSetLabel
* @param editingColumnInformation
* @param relationalViewProcedure
* the columnInfo table object
*/
public EditColumnDialog(Shell parent, RelationalColumn column) {
super(parent);
this.column = column;
}
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setText(Messages.EditColumnTitle);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.window.Window#setShellStyle(int)
*/
@Override
protected void setShellStyle(int newShellStyle) {
super.setShellStyle(newShellStyle | SWT.RESIZE | SWT.MAX);
}
// =============================================================
// Instance methods
// =============================================================
@Override
protected Control createDialogArea(Composite parent) {
setTitle(Messages.EditColumnTitle);
setMessage(NLS.bind(Messages.EditingColumnInformation, column.getName()), IMessageProvider.INFORMATION);
Composite dialogComposite = (Composite) super.createDialogArea(parent);
Composite composite = WidgetFactory.createPanel(dialogComposite);
// ------------------------------
// Set layout for the Composite
// ------------------------------
GridLayout gridLayout = new GridLayout();
composite.setLayout(gridLayout);
gridLayout.numColumns = 2;
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.grabExcessHorizontalSpace = true;
gridData.widthHint = 500;
composite.setLayoutData(gridData);
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = GridData.FILL;
// ------------------------------
// Column Name
// ------------------------------
Label label = new Label(composite, SWT.NONE | SWT.SINGLE);
label.setText(Messages.Name);
label.setLayoutData(new GridData());
final Text columnNameText = new Text(composite, SWT.BORDER | SWT.NONE);
columnNameText.setText(column.getName());
columnNameText.setForeground(Display.getCurrent().getSystemColor(
SWT.COLOR_DARK_BLUE));
columnNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
columnNameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent event) {
String value = columnNameText.getText();
if (value == null) {
value = EMPTY_STRING;
}
column.setName(value);
validate();
}
});
// ------------------------------
// Data type dropdown
// ------------------------------
Label datatype = new Label(composite, SWT.BORDER | SWT.NONE);
datatype.setText(Messages.dataTypeLabel);
datatype.setLayoutData(new GridData());
final Combo datatypeCombo = new Combo(composite,
SWT.NONE);
datatypeCombo.setForeground(Display.getCurrent().getSystemColor(
SWT.COLOR_DARK_BLUE));
datatypeCombo.setLayoutData(new GridData(SWT.LEFT, SWT.LEFT, true, true));
IDataTypeManagerService service = ModelerCore.getTeiidDataTypeManagerService();
Set<String> unsortedDatatypes = service.getAllDataTypeNames();
Collection<String> dTypes = new ArrayList<String>();
String[] sortedStrings = unsortedDatatypes.toArray(new String[unsortedDatatypes.size()]);
Arrays.sort(sortedStrings);
for( String dType : sortedStrings ) {
dTypes.add(dType);
}
String[] datatypes = dTypes.toArray(new String[dTypes.size()]);
datatypeCombo.setItems(datatypes);
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(datatypeCombo);
datatypeCombo.setText(column.getDatatype());
datatypeCombo.redraw();
datatypeCombo.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent event) {
column.setDatatype(datatypeCombo.getText());
validate();
}
});
// ------------------------------
// Length value
// ------------------------------
Label label1 = new Label(composite, SWT.NONE | SWT.SINGLE);
label1.setText(Messages.lengthLabel);
label1.setLayoutData(new GridData());
final Text lengthValueText = new Text(composite, SWT.BORDER | SWT.NONE);
lengthValueText.setText(String.valueOf(column.getLength()));
lengthValueText.setForeground(Display.getCurrent().getSystemColor(
SWT.COLOR_DARK_BLUE));
lengthValueText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
lengthValueText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent event) {
String value = lengthValueText.getText();
if (value == null) {
value = EMPTY_STRING;
}
column.setLength(Integer.parseInt(value));
validate();
}
});
return composite;
}
private void validate() {
boolean enable = true;
getButton(IDialogConstants.OK_ID).setEnabled(enable);
}
@Override
public void create() {
super.create();
getButton(IDialogConstants.OK_ID).setEnabled(true);
}
@Override
protected void okPressed() {
super.okPressed();
}
class ColumnDataLabelProvider extends ColumnLabelProvider {
private final int columnNumber;
public ColumnDataLabelProvider(int columnNumber) {
this.columnNumber = columnNumber;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(Object element) {
if (element instanceof ITeiidXmlColumnInfo) {
switch (this.columnNumber) {
case 0: {
return ((ITeiidXmlColumnInfo) element).getName();
}
case 1: {
return Boolean.toString(((ITeiidXmlColumnInfo) element)
.getOrdinality());
}
case 2: {
return ((ITeiidXmlColumnInfo) element).getDatatype();
}
case 3: {
return (((ITeiidXmlColumnInfo) element).getRelativePath());
}
}
}
return EMPTY_STRING;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
*/
@Override
public String getToolTipText(Object element) {
switch (this.columnNumber) {
case 0: {
return "Tooltip 1"; //getString("columnNameColumnTooltip"); //$NON-NLS-1$
}
case 1: {
return "Tooltip 2"; //getString("datatypeColumnTooltip"); //$NON-NLS-1$
}
}
return "unknown tooltip"; //$NON-NLS-1$
}
@Override
public Image getImage(Object element) {
if (this.columnNumber == 0) {
return UiPlugin.getDefault().getImage(
UiConstants.Images.COLUMN_ICON);
}
return null;
}
}
}