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 :

Introduire des combo dans les Tree table?


Sujet :

SWT/JFace Java

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2008
    Messages
    108
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 108
    Par défaut Introduire des combo dans les Tree table?
    je veux construire un tree table en SWT/JFACE ( comme celui de l'onglet property sous eclipse) avec des combo et des champs texte a remplir


    TreeItem subCurrent = new TreeItem(current, SWT.NONE);

    subCurrent.setText(1, "Valeur "); // 2eme colonne du tableau
    subCurrent.setText(2, "True ou false");// 3eme colonne



    jarrive pas a placer mon combo ou un champs texte sur la 2eme ligne 3eme colonne (a la place de true ou false) je peux juste ecrire su texte avec la methode setText.
    comment faire ?? merci d'avance

  2. #2
    Expert confirmé
    Avatar de djo.mos
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    4 666
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2004
    Messages : 4 666
    Par défaut
    Salut,
    Il faut utiliser les CellEditors et CellModifiers.
    http://dev.eclipse.org/viewcvs/index...va?view=markup

  3. #3
    Membre expérimenté

    Profil pro
    Inscrit en
    Août 2006
    Messages
    218
    Détails du profil
    Informations personnelles :
    Âge : 50
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Août 2006
    Messages : 218
    Par défaut
    Salut,

    Si tu n'utilises pas JFace, tu peux utiliser les TreeEditor de SWT :

    http://dev.eclipse.org/viewcvs/index...1.java?view=co

    Bon courage

    Laurent

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2008
    Messages
    108
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 108
    Par défaut
    merci
    mais mon probleme c'est que jarrive pas a modifier ou atteindre ma 3eme colonne
    mm avec celleditor

  5. #5
    Membre expérimenté

    Profil pro
    Inscrit en
    Août 2006
    Messages
    218
    Détails du profil
    Informations personnelles :
    Âge : 50
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Août 2006
    Messages : 218
    Par défaut
    Tu peux poster ton code s'il te plait ?

    Laurent

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2008
    Messages
    108
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 108
    Par défaut
    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
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.custom.TreeEditor;
    import org.eclipse.swt.events.MouseAdapter;
    import org.eclipse.swt.events.MouseEvent;
    import org.eclipse.swt.graphics.Point;
    import org.eclipse.swt.layout.FillLayout;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Event;
    import org.eclipse.swt.widgets.Listener;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Tree;
    import org.eclipse.swt.widgets.TreeColumn;
    import org.eclipse.swt.widgets.TreeItem;
     
     
     
    public class TableTreeTest {
     
     
    	//private String[] options = { "true", "false"};
     
     
    	public TableTreeTest() {
    		final Display display = new Display();
    		final Shell shell = new Shell(display);
    		shell.setText("Elements");
    		shell.setLayout(new FillLayout());
    		final Tree myTree = new Tree(shell, SWT.FULL_SELECTION);
    		final TreeItem iItem = new TreeItem(myTree, SWT.NONE);
     
     
     
    		TreeColumn column = new TreeColumn(myTree, SWT.NONE);
    		column.setText("Property");
    		column.setResizable(true);
    		column.setMoveable(false);
    		column.setWidth(100);
    		column = new TreeColumn(myTree, SWT.NONE);
    		column.setText("Attributes");
    		column.setResizable(true);
    		column.setWidth(100);
    		column = new TreeColumn(myTree, SWT.NONE);
    		column.setText("Value");
    		column.setResizable(true);
    		column.setWidth(100);
     
                    iItem.setText("Prompt" );
    		for (int j = 1; j < 2; j++) {
    			TreeItem jItem = new TreeItem(iItem, SWT.NONE);
    			jItem.setText(1,"bargein");
    			jItem.setText(2,"true ou false " );/***/
     
    		}
     
    		for (int j = 1; j < 2; j++) {
    			TreeItem jItem2 = new TreeItem(iItem, SWT.NONE);
    			jItem2.setText(1,"Timeout" );
    			jItem2.setText(2,"Entrer votre temps!!" );/***/
     
    		}
    		for (int j = 1; j < 2; j++) {
    			TreeItem jItem3 = new TreeItem(iItem, SWT.NONE);
    			jItem3.setText(1,"cond" );
    			jItem3.setText(2,"définir une condition!!" );/***/
     
     
    		}
    		for (int j = 1; j < 2; j++) {
    			TreeItem jItem4 = new TreeItem(iItem, SWT.NONE);
    			jItem4.setText(1,"bargeintype" );
    			jItem4.setText(2,"speech ou hotword" );/***/
     
     
    		}
    		for (int j = 1; j < 2; j++) {
    			final TreeItem jItem5 = new TreeItem(iItem, SWT.NONE);
    			jItem5.setText(1,"count" );
    			jItem5.setText(2,"1-2-3....." );/***/
     
     
    		}
     
     
     
     
     
     
     
    		myTree.setHeaderVisible(true);
    		myTree.setLinesVisible(true);
    		//myTree.setTopItem(myTree.getItem(0));
    		//myTree.setSelection(myTree.getItem(0));
    		myTree.getItem(0).setExpanded(true);
     
    		shell.setSize(350, 350);
    		shell.open();
    		while (!shell.isDisposed()) {
    			if (!display.readAndDispatch())
    				display.sleep();
    		}
    		display.dispose();
    	}
     
    	public static void main(String[] argv) {
    		new TableTreeTest();
    	}
    }

  7. #7
    Membre expérimenté

    Profil pro
    Inscrit en
    Août 2006
    Messages
    218
    Détails du profil
    Informations personnelles :
    Âge : 50
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Août 2006
    Messages : 218
    Par défaut
    Bonjour,

    Voici une version qui fait ce que tu veux je pense

    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
     
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.custom.CCombo;
    import org.eclipse.swt.custom.TreeEditor;
    import org.eclipse.swt.graphics.GC;
    import org.eclipse.swt.graphics.Point;
    import org.eclipse.swt.graphics.Rectangle;
    import org.eclipse.swt.layout.FillLayout;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Event;
    import org.eclipse.swt.widgets.Listener;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Text;
    import org.eclipse.swt.widgets.Tree;
    import org.eclipse.swt.widgets.TreeColumn;
    import org.eclipse.swt.widgets.TreeItem;
     
    public class TableTreeTest {
     
        // Rajout Laurent
        static Point lastMouseDown;
     
        public TableTreeTest() {
            final Display display = new Display();
            final Shell shell = new Shell(display);
            shell.setText("Elements");
            shell.setLayout(new FillLayout());
            final Tree myTree = new Tree(shell, SWT.FULL_SELECTION);
            final TreeItem iItem = new TreeItem(myTree, SWT.NONE);
     
            TreeColumn column = new TreeColumn(myTree, SWT.NONE);
            column.setText("Property");
            column.setResizable(true);
            column.setMoveable(false);
            column.setWidth(100);
            column = new TreeColumn(myTree, SWT.NONE);
            column.setText("Attributes");
            column.setResizable(true);
            column.setWidth(100);
            column = new TreeColumn(myTree, SWT.NONE);
            column.setText("Value");
            column.setResizable(true);
            column.setWidth(100);
     
            iItem.setText("Prompt");
            for (int j = 1; j < 2; j++) {
                TreeItem jItem = new TreeItem(iItem, SWT.NONE);
                jItem.setText(1, "bargein");
                jItem.setText(2, "True");
                /***/
     
            }
     
            for (int j = 1; j < 2; j++) {
                TreeItem jItem2 = new TreeItem(iItem, SWT.NONE);
                jItem2.setText(1, "Timeout");
                jItem2.setText(2, "False");
                /***/
     
            }
            for (int j = 1; j < 2; j++) {
                TreeItem jItem3 = new TreeItem(iItem, SWT.NONE);
                jItem3.setText(1, "cond");
                jItem3.setText(2, "True");
                /***/
     
            }
            for (int j = 1; j < 2; j++) {
                TreeItem jItem4 = new TreeItem(iItem, SWT.NONE);
                jItem4.setText(1, "bargeintype");
                jItem4.setText(2, "False");
                /***/
     
            }
            for (int j = 1; j < 2; j++) {
                final TreeItem jItem5 = new TreeItem(iItem, SWT.NONE);
                jItem5.setText(1, "count");
                jItem5.setText(2, "False");
                /***/
     
            }
     
            myTree.setHeaderVisible(true);
            myTree.setLinesVisible(true);
            myTree.getItem(0).setExpanded(true);
     
            // Rajout Laurent
            final TreeEditor editor = new TreeEditor(myTree);
     
            myTree.addListener(SWT.MouseDown, new Listener() {
                public void handleEvent(Event event) {
                    lastMouseDown = new Point(event.x, event.y);
                }
            });
     
            myTree.addListener(SWT.KeyDown, new Listener() {
                public void handleEvent(Event event) {
                    lastMouseDown = null;
                }
            });
     
            myTree.addListener(SWT.Selection, new Listener() {
                public void handleEvent(Event event) {
                    if (lastMouseDown == null)
                        return; // Selection faite au clavier
     
                    TreeItem item = myTree.getItem(lastMouseDown);
                    for (int i = 0; i < myTree.getColumnCount(); i++) {
                        Rectangle rect = item.getBounds(i);
                        if (rect.contains(lastMouseDown)) {
                            if (i == 1) {
                                buildText(editor, item, i);
                            }
                            if (i == 2) {
                                buildCombo(editor, item, i);
                            }
                        }
                    }
                    lastMouseDown = null;
                }
            });
     
            shell.setSize(350, 350);
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
            display.dispose();
        }
     
        /**
         * @param editor
         * @param item
         * @param i
         */
        protected void buildCombo(final TreeEditor editor, final TreeItem item, final int i) {
            boolean showBorder = true;
            final Composite composite = new Composite(item.getParent(), SWT.NONE);
            if (showBorder)
                composite.setBackground(item.getDisplay().getSystemColor(SWT.COLOR_BLACK));
     
            final CCombo combo = new CCombo(composite, SWT.READ_ONLY);
            combo.add("True");
            combo.add("False");
            combo.pack();
            editor.horizontalAlignment = SWT.LEFT;
            editor.minimumWidth = combo.getSize().x;
            editor.minimumHeight = combo.getSize().y;
            editor.layout();
     
            final int inset = showBorder ? 1 : 0;
            composite.addListener(SWT.Resize, new Listener() {
                public void handleEvent(Event e) {
                    Rectangle rect = composite.getClientArea();
                    combo.setBounds(rect.x + inset, rect.y + inset, rect.width - inset * 2, rect.height - inset * 2);
                }
            });
     
            Listener listener = new Listener() {
                public void handleEvent(final Event e) {
                    switch (e.type) {
                    case SWT.FocusOut:
                        item.setText(i,combo.getText());
                        composite.dispose();
                        break;
                    case SWT.Traverse:
                        switch (e.detail) {
                        case SWT.TRAVERSE_RETURN:
                            item.setText(i,combo.getText());
                            // FALL THROUGH
                        case SWT.TRAVERSE_ESCAPE:
                            composite.dispose();
                            e.doit = false;
                        }
                        break;
                    }
                }
            };
            combo.addListener(SWT.FocusOut, listener);
            combo.addListener(SWT.Traverse, listener);
     
     
     
            editor.setEditor(composite, item, i);
            combo.setText(item.getText(i));
            combo.setFocus();        
        }
     
        /**
         * @param editor
         * @param item
         * @param i
         */
        protected void buildText(final TreeEditor editor, final TreeItem item, final int i) {
            boolean showBorder = true;
            final Composite composite = new Composite(item.getParent(), SWT.NONE);
            if (showBorder)
                composite.setBackground(item.getDisplay().getSystemColor(SWT.COLOR_BLACK));
     
            final Text text = new Text(composite, SWT.NONE);
            final int inset = showBorder ? 1 : 0;
            composite.addListener(SWT.Resize, new Listener() {
                public void handleEvent(Event e) {
                    Rectangle rect = composite.getClientArea();
                    text.setBounds(rect.x + inset, rect.y + inset, rect.width - inset * 2, rect.height - inset * 2);
                }
            });
     
            Listener textListener = new Listener() {
                public void handleEvent(final Event e) {
                    switch (e.type) {
                    case SWT.FocusOut:
                        item.setText(i,text.getText());
                        composite.dispose();
                        break;
                    case SWT.Verify:
                        String newText = text.getText();
                        String leftText = newText.substring(0, e.start);
                        String rightText = newText.substring(e.end, newText.length());
                        GC gc = new GC(text);
                        Point size = gc.textExtent(leftText + e.text + rightText);
                        gc.dispose();
                        size = text.computeSize(size.x, SWT.DEFAULT);
                        editor.horizontalAlignment = SWT.LEFT;
                        Rectangle itemRect = item.getBounds(),
                        rect = item.getParent().getClientArea();
                        editor.minimumWidth = Math.max(size.x, itemRect.width) + inset * 2;
                        int left = itemRect.x,
                        right = rect.x + rect.width;
                        editor.minimumWidth = Math.min(editor.minimumWidth, right - left);
                        editor.minimumHeight = size.y + inset * 2;
                        editor.layout();
                        break;
                    case SWT.Traverse:
                        switch (e.detail) {
                        case SWT.TRAVERSE_RETURN:
                            item.setText(i,text.getText());
                            // FALL THROUGH
                        case SWT.TRAVERSE_ESCAPE:
                            composite.dispose();
                            e.doit = false;
                        }
                        break;
                    }
                }
            };
            text.addListener(SWT.FocusOut, textListener);
            text.addListener(SWT.Traverse, textListener);
            text.addListener(SWT.Verify, textListener);
     
     
     
            editor.setEditor(composite, item, i);
            text.setText(item.getText(i));
            text.selectAll();
            text.setFocus();
     
        }
     
        public static void main(String[] argv) {
            new TableTreeTest();
        }
    }
    J'espère t'avoir aidé,

    Laurent

  8. #8
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2008
    Messages
    108
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 108
    Par défaut
    je ne sais pas comment te remercier laurent Merci bcp


    jai juste une petite question:
    est ce que je peux spécifier précisément ou placer un combo ou une entrée Text??
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    if (rect.contains(lastMouseDown)) {
                            if (i == 1) {
                                buildText(editor, item, i);
                            }
                            if (i == 2) {
                                buildCombo(editor, item, i);
                            }
                        }
    la c la 2eme colonne(attributes) qui est en entree texte et la 3eme colonne (values) en combo
    moi je veux que pour chaque ligne avoir le choix entre entree text et combo (juste dans la 3eme colonne!) exemple pour timeout une entree text et la ligne suivante(cond) un combo!!

    merci encore

  9. #9
    Membre expérimenté

    Profil pro
    Inscrit en
    Août 2006
    Messages
    218
    Détails du profil
    Informations personnelles :
    Âge : 50
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Août 2006
    Messages : 218
    Par défaut
    Bonjour,

    Oui tu peux bien sûr, là j'avais mis un exemple mixte.

    A l'endroit que tu as pointé, on récupère la colonne sélectionnée.
    L'entrée de l'arbre se trouve dans l'objet item.

    Donc en fonction de l'item et de la colonne, tu peux soit afficher une combo, soit afficher un text, soit afficher... ce que tu veux en fait.

    N'oublie pas d'ajouter résolu à ton post

    A+

    Laurent

  10. #10
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2008
    Messages
    108
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 108
    Par défaut
    Citation Envoyé par meddle Voir le message
    Bonjour,

    Oui tu peux bien sûr, là j'avais mis un exemple mixte.

    A l'endroit que tu as pointé, on récupère la colonne sélectionnée.
    L'entrée de l'arbre se trouve dans l'objet item.

    Donc en fonction de l'item et de la colonne, tu peux soit afficher une combo, soit afficher un text, soit afficher... ce que tu veux en fait.

    N'oublie pas d'ajouter résolu à ton post

    A+

    Laurent



    désolé laurent mais jarrive pas a atteindre les cases du tableau pour faire ce que je veux dessus

  11. #11
    Membre expérimenté

    Profil pro
    Inscrit en
    Août 2006
    Messages
    218
    Détails du profil
    Informations personnelles :
    Âge : 50
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Août 2006
    Messages : 218
    Par défaut
    Salut,

    Il te faut utiliser getText(1) pour récupérer le libellé de la première colonne...

    Voici un exemple :

    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
     
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.custom.CCombo;
    import org.eclipse.swt.custom.TreeEditor;
    import org.eclipse.swt.graphics.GC;
    import org.eclipse.swt.graphics.Point;
    import org.eclipse.swt.graphics.Rectangle;
    import org.eclipse.swt.layout.FillLayout;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Event;
    import org.eclipse.swt.widgets.Listener;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Text;
    import org.eclipse.swt.widgets.Tree;
    import org.eclipse.swt.widgets.TreeColumn;
    import org.eclipse.swt.widgets.TreeItem;
     
    public class TableTreeTest {
     
        // Rajout Laurent
        static Point lastMouseDown;
     
        public TableTreeTest() {
            final Display display = new Display();
            final Shell shell = new Shell(display);
            shell.setText("Elements");
            shell.setLayout(new FillLayout());
            final Tree myTree = new Tree(shell, SWT.FULL_SELECTION);
            final TreeItem iItem = new TreeItem(myTree, SWT.NONE);
     
            TreeColumn column = new TreeColumn(myTree, SWT.NONE);
            column.setText("Property");
            column.setResizable(true);
            column.setMoveable(false);
            column.setWidth(100);
            column = new TreeColumn(myTree, SWT.NONE);
            column.setText("Attributes");
            column.setResizable(true);
            column.setWidth(100);
            column = new TreeColumn(myTree, SWT.NONE);
            column.setText("Value");
            column.setResizable(true);
            column.setWidth(100);
     
            iItem.setText("Prompt");
            for (int j = 1; j < 2; j++) {
                TreeItem jItem = new TreeItem(iItem, SWT.NONE);
                jItem.setText(1, "bargein");
                jItem.setText(2, "True");
                /***/
     
            }
     
            for (int j = 1; j < 2; j++) {
                TreeItem jItem2 = new TreeItem(iItem, SWT.NONE);
                jItem2.setText(1, "Timeout");
                jItem2.setText(2, "Saisissez le temps");
                /***/
     
            }
            for (int j = 1; j < 2; j++) {
                TreeItem jItem3 = new TreeItem(iItem, SWT.NONE);
                jItem3.setText(1, "cond");
                jItem3.setText(2, "Définir la condition");
                /***/
     
            }
            for (int j = 1; j < 2; j++) {
                TreeItem jItem4 = new TreeItem(iItem, SWT.NONE);
                jItem4.setText(1, "bargeintype");
                jItem4.setText(2, "sppech ou hotword");
                /***/
     
            }
            for (int j = 1; j < 2; j++) {
                final TreeItem jItem5 = new TreeItem(iItem, SWT.NONE);
                jItem5.setText(1, "count");
                jItem5.setText(2, "False");
                /***/
     
            }
     
            myTree.setHeaderVisible(true);
            myTree.setLinesVisible(true);
            myTree.getItem(0).setExpanded(true);
     
            // Rajout Laurent
            final TreeEditor editor = new TreeEditor(myTree);
     
            myTree.addListener(SWT.MouseDown, new Listener() {
                public void handleEvent(Event event) {
                    lastMouseDown = new Point(event.x, event.y);
                }
            });
     
            myTree.addListener(SWT.KeyDown, new Listener() {
                public void handleEvent(Event event) {
                    lastMouseDown = null;
                }
            });
     
            myTree.addListener(SWT.Selection, new Listener() {
                public void handleEvent(Event event) {
                    if (lastMouseDown == null)
                        return; // Selection faite au clavier
     
                    TreeItem item = myTree.getItem(lastMouseDown);
                    for (int i = 0; i < myTree.getColumnCount(); i++) {
                        Rectangle rect = item.getBounds(i);
                        if (rect.contains(lastMouseDown)) {
                            if (i == 1) {
                                buildText(editor, item, i);
                            }
                            if (i == 2) {
                                // Attention, on est sur la troisième colonne, on affiche : 
                                // une combo pour bargein
                                // une combo différente pour bargeintype
                                // Pour les autres on affiche du texte
                                if (item.getText(1).equalsIgnoreCase("bargein")) {
                                    buildCombo(editor, item, i, new String[] {"True","False"});
                                } else if (item.getText(1).equalsIgnoreCase("bargeintype")) {
                                    buildCombo(editor, item, i, new String[] {"Speech","Hotword"});
                                } else {
                                    buildText(editor, item, i);    
                                }
                            }
                        }
                    }
                    lastMouseDown = null;
                }
            });
     
            shell.setSize(350, 350);
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
            display.dispose();
        }
     
        /**
         * @param editor
         * @param item
         * @param i
         */
        protected void buildCombo(final TreeEditor editor, final TreeItem item, final int i, final String[] values) {
            boolean showBorder = true;
            final Composite composite = new Composite(item.getParent(), SWT.NONE);
            if (showBorder)
                composite.setBackground(item.getDisplay().getSystemColor(SWT.COLOR_BLACK));
     
            final CCombo combo = new CCombo(composite, SWT.READ_ONLY);
            for (String current : values) {
                combo.add(current);
            }
            combo.pack();
            editor.horizontalAlignment = SWT.LEFT;
            editor.minimumWidth = combo.getSize().x;
            editor.minimumHeight = combo.getSize().y;
            editor.layout();
     
            final int inset = showBorder ? 1 : 0;
            composite.addListener(SWT.Resize, new Listener() {
                public void handleEvent(Event e) {
                    Rectangle rect = composite.getClientArea();
                    combo.setBounds(rect.x + inset, rect.y + inset, rect.width - inset * 2, rect.height - inset * 2);
                }
            });
     
            Listener listener = new Listener() {
                public void handleEvent(final Event e) {
                    switch (e.type) {
                    case SWT.FocusOut:
                        item.setText(i, combo.getText());
                        composite.dispose();
                        break;
                    case SWT.Traverse:
                        switch (e.detail) {
                        case SWT.TRAVERSE_RETURN:
                            item.setText(i, combo.getText());
                            // FALL THROUGH
                        case SWT.TRAVERSE_ESCAPE:
                            composite.dispose();
                            e.doit = false;
                        }
                        break;
                    }
                }
            };
            combo.addListener(SWT.FocusOut, listener);
            combo.addListener(SWT.Traverse, listener);
     
            editor.setEditor(composite, item, i);
            combo.setText(item.getText(i));
            combo.setFocus();
        }
     
        /**
         * @param editor
         * @param item
         * @param i
         */
        protected void buildText(final TreeEditor editor, final TreeItem item, final int i) {
            boolean showBorder = true;
            final Composite composite = new Composite(item.getParent(), SWT.NONE);
            if (showBorder)
                composite.setBackground(item.getDisplay().getSystemColor(SWT.COLOR_BLACK));
     
            final Text text = new Text(composite, SWT.NONE);
            final int inset = showBorder ? 1 : 0;
            composite.addListener(SWT.Resize, new Listener() {
                public void handleEvent(Event e) {
                    Rectangle rect = composite.getClientArea();
                    text.setBounds(rect.x + inset, rect.y + inset, rect.width - inset * 2, rect.height - inset * 2);
                }
            });
     
            Listener textListener = new Listener() {
                public void handleEvent(final Event e) {
                    switch (e.type) {
                    case SWT.FocusOut:
                        item.setText(i, text.getText());
                        composite.dispose();
                        break;
                    case SWT.Verify:
                        String newText = text.getText();
                        String leftText = newText.substring(0, e.start);
                        String rightText = newText.substring(e.end, newText.length());
                        GC gc = new GC(text);
                        Point size = gc.textExtent(leftText + e.text + rightText);
                        gc.dispose();
                        size = text.computeSize(size.x, SWT.DEFAULT);
                        editor.horizontalAlignment = SWT.LEFT;
                        Rectangle itemRect = item.getBounds(),
                        rect = item.getParent().getClientArea();
                        editor.minimumWidth = Math.max(size.x, itemRect.width) + inset * 2;
                        int left = itemRect.x,
                        right = rect.x + rect.width;
                        editor.minimumWidth = Math.min(editor.minimumWidth, right - left);
                        editor.minimumHeight = size.y + inset * 2;
                        editor.layout();
                        break;
                    case SWT.Traverse:
                        switch (e.detail) {
                        case SWT.TRAVERSE_RETURN:
                            item.setText(i, text.getText());
                            // FALL THROUGH
                        case SWT.TRAVERSE_ESCAPE:
                            composite.dispose();
                            e.doit = false;
                        }
                        break;
                    }
                }
            };
            text.addListener(SWT.FocusOut, textListener);
            text.addListener(SWT.Traverse, textListener);
            text.addListener(SWT.Verify, textListener);
     
            editor.setEditor(composite, item, i);
            text.setText(item.getText(i));
            text.selectAll();
            text.setFocus();
     
        }
     
        public static void main(String[] argv) {
            new TableTreeTest();
        }
    }
    Ca te va comme ça ?

    Lolo

  12. #12
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2008
    Messages
    108
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 108
    Par défaut
    Merci bcp

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 21/09/2011, 14h29
  2. Injection des accents dans les nom de tables ?
    Par lathenor dans le forum SQLite
    Réponses: 3
    Dernier message: 21/05/2007, 11h36
  3. [MySQL] Php, je ne comprends pas comment faire pour introduire des données dans une table
    Par Liondd dans le forum PHP & Base de données
    Réponses: 23
    Dernier message: 14/12/2006, 12h53
  4. Gestion des durées dans les tables Access
    Par climz dans le forum Requêtes et SQL.
    Réponses: 17
    Dernier message: 24/05/2006, 15h29
  5. Gestion des NULL dans les tables externes
    Par plouf2244 dans le forum Firebird
    Réponses: 1
    Dernier message: 23/03/2006, 16h55

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