Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
03c544b3
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,发现更多精彩内容 >>
提交
03c544b3
编写于
9月 21, 2016
作者:
S
Serge Rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Content editor refactoring (+save fix)
上级
d40ef9a7
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
405 addition
and
564 deletion
+405
-564
plugins/org.jkiss.dbeaver.core/META-INF/MANIFEST.MF
plugins/org.jkiss.dbeaver.core/META-INF/MANIFEST.MF
+1
-1
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/IStreamValueManager.java
...re/src/org/jkiss/dbeaver/ui/data/IStreamValueManager.java
+2
-1
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/editors/XMLPanelEditor.java
...src/org/jkiss/dbeaver/ui/data/editors/XMLPanelEditor.java
+1
-1
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/ContentValueManager.java
...g/jkiss/dbeaver/ui/data/managers/ContentValueManager.java
+56
-16
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/BinaryEditorPart.java
...iss/dbeaver/ui/data/managers/stream/BinaryEditorPart.java
+47
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/BinaryStreamValueManager.java
...ver/ui/data/managers/stream/BinaryStreamValueManager.java
+3
-4
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/ImageEditorPart.java
...kiss/dbeaver/ui/data/managers/stream/ImageEditorPart.java
+162
-204
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/ImageStreamValueManager.java
...aver/ui/data/managers/stream/ImageStreamValueManager.java
+3
-5
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/TextEditorPart.java
...jkiss/dbeaver/ui/data/managers/stream/TextEditorPart.java
+48
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/TextStreamValueManager.java
...eaver/ui/data/managers/stream/TextStreamValueManager.java
+3
-4
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/registry/ValueManagerRegistry.java
.../jkiss/dbeaver/ui/data/registry/ValueManagerRegistry.java
+1
-1
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditor.java
...c/org/jkiss/dbeaver/ui/editors/content/ContentEditor.java
+32
-66
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorInput.java
.../jkiss/dbeaver/ui/editors/content/ContentEditorInput.java
+30
-4
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorSite.java
...g/jkiss/dbeaver/ui/editors/content/ContentEditorSite.java
+0
-13
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/SelectContentPartDialog.java
...s/dbeaver/ui/editors/content/SelectContentPartDialog.java
+8
-40
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentBinaryEditorPart.java
...ver/ui/editors/content/parts/ContentBinaryEditorPart.java
+0
-98
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentXMLEditorPart.java
...beaver/ui/editors/content/parts/ContentXMLEditorPart.java
+0
-103
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/BytesContentStorage.java
...src/org/jkiss/dbeaver/model/impl/BytesContentStorage.java
+8
-3
未找到文件。
plugins/org.jkiss.dbeaver.core/META-INF/MANIFEST.MF
浏览文件 @
03c544b3
...
...
@@ -54,6 +54,7 @@ Export-Package: org.jkiss.dbeaver,
org.jkiss.dbeaver.ui.data,
org.jkiss.dbeaver.ui.data.editors,
org.jkiss.dbeaver.ui.data.managers,
org.jkiss.dbeaver.ui.data.managers.stream,
org.jkiss.dbeaver.ui.data.registry,
org.jkiss.dbeaver.ui.dialogs,
org.jkiss.dbeaver.ui.dialogs.connection,
...
...
@@ -69,7 +70,6 @@ Export-Package: org.jkiss.dbeaver,
org.jkiss.dbeaver.ui.editors.binary.dialogs,
org.jkiss.dbeaver.ui.editors.binary.pref,
org.jkiss.dbeaver.ui.editors.content,
org.jkiss.dbeaver.ui.editors.content.parts,
org.jkiss.dbeaver.ui.editors.data,
org.jkiss.dbeaver.ui.editors.entity,
org.jkiss.dbeaver.ui.editors.entity.handlers,
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/IStreamValueManager.java
浏览文件 @
03c544b3
...
...
@@ -25,6 +25,7 @@ import org.jkiss.dbeaver.DBException;
import
org.jkiss.dbeaver.model.data.DBDContent
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.struct.DBSAttributeBase
;
import
org.jkiss.dbeaver.model.struct.DBSTypedObject
;
/**
* Stream value manager
...
...
@@ -39,7 +40,7 @@ public interface IStreamValueManager {
NONE
,
// Doesn't support
}
MatchType
matchesTo
(
@NotNull
DBRProgressMonitor
monitor
,
@NotNull
DBS
AttributeBase
attribute
,
@Nullable
DBDContent
value
);
MatchType
matchesTo
(
@NotNull
DBRProgressMonitor
monitor
,
@NotNull
DBS
TypedObject
attribute
,
@Nullable
DBDContent
value
);
IStreamValueEditor
createPanelEditor
(
@NotNull
IValueController
controller
)
throws
DBException
;
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/editors/XMLPanelEditor.java
浏览文件 @
03c544b3
...
...
@@ -66,7 +66,7 @@ public class XMLPanelEditor extends ContentPanelEditor {
try
{
monitor
.
subTask
(
"Prime XML value"
);
IEditorInput
sqlInput
=
new
ContentEditorInput
(
valueController
,
null
,
monitor
);
IEditorInput
sqlInput
=
new
ContentEditorInput
(
valueController
,
null
,
null
,
monitor
);
editor
.
init
(
subSite
,
sqlInput
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
);
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/ContentValueManager.java
浏览文件 @
03c544b3
...
...
@@ -20,34 +20,36 @@ package org.jkiss.dbeaver.ui.data.managers;
import
org.eclipse.jface.action.Action
;
import
org.eclipse.jface.action.IContributionManager
;
import
org.eclipse.jface.action.Separator
;
import
org.eclipse.ui.IEditorPart
;
import
org.jkiss.code.NotNull
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.DBeaverPreferences
;
import
org.jkiss.dbeaver.core.CoreMessages
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.core.CoreMessages
;
import
org.jkiss.dbeaver.model.DBPPropertyManager
;
import
org.jkiss.dbeaver.model.data.*
;
import
org.jkiss.dbeaver.model.data.DBDContent
;
import
org.jkiss.dbeaver.model.data.DBDContentCached
;
import
org.jkiss.dbeaver.model.exec.DBCException
;
import
org.jkiss.dbeaver.model.runtime.VoidProgressMonitor
;
import
org.jkiss.dbeaver.ui.DBeaverIcons
;
import
org.jkiss.dbeaver.ui.UIIcon
;
import
org.jkiss.dbeaver.ui.data.editors.XMLPanelEditor
;
import
org.jkiss.dbeaver.ui.dialogs.DialogUtils
;
import
org.jkiss.dbeaver.ui.data.IStreamValueManager
;
import
org.jkiss.dbeaver.ui.data.IValueController
;
import
org.jkiss.dbeaver.ui.data.IValueEditor
;
import
org.jkiss.dbeaver.ui.data.editors.ContentInlineEditor
;
import
org.jkiss.dbeaver.ui.data.editors.ContentPanelEditor
;
import
org.jkiss.dbeaver.ui.data.editors.XMLPanelEditor
;
import
org.jkiss.dbeaver.ui.data.registry.StreamValueManagerDescriptor
;
import
org.jkiss.dbeaver.ui.data.registry.ValueManagerRegistry
;
import
org.jkiss.dbeaver.ui.dialogs.DialogUtils
;
import
org.jkiss.dbeaver.ui.dialogs.data.TextViewDialog
;
import
org.jkiss.dbeaver.ui.editors.content.ContentEditor
;
import
org.jkiss.dbeaver.ui.editors.content.ContentEditorPart
;
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.utils.ContentUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
* JDBC Content value handler.
...
...
@@ -91,21 +93,59 @@ public class ContentValueManager extends BaseValueManager {
return
new
TextViewDialog
(
controller
);
}
else
if
(
value
instanceof
DBDContent
)
{
DBDContent
content
=
(
DBDContent
)
value
;
boolean
isText
=
ContentUtils
.
isTextContent
(
content
);
List
<
ContentEditorPart
>
parts
=
new
ArrayList
<>();
Map
<
StreamValueManagerDescriptor
,
IStreamValueManager
.
MatchType
>
streamManagers
=
ValueManagerRegistry
.
getInstance
().
getApplicableStreamManagers
(
VoidProgressMonitor
.
INSTANCE
,
controller
.
getValueType
(),
content
);
//boolean isText = ContentUtils.isTextContent(content);
List
<
IEditorPart
>
parts
=
new
ArrayList
<>();
IEditorPart
defaultPart
=
null
;
IStreamValueManager
.
MatchType
defaultMatch
=
null
;
for
(
Map
.
Entry
<
StreamValueManagerDescriptor
,
IStreamValueManager
.
MatchType
>
entry
:
streamManagers
.
entrySet
())
{
IStreamValueManager
streamValueManager
=
entry
.
getKey
().
getInstance
();
try
{
IEditorPart
editorPart
=
streamValueManager
.
createEditorPart
(
controller
);
IStreamValueManager
.
MatchType
matchType
=
entry
.
getValue
();
if
(
defaultPart
==
null
)
{
defaultPart
=
editorPart
;
defaultMatch
=
matchType
;
}
else
{
boolean
setDefault
=
false
;
switch
(
matchType
)
{
case
EXCLUSIVE:
case
PRIMARY:
setDefault
=
true
;
break
;
case
DEFAULT:
setDefault
=
(
defaultMatch
==
IStreamValueManager
.
MatchType
.
APPLIES
);
break
;
default
:
break
;
}
if
(
setDefault
)
{
defaultPart
=
editorPart
;
defaultMatch
=
matchType
;
}
}
parts
.
add
(
editorPart
);
}
catch
(
DBException
e
)
{
log
.
error
(
e
);
}
}
/*
if (isText) {
parts
.
add
(
new
Content
TextEditorPart
());
parts.add(new TextEditorPart());
if (ContentUtils.isXML(content)) {
parts.add(new ContentXMLEditorPart());
}
} else {
parts
.
add
(
new
Content
BinaryEditorPart
());
parts
.
add
(
new
Content
TextEditorPart
());
parts
.
add
(
new
Content
ImageEditorPart
());
parts.add(new BinaryEditorPart());
parts.add(new TextEditorPart());
parts.add(new ImageEditorPart());
}
*/
return
ContentEditor
.
openEditor
(
controller
,
parts
.
toArray
(
new
ContentEditorPart
[
parts
.
size
()]));
parts
.
toArray
(
new
IEditorPart
[
parts
.
size
()]),
defaultPart
);
}
else
{
controller
.
showMessage
(
CoreMessages
.
model_jdbc_unsupported_content_value_type_
,
true
);
return
null
;
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/
editors/content/Content
EditorPart.java
→
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/
data/managers/stream/Binary
EditorPart.java
浏览文件 @
03c544b3
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package
org.jkiss.dbeaver.ui.editors.content
;
import
org.eclipse.ui.IEditorActionBarContributor
;
import
org.eclipse.ui.IEditorPart
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.model.DBPImage
;
import
org.jkiss.dbeaver.ui.ISingleControlEditor
;
import
javax.activation.MimeType
;
/**
* Database content editor
*/
public
interface
ContentEditorPart
extends
IEditorPart
,
ISingleControlEditor
{
void
initPart
(
IEditorPart
contentEditor
,
@Nullable
MimeType
mimeType
);
IEditorActionBarContributor
getActionBarContributor
();
String
getContentTypeTitle
();
DBPImage
getContentTypeImage
();
String
getPreferredMimeType
();
/**
* Maximum part length. If content length is more than this value then this part will be committed.
* @return max length
*/
long
getMaxContentLength
();
/**
* Preferred content part will be set as default part in content editor.
* @return true or false
*/
boolean
isPreferredContent
();
boolean
isOptionalContent
();
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package
org.jkiss.dbeaver.ui.data.managers.stream
;
import
org.eclipse.swt.graphics.Image
;
import
org.eclipse.ui.IEditorPart
;
import
org.jkiss.dbeaver.model.DBIcon
;
import
org.jkiss.dbeaver.ui.DBeaverIcons
;
import
org.jkiss.dbeaver.ui.editors.binary.BinaryEditor
;
/**
* CONTENT Binary Editor
*/
public
class
BinaryEditorPart
extends
BinaryEditor
implements
IEditorPart
{
public
BinaryEditorPart
()
{
}
@Override
public
String
getTitle
()
{
return
"Binary"
;
}
@Override
public
Image
getTitleImage
()
{
return
DBeaverIcons
.
getImage
(
DBIcon
.
TYPE_BINARY
);
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/BinaryStreamValueManager.java
浏览文件 @
03c544b3
...
...
@@ -24,11 +24,10 @@ import org.jkiss.dbeaver.DBException;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.model.data.DBDContent
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.struct.DBS
AttributeBase
;
import
org.jkiss.dbeaver.model.struct.DBS
TypedObject
;
import
org.jkiss.dbeaver.ui.data.IStreamValueEditor
;
import
org.jkiss.dbeaver.ui.data.IStreamValueManager
;
import
org.jkiss.dbeaver.ui.data.IValueController
;
import
org.jkiss.dbeaver.ui.editors.content.parts.ContentBinaryEditorPart
;
/**
* Hex editor manager
...
...
@@ -38,7 +37,7 @@ public class BinaryStreamValueManager implements IStreamValueManager {
private
static
final
Log
log
=
Log
.
getLog
(
BinaryStreamValueManager
.
class
);
@Override
public
MatchType
matchesTo
(
@NotNull
DBRProgressMonitor
monitor
,
@NotNull
DBS
AttributeBase
attribute
,
@Nullable
DBDContent
value
)
{
public
MatchType
matchesTo
(
@NotNull
DBRProgressMonitor
monitor
,
@NotNull
DBS
TypedObject
attribute
,
@Nullable
DBDContent
value
)
{
// Applies to any values
return
MatchType
.
APPLIES
;
}
...
...
@@ -52,7 +51,7 @@ public class BinaryStreamValueManager implements IStreamValueManager {
@Override
public
IEditorPart
createEditorPart
(
@NotNull
IValueController
controller
)
{
return
new
Content
BinaryEditorPart
();
return
new
BinaryEditorPart
();
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/
editors/content/parts/Content
ImageEditorPart.java
→
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/
data/managers/stream/
ImageEditorPart.java
浏览文件 @
03c544b3
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package
org.jkiss.dbeaver.ui.editors.content.parts
;
import
org.eclipse.core.resources.IResourceChangeEvent
;
import
org.eclipse.core.resources.IResourceChangeListener
;
import
org.eclipse.core.resources.IResourceDelta
;
import
org.eclipse.core.resources.ResourcesPlugin
;
import
org.eclipse.core.runtime.IPath
;
import
org.eclipse.core.runtime.IProgressMonitor
;
import
org.eclipse.swt.SWT
;
import
org.eclipse.swt.widgets.Composite
;
import
org.eclipse.swt.widgets.Control
;
import
org.eclipse.ui.*
;
import
org.eclipse.ui.part.EditorPart
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.core.DBeaverUI
;
import
org.jkiss.dbeaver.model.DBIcon
;
import
org.jkiss.dbeaver.model.DBPImage
;
import
org.jkiss.dbeaver.ui.controls.imageview.ImageEditor
;
import
org.jkiss.dbeaver.ui.editors.content.ContentEditorPart
;
import
org.jkiss.dbeaver.utils.ContentUtils
;
import
javax.activation.MimeType
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.InputStream
;
/**
* CONTENT text editor
*/
public
class
ContentImageEditorPart
extends
EditorPart
implements
ContentEditorPart
,
IResourceChangeListener
{
private
static
final
Log
log
=
Log
.
getLog
(
ContentImageEditorPart
.
class
);
private
ImageEditor
imageViewer
;
private
boolean
contentValid
;
@Override
public
void
doSave
(
IProgressMonitor
monitor
)
{
}
@Override
public
void
doSaveAs
()
{
}
@Override
public
void
init
(
IEditorSite
site
,
IEditorInput
input
)
throws
PartInitException
{
setSite
(
site
);
setInput
(
input
);
ResourcesPlugin
.
getWorkspace
().
addResourceChangeListener
(
this
);
}
@Override
public
void
dispose
()
{
ResourcesPlugin
.
getWorkspace
().
removeResourceChangeListener
(
this
);
super
.
dispose
();
}
@Override
public
boolean
isDirty
()
{
return
false
;
}
@Override
public
boolean
isSaveAsAllowed
()
{
return
false
;
}
@Override
public
void
createPartControl
(
Composite
parent
)
{
imageViewer
=
new
ImageEditor
(
parent
,
SWT
.
NONE
);
loadImage
();
}
private
void
loadImage
()
{
if
(
imageViewer
==
null
||
imageViewer
.
isDisposed
())
{
return
;
}
if
(
getEditorInput
()
instanceof
IPathEditorInput
)
{
try
{
final
IPath
absolutePath
=
((
IPathEditorInput
)
getEditorInput
()).
getPath
();
File
localFile
=
absolutePath
.
toFile
();
if
(
localFile
.
exists
())
{
try
(
InputStream
inputStream
=
new
FileInputStream
(
localFile
))
{
contentValid
=
imageViewer
.
loadImage
(
inputStream
);
imageViewer
.
update
();
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"Can't load image contents"
,
e
);
}
}
}
@Override
public
void
setFocus
()
{
imageViewer
.
setFocus
();
}
@Override
public
void
initPart
(
IEditorPart
contentEditor
,
MimeType
mimeType
)
{
}
@Override
public
IEditorActionBarContributor
getActionBarContributor
()
{
return
null
;
}
@Nullable
@Override
public
Control
getEditorControl
()
{
return
imageViewer
;
}
@Override
public
String
getContentTypeTitle
()
{
return
"Image"
;
}
@Override
public
DBPImage
getContentTypeImage
()
{
return
DBIcon
.
TYPE_IMAGE
;
}
@Override
public
String
getPreferredMimeType
()
{
return
"image"
;
}
@Override
public
long
getMaxContentLength
()
{
return
20
*
1024
*
1024
;
}
@Override
public
boolean
isPreferredContent
()
{
return
contentValid
;
}
@Override
public
boolean
isOptionalContent
()
{
return
true
;
}
@Override
public
void
resourceChanged
(
IResourceChangeEvent
event
)
{
IResourceDelta
delta
=
event
.
getDelta
();
if
(
delta
==
null
)
{
return
;
}
IEditorInput
input
=
getEditorInput
();
IPath
localPath
=
null
;
if
(
input
instanceof
IPathEditorInput
)
{
localPath
=
((
IPathEditorInput
)
input
).
getPath
();
}
if
(
localPath
==
null
)
{
return
;
}
localPath
=
ContentUtils
.
convertPathToWorkspacePath
(
localPath
);
delta
=
delta
.
findMember
(
localPath
);
if
(
delta
==
null
)
{
return
;
}
if
(
delta
.
getKind
()
==
IResourceDelta
.
CHANGED
)
{
// Refresh editor
DBeaverUI
.
asyncExec
(
new
Runnable
()
{
@Override
public
void
run
()
{
loadImage
();
}
});
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package
org.jkiss.dbeaver.ui.data.managers.stream
;
import
org.eclipse.core.resources.IResourceChangeEvent
;
import
org.eclipse.core.resources.IResourceChangeListener
;
import
org.eclipse.core.resources.IResourceDelta
;
import
org.eclipse.core.resources.ResourcesPlugin
;
import
org.eclipse.core.runtime.IPath
;
import
org.eclipse.core.runtime.IProgressMonitor
;
import
org.eclipse.swt.SWT
;
import
org.eclipse.swt.graphics.Image
;
import
org.eclipse.swt.widgets.Composite
;
import
org.eclipse.ui.IEditorInput
;
import
org.eclipse.ui.IEditorSite
;
import
org.eclipse.ui.IPathEditorInput
;
import
org.eclipse.ui.PartInitException
;
import
org.eclipse.ui.part.EditorPart
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.core.DBeaverUI
;
import
org.jkiss.dbeaver.model.DBIcon
;
import
org.jkiss.dbeaver.ui.DBeaverIcons
;
import
org.jkiss.dbeaver.ui.controls.imageview.ImageEditor
;
import
org.jkiss.dbeaver.utils.ContentUtils
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.InputStream
;
/**
* CONTENT text editor
*/
public
class
ImageEditorPart
extends
EditorPart
implements
IResourceChangeListener
{
private
static
final
Log
log
=
Log
.
getLog
(
ImageEditorPart
.
class
);
private
ImageEditor
imageViewer
;
private
boolean
contentValid
;
@Override
public
void
doSave
(
IProgressMonitor
monitor
)
{
}
@Override
public
void
doSaveAs
()
{
}
@Override
public
void
init
(
IEditorSite
site
,
IEditorInput
input
)
throws
PartInitException
{
setSite
(
site
);
setInput
(
input
);
ResourcesPlugin
.
getWorkspace
().
addResourceChangeListener
(
this
);
}
@Override
public
void
dispose
()
{
ResourcesPlugin
.
getWorkspace
().
removeResourceChangeListener
(
this
);
super
.
dispose
();
}
@Override
public
boolean
isDirty
()
{
return
false
;
}
@Override
public
boolean
isSaveAsAllowed
()
{
return
false
;
}
@Override
public
void
createPartControl
(
Composite
parent
)
{
imageViewer
=
new
ImageEditor
(
parent
,
SWT
.
NONE
);
loadImage
();
}
private
void
loadImage
()
{
if
(
imageViewer
==
null
||
imageViewer
.
isDisposed
())
{
return
;
}
if
(
getEditorInput
()
instanceof
IPathEditorInput
)
{
try
{
final
IPath
absolutePath
=
((
IPathEditorInput
)
getEditorInput
()).
getPath
();
File
localFile
=
absolutePath
.
toFile
();
if
(
localFile
.
exists
())
{
try
(
InputStream
inputStream
=
new
FileInputStream
(
localFile
))
{
contentValid
=
imageViewer
.
loadImage
(
inputStream
);
imageViewer
.
update
();
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"Can't load image contents"
,
e
);
}
}
}
@Override
public
void
setFocus
()
{
imageViewer
.
setFocus
();
}
@Override
public
String
getTitle
()
{
return
"Image"
;
}
@Override
public
Image
getTitleImage
()
{
return
DBeaverIcons
.
getImage
(
DBIcon
.
TYPE_IMAGE
);
}
@Override
public
void
resourceChanged
(
IResourceChangeEvent
event
)
{
IResourceDelta
delta
=
event
.
getDelta
();
if
(
delta
==
null
)
{
return
;
}
IEditorInput
input
=
getEditorInput
();
IPath
localPath
=
null
;
if
(
input
instanceof
IPathEditorInput
)
{
localPath
=
((
IPathEditorInput
)
input
).
getPath
();
}
if
(
localPath
==
null
)
{
return
;
}
localPath
=
ContentUtils
.
convertPathToWorkspacePath
(
localPath
);
delta
=
delta
.
findMember
(
localPath
);
if
(
delta
==
null
)
{
return
;
}
if
(
delta
.
getKind
()
==
IResourceDelta
.
CHANGED
)
{
// Refresh editor
DBeaverUI
.
asyncExec
(
new
Runnable
()
{
@Override
public
void
run
()
{
loadImage
();
}
});
}
}
}
\ No newline at end of file
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/ImageStreamValueManager.java
浏览文件 @
03c544b3
...
...
@@ -29,12 +29,10 @@ import org.jkiss.dbeaver.model.data.DBDContent;
import
org.jkiss.dbeaver.model.data.DBDContentStorage
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress
;
import
org.jkiss.dbeaver.model.struct.DBS
AttributeBase
;
import
org.jkiss.dbeaver.model.struct.DBS
TypedObject
;
import
org.jkiss.dbeaver.ui.data.IStreamValueEditor
;
import
org.jkiss.dbeaver.ui.data.IStreamValueManager
;
import
org.jkiss.dbeaver.ui.data.IValueController
;
import
org.jkiss.dbeaver.ui.editors.content.parts.ContentBinaryEditorPart
;
import
org.jkiss.dbeaver.ui.editors.content.parts.ContentImageEditorPart
;
import
java.io.InputStream
;
import
java.lang.reflect.InvocationTargetException
;
...
...
@@ -47,7 +45,7 @@ public class ImageStreamValueManager implements IStreamValueManager {
private
static
final
Log
log
=
Log
.
getLog
(
ImageStreamValueManager
.
class
);
@Override
public
MatchType
matchesTo
(
@NotNull
DBRProgressMonitor
monitor
,
@NotNull
DBS
AttributeBase
attribute
,
@Nullable
DBDContent
value
)
{
public
MatchType
matchesTo
(
@NotNull
DBRProgressMonitor
monitor
,
@NotNull
DBS
TypedObject
attribute
,
@Nullable
DBDContent
value
)
{
// Applies to image values
ImageDetector
imageDetector
=
new
ImageDetector
(
value
);
if
(!
DBUtils
.
isNullValue
(
value
))
{
...
...
@@ -65,7 +63,7 @@ public class ImageStreamValueManager implements IStreamValueManager {
@Override
public
IEditorPart
createEditorPart
(
@NotNull
IValueController
controller
)
{
return
new
Content
ImageEditorPart
();
return
new
ImageEditorPart
();
}
private
static
class
ImageDetector
implements
DBRRunnableWithProgress
{
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/
editors/content/parts/Content
TextEditorPart.java
→
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/
data/managers/stream/
TextEditorPart.java
浏览文件 @
03c544b3
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package
org.jkiss.dbeaver.ui.editors.content.parts
;
import
org.eclipse.ui.IEditorActionBarContributor
;
import
org.eclipse.ui.IEditorPart
;
import
org.jkiss.dbeaver.DBeaverPreferences
;
import
org.jkiss.dbeaver.model.DBIcon
;
import
org.jkiss.dbeaver.model.DBPContextProvider
;
import
org.jkiss.dbeaver.model.DBPImage
;
import
org.jkiss.dbeaver.model.exec.DBCExecutionContext
;
import
org.jkiss.dbeaver.ui.editors.content.ContentEditorPart
;
import
org.jkiss.dbeaver.ui.editors.text.BaseTextEditor
;
import
org.jkiss.dbeaver.ui.editors.text.FileRefDocumentProvider
;
import
org.jkiss.dbeaver.utils.MimeTypes
;
import
javax.activation.MimeType
;
/**
* CONTENT text editor
*/
public
class
ContentTextEditorPart
extends
BaseTextEditor
implements
ContentEditorPart
{
private
IEditorPart
contentEditor
;
public
ContentTextEditorPart
()
{
setDocumentProvider
(
new
FileRefDocumentProvider
());
}
@Override
public
void
initPart
(
IEditorPart
contentEditor
,
MimeType
mimeType
)
{
this
.
contentEditor
=
contentEditor
;
}
@Override
public
IEditorActionBarContributor
getActionBarContributor
()
{
return
null
;
}
@Override
public
String
getContentTypeTitle
()
{
return
"Text"
;
}
@Override
public
DBPImage
getContentTypeImage
()
{
return
DBIcon
.
TYPE_TEXT
;
}
@Override
public
String
getPreferredMimeType
()
{
return
MimeTypes
.
TEXT
;
}
@Override
public
long
getMaxContentLength
()
{
if
(
contentEditor
instanceof
DBPContextProvider
)
{
DBCExecutionContext
context
=
((
DBPContextProvider
)
contentEditor
).
getExecutionContext
();
if
(
context
!=
null
)
{
return
context
.
getDataSource
().
getContainer
().
getPreferenceStore
().
getInt
(
DBeaverPreferences
.
RS_EDIT_MAX_TEXT_SIZE
);
}
}
return
10
*
1024
*
1024
;
}
/**
* Always return false cos' text editor can load any binary content
* @return false
*/
@Override
public
boolean
isPreferredContent
()
{
return
false
;
}
@Override
public
boolean
isOptionalContent
()
{
return
true
;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package
org.jkiss.dbeaver.ui.data.managers.stream
;
import
org.eclipse.swt.graphics.Image
;
import
org.eclipse.ui.IEditorPart
;
import
org.jkiss.dbeaver.model.DBIcon
;
import
org.jkiss.dbeaver.ui.DBeaverIcons
;
import
org.jkiss.dbeaver.ui.editors.text.BaseTextEditor
;
import
org.jkiss.dbeaver.ui.editors.text.FileRefDocumentProvider
;
/**
* CONTENT text editor
*/
public
class
TextEditorPart
extends
BaseTextEditor
implements
IEditorPart
{
public
TextEditorPart
()
{
setDocumentProvider
(
new
FileRefDocumentProvider
());
}
@Override
public
String
getTitle
()
{
return
"Text"
;
}
@Override
public
Image
getTitleImage
()
{
return
DBeaverIcons
.
getImage
(
DBIcon
.
TYPE_TEXT
);
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/TextStreamValueManager.java
浏览文件 @
03c544b3
...
...
@@ -24,11 +24,10 @@ import org.jkiss.dbeaver.DBException;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.model.data.DBDContent
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.struct.DBS
AttributeBase
;
import
org.jkiss.dbeaver.model.struct.DBS
TypedObject
;
import
org.jkiss.dbeaver.ui.data.IStreamValueEditor
;
import
org.jkiss.dbeaver.ui.data.IStreamValueManager
;
import
org.jkiss.dbeaver.ui.data.IValueController
;
import
org.jkiss.dbeaver.ui.editors.content.parts.ContentTextEditorPart
;
import
org.jkiss.dbeaver.utils.ContentUtils
;
/**
...
...
@@ -39,7 +38,7 @@ public class TextStreamValueManager implements IStreamValueManager {
private
static
final
Log
log
=
Log
.
getLog
(
TextStreamValueManager
.
class
);
@Override
public
MatchType
matchesTo
(
@NotNull
DBRProgressMonitor
monitor
,
@NotNull
DBS
AttributeBase
attribute
,
@Nullable
DBDContent
value
)
{
public
MatchType
matchesTo
(
@NotNull
DBRProgressMonitor
monitor
,
@NotNull
DBS
TypedObject
attribute
,
@Nullable
DBDContent
value
)
{
// Applies to text values
return
ContentUtils
.
isTextContent
(
value
)
?
MatchType
.
DEFAULT
:
MatchType
.
APPLIES
;
}
...
...
@@ -53,7 +52,7 @@ public class TextStreamValueManager implements IStreamValueManager {
@Override
public
IEditorPart
createEditorPart
(
@NotNull
IValueController
controller
)
{
return
new
Content
TextEditorPart
();
return
new
TextEditorPart
();
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/registry/ValueManagerRegistry.java
浏览文件 @
03c544b3
...
...
@@ -99,7 +99,7 @@ public class ValueManagerRegistry {
return
getInstance
().
getManager
(
dataSource
,
typedObject
,
valueType
);
}
public
Map
<
StreamValueManagerDescriptor
,
IStreamValueManager
.
MatchType
>
getApplicableStreamManagers
(
@NotNull
DBRProgressMonitor
monitor
,
@NotNull
DBS
AttributeBase
attribute
,
@Nullable
DBDContent
value
)
{
public
Map
<
StreamValueManagerDescriptor
,
IStreamValueManager
.
MatchType
>
getApplicableStreamManagers
(
@NotNull
DBRProgressMonitor
monitor
,
@NotNull
DBS
TypedObject
attribute
,
@Nullable
DBDContent
value
)
{
Map
<
StreamValueManagerDescriptor
,
IStreamValueManager
.
MatchType
>
result
=
new
LinkedHashMap
<>();
for
(
StreamValueManagerDescriptor
contentManager
:
streamManagers
)
{
IStreamValueManager
.
MatchType
matchType
=
contentManager
.
getInstance
().
matchesTo
(
monitor
,
attribute
,
value
);
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditor.java
浏览文件 @
03c544b3
...
...
@@ -32,23 +32,21 @@ import org.eclipse.ui.*;
import
org.jkiss.code.NotNull
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.core.DBeaverUI
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.core.DBeaverUI
;
import
org.jkiss.dbeaver.model.data.DBDContent
;
import
org.jkiss.dbeaver.model.exec.DBCException
;
import
org.jkiss.dbeaver.utils.RuntimeUtils
;
import
org.jkiss.dbeaver.ui.data.IValueController
;
import
org.jkiss.dbeaver.ui.data.IValueEditorStandalone
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress
;
import
org.jkiss.dbeaver.model.runtime.VoidProgressMonitor
;
import
org.jkiss.dbeaver.ui.DBeaverIcons
;
import
org.jkiss.dbeaver.ui.UIUtils
;
import
org.jkiss.dbeaver.ui.data.IValueController
;
import
org.jkiss.dbeaver.ui.data.IValueEditorStandalone
;
import
org.jkiss.dbeaver.ui.dialogs.ColumnInfoPanel
;
import
org.jkiss.dbeaver.ui.editors.MultiPageAbstractEditor
;
import
org.jkiss.dbeaver.utils.ContentUtils
;
import
org.jkiss.dbeaver.utils.RuntimeUtils
;
import
javax.activation.MimeType
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -65,12 +63,12 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
}
@Nullable
public
static
ContentEditor
openEditor
(
IValueController
valueController
,
ContentEditorPart
[]
editorParts
)
public
static
ContentEditor
openEditor
(
IValueController
valueController
,
IEditorPart
[]
editorParts
,
IEditorPart
defaultPart
)
{
ContentEditorInput
editorInput
;
// Save data to file
try
{
LOBInitializer
initializer
=
new
LOBInitializer
(
valueController
,
editorParts
,
null
);
LOBInitializer
initializer
=
new
LOBInitializer
(
valueController
,
editorParts
,
defaultPart
,
null
);
//valueController.getValueSite().getWorkbenchWindow().run(true, true, initializer);
DBeaverUI
.
runInProgressService
(
initializer
);
editorInput
=
initializer
.
editorInput
;
...
...
@@ -98,24 +96,28 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
private
static
final
Log
log
=
Log
.
getLog
(
ContentEditor
.
class
);
static
class
ContentPartInfo
{
ContentEditorPart
editorPart
;
IEditorPart
editorPart
;
boolean
isDefault
;
boolean
activated
;
public
int
index
=
-
1
;
private
ContentPartInfo
(
ContentEditorPart
editorPar
t
)
{
private
ContentPartInfo
(
IEditorPart
editorPart
,
boolean
isDefaul
t
)
{
this
.
editorPart
=
editorPart
;
this
.
isDefault
=
isDefault
;
}
}
private
static
class
LOBInitializer
implements
DBRRunnableWithProgress
{
IValueController
valueController
;
ContentEditorPart
[]
editorParts
;
IEditorPart
[]
editorParts
;
IEditorPart
defaultPart
;
ContentEditorInput
editorInput
;
private
LOBInitializer
(
IValueController
valueController
,
ContentEditorPart
[]
editorParts
,
@Nullable
ContentEditorInput
editorInput
)
private
LOBInitializer
(
IValueController
valueController
,
IEditorPart
[]
editorParts
,
IEditorPart
defaultPart
,
@Nullable
ContentEditorInput
editorInput
)
{
this
.
valueController
=
valueController
;
this
.
editorParts
=
editorParts
;
this
.
defaultPart
=
defaultPart
;
this
.
editorInput
=
editorInput
;
}
...
...
@@ -127,6 +129,7 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
editorInput
=
new
ContentEditorInput
(
valueController
,
editorParts
,
defaultPart
,
monitor
);
}
else
{
editorInput
.
refreshContent
(
monitor
,
valueController
);
...
...
@@ -171,14 +174,14 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
public
void
run
()
{
try
{
// Check for dirty parts
final
List
<
Content
EditorPart
>
dirtyParts
=
new
ArrayList
<>();
final
List
<
I
EditorPart
>
dirtyParts
=
new
ArrayList
<>();
for
(
ContentPartInfo
partInfo
:
contentParts
)
{
if
(
partInfo
.
activated
&&
partInfo
.
editorPart
.
isDirty
())
{
dirtyParts
.
add
(
partInfo
.
editorPart
);
}
}
Content
EditorPart
dirtyPart
=
null
;
I
EditorPart
dirtyPart
=
null
;
if
(
dirtyParts
.
isEmpty
())
{
// No modified parts - no additional save required
}
else
if
(
dirtyParts
.
size
()
==
1
)
{
...
...
@@ -236,13 +239,11 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
return
;
}
MimeType
mimeType
=
ContentUtils
.
getMimeType
(
content
.
getContentType
());
// Fill nested editorParts info
Content
EditorPart
[]
editorParts
=
getEditorInput
().
getEditors
();
for
(
Content
EditorPart
editorPart
:
editorParts
)
{
contentParts
.
add
(
new
ContentPartInfo
(
editorPart
));
editorPart
.
initPart
(
this
,
mimeType
);
I
EditorPart
[]
editorParts
=
getEditorInput
().
getEditors
();
for
(
I
EditorPart
editorPart
:
editorParts
)
{
contentParts
.
add
(
new
ContentPartInfo
(
editorPart
,
editorPart
==
getEditorInput
().
getDefaultEditor
()
));
//editorPart.init(site, input
);
}
ResourcesPlugin
.
getWorkspace
().
addResourceChangeListener
(
this
);
...
...
@@ -303,60 +304,24 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
if
(
content
==
null
)
{
return
;
}
String
contentType
=
null
;
try
{
contentType
=
content
.
getContentType
();
}
catch
(
Exception
e
)
{
log
.
error
(
"Can't determine value content type"
,
e
);
}
long
contentLength
;
try
{
contentLength
=
content
.
getContentLength
();
}
catch
(
Exception
e
)
{
log
.
warn
(
"Can't determine value content length"
,
e
);
// Get file length
contentLength
=
getEditorInput
().
getContentFile
().
length
();
}
MimeType
mimeType
=
ContentUtils
.
getMimeType
(
contentType
);
IEditorPart
defaultPage
=
null
,
preferredPage
=
null
;
ContentPartInfo
defaultPage
=
null
;
for
(
ContentPartInfo
contentPart
:
contentParts
)
{
ContentEditorPart
editorPart
=
contentPart
.
editorPart
;
if
(
contentLength
>
editorPart
.
getMaxContentLength
())
{
continue
;
}
if
(
preferredPage
!=
null
&&
editorPart
.
isOptionalContent
())
{
// Do not add optional parts if we already have prefered one
continue
;
if
(
contentPart
.
isDefault
)
{
defaultPage
=
contentPart
;
}
IEditorPart
editorPart
=
contentPart
.
editorPart
;
try
{
int
index
=
addPage
(
editorPart
,
getEditorInput
());
setPageText
(
index
,
editorPart
.
get
ContentType
Title
());
setPageImage
(
index
,
DBeaverIcons
.
getImage
(
editorPart
.
getContentTypeImage
()
));
setPageText
(
index
,
editorPart
.
getTitle
());
setPageImage
(
index
,
editorPart
.
getTitleImage
(
));
contentPart
.
activated
=
true
;
contentPart
.
index
=
index
;
// Check MIME type
if
(
mimeType
!=
null
&&
mimeType
.
getPrimaryType
().
equals
(
editorPart
.
getPreferredMimeType
()))
{
defaultPage
=
editorPart
;
}
if
(
editorPart
.
isPreferredContent
())
{
preferredPage
=
editorPart
;
}
}
catch
(
PartInitException
e
)
{
log
.
error
(
e
);
}
}
if
(
preferredPage
!=
null
)
{
// Remove all optional pages
for
(
ContentPartInfo
contentPart
:
contentParts
)
{
if
(
contentPart
.
activated
&&
contentPart
.
editorPart
!=
preferredPage
&&
contentPart
.
editorPart
.
isOptionalContent
())
{
removePage
(
contentPart
.
index
);
}
}
// Set default page
setActiveEditor
(
preferredPage
);
}
else
if
(
defaultPage
!=
null
)
{
setActiveEditor
(
defaultPage
);
if
(
defaultPage
!=
null
)
{
setActiveEditor
(
defaultPage
.
editorPart
);
}
this
.
partsLoaded
=
true
;
...
...
@@ -473,8 +438,9 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
@Override
public
void
primeEditorValue
(
@Nullable
Object
value
)
throws
DBException
{
IValueController
valueController
=
getEditorInput
().
getValueController
();
LOBInitializer
initializer
=
new
LOBInitializer
(
valueController
,
getEditorInput
().
getEditors
(),
getEditorInput
());
ContentEditorInput
input
=
getEditorInput
();
IValueController
valueController
=
input
.
getValueController
();
LOBInitializer
initializer
=
new
LOBInitializer
(
valueController
,
input
.
getEditors
(),
input
.
getDefaultEditor
(),
input
);
try
{
//valueController.getValueSite().getWorkbenchWindow().run(true, true, initializer);
DBeaverUI
.
runInProgressService
(
initializer
);
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorInput.java
浏览文件 @
03c544b3
...
...
@@ -23,6 +23,7 @@ import org.eclipse.core.runtime.IPath;
import
org.eclipse.core.runtime.IProgressMonitor
;
import
org.eclipse.core.runtime.Path
;
import
org.eclipse.jface.resource.ImageDescriptor
;
import
org.eclipse.ui.IEditorPart
;
import
org.eclipse.ui.IPathEditorInput
;
import
org.eclipse.ui.IPersistableElement
;
import
org.jkiss.code.Nullable
;
...
...
@@ -32,19 +33,22 @@ import org.jkiss.dbeaver.core.DBeaverCore;
import
org.jkiss.dbeaver.model.DBIcon
;
import
org.jkiss.dbeaver.model.DBPContextProvider
;
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.DBDContentStorageLocal
;
import
org.jkiss.dbeaver.model.exec.DBCException
;
import
org.jkiss.dbeaver.model.exec.DBCExecutionContext
;
import
org.jkiss.dbeaver.model.impl.BytesContentStorage
;
import
org.jkiss.dbeaver.model.impl.StringContentStorage
;
import
org.jkiss.dbeaver.model.impl.TemporaryContentStorage
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.runtime.LocalFileStorage
;
import
org.jkiss.dbeaver.utils.RuntimeUtils
;
import
org.jkiss.dbeaver.ui.DBeaverIcons
;
import
org.jkiss.dbeaver.ui.data.IAttributeController
;
import
org.jkiss.dbeaver.ui.data.IValueController
;
import
org.jkiss.dbeaver.utils.ContentUtils
;
import
org.jkiss.dbeaver.utils.GeneralUtils
;
import
org.jkiss.dbeaver.utils.RuntimeUtils
;
import
java.io.*
;
...
...
@@ -56,19 +60,22 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
private
static
final
Log
log
=
Log
.
getLog
(
ContentEditorInput
.
class
);
private
IValueController
valueController
;
private
ContentEditorPart
[]
editorParts
;
private
IEditorPart
[]
editorParts
;
private
IEditorPart
defaultPart
;
private
File
contentFile
;
private
boolean
contentDetached
=
false
;
private
String
fileCharset
=
ContentUtils
.
DEFAULT_CHARSET
;
public
ContentEditorInput
(
IValueController
valueController
,
ContentEditorPart
[]
editorParts
,
IEditorPart
[]
editorParts
,
IEditorPart
defaultPart
,
DBRProgressMonitor
monitor
)
throws
DBException
{
this
.
valueController
=
valueController
;
this
.
editorParts
=
editorParts
;
this
.
defaultPart
=
defaultPart
;
this
.
prepareContent
(
monitor
);
}
...
...
@@ -87,11 +94,15 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
this
.
prepareContent
(
monitor
);
}
Content
EditorPart
[]
getEditors
()
I
EditorPart
[]
getEditors
()
{
return
editorParts
;
}
public
IEditorPart
getDefaultEditor
()
{
return
defaultPart
;
}
@Override
public
boolean
exists
()
{
...
...
@@ -296,6 +307,21 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
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
,
GeneralUtils
.
getDefaultFileEncoding
()))
{
storage
=
StringContentStorage
.
createFromReader
(
reader
);
}
}
else
{
storage
=
BytesContentStorage
.
createFromStream
(
is
,
contentFile
.
length
(),
GeneralUtils
.
getDefaultFileEncoding
());
}
//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
);
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorSite.java
浏览文件 @
03c544b3
...
...
@@ -17,7 +17,6 @@
*/
package
org.jkiss.dbeaver.ui.editors.content
;
import
org.eclipse.ui.IEditorActionBarContributor
;
import
org.eclipse.ui.IEditorPart
;
import
org.eclipse.ui.IWorkbenchPart
;
import
org.eclipse.ui.part.MultiPageEditorSite
;
...
...
@@ -32,18 +31,6 @@ class ContentEditorSite extends MultiPageEditorSite {
super
(
contentEditor
,
editor
);
}
@Override
public
IEditorActionBarContributor
getActionBarContributor
()
{
IEditorPart
editor
=
getEditor
();
ContentEditor
contentEditor
=
(
ContentEditor
)
getMultiPageEditor
();
ContentEditor
.
ContentPartInfo
contentPart
=
contentEditor
.
getContentEditor
(
editor
);
if
(
contentPart
!=
null
)
{
return
contentPart
.
editorPart
.
getActionBarContributor
();
}
else
{
return
super
.
getActionBarContributor
();
}
}
@Override
public
IWorkbenchPart
getPart
()
{
return
getMultiPageEditor
();
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/SelectContentPartDialog.java
浏览文件 @
03c544b3
...
...
@@ -24,6 +24,7 @@ import org.eclipse.swt.events.SelectionAdapter;
import
org.eclipse.swt.events.SelectionEvent
;
import
org.eclipse.swt.layout.GridData
;
import
org.eclipse.swt.widgets.*
;
import
org.eclipse.ui.IEditorPart
;
import
java.util.List
;
...
...
@@ -34,10 +35,10 @@ import java.util.List;
*/
class
SelectContentPartDialog
extends
Dialog
{
private
List
<
Content
EditorPart
>
dirtyParts
;
private
Content
EditorPart
selectedPart
;
private
List
<
I
EditorPart
>
dirtyParts
;
private
I
EditorPart
selectedPart
;
private
SelectContentPartDialog
(
Shell
parentShell
,
List
<
Content
EditorPart
>
dirtyParts
)
private
SelectContentPartDialog
(
Shell
parentShell
,
List
<
I
EditorPart
>
dirtyParts
)
{
super
(
parentShell
);
this
.
dirtyParts
=
dirtyParts
;
...
...
@@ -67,8 +68,8 @@ class SelectContentPartDialog extends Dialog {
gd
=
new
GridData
(
GridData
.
FILL_HORIZONTAL
);
combo
.
setLayoutData
(
gd
);
combo
.
add
(
""
);
for
(
Content
EditorPart
part
:
dirtyParts
)
{
combo
.
add
(
part
.
get
ContentType
Title
());
for
(
I
EditorPart
part
:
dirtyParts
)
{
combo
.
add
(
part
.
getTitle
());
}
combo
.
addSelectionListener
(
new
SelectionAdapter
()
{
@Override
...
...
@@ -82,39 +83,6 @@ class SelectContentPartDialog extends Dialog {
getButton
(
IDialogConstants
.
OK_ID
).
setEnabled
(
selectedPart
!=
null
);
}
});
/*
final Table table = new Table(group, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
table.setLinesVisible (true);
table.setHeaderVisible(true);
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 150;
gd.widthHint = 200;
table.setLayoutData(gd);
TableColumn tableColumn = new TableColumn(table, SWT.NONE);
tableColumn.setText("Editor");
for (ContentEditorPart part : dirtyParts) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(part.getContentTypeTitle());
Image image = part.getContentTypeImage();
if (image != null) {
item.setImage(image);
}
item.setData(part);
}
tableColumn.pack();
table.pack();
table.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
TableItem item = (TableItem) e.item;
selectedPart = (ContentEditorPart) item.getData();
getButton(IDialogConstants.OK_ID).setEnabled(true);
}
});
*/
return
group
;
}
...
...
@@ -127,12 +95,12 @@ class SelectContentPartDialog extends Dialog {
return
ctl
;
}
public
Content
EditorPart
getSelectedPart
()
public
I
EditorPart
getSelectedPart
()
{
return
selectedPart
;
}
public
static
ContentEditorPart
selectContentPart
(
Shell
parentShell
,
List
<
Content
EditorPart
>
dirtyParts
)
public
static
IEditorPart
selectContentPart
(
Shell
parentShell
,
List
<
I
EditorPart
>
dirtyParts
)
{
SelectContentPartDialog
scDialog
=
new
SelectContentPartDialog
(
parentShell
,
dirtyParts
);
if
(
scDialog
.
open
()
==
IDialogConstants
.
OK_ID
)
{
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentBinaryEditorPart.java
已删除
100644 → 0
浏览文件 @
d40ef9a7
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package
org.jkiss.dbeaver.ui.editors.content.parts
;
import
org.eclipse.swt.widgets.Control
;
import
org.eclipse.ui.IEditorActionBarContributor
;
import
org.eclipse.ui.IEditorPart
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.model.DBIcon
;
import
org.jkiss.dbeaver.model.DBPImage
;
import
org.jkiss.dbeaver.ui.editors.binary.BinaryEditor
;
import
org.jkiss.dbeaver.ui.editors.content.ContentEditorPart
;
import
javax.activation.MimeType
;
/**
* CONTENT Binary Editor
*/
public
class
ContentBinaryEditorPart
extends
BinaryEditor
implements
ContentEditorPart
{
public
ContentBinaryEditorPart
()
{
}
@Override
public
void
initPart
(
IEditorPart
contentEditor
,
MimeType
mimeType
)
{
}
@Override
public
IEditorActionBarContributor
getActionBarContributor
()
{
return
null
;
}
@Nullable
@Override
public
Control
getEditorControl
()
{
return
getManager
().
getControl
();
}
@Override
public
String
getContentTypeTitle
()
{
return
"Binary"
;
}
@Override
public
DBPImage
getContentTypeImage
()
{
return
DBIcon
.
TYPE_BINARY
;
}
@Override
public
String
getPreferredMimeType
()
{
return
"application"
;
}
@Override
public
long
getMaxContentLength
()
{
return
Long
.
MAX_VALUE
;
}
/**
* Any content is valid for binary editor so always returns true
* @return
*/
@Override
public
boolean
isPreferredContent
()
{
return
false
;
}
@Override
public
boolean
isOptionalContent
()
{
return
false
;
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentXMLEditorPart.java
已删除
100644 → 0
浏览文件 @
d40ef9a7
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package
org.jkiss.dbeaver.ui.editors.content.parts
;
import
org.eclipse.ui.IEditorActionBarContributor
;
import
org.eclipse.ui.IEditorPart
;
import
org.jkiss.dbeaver.DBeaverPreferences
;
import
org.jkiss.dbeaver.model.DBIcon
;
import
org.jkiss.dbeaver.model.DBPContextProvider
;
import
org.jkiss.dbeaver.model.DBPImage
;
import
org.jkiss.dbeaver.model.exec.DBCExecutionContext
;
import
org.jkiss.dbeaver.ui.editors.content.ContentEditorPart
;
import
org.jkiss.dbeaver.ui.editors.xml.XMLEditor
;
import
org.jkiss.dbeaver.utils.MimeTypes
;
import
javax.activation.MimeType
;
import
javax.activation.MimeTypeParseException
;
/**
* XML editor
*/
public
class
ContentXMLEditorPart
extends
XMLEditor
implements
ContentEditorPart
{
private
IEditorPart
contentEditor
;
private
MimeType
mimeType
;
public
ContentXMLEditorPart
()
{
}
@Override
public
void
initPart
(
IEditorPart
contentEditor
,
MimeType
mimeType
)
{
this
.
contentEditor
=
contentEditor
;
this
.
mimeType
=
mimeType
;
}
@Override
public
IEditorActionBarContributor
getActionBarContributor
()
{
return
null
;
}
@Override
public
String
getContentTypeTitle
()
{
return
"XML"
;
}
@Override
public
DBPImage
getContentTypeImage
()
{
return
DBIcon
.
TYPE_XML
;
}
@Override
public
String
getPreferredMimeType
()
{
return
MimeTypes
.
TEXT_XML
;
}
@Override
public
long
getMaxContentLength
()
{
if
(
contentEditor
instanceof
DBPContextProvider
)
{
DBCExecutionContext
context
=
((
DBPContextProvider
)
contentEditor
).
getExecutionContext
();
if
(
context
!=
null
)
{
return
context
.
getDataSource
().
getContainer
().
getPreferenceStore
().
getInt
(
DBeaverPreferences
.
RS_EDIT_MAX_TEXT_SIZE
);
}
}
return
10
*
1024
*
1024
;
}
@Override
public
boolean
isPreferredContent
()
{
try
{
return
mimeType
.
match
(
MimeTypes
.
TEXT_XML
);
}
catch
(
MimeTypeParseException
e
)
{
return
false
;
}
}
@Override
public
boolean
isOptionalContent
()
{
return
true
;
}
}
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/BytesContentStorage.java
浏览文件 @
03c544b3
...
...
@@ -18,9 +18,9 @@
package
org.jkiss.dbeaver.model.impl
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.model.data.DBDContentCached
;
import
org.jkiss.dbeaver.model.data.DBDContentStorage
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.utils.GeneralUtils
;
import
org.jkiss.utils.IOUtils
;
import
java.io.*
;
...
...
@@ -28,7 +28,7 @@ import java.io.*;
/**
* Memory content storage
*/
public
class
BytesContentStorage
implements
DBDContentStorage
{
public
class
BytesContentStorage
implements
DBDContentStorage
,
DBDContentCached
{
private
static
final
Log
log
=
Log
.
getLog
(
BytesContentStorage
.
class
);
...
...
@@ -66,7 +66,7 @@ public class BytesContentStorage implements DBDContentStorage {
@Override
public
String
getCharset
()
{
return
GeneralUtils
.
getDefaultFileEncoding
()
;
return
encoding
;
}
@Override
...
...
@@ -99,4 +99,9 @@ public class BytesContentStorage implements DBDContentStorage {
}
return
new
BytesContentStorage
(
result
,
encoding
);
}
@Override
public
Object
getCachedValue
()
{
return
data
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录