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
|
public class TutoTable {
private static Table table;
private static TableColumn colonneClef;
private static TableColumn colonneValeur;
private static ArrayList<Text> textSendClef;
private static ArrayList<Text> textSendValue;
private static List listInfo;
private static Display display;
private static ArrayList<TableItem> tableItem;
private static String textEnCours = "";
public static void main(String[] args) {
display = new Display();
Shell shell = new Shell(display);
shell.setText("test");
shell.setSize(500, 500);
table = new Table(shell,SWT.BORDER | SWT.V_SCROLL);
table.setSize(250, 200);
table.setLocation(5, 30);
table.setHeaderVisible(true);
table.setLinesVisible(true);
colonneClef = new TableColumn(table, SWT.NONE);
colonneClef.setText("Clef");
colonneClef.setWidth(150);
colonneClef.setResizable(false);
colonneValeur = new TableColumn(table, SWT.NONE);
colonneValeur.setText("valeur");
colonneValeur.setWidth(150);
colonneValeur.setResizable(false);
listInfo = new List(shell, SWT.BORDER);
listInfo.setSize(200, 300);
listInfo.setLocation(275, 80);
//listener pour la colonne Clef de champs Text
class ListenerSendClef implements Listener{
Text textSend;
public ListenerSendClef(Text textSend){
this.textSend = textSend;
}
public void handleEvent(Event e) {
String SendMajClef = textSend.getText();
textEnCours = SendMajClef;
listInfo.add(SendMajClef);
}
};
//listener pour la colonne Valeur de champs Text
class ListenerSendValue implements Listener{
Text textSend;
public ListenerSendValue(Text textSend){
this.textSend = textSend;
}
public void handleEvent(Event e) {
String SendMajValue = textSend.getText();
textEnCours = SendMajValue;
listInfo.add(SendMajValue);
}
};
textSendClef = new ArrayList<Text>();
textSendValue = new ArrayList<Text>();
tableItem = new ArrayList<TableItem>();
//je remplis le tableau
for (int index = 0; index < 10; index++)
{
String clef = "clef " + String.valueOf(index);
String value = "value " + String.valueOf(index);
TableItem item = new TableItem(table, SWT.NONE);
tableItem.add(item);
TableEditor editor = new TableEditor(table);
Text textClef = new Text(table, SWT.NONE);
textClef.setText(clef);
editor.grabHorizontal = true;
editor.setEditor(textClef, item, 0);
textSendClef.add(textClef);
editor = new TableEditor(table);
Text textValue = new Text(table, SWT.NONE);
textValue.setText(value);
editor.grabHorizontal = true;
editor.setEditor(textValue, item, 1);
textSendValue.add(textValue);
}
//implémentation des listeners
for (int index = 0; index < 10; index++)
textSendClef.get(index).addListener(SWT.MouseDoubleClick, new ListenerSendClef(textSendClef.get(index)));
for (int index = 0; index < 10; index++)
textSendValue.get(index).addListener(SWT.MouseDoubleClick, new ListenerSendValue(textSendValue.get(index)));
Button btOk2 = new Button(shell,SWT.PUSH);
btOk2.setSize(50,50);
btOk2.setLocation(350,30);
btOk2.setText("Test");
btOk2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (textEnCours.length() == 0)
return;
// je recherche le type de Text et sa position
for (int index = 0; index < 10; index++)
{
String clef = textSendClef.get(index).getText();
String valeur = textSendValue.get(index).getText();
if (clef.contains(textEnCours))
listInfo.add("C'est une Clef à l'index = " + String.valueOf(index));
if (valeur.contains(textEnCours))
listInfo.add("C'est une Valeur à l'index = " + String.valueOf(index));
}
//On le supprime comment ?????????????????????
}
});
//Affichage de la fenetre
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
} |
Partager