Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CometeSWT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Software Control System
Libraries
java
CometeSWT
Commits
4c6b60eb
Commit
4c6b60eb
authored
Jan 23, 2012
by
Sylvain Mainguy
Browse files
Options
Downloads
Patches
Plain Diff
Sylvain's implementation
parent
11e2db6b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/fr/soleil/comete/swt/ComboBox.java
+44
-48
44 additions, 48 deletions
src/main/java/fr/soleil/comete/swt/ComboBox.java
with
44 additions
and
48 deletions
src/main/java/fr/soleil/comete/swt/ComboBox.java
+
44
−
48
View file @
4c6b60eb
...
...
@@ -16,10 +16,7 @@ import fr.soleil.comete.definition.widget.IComponent;
public
class
ComboBox
extends
CometeComposite
<
Combo
>
implements
IComboBox
{
private
final
ArrayList
<
WeakReference
<
IComboBoxListener
>>
comboBoxListeners
=
new
ArrayList
<
WeakReference
<
IComboBoxListener
>>();
protected
boolean
editing
=
true
;
private
String
[]
valueList
;
private
String
selectedValue
;
private
String
[]
valueList
=
null
;
public
ComboBox
(
Composite
parent
,
int
style
)
{
super
(
parent
,
style
);
...
...
@@ -27,27 +24,28 @@ public class ComboBox extends CometeComposite<Combo> implements IComboBox {
@Override
protected
Combo
initControl
()
{
Combo
combo
=
new
Combo
(
this
,
SWT
.
READ_ONLY
);
combo
.
setBounds
(
0
,
0
,
150
,
65
);
setValueList
(
null
);
setHorizontalAlignment
(
IComponent
.
CENTER
);
setEditable
(
false
);
Combo
combo
=
new
Combo
(
this
,
SWT
.
DROP_DOWN
|
SWT
.
READ_ONLY
);
return
combo
;
}
@Override
public
String
getText
()
{
return
getSelectedValue
();
// should return the content of the textfield in case of an editable combo
// here we return the currently displayed item
return
getControl
().
getItem
(
getControl
().
getSelectionIndex
());
}
@Override
public
void
setText
(
String
text
)
{
// sets the currently displayed item
getControl
().
clearSelection
();
if
(
text
!=
null
)
{
if
(
valueList
!=
null
)
{
for
(
int
i
=
0
;
i
<
valueList
.
length
;
i
++)
{
if
(
valueList
[
i
].
equals
(
text
))
{
String
[]
displayedList
=
getDisplayedList
();
if
(
displayedList
.
length
>
0
)
{
for
(
int
i
=
0
;
i
<
displayedList
.
length
;
i
++)
{
if
(
displayedList
[
i
].
equals
(
text
))
{
getControl
().
select
(
i
);
break
;
}
}
}
...
...
@@ -56,13 +54,12 @@ public class ComboBox extends CometeComposite<Combo> implements IComboBox {
@Override
public
void
setHorizontalAlignment
(
int
halign
)
{
//
TODO Auto-generated method stub
//
nop
}
@Override
public
int
getHorizontalAlignment
()
{
// TODO Auto-generated method stub
return
0
;
return
IComponent
.
LEFT
;
}
@Override
...
...
@@ -108,7 +105,6 @@ public class ComboBox extends CometeComposite<Combo> implements IComboBox {
}
}
toRemove
.
clear
();
toRemove
=
null
;
}
}
...
...
@@ -123,12 +119,10 @@ public class ComboBox extends CometeComposite<Combo> implements IComboBox {
if
((
temp
==
null
)
||
temp
.
equals
(
listener
))
{
toRemove
.
add
(
ref
);
}
temp
=
null
;
}
comboBoxListeners
.
removeAll
(
toRemove
);
}
toRemove
.
clear
();
toRemove
=
null
;
}
}
...
...
@@ -146,12 +140,10 @@ public class ComboBox extends CometeComposite<Combo> implements IComboBox {
else
{
temp
.
selectedItemChanged
(
event
);
}
temp
=
null
;
}
comboBoxListeners
.
removeAll
(
toRemove
);
}
toRemove
.
clear
();
toRemove
=
null
;
}
@Override
...
...
@@ -161,37 +153,36 @@ public class ComboBox extends CometeComposite<Combo> implements IComboBox {
@Override
public
void
setDisplayedList
(
String
[]
displayedList
)
{
if
(
editing
)
{
if
(
displayedList
!=
null
)
{
if
(
getControl
().
getItems
()!=
null
)
{
if
(
displayedList
==
null
)
{
getControl
().
removeAll
();
}
for
(
String
value
:
displayedList
)
{
getControl
().
add
(
value
);
}
}
else
{
// TODO ensure there are no null items
getControl
().
setItems
(
displayedList
);
}
}
@Override
public
String
[]
getValueList
()
{
// TODO should clone the returned array
return
valueList
;
}
@Override
public
void
setValueList
(
String
[]
valueList
)
{
if
(
editing
)
{
if
(
valueList
!=
null
)
{
if
(
getControl
().
getItems
()!=
null
)
{
if
(
valueList
==
null
)
{
getControl
().
removeAll
();
}
else
{
String
[]
displayedList
=
getControl
().
getItems
();
// if displayed list is empty, use values as displayed values
if
(
displayedList
.
length
==
0
)
{
for
(
String
value
:
valueList
)
{
getControl
().
add
(
value
);
}
}
this
.
valueList
=
valueList
;
}
this
.
valueList
=
valueList
;
}
@Override
...
...
@@ -202,26 +193,32 @@ public class ComboBox extends CometeComposite<Combo> implements IComboBox {
@Override
public
Object
getSelectedItem
()
{
// not to do
return
null
;
return
getSelectedValue
()
;
}
@Override
public
void
setSelectedItem
(
Object
item
)
{
// not to do
String
value
=
item
.
toString
();
if
(
item
instanceof
String
)
{
value
=
(
String
)
item
;
}
setSelectedValue
(
value
);
}
@Override
public
String
getSelectedValue
()
{
if
(
getControl
().
getSelectionIndex
()
!=
-
1
)
{
selectedValue
=
getControl
().
getItem
(
getControl
().
getSelectionIndex
());
String
selectedValue
=
null
;
int
selectionIndex
=
getControl
().
getSelectionIndex
();
// ensure we have enough values
if
(
selectionIndex
!=
-
1
&&
selectionIndex
<
valueList
.
length
)
{
selectedValue
=
valueList
[
selectionIndex
];
}
return
selectedValue
;
}
@Override
public
void
setSelectedValue
(
String
value
)
{
editing
=
true
;
if
(
valueList
!=
null
)
{
for
(
int
i
=
0
;
i
<
valueList
.
length
;
i
++)
{
if
(
valueList
[
i
].
equals
(
value
))
{
...
...
@@ -230,7 +227,6 @@ public class ComboBox extends CometeComposite<Combo> implements IComboBox {
}
}
}
editing
=
false
;
}
@Override
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment