Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
9e3a4155
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,体验更适合开发者的 AI 搜索 >>
提交
9e3a4155
编写于
4月 27, 2022
作者:
G
Georgy Gvinepadze
提交者:
Gvinepadze Georgy
4月 28, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#16078 recreate editors on mode switch instead of hiding
上级
11dbcc1f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
124 addition
and
119 deletion
+124
-119
plugins/org.jkiss.dbeaver.ui.editors.data/src/org/jkiss/dbeaver/ui/data/editors/BaseValueEditor.java
...rc/org/jkiss/dbeaver/ui/data/editors/BaseValueEditor.java
+6
-2
plugins/org.jkiss.dbeaver.ui.editors.data/src/org/jkiss/dbeaver/ui/data/editors/DateTimeInlineEditor.java
...g/jkiss/dbeaver/ui/data/editors/DateTimeInlineEditor.java
+22
-15
plugins/org.jkiss.dbeaver.ui/src/org/jkiss/dbeaver/ui/controls/CustomTimeEditor.java
...i/src/org/jkiss/dbeaver/ui/controls/CustomTimeEditor.java
+96
-102
未找到文件。
plugins/org.jkiss.dbeaver.ui.editors.data/src/org/jkiss/dbeaver/ui/data/editors/BaseValueEditor.java
浏览文件 @
9e3a4155
...
...
@@ -166,8 +166,12 @@ public abstract class BaseValueEditor<T extends Control> implements IValueEditor
}
}
final
ControlModifyListener
modifyListener
=
new
ControlModifyListener
();
inlineControl
.
addListener
(
SWT
.
Modify
,
modifyListener
);
inlineControl
.
addListener
(
SWT
.
Selection
,
modifyListener
);
addInlineListeners
(
inlineControl
,
modifyListener
);
}
protected
void
addInlineListeners
(
@NotNull
Control
inlineControl
,
@NotNull
Listener
listener
)
{
inlineControl
.
addListener
(
SWT
.
Modify
,
listener
);
inlineControl
.
addListener
(
SWT
.
Selection
,
listener
);
}
private
void
addAutoSaveSupport
(
final
Control
inlineControl
)
{
...
...
plugins/org.jkiss.dbeaver.ui.editors.data/src/org/jkiss/dbeaver/ui/data/editors/DateTimeInlineEditor.java
浏览文件 @
9e3a4155
...
...
@@ -25,6 +25,7 @@ import org.eclipse.swt.events.SelectionEvent;
import
org.eclipse.swt.widgets.Composite
;
import
org.eclipse.swt.widgets.Control
;
import
org.eclipse.swt.widgets.Event
;
import
org.eclipse.swt.widgets.Listener
;
import
org.jkiss.code.NotNull
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBException
;
...
...
@@ -108,6 +109,9 @@ public class DateTimeInlineEditor extends BaseValueEditor<Control> {
@Override
public
void
run
()
{
super
.
run
();
if
(
parent
.
isCalendarMode
())
{
return
;
}
if
(
parent
.
isDirty
())
{
try
{
Object
value
=
parent
.
extractEditorValue
();
...
...
@@ -142,6 +146,24 @@ public class DateTimeInlineEditor extends BaseValueEditor<Control> {
super
(
controller
);
}
@Override
protected
void
addInlineListeners
(
@NotNull
Control
inlineControl
,
@NotNull
Listener
listener
)
{
super
.
addInlineListeners
(
inlineControl
,
listener
);
timeEditor
.
addSelectionAdapter
(
new
SelectionAdapter
()
{
@Override
public
void
widgetSelected
(
SelectionEvent
e
)
{
Event
selectionEvent
=
new
Event
();
selectionEvent
.
widget
=
timeEditor
.
getControl
();
timeEditor
.
getControl
().
notifyListeners
(
SWT
.
Selection
,
selectionEvent
);
}
});
timeEditor
.
addModifyListener
(
e
->
{
Event
modificationEvent
=
new
Event
();
modificationEvent
.
widget
=
timeEditor
.
getControl
();
timeEditor
.
getControl
().
notifyListeners
(
SWT
.
Modify
,
modificationEvent
);
});
}
@Override
protected
Control
createControl
(
Composite
editPlaceholder
)
{
Object
value
=
valueController
.
getValue
();
...
...
@@ -157,21 +179,6 @@ public class DateTimeInlineEditor extends BaseValueEditor<Control> {
textMode
.
setChecked
(
true
);
}
else
dateEditorMode
.
setChecked
(
true
);
timeEditor
.
addSelectionAdapter
(
new
SelectionAdapter
()
{
@Override
public
void
widgetSelected
(
SelectionEvent
e
)
{
dirty
=
true
;
Event
selectionEvent
=
new
Event
();
selectionEvent
.
widget
=
timeEditor
.
getControl
();
timeEditor
.
getControl
().
notifyListeners
(
SWT
.
Selection
,
selectionEvent
);
}
});
timeEditor
.
addModifyListener
(
e
->
{
dirty
=
true
;
Event
modificationEvent
=
new
Event
();
modificationEvent
.
widget
=
timeEditor
.
getControl
();
timeEditor
.
getControl
().
notifyListeners
(
SWT
.
Modify
,
modificationEvent
);
});
primeEditorValue
(
value
);
timeEditor
.
createDateFormat
(
valueController
.
getValueType
());
timeEditor
.
setEditable
(!
valueController
.
isReadOnly
());
...
...
plugins/org.jkiss.dbeaver.ui/src/org/jkiss/dbeaver/ui/controls/CustomTimeEditor.java
浏览文件 @
9e3a4155
...
...
@@ -17,14 +17,10 @@
package
org.jkiss.dbeaver.ui.controls
;
import
org.eclipse.swt.SWT
;
import
org.eclipse.swt.events.ModifyListener
;
import
org.eclipse.swt.events.SelectionAdapter
;
import
org.eclipse.swt.layout.GridData
;
import
org.eclipse.swt.layout.GridLayout
;
import
org.eclipse.swt.widgets.Composite
;
import
org.eclipse.swt.widgets.DateTime
;
import
org.eclipse.swt.widgets.Label
;
import
org.eclipse.swt.widgets.Text
;
import
org.eclipse.swt.widgets.*
;
import
org.jkiss.code.NotNull
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.model.impl.data.formatters.TimestampFormatSample
;
...
...
@@ -42,21 +38,26 @@ import java.util.Map;
*/
public
class
CustomTimeEditor
{
private
final
static
String
FORMAT_PATTERN
=
"pattern"
;
private
final
int
style
;
private
final
boolean
isPanel
;
private
DateTime
dateEditor
;
private
DateTime
timeEditor
;
private
final
Composite
basePart
;
private
Composite
basePart
;
private
static
final
String
TIMESTAMP_DEFAULT_FORMAT
=
"yyyy-MM-dd HH:mm:ss"
;
private
String
format
=
""
;
private
Label
timeLabel
;
private
Label
dateLabel
;
private
int
millis
=
-
1
;
private
String
dateAsText
=
""
;
private
final
boolean
isInline
;
private
InputMode
inputMode
=
InputMode
.
None
;
private
final
Calendar
calendar
=
Calendar
.
getInstance
();
private
Text
textEditor
;
private
Listener
modifyListener
;
private
SelectionAdapter
selectionListener
;
private
boolean
editable
;
private
enum
InputMode
{
None
,
...
...
@@ -70,17 +71,11 @@ public class CustomTimeEditor {
switch
(
jdbcType
)
{
case
DATE:
inputMode
=
InputMode
.
Date
;
timeEditor
.
dispose
();
if
(
timeLabel
!=
null
)
{
timeLabel
.
dispose
();
}
disposeDateEditor
(
timeEditor
,
timeLabel
);
break
;
case
TIME:
inputMode
=
InputMode
.
Time
;
dateEditor
.
dispose
();
if
(
dateLabel
!=
null
)
{
dateLabel
.
dispose
();
}
disposeDateEditor
(
dateEditor
,
dateLabel
);
break
;
default
:
inputMode
=
InputMode
.
DateTime
;
...
...
@@ -89,13 +84,14 @@ public class CustomTimeEditor {
}
public
CustomTimeEditor
(
@NotNull
Composite
parent
,
int
style
,
boolean
isPanel
,
boolean
isInline
)
{
basePart
=
getComposite
(
parent
,
style
,
isPanel
,
isInline
);
this
.
isInline
=
isInline
;
this
.
isPanel
=
isPanel
;
this
.
style
=
style
;
initEditor
(
parent
,
style
);
}
@NotNull
private
Composite
getComposite
(
@NotNull
Composite
parent
,
int
style
,
boolean
isPanel
,
boolean
isInline
)
{
final
Composite
basePart
;
private
Composite
initEditor
(
@NotNull
Composite
parent
,
int
style
)
{
basePart
=
new
Composite
(
parent
,
style
);
GridLayout
layout
=
new
GridLayout
(
2
,
false
);
if
(
isInline
)
{
...
...
@@ -103,97 +99,67 @@ public class CustomTimeEditor {
layout
.
marginHeight
=
0
;
}
basePart
.
setLayout
(
layout
);
setToDateComposite
();
final
GridData
layoutData
=
new
GridData
(
SWT
.
FILL
,
SWT
.
RIGHT
,
true
,
false
,
1
,
1
);
if
(!
isInline
)
dateLabel
=
UIUtils
.
createLabel
(
basePart
,
"Date"
);
this
.
dateEditor
=
new
DateTime
(
basePart
,
SWT
.
DROP_DOWN
);
dateEditor
.
setLayoutData
(
layoutData
);
if
(!
isInline
)
timeLabel
=
UIUtils
.
createLabel
(
basePart
,
"Time"
);
this
.
timeEditor
=
new
DateTime
(
basePart
,
SWT
.
TIME
|
SWT
.
MEDIUM
);
this
.
timeEditor
.
setLayoutData
(
layoutData
);
textEditor
=
new
Text
(
basePart
,
isPanel
&&
!
isInline
?
style
:
style
|
SWT
.
BORDER
);
final
GridData
gridData
=
new
GridData
(
SWT
.
FILL
,
SWT
.
FILL
,
true
,
true
,
1
,
1
);
textEditor
.
setLayoutData
(
gridData
);
textEditor
.
setVisible
(
false
);
gridData
.
exclude
=
true
;
//
Magical part which fixes incorrect display of first value i
n inline mode
//
fixes calendar issues o
n inline mode
basePart
.
pack
();
basePart
.
layout
();
this
.
format
=
getTimestampFormat
();
return
basePart
;
}
/**
*
Hides all DateTime editors and shows text editor instead
*
Disposes all DateTime editors and their labels and creates text editor
*/
public
void
setToTextComposite
()
{
if
(
textEditor
!=
null
&&
!
textEditor
.
isDisposed
())
{
return
;
}
disposeDateEditor
(
timeEditor
,
timeLabel
);
timeEditor
=
null
;
disposeDateEditor
(
dateEditor
,
dateLabel
);
dateEditor
=
null
;
textEditor
=
new
Text
(
basePart
,
isPanel
&&
!
isInline
?
style
:
style
|
SWT
.
BORDER
);
final
GridData
gridData
=
new
GridData
(
SWT
.
FILL
,
SWT
.
FILL
,
true
,
true
,
1
,
1
);
textEditor
.
setLayoutData
(
gridData
);
textEditor
.
setVisible
(
true
);
GridLayout
layout
=
new
GridLayout
(
1
,
false
);
{
layout
.
marginHeight
=
0
;
layout
.
marginWidth
=
0
;
}
basePart
.
setLayout
(
layout
);
final
GridData
layoutData
=
new
GridData
(
SWT
.
FILL
,
SWT
.
UP
,
true
,
false
,
1
,
1
);
if
(!
timeEditor
.
isDisposed
())
{
timeEditor
.
setLayoutData
(
layoutData
);
timeEditor
.
setVisible
(
layoutData
.
exclude
);
if
(
timeLabel
!=
null
)
{
timeLabel
.
setLayoutData
(
layoutData
);
timeLabel
.
setVisible
(
layoutData
.
exclude
);
}
}
if
(!
dateEditor
.
isDisposed
())
{
dateEditor
.
setLayoutData
(
layoutData
);
dateEditor
.
setVisible
(
layoutData
.
exclude
);
if
(
dateLabel
!=
null
)
{
dateLabel
.
setLayoutData
(
layoutData
);
dateLabel
.
setVisible
(
layoutData
.
exclude
);
allowEdit
();
textEditor
.
setText
(
dateAsText
);
basePart
.
layout
();
}
private
void
disposeDateEditor
(
DateTime
dateTimeEditor
,
Label
dateTimeLabel
)
{
if
(
dateTimeEditor
!=
null
)
{
dateTimeEditor
.
dispose
();
if
(
dateTimeLabel
!=
null
)
{
dateTimeLabel
.
dispose
();
}
}
layoutData
.
exclude
=
true
;
basePart
.
layout
();
}
/**
*
Hides Text editor and shows DateTime one
s
*
Disposes text editor components and creates DateTime editor
s
*/
public
void
setToDateComposite
()
{
final
GridData
gridData
=
new
GridData
(
SWT
.
FILL
,
SWT
.
FILL
,
true
,
true
,
1
,
1
);
textEditor
.
setLayoutData
(
gridData
);
textEditor
.
setVisible
(
false
);
gridData
.
exclude
=
true
;
GridLayout
layout
=
new
GridLayout
(
2
,
false
);
if
(
isInline
){
layout
.
marginWidth
=
0
;
layout
.
marginHeight
=
0
;
if
(
dateEditor
!=
null
||
timeEditor
!=
null
)
{
return
;
}
if
(
textEditor
!=
null
&&
!
textEditor
.
isDisposed
())
{
textEditor
.
dispose
();
textEditor
=
null
;
}
basePart
.
setLayout
(
layout
);
final
GridData
layoutData
=
new
GridData
(
SWT
.
FILL
,
SWT
.
RIGHT
,
true
,
false
,
1
,
1
);
final
GridData
layoutDataForLabels
=
new
GridData
(
SWT
.
FILL
,
SWT
.
CENTER
,
false
,
false
,
1
,
1
);
if
(!
isInline
)
dateLabel
=
UIUtils
.
createLabel
(
basePart
,
"Date"
);
this
.
dateEditor
=
new
DateTime
(
basePart
,
SWT
.
DROP_DOWN
);
dateEditor
.
setLayoutData
(
layoutData
);
if
(!
isInline
)
timeLabel
=
UIUtils
.
createLabel
(
basePart
,
"Time"
);
this
.
timeEditor
=
new
DateTime
(
basePart
,
SWT
.
TIME
|
SWT
.
MEDIUM
);
this
.
timeEditor
.
setLayoutData
(
layoutData
);
allowEdit
();
if
(!
dateEditor
.
isDisposed
())
{
dateEditor
.
setLayoutData
(
layoutData
);
dateEditor
.
setVisible
(
true
);
dateLabel
.
setLayoutData
(
layoutDataForLabels
);
dateLabel
.
setVisible
(
true
);
}
if
(!
timeEditor
.
isDisposed
())
{
timeEditor
.
setLayoutData
(
layoutData
);
timeEditor
.
setVisible
(
true
);
timeLabel
.
setLayoutData
(
layoutDataForLabels
);
timeLabel
.
setVisible
(
true
);
}
setDateFromCalendar
();
updateListeners
();
basePart
.
layout
();
}
...
...
@@ -201,23 +167,42 @@ public class CustomTimeEditor {
this
.
format
=
format
;
}
public
void
updateListeners
()
{
if
(
selectionListener
!=
null
)
{
if
(
dateEditor
!=
null
&&
!
dateEditor
.
isDisposed
())
{
dateEditor
.
addSelectionListener
(
selectionListener
);
}
if
(
timeEditor
!=
null
&&
!
timeEditor
.
isDisposed
())
{
timeEditor
.
addSelectionListener
(
selectionListener
);
}
}
if
(
modifyListener
!=
null
&&
textEditor
!=
null
&&
!
textEditor
.
isDisposed
())
{
textEditor
.
addListener
(
SWT
.
Modify
,
modifyListener
);
}
}
/**
* Creates listeners for date editors.
*
* @param listener listener to add to all existing editors
*/
public
void
addSelectionAdapter
(
@NotNull
SelectionAdapter
listener
)
{
if
(
dateEditor
!=
null
&&
!
dateEditor
.
isDisposed
())
{
dateEditor
.
addSelectionListener
(
listener
);
}
if
(
timeEditor
!=
null
&&
!
timeEditor
.
isDisposed
())
{
timeEditor
.
addSelectionListener
(
listener
);
}
selectionListener
=
listener
;
updateListeners
();
}
public
void
addModifyListener
(
@NotNull
ModifyListener
listener
)
{
if
(
textEditor
!=
null
&&
!
textEditor
.
isDisposed
())
{
textEditor
.
addModifyListener
(
listener
);
public
void
addModifyListener
(
@NotNull
Listener
listener
)
{
modifyListener
=
listener
;
updateListeners
();
}
private
static
void
setWithoutListener
(
@NotNull
Control
control
,
int
type
,
Listener
listener
,
@NotNull
Runnable
blockToRun
)
{
if
(
listener
!=
null
)
{
control
.
removeListener
(
type
,
listener
);
blockToRun
.
run
();
control
.
addListener
(
type
,
listener
);
}
else
{
blockToRun
.
run
();
}
}
...
...
@@ -233,8 +218,11 @@ public class CustomTimeEditor {
}
public
void
setTextValue
(
@Nullable
String
value
)
{
dateAsText
=
value
;
if
(
textEditor
!=
null
&&
!
textEditor
.
isDisposed
())
{
textEditor
.
setText
(
value
!=
null
?
value
:
""
);
setWithoutListener
(
textEditor
,
SWT
.
Modify
,
modifyListener
,
()
->
{
textEditor
.
setText
(
value
);
});
}
}
...
...
@@ -242,15 +230,17 @@ public class CustomTimeEditor {
if
(
value
!=
null
)
{
calendar
.
setTime
(
value
);
}
if
(!
dateEditor
.
isDisposed
())
{
setDateFromCalendar
();
}
private
void
setDateFromCalendar
()
{
if
(
dateEditor
!=
null
&&
!
dateEditor
.
isDisposed
())
{
dateEditor
.
setDate
(
calendar
.
get
(
Calendar
.
YEAR
),
calendar
.
get
(
Calendar
.
MONTH
),
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
));
}
if
(!
timeEditor
.
isDisposed
())
{
if
(
timeEditor
!=
null
&&
!
timeEditor
.
isDisposed
())
{
timeEditor
.
addTraverseListener
(
e
->
timeEditor
.
setFocus
());
timeEditor
.
setTime
(
calendar
.
get
(
Calendar
.
HOUR_OF_DAY
),
calendar
.
get
(
Calendar
.
MINUTE
),
calendar
.
get
(
Calendar
.
SECOND
));
try
{
millis
=
calendar
.
get
(
Calendar
.
MILLISECOND
);
}
catch
(
ArrayIndexOutOfBoundsException
e
)
{
...
...
@@ -258,12 +248,11 @@ public class CustomTimeEditor {
millis
=
-
1
;
}
}
}
@Nullable
public
String
getValueAsString
()
{
if
(
textEditor
!=
null
&&
!
textEditor
.
isDisposed
()
&&
textEditor
.
isVisible
()
)
{
if
(
textEditor
!=
null
&&
!
textEditor
.
isDisposed
())
{
return
textEditor
.
getText
();
}
return
null
;
...
...
@@ -294,6 +283,11 @@ public class CustomTimeEditor {
}
public
void
setEditable
(
boolean
editable
)
{
this
.
editable
=
editable
;
allowEdit
();
}
public
void
allowEdit
()
{
if
(
this
.
dateEditor
!=
null
&&
!
this
.
dateEditor
.
isDisposed
())
{
this
.
dateEditor
.
setEnabled
(
editable
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录