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
| private class MonAction extends Action {
int typeAction = SWT.DOWN; //Valeur par défaut
public MonAction(String nomAction, int typeAction) {
super(nomAction);
this.typeAction = typeAction;
}
public void run() {
int inc = 0; //Valeur à incrémenter par rapport à l'index de la sélection
if (typeAction == SWT.DOWN)
inc = 1;
else if (typeAction == SWT.UP)
inc = -1;
TableViewer viewer = new TableViewer(table);
int index0 = table.getSelectionIndex();
int index1 = index0 + inc;
Object o1 = viewer.getElementAt(index0);
Object o2 = viewer.getElementAt(index1);
viewer.replace(o2, index0);
viewer.replace(o1, index1);
table.select(index0);
}
}
public void maMethode() {
...
MonAction actionUp = new MonAction("Monter", SWT.UP);
MonAction actionDown = new MonAction("Descendre", SWT.DOWN);
...
} |
Partager