Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
ikus-soft
planimod
Compare revisions
master to develop/patrik/reffactor-databinding
Commits on Source (1)
WIP: Reffactoring databinding
· 6915fd28
Patrik Dufresne
authored
Feb 27, 2019
6915fd28
Hide whitespace changes
Inline
Side-by-side
com.patrikdufresne.planimod/src/main/java/com/planimod/ui/views/AbstractViewPart.java
View file @
6915fd28
...
...
@@ -48,7 +48,9 @@ import org.eclipse.swt.widgets.Text;
import
com.patrikdufresne.jface.databinding.collections.FilteredObservableSet
;
import
com.patrikdufresne.jface.preference.PreferenceConverter
;
import
com.patrikdufresne.managers.databinding.ManagerDataBindingContext
;
import
com.patrikdufresne.ui.ViewPart
;
import
com.planimod.core.PlanimodManagers
;
/**
* TODO
...
...
@@ -133,7 +135,7 @@ public abstract class AbstractViewPart extends ViewPart {
*
*/
protected
void
bind
()
{
this
.
dbc
=
new
DataBindingContext
();
this
.
dbc
=
new
Manager
DataBindingContext
(
getSite
().
getService
(
PlanimodManagers
.
class
)
);
this
.
om
=
new
ObservablesManager
();
this
.
om
.
runAndCollect
(
new
Runnable
()
{
@Override
...
...
com.patrikdufresne.planimod/src/main/java/com/planimod/ui/views/employees/EmployeeViewPart.java
View file @
6915fd28
...
...
@@ -23,6 +23,7 @@ import java.util.Date;
import
org.eclipse.core.databinding.BindingProperties
;
import
org.eclipse.core.databinding.DataBindingContext
;
import
org.eclipse.core.databinding.ObservablesManager
;
import
org.eclipse.core.databinding.UpdateValueStrategy
;
import
org.eclipse.core.databinding.beans.BeanProperties
;
import
org.eclipse.core.databinding.conversion.Converter
;
...
...
@@ -38,11 +39,9 @@ import org.eclipse.core.internal.databinding.property.value.SelfValueProperty;
import
org.eclipse.jface.action.ActionContributionItem
;
import
org.eclipse.jface.action.IToolBarManager
;
import
org.eclipse.jface.action.Separator
;
import
org.eclipse.jface.databinding.swt.SWTObservables
;
import
org.eclipse.jface.databinding.swt.WidgetProperties
;
import
org.eclipse.jface.databinding.viewers.IViewerObservableList
;
import
org.eclipse.jface.databinding.viewers.ObservableListContentProvider
;
import
org.eclipse.jface.databinding.viewers.ObservableSetContentProvider
;
import
org.eclipse.jface.databinding.viewers.ViewerProperties
;
import
org.eclipse.jface.databinding.viewers.ViewerSupport
;
import
org.eclipse.jface.viewers.ComboViewer
;
...
...
@@ -65,7 +64,7 @@ import com.patrikdufresne.jface.databinding.util.JFaceProperties;
import
com.patrikdufresne.jface.databinding.viewers.ColumnSupport
;
import
com.patrikdufresne.jface.databinding.viewers.PropertyViewerComparator
;
import
com.patrikdufresne.jface.viewers.ColumnViewerPreferences
;
import
com.patrikdufresne.managers.databinding.Manager
UpdateValueStrategy
;
import
com.patrikdufresne.managers.databinding.Manager
ContentProvider
;
import
com.patrikdufresne.managers.jface.RemoveArchiveAction
;
import
com.patrikdufresne.printing.PrintAction
;
import
com.patrikdufresne.ui.SashFactory
;
...
...
@@ -213,15 +212,16 @@ public class EmployeeViewPart extends AbstractViewPart {
/*
* Bind the viewer
*/
IObservableSet
employeePreferences
=
new
EmployeePreferenceComputedSet
(
managers
);
createViewerColumns
(
this
.
viewer
,
employeePreferences
);
this
.
viewer
.
setContentProvider
(
new
ObservableSetContentProvider
());
this
.
viewer
.
setInput
(
filter
(
employeePreferences
,
CONVERTER
));
this
.
viewer
.
setContentProvider
(
new
ManagerContentProvider
());
createViewerColumns
(
this
.
viewer
);
this
.
viewer
.
setInput
(
managers
.
getEmployeePreferenceManager
());
// TODO Add filter back.
/*
* Bind Actions
*/
getDbc
().
bindList
(
JFaceProperties
.
list
(
RemoveArchiveAction
.
class
,
RemoveArchiveAction
.
OBJECTS
,
RemoveArchiveAction
.
OBJECTS
).
observe
(
this
.
removeAction
),
JFaceProperties
.
list
(
RemoveArchiveAction
.
class
,
RemoveArchiveAction
.
OBJECTS
).
observe
(
this
.
removeAction
),
ViewerProperties
.
multipleSelection
().
values
(
BeanProperties
.
value
(
EmployeePreference
.
class
,
EmployeePreference
.
EMPLOYEE
)).
observe
(
this
.
viewer
));
/*
* Bind right editor.
...
...
@@ -230,10 +230,10 @@ public class EmployeeViewPart extends AbstractViewPart {
IObservableValue
employee
=
BeanProperties
.
value
(
EmployeePreference
.
class
,
EmployeePreference
.
EMPLOYEE
).
observeDetail
(
selection
);
// Bind firstname
IObservableValue
firstname
=
BeanProperties
.
value
(
Employee
.
class
,
Employee
.
FIRSTNAME
,
String
.
class
).
observeDetail
(
employee
);
dbc
.
bindValue
(
WidgetProperties
.
text
(
SWT
.
FocusOut
).
observe
(
this
.
firstnameText
),
firstname
,
new
ManagerUpdateValueStrategy
(
managers
),
null
);
dbc
.
bindValue
(
WidgetProperties
.
text
(
SWT
.
FocusOut
).
observe
(
this
.
firstnameText
),
firstname
);
// Bind lastname
IObservableValue
lastname
=
BeanProperties
.
value
(
Employee
.
class
,
Employee
.
LASTNAME
,
String
.
class
).
observeDetail
(
employee
);
dbc
.
bindValue
(
SWTObservables
.
observeText
(
this
.
lastnameT
ext
,
SWT
.
FocusOut
)
,
lastname
,
new
ManagerUpdateValueStrategy
(
managers
),
null
);
dbc
.
bindValue
(
WidgetProperties
.
t
ext
(
SWT
.
FocusOut
)
.
observe
(
this
.
lastnameText
),
lastname
);
// Bind Hire date
IObservableValue
hireDate
=
BeanProperties
.
value
(
Employee
.
class
,
Employee
.
HIRE_DATE
,
Date
.
class
).
observeDetail
(
employee
);
IObservableValue
hireDateTime
=
new
WritableValue
(
null
,
Date
.
class
);
...
...
@@ -242,36 +242,27 @@ public class EmployeeViewPart extends AbstractViewPart {
if
(
this
.
hireTime
.
getLayoutData
()
instanceof
GridData
)
{
((
GridData
)
this
.
hireTime
.
getLayoutData
()).
widthHint
=
dts
.
getWidthHint
();
}
dbc
.
bindValue
(
new
DateAndTimeObservableValue
(
SWTObservables
.
observeSelection
(
this
.
hireDate
),
hireDateTime
),
hireDate
,
new
ManagerUpdateValueStrategy
(
managers
),
null
);
dbc
.
bindValue
(
new
DateAndTimeObservableValue
(
WidgetProperties
.
selection
().
observe
(
this
.
hireDate
),
hireDateTime
),
hireDate
);
// Bind preferred seniority
IObservableValue
preferencialSeniority
=
BeanProperties
.
value
(
Employee
.
class
,
Employee
.
PREFERENCIAL_SENIORITY
,
Boolean
.
TYPE
).
observeDetail
(
employee
);
dbc
.
bindValue
(
SWTObservables
.
observeSelection
(
this
.
preferredSeniorityButton
),
preferencialSeniority
,
new
ManagerUpdateValueStrategy
(
managers
),
null
);
dbc
.
bindValue
(
WidgetProperties
.
selection
().
observe
(
this
.
preferredSeniorityButton
),
preferencialSeniority
);
// Bind preferred section viewer.
IObservableSet
proposedSections
=
PlanimodObservables
.
listSection
(
managers
);
IValueProperty
sectionLabel
=
BeanProperties
.
value
(
Section
.
class
,
Section
.
NAME
).
value
(
BindingProperties
.
convertedValue
(
Converters
.
removeFrontNumber
()));
this
.
preferredSectionViewer
.
setComparator
(
new
PropertyViewerComparator
(
SectionComparators
.
byName
()));
ViewerSupport
.
bind
(
this
.
preferredSectionViewer
,
proposedSections
,
sectionLabel
);
IObservableValue
preferredSection
=
BeanProperties
.
value
(
EmployeePreference
.
class
,
EmployeePreference
.
PREFERRED_SECTION
).
observeDetail
(
selection
);
dbc
.
bindValue
(
ViewerProperties
.
singleSelection
().
observe
(
this
.
preferredSectionViewer
),
preferredSection
,
new
ManagerUpdateValueStrategy
(
managers
),
null
);
dbc
.
bindValue
(
ViewerProperties
.
singleSelection
().
observe
(
this
.
preferredSectionViewer
),
preferredSection
);
// Bind preferred position
IObservableValue
preferredPositionLabel
=
(
new
EmployeePreferredPositionValueProperty
(
_
(
"Aucune préférence"
))).
observeDetail
(
selection
);
dbc
.
bindValue
(
JFaceProperties
.
value
(
EmployeeEditPreferredPositionAction
.
class
,
EmployeeEditPreferredPositionAction
.
TEXT
,
EmployeeEditPreferredPositionAction
.
TEXT
).
observe
(
this
.
preferredPositionAction
),
preferredPositionLabel
);
dbc
.
bindValue
(
JFaceProperties
.
value
(
EmployeeEditPreferredPositionAction
.
class
,
EmployeeEditPreferredPositionAction
.
TOOL_TIP_TEXT
,
EmployeeEditPreferredPositionAction
.
TOOL_TIP_TEXT
).
observe
(
this
.
preferredPositionAction
),
preferredPositionLabel
);
dbc
.
bindValue
(
JFaceProperties
.
value
(
EmployeeEditPreferredPositionAction
.
class
,
EmployeeEditPreferredPositionAction
.
EMPLOYEE_PREFERENCE
,
EmployeeEditPreferredPositionAction
.
EMPLOYEE_PREFERENCE
).
observe
(
this
.
preferredPositionAction
),
selection
);
// Bind preferred team viewer
// Avoid creating columns for this viewer Since the data will not
...
...
@@ -286,24 +277,20 @@ public class EmployeeViewPart extends AbstractViewPart {
// Add all
dbc
.
bindValue
(
JFaceProperties
.
value
(
EmployeePreferredTeamAddAllAction
.
class
,
EmployeePreferredTeamAddAllAction
.
EMPLOYEE_PREFERENCE
,
EmployeePreferredTeamAddAllAction
.
EMPLOYEE_PREFERENCE
).
observe
(
this
.
preferredTeamAddAllAction
),
selection
);
// Remove action
dbc
.
bindValue
(
JFaceProperties
.
value
(
EmployeePreferredTeamRemoveAction
.
class
,
EmployeePreferredTeamRemoveAction
.
EMPLOYEE_PREFERENCE
,
EmployeePreferredTeamRemoveAction
.
EMPLOYEE_PREFERENCE
).
observe
(
this
.
preferredTeamRemoveAction
),
selection
);
dbc
.
bindValue
(
JFaceProperties
.
value
(
EmployeePreferredTeamRemoveAction
.
class
,
EmployeePreferredTeamRemoveAction
.
SHIFTS
,
EmployeePreferredTeamRemoveAction
.
SHIFTS
).
observe
(
this
.
preferredTeamRemoveAction
),
new
ListObservableValue
(
preferredTeamSelections
,
Team
.
class
));
// Move up
dbc
.
bindValue
(
JFaceProperties
.
value
(
EmployeePreferredTeamMoveAction
.
class
,
EmployeePreferredTeamMoveAction
.
EMPLOYEE_PREFERENCE
,
EmployeePreferredTeamMoveAction
.
EMPLOYEE_PREFERENCE
).
observe
(
this
.
preferredTeamMoveUpAction
),
selection
);
dbc
.
bindValue
(
JFaceProperties
.
value
(
EmployeePreferredTeamMoveAction
.
class
,
EmployeePreferredTeamMoveAction
.
SHIFT
,
EmployeePreferredTeamMoveAction
.
SHIFT
)
...
...
@@ -311,7 +298,6 @@ public class EmployeeViewPart extends AbstractViewPart {
// Move down
dbc
.
bindValue
(
JFaceProperties
.
value
(
EmployeePreferredTeamMoveAction
.
class
,
EmployeePreferredTeamMoveAction
.
EMPLOYEE_PREFERENCE
,
EmployeePreferredTeamMoveAction
.
EMPLOYEE_PREFERENCE
).
observe
(
this
.
preferredTeamMoveDownAction
),
selection
);
dbc
.
bindValue
(
JFaceProperties
.
value
(
EmployeePreferredTeamMoveAction
.
class
,
EmployeePreferredTeamMoveAction
.
SHIFT
,
EmployeePreferredTeamMoveAction
.
SHIFT
)
...
...
@@ -434,7 +420,7 @@ public class EmployeeViewPart extends AbstractViewPart {
private
void
createPreferredTeamColumns
(
final
TableViewer
viewer
,
IObservableSet
knownElements
)
{
// Team
IValueProperty
teamLabel
=
BeanProperties
.
value
(
Team
.
class
,
Team
.
NAME
).
value
(
BindingProperties
.
convertedValue
(
Converters
.
removeFrontNumber
()));
ColumnSupport
.
create
(
viewer
,
_
(
"équipe de travail"
),
knownElements
,
teamLabel
);
ColumnSupport
.
create
(
viewer
,
_
(
"équipe de travail"
),
teamLabel
);
}
/**
...
...
@@ -445,29 +431,25 @@ public class EmployeeViewPart extends AbstractViewPart {
* @param employeePreferences
* the known elements
*/
private
void
createViewerColumns
(
TableViewer
viewer
,
IObservableSet
employeePreferences
)
{
private
void
createViewerColumns
(
TableViewer
viewer
)
{
// RedId
IValueProperty
refIdProperty
=
BeanProperties
.
value
(
EmployeePreference
.
class
,
EmployeePreference
.
EMPLOYEE
+
DOT
+
Employee
.
REFID
);
ColumnSupport
.
create
(
viewer
,
_
(
"No."
),
employeePreferences
,
refIdProperty
).
addPropertySorting
().
addTextEditingSupport
(
getDbc
(),
new
ManagerUpdateValueStrategy
(
getSite
().
getService
(
PlanimodManagers
.
class
),
UpdateValueStrategy
.
POLICY_CONVERT
),
null
);
ColumnSupport
.
create
(
viewer
,
_
(
"No."
),
EmployeePreference
.
class
,
EmployeePreference
.
EMPLOYEE
+
DOT
+
Employee
.
REFID
)
.
addTextEditingSupport
(
getDbc
());
// FirstName
IValueProperty
firstnameProperty
=
BeanProperties
.
value
(
EmployeePreference
.
class
,
EmployeePreference
.
EMPLOYEE
+
DOT
+
Employee
.
FIRSTNAME
);
ColumnSupport
.
create
(
viewer
,
(
"Prénom"
),
employeePreferences
,
firstnameProperty
).
setWidth
(
150
).
addPropertySorting
().
addTextEditingSupport
(
getDbc
(),
new
ManagerUpdateValueStrategy
(
getSite
().
getService
(
PlanimodManagers
.
class
),
UpdateValueStrategy
.
POLICY_CONVERT
),
null
);
ColumnSupport
.
create
(
viewer
,
(
"Prénom"
),
EmployeePreference
.
class
,
EmployeePreference
.
EMPLOYEE
+
DOT
+
Employee
.
FIRSTNAME
)
.
setWidth
(
150
)
.
addTextEditingSupport
(
getDbc
());
// Lastname
IValueProperty
lastnameProperty
=
BeanProperties
.
value
(
EmployeePreference
.
class
,
EmployeePreference
.
EMPLOYEE
+
DOT
+
Employee
.
LASTNAME
);
ColumnSupport
.
create
(
viewer
,
_
(
"Nom"
),
employeePreferences
,
lastnameProperty
).
setWidth
(
150
).
addPropertySorting
().
addTextEditingSupport
(
getDbc
(),
new
ManagerUpdateValueStrategy
(
getSite
().
getService
(
PlanimodManagers
.
class
),
UpdateValueStrategy
.
POLICY_CONVERT
),
null
);
ColumnSupport
.
create
(
viewer
,
_
(
"Nom"
),
EmployeePreference
.
class
,
EmployeePreference
.
EMPLOYEE
+
DOT
+
Employee
.
LASTNAME
)
.
setWidth
(
150
)
.
addTextEditingSupport
(
getDbc
());
// HireDate
IValueProperty
hireDateLabelProperty
=
BeanProperties
.
value
(
EmployeePreference
.
class
,
EmployeePreference
.
EMPLOYEE
+
DOT
+
Employee
.
HIRE_DATE
).
value
(
BindingProperties
.
convertedValue
(
Converters
.
shortDateConverter
()));
ColumnSupport
.
create
(
viewer
,
_
(
"Date d'ancienneté"
),
employeePreferences
,
hireDateLabelProperty
).
setWidth
(
150
).
addPropertySorting
(
ColumnSupport
.
create
(
viewer
,
_
(
"Date d'ancienneté"
),
hireDateLabelProperty
).
setWidth
(
150
).
addPropertySorting
(
new
SelfValueProperty
(
EmployeePreference
.
class
),
EmployeePreferenceComparators
.
bySeniority
()).
activateSorting
();
// Preferred Seniority
...
...
@@ -475,14 +457,14 @@ public class EmployeeViewPart extends AbstractViewPart {
+
DOT
+
Employee
.
PREFERENCIAL_SENIORITY
,
Boolean
.
TYPE
);
IValueProperty
preferredSeniorityLabel
=
preferredSeniorityProperty
.
value
(
BindingProperties
.
convertedValue
(
Converters
.
booleanConverter
()));
ColumnSupport
.
create
(
viewer
,
_
(
"Ancienneté privilégiée"
),
employeePreferences
,
preferredSeniorityLabel
)
.
addPropertySorting
()
;
ColumnSupport
.
create
(
viewer
,
_
(
"Ancienneté privilégiée"
),
preferredSeniorityLabel
);
// Preferred Section
IValueProperty
preferredSectionProperty
=
BeanProperties
.
value
(
EmployeePreference
.
class
,
EmployeePreference
.
PREFERRED_SECTION
+
DOT
+
Section
.
NAME
);
IValueProperty
preferredSectionLabel
=
preferredSectionProperty
.
value
(
BindingProperties
.
convertedValue
(
Converters
.
removeFrontNumber
()));
ColumnSupport
.
create
(
viewer
,
_
(
"Section préférée"
),
employeePreferences
,
preferredSectionLabel
).
setWidth
(
150
)
.
addPropertySorting
()
;
ColumnSupport
.
create
(
viewer
,
_
(
"Section préférée"
),
preferredSectionLabel
).
setWidth
(
150
);
// Preferred Position
IValueProperty
preferredPositionLabel
=
new
EmployeePreferredPositionValueProperty
();
ColumnSupport
.
create
(
viewer
,
_
(
"Poste préféré"
),
employeePreferences
,
preferredPositionLabel
)
.
addPropertySorting
()
;
ColumnSupport
.
create
(
viewer
,
_
(
"Poste préféré"
),
preferredPositionLabel
);
// Column preferences
ColumnViewerPreferences
.
create
(
viewer
,
PlanimodPreferences
.
getPreferenceStore
(),
PREFERENCE_COLUMNS
);
}
...
...
pom.xml
View file @
6915fd28
...
...
@@ -5,7 +5,7 @@
<parent>
<groupId>
com.patrikdufresne
</groupId>
<artifactId>
swt
</artifactId>
<version>
3.109.0.
2
</version>
<version>
3.109.0.
3-9-gf607e9e
</version>
</parent>
<artifactId>
planimod-parent
</artifactId>
<version>
${revision}
</version>
...
...