IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

NetBeans Java Discussion :

Binding Beans ArrayList


Sujet :

NetBeans Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Ingénieur Informatique et Réseaux
    Inscrit en
    Avril 2011
    Messages
    232
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur Informatique et Réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 232
    Par défaut Binding Beans ArrayList
    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);
        }

  2. #2
    Membre éclairé
    Homme Profil pro
    Ingénieur Informatique et Réseaux
    Inscrit en
    Avril 2011
    Messages
    232
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur Informatique et Réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 232
    Par défaut
    J'ai aussi essayé en utilisant le PropertyChange dans mes methodes "add" et remove":
    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
     
        public void addEvolution(Evolution evolution){
            evolutionList.add(evolution);
            changeSupport.firePropertyChange("evolutionList", null, this.evolutionList);
     
        }
     
        public void removeEvolution(Evolution evolution){
            evolutionList.remove(evolution);
            changeSupport.firePropertyChange("evolutionList", null, this.evolutionList);
     
        }
     
        public void removeEvolution(int index){
            evolutionList.remove(index);
            changeSupport.firePropertyChange("evolutionList", null, this.evolutionList);
     
        }
    Mais ça ne fonctionne pas mieux. La JList ne se raffraichit pas.


    Merci pour aide.
    Spiritkill

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. HtmlSelectOneRadio Binding Bean
    Par micanti dans le forum JSF
    Réponses: 1
    Dernier message: 22/02/2010, 10h27
  2. Bean JSF + arrayList
    Par aocorp dans le forum JSF
    Réponses: 1
    Dernier message: 21/08/2006, 09h23
  3. [JSF]Affichage de beans depuis une ArrayList dans une JSP
    Par adrien.nicolet dans le forum Servlets/JSP
    Réponses: 6
    Dernier message: 05/06/2006, 17h33
  4. [Swing] Problème avec un bean et un arraylist
    Par kikoufr dans le forum AWT/Swing
    Réponses: 16
    Dernier message: 30/09/2004, 09h08
  5. [JSP][BEAN]Récuperer des Beans dans un ArrayList
    Par Jones dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 30/08/2004, 11h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo