Lines 39-45
Link Here
|
39 |
* |
39 |
* |
40 |
* Portions Copyrighted 2009-2010 Sun Microsystems, Inc. |
40 |
* Portions Copyrighted 2009-2010 Sun Microsystems, Inc. |
41 |
*/ |
41 |
*/ |
42 |
|
|
|
43 |
package org.netbeans.modules.db.explorer.node; |
42 |
package org.netbeans.modules.db.explorer.node; |
44 |
|
43 |
|
45 |
import java.awt.datatransfer.Transferable; |
44 |
import java.awt.datatransfer.Transferable; |
Lines 80-92
Link Here
|
80 |
* @author Rob Englander |
79 |
* @author Rob Englander |
81 |
*/ |
80 |
*/ |
82 |
public class ColumnNode extends BaseNode implements SchemaNameProvider, ColumnNameProvider { |
81 |
public class ColumnNode extends BaseNode implements SchemaNameProvider, ColumnNameProvider { |
|
|
82 |
|
83 |
private static final String COLUMN = "org/netbeans/modules/db/resources/column.gif"; |
83 |
private static final String COLUMN = "org/netbeans/modules/db/resources/column.gif"; |
84 |
private static final String PRIMARY = "org/netbeans/modules/db/resources/columnPrimary.gif"; |
84 |
private static final String PRIMARY = "org/netbeans/modules/db/resources/columnPrimary.gif"; |
85 |
private static final String INDEX = "org/netbeans/modules/db/resources/columnIndex.gif"; |
85 |
private static final String INDEX = "org/netbeans/modules/db/resources/columnIndex.gif"; |
86 |
private static final String FOLDER = "Column"; //NOI18N |
86 |
private static final String FOLDER = "Column"; //NOI18N |
87 |
private static final String TOOLTIP_COLUMN = NbBundle.getMessage(ColumnNode.class, "ND_Column"); |
|
|
88 |
private static final String TOOLTIP_PRIMARY = NbBundle.getMessage(ColumnNode.class, "ND_PrimaryKey"); |
89 |
private static final String TOOLTIP_INDEX = NbBundle.getMessage(ColumnNode.class, "ND_Index"); |
90 |
private static final Logger LOG = Logger.getLogger(ColumnNode.class.getName()); |
87 |
private static final Logger LOG = Logger.getLogger(ColumnNode.class.getName()); |
91 |
|
88 |
|
92 |
/** |
89 |
/** |
Lines 100-110
Link Here
|
100 |
node.setup(); |
97 |
node.setup(); |
101 |
return node; |
98 |
return node; |
102 |
} |
99 |
} |
103 |
|
|
|
104 |
private String name = ""; // NOI18N |
100 |
private String name = ""; // NOI18N |
105 |
private String icon; |
101 |
private String icon; |
106 |
/** Description used for tooltip. */ |
102 |
/** Description used for tooltip. */ |
107 |
private String description = TOOLTIP_COLUMN; |
103 |
private String description = ""; |
108 |
private final MetadataElementHandle<Column> columnHandle; |
104 |
private final MetadataElementHandle<Column> columnHandle; |
109 |
private final DatabaseConnection connection; |
105 |
private final DatabaseConnection connection; |
110 |
private boolean isTableColumn = true; |
106 |
private boolean isTableColumn = true; |
Lines 134-215
Link Here
|
134 |
try { |
130 |
try { |
135 |
metaDataModel.runReadAction( |
131 |
metaDataModel.runReadAction( |
136 |
new Action<Metadata>() { |
132 |
new Action<Metadata>() { |
|
|
133 |
|
137 |
@Override |
134 |
@Override |
138 |
public void run(Metadata metaData) { |
135 |
public void run(Metadata metaData) { |
|
|
136 |
boolean isPartOfPrimaryKey = false; |
137 |
boolean isPartOfIndex = false; |
139 |
Column column = columnHandle.resolve(metaData); |
138 |
Column column = columnHandle.resolve(metaData); |
140 |
if (column != null) { |
139 |
if (column != null) { |
141 |
name = column.getName(); |
140 |
name = column.getName(); |
142 |
icon = COLUMN; |
141 |
icon = COLUMN; |
143 |
|
142 |
|
144 |
updateProperties(column); |
|
|
145 |
|
146 |
Tuple tuple = column.getParent(); |
143 |
Tuple tuple = column.getParent(); |
147 |
if (tuple instanceof Table) { |
144 |
if (tuple instanceof Table) { |
148 |
Table table = (Table)tuple; |
145 |
Table table = (Table) tuple; |
149 |
PrimaryKey pkey = table.getPrimaryKey(); |
146 |
PrimaryKey pkey = table.getPrimaryKey(); |
150 |
|
147 |
|
151 |
boolean found = false; |
|
|
152 |
if (pkey != null) { |
148 |
if (pkey != null) { |
153 |
Collection<Column> columns = pkey.getColumns(); |
149 |
Collection<Column> columns = pkey.getColumns(); |
154 |
for (Column c : columns) { |
150 |
for (Column c : columns) { |
155 |
if (c != null && column.getName().equals(c.getName())) { |
151 |
if (c != null && column.getName().equals(c.getName())) { |
156 |
found = true; |
|
|
157 |
icon = PRIMARY; |
152 |
icon = PRIMARY; |
158 |
description = TOOLTIP_PRIMARY; |
153 |
isPartOfPrimaryKey = true; |
159 |
break; |
154 |
break; |
160 |
} |
155 |
} |
161 |
} |
156 |
} |
162 |
} |
157 |
} |
163 |
|
158 |
|
164 |
if (!found) { |
|
|
165 |
Collection<Index> indexes = table.getIndexes(); |
159 |
Collection<Index> indexes = table.getIndexes(); |
166 |
for (Index index : indexes) { |
160 |
for (Index index : indexes) { |
167 |
Collection<IndexColumn> columns = index.getColumns(); |
161 |
Collection<IndexColumn> columns = index.getColumns(); |
168 |
for (IndexColumn c : columns) { |
162 |
for (IndexColumn c : columns) { |
169 |
if (c.getName().equals(column.getName())) { |
163 |
if (c.getName().equals(column.getName())) { |
170 |
found = true; |
164 |
if (!isPartOfPrimaryKey) { |
171 |
icon = INDEX; |
165 |
icon = INDEX; |
172 |
description = TOOLTIP_INDEX; |
|
|
173 |
break; |
174 |
} |
166 |
} |
|
|
167 |
isPartOfIndex = true; |
168 |
break; |
175 |
} |
169 |
} |
176 |
} |
170 |
} |
177 |
} |
171 |
} |
|
|
172 |
isTableColumn = true; |
178 |
} else { |
173 |
} else { |
179 |
isTableColumn = false; |
174 |
isTableColumn = false; |
180 |
} |
175 |
} |
|
|
176 |
|
177 |
updateProperties(column, isPartOfPrimaryKey, isPartOfIndex); |
181 |
} |
178 |
} |
182 |
} |
179 |
} |
183 |
} |
180 |
}); |
184 |
); |
|
|
185 |
} catch (MetadataModelException e) { |
181 |
} catch (MetadataModelException e) { |
186 |
NodeRegistry.handleMetadataModelException(this.getClass(), connection, e, true); |
182 |
NodeRegistry.handleMetadataModelException(this.getClass(), connection, e, true); |
187 |
} |
183 |
} |
188 |
} |
184 |
} |
189 |
} |
185 |
} |
190 |
|
186 |
|
191 |
private void updateProperties(Column column) { |
187 |
private void updateProperties(Column column, boolean isPartOfPrimaryKey, boolean isPartOfIndex) { |
192 |
PropertySupport.Name ps = new PropertySupport.Name(this); |
188 |
PropertySupport.Name ps = new PropertySupport.Name(this); |
193 |
addProperty(ps); |
189 |
addProperty(ps); |
194 |
|
190 |
|
195 |
assert column != null : "Column " + this + " cannot be null."; |
191 |
assert column != null : "Column " + this + " cannot be null."; |
196 |
if (column == null) { |
192 |
if (column == null) { |
197 |
return ; |
193 |
return; |
198 |
} |
194 |
} |
199 |
|
195 |
|
200 |
try { |
196 |
try { |
201 |
addProperty(NULL, NULLDESC, Boolean.class, false, column.getNullable() == Nullable.NULLABLE); |
197 |
addProperty(NULL, NULLDESC, Boolean.class, false, column.getNullable() == Nullable.NULLABLE); |
|
|
198 |
|
202 |
if (column.getType() != null) { |
199 |
if (column.getType() != null) { |
203 |
addProperty(DATATYPE, DATATYPEDESC, String.class, false, column.getType().toString()); |
200 |
addProperty(DATATYPE, DATATYPEDESC, String.class, false, column.getType().toString()); |
204 |
} |
201 |
} |
205 |
|
202 |
|
206 |
int len = column.getLength(); |
203 |
int len = column.getLength(); |
|
|
204 |
|
207 |
if (len == 0) { |
205 |
if (len == 0) { |
208 |
len = column.getPrecision(); |
206 |
len = column.getPrecision(); |
209 |
} |
207 |
} |
|
|
208 |
|
210 |
addProperty(COLUMNSIZE, COLUMNSIZEDESC, Integer.class, false, len); |
209 |
addProperty(COLUMNSIZE, COLUMNSIZEDESC, Integer.class, false, len); |
211 |
addProperty(DIGITS, DIGITSDESC, Short.class, false, column.getScale()); |
210 |
addProperty(DIGITS, DIGITSDESC, Short.class, false, column.getScale()); |
212 |
addProperty(POSITION, POSITIONDESC, Integer.class, false, column.getPosition()); |
211 |
addProperty(POSITION, POSITIONDESC, Integer.class, false, column.getPosition()); |
|
|
212 |
addProperty(PKPART, PKPARTDESC, Boolean.class, false, isPartOfPrimaryKey); |
213 |
addProperty(INDEXPART, INDEXPARTDESC, Boolean.class, false, isPartOfIndex); |
214 |
|
215 |
StringBuilder strBuf = new StringBuilder("<html>"); |
216 |
strBuf.append("<table border=0 cellspacing=0 cellpadding=0 >") |
217 |
.append("<tr> <td colspan='2'> <b>") |
218 |
.append(getName()) |
219 |
.append("</b></td></tr>") |
220 |
.append("<tr><td> ") |
221 |
.append(NbBundle.getMessage(BaseNode.class, TYPE)) |
222 |
.append("</td><td> : <b>") |
223 |
.append(column.getType()) |
224 |
.append("</b></td></tr>") |
225 |
.append("<tr><td> ") |
226 |
.append(NbBundle.getMessage(BaseNode.class, COLUMNSIZE)) |
227 |
.append("</td><td> : <b>") |
228 |
.append(len) |
229 |
.append("</b></td></tr>") |
230 |
.append("<tr><td> ") |
231 |
.append(NbBundle.getMessage(BaseNode.class, DIGITS)) |
232 |
.append("</td><td> : <b>") |
233 |
.append(column.getScale()) |
234 |
.append("</b></td></tr>") |
235 |
.append("<tr><td> ") |
236 |
.append(NbBundle.getMessage(BaseNode.class, PKPART)) |
237 |
.append("</td><td> : <b>") |
238 |
.append(isPartOfPrimaryKey) |
239 |
.append("</b></td></tr>") |
240 |
.append("<tr><td> ") |
241 |
.append(NbBundle.getMessage(BaseNode.class, INDEXPART)) |
242 |
.append("</td><td> : <b>") |
243 |
.append(isPartOfIndex) |
244 |
.append("</b></td></tr>") |
245 |
.append("<tr><td> ") |
246 |
.append(NbBundle.getMessage(BaseNode.class, POSITION)) |
247 |
.append("</td><td> : <b>") |
248 |
.append(column.getPosition()) |
249 |
.append("</b></td></tr>") |
250 |
.append("</table></html>") |
251 |
; |
252 |
description = strBuf.toString(); |
213 |
} catch (Exception e) { |
253 |
} catch (Exception e) { |
214 |
LOG.log(Level.INFO, e.getMessage(), e); |
254 |
LOG.log(Level.INFO, e.getMessage(), e); |
215 |
} |
255 |
} |
Lines 248-253
Link Here
|
248 |
try { |
288 |
try { |
249 |
metaDataModel.runReadAction( |
289 |
metaDataModel.runReadAction( |
250 |
new Action<Metadata>() { |
290 |
new Action<Metadata>() { |
|
|
291 |
|
251 |
@Override |
292 |
@Override |
252 |
public void run(Metadata metaData) { |
293 |
public void run(Metadata metaData) { |
253 |
Column column = columnHandle.resolve(metaData); |
294 |
Column column = columnHandle.resolve(metaData); |
Lines 255-262
Link Here
|
255 |
array[0] = column.getPosition(); |
296 |
array[0] = column.getPosition(); |
256 |
} |
297 |
} |
257 |
} |
298 |
} |
258 |
} |
299 |
}); |
259 |
); |
|
|
260 |
} catch (MetadataModelException e) { |
300 |
} catch (MetadataModelException e) { |
261 |
NodeRegistry.handleMetadataModelException(this.getClass(), connection, e, true); |
301 |
NodeRegistry.handleMetadataModelException(this.getClass(), connection, e, true); |
262 |
} |
302 |
} |
Lines 284-290
Link Here
|
284 |
LOG.log(Level.INFO, e.getMessage(), e); |
324 |
LOG.log(Level.INFO, e.getMessage(), e); |
285 |
} |
325 |
} |
286 |
|
326 |
|
287 |
SystemAction.get(RefreshAction.class).performAction(new Node[] { getParentNode() }); |
327 |
SystemAction.get(RefreshAction.class).performAction(new Node[]{getParentNode()}); |
288 |
} |
328 |
} |
289 |
|
329 |
|
290 |
@Override |
330 |
@Override |
Lines 321-326
Link Here
|
321 |
public Transferable clipboardCopy() throws IOException { |
361 |
public Transferable clipboardCopy() throws IOException { |
322 |
ExTransferable result = ExTransferable.create(super.clipboardCopy()); |
362 |
ExTransferable result = ExTransferable.create(super.clipboardCopy()); |
323 |
result.put(new ExTransferable.Single(DatabaseMetaDataTransfer.COLUMN_FLAVOR) { |
363 |
result.put(new ExTransferable.Single(DatabaseMetaDataTransfer.COLUMN_FLAVOR) { |
|
|
364 |
|
324 |
@Override |
365 |
@Override |
325 |
protected Object getData() { |
366 |
protected Object getData() { |
326 |
return DatabaseMetaDataTransferAccessor.DEFAULT.createColumnData(connection.getDatabaseConnection(), |
367 |
return DatabaseMetaDataTransferAccessor.DEFAULT.createColumnData(connection.getDatabaseConnection(), |
Lines 342-351
Link Here
|
342 |
|
383 |
|
343 |
public static String getColumnName(DatabaseConnection connection, final MetadataElementHandle<Column> handle) { |
384 |
public static String getColumnName(DatabaseConnection connection, final MetadataElementHandle<Column> handle) { |
344 |
MetadataModel metaDataModel = connection.getMetadataModel(); |
385 |
MetadataModel metaDataModel = connection.getMetadataModel(); |
345 |
final String[] array = { null }; |
386 |
final String[] array = {null}; |
346 |
try { |
387 |
try { |
347 |
metaDataModel.runReadAction( |
388 |
metaDataModel.runReadAction( |
348 |
new Action<Metadata>() { |
389 |
new Action<Metadata>() { |
|
|
390 |
|
349 |
@Override |
391 |
@Override |
350 |
public void run(Metadata metaData) { |
392 |
public void run(Metadata metaData) { |
351 |
Column column = handle.resolve(metaData); |
393 |
Column column = handle.resolve(metaData); |
Lines 353-360
Link Here
|
353 |
array[0] = column.getName(); |
395 |
array[0] = column.getName(); |
354 |
} |
396 |
} |
355 |
} |
397 |
} |
356 |
} |
398 |
}); |
357 |
); |
|
|
358 |
} catch (MetadataModelException e) { |
399 |
} catch (MetadataModelException e) { |
359 |
NodeRegistry.handleMetadataModelException(ColumnNode.class, connection, e, true); |
400 |
NodeRegistry.handleMetadataModelException(ColumnNode.class, connection, e, true); |
360 |
} |
401 |
} |
Lines 364-374
Link Here
|
364 |
|
405 |
|
365 |
public static String getParentName(DatabaseConnection connection, final MetadataElementHandle<Column> handle) { |
406 |
public static String getParentName(DatabaseConnection connection, final MetadataElementHandle<Column> handle) { |
366 |
MetadataModel metaDataModel = connection.getMetadataModel(); |
407 |
MetadataModel metaDataModel = connection.getMetadataModel(); |
367 |
final String[] array = { null }; |
408 |
final String[] array = {null}; |
368 |
|
409 |
|
369 |
try { |
410 |
try { |
370 |
metaDataModel.runReadAction( |
411 |
metaDataModel.runReadAction( |
371 |
new Action<Metadata>() { |
412 |
new Action<Metadata>() { |
|
|
413 |
|
372 |
@Override |
414 |
@Override |
373 |
public void run(Metadata metaData) { |
415 |
public void run(Metadata metaData) { |
374 |
Column column = handle.resolve(metaData); |
416 |
Column column = handle.resolve(metaData); |
Lines 376-383
Link Here
|
376 |
array[0] = column.getParent().getName(); |
418 |
array[0] = column.getParent().getName(); |
377 |
} |
419 |
} |
378 |
} |
420 |
} |
379 |
} |
421 |
}); |
380 |
); |
|
|
381 |
} catch (MetadataModelException e) { |
422 |
} catch (MetadataModelException e) { |
382 |
NodeRegistry.handleMetadataModelException(ColumnNode.class, connection, e, true); |
423 |
NodeRegistry.handleMetadataModelException(ColumnNode.class, connection, e, true); |
383 |
} |
424 |
} |
Lines 392-397
Link Here
|
392 |
try { |
433 |
try { |
393 |
metaDataModel.runReadAction( |
434 |
metaDataModel.runReadAction( |
394 |
new Action<Metadata>() { |
435 |
new Action<Metadata>() { |
|
|
436 |
|
395 |
@Override |
437 |
@Override |
396 |
public void run(Metadata metaData) { |
438 |
public void run(Metadata metaData) { |
397 |
Column column = handle.resolve(metaData); |
439 |
Column column = handle.resolve(metaData); |
Lines 399-406
Link Here
|
399 |
array[0] = column.getParent().getParent().getName(); |
441 |
array[0] = column.getParent().getParent().getName(); |
400 |
} |
442 |
} |
401 |
} |
443 |
} |
402 |
} |
444 |
}); |
403 |
); |
|
|
404 |
} catch (MetadataModelException e) { |
445 |
} catch (MetadataModelException e) { |
405 |
NodeRegistry.handleMetadataModelException(ColumnNode.class, connection, e, true); |
446 |
NodeRegistry.handleMetadataModelException(ColumnNode.class, connection, e, true); |
406 |
} |
447 |
} |
Lines 415-420
Link Here
|
415 |
try { |
456 |
try { |
416 |
metaDataModel.runReadAction( |
457 |
metaDataModel.runReadAction( |
417 |
new Action<Metadata>() { |
458 |
new Action<Metadata>() { |
|
|
459 |
|
418 |
@Override |
460 |
@Override |
419 |
public void run(Metadata metaData) { |
461 |
public void run(Metadata metaData) { |
420 |
Column column = handle.resolve(metaData); |
462 |
Column column = handle.resolve(metaData); |
Lines 422-434
Link Here
|
422 |
array[0] = column.getParent().getParent().getParent().getName(); |
464 |
array[0] = column.getParent().getParent().getParent().getName(); |
423 |
} |
465 |
} |
424 |
} |
466 |
} |
425 |
} |
467 |
}); |
426 |
); |
|
|
427 |
} catch (MetadataModelException e) { |
468 |
} catch (MetadataModelException e) { |
428 |
NodeRegistry.handleMetadataModelException(ColumnNode.class, connection, e, true); |
469 |
NodeRegistry.handleMetadataModelException(ColumnNode.class, connection, e, true); |
429 |
} |
470 |
} |
430 |
|
471 |
|
431 |
return array[0]; |
472 |
return array[0]; |
432 |
} |
473 |
} |
433 |
|
|
|
434 |
} |
474 |
} |