Search in sources :

Example 1 with NodeTableCell

use of com.faforever.client.fx.NodeTableCell in project downlords-faf-client by FAForever.

the class CoopController method initialize.

public void initialize() {
    missionComboBox.setCellFactory(param -> missionListCell());
    missionComboBox.setButtonCell(missionListCell());
    missionComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> setSelectedMission(newValue));
    playButton.disableProperty().bind(titleTextField.textProperty().isEmpty());
    numberOfPlayersComboBox.setButtonCell(numberOfPlayersCell());
    numberOfPlayersComboBox.setCellFactory(param -> numberOfPlayersCell());
    numberOfPlayersComboBox.getSelectionModel().select(2);
    numberOfPlayersComboBox.getSelectionModel().selectedItemProperty().addListener(observable -> loadLeaderboard());
    // TODO don't use API object but bean instead
    rankColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getRanking()));
    rankColumn.setCellFactory(param -> new StringCell<>(String::valueOf));
    playerCountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getPlayerCount()));
    playerCountColumn.setCellFactory(param -> new StringCell<>(String::valueOf));
    playerNamesColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPlayerNames()));
    playerNamesColumn.setCellFactory(param -> new StringCell<>(String::valueOf));
    secondaryObjectivesColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue().isSecondaryObjectives()));
    secondaryObjectivesColumn.setCellFactory(param -> new StringCell<>(aBoolean -> aBoolean ? i18n.get("yes") : i18n.get("no")));
    timeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDuration()));
    timeColumn.setCellFactory(param -> new StringCell<>(timeService::shortDuration));
    replayColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getId()));
    replayColumn.setCellFactory(param -> new NodeTableCell<>((replayId) -> {
        ReplayButtonController button = uiService.loadFxml("theme/play/coop/replay_button.fxml");
        button.setReplayId(replayId);
        button.setOnClickedAction(this::onReplayButtonClicked);
        return button.getRoot();
    }));
    webViewConfigurer.configureWebView(descriptionWebView);
    ObservableList<Game> games = gameService.getGames();
    FilteredList<Game> filteredItems = new FilteredList<>(games);
    filteredItems.setPredicate(OPEN_COOP_GAMES_PREDICATE);
    GamesTableController gamesTableController = uiService.loadFxml("theme/play/games_table.fxml");
    gamesTableController.initializeGameTable(filteredItems);
    Node root = gamesTableController.getRoot();
    populateContainer(root);
    coopService.getMissions().thenAccept(coopMaps -> {
        Platform.runLater(() -> missionComboBox.setItems(observableList(coopMaps)));
        SingleSelectionModel<CoopMission> selectionModel = missionComboBox.getSelectionModel();
        if (selectionModel.isEmpty()) {
            Platform.runLater(selectionModel::selectFirst);
        }
    }).exceptionally(throwable -> {
        notificationService.addPersistentErrorNotification(throwable, "coop.couldNotLoad", throwable.getLocalizedMessage());
        return null;
    });
}
Also used : Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) NewGameInfo(com.faforever.client.game.NewGameInfo) Arrays(java.util.Arrays) GameService(com.faforever.client.game.GameService) UiService(com.faforever.client.theme.UiService) COOP(com.faforever.client.game.KnownFeaturedMod.COOP) ListCell(javafx.scene.control.ListCell) ReportingService(com.faforever.client.reporting.ReportingService) FXCollections.observableList(javafx.collections.FXCollections.observableList) TimeService(com.faforever.client.util.TimeService) ComboBox(javafx.scene.control.ComboBox) Duration(java.time.Duration) GameStatus(com.faforever.client.remote.domain.GameStatus) TableView(javafx.scene.control.TableView) Pane(javafx.scene.layout.Pane) TextField(javafx.scene.control.TextField) Predicate(java.util.function.Predicate) SingleSelectionModel(javafx.scene.control.SingleSelectionModel) FilteredList(javafx.collections.transformation.FilteredList) AbstractViewController(com.faforever.client.fx.AbstractViewController) CoopResult(com.faforever.client.api.dto.CoopResult) DismissAction(com.faforever.client.notification.DismissAction) Platform(javafx.application.Platform) Text(javafx.scene.text.Text) ModService(com.faforever.client.mod.ModService) ObservableList(javafx.collections.ObservableList) NodeTableCell(com.faforever.client.fx.NodeTableCell) PreferencesService(com.faforever.client.preferences.PreferencesService) PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Scope(org.springframework.context.annotation.Scope) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) Strings(com.google.common.base.Strings) StringListCell(com.faforever.client.fx.StringListCell) PasswordField(javafx.scene.control.PasswordField) ReportAction(com.faforever.client.notification.ReportAction) WebView(javafx.scene.web.WebView) StringCell(com.faforever.client.fx.StringCell) Collections.emptySet(java.util.Collections.emptySet) JavaFxUtil(com.faforever.client.fx.JavaFxUtil) Node(javafx.scene.Node) ReplayService(com.faforever.client.replay.ReplayService) WebViewConfigurer(com.faforever.client.fx.WebViewConfigurer) GamesTableController(com.faforever.client.game.GamesTableController) Component(org.springframework.stereotype.Component) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Severity(com.faforever.client.notification.Severity) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ImageView(javafx.scene.image.ImageView) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Game(com.faforever.client.game.Game) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SingleSelectionModel(javafx.scene.control.SingleSelectionModel) Node(javafx.scene.Node) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) GamesTableController(com.faforever.client.game.GamesTableController) FilteredList(javafx.collections.transformation.FilteredList) Game(com.faforever.client.game.Game)

Example 2 with NodeTableCell

use of com.faforever.client.fx.NodeTableCell in project downlords-faf-client by FAForever.

the class LiveReplayController method initializeGameTable.

private void initializeGameTable(ObservableList<Game> games) {
    SortedList<Game> sortedList = new SortedList<>(games);
    sortedList.comparatorProperty().bind(liveReplayControllerRoot.comparatorProperty());
    mapPreviewColumn.setCellFactory(param -> new MapPreviewTableCell(uiService));
    mapPreviewColumn.setCellValueFactory(param -> Bindings.createObjectBinding(() -> mapService.loadPreview(param.getValue().getMapFolderName(), PreviewSize.SMALL), param.getValue().mapFolderNameProperty()));
    gameTitleColumn.setCellValueFactory(param -> param.getValue().titleProperty());
    gameTitleColumn.setCellFactory(param -> new StringCell<>(title -> title));
    playersColumn.setCellValueFactory(param -> param.getValue().numPlayersProperty());
    playersColumn.setCellFactory(param -> new StringCell<>(number -> i18n.number(number.intValue())));
    hostColumn.setCellValueFactory(param -> param.getValue().hostProperty());
    hostColumn.setCellFactory(param -> new StringCell<>(String::toString));
    modsColumn.setCellValueFactory(this::modCell);
    modsColumn.setCellFactory(param -> new StringCell<>(String::toString));
    watchColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue()));
    watchColumn.setCellFactory(param -> new NodeTableCell<>(this::watchReplayButton));
    liveReplayControllerRoot.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> Platform.runLater(() -> selectedGame.set(newValue)));
    liveReplayControllerRoot.setItems(games);
}
Also used : GameService(com.faforever.client.game.GameService) UiService(com.faforever.client.theme.UiService) MapPreviewTableCell(com.faforever.client.game.MapPreviewTableCell) PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Bindings(javafx.beans.binding.Bindings) Scope(org.springframework.context.annotation.Scope) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) GameStatus(com.faforever.client.remote.domain.GameStatus) TableView(javafx.scene.control.TableView) SortedList(javafx.collections.transformation.SortedList) StringCell(com.faforever.client.fx.StringCell) ObjectProperty(javafx.beans.property.ObjectProperty) Node(javafx.scene.Node) AbstractViewController(com.faforever.client.fx.AbstractViewController) ObservableMap(javafx.collections.ObservableMap) Collectors(java.util.stream.Collectors) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) Platform(javafx.application.Platform) Component(org.springframework.stereotype.Component) List(java.util.List) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Entry(java.util.Map.Entry) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) NotNull(org.jetbrains.annotations.NotNull) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Image(javafx.scene.image.Image) Game(com.faforever.client.game.Game) NodeTableCell(com.faforever.client.fx.NodeTableCell) Joiner(com.google.common.base.Joiner) MapPreviewTableCell(com.faforever.client.game.MapPreviewTableCell) Game(com.faforever.client.game.Game) SortedList(javafx.collections.transformation.SortedList)

Aggregations

AbstractViewController (com.faforever.client.fx.AbstractViewController)2 NodeTableCell (com.faforever.client.fx.NodeTableCell)2 StringCell (com.faforever.client.fx.StringCell)2 Game (com.faforever.client.game.Game)2 GameService (com.faforever.client.game.GameService)2 I18n (com.faforever.client.i18n.I18n)2 MapService (com.faforever.client.map.MapService)2 PreviewSize (com.faforever.client.map.MapServiceImpl.PreviewSize)2 GameStatus (com.faforever.client.remote.domain.GameStatus)2 UiService (com.faforever.client.theme.UiService)2 Platform (javafx.application.Platform)2 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)2 ObservableList (javafx.collections.ObservableList)2 Node (javafx.scene.Node)2 TableColumn (javafx.scene.control.TableColumn)2 TableView (javafx.scene.control.TableView)2 Inject (javax.inject.Inject)2 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)2 Scope (org.springframework.context.annotation.Scope)2