Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
8fbfccdb
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,发现更多精彩内容 >>
未验证
提交
8fbfccdb
编写于
8月 12, 2021
作者:
S
Serge Rider
提交者:
GitHub
8月 12, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13511 from dbeaver/number-radix-formatter-enhancements#13510
#13510 Improve radix number transformer
上级
3a48d5fe
0badbcb9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
14 deletion
+37
-14
plugins/org.jkiss.dbeaver.model/plugin.xml
plugins/org.jkiss.dbeaver.model/plugin.xml
+2
-1
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/data/transformers/RadixAttributeTransformer.java
...del/impl/data/transformers/RadixAttributeTransformer.java
+35
-13
未找到文件。
plugins/org.jkiss.dbeaver.model/plugin.xml
浏览文件 @
8fbfccdb
...
...
@@ -178,8 +178,9 @@
<type
kind=
"NUMERIC"
/>
<propertyGroup
label=
"Properties"
>
<property
id=
"radix"
label=
"Radix"
type=
"string"
description=
"Number radix"
defaultValue=
"16"
required=
"true"
validValues=
"2,8,10,16,32"
/>
<property
id=
"bits"
label=
"Bits"
type=
"integer"
description=
"Visible
bit number
"
defaultValue=
"32"
required=
"true"
/>
<property
id=
"bits"
label=
"Bits"
type=
"integer"
description=
"Visible
least significant bits number (when radix is 2)
"
defaultValue=
"32"
required=
"true"
/>
<property
id=
"prefix"
label=
"Show prefix"
type=
"boolean"
description=
"Shows radix prefix (0x for hex)"
defaultValue=
"false"
required=
"true"
/>
<property
id=
"unsigned"
label=
"Unsigned"
type=
"boolean"
description=
"Shows value without sign"
defaultValue=
"false"
required=
"true"
/>
</propertyGroup>
</transformer>
<transformer
...
...
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/data/transformers/RadixAttributeTransformer.java
浏览文件 @
8fbfccdb
...
...
@@ -46,6 +46,7 @@ public class RadixAttributeTransformer implements DBDAttributeTransformer {
public
static
final
String
PROP_RADIX
=
"radix"
;
public
static
final
String
PROP_BITS
=
"bits"
;
public
static
final
String
PROP_PREFIX
=
"prefix"
;
public
static
final
String
PROP_UNSIGNED
=
"unsigned"
;
public
static
final
String
PREFIX_HEX
=
"0x"
;
public
static
final
String
PREFIX_OCT
=
"0"
;
...
...
@@ -56,6 +57,7 @@ public class RadixAttributeTransformer implements DBDAttributeTransformer {
int
radix
=
16
;
int
bits
=
32
;
boolean
showPrefix
=
false
;
boolean
unsigned
=
false
;
if
(
options
.
containsKey
(
PROP_RADIX
))
{
radix
=
CommonUtils
.
toInt
(
options
.
get
(
PROP_RADIX
),
radix
);
}
...
...
@@ -65,23 +67,27 @@ public class RadixAttributeTransformer implements DBDAttributeTransformer {
if
(
options
.
containsKey
(
PROP_PREFIX
))
{
showPrefix
=
CommonUtils
.
getBoolean
(
options
.
get
(
PROP_PREFIX
),
showPrefix
);
}
if
(
options
.
containsKey
(
PROP_UNSIGNED
))
{
unsigned
=
CommonUtils
.
getBoolean
(
options
.
get
(
PROP_UNSIGNED
),
unsigned
);
}
attribute
.
setTransformHandler
(
new
RadixValueHandler
(
attribute
.
getValueHandler
(),
radix
,
bits
,
showPrefix
));
attribute
.
setTransformHandler
(
new
RadixValueHandler
(
attribute
.
getValueHandler
(),
radix
,
bits
,
showPrefix
,
unsigned
));
attribute
.
setPresentationAttribute
(
new
TransformerPresentationAttribute
(
attribute
,
"StringNumber"
,
-
1
,
DBPDataKind
.
STRING
));
}
private
class
RadixValueHandler
extends
ProxyValueHandler
{
private
int
radix
;
private
int
bits
;
private
boolean
showPrefix
;
private
static
class
RadixValueHandler
extends
ProxyValueHandler
{
private
final
int
radix
;
private
final
int
bits
;
private
final
boolean
showPrefix
;
private
final
boolean
unsigned
;
public
RadixValueHandler
(
DBDValueHandler
target
,
int
radix
,
int
bits
,
boolean
showPrefix
)
{
public
RadixValueHandler
(
DBDValueHandler
target
,
int
radix
,
int
bits
,
boolean
showPrefix
,
boolean
unsigned
)
{
super
(
target
);
this
.
radix
=
radix
;
this
.
bits
=
bits
;
this
.
showPrefix
=
showPrefix
;
this
.
unsigned
=
unsigned
;
}
@NotNull
...
...
@@ -89,17 +95,25 @@ public class RadixAttributeTransformer implements DBDAttributeTransformer {
public
String
getValueDisplayString
(
@NotNull
DBSTypedObject
column
,
@Nullable
Object
value
,
@NotNull
DBDDisplayFormat
format
)
{
if
(
value
instanceof
Number
)
{
final
long
longValue
=
((
Number
)
value
).
longValue
();
final
String
strValue
=
Long
.
toString
(
longValue
,
radix
).
toUpperCase
(
Locale
.
ENGLISH
);
final
String
strValue
;
final
String
strValueSign
;
if
(
unsigned
||
longValue
>=
0
)
{
strValue
=
Long
.
toUnsignedString
(
longValue
,
radix
).
toUpperCase
(
Locale
.
ENGLISH
);
strValueSign
=
""
;
}
else
{
strValue
=
Long
.
toString
(
longValue
,
radix
).
substring
(
1
).
toUpperCase
(
Locale
.
ENGLISH
);
strValueSign
=
"-"
;
}
if
(
showPrefix
)
{
if
(
radix
==
16
)
{
return
PREFIX_HEX
+
strValue
;
return
strValueSign
+
PREFIX_HEX
+
strValue
;
}
else
if
(
radix
==
8
)
{
return
PREFIX_OCT
+
strValue
;
return
strValueSign
+
PREFIX_OCT
+
strValue
;
}
else
if
(
radix
==
2
)
{
return
PREFIX_BIN
+
strValue
;
return
strValueSign
+
PREFIX_BIN
+
strValue
.
substring
(
Math
.
max
(
strValue
.
length
()
-
bits
,
1
))
;
}
}
return
strValue
;
return
strValue
Sign
+
strValue
;
}
return
DBValueFormatting
.
getDefaultValueDisplayString
(
value
,
format
);
}
...
...
@@ -109,6 +123,14 @@ public class RadixAttributeTransformer implements DBDAttributeTransformer {
public
Object
getValueFromObject
(
@NotNull
DBCSession
session
,
@NotNull
DBSTypedObject
type
,
@Nullable
Object
object
,
boolean
copy
,
boolean
validateValue
)
throws
DBCException
{
if
(
object
instanceof
String
)
{
String
strValue
=
(
String
)
object
;
String
strValueSign
=
""
;
if
(
strValue
.
isEmpty
())
{
return
0
;
}
if
(
strValue
.
charAt
(
0
)
==
'-'
)
{
strValue
=
strValue
.
substring
(
1
);
strValueSign
=
"-"
;
}
if
(
showPrefix
)
{
if
(
radix
==
16
&&
strValue
.
startsWith
(
PREFIX_HEX
))
{
strValue
=
strValue
.
substring
(
2
);
...
...
@@ -119,7 +141,7 @@ public class RadixAttributeTransformer implements DBDAttributeTransformer {
}
}
try
{
return
Long
.
parseLong
(
strValue
,
radix
);
return
Long
.
parseLong
(
strValue
Sign
+
strValue
,
radix
);
}
catch
(
NumberFormatException
e
)
{
log
.
debug
(
e
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录