Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
d960e4c1
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dbeaver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d960e4c1
编写于
9月 12, 2020
作者:
H
halitanildonmez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixing tab indents, removing the extra dialog, fix imports
上级
bf3c06d1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
113 addition
and
127 deletion
+113
-127
plugins/org.jkiss.dbeaver.ui.editors.data/src/org/jkiss/dbeaver/ui/data/managers/ContentValueManager.java
...g/jkiss/dbeaver/ui/data/managers/ContentValueManager.java
+113
-127
未找到文件。
plugins/org.jkiss.dbeaver.ui.editors.data/src/org/jkiss/dbeaver/ui/data/managers/ContentValueManager.java
浏览文件 @
d960e4c1
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录