Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
388a22d0
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,发现更多精彩内容 >>
提交
388a22d0
编写于
6月 12, 2014
作者:
J
jurgen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Number value editor
上级
1cd7cba2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
286 addition
and
170 deletion
+286
-170
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/data/BitInlineEditor.java
...rc/org/jkiss/dbeaver/model/impl/data/BitInlineEditor.java
+64
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/data/NumberEditorHelper.java
...org/jkiss/dbeaver/model/impl/data/NumberEditorHelper.java
+37
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/data/NumberInlineEditor.java
...org/jkiss/dbeaver/model/impl/data/NumberInlineEditor.java
+140
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/jdbc/data/JDBCNumberValueHandler.java
.../dbeaver/model/impl/jdbc/data/JDBCNumberValueHandler.java
+45
-170
未找到文件。
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/data/BitInlineEditor.java
0 → 100644
浏览文件 @
388a22d0
/*
* Copyright (C) 2010-2014 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.model.impl.data
;
import
org.eclipse.swt.SWT
;
import
org.eclipse.swt.widgets.Combo
;
import
org.eclipse.swt.widgets.Composite
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.model.data.DBDValueController
;
/**
* BitInlineEditor
*/
public
class
BitInlineEditor
extends
BaseValueEditor
<
Combo
>
{
public
BitInlineEditor
(
DBDValueController
controller
)
{
super
(
controller
);
}
@Override
protected
Combo
createControl
(
Composite
editPlaceholder
)
{
final
Combo
editor
=
new
Combo
(
valueController
.
getEditPlaceholder
(),
SWT
.
READ_ONLY
);
editor
.
add
(
"0"
);
//$NON-NLS-1$
editor
.
add
(
"1"
);
//$NON-NLS-1$
editor
.
setEnabled
(!
valueController
.
isReadOnly
());
return
editor
;
}
@Override
public
void
primeEditorValue
(
@Nullable
Object
value
)
throws
DBException
{
control
.
setText
(
value
==
null
?
"0"
:
value
.
toString
());
//$NON-NLS-1$
}
@Override
public
Object
extractEditorValue
()
{
switch
(
control
.
getSelectionIndex
())
{
case
0
:
return
(
byte
)
0
;
case
1
:
return
(
byte
)
1
;
default
:
return
null
;
}
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/data/NumberEditorHelper.java
0 → 100644
浏览文件 @
388a22d0
/*
* Copyright (C) 2010-2014 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.model.impl.data
;
import
org.jkiss.dbeaver.model.data.DBDDataFormatter
;
import
org.jkiss.dbeaver.model.struct.DBSTypedObject
;
import
java.util.Locale
;
/**
* NumberEditorHelper
*/
public
interface
NumberEditorHelper
{
Locale
getLocale
();
DBDDataFormatter
getFormatter
();
Class
<?
extends
Number
>
getNumberType
(
DBSTypedObject
type
,
Object
originalValue
);
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/data/NumberInlineEditor.java
0 → 100644
浏览文件 @
388a22d0
/*
* Copyright (C) 2010-2014 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.model.impl.data
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.eclipse.swt.SWT
;
import
org.eclipse.swt.widgets.Composite
;
import
org.eclipse.swt.widgets.Text
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.model.data.DBDDataFormatter
;
import
org.jkiss.dbeaver.model.data.DBDDisplayFormat
;
import
org.jkiss.dbeaver.model.data.DBDValueController
;
import
org.jkiss.dbeaver.ui.UIUtils
;
import
org.jkiss.utils.CommonUtils
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.text.ParseException
;
/**
* NumberInlineEditor
*/
public
class
NumberInlineEditor
extends
BaseValueEditor
<
Text
>
{
static
final
Log
log
=
LogFactory
.
getLog
(
NumberInlineEditor
.
class
);
private
static
final
int
MAX_NUMBER_LENGTH
=
100
;
private
static
final
String
BAD_DOUBLE_VALUE
=
"2.2250738585072012e-308"
;
//$NON-NLS-1$
private
final
NumberEditorHelper
helper
;
public
NumberInlineEditor
(
DBDValueController
controller
,
NumberEditorHelper
helper
)
{
super
(
controller
);
this
.
helper
=
helper
;
}
@Override
protected
Text
createControl
(
Composite
editPlaceholder
)
{
final
Text
editor
=
new
Text
(
valueController
.
getEditPlaceholder
(),
SWT
.
BORDER
);
editor
.
setEditable
(!
valueController
.
isReadOnly
());
editor
.
setTextLimit
(
MAX_NUMBER_LENGTH
);
Class
<?
extends
Number
>
type
=
helper
.
getNumberType
(
valueController
.
getValueType
(),
valueController
.
getValue
());
if
(
type
==
Float
.
class
||
type
==
Double
.
class
||
type
==
BigDecimal
.
class
)
{
editor
.
addVerifyListener
(
UIUtils
.
getNumberVerifyListener
(
helper
.
getLocale
()));
}
else
{
editor
.
addVerifyListener
(
UIUtils
.
getIntegerVerifyListener
(
helper
.
getLocale
()));
}
return
editor
;
}
@Override
public
void
primeEditorValue
(
@Nullable
Object
value
)
throws
DBException
{
if
(
value
!=
null
)
{
control
.
setText
(
valueController
.
getValueHandler
().
getValueDisplayString
(
valueController
.
getValueType
(),
value
,
DBDDisplayFormat
.
UI
));
}
else
{
control
.
setText
(
""
);
}
if
(
valueController
.
getEditType
()
==
DBDValueController
.
EditType
.
INLINE
)
{
control
.
selectAll
();
}
}
@Nullable
@Override
public
Object
extractEditorValue
()
{
String
text
=
control
.
getText
();
if
(
CommonUtils
.
isEmpty
(
text
))
{
return
null
;
}
Class
<?
extends
Number
>
hintType
=
helper
.
getNumberType
(
valueController
.
getValueType
(),
valueController
.
getValue
());
return
convertStringToNumber
(
text
,
hintType
,
helper
.
getFormatter
());
}
@Nullable
public
static
Number
convertStringToNumber
(
String
text
,
Class
<?
extends
Number
>
hintType
,
DBDDataFormatter
formatter
)
{
if
(
text
==
null
||
text
.
length
()
==
0
)
{
return
null
;
}
try
{
if
(
hintType
==
Long
.
class
)
{
try
{
return
Long
.
valueOf
(
text
);
}
catch
(
NumberFormatException
e
)
{
return
new
BigInteger
(
text
);
}
}
else
if
(
hintType
==
Integer
.
class
)
{
return
Integer
.
valueOf
(
text
);
}
else
if
(
hintType
==
Short
.
class
)
{
return
Short
.
valueOf
(
text
);
}
else
if
(
hintType
==
Byte
.
class
)
{
return
Byte
.
valueOf
(
text
);
}
else
if
(
hintType
==
Float
.
class
)
{
return
Float
.
valueOf
(
text
);
}
else
if
(
hintType
==
Double
.
class
)
{
return
toDouble
(
text
);
}
else
if
(
hintType
==
BigInteger
.
class
)
{
return
new
BigInteger
(
text
);
}
else
{
return
new
BigDecimal
(
text
);
}
}
catch
(
NumberFormatException
e
)
{
log
.
debug
(
"Bad numeric value '"
+
text
+
"' - "
+
e
.
getMessage
());
//$NON-NLS-1$ //$NON-NLS-2$
try
{
return
(
Number
)
formatter
.
parseValue
(
text
,
hintType
);
}
catch
(
ParseException
e1
)
{
log
.
debug
(
"Can't parse numeric value ["
+
text
+
"] using formatter"
,
e
);
return
null
;
}
}
}
private
static
Number
toDouble
(
String
text
)
{
if
(
text
.
equals
(
BAD_DOUBLE_VALUE
))
{
return
Double
.
MIN_VALUE
;
}
return
Double
.
valueOf
(
text
);
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/jdbc/data/JDBCNumberValueHandler.java
浏览文件 @
388a22d0
...
...
@@ -18,10 +18,6 @@
*/
package
org.jkiss.dbeaver.model.impl.jdbc.data
;
import
org.eclipse.swt.SWT
;
import
org.eclipse.swt.widgets.Combo
;
import
org.eclipse.swt.widgets.Composite
;
import
org.eclipse.swt.widgets.Text
;
import
org.jkiss.code.NotNull
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBException
;
...
...
@@ -33,28 +29,24 @@ import org.jkiss.dbeaver.model.exec.DBCSession;
import
org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement
;
import
org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet
;
import
org.jkiss.dbeaver.model.exec.jdbc.JDBCSession
;
import
org.jkiss.dbeaver.model.impl.data.B
aseValu
eEditor
;
import
org.jkiss.dbeaver.model.impl.data.B
itInlin
eEditor
;
import
org.jkiss.dbeaver.model.impl.data.DefaultDataFormatter
;
import
org.jkiss.dbeaver.model.impl.data.NumberEditorHelper
;
import
org.jkiss.dbeaver.model.impl.data.NumberInlineEditor
;
import
org.jkiss.dbeaver.model.struct.DBSTypedObject
;
import
org.jkiss.dbeaver.ui.UIUtils
;
import
org.jkiss.dbeaver.ui.dialogs.data.DefaultValueViewDialog
;
import
org.jkiss.utils.CommonUtils
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.sql.SQLException
;
import
java.text.ParseException
;
import
java.util.Locale
;
/**
* JDBC number value handler
*/
public
class
JDBCNumberValueHandler
extends
JDBCAbstractValueHandler
{
public
class
JDBCNumberValueHandler
extends
JDBCAbstractValueHandler
implements
NumberEditorHelper
{
private
static
final
String
TYPE_NAME_NUMBER
=
"number"
;
//$NON-NLS-1$
private
static
final
int
MAX_NUMBER_LENGTH
=
100
;
private
static
final
String
BAD_DOUBLE_VALUE
=
"2.2250738585072012e-308"
;
//$NON-NLS-1$
private
Locale
locale
;
private
DBDDataFormatter
formatter
;
...
...
@@ -221,79 +213,9 @@ public class JDBCNumberValueHandler extends JDBCAbstractValueHandler {
case
INLINE:
case
PANEL:
if
(
controller
.
getValueType
().
getDataKind
()
==
DBPDataKind
.
BOOLEAN
)
{
return
new
BaseValueEditor
<
Combo
>(
controller
)
{
@Override
protected
Combo
createControl
(
Composite
editPlaceholder
)
{
final
Combo
editor
=
new
Combo
(
valueController
.
getEditPlaceholder
(),
SWT
.
READ_ONLY
);
editor
.
add
(
"0"
);
//$NON-NLS-1$
editor
.
add
(
"1"
);
//$NON-NLS-1$
editor
.
setEnabled
(!
valueController
.
isReadOnly
());
return
editor
;
}
@Override
public
void
primeEditorValue
(
@Nullable
Object
value
)
throws
DBException
{
control
.
setText
(
value
==
null
?
"0"
:
value
.
toString
());
//$NON-NLS-1$
}
@Override
public
Object
extractEditorValue
()
{
switch
(
control
.
getSelectionIndex
())
{
case
0
:
return
(
byte
)
0
;
case
1
:
return
(
byte
)
1
;
default
:
return
null
;
}
}
};
return
new
BitInlineEditor
(
controller
);
}
else
{
return
new
BaseValueEditor
<
Text
>(
controller
)
{
@Override
protected
Text
createControl
(
Composite
editPlaceholder
)
{
final
Text
editor
=
new
Text
(
valueController
.
getEditPlaceholder
(),
SWT
.
BORDER
);
editor
.
setEditable
(!
valueController
.
isReadOnly
());
editor
.
setTextLimit
(
MAX_NUMBER_LENGTH
);
switch
(
valueController
.
getValueType
().
getTypeID
())
{
case
java
.
sql
.
Types
.
BIGINT
:
case
java
.
sql
.
Types
.
INTEGER
:
case
java
.
sql
.
Types
.
SMALLINT
:
case
java
.
sql
.
Types
.
TINYINT
:
case
java
.
sql
.
Types
.
BIT
:
editor
.
addVerifyListener
(
UIUtils
.
getIntegerVerifyListener
(
locale
));
break
;
default
:
editor
.
addVerifyListener
(
UIUtils
.
getNumberVerifyListener
(
locale
));
break
;
}
return
editor
;
}
@Override
public
void
primeEditorValue
(
@Nullable
Object
value
)
throws
DBException
{
if
(
value
!=
null
)
{
control
.
setText
(
getValueDisplayString
(
valueController
.
getValueType
(),
value
,
DBDDisplayFormat
.
UI
));
}
else
{
control
.
setText
(
""
);
}
if
(
valueController
.
getEditType
()
==
DBDValueController
.
EditType
.
INLINE
)
{
control
.
selectAll
();
}
}
@Nullable
@Override
public
Object
extractEditorValue
()
{
String
text
=
control
.
getText
();
if
(
CommonUtils
.
isEmpty
(
text
))
{
return
null
;
}
return
convertStringToNumber
(
formatter
,
text
,
valueController
.
getValue
(),
valueController
.
getValueType
());
}
};
return
new
NumberInlineEditor
(
controller
,
this
);
}
case
EDITOR:
return
new
DefaultValueViewDialog
(
controller
);
...
...
@@ -323,100 +245,53 @@ public class JDBCNumberValueHandler extends JDBCAbstractValueHandler {
}
else
if
(
object
instanceof
Number
)
{
return
object
;
}
else
if
(
object
instanceof
String
)
{
return
convertStringToNumber
(
formatter
,
(
String
)
object
,
null
,
type
);
return
NumberInlineEditor
.
convertStringToNumber
((
String
)
object
,
getNumberType
(
type
,
null
),
formatter
);
}
else
{
log
.
warn
(
"Unrecognized type '"
+
object
.
getClass
().
getName
()
+
"' - can't convert to numeric"
);
return
null
;
}
}
@Nullable
public
static
Number
convertStringToNumber
(
DBDDataFormatter
formatter
,
String
text
,
@Nullable
Object
originalValue
,
DBSTypedObject
type
)
{
if
(
text
==
null
||
text
.
length
()
==
0
)
{
return
null
;
}
Class
<?>
hintType
=
null
;
try
{
if
(
originalValue
instanceof
Number
)
{
if
(
originalValue
instanceof
Long
)
{
hintType
=
Long
.
class
;
return
Long
.
valueOf
(
text
);
}
else
if
(
originalValue
instanceof
Integer
)
{
hintType
=
Integer
.
class
;
return
Integer
.
valueOf
(
text
);
}
else
if
(
originalValue
instanceof
Short
)
{
hintType
=
Short
.
class
;
return
Short
.
valueOf
(
text
);
}
else
if
(
originalValue
instanceof
Byte
)
{
hintType
=
Byte
.
class
;
return
Byte
.
valueOf
(
text
);
}
else
if
(
originalValue
instanceof
Float
)
{
hintType
=
Float
.
class
;
return
Float
.
valueOf
(
text
);
}
else
if
(
originalValue
instanceof
Double
)
{
hintType
=
Double
.
class
;
return
Double
.
valueOf
(
text
);
}
else
if
(
originalValue
instanceof
BigInteger
)
{
hintType
=
BigInteger
.
class
;
return
new
BigInteger
(
text
);
}
else
{
hintType
=
BigDecimal
.
class
;
return
new
BigDecimal
(
text
);
}
}
else
{
switch
(
type
.
getTypeID
())
{
case
java
.
sql
.
Types
.
BIGINT
:
hintType
=
Long
.
class
;
try
{
return
Long
.
parseLong
(
text
);
}
catch
(
NumberFormatException
e
)
{
return
new
BigInteger
(
text
);
}
case
java
.
sql
.
Types
.
DECIMAL
:
case
java
.
sql
.
Types
.
DOUBLE
:
case
java
.
sql
.
Types
.
REAL
:
hintType
=
Double
.
class
;
return
toDouble
(
text
);
case
java
.
sql
.
Types
.
FLOAT
:
hintType
=
Float
.
class
;
return
Float
.
valueOf
(
text
);
case
java
.
sql
.
Types
.
INTEGER
:
hintType
=
Integer
.
class
;
return
Integer
.
valueOf
(
text
);
case
java
.
sql
.
Types
.
SMALLINT
:
case
java
.
sql
.
Types
.
TINYINT
:
hintType
=
Short
.
class
;
return
Short
.
valueOf
(
text
);
case
java
.
sql
.
Types
.
NUMERIC
:
hintType
=
BigDecimal
.
class
;
return
new
BigDecimal
(
text
);
default
:
if
(
type
.
getScale
()
>
0
)
{
hintType
=
Double
.
class
;
return
toDouble
(
text
);
}
else
{
hintType
=
Long
.
class
;
return
Long
.
valueOf
(
text
);
}
}
}
}
catch
(
NumberFormatException
e
)
{
log
.
debug
(
"Bad numeric value '"
+
text
+
"' - "
+
e
.
getMessage
());
//$NON-NLS-1$ //$NON-NLS-2$
try
{
return
(
Number
)
formatter
.
parseValue
(
text
,
hintType
);
}
catch
(
ParseException
e1
)
{
log
.
debug
(
"Can't parse numeric value ["
+
text
+
"] using formatter"
,
e
);
return
null
;
}
}
@Override
public
Locale
getLocale
()
{
return
locale
;
}
private
static
Number
toDouble
(
String
text
)
{
if
(
text
.
equals
(
BAD_DOUBLE_VALUE
))
{
return
Double
.
MIN_VALUE
;
@Override
public
DBDDataFormatter
getFormatter
()
{
return
formatter
;
}
@Override
public
Class
<?
extends
Number
>
getNumberType
(
DBSTypedObject
type
,
Object
originalValue
)
{
if
(
originalValue
instanceof
Number
)
{
return
((
Number
)
originalValue
).
getClass
();
}
else
{
switch
(
type
.
getTypeID
())
{
case
java
.
sql
.
Types
.
BIGINT
:
return
Long
.
class
;
case
java
.
sql
.
Types
.
DECIMAL
:
case
java
.
sql
.
Types
.
DOUBLE
:
case
java
.
sql
.
Types
.
REAL
:
return
Double
.
class
;
case
java
.
sql
.
Types
.
FLOAT
:
return
Float
.
class
;
case
java
.
sql
.
Types
.
INTEGER
:
return
Integer
.
class
;
case
java
.
sql
.
Types
.
SMALLINT
:
case
java
.
sql
.
Types
.
TINYINT
:
return
Short
.
class
;
case
java
.
sql
.
Types
.
BIT
:
return
Byte
.
class
;
case
java
.
sql
.
Types
.
NUMERIC
:
return
BigDecimal
.
class
;
default
:
if
(
type
.
getScale
()
>
0
)
{
return
Double
.
class
;
}
else
{
return
Long
.
class
;
}
}
}
return
Double
.
valueOf
(
text
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录