Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
f2496b1e
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,发现更多精彩内容 >>
提交
f2496b1e
编写于
9月 25, 2020
作者:
N
Nikita Akilov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#9518 replace role text with combo
Former-commit-id:
fe349f4c
上级
13cc74ae
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
66 addition
and
21 deletion
+66
-21
plugins/org.jkiss.dbeaver.ext.postgresql.ui/src/org/jkiss/dbeaver/ext/postgresql/PostgreMessages.java
...src/org/jkiss/dbeaver/ext/postgresql/PostgreMessages.java
+1
-0
plugins/org.jkiss.dbeaver.ext.postgresql.ui/src/org/jkiss/dbeaver/ext/postgresql/PostgresResources.properties
...jkiss/dbeaver/ext/postgresql/PostgresResources.properties
+1
-0
plugins/org.jkiss.dbeaver.ext.postgresql.ui/src/org/jkiss/dbeaver/ext/postgresql/ui/PostgreConnectionPage.java
...kiss/dbeaver/ext/postgresql/ui/PostgreConnectionPage.java
+64
-21
未找到文件。
plugins/org.jkiss.dbeaver.ext.postgresql.ui/src/org/jkiss/dbeaver/ext/postgresql/PostgreMessages.java
浏览文件 @
f2496b1e
...
...
@@ -130,6 +130,7 @@ public class PostgreMessages extends NLS {
public
static
String
dialog_setting_sql_dd_tag_tip
;
public
static
String
dialog_setting_sql_dd_string
;
public
static
String
dialog_setting_sql_dd_code_block
;
public
static
String
dialog_setting_use_role
;
/* PostgreCreateRoleDialog */
public
static
String
dialog_create_role_title
;
...
...
plugins/org.jkiss.dbeaver.ext.postgresql.ui/src/org/jkiss/dbeaver/ext/postgresql/PostgresResources.properties
浏览文件 @
f2496b1e
...
...
@@ -108,6 +108,7 @@ dialog_setting_sql_dd_tag_label = Show $tagName$ quote as
dialog_setting_sql_dd_tag_tip
=
Show $tagName$ quotes as string quote or as code block quote
dialog_setting_sql_dd_string
=
String
dialog_setting_sql_dd_code_block
=
Code block
dialog_setting_use_role
=
Use role
dialog_setting_connection_password
=
Password
dialog_setting_connection_port
=
Port
...
...
plugins/org.jkiss.dbeaver.ext.postgresql.ui/src/org/jkiss/dbeaver/ext/postgresql/ui/PostgreConnectionPage.java
浏览文件 @
f2496b1e
...
...
@@ -21,47 +21,53 @@ import org.eclipse.swt.SWT;
import
org.eclipse.swt.events.ModifyListener
;
import
org.eclipse.swt.layout.GridData
;
import
org.eclipse.swt.layout.GridLayout
;
import
org.eclipse.swt.widgets.Combo
;
import
org.eclipse.swt.widgets.Composite
;
import
org.eclipse.swt.widgets.Group
;
import
org.eclipse.swt.widgets.Text
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.ext.postgresql.PostgreConstants
;
import
org.jkiss.dbeaver.ext.postgresql.PostgreMessages
;
import
org.jkiss.dbeaver.ext.postgresql.PostgreUtils
;
import
org.jkiss.dbeaver.ext.postgresql.model.PostgreExecutionContext
;
import
org.jkiss.dbeaver.ext.postgresql.model.impls.PostgreServerType
;
import
org.jkiss.dbeaver.model.DBPDataSourceContainer
;
import
org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration
;
import
org.jkiss.dbeaver.model.connection.DBPDriver
;
import
org.jkiss.dbeaver.model.exec.*
;
import
org.jkiss.dbeaver.ui.DBeaverIcons
;
import
org.jkiss.dbeaver.ui.ICompositeDialogPage
;
import
org.jkiss.dbeaver.ui.IDataSourceConnectionTester
;
import
org.jkiss.dbeaver.ui.UIUtils
;
import
org.jkiss.dbeaver.ui.dialogs.connection.ClientHomesSelector
;
import
org.jkiss.dbeaver.ui.dialogs.connection.ConnectionPageWithAuth
;
import
org.jkiss.dbeaver.ui.dialogs.connection.DriverPropertiesDialogPage
;
import
org.jkiss.utils.CommonUtils
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Locale
;
/**
* PostgreConnectionPage
*/
public
class
PostgreConnectionPage
extends
ConnectionPageWithAuth
implements
ICompositeDialogPage
{
public
class
PostgreConnectionPage
extends
ConnectionPageWithAuth
implements
ICompositeDialogPage
,
IDataSourceConnectionTester
{
private
static
final
Log
log
=
Log
.
getLog
(
PostgreConnectionPage
.
class
);
private
Text
hostText
;
private
Text
portText
;
private
Text
dbText
;
private
Text
roleText
;
private
Combo
roleCombo
;
private
ClientHomesSelector
homesSelector
;
private
boolean
activated
=
false
;
@Override
public
void
dispose
()
{
public
void
dispose
()
{
super
.
dispose
();
}
@Override
public
void
createControl
(
Composite
composite
)
{
public
void
createControl
(
Composite
composite
)
{
//Composite group = new Composite(composite, SWT.NONE);
//group.setLayout(new GridLayout(1, true));
ModifyListener
textListener
=
e
->
{
...
...
@@ -99,12 +105,11 @@ public class PostgreConnectionPage extends ConnectionPageWithAuth implements ICo
createAuthPanel
(
mainGroup
,
1
);
Group
advancedGroup
=
UIUtils
.
createControlGroup
(
mainGroup
,
"Advanced"
,
2
,
GridData
.
HORIZONTAL_ALIGN_BEGINNING
,
0
);
roleText
=
UIUtils
.
createLabelText
(
advancedGroup
,
"Role"
,
null
,
SWT
.
BORDER
);
gd
=
new
GridData
(
GridData
.
FILL_HORIZONTAL
|
GridData
.
HORIZONTAL_ALIGN_BEGINNING
);
roleText
.
setLayoutData
(
gd
);
roleText
.
addModifyListener
(
textListener
);
roleCombo
=
UIUtils
.
createLabelCombo
(
advancedGroup
,
PostgreMessages
.
dialog_setting_use_role
,
SWT
.
DROP_DOWN
);
roleCombo
.
setLayoutData
(
new
GridData
(
GridData
.
HORIZONTAL_ALIGN_BEGINNING
));
homesSelector
=
new
ClientHomesSelector
(
advancedGroup
,
PostgreMessages
.
dialog_setting_connection_localClient
,
false
);
gd
=
new
GridData
(
GridData
.
FILL_HORIZONTAL
|
GridData
.
HORIZONTAL_ALIGN_BEGINNING
);
...
...
@@ -115,8 +120,7 @@ public class PostgreConnectionPage extends ConnectionPageWithAuth implements ICo
}
@Override
public
boolean
isComplete
()
{
public
boolean
isComplete
()
{
return
hostText
!=
null
&&
portText
!=
null
&&
!
CommonUtils
.
isEmpty
(
hostText
.
getText
())
&&
!
CommonUtils
.
isEmpty
(
portText
.
getText
());
...
...
@@ -162,8 +166,8 @@ public class PostgreConnectionPage extends ConnectionPageWithAuth implements ICo
}
dbText
.
setText
(
databaseName
);
}
if
(
role
Text
!=
null
)
{
role
Text
.
setText
(
CommonUtils
.
notEmpty
(
connectionInfo
.
getProviderProperty
(
PostgreConstants
.
PROP_CHOSEN_ROLE
)));
if
(
role
Combo
!=
null
)
{
role
Combo
.
setText
(
CommonUtils
.
notEmpty
(
connectionInfo
.
getProviderProperty
(
PostgreConstants
.
PROP_CHOSEN_ROLE
)));
}
homesSelector
.
populateHomes
(
driver
,
connectionInfo
.
getClientHomeId
(),
site
.
isNew
());
...
...
@@ -171,8 +175,7 @@ public class PostgreConnectionPage extends ConnectionPageWithAuth implements ICo
}
@Override
public
void
saveSettings
(
DBPDataSourceContainer
dataSource
)
{
public
void
saveSettings
(
DBPDataSourceContainer
dataSource
)
{
DBPConnectionConfiguration
connectionInfo
=
dataSource
.
getConnectionConfiguration
();
if
(
hostText
!=
null
)
{
connectionInfo
.
setHostName
(
hostText
.
getText
().
trim
());
...
...
@@ -183,8 +186,8 @@ public class PostgreConnectionPage extends ConnectionPageWithAuth implements ICo
if
(
dbText
!=
null
)
{
connectionInfo
.
setDatabaseName
(
dbText
.
getText
().
trim
());
}
if
(
role
Text
!=
null
)
{
connectionInfo
.
setProviderProperty
(
PostgreConstants
.
PROP_CHOSEN_ROLE
,
role
Text
.
getText
().
trim
());
if
(
role
Combo
!=
null
)
{
connectionInfo
.
setProviderProperty
(
PostgreConstants
.
PROP_CHOSEN_ROLE
,
role
Combo
.
getText
().
trim
());
}
if
(
homesSelector
!=
null
)
{
connectionInfo
.
setClientHomeId
(
homesSelector
.
getSelectedHome
());
...
...
@@ -194,11 +197,51 @@ public class PostgreConnectionPage extends ConnectionPageWithAuth implements ICo
}
@Override
public
IDialogPage
[]
getSubPages
(
boolean
extrasOnly
,
boolean
forceCreate
)
{
public
IDialogPage
[]
getSubPages
(
boolean
extrasOnly
,
boolean
forceCreate
)
{
return
new
IDialogPage
[]
{
new
PostgreConnectionPageAdvanced
(),
new
DriverPropertiesDialogPage
(
this
)
};
}
@Override
public
void
testConnection
(
final
DBCSession
session
)
{
try
{
updateRolesCombo
(
session
);
}
catch
(
DBCException
e
)
{
log
.
error
(
e
);
}
}
private
void
updateRolesCombo
(
final
DBCSession
session
)
throws
DBCException
{
final
Collection
<
String
>
result
=
new
ArrayList
<>();
final
String
userName
=
((
PostgreExecutionContext
)
session
.
getExecutionContext
()).
getActiveUser
();
session
.
getProgressMonitor
().
subTask
(
"Exec finding roles query"
);
final
String
query
=
"WITH RECURSIVE cte AS ("
+
" SELECT oid FROM pg_roles WHERE rolname = '"
+
userName
+
"'"
+
" UNION ALL"
+
" SELECT m.roleid"
+
" FROM cte"
+
" JOIN pg_auth_members m ON m.member = cte.oid"
+
" )"
+
"SELECT oid::regrole::text AS rolenames FROM cte;"
;
try
(
DBCStatement
dbStat
=
session
.
prepareStatement
(
DBCStatementType
.
QUERY
,
query
,
false
,
false
,
false
))
{
dbStat
.
executeStatement
();
try
(
DBCResultSet
dbResult
=
dbStat
.
openResultSet
())
{
while
(
dbResult
.
nextRow
())
{
result
.
add
(
CommonUtils
.
toString
(
dbResult
.
getAttributeValue
(
"rolenames"
)));
//$NON-NLS-1$
}
}
}
UIUtils
.
asyncExec
(()
->
{
String
oldText
=
roleCombo
.
getText
();
if
(!
result
.
contains
(
""
))
{
result
.
add
(
""
);
}
roleCombo
.
setItems
(
result
.
toArray
(
new
String
[
0
]));
if
(!
result
.
contains
(
oldText
))
{
roleCombo
.
setText
(
userName
);
}
});
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录