Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
67dbdd7b
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,发现更多精彩内容 >>
提交
67dbdd7b
编写于
10月 14, 2013
作者:
J
jurgen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Base SQL dialog
Former-commit-id:
266e1089
上级
50f3e89d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
292 addition
and
51 deletion
+292
-51
plugins/org.jkiss.dbeaver.core/META-INF/MANIFEST.MF
plugins/org.jkiss.dbeaver.core/META-INF/MANIFEST.MF
+1
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/actions/navigator/NavigatorHandlerObjectBase.java
...aver/ui/actions/navigator/NavigatorHandlerObjectBase.java
+3
-3
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/sql/BaseSQLDialog.java
...e/src/org/jkiss/dbeaver/ui/dialogs/sql/BaseSQLDialog.java
+35
-43
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/sql/GenerateSQLDialog.java
...c/org/jkiss/dbeaver/ui/dialogs/sql/GenerateSQLDialog.java
+155
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/sql/ViewSQLDialog.java
...e/src/org/jkiss/dbeaver/ui/dialogs/sql/ViewSQLDialog.java
+88
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/StringEditorInput.java
...e/src/org/jkiss/dbeaver/ui/editors/StringEditorInput.java
+6
-1
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/entity/EntityEditor.java
...src/org/jkiss/dbeaver/ui/editors/entity/EntityEditor.java
+4
-4
未找到文件。
plugins/org.jkiss.dbeaver.core/META-INF/MANIFEST.MF
浏览文件 @
67dbdd7b
...
...
@@ -80,6 +80,7 @@ Export-Package: org.apache.commons.logging,
org.jkiss.dbeaver.ui.dialogs.connection,
org.jkiss.dbeaver.ui.dialogs.data,
org.jkiss.dbeaver.ui.dialogs.driver,
org.jkiss.dbeaver.ui.dialogs.sql,
org.jkiss.dbeaver.ui.dialogs.struct,
org.jkiss.dbeaver.ui.dialogs.tools,
org.jkiss.dbeaver.ui.dnd,
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/actions/navigator/NavigatorHandlerObjectBase.java
浏览文件 @
67dbdd7b
...
...
@@ -47,7 +47,7 @@ import org.jkiss.dbeaver.model.struct.DBSObject;
import
org.jkiss.dbeaver.runtime.RuntimeUtils
;
import
org.jkiss.dbeaver.ui.DBIcon
;
import
org.jkiss.dbeaver.ui.UIUtils
;
import
org.jkiss.dbeaver.ui.dialogs.ViewSQLDialog
;
import
org.jkiss.dbeaver.ui.dialogs.
sql.
ViewSQLDialog
;
import
org.jkiss.dbeaver.ui.views.navigator.database.DatabaseNavigatorView
;
import
java.lang.reflect.InvocationTargetException
;
...
...
@@ -170,10 +170,10 @@ public abstract class NavigatorHandlerObjectBase extends AbstractHandler {
if
(
view
!=
null
)
{
ViewSQLDialog
dialog
=
new
ViewSQLDialog
(
view
.
getSite
(),
commandContext
.
getDataSourceContainer
(),
commandContext
.
getDataSourceContainer
()
.
getDataSource
()
,
dialogTitle
,
DBIcon
.
SQL_PREVIEW
.
getImage
(),
script
.
toString
());
dialog
.
setImage
(
DBIcon
.
SQL_PREVIEW
.
getImage
());
dialog
.
setShowSaveButton
(
true
);
return
dialog
.
open
()
==
IDialogConstants
.
PROCEED_ID
;
}
else
{
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/
View
SQLDialog.java
→
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/
sql/Base
SQLDialog.java
浏览文件 @
67dbdd7b
...
...
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package
org.jkiss.dbeaver.ui.dialogs
;
package
org.jkiss.dbeaver.ui.dialogs
.sql
;
import
org.eclipse.jface.dialogs.Dialog
;
import
org.eclipse.jface.dialogs.IDialogConstants
;
...
...
@@ -28,46 +28,31 @@ import org.eclipse.swt.graphics.Image;
import
org.eclipse.swt.layout.FillLayout
;
import
org.eclipse.swt.layout.GridData
;
import
org.eclipse.swt.widgets.Composite
;
import
org.eclipse.swt.widgets.Control
;
import
org.eclipse.ui.IEditorSite
;
import
org.eclipse.ui.IWorkbenchPartSite
;
import
org.eclipse.ui.PartInitException
;
import
org.jkiss.dbeaver.core.CoreMessages
;
import
org.jkiss.dbeaver.ext.IDataSourceProvider
;
import
org.jkiss.dbeaver.model.DBPDataSource
;
import
org.jkiss.dbeaver.model.struct.DBSDataSourceContainer
;
import
org.jkiss.dbeaver.ui.UIUtils
;
import
org.jkiss.dbeaver.ui.editors.StringEditorInput
;
import
org.jkiss.dbeaver.ui.editors.SubEditorSite
;
import
org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase
;
public
class
ViewSQLDialog
extends
Dialog
{
public
abstract
class
BaseSQLDialog
extends
Dialog
implements
IDataSourceProvider
{
private
IEditorSite
subSite
;
private
DBSDataSourceContainer
dataSource
;
private
String
title
;
private
String
text
;
private
SQLEditorBase
sqlViewer
;
private
String
title
;
private
Image
image
;
private
boolean
showSaveButton
=
false
;
private
StringEditorInput
sqlInput
;
public
ViewSQLDialog
(
final
IWorkbenchPartSite
parentSite
,
DBSDataSourceContainer
dataSource
,
String
title
,
String
text
)
public
BaseSQLDialog
(
final
IWorkbenchPartSite
parentSite
,
String
title
,
Image
image
)
{
super
(
parentSite
.
getShell
());
this
.
dataSource
=
dataSource
;
this
.
title
=
title
;
this
.
text
=
text
;
this
.
subSite
=
new
SubEditorSite
(
parentSite
);
}
public
void
setImage
(
Image
image
)
{
this
.
image
=
image
;
}
public
void
setShowSaveButton
(
boolean
showSaveButton
)
{
this
.
showSaveButton
=
showSaveButton
;
this
.
subSite
=
new
SubEditorSite
(
parentSite
);
}
@Override
...
...
@@ -76,13 +61,17 @@ public class ViewSQLDialog extends Dialog {
}
@Override
p
rotected
Control
createDialogArea
(
Composite
parent
)
p
ublic
void
create
(
)
{
super
.
create
();
getShell
().
setText
(
title
);
if
(
image
!=
null
)
{
getShell
().
setImage
(
image
);
}
}
protected
Composite
createSQLPanel
(
Composite
parent
)
{
Composite
composite
=
(
Composite
)
super
.
createDialogArea
(
parent
);
Composite
editorPH
=
new
Composite
(
composite
,
SWT
.
BORDER
);
GridData
gd
=
new
GridData
(
GridData
.
FILL_BOTH
);
...
...
@@ -95,14 +84,10 @@ public class ViewSQLDialog extends Dialog {
@Override
public
DBPDataSource
getDataSource
()
{
return
dataSource
.
getDataSource
();
return
BaseSQLDialog
.
this
.
getDataSource
();
}
};
try
{
sqlViewer
.
init
(
subSite
,
new
StringEditorInput
(
title
,
text
,
true
));
}
catch
(
PartInitException
e
)
{
UIUtils
.
showErrorDialog
(
getShell
(),
title
,
null
,
e
);
}
updateSQL
();
sqlViewer
.
createPartControl
(
editorPH
);
sqlViewer
.
reloadSyntaxRules
();
...
...
@@ -116,29 +101,36 @@ public class ViewSQLDialog extends Dialog {
return
parent
;
}
@Override
protected
void
createButtonsForButtonBar
(
Composite
parent
)
protected
abstract
String
getSQLText
();
protected
void
createCopyButton
(
Composite
parent
)
{
if
(
showSaveButton
)
{
createButton
(
parent
,
IDialogConstants
.
PROCEED_ID
,
CoreMessages
.
dialog_view_sql_button_persist
,
true
);
createButton
(
parent
,
IDialogConstants
.
DETAILS_ID
,
CoreMessages
.
dialog_view_sql_button_copy
,
false
);
createButton
(
parent
,
IDialogConstants
.
CANCEL_ID
,
IDialogConstants
.
CANCEL_LABEL
,
false
);
}
else
{
createButton
(
parent
,
IDialogConstants
.
DETAILS_ID
,
CoreMessages
.
dialog_view_sql_button_copy
,
false
);
createButton
(
parent
,
IDialogConstants
.
OK_ID
,
IDialogConstants
.
CLOSE_LABEL
,
true
);
}
createButton
(
parent
,
IDialogConstants
.
DETAILS_ID
,
CoreMessages
.
dialog_view_sql_button_copy
,
false
);
}
protected
void
saveToClipboard
()
{
CharSequence
text
=
getSQLText
();
UIUtils
.
setClipboardContents
(
getShell
().
getDisplay
(),
TextTransfer
.
getInstance
(),
text
);
}
@Override
protected
void
buttonPressed
(
int
buttonId
)
{
if
(
buttonId
==
IDialogConstants
.
DETAILS_ID
)
{
UIUtils
.
setClipboardContents
(
getShell
().
getDisplay
(),
TextTransfer
.
getInstance
(),
text
);
}
else
if
(
buttonId
==
IDialogConstants
.
PROCEED_ID
)
{
setReturnCode
(
IDialogConstants
.
PROCEED_ID
);
close
();
saveToClipboard
();
}
else
{
super
.
buttonPressed
(
buttonId
);
}
}
protected
void
updateSQL
()
{
try
{
sqlInput
=
new
StringEditorInput
(
getShell
().
getText
(),
getSQLText
(),
true
);
sqlViewer
.
init
(
subSite
,
sqlInput
);
}
catch
(
PartInitException
e
)
{
UIUtils
.
showErrorDialog
(
getShell
(),
getShell
().
getText
(),
null
,
e
);
}
}
}
\ No newline at end of file
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/sql/GenerateSQLDialog.java
0 → 100644
浏览文件 @
67dbdd7b
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package
org.jkiss.dbeaver.ui.dialogs.sql
;
import
org.eclipse.core.runtime.IStatus
;
import
org.eclipse.core.runtime.Status
;
import
org.eclipse.core.runtime.jobs.IJobChangeEvent
;
import
org.eclipse.core.runtime.jobs.JobChangeAdapter
;
import
org.eclipse.jface.dialogs.IDialogConstants
;
import
org.eclipse.swt.SWT
;
import
org.eclipse.swt.custom.SashForm
;
import
org.eclipse.swt.graphics.Image
;
import
org.eclipse.swt.layout.GridData
;
import
org.eclipse.swt.widgets.Composite
;
import
org.eclipse.swt.widgets.Control
;
import
org.eclipse.ui.IWorkbenchPartSite
;
import
org.jkiss.dbeaver.core.CoreMessages
;
import
org.jkiss.dbeaver.model.DBPDataSource
;
import
org.jkiss.dbeaver.model.DBUtils
;
import
org.jkiss.dbeaver.model.exec.DBCException
;
import
org.jkiss.dbeaver.model.exec.DBCExecutionPurpose
;
import
org.jkiss.dbeaver.model.exec.DBCSession
;
import
org.jkiss.dbeaver.model.exec.DBCStatement
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.runtime.RuntimeUtils
;
import
org.jkiss.dbeaver.runtime.jobs.DataSourceJob
;
import
org.jkiss.dbeaver.utils.ContentUtils
;
public
abstract
class
GenerateSQLDialog
extends
BaseSQLDialog
{
private
DBPDataSource
dataSource
;
private
Runnable
onSuccess
;
public
GenerateSQLDialog
(
IWorkbenchPartSite
parentSite
,
DBPDataSource
dataSource
,
String
title
,
Image
image
)
{
super
(
parentSite
,
title
,
image
);
this
.
dataSource
=
dataSource
;
}
public
void
setOnSuccess
(
Runnable
onSuccess
)
{
this
.
onSuccess
=
onSuccess
;
}
@Override
protected
Control
createDialogArea
(
Composite
parent
)
{
SashForm
sashForm
=
new
SashForm
(
parent
,
SWT
.
HORIZONTAL
|
SWT
.
SMOOTH
);
sashForm
.
setLayoutData
(
new
GridData
(
GridData
.
FILL_BOTH
));
sashForm
.
setSashWidth
(
5
);
createSQLPanel
(
sashForm
);
createControls
(
sashForm
);
sashForm
.
setWeights
(
new
int
[]
{
80
,
20
});
return
sashForm
;
}
@Override
protected
void
createButtonsForButtonBar
(
Composite
parent
)
{
createButton
(
parent
,
IDialogConstants
.
PROCEED_ID
,
CoreMessages
.
dialog_view_sql_button_persist
,
true
);
createCopyButton
(
parent
);
createButton
(
parent
,
IDialogConstants
.
CANCEL_ID
,
IDialogConstants
.
CANCEL_LABEL
,
false
);
}
@Override
protected
void
buttonPressed
(
int
buttonId
)
{
if
(
buttonId
==
IDialogConstants
.
PROCEED_ID
)
{
setReturnCode
(
IDialogConstants
.
PROCEED_ID
);
executeSQL
();
close
();
}
else
{
super
.
buttonPressed
(
buttonId
);
}
}
private
void
executeSQL
()
{
final
String
[]
scriptLines
=
generateSQLScript
();
DataSourceJob
job
=
new
DataSourceJob
(
getShell
().
getText
(),
null
,
dataSource
)
{
@Override
protected
IStatus
run
(
DBRProgressMonitor
monitor
)
{
DBCSession
session
=
getDataSource
().
openSession
(
monitor
,
DBCExecutionPurpose
.
UTIL
,
getShell
().
getText
());
try
{
for
(
String
line
:
scriptLines
)
{
DBCStatement
statement
=
DBUtils
.
prepareStatement
(
session
,
line
);
try
{
statement
.
executeStatement
();
}
finally
{
statement
.
close
();
}
}
}
catch
(
DBCException
e
)
{
return
RuntimeUtils
.
makeExceptionStatus
(
e
);
}
finally
{
session
.
close
();
}
return
Status
.
OK_STATUS
;
}
};
job
.
addJobChangeListener
(
new
JobChangeAdapter
()
{
@Override
public
void
done
(
IJobChangeEvent
event
)
{
if
(
event
.
getResult
().
isOK
())
{
if
(
onSuccess
!=
null
)
{
onSuccess
.
run
();
}
}
}
});
job
.
schedule
();
}
@Override
public
DBPDataSource
getDataSource
()
{
return
dataSource
;
}
@Override
protected
String
getSQLText
()
{
String
scriptDelimiter
=
dataSource
.
getInfo
().
getScriptDelimiter
()
+
ContentUtils
.
getDefaultLineSeparator
();
String
[]
scriptLines
=
generateSQLScript
();
StringBuilder
sql
=
new
StringBuilder
(
scriptLines
.
length
*
64
);
for
(
String
line
:
scriptLines
)
{
sql
.
append
(
line
).
append
(
scriptDelimiter
);
}
return
sql
.
toString
();
}
protected
abstract
void
createControls
(
Composite
parent
);
protected
abstract
String
[]
generateSQLScript
();
}
\ No newline at end of file
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/sql/ViewSQLDialog.java
0 → 100644
浏览文件 @
67dbdd7b
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package
org.jkiss.dbeaver.ui.dialogs.sql
;
import
org.eclipse.jface.dialogs.IDialogConstants
;
import
org.eclipse.swt.graphics.Image
;
import
org.eclipse.swt.widgets.Composite
;
import
org.eclipse.swt.widgets.Control
;
import
org.eclipse.ui.IWorkbenchPartSite
;
import
org.jkiss.dbeaver.core.CoreMessages
;
import
org.jkiss.dbeaver.model.DBPDataSource
;
public
class
ViewSQLDialog
extends
BaseSQLDialog
{
private
DBPDataSource
dataSource
;
private
String
text
;
private
boolean
showSaveButton
=
false
;
public
ViewSQLDialog
(
final
IWorkbenchPartSite
parentSite
,
DBPDataSource
dataSource
,
String
title
,
Image
image
,
String
text
)
{
super
(
parentSite
,
title
,
image
);
this
.
dataSource
=
dataSource
;
this
.
text
=
text
;
}
public
void
setShowSaveButton
(
boolean
showSaveButton
)
{
this
.
showSaveButton
=
showSaveButton
;
}
@Override
protected
Control
createDialogArea
(
Composite
parent
)
{
return
createSQLPanel
(
parent
);
}
@Override
protected
void
createButtonsForButtonBar
(
Composite
parent
)
{
if
(
showSaveButton
)
{
createButton
(
parent
,
IDialogConstants
.
PROCEED_ID
,
CoreMessages
.
dialog_view_sql_button_persist
,
true
);
createCopyButton
(
parent
);
createButton
(
parent
,
IDialogConstants
.
CANCEL_ID
,
IDialogConstants
.
CANCEL_LABEL
,
false
);
}
else
{
createCopyButton
(
parent
);
createButton
(
parent
,
IDialogConstants
.
OK_ID
,
IDialogConstants
.
CLOSE_LABEL
,
true
);
}
}
@Override
protected
String
getSQLText
()
{
return
text
;
}
@Override
protected
void
buttonPressed
(
int
buttonId
)
{
if
(
buttonId
==
IDialogConstants
.
PROCEED_ID
)
{
setReturnCode
(
IDialogConstants
.
PROCEED_ID
);
close
();
}
else
{
super
.
buttonPressed
(
buttonId
);
}
}
@Override
public
DBPDataSource
getDataSource
()
{
return
dataSource
;
}
}
\ No newline at end of file
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/StringEditorInput.java
浏览文件 @
67dbdd7b
...
...
@@ -125,7 +125,12 @@ public class StringEditorInput implements IEditorInput {
return
name
;
}
public
String
toString
()
{
public
StringBuilder
getBuffer
()
{
return
buffer
;
}
public
String
toString
()
{
return
buffer
.
toString
();
//$NON-NLS-1$ //$NON-NLS-2$
}
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/entity/EntityEditor.java
浏览文件 @
67dbdd7b
...
...
@@ -61,7 +61,7 @@ import org.jkiss.dbeaver.ui.IHelpContextIds;
import
org.jkiss.dbeaver.ui.UIUtils
;
import
org.jkiss.dbeaver.ui.controls.ProgressPageControl
;
import
org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog
;
import
org.jkiss.dbeaver.ui.dialogs.ViewSQLDialog
;
import
org.jkiss.dbeaver.ui.dialogs.
sql.
ViewSQLDialog
;
import
org.jkiss.dbeaver.ui.editors.MultiPageDatabaseEditor
;
import
org.jkiss.dbeaver.ui.preferences.PrefConstants
;
import
org.jkiss.utils.CommonUtils
;
...
...
@@ -838,11 +838,11 @@ public class EntityEditor extends MultiPageDatabaseEditor
{
ViewSQLDialog
dialog
=
new
ViewSQLDialog
(
getEditorSite
(),
getDataSource
().
getContainer
(),
allowSave
?
CoreMessages
.
editors_entity_dialog_persist_title
:
CoreMessages
.
editors_entity_dialog_preview_title
,
getDataSource
(),
allowSave
?
CoreMessages
.
editors_entity_dialog_persist_title
:
CoreMessages
.
editors_entity_dialog_preview_title
,
DBIcon
.
SQL_PREVIEW
.
getImage
(),
script
.
toString
());
dialog
.
setShowSaveButton
(
allowSave
);
dialog
.
setImage
(
DBIcon
.
SQL_PREVIEW
.
getImage
());
result
=
dialog
.
open
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录