use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class DialogUtils method saveToFile.
public static void saveToFile(IValueController controller) {
if (!(controller.getValue() instanceof DBDContent)) {
log.error(CoreMessages.model_jdbc_bad_content_value_ + controller.getValue());
return;
}
Shell shell = UIUtils.getShell(controller.getValueSite());
final File saveFile = selectFileForSave(shell, controller.getValueName());
if (saveFile == null) {
return;
}
final DBDContent value = (DBDContent) controller.getValue();
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
DBDContentStorage storage = value.getContents(monitor);
if (ContentUtils.isTextContent(value)) {
try (Reader cr = storage.getContentReader()) {
ContentUtils.saveContentToFile(cr, saveFile, GeneralUtils.UTF8_ENCODING, monitor);
}
} else {
try (InputStream cs = storage.getContentStream()) {
ContentUtils.saveContentToFile(cs, saveFile, monitor);
}
}
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
UIUtils.showErrorDialog(shell, CoreMessages.model_jdbc_could_not_save_content, //$NON-NLS-2$
CoreMessages.model_jdbc_could_not_save_content_to_file_ + saveFile.getAbsolutePath() + "'", e.getTargetException());
} catch (InterruptedException e) {
// do nothing
}
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class TextViewDialog method extractEditorValue.
@Override
public Object extractEditorValue() {
Object prevValue = getValueController().getValue();
Object rawValue;
if (prevValue instanceof DBDContent) {
if (ContentUtils.isTextContent((DBDContent) prevValue)) {
rawValue = isTextEditorActive() ? textEdit.getText() : getBinaryString();
} else {
rawValue = isTextEditorActive() ? GeneralUtils.convertToBytes(textEdit.getText()) : getBinaryContent();
}
} else {
if (isTextEditorActive()) {
rawValue = textEdit.getText();
} else {
rawValue = getBinaryString();
}
}
try (DBCSession session = getValueController().getExecutionContext().openSession(VoidProgressMonitor.INSTANCE, DBCExecutionPurpose.UTIL, "Make text value from editor")) {
return getValueController().getValueHandler().getValueFromObject(session, getValueController().getValueType(), rawValue, false);
} catch (Exception e) {
UIUtils.showErrorDialog(getShell(), "Extract editor value", "Can't extract editor value", e);
return null;
}
}
Aggregations