Bonjour,

Je suis en train de développer un application swing.
J'utilise Hibernate et et le binding.

Mon projet:
J'ai 2 Entity Class : Exercise et Evolution.
un Exercise a un liste d'évolution.

Au niveau de l'interface, un JTree qui représente mes exercices et une JList permet d'afficher les évolutions de l'exercice selectionné par binding.
Un bouton permet aussi de rajouter une évolution à l'exercice selectionné.

Je voudrait savoir, comment l'ajout d'un évolution à un exercise peut se faire pour que la JList se raffraichisse.

Merci pour votre aide.


Exercise.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
@Entity
public class Exercise extends MyTreeNode {
 
    protected PropertyChangeSupport changeSupport;
    private static final long serialVersionUID = 1L;
    private String name;
    private int actifPlayers;
    private String materials;
    private int exerciseTime;
    private List<Evolution> evolutionList;
    private List<Training> trainingList;
 
    public Exercise() {
        this.changeSupport = new PropertyChangeSupport(this);
        this.father = null;
        this.childList = new ArrayList<>();
        this.name = "Exercise";
        this.actifPlayers = 0;
        this.materials = "";
        this.exerciseTime = 0;
        this.evolutionList = new ArrayList<>();
        this.trainingList = new ArrayList<>();
    }
 
    public Exercise(String name, int actifPlayers, String materials, int exerciseTime, List<Evolution> evolutionList, List<Training> trainingList, MyTreeNode father) {
        this.changeSupport = new PropertyChangeSupport(this);
        this.name = name;
        this.actifPlayers = actifPlayers;
        this.materials = materials;
        this.exerciseTime = exerciseTime;
        this.evolutionList = evolutionList;
        this.trainingList = trainingList;
        this.father = father;
    }
 
    public int getActifPlayers() {
        return actifPlayers;
    }
 
    public void setActifPlayers(int actifPlayers) {
        int oldActifPlayers = this.actifPlayers;
        this.actifPlayers = actifPlayers;
        changeSupport.firePropertyChange("actifPlayers", oldActifPlayers, this.actifPlayers);
    }
 
    public void addEvolution(Evolution evolution){
        evolutionList.add(evolution);
    }
 
    public void removeEvolution(Evolution evolution){
        evolutionList.remove(evolution);
    }
 
    public void removeEvolution(int index){
        evolutionList.remove(index);
    }
 
    @OneToMany(mappedBy = "exercise", cascade = {CascadeType.ALL})
    public List<Evolution> getEvolutionList() {
        return evolutionList;
    }
 
    public void setEvolutionList(List<Evolution> evolutionList) {
        List<Evolution> oldEvolutionList = this.evolutionList;
        this.evolutionList = evolutionList;
        changeSupport.firePropertyChange("evolutionList", oldEvolutionList, this.evolutionList);
    }
 
    public int getExerciseTime() {
        return exerciseTime;
    }
 
    public void setExerciseTime(int exerciseTime) {
        int oldExerciseTime = this.exerciseTime;
        this.exerciseTime = exerciseTime;
        changeSupport.firePropertyChange("exerciseTime", oldExerciseTime, this.exerciseTime);
    }
 
    public String getMaterials() {
        return materials;
    }
 
    public void setMaterials(String materials) {
        String oldMaterials = this.materials;
        this.materials = materials;
        changeSupport.firePropertyChange("materials", oldMaterials, this.materials);
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        String oldName = this.name;
        this.name = name;
        changeSupport.firePropertyChange("name", oldName, this.name);
    }
 
    @ManyToMany(mappedBy = "exerciseList", targetEntity = Training.class, cascade = {CascadeType.ALL})
    @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.ALL)
    public List<Training> getTrainingList() {
        return trainingList;
    }
 
    public void setTrainingList(List<Training> trainingList) {
        this.trainingList = trainingList;
    }
 
    @Override
    public String toString() {
        return name;
    }
 
    @Override
    public Enumeration<TreeNode> children() {
        return null;
    }
 
    @Override
    @Transient
    public boolean getAllowsChildren() {
        return false;
    }
 
    @Override
    public TreeNode getChildAt(int childIndex) {
        return childList.get(childIndex);
    }
 
    @Override
    @Transient
    public int getChildCount() {
        return childList.size();
    }
 
    @Override
    public int getIndex(TreeNode node) {
        return childList.indexOf(node);
    }
 
    @Override
    @Transient
    public TreeNode getParent() {
        return father;
    }
 
    @Override
    @Transient
    public boolean isLeaf() {
        return true;
    }
 
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }
 
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
}
Evolution.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
@Entity
public class Evolution implements Serializable {
 
    private static final long serialVersionUID = 1L;
    private Integer id;
    private Exercise exercise;
    private String name;
    private int evolutionTime;
    private String principe;
    private String requirement;
    private JPanel diagram;
 
    public Evolution() {
        this.exercise = null;
        this.name = "Evolution";
        this.evolutionTime = 0;
        this.principe = "";
        this.requirement = "";
        this.diagram = null;
    }
 
    public Evolution(Exercise exercise, String name, int evolutionTime, String principe, String requirement, JPanel diagram) {
        this.exercise = exercise;
        this.name = name;
        this.evolutionTime = evolutionTime;
        this.principe = principe;
        this.requirement = requirement;
        this.diagram = diagram;
    }
 
    public JPanel getDiagram() {
        return diagram;
    }
 
    public void setDiagram(JPanel diagram) {
        this.diagram = diagram;
    }
 
    public int getEvolutionTime() {
        return evolutionTime;
    }
 
    public void setEvolutionTime(int evolutionTime) {
        this.evolutionTime = evolutionTime;
    }
 
    @ManyToOne(cascade = {CascadeType.ALL})
    public Exercise getExercise() {
        return exercise;
    }
 
    public void setExercise(Exercise exercise) {
        this.exercise = exercise;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getPrincipe() {
        return principe;
    }
 
    public void setPrincipe(String principe) {
        this.principe = principe;
    }
 
    public String getRequirement() {
        return requirement;
    }
 
    public void setRequirement(String requirement) {
        this.requirement = requirement;
    }
 
    @Id
    @Column(name = "id")
    @GeneratedValue(generator = "increment")
    @GenericGenerator(name = "increment", strategy = "increment")
    public Integer getId() {
        return id;
    }
 
    public void setId(Integer id) {
        this.id = id;
    }
 
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }
 
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Evolution)) {
            return false;
        }
        Evolution other = (Evolution) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }
 
    @Override
    public String toString() {
        return name;
    }
}
Action sur le bouton
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
 
    private void jButtonAddEvolutionActionPerformed(java.awt.event.ActionEvent evt) {                                                    
        // TODO add your handling code here:
        Evolution evolution = new Evolution();
        Exercise exercise = (Exercise) jTreeExercise.getLastSelectedPathComponent();
        evolution.setExercise(exercise);
        exercise.addEvolution(evolution);
    }