Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
05871716
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
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,发现更多精彩内容 >>
提交
05871716
编写于
4月 22, 2017
作者:
S
Serge Rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#1492 SQL converter settings dialog
上级
a96df967
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
196 addition
and
9 deletion
+196
-9
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/convert/ISQLTextConverter.java
...iss/dbeaver/ui/editors/sql/convert/ISQLTextConverter.java
+10
-2
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/convert/SQLTargetConverterDescriptor.java
.../ui/editors/sql/convert/SQLTargetConverterDescriptor.java
+2
-2
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/convert/UnformattedSQLConverter.java
...eaver/ui/editors/sql/convert/UnformattedSQLConverter.java
+92
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/handlers/CopySourceCodeHandler.java
...beaver/ui/editors/sql/handlers/CopySourceCodeHandler.java
+92
-5
未找到文件。
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/convert/ISQL
Code
Converter.java
→
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/convert/ISQL
Text
Converter.java
浏览文件 @
05871716
...
...
@@ -17,16 +17,24 @@
package
org.jkiss.dbeaver.ui.editors.sql.convert
;
import
org.eclipse.jface.text.IDocument
;
import
org.jkiss.code.NotNull
;
import
org.jkiss.dbeaver.model.sql.SQLDialect
;
import
org.jkiss.dbeaver.model.sql.SQLSyntaxManager
;
import
java.util.Map
;
/**
* SQL code converter
*/
public
interface
ISQL
Code
Converter
{
public
interface
ISQL
Text
Converter
{
@NotNull
String
convertSQL
(
@NotNull
String
source
,
@NotNull
Map
<
String
,
Object
>
options
);
String
convertText
(
@NotNull
SQLDialect
dialect
,
@NotNull
SQLSyntaxManager
syntaxManager
,
@NotNull
IDocument
document
,
int
startPos
,
int
length
,
@NotNull
Map
<
String
,
Object
>
options
);
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/convert/SQLTargetConverterDescriptor.java
浏览文件 @
05871716
...
...
@@ -60,8 +60,8 @@ public class SQLTargetConverterDescriptor extends AbstractContextDescriptor {
return
icon
;
}
public
ISQL
Code
Converter
createInstance
()
throws
DBException
{
return
implClass
.
createInstance
(
ISQL
Code
Converter
.
class
);
public
ISQL
Text
Converter
createInstance
()
throws
DBException
{
return
implClass
.
createInstance
(
ISQL
Text
Converter
.
class
);
}
@Override
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/convert/UnformattedSQLConverter.java
0 → 100644
浏览文件 @
05871716
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.jkiss.dbeaver.ui.editors.sql.convert
;
import
org.eclipse.jface.text.BadLocationException
;
import
org.eclipse.jface.text.IDocument
;
import
org.eclipse.jface.text.rules.IToken
;
import
org.jkiss.code.NotNull
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.model.sql.SQLDialect
;
import
org.jkiss.dbeaver.model.sql.SQLSyntaxManager
;
import
org.jkiss.dbeaver.ui.TextUtils
;
import
org.jkiss.dbeaver.ui.editors.sql.syntax.SQLRuleManager
;
import
org.jkiss.dbeaver.ui.editors.sql.syntax.tokens.SQLCommentToken
;
import
org.jkiss.utils.Pair
;
import
java.util.Map
;
/**
* UnformattedSQLConverter
*/
public
class
UnformattedSQLConverter
implements
ISQLTextConverter
{
private
static
final
Log
log
=
Log
.
getLog
(
UnformattedSQLConverter
.
class
);
@NotNull
@Override
public
String
convertText
(
@NotNull
SQLDialect
dialect
,
@NotNull
SQLSyntaxManager
syntaxManager
,
@NotNull
IDocument
document
,
int
startPos
,
int
length
,
@NotNull
Map
<
String
,
Object
>
options
)
{
StringBuilder
result
=
new
StringBuilder
();
SQLRuleManager
ruleManager
=
new
SQLRuleManager
(
syntaxManager
);
ruleManager
.
setRange
(
document
,
startPos
,
length
);
String
[]
singleLineComments
=
dialect
.
getSingleLineComments
();
Pair
<
String
,
String
>
multiLineComments
=
dialect
.
getMultiLineComments
();
boolean
lastWhitespace
=
false
;
try
{
for
(;;)
{
IToken
token
=
ruleManager
.
nextToken
();
if
(
token
.
isEOF
())
{
break
;
}
int
tokenOffset
=
ruleManager
.
getTokenOffset
();
final
int
tokenLength
=
ruleManager
.
getTokenLength
();
if
(
token
.
isWhitespace
())
{
if
(!
lastWhitespace
)
{
result
.
append
(
' '
);
}
lastWhitespace
=
true
;
}
else
if
(
token
instanceof
SQLCommentToken
)
{
String
comment
=
document
.
get
(
tokenOffset
,
tokenLength
);
for
(
String
slc
:
singleLineComments
)
{
if
(
comment
.
startsWith
(
slc
))
{
if
(
multiLineComments
!=
null
)
{
comment
=
multiLineComments
.
getFirst
()
+
comment
.
substring
(
slc
.
length
())
+
multiLineComments
.
getSecond
();
}
break
;
}
}
comment
=
TextUtils
.
compactWhiteSpaces
(
comment
);
result
.
append
(
comment
);
}
else
{
lastWhitespace
=
false
;
result
.
append
(
document
.
get
(
tokenOffset
,
tokenLength
));
}
}
}
catch
(
BadLocationException
e
)
{
log
.
error
(
"Error unformatting SQL"
,
e
);
}
return
result
.
toString
().
trim
();
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/handlers/CopySourceCodeHandler.java
浏览文件 @
05871716
...
...
@@ -19,16 +19,31 @@ package org.jkiss.dbeaver.ui.editors.sql.handlers;
import
org.eclipse.core.commands.AbstractHandler
;
import
org.eclipse.core.commands.ExecutionEvent
;
import
org.eclipse.core.commands.ExecutionException
;
import
org.eclipse.jface.dialogs.IDialogConstants
;
import
org.eclipse.jface.dialogs.IDialogSettings
;
import
org.eclipse.jface.text.TextSelection
;
import
org.eclipse.jface.viewers.ISelection
;
import
org.eclipse.jface.viewers.ISelectionProvider
;
import
org.eclipse.swt.SWT
;
import
org.eclipse.swt.custom.SashForm
;
import
org.eclipse.swt.custom.StyledText
;
import
org.eclipse.swt.dnd.TextTransfer
;
import
org.eclipse.swt.layout.GridData
;
import
org.eclipse.swt.layout.GridLayout
;
import
org.eclipse.swt.widgets.Button
;
import
org.eclipse.swt.widgets.Composite
;
import
org.eclipse.swt.widgets.Display
;
import
org.eclipse.swt.widgets.Group
;
import
org.eclipse.ui.handlers.HandlerUtil
;
import
org.jkiss.dbeaver.model.exec.DBCExecutionContext
;
import
org.jkiss.dbeaver.registry.sql.SQLCommandsRegistry
;
import
org.jkiss.dbeaver.ui.UIUtils
;
import
org.jkiss.dbeaver.ui.dialogs.sql.BaseSQLDialog
;
import
org.jkiss.dbeaver.ui.editors.sql.SQLEditor
;
import
org.jkiss.dbeaver.ui.editors.sql.convert.SQLConverterRegistry
;
import
org.jkiss.dbeaver.ui.editors.sql.convert.SQLTargetConverterDescriptor
;
import
org.jkiss.dbeaver.ui.properties.PropertyTreeViewer
;
import
org.jkiss.dbeaver.utils.RuntimeUtils
;
public
class
CopySourceCodeHandler
extends
AbstractHandler
{
@Override
...
...
@@ -43,13 +58,85 @@ public class CopySourceCodeHandler extends AbstractHandler {
if
(
selection
.
isEmpty
()
||
!(
selection
instanceof
TextSelection
))
{
return
null
;
}
String
text
=
((
TextSelection
)
selection
).
getText
();
StringBuilder
result
=
new
StringBuilder
(
text
);
TargetFormatDialog
dialog
=
new
TargetFormatDialog
(
editor
,
(
TextSelection
)
selection
);
if
(
dialog
.
open
()
!=
IDialogConstants
.
OK_ID
)
{
return
null
;
}
UIUtils
.
setClipboardContents
(
HandlerUtil
.
getActiveShell
(
event
).
getDisplay
(),
TextTransfer
.
getInstance
(),
result
.
toString
());
UIUtils
.
setClipboardContents
(
Display
.
getCurrent
(),
TextTransfer
.
getInstance
(),
dialog
.
getConvertedText
());
return
null
;
}
private
static
class
TargetFormatDialog
extends
BaseSQLDialog
{
private
static
final
String
DIALOG_ID
=
"DBeaver.SQLTargetFormatDialog"
;
//$NON-NLS-1$
private
final
SQLEditor
editor
;
private
final
TextSelection
selection
;
TargetFormatDialog
(
SQLEditor
editor
,
TextSelection
selection
)
{
super
(
editor
.
getSite
(),
"Choose format"
,
null
);
this
.
editor
=
editor
;
this
.
selection
=
selection
;
}
@Override
protected
IDialogSettings
getDialogBoundsSettings
()
{
return
UIUtils
.
getDialogSettings
(
DIALOG_ID
);
}
@Override
protected
Composite
createDialogArea
(
Composite
parent
)
{
Composite
composite
=
super
.
createDialogArea
(
parent
);
((
GridLayout
)
composite
.
getLayout
()).
numColumns
=
2
;
{
Composite
formatPanel
=
UIUtils
.
createPlaceholder
(
composite
,
1
);
formatPanel
.
setLayoutData
(
new
GridData
(
GridData
.
FILL_BOTH
));
Group
formatsGroup
=
UIUtils
.
createControlGroup
(
formatPanel
,
"Format"
,
1
,
GridData
.
FILL_HORIZONTAL
,
0
);
for
(
SQLTargetConverterDescriptor
converter
:
SQLConverterRegistry
.
getInstance
().
getTargetConverters
())
{
Button
formatButton
=
new
Button
(
formatsGroup
,
SWT
.
RADIO
);
formatButton
.
setText
(
converter
.
getLabel
());
formatButton
.
setToolTipText
(
converter
.
getDescription
());
}
Group
settingsGroup
=
UIUtils
.
createControlGroup
(
formatPanel
,
"Settings"
,
1
,
GridData
.
FILL_HORIZONTAL
,
0
);
settingsGroup
.
setLayoutData
(
new
GridData
(
GridData
.
FILL_BOTH
));
PropertyTreeViewer
propsViewer
=
new
PropertyTreeViewer
(
settingsGroup
,
SWT
.
BORDER
);
}
{
Composite
previewPanel
=
new
Composite
(
composite
,
SWT
.
NONE
);
previewPanel
.
setLayoutData
(
new
GridData
(
GridData
.
FILL_BOTH
));
previewPanel
.
setLayout
(
new
GridLayout
(
1
,
false
));
SashForm
sash
=
new
SashForm
(
previewPanel
,
SWT
.
VERTICAL
);
sash
.
setLayoutData
(
new
GridData
(
GridData
.
FILL_BOTH
));
createSQLPanel
(
sash
);
Composite
targetGroup
=
UIUtils
.
createPlaceholder
(
sash
,
1
);
targetGroup
.
setLayoutData
(
new
GridData
(
GridData
.
FILL_BOTH
));
UIUtils
.
createControlLabel
(
targetGroup
,
"Result"
);
StyledText
targetText
=
new
StyledText
(
targetGroup
,
SWT
.
BORDER
|
SWT
.
READ_ONLY
);
targetText
.
setLayoutData
(
new
GridData
(
GridData
.
FILL_BOTH
));
}
return
composite
;
}
String
getConvertedText
()
{
return
selection
.
getText
();
}
@Override
protected
DBCExecutionContext
getExecutionContext
()
{
return
editor
.
getExecutionContext
();
}
@Override
protected
String
getSQLText
()
{
return
this
.
selection
.
getText
();
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录