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
| /**
*
*/
public static void main(final String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
Button button = new Button(shell, SWT.PUSH);
button.setLayoutData(new GridData());
final ListViewer viewer =
new ListViewer(shell, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL
| SWT.BORDER);
viewer.getList().setLayoutData(
new GridData(SWT.FILL, SWT.FILL, true, true));
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new LabelProvider() {
/**
* {@inheritDoc}
*/
@Override
public String getText(final Object element) {
return super.getText(element);
}
});
final List < File > selectableFiles = new ArrayList < File >();
button.addSelectionListener(new SelectionAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void widgetSelected(final SelectionEvent e) {
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
String path = dialog.open();
if (path != null) {
File selectedFile = new File(path);
selectableFiles.add(selectedFile);
viewer.setInput(selectableFiles);
}
}
});
button.setText("Add File");
shell.setSize(300, 300);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
} |
Partager