Skip to content

Commit

Permalink
#1723 WIP Adds paging controller to calls table view.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Sheirer committed Dec 2, 2023
1 parent b53ef33 commit eb3e90a
Show file tree
Hide file tree
Showing 4 changed files with 376 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@

package io.github.dsheirer.audio.call;

import org.springframework.data.repository.CrudRepository;
import org.springframework.data.jpa.repository.JpaRepository;

/**
* Calls database repository
*/
public interface CallRepository extends CrudRepository<Call,Long>
public interface CallRepository extends JpaRepository<Call,Long>
{

}
123 changes: 111 additions & 12 deletions src/main/java/io/github/dsheirer/audio/call/CallViewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,32 @@
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import org.controlsfx.control.textfield.TextFields;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;

/**
* Audio call events playback and audio event database control/view panel.
*/
public class CallViewPanel extends VBox
public class CallViewPanel extends VBox implements IPageRequestListener
{
private static final Logger LOGGER = LoggerFactory.getLogger(CallViewPanel.class);

Expand All @@ -64,7 +66,12 @@ public class CallViewPanel extends VBox
private TableView<Call> mCallTableView;
private ProgressIndicator mPlaceholderProgressIndicator;
private HBox mSearchBox;
private HBox mPagingBox;
private TextField mSearchField;
private PagingController mPagingController;
private ComboBox<Integer> mPageSizeComboBox;
private Label mCallsCountLabel;
private long mCallCount;

/**
* Constructs an instance
Expand All @@ -81,20 +88,14 @@ public CallViewPanel()
public void postConstruct()
{
VBox.setVgrow(getCallTableView(), Priority.ALWAYS);
getChildren().addAll(getSearchBox(), getCallTableView());
getChildren().addAll(getSearchBox(), getCallTableView(), getPagingBox());

getPagingController().update(1, 20);

//Register for call event notifications
mAudioManager.add(mCallEventListener);

getPlaceholderProgressIndicator().setVisible(true);
ThreadPool.CACHED.submit(() -> {
List<Call> calls = new ArrayList<>();
mCallRepository.findAll().forEach(call -> calls.add(call));
Platform.runLater(() -> {
mCalls.addAll(calls);
getPlaceholderProgressIndicator().setVisible(false);
});
});

}

Expand All @@ -108,6 +109,91 @@ public void preDestroy()
mAudioManager.remove(mCallEventListener);
}

@Override
public void pageRequested(int page)
{
if(page >= 1)
{
Platform.runLater(() -> getPlaceholderProgressIndicator().setVisible(true));

ThreadPool.CACHED.submit(() -> {
Page<Call> callPage = mCallRepository.findAll(PageRequest.of(page - 1, getPageSize()));
Platform.runLater(() -> {
mCalls.clear();
mCalls.addAll(callPage.stream().toList());
getPlaceholderProgressIndicator().setVisible(false);
getPagingController().update(callPage.getNumber() + 1, callPage.getTotalPages());
getCallsCountLabel().setText("Calls: " + callPage.getTotalElements());
});
});
}
}

/**
* Current page size
*/
private int getPageSize()
{
return getPageSizeComboBox().getValue();
}

/**
* Calls label to display the number of calls in the database.
*/
private Label getCallsCountLabel()
{
if(mCallsCountLabel == null)
{
mCallsCountLabel = new Label("Calls: 0");
}

return mCallsCountLabel;
}

/**
* Page size selection combo box.
*
* Note: when the user changes the page size, we always request page 1 again.
*/
private ComboBox<Integer> getPageSizeComboBox()
{
if(mPageSizeComboBox == null)
{
ObservableList<Integer> pageSizes = FXCollections.observableArrayList();
pageSizes.addAll(25, 50, 100, 200);
mPageSizeComboBox = new ComboBox<>(pageSizes);
mPageSizeComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> pageRequested(1));
mPageSizeComboBox.setTooltip(new Tooltip("Select the page size"));
mPageSizeComboBox.getSelectionModel().select(0);
}

return mPageSizeComboBox;
}

/**
* Paging controls panel
*/
private HBox getPagingBox()
{
if(mPagingBox == null)
{
mPagingBox = new HBox();
mPagingBox.setAlignment(Pos.CENTER_LEFT);
mPagingBox.setSpacing(3);
Label pageSizeLabel = new Label("Page Size:");
getPagingController().setPadding(new Insets(2, 0, 6, 20));
pageSizeLabel.setPadding(new Insets(0, 2, 0, 10));
getCallsCountLabel().setPadding(new Insets(0, 0, 0, 10));
mPagingBox.getChildren().addAll(getPagingController(), pageSizeLabel, getPageSizeComboBox(), getCallsCountLabel());
}

return mPagingBox;
}

/**
* Call table view
* @return
*/
private TableView<Call> getCallTableView()
{
if(mCallTableView == null)
Expand Down Expand Up @@ -185,6 +271,19 @@ private TableView<Call> getCallTableView()
return mCallTableView;
}

/**
* Paging controller
*/
public PagingController getPagingController()
{
if(mPagingController == null)
{
mPagingController = new PagingController(this::pageRequested);
}

return mPagingController;
}

/**
* Progress indicator to convey data loading status when the table content is being updated.
* @return progress indicator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2023 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/

package io.github.dsheirer.audio.call;

/**
* Listener interface for receiving paging requests from user initiated actions.
*/
public interface IPageRequestListener
{
/**
* Indicates the user requests to display a page number
* @param page number to display.
*/
void pageRequested(int page);
}
Loading

0 comments on commit eb3e90a

Please sign in to comment.