use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class ContentPanelEditor method createControl.
@Override
protected Control createControl(Composite editPlaceholder) {
final DBDContent content = (DBDContent) valueController.getValue();
if (curStreamManager == null) {
detectStreamManager(content);
}
if (curStreamManager != null) {
try {
streamEditor = curStreamManager.getInstance().createPanelEditor(valueController);
} catch (Throwable e) {
UIUtils.showErrorDialog(editPlaceholder.getShell(), "No stream editor", "Can't create stream editor", e);
}
}
if (streamEditor == null) {
return UIUtils.createInfoLabel(editPlaceholder, "No Editor");
}
editorControl = streamEditor.createControl(valueController);
return editorControl;
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class ContentInlineEditor method extractEditorValue.
@Override
public Object extractEditorValue() {
String newValue = control.getText();
final DBDContent content = (DBDContent) valueController.getValue();
assert content != null;
try {
if (isText) {
content.updateContents(VoidProgressMonitor.INSTANCE, new StringContentStorage(newValue));
} else {
content.updateContents(VoidProgressMonitor.INSTANCE, new BytesContentStorage(newValue.getBytes(GeneralUtils.getDefaultFileEncoding()), GeneralUtils.getDefaultFileEncoding()));
}
} catch (Exception e) {
log.error(e);
}
return content;
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class ContentPanelEditor method primeEditorValue.
@Override
public void primeEditorValue(@Nullable final Object value) throws DBException {
final DBDContent content = (DBDContent) valueController.getValue();
if (content == null) {
valueController.showMessage("NULL content value. Must be DBDContent.", DBPMessageType.ERROR);
return;
}
if (streamEditor == null) {
valueController.showMessage("NULL content editor.", DBPMessageType.ERROR);
return;
}
DBeaverUI.runInUI(valueController.getValueSite().getWorkbenchWindow(), new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
streamEditor.primeEditorValue(monitor, control, content);
} catch (Throwable e) {
log.debug(e);
valueController.showMessage(e.getMessage(), DBPMessageType.ERROR);
}
}
});
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class DataExporterJSON method exportRow.
@Override
public void exportRow(DBCSession session, Object[] row) throws DBException, IOException {
if (rowNum > 0) {
out.write(",\n");
}
rowNum++;
out.write("\t{\n");
for (int i = 0; i < row.length; i++) {
DBDAttributeBinding column = columns.get(i);
String columnName = column.getName();
out.write("\t\t\"" + escapeJsonString(columnName) + "\" : ");
Object cellValue = row[i];
if (DBUtils.isNullValue(cellValue)) {
writeTextCell(null);
} else if (cellValue instanceof DBDContent) {
// Content
// Inline textual content and handle binaries in some special way
DBDContent content = (DBDContent) cellValue;
try {
DBDContentStorage cs = content.getContents(session.getProgressMonitor());
if (cs != null) {
if (ContentUtils.isTextContent(content)) {
try (Reader in = cs.getContentReader()) {
out.write("\"");
writeCellValue(in);
out.write("\"");
}
} else {
getSite().writeBinaryData(cs);
}
}
} finally {
content.release();
}
} else {
if (cellValue instanceof Number || cellValue instanceof Boolean) {
out.write(cellValue.toString());
} else if (cellValue instanceof Date && formatDateISO) {
writeTextCell(dateFormat.format(cellValue));
} else {
writeTextCell(super.getValueDisplayString(column, cellValue));
}
}
if (i < row.length - 1) {
out.write(",");
}
out.write("\n");
}
out.write("\t}");
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class StreamTransferConsumer method fetchRow.
@Override
public void fetchRow(DBCSession session, DBCResultSet resultSet) throws DBCException {
try {
// Get values
for (int i = 0; i < metaColumns.size(); i++) {
DBDAttributeBinding column = metaColumns.get(i);
Object value = column.getValueHandler().fetchValueObject(session, resultSet, column.getAttribute(), column.getOrdinalPosition());
if (value instanceof DBDContent && !settings.isOutputClipboard()) {
// Check for binary type export
if (!ContentUtils.isTextContent((DBDContent) value)) {
switch(settings.getLobExtractType()) {
case SKIP:
// Set it it null
value = null;
break;
case INLINE:
// Just pass content to exporter
break;
case FILES:
// Save content to file and pass file reference to exporter
value = saveContentToFile(session.getProgressMonitor(), (DBDContent) value);
break;
}
}
}
row[i] = value;
}
// Export row
processor.exportRow(session, row);
} catch (DBException e) {
throw new DBCException("Error while exporting table row", e);
} catch (IOException e) {
throw new DBCException("IO error", e);
}
}
Aggregations