btnRenameButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
btnRenameButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TableItem[] items = table.getSelection();
Favorite favorite = (Favorite) items[0].getData();
RenameFavoriteDialog dialog = new RenameFavoriteDialog(shell, image, favorite);
String name = (String) dialog.open();
if(name != null) {
items[0].setText(new String[] { name, favorite.getFavorite() });
favorite.setName(name);
items[0].setData(favorite);
}
}
});
btnRenameButton.setEnabled(false);
btnRenameButton.setText(RedisClient.i18nFile.getText(I18nFile.RENAME));
btnRemoveButton = new Button(grpFavorites, SWT.NONE);
btnRemoveButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
btnRemoveButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TableItem[] items = table.getSelection();
for(TableItem item : items){
item.dispose();
}
tableItemSelected();
}
});
btnRemoveButton.setEnabled(false);
btnRemoveButton.setText(RedisClient.i18nFile.getText(I18nFile.REMOVE));
Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new FillLayout(SWT.HORIZONTAL));
composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
Button btnOk = new Button(composite, SWT.NONE);
btnOk.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("unchecked")
@Override
public void widgetSelected(SelectionEvent e) {
TableItem[] items = table.getItems();
for(TableItem item : items){
((ArrayList<Favorite>) result).add((Favorite) item.getData());
}
shell.dispose();
}
});
btnOk.setText(RedisClient.i18nFile.getText(I18nFile.OK));
Button btnCancel = new Button(composite, SWT.NONE);
btnCancel.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
result = null;
shell.dispose();
}
});
btnCancel.setText(RedisClient.i18nFile.getText(I18nFile.CANCEL));
List<Favorite> favorites = service.listAll();
for(Favorite favorite: favorites){
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[] { favorite.getName(),
favorite.getFavorite() });
item.setData(favorite);
}
super.createContents();
}