use of org.jkiss.dbeaver.model.impl.StringContentStorage in project dbeaver by serge-rider.
the class TextPanelEditor method extractEditorValue.
@Override
public void extractEditorValue(@NotNull DBRProgressMonitor monitor, @NotNull StyledText control, @NotNull DBDContent value) throws DBException {
monitor.subTask("Read text value");
value.updateContents(monitor, new StringContentStorage(control.getText()));
}
use of org.jkiss.dbeaver.model.impl.StringContentStorage 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.impl.StringContentStorage in project dbeaver by serge-rider.
the class ContentEditorInput method updateContentFromFile.
public void updateContentFromFile(IProgressMonitor monitor) throws DBException {
if (valueController.isReadOnly()) {
throw new DBCException("Can't update read-only value");
}
DBRProgressMonitor localMonitor = RuntimeUtils.makeMonitor(monitor);
DBDContent content = getContent();
DBDContentStorage storage = content.getContents(localMonitor);
if (storage instanceof DBDContentStorageLocal) {
// Nothing to update - we user content's storage
contentDetached = true;
} else if (storage instanceof DBDContentCached) {
// Create new storage and pass it to content
try (FileInputStream is = new FileInputStream(contentFile)) {
if (storage instanceof StringContentStorage) {
try (Reader reader = new InputStreamReader(is, fileCharset)) {
storage = StringContentStorage.createFromReader(reader);
}
} else {
storage = BytesContentStorage.createFromStream(is, contentFile.length(), fileCharset);
}
//StringContentStorage.
contentDetached = content.updateContents(localMonitor, 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(DBeaverCore.getInstance(), contentFile, fileCharset);
contentDetached = content.updateContents(localMonitor, storage);
}
}
Aggregations