use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by dbeaver.
the class ContentEditorInput method updateContentFromFile.
public void updateContentFromFile(DBRProgressMonitor monitor, Object value) throws DBException {
if (valueController.isReadOnly()) {
throw new DBCException("Can't update read-only value");
}
if (value instanceof DBDContent) {
DBDContent content = (DBDContent) value;
DBDContentStorage storage = content.getContents(monitor);
if (storage instanceof DBDContentStorageLocal) {
// Nothing to update - we use content's storage
content.updateContents(monitor, storage);
contentDetached = true;
} else if (storage instanceof DBDContentCached) {
// Create new storage and pass it to content
try (FileInputStream is = new FileInputStream(contentFile)) {
if (ContentUtils.isTextContent(content)) {
try (Reader reader = new InputStreamReader(is, fileCharset)) {
storage = StringContentStorage.createFromReader(reader);
}
} else {
storage = BytesContentStorage.createFromStream(is, contentFile.length(), fileCharset);
}
// StringContentStorage.
contentDetached = content.updateContents(monitor, storage);
} catch (IOException e) {
throw new DBException("Error reading content from file", e);
}
} else {
// Create new storage and pass it to content
storage = new TemporaryContentStorage(DBWorkbench.getPlatform(), contentFile, fileCharset);
contentDetached = content.updateContents(monitor, storage);
}
} else if (stringStorage != null) {
// Just read as string
valueController.updateValue(stringStorage.getString(), false);
contentDetached = true;
}
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by dbeaver.
the class AbstractTextPanelEditor method extractEditorValue.
@Override
public void extractEditorValue(@NotNull DBRProgressMonitor monitor, @NotNull StyledText control, @NotNull DBDContent value) throws DBException {
if (valueController.getValue() instanceof DBDContent) {
monitor.beginTask("Extract text", 1);
try {
monitor.subTask("Extracting text from editor");
editor.doSave(RuntimeUtils.getNestedMonitor(monitor));
final IEditorInput editorInput = editor.getEditorInput();
if (editorInput instanceof ContentEditorInput) {
final ContentEditorInput contentEditorInput = (ContentEditorInput) editorInput;
contentEditorInput.updateContentFromFile(monitor, value);
}
} catch (Exception e) {
throw new DBException("Error extracting text from editor", e);
} finally {
monitor.done();
}
} else {
value.updateContents(monitor, new StringContentStorage(control.getText()));
}
}
Aggregations