javafx.scene.control.TableColumn.SortType Java Examples

The following examples show how to use javafx.scene.control.TableColumn.SortType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Tools.java    From logbook-kai with MIT License 6 votes vote down vote up
/**
 * テーブルソート列の設定を行う
 * @param table テーブル
 * @param key テーブルのキー名
 */
public static <S> void setSortOrder(TableView<S> table, String key) {
    Map<String, String> setting = AppConfig.get()
            .getColumnSortOrderMap()
            .get(key);
    ObservableList<TableColumn<S, ?>> sortOrder = table.getSortOrder();
    if (setting != null) {
        // 初期設定
        Map<String, TableColumn<S, ?>> columnsMap = getColumns(table)
                .collect(Collectors.toMap(Tables::getColumnName, c -> c, (c1, c2) -> c1));
        setting.forEach((k, v) -> {
            Optional.ofNullable(columnsMap.get(k)).ifPresent(col -> {
                sortOrder.add(col);
                col.setSortType(SortType.valueOf(v));
            });
        });
    }
    // ソート列またはソートタイプが変更された時に設定を保存する
    sortOrder.addListener((ListChangeListener<TableColumn<S, ?>>) e -> storeSortOrder(table, key));
    getColumns(table).forEach(col -> {
        col.sortTypeProperty().addListener((ob, o, n) -> storeSortOrder(table, key));
    });
}
 
Example #2
Source File: ProcController.java    From erlyberly with GNU General Public License v3.0 5 votes vote down vote up
private void updateProcessList(final ArrayList<ProcInfo> processList) {
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            ProcSort procSort = procSortProperty.get();
            if(procSort != null) {
                Comparator<ProcInfo> comparator = null;

                if("proc".equals(procSort.getSortField())) {
                    comparator = new Comparator<ProcInfo>() {
                        @Override
                        public int compare(ProcInfo o1, ProcInfo o2) {
                            return o1.getProcessName().compareTo(o2.getProcessName());
                        }};
                }
                else if("reduc".equals(procSort.getSortField())) {
                    comparator = new Comparator<ProcInfo>() {
                        @Override
                        public int compare(ProcInfo o1, ProcInfo o2) {
                            return Long.compare(o1.getReductions(), o2.getReductions());
                        }};
                }

                if(comparator != null) {
                    if(procSort.getSortType() == SortType.DESCENDING) {
                        comparator = Collections.reverseOrder(comparator);
                    }
                    Collections.sort(processList, comparator);
                }
            }
            processes.clear();
            processes.addAll(processList);
        }});
}
 
Example #3
Source File: AnnunciatorTable.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Create an AnnunciatorTable view.
 * @param client - TalkClient used to listen to the *Talk topic.
 */
public AnnunciatorTable (final TalkClient client)
{
    this.client = client;
    this.client.addListener(this);

    if (annunciator_retention_count < 1)
        logger.log(Level.SEVERE, "Annunciation Retention Count set below 1.");

    table.setPlaceholder(new Label("No annunciations"));

    time.setCellValueFactory(cell -> cell.getValue().time_received);
    time.setCellFactory(c -> new TimeCell());
    time.setPrefWidth(190);
    time.setResizable(false);
    table.getColumns().add(time);

    // Sort by time, most recent on top
    time.setSortType(SortType.DESCENDING);
    table.getSortOrder().setAll(List.of(time));

    severity.setCellValueFactory(cell -> cell.getValue().severity);
    severity.setCellFactory(c -> new SeverityCell());
    severity.setPrefWidth(90);
    severity.setResizable(false);
    table.getColumns().add(severity);

    description.setCellValueFactory(cell -> cell.getValue().message);
    description.setCellFactory(c -> new MessageCell());
    // Width left in window is window width minus time width (190), minus severity width (90), minus width of window edges(1 * 2).
    description.prefWidthProperty().bind(table.widthProperty().subtract(282));
    table.getColumns().add(description);

    // Table should always grow to fill VBox.
    setVgrow(table, Priority.ALWAYS);

    // Give the addAnnunciationToTable method as a callback to the controller. Will be called after message handling to add message to table.
    annunciatorController = new AnnunciatorController(annunciator_threshold, this::addAnnunciationToTable);

    // Top button row
    muteButton.setTooltip(muteTip);
    muteButton.setOnAction(event ->
    {
        // Mute is true when the annunciator should be muted.
        final boolean mute = muteButton.isSelected();
        // Update image
        final ImageView image = (ImageView) muteButton.getGraphic();
        image.setImage(mute ? anunciate_icon : mute_icon);
        muteButton.setTooltip(mute ? annunciateTip : muteTip);
        annunciatorController.setMuted(mute);
        // Refresh the table cell items so that they recalculate their background color.
        table.refresh();
    });

    testButton.setTooltip(new Tooltip("Play test message"));
    testButton.setOnAction(event ->
        annunciatorController.annunciate(new AnnunciatorMessage(false, SeverityLevel.OK, Instant.now(), "Testing 1 2 3")) );

    clearTableButton.setTooltip(new Tooltip("Clear the messages in the table."));
    clearTableButton.setOnAction(event ->
    {
        final Alert alert  = new Alert(AlertType.CONFIRMATION);
        alert.setTitle("Clear Annunciator Table");
        alert.setHeaderText("Clear the table of all annunciations?");
        DialogHelper.positionDialog(alert, clearTableButton, -200, -100);
        alert.showAndWait()
            .filter(response -> response == ButtonType.OK)
            .ifPresent(response -> clearTable());
    });

    toolbar = new ToolBar(ToolbarHelper.createSpring(), muteButton, testButton, clearTableButton);

    getChildren().setAll(toolbar, table);

    // Annunciate message so that user can determine if annunciator and table are indeed functional.
    messageReceived(SeverityLevel.OK, true, "Annunciator started");
}
 
Example #4
Source File: AlarmTableUI.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private TableView<AlarmInfoRow> createTable(final ObservableList<AlarmInfoRow> rows,
                                            final boolean active)
{
    final SortedList<AlarmInfoRow> sorted = new SortedList<>(rows);
    final TableView<AlarmInfoRow> table = new TableView<>(sorted);

    // Ensure that the sorted rows are always updated as the column sorting
    // of the TableView is changed by the user clicking on table headers.
    sorted.comparatorProperty().bind(table.comparatorProperty());

    TableColumn<AlarmInfoRow, SeverityLevel> sevcol = new TableColumn<>(/* Icon */);
    sevcol.setPrefWidth(25);
    sevcol.setReorderable(false);
    sevcol.setResizable(false);
    sevcol.setCellValueFactory(cell -> cell.getValue().severity);
    sevcol.setCellFactory(c -> new SeverityIconCell());
    table.getColumns().add(sevcol);

    final TableColumn<AlarmInfoRow, String> pv_col = new TableColumn<>("PV");
    pv_col.setPrefWidth(240);
    pv_col.setReorderable(false);
    pv_col.setCellValueFactory(cell -> cell.getValue().pv);
    pv_col.setCellFactory(c -> new DragPVCell());
    pv_col.setComparator(CompareNatural.INSTANCE);
    table.getColumns().add(pv_col);

    TableColumn<AlarmInfoRow, String> col = new TableColumn<>("Description");
    col.setPrefWidth(400);
    col.setReorderable(false);
    col.setCellValueFactory(cell -> cell.getValue().description);
    col.setCellFactory(c -> new DragPVCell());
    col.setComparator(CompareNatural.INSTANCE);
    table.getColumns().add(col);

    sevcol = new TableColumn<>("Alarm Severity");
    sevcol.setPrefWidth(130);
    sevcol.setReorderable(false);
    sevcol.setCellValueFactory(cell -> cell.getValue().severity);
    sevcol.setCellFactory(c -> new SeverityLevelCell());
    table.getColumns().add(sevcol);

    col = new TableColumn<>("Alarm Status");
    col.setPrefWidth(130);
    col.setReorderable(false);
    col.setCellValueFactory(cell -> cell.getValue().status);
    col.setCellFactory(c -> new DragPVCell());
    table.getColumns().add(col);

    TableColumn<AlarmInfoRow, Instant> timecol = new TableColumn<>("Alarm Time");
    timecol.setPrefWidth(200);
    timecol.setReorderable(false);
    timecol.setCellValueFactory(cell -> cell.getValue().time);
    timecol.setCellFactory(c -> new TimeCell());
    table.getColumns().add(timecol);

    col = new TableColumn<>("Alarm Value");
    col.setPrefWidth(100);
    col.setReorderable(false);
    col.setCellValueFactory(cell -> cell.getValue().value);
    col.setCellFactory(c -> new DragPVCell());
    table.getColumns().add(col);

    sevcol = new TableColumn<>("PV Severity");
    sevcol.setPrefWidth(130);
    sevcol.setReorderable(false);
    sevcol.setCellValueFactory(cell -> cell.getValue().pv_severity);
    sevcol.setCellFactory(c -> new SeverityLevelCell());
    table.getColumns().add(sevcol);

    col = new TableColumn<>("PV Status");
    col.setPrefWidth(130);
    col.setReorderable(false);
    col.setCellValueFactory(cell -> cell.getValue().pv_status);
    col.setCellFactory(c -> new DragPVCell());
    table.getColumns().add(col);

    // Initially, sort on PV name
    // - restore(Memento) might change that
    table.getSortOrder().setAll(List.of(pv_col));
    pv_col.setSortType(SortType.ASCENDING);

    table.setPlaceholder(new Label(active ? "No active alarms" : "No acknowledged alarms"));
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    createContextMenu(table, active);

    // Double-click to acknowledge or un-acknowledge
    table.setRowFactory(tv ->
    {
        final TableRow<AlarmInfoRow> row = new TableRow<>();
        row.setOnMouseClicked(event ->
        {
            if (event.getClickCount() == 2  &&  !row.isEmpty())
                JobManager.schedule("ack", monitor ->  client.acknowledge(row.getItem().item, active));
        });
        return row;
    });

    return table;
}
 
Example #5
Source File: BattleOfDecksResultView.java    From metastone with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public BattleOfDecksResultView() {
	FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/BattleOfDecksResultView.fxml"));
	fxmlLoader.setRoot(this);
	fxmlLoader.setController(this);

	try {
		fxmlLoader.load();
	} catch (IOException exception) {
		throw new RuntimeException(exception);
	}

	TableColumn<BattleDeckResult, String> nameColumn = new TableColumn<>("Deck name");
	nameColumn.setPrefWidth(200);
	TableColumn<BattleDeckResult, Double> winRateColumn = new TableColumn<>("Win rate");
	winRateColumn.setPrefWidth(150);

	nameColumn.setCellValueFactory(new PropertyValueFactory<BattleDeckResult, String>("deckName"));
	winRateColumn.setCellValueFactory(new PropertyValueFactory<BattleDeckResult, Double>("winRate"));

	winRateColumn.setCellFactory(new Callback<TableColumn<BattleDeckResult, Double>, TableCell<BattleDeckResult, Double>>() {
		public TableCell<BattleDeckResult, Double> call(TableColumn<BattleDeckResult, Double> p) {
			TableCell<BattleDeckResult, Double> cell = new TableCell<BattleDeckResult, Double>() {
				private final Label label = new Label();
				private final ProgressBar progressBar = new ProgressBar();
				private final StackPane stackPane = new StackPane();

				{
					label.getStyleClass().setAll("progress-text");
					stackPane.setAlignment(Pos.CENTER);
					stackPane.getChildren().setAll(progressBar, label);
					setGraphic(stackPane);
				}

				@Override
				protected void updateItem(Double winrate, boolean empty) {
					super.updateItem(winrate, empty);
					if (winrate == null || empty) {
						setGraphic(null);
						return;
					}
					progressBar.setProgress(winrate);
					label.setText(String.format("%.2f", winrate * 100) + "%");
					setGraphic(stackPane);
				}

			};
			return cell;
		}
	});

	rankingTable.getColumns().setAll(nameColumn, winRateColumn);
	rankingTable.getColumns().get(1).setSortType(SortType.DESCENDING);

	backButton.setOnAction(event -> NotificationProxy.sendNotification(GameNotification.MAIN_MENU));
}
 
Example #6
Source File: ProcSort.java    From erlyberly with GNU General Public License v3.0 4 votes vote down vote up
public ProcSort(String sortField, SortType sortType) {
    this.sortField = sortField;
    this.sortType = sortType;
}
 
Example #7
Source File: ProcSort.java    From erlyberly with GNU General Public License v3.0 4 votes vote down vote up
public SortType getSortType() {
    return sortType;
}
 
Example #8
Source File: ProcController.java    From erlyberly with GNU General Public License v3.0 3 votes vote down vote up
public ProcController() {
    polling = new SimpleBooleanProperty();

    procSortProperty = new SimpleObjectProperty<>(new ProcSort("reduc", SortType.DESCENDING));

    procPollerThread = new ProcPollerThread();

    waiter = new Object();

    Platform.runLater(() -> {
        ErlyBerly.nodeAPI().connectedProperty().addListener((o) -> { startPollingThread(); } );
    });

    filter.addListener((o, ov, nv) -> { updateProcFilter(nv); });
}