提交 dbcab98b 编写于 作者: J jurgen

Binary presentation in editors

Former-commit-id: 955b4a4a
上级 0fb14ec2
......@@ -19,6 +19,7 @@
package org.jkiss.dbeaver.model.impl.data;
import org.jkiss.dbeaver.model.data.DBDBinaryPresentation;
import org.jkiss.dbeaver.utils.ContentUtils;
/**
* String presentation
......@@ -40,12 +41,13 @@ public class BinaryPresentationString implements DBDBinaryPresentation {
@Override
public String toString(byte[] bytes, int offset, int length)
{
return null;
return ContentUtils.convertToString(bytes, offset, length);
}
@Override
public byte[] toBytes(String string)
{
return new byte[0];
return ContentUtils.convertToBytes(string);
}
}
......@@ -63,6 +63,11 @@ public class JDBCContentBytes extends JDBCContentAbstract implements DBDContentS
this.data = this.originalData = data;
}
public JDBCContentBytes(DBPDataSource dataSource, String data) {
super(dataSource);
this.data = this.originalData = DBUtils.getBinaryPresentation(dataSource).toBytes(data);
}
@Override
public InputStream getContentStream()
throws IOException
......
......@@ -33,6 +33,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.ext.IContentEditorPart;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.data.*;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
......@@ -56,6 +57,7 @@ import org.jkiss.dbeaver.ui.editors.content.parts.ContentBinaryEditorPart;
import org.jkiss.dbeaver.ui.editors.content.parts.ContentImageEditorPart;
import org.jkiss.dbeaver.ui.editors.content.parts.ContentTextEditorPart;
import org.jkiss.dbeaver.ui.editors.content.parts.ContentXMLEditorPart;
import org.jkiss.dbeaver.ui.preferences.PrefConstants;
import org.jkiss.dbeaver.ui.properties.PropertySourceAbstract;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.MimeTypes;
......@@ -187,7 +189,7 @@ public class JDBCContentValueHandler extends JDBCAbstractValueHandler {
case java.sql.Types.BINARY:
case java.sql.Types.VARBINARY:
case java.sql.Types.LONGVARBINARY:
return new JDBCContentBytes(context.getDataSource(), ContentUtils.convertToBytes((String) object));
return new JDBCContentBytes(context.getDataSource(), (String) object);
default:
// String by default
return new JDBCContentChars(context.getDataSource(), (String) object);
......@@ -288,7 +290,8 @@ public class JDBCContentValueHandler extends JDBCAbstractValueHandler {
if (cachedValue == null) {
stringValue = ""; //$NON-NLS-1$
} else if (cachedValue instanceof byte[]) {
stringValue = ContentUtils.convertToString((byte[])cachedValue);
byte[] bytes = (byte[]) cachedValue;
stringValue = DBUtils.getBinaryPresentation(controller.getDataSource()).toString(bytes, 0, bytes.length);
} else {
stringValue = cachedValue.toString();
}
......@@ -319,7 +322,7 @@ public class JDBCContentValueHandler extends JDBCAbstractValueHandler {
} else {
return new JDBCContentBytes(
valueController.getDataSource(),
ContentUtils.convertToBytes(newValue));
newValue);
}
}
};
......@@ -331,13 +334,12 @@ public class JDBCContentValueHandler extends JDBCAbstractValueHandler {
{
// Open LOB editor
Object value = controller.getValue();
/*if (value instanceof DBDContentCached) {
DBDValueController.EditType binaryEditType = DBDValueController.EditType.valueOf(
controller.getDataSource().getContainer().getPreferenceStore().getString(PrefConstants.RESULT_SET_BINARY_EDITOR_TYPE));
if (binaryEditType != DBDValueController.EditType.EDITOR && value instanceof DBDContentCached) {
// Use string editor for cached content
return new TextViewDialog(controller);
} else */
// Always use separate editor
// content could be an image or something huge so it is not an option to open text editor
if (value instanceof DBDContent) {
} else if (value instanceof DBDContent) {
DBDContent content = (DBDContent)value;
boolean isText = ContentUtils.isTextContent(content);
List<IContentEditorPart> parts = new ArrayList<IContentEditorPart>();
......
......@@ -293,9 +293,10 @@ public class TextViewDialog extends ValueViewDialog {
}
if (value instanceof byte[]) {
// Binary
textEdit.setText(ContentUtils.convertToString((byte[]) value));
byte[] bytes = (byte[]) value;
textEdit.setText(DBUtils.getBinaryPresentation(getValueController().getDataSource()).toString(bytes, 0, bytes.length));
if (hexEditControl != null) {
hexEditControl.setContent((byte[]) value);
hexEditControl.setContent(bytes);
}
} else {
// Should be string
......@@ -307,7 +308,8 @@ public class TextViewDialog extends ValueViewDialog {
String strValue = CommonUtils.toString(value);
textEdit.setText(strValue);
if (hexEditControl != null) {
setBinaryContent(strValue);
byte[] bytes = DBUtils.getBinaryPresentation(getValueController().getDataSource()).toBytes(strValue);
hexEditControl.setContent(bytes);
}
}
}
......
......@@ -550,10 +550,10 @@ public class ContentUtils {
return fileEncoding;
}
public static String convertToString(byte[] bytes)
public static String convertToString(byte[] bytes, int offset, int length)
{
char[] chars = new char[bytes.length];
for (int i = 0; i < bytes.length; i++) {
char[] chars = new char[length];
for (int i = offset; i < offset + length; i++) {
int b = bytes[i];
if (b < 0) {
b = -b + 127;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册