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
| /**
* The number of {@link CTabItem}s.
*/
private static final int NUMBER_OF_ELEMENTS = 4;
/**
* The key to the data store in each {@link CTabItem}.
*/
private static final String IS_ENABLED = "isEnabled";
/**
* @param args the entries of the main.
*/
public static void main(final String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
CTabFolder folder = new CTabFolder(shell, SWT.BORDER);
CTabItem item;
Composite folderComposite;
Text text;
for (int i = 0; i < NUMBER_OF_ELEMENTS; i++) {
item = new CTabItem(folder, SWT.CLOSE);
item.setText("Item " + i);
folderComposite = new Composite(folder, SWT.NONE);
folderComposite.setLayout(new FillLayout());
text = new Text(folderComposite, SWT.MULTI);
text.setText("Content for Item " + i);
item.setControl(folderComposite);
// On stocke l'état (actif ou non) du contenu
item.setData(IS_ENABLED, i % 2 == 0);
}
folder.addListener(SWT.Selection, new Listener() {
/**
* {@inheritDoc}
*/
public void handleEvent(final Event event) {
Widget selectedItem = event.item;
if (selectedItem instanceof CTabItem) {
// On récupère le contenu stocké
boolean isEnabled =
(Boolean) selectedItem.getData(IS_ENABLED);
// On met à jour l'état du Composite.
((CTabItem) selectedItem).getControl()
.setEnabled(isEnabled);
}
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
} |
Partager