List of usage examples for javafx.scene.control ListCell ListCell
public ListCell()
From source file:ubicrypt.ui.ctrl.providers.ProvidersController.java
@Override public void initialize(URL url, ResourceBundle resourceBundle) { String fxml = substringBefore(substringAfterLast(url.getFile(), "/"), ".fxml"); navigator = new StackNavigator(root, fxml, controllerFactory); providers.setCellFactory(listView -> new ListCell<ProviderItem>() { @Override/*from ww w . j a v a 2 s .c o m*/ protected void updateItem(ProviderItem pi, boolean empty) { super.updateItem(pi, empty); if (empty) { setText(null); setGraphic(null); return; } setContextMenu(pi.getContextMenu()); Platform.runLater(() -> setGraphic(pi.getGraphics())); } }); providerDescriptors.stream().forEach(pd -> { Button button = new Button(); Image img = pd.getLogo().getImage(); ImageView view = new ImageView(img); view.setFitWidth(30.0); view.setPickOnBounds(true); view.setPreserveRatio(true); button.setGraphic(view); button.setOnMouseClicked(mouseEvent -> { log.debug("adding provider :{}", pd.getCode()); navigator.browse(format("provider/%s", pd.getCode())); }); button.setTooltip(new Tooltip("Add " + pd.getDescription())); availableProviders.getItems().add(button); }); //provider status events providerEvent.subscribe(pevent -> { UbiProvider provider = pevent.getHook().getProvider(); if (!providers.getItems().stream().filter(pi -> pi.getProvider().equals(provider)).findFirst() .isPresent()) { log.info("add new provider:{}", pevent.getHook().getProvider()); String code = providerDescriptors.stream().filter(pd -> pd.getType() == provider.getClass()) .map(ProviderDescriptor::getCode).findFirst().get(); final ProviderItem providerItem = new ProviderItem(provider, providerDescriptors.stream() .filter(pd -> pd.getType() == provider.getClass()).findFirst().get(), providerRemover, navigator); providers.getItems().add(providerItem); pevent.getHook().getStatusEvents().subscribe(providerItem::changeStatus); } switch (pevent.getEvent()) { case removed: //TODO: remove provider break; default: log.warn("unmanaged event:{}", pevent.getEvent()); } providers.getItems().stream().filter(pi -> pi.getProvider().equals(provider)).findFirst() .ifPresent(pi -> pi.changeStatus(pevent.getEvent())); }); }
From source file:Watcher.FXMLDocumentController.java
@Override public void initialize(URL url, ResourceBundle rb) { ServiceHandler.start(new notificationService()); try {/* w ww. ja va 2 s . c o m*/ HSQL_Manager.init("jdbc:hsqldb:file:src/dbEnv/", "SA", ""); } catch (ClassNotFoundException | SQLException ex) { Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex); } int count = 0; for (Site a : HSQL_Manager.getSites()) { items.add(a.getAddress()); try { //sites.add(new Site(siteList.getItems().get(i).toString())); watcherManager.addSite(a); } catch (WatchDogNotStartedException | SiteAlreadyAddedException ex) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); new errDialog().showError(sw.toString()); break; } count++; } MenuItem deleteItem = new MenuItem("Delete"); final ContextMenu contextMenu = new ContextMenu(deleteItem); contextMenu.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { removeItem(new Site(siteList.getSelectionModel().getSelectedItem().toString())); } }); siteList.setCellFactory(new Callback<ListView<String>, ListCell<String>>() { @Override public ListCell<String> call(ListView<String> param) { ListCell<String> cell = new ListCell<String>() { @Override protected void updateItem(String item, boolean empty) { super.updateItem(item, empty); //textProperty().unbind(); setContextMenu(null); if (!empty && item != null) { setContextMenu(contextMenu); setText(item); } if (item != null) { } else { setGraphic(null); setText(""); } } }; return cell; } }); siteList.getSelectionModel().selectedItemProperty().addListener(new listViewChangeListener()); siteList.setItems(items); siteList.autosize(); if (count > 0) { siteList.getSelectionModel().select(0); } uptime.setAnimated(false); //uptime.setStyle(null); processor = new processData(uptime, detailedData); try { ServiceHandler.startService(new InternetWatcher("http://www.google.com", 3)); ServiceHandler.startService( new StatusUpdater(1, (FXMLDocumentController) JavaFXApplication4.getLoader().getController())); } catch (InternetWatcherServiceAlreadyStartedException | WatchDogTimerServiceAlreadyStartedException | StatusUpdaterServiceAlreadyStartedException ex) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); new errDialog().showError(sw.toString()); } removeFilter.setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent t) { if (t.isPrimaryButtonDown()) { processor.cancelFilter(getSelectedItem()); } } }); }