public void removeSelected() {
final String address = rnListView.getSelectionModel().getSelectedItem();
if (address == null || address.isEmpty()) {
return;
}
final Button closeBtn = ButtonBuilder.create().text(RS.rbLabel(KEY.CLOSE)).build();
final GuiUtil.DialogService dialogService = GuiUtil.dialogService(null, KEY.APP_TITLE,
RS.rbLabel(KEY.WIRELESS_NODE_REMOTE_REMOVE, address),
KEY.SUBMIT, 550d, 300d, new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
// if the dialog shouldn't be closed call super.cancel()
try {
log.info("Attempting to remove remote node at address: "
+ address);
if (controlBar.getActor().getHost().getRemoteNodes().size() > 1) {
RemoteNode rnr = null;
for (final RemoteNode rn : controlBar.getActor().getHost().getRemoteNodes()) {
if (address.equalsIgnoreCase(rn.getAddress())) {
rnr = rn;
break;
}
}
if (rnr != null) {
// remove node and persist changes (actual removal from view will
// occur when the removal has been committed)
controlBar.getActor().getHost().getRemoteNodes().remove(rnr);
ServiceProvider.IMPL.getCredentialService().mergeHost(
controlBar.getActor().getHost(), rnr);
}
}
} catch (final Throwable t) {
throw new RuntimeException();
}
return null;
}
};
}
}, Modality.APPLICATION_MODAL, closeBtn);
if (closeBtn != null) {
closeBtn.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(final MouseEvent event) {
dialogService.hide();
}
});