提交 d960e4c1 编写于 作者: H halitanildonmez

fixing tab indents, removing the extra dialog, fix imports

上级 bf3c06d1
......@@ -16,7 +16,6 @@
*/
package org.jkiss.dbeaver.ui.data.managers;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.action.Separator;
......@@ -29,10 +28,7 @@ import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.DBPMessageType;
import org.jkiss.dbeaver.model.DBValueFormatting;
import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.data.DBDContentCached;
import org.jkiss.dbeaver.model.data.DBDContentStorage;
import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
import org.jkiss.dbeaver.model.data.*;
import org.jkiss.dbeaver.model.data.storage.ExternalContentStorage;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.preferences.DBPPropertyManager;
......@@ -52,19 +48,11 @@ import org.jkiss.dbeaver.ui.dialogs.DialogUtils;
import org.jkiss.dbeaver.ui.editors.content.ContentEditor;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
import java.awt.Desktop;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset;
/**
* JDBC Content value handler.
......@@ -77,9 +65,9 @@ public class ContentValueManager extends BaseValueManager {
private static final Log log = Log.getLog(ContentValueManager.class);
public static final String PROP_CATEGORY_CONTENT = "CONTENT";
public static void contributeContentActions(@NotNull IContributionManager manager, @NotNull final IValueController controller, final IValueEditor activeEditor)
throws DBCException
throws DBCException
{
if (controller.getValue() instanceof DBDContent) {
if (!((DBDContent) controller.getValue()).isNull()) {
......@@ -92,31 +80,31 @@ public class ContentValueManager extends BaseValueManager {
}
// Logo can be changed
manager.add(new Action("Open in external editor", DBeaverIcons.getImageDescriptor(UIIcon.DOTS_BUTTON)) {
@Override
public void run() {
try {
final Object value = controller.getValue();
if (value == null) {
DBWorkbench.getPlatformUI().showError("Data is empty", "Can not save null data value");
}
if (value instanceof DBDContent) {
getDBDContent(value);
} else {
String str = controller.getValueHandler()
.getValueDisplayString(controller.getValueType(),
controller.getValue(), DBDDisplayFormat.EDIT);
String charset =
DBValueFormatting.getDefaultBinaryFileEncoding(controller.getExecutionContext().getDataSource());
byte[] bytes = str.getBytes(charset);
openOctetStream(bytes);
}
} catch (IOException e) {
DBWorkbench.getPlatformUI().showError("Open content", "Error while trying to open the value", e);
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Error",
"Unexpected error while trying to open the selected value", e);
}
}
@Override
public void run() {
try {
final Object value = controller.getValue();
if (value == null) {
DBWorkbench.getPlatformUI().showError("Data is empty", "Can not save null data value");
}
if (value instanceof DBDContent) {
getDBDContent(value);
} else {
String str = controller.getValueHandler()
.getValueDisplayString(controller.getValueType(),
controller.getValue(), DBDDisplayFormat.EDIT);
String charset =
DBValueFormatting.getDefaultBinaryFileEncoding(controller.getExecutionContext().getDataSource());
byte[] bytes = str.getBytes(charset);
openOctetStream(bytes);
}
} catch (IOException e) {
DBWorkbench.getPlatformUI().showError("Open content", "Error while trying to open the value", e);
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Error",
"Unexpected error while trying to open the selected value", e);
}
}
});
manager.add(new Action(ResultSetMessages.model_jdbc_load_from_file_, DBeaverIcons.getImageDescriptor(UIIcon.LOAD)) {
@Override
......@@ -135,67 +123,65 @@ public class ContentValueManager extends BaseValueManager {
manager.add(new Separator());
}
}
private static void getDBDContent(Object value) throws IOException, DBCException {
DBDContent content = (DBDContent) value;
try {
UIUtils.runInProgressService(monitor -> {
String charset = null;
DBDContentStorage storage;
try {
storage = content.getContents(monitor);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
if (storage != null) {
try (InputStream inputStream = storage.getContentStream()) {
ContentUtils.copyStreams(inputStream, -1, buffer, monitor);
} catch (IOException e) {
DBWorkbench.getPlatformUI().showError("IOException", "File exception", e);
}
charset = storage.getCharset();
} else {
charset = DBValueFormatting.getDefaultBinaryFileEncoding(content.getDataSource());
}
byte[] byteData = buffer.toByteArray();
openOctetStream(byteData);
} catch (DBCException e1) {
DBWorkbench.getPlatformUI().showError("DBCException", "Error reading contents", e1);
} catch (IOException e) {
DBWorkbench.getPlatformUI().showError("IOException", "File exception while opening", e);
}
});
} catch (InvocationTargetException | InterruptedException e) {
DBWorkbench.getPlatformUI().showError("Reading from content", "Error loading contents from file", e);
}
DBDContent content = (DBDContent) value;
try {
UIUtils.runInProgressService(monitor -> {
String charset = null;
DBDContentStorage storage;
try {
storage = content.getContents(monitor);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
if (storage != null) {
try (InputStream inputStream = storage.getContentStream()) {
ContentUtils.copyStreams(inputStream, -1, buffer, monitor);
} catch (IOException e) {
DBWorkbench.getPlatformUI().showError("IOException", "File exception", e);
}
charset = storage.getCharset();
} else {
charset = DBValueFormatting.getDefaultBinaryFileEncoding(content.getDataSource());
}
byte[] byteData = buffer.toByteArray();
openOctetStream(byteData);
} catch (DBCException e1) {
DBWorkbench.getPlatformUI().showError("DBCException", "Error reading contents", e1);
} catch (IOException e) {
DBWorkbench.getPlatformUI().showError("IOException", "File exception while opening", e);
}
});
} catch (InvocationTargetException | InterruptedException e) {
DBWorkbench.getPlatformUI().showError("Reading from content", "Error loading contents from file", e);
}
}
private static void openOctetStream(byte[] data) throws IOException {
File tmpFile = File.createTempFile("dbtmp", ".octet-stream");
FileOutputStream fos = new FileOutputStream(tmpFile);
if (data == null) {
DBWorkbench.getPlatformUI().showError("Open Content", "Raw value was null");
fos.close();
}
if (data.length == 0) {
log.info("file has no content");
fos.close();
tmpFile.delete();
} else {
fos.write(data);
fos.close();
// use OS to open the file
DBWorkbench.getPlatformUI().showMessageBox("Open Content",
"Opening the file at " + tmpFile.getPath(), false);
Desktop.getDesktop().open(tmpFile);
// delete the file when the user closes the DBeaver application
tmpFile.deleteOnExit();
}
File tmpFile = File.createTempFile("dbtmp", ".octet-stream");
FileOutputStream fos = new FileOutputStream(tmpFile);
if (data == null) {
DBWorkbench.getPlatformUI().showError("Open Content", "Raw value was null");
fos.close();
}
if (data.length == 0) {
log.info("file has no content");
fos.close();
tmpFile.delete();
} else {
fos.write(data);
fos.close();
// use OS to open the file
Desktop.getDesktop().open(tmpFile);
// delete the file when the user closes the DBeaver application
tmpFile.deleteOnExit();
}
}
public static IValueEditor openContentEditor(@NotNull IValueController controller)
{
Object value = controller.getValue();
IValueController.EditType binaryEditType = IValueController.EditType.valueOf(
controller.getExecutionContext().getDataSource().getContainer().getPreferenceStore().getString(ResultSetPreferences.RESULT_SET_BINARY_EDITOR_TYPE));
controller.getExecutionContext().getDataSource().getContainer().getPreferenceStore().getString(ResultSetPreferences.RESULT_SET_BINARY_EDITOR_TYPE));
if (controller.getValueType().getDataKind() == DBPDataKind.STRING) {
// String
return new TextViewDialog(controller);
......@@ -260,11 +246,11 @@ public class ContentValueManager extends BaseValueManager {
if (ContentUtils.isTextContent(value)) {
try (Reader cr = storage.getContentReader()) {
ContentUtils.saveContentToFile(
cr,
saveFile,
GeneralUtils.UTF8_ENCODING,
monitor
);
cr,
saveFile,
GeneralUtils.UTF8_ENCODING,
monitor
);
}
} else {
try (InputStream cs = storage.getContentStream()) {
......@@ -279,8 +265,8 @@ public class ContentValueManager extends BaseValueManager {
catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError(
ResultSetMessages.model_jdbc_could_not_save_content,
ResultSetMessages.model_jdbc_could_not_save_content_to_file_ + saveFile.getAbsolutePath() + "'", //$NON-NLS-2$
e.getTargetException());
ResultSetMessages.model_jdbc_could_not_save_content_to_file_ + saveFile.getAbsolutePath() + "'", //$NON-NLS-2$
e.getTargetException());
}
catch (InterruptedException e) {
// do nothing
......@@ -289,7 +275,7 @@ public class ContentValueManager extends BaseValueManager {
@Override
public void contributeActions(@NotNull IContributionManager manager, @NotNull final IValueController controller, @Nullable IValueEditor activeEditor)
throws DBCException
throws DBCException
{
super.contributeActions(manager, controller, activeEditor);
contributeContentActions(manager, controller, activeEditor);
......@@ -303,17 +289,17 @@ public class ContentValueManager extends BaseValueManager {
Object value = controller.getValue();
if (value instanceof DBDContent) {
propertySource.addProperty(
PROP_CATEGORY_CONTENT,
"content_type", //$NON-NLS-1$
ResultSetMessages.model_jdbc_content_type,
((DBDContent)value).getContentType());
PROP_CATEGORY_CONTENT,
"content_type", //$NON-NLS-1$
ResultSetMessages.model_jdbc_content_type,
((DBDContent)value).getContentType());
final long contentLength = ((DBDContent) value).getContentLength();
if (contentLength >= 0) {
propertySource.addProperty(
PROP_CATEGORY_CONTENT,
"content_length", //$NON-NLS-1$
ResultSetMessages.model_jdbc_content_length,
contentLength);
PROP_CATEGORY_CONTENT,
"content_length", //$NON-NLS-1$
ResultSetMessages.model_jdbc_content_length,
contentLength);
}
}
}
......@@ -330,27 +316,27 @@ public class ContentValueManager extends BaseValueManager {
@Override
public IValueEditor createEditor(@NotNull final IValueController controller)
throws DBException
throws DBException
{
switch (controller.getEditType()) {
case INLINE:
// Open inline/panel editor
Object value = controller.getValue();
if (controller.getValueType().getDataKind() == DBPDataKind.STRING) {
return new StringInlineEditor(controller);
} else if (value instanceof DBDContentCached &&
case INLINE:
// Open inline/panel editor
Object value = controller.getValue();
if (controller.getValueType().getDataKind() == DBPDataKind.STRING) {
return new StringInlineEditor(controller);
} else if (value instanceof DBDContentCached &&
ContentUtils.isTextValue(((DBDContentCached) value).getCachedValue()))
{
return new ContentInlineEditor(controller);
} else {
return null;
}
case EDITOR:
return openContentEditor(controller);
case PANEL:
return new ContentPanelEditor(controller);
default:
{
return new ContentInlineEditor(controller);
} else {
return null;
}
case EDITOR:
return openContentEditor(controller);
case PANEL:
return new ContentPanelEditor(controller);
default:
return null;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册