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

SWT/JFace Java Discussion :

Récupérer les données d'un TableItem vers une Combo


Sujet :

SWT/JFace Java

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 14
    Points : 8
    Points
    8
    Par défaut Récupérer les données d'un TableItem vers une Combo
    Bonjour tout le monde!!!!

    Mon application est composée d'un tableViewer et de formulaires avec des cCombo, text et combo. Mes combo se remplissent automatiquement au fur et à mesure que l'utilisateur rempli les Text.
    Or l'utilisateur peut supprimer des lignes du tableViewer (s'il y a erreur de saisies) grâce à un bouton "supprimer". Si le TableViewer est bon mes combo conservent les données erronées. Y a t'il un moyen de supprimer ces données erronées en même temps que l'on supprime la ligne du tableViewer afin qu'ils soient en conformité l'un avec l'autre?

    Merci de votre aide précieuse.

  2. #2
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Septembre 2007
    Messages
    340
    Détails du profil
    Informations personnelles :
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2007
    Messages : 340
    Points : 379
    Points
    379
    Par défaut
    Tu peux ajouter un DisposeListener à test TableItem, lorsqu'un d'eux est supprimé il sera appelé, tu pourras ensuite effectuer un traitement de ce type :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    void widgetDisposed(DisposeEvent e) {
        TableItem item = (TableItem) e.getSource();
        String text = item.getText();
        cCombo.remove(text);
    }

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 14
    Points : 8
    Points
    8
    Par défaut
    Merci Soft0613 pour ta réponse,

    Cela me met sur la voie de la solution par contre malgré le DisposeListener cela ne change rien à mon problème. L'ai-je bien placé je te joins mon code:

    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
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
     
    import org.eclipse.swt.graphics.Point;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.TableItem;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.widgets.Table;
    import org.eclipse.swt.graphics.Rectangle;
    import org.eclipse.swt.widgets.TableColumn;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.custom.CCombo;
    import org.eclipse.swt.widgets.Text;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.jface.viewers.TableViewer;
    import org.eclipse.swt.widgets.Combo;
    import org.eclipse.jface.viewers.ComboViewer;
     
     
    public class FenêtrePrincipale {
     
     
        /**
         * 
         */
        private static final long serialVersionUID = 2239351457708703588L;
        Shell sShell;  //  @jve:decl-index=0:visual-constraint="10,10"
        Label label;
        CCombo cCombo;
        Label label1;
        Text text;
        Button button;
        Button button1;
        Table table1;
        TableItem items;
        TableViewer tableViewer;
        Label label2;
        CCombo cCombo1;
        String Civilité, Nom, Nom1, CatEtab, Prénom, NomEtab, Ville, MatEns;
        int i;
        Label label3;
        Text text1;
        Label label4;
        Text text2;
        Label label5;
        Text text3;
        Label label6;
        CCombo cCombo2;
        Button button2;
        Button button3;
        Label label7;
        Combo combo;
        ComboViewer comboViewer;
        /**
         * This method initializes combo    
         *
         */
     
     
        public static void main(String[] args) {
     
            Display display = Display.getDefault();
            FenêtrePrincipale thisClass = new FenêtrePrincipale();
            thisClass.createSShell();
            thisClass.sShell.open();
     
            while (!thisClass.sShell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
            display.dispose();
        }
     
     
        private void createSShell() {
     
        //Création de la Fenêtre:
            sShell = new Shell(SWT.BORDER | SWT.SHELL_TRIM);
            sShell.setText("Test Table cCombo");
            sShell.setSize(new Point(900, 614));
            sShell.setLayout(null);
     
        //Création du Tableau:
            table1 = new Table(sShell, SWT.NONE | SWT.FULL_SELECTION | SWT.MULTI);
            table1.setHeaderVisible(true);
            table1.setLinesVisible(true);
            table1.setBounds(new Rectangle(57, 31, 771, 257));
     
     
     
        //Création du TableViewer:
            tableViewer = new TableViewer(table1);
     
        //Création des Colonnes du Tableau:
            TableColumn tableColumn = new TableColumn(table1, SWT.CENTER);
            tableColumn.setWidth(70);
            tableColumn.setText("Civilité");
            tableColumn.setResizable(true);
            TableColumn tableColumn1 = new TableColumn(table1, SWT.CENTER);
            tableColumn1.setWidth(100);
            tableColumn1.setText("Nom");
            tableColumn1.setResizable(true);
            TableColumn tableColumn2 = new TableColumn(table1, SWT.CENTER);
            tableColumn2.setWidth(100);
            tableColumn2.setText("Prénom");
            tableColumn2.setResizable(true);
            TableColumn tableColumn3 = new TableColumn(table1, SWT.CENTER);
            tableColumn3.setWidth(150);
            tableColumn3.setText("Catégorie etab");
            tableColumn3.setResizable(true);
            TableColumn tableColumn4 = new TableColumn(table1, SWT.CENTER);
            tableColumn4.setWidth(120);
            tableColumn4.setText("Nom etab");
            tableColumn4.setResizable(true);
            TableColumn tableColumn5 = new TableColumn(table1, SWT.CENTER);
            tableColumn5.setWidth(100);
            tableColumn5.setText("Ville");
            tableColumn5.setResizable(true);
            TableColumn tableColumn6 = new TableColumn(table1, SWT.CENTER);
            tableColumn6.setWidth(150);
            tableColumn6.setText("Matière enseignée");
            tableColumn6.setResizable(true);
     
        //Création des lignes du Tableau:
            for (int i = 0; i < 50; i++) {new TableItem (table1, SWT.NONE);}
            final TableItem[] items = table1.getItems();
            for (int i = 0; i < items.length; i++) {
            }
            items[i].addDisposeListener(new org.eclipse.swt.events.DisposeListener() {
                public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
                        TableItem[] items = (TableItem[]) e.getSource();
                        String Nom = items[i].getText();
                        combo.remove(Nom);
                    }
                });
     
        //Création du Label et de la cCombo "Civilité":
            label = new Label(sShell, SWT.NONE);
            label.setText("Civilité:");
            label.setBounds(new Rectangle(31, 314, 79, 19));
            cCombo = new CCombo(sShell, SWT.BORDER);
            cCombo.setTextLimit(10);
            cCombo.add("M.");
            cCombo.add("Melle");
            cCombo.add("Mme");
            cCombo.setBounds(new Rectangle(135, 314, 81, 18));
     
     
        //Création du Label et de la zone de texte "Nom":
            label1 = new Label(sShell, SWT.NONE);
            label1.setBounds(new Rectangle(269, 315, 37, 17));
            label1.setText("Nom:");
            text = new Text(sShell, SWT.BORDER | SWT.SINGLE);
            text.setBounds(new Rectangle(329, 309, 198, 25));
            text.setTextLimit(30);
     
        //Création du Label et de la zone de texte "Prénom":
            label3 = new Label(sShell, SWT.NONE);
            label3.setBounds(new Rectangle(558, 317, 59, 17));
            label3.setText("Prénom:");
            text1 = new Text(sShell, SWT.BORDER);
            text1.setBounds(new Rectangle(631, 310, 210, 23));
            text1.setTextLimit(30);
     
        //Création du Label et de la cCombo "Catégorie Etablissement":    
            label2 = new Label(sShell, SWT.NONE);
            label2.setBounds(new Rectangle(29, 375, 93, 16));
            label2.setText("Catégorie etab:");
            cCombo1 = new CCombo(sShell, SWT.BORDER);
            cCombo1.setBounds(new Rectangle(135, 375, 109, 22));
            cCombo1.add("CLG");
            cCombo1.add("LYC");
            cCombo1.add("LYC PROF");
     
        //Création du Label et de la zone de texte "Nom d'établissement":
            label4 = new Label(sShell, SWT.NONE);
            label4.setBounds(new Rectangle(30, 421, 121, 16));
            label4.setText("Nom Etablissement:");
            text2 = new Text(sShell, SWT.BORDER);
            text2.setBounds(new Rectangle(179, 413, 243, 23));
            text2.setTextLimit(40);
     
        //Création du Label et de la zone de texte "Ville":
            label5 = new Label(sShell, SWT.NONE);
            label5.setBounds(new Rectangle(30, 466, 40, 16));
            label5.setText("Ville:");
            text3 = new Text(sShell, SWT.BORDER);
            text3.setBounds(new Rectangle(90, 460, 272, 21));
            text3.setTextLimit(40);
     
        //Création du Label et de la combo "Matière enseignée":
            label6 = new Label(sShell, SWT.NONE);
            label6.setBounds(new Rectangle(31, 510, 107, 17));
            label6.setText("Matière enseignée:");
            cCombo2 = new CCombo(sShell, SWT.BORDER);
            cCombo2.setBounds(new Rectangle(166, 506, 226, 21));
            cCombo2.add("Allemand");
            cCombo2.add("Anglais");
            cCombo2.add("Arabe");
            cCombo2.add("Arts-Plastiques");
            cCombo2.add("Espagnol");
            cCombo2.add("Français");
            cCombo2.add("Histoire-géographie");
            cCombo2.add("Mathématiques");
            cCombo2.add("Science de la Vie et de la Terre");
            cCombo2.add("Sciences Physiques");
     
        //Création du Label et de la combo "Identité correcteur":
            label7 = new Label(sShell, SWT.NONE);
            label7.setBounds(new Rectangle(450, 373, 111, 18));
            label7.setText("Identité Correcteur:");
            combo = new Combo(sShell, SWT.NONE);
            combo.setBounds(new Rectangle(584, 372, 215, 27));
            comboViewer = new ComboViewer(combo);
     
     
        //Création du bouton "Valider":    
            button = new Button(sShell, SWT.NONE);
            button.setBounds(new Rectangle(464, 540, 107, 31));
            button.setText("Valider");
            button.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
                public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
     
                    //Récupération des données dans les différents formulaires et ajout au TableViewer:
                    String Civilité = cCombo.getText();
                    String Nom = text.getText();
                    String CatEtab = cCombo1.getText();
                    String Prénom = text1.getText();
                    String NomEtab = text2.getText();
                    String Ville = text3.getText();
                    String MatEns = cCombo2.getText();
                    items[i].setText( new String[] {Civilité, Nom, Prénom, CatEtab, NomEtab, Ville, MatEns});
                    tableViewer.add(items[i++]);
                    combo.add(Nom + " " + Prénom);
     
                    //Reinitialisation des cCombo et Text:
                    cCombo.setText("");
                    cCombo1.setText("");
                    cCombo2.setText("");
                    text.setText("");
                    text1.setText("");
                    text2.setText("");
                    text3.setText("");
     
                }
            });
     
        //Création du bouton "Quitter":
            button1 = new Button(sShell, SWT.NONE);
            button1.setBounds(new Rectangle(763, 538, 92, 32));
            button1.setText("Quitter");
            button1.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
                public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                    sShell.close();
                }
            });
     
        //Création du bouton "enregistrer":
            button2 = new Button(sShell, SWT.NONE);
            button2.setBounds(new Rectangle(614, 538, 107, 32));
            button2.setText("Enregistrer");
            button2.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
                public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                    System.out.println("widgetSelected()"); // TODO Auto-generated Event stub widgetSelected()
     
                }
            });
     
            //Création du bouton supprimer un correcteur:
            button3 = new Button(sShell, SWT.NONE);
            button3.setBounds(new Rectangle(614, 477, 164, 35));
            button3.setText("Supprimer un correcteur");
            button3.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
                public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                    table1.remove(table1.getSelectionIndices());
                }
            });
     
        }

  4. #4
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Septembre 2007
    Messages
    340
    Détails du profil
    Informations personnelles :
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2007
    Messages : 340
    Points : 379
    Points
    379
    Par défaut
    S'il s'agit de ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    items[i].addDisposeListener(new org.eclipse.swt.events.DisposeListener() {
        public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
            TableItem[] items = (TableItem[]) e.getSource();
            String Nom = items[i].getText();
            combo.remove(Nom);
        }
    }
    ça ne marchera pas, la valeur retournée par getSource() est de type TableItem, et non pas TableItem[].

  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 14
    Points : 8
    Points
    8
    Par défaut
    Citation Envoyé par soft0613 Voir le message
    Tu peux ajouter un DisposeListener à test TableItem, lorsqu'un d'eux est supprimé il sera appelé, tu pourras ensuite effectuer un traitement de ce type :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    void widgetDisposed(DisposeEvent e) {
        TableItem item = (TableItem) e.getSource();
        String text = item.getText();
        cCombo.remove(text);
    }
    Je vois ce que tu veux dire mais je ne sais pas où je dois placer ce code. De plus lorsque je saisis le code en question Eclipse me signale des problèmes. Que dois je faire à ton avis?

  6. #6
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Septembre 2007
    Messages
    340
    Détails du profil
    Informations personnelles :
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2007
    Messages : 340
    Points : 379
    Points
    379
    Par défaut
    Remplaces ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    items[i].addDisposeListener(new org.eclipse.swt.events.DisposeListener() {
        public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
            TableItem[] items = (TableItem[]) e.getSource();
            String Nom = items[i].getText();
            combo.remove(Nom);
        }
    }
    par ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    items[i].addDisposeListener(new org.eclipse.swt.events.DisposeListener() {
        public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
            TableItem item = (TableItem) e.getSource();
            String text = item.getText();
            combo.remove(text);
        }
    }

Discussions similaires

  1. Réponses: 2
    Dernier message: 22/12/2008, 18h29
  2. [Sunopsis V3]passer les données d'un fichier vers une table
    Par PetitChat73 dans le forum ODI (ex-Sunopsis)
    Réponses: 0
    Dernier message: 07/03/2008, 15h44
  3. Réponses: 8
    Dernier message: 12/10/2007, 12h54
  4. [Delphi for PHP] Récupérer les données d'un Datagrid pour une combobox ou listbox
    Par Truebison dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 2
    Dernier message: 27/08/2007, 09h27
  5. Réponses: 6
    Dernier message: 27/09/2006, 20h27

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