use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class TableViewTopComponentNGTest method handleGraphClosed.
@Test
public void handleGraphClosed() throws InterruptedException {
final TableViewTopComponent tableViewTopComponent = mock(TableViewTopComponent.class);
final TablePane tablePane = mock(TablePane.class);
final ActiveTableReference activeTableReference = mock(ActiveTableReference.class);
final Pagination pagination = mock(Pagination.class);
final UserTablePreferences userTablePreferences = new UserTablePreferences();
userTablePreferences.setMaxRowsPerPage(42);
when(tableViewTopComponent.getTablePane()).thenReturn(tablePane);
when(tablePane.getActiveTableReference()).thenReturn(activeTableReference);
when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
when(activeTableReference.getPagination()).thenReturn(pagination);
doCallRealMethod().when(tableViewTopComponent).handleGraphClosed(any(Graph.class));
tableViewTopComponent.handleGraphClosed(mock(Graph.class));
verify(activeTableReference).updatePagination(42, null, tablePane);
}
use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class TableViewPreferencesIoProvider method savePreferences.
/**
* Saves details of the table's current preferences. Persists the
* preferences as JSON to the local disk.
*
* @param tableElementType the current table setting specifying which
* element type to display
* @param table the current table
* @param pageSize the current table page size
*/
public static void savePreferences(final GraphElementType tableElementType, final TableView<ObservableList<String>> table, final int pageSize) {
final String filePrefix = tableElementType == GraphElementType.VERTEX ? VERTEX_FILE_PREFIX : TRANSACTION_FILE_PREFIX;
final UserTablePreferences tablePreferences = new UserTablePreferences();
tablePreferences.setColumnOrder(table.getColumns().stream().filter(column -> column.isVisible()).map(column -> column.getText()).collect(Collectors.toList()));
tablePreferences.setMaxRowsPerPage(pageSize);
if (!table.getSortOrder().isEmpty()) {
tablePreferences.setSortByColumn(ImmutablePair.of(table.getSortOrder().get(0).getText(), table.getSortOrder().get(0).getSortType()));
}
JsonIO.saveJsonPreferences(Optional.of(TABLE_VIEW_PREF_DIR), Optional.of(filePrefix), List.of(tablePreferences));
}
use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class TableViewPreferencesIoProvider method getPreferences.
/**
* Load in the preferences from the JSON file into the
* {@link UserTablePreferences} POJO.
*
* @param tableElementType the current table setting specifying which
* element type to display
*
* @return a populated {@link UserTablePreferences} from the local file
*/
public static UserTablePreferences getPreferences(final GraphElementType tableElementType) {
final String filePrefix = tableElementType == GraphElementType.VERTEX ? VERTEX_FILE_PREFIX : TRANSACTION_FILE_PREFIX;
final List<UserTablePreferences> root = JsonIO.loadJsonPreferences(Optional.of(TABLE_VIEW_PREF_DIR), Optional.of(filePrefix), new TypeReference<List<UserTablePreferences>>() {
});
return root == null ? new UserTablePreferences() : root.get(0);
}
use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class ExportMenuNGTest method verifyExportExcelAction.
/**
* Verify that the passed event handler exports to Excel either the whole
* table or just the selected rows.
*
* @param eventHandler the handler to test
* @param expectedCopyOnlySelectedRows true if only the selected rows are
* expected to be exported, false otherwise
* @param userCancelsRequest true if the user is meant to cancel the export when
* picking a file in the file chooser
*/
private void verifyExportExcelAction(final EventHandler<ActionEvent> eventHandler, final boolean userCancelsRequest, final boolean expectedExportOnlySelectedRows) throws InterruptedException, PluginException, ExecutionException {
final ExportMenuItemActionHandler exportActionHandler = (ExportMenuItemActionHandler) eventHandler;
final ExportMenuItemActionHandler spiedExportActionHandler = spy(exportActionHandler);
final FileChooserBuilder exportFileChooser = mock(FileChooserBuilder.class);
final File exportFile = userCancelsRequest ? null : new File("test.xlsx");
final Optional<File> optionalExportFile = Optional.ofNullable(exportFile);
doReturn(exportFileChooser).when(spiedExportActionHandler).getExportFileChooser();
try (final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class);
final MockedStatic<FileChooser> fileChooserMockedStatic = Mockito.mockStatic(FileChooser.class);
final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
// This is added so that the mocked static that we would otherwise be
// trying to run in the fx thread is actually invoked properly
platformMockedStatic.when(() -> Platform.runLater(any(Runnable.class))).thenAnswer(iom -> {
((Runnable) iom.getArgument(0)).run();
return null;
});
fileChooserMockedStatic.when(() -> FileChooser.openSaveDialog(exportFileChooser)).thenReturn(CompletableFuture.completedFuture(optionalExportFile));
final ActionEvent actionEvent = mock(ActionEvent.class);
final Pagination pagination = mock(Pagination.class);
final TableView<ObservableList<String>> tableView = mock(TableView.class);
final int maxRowsPerPage = 42;
final UserTablePreferences userTablePreferences = new UserTablePreferences();
userTablePreferences.setMaxRowsPerPage(maxRowsPerPage);
when(activeTableReference.getPagination()).thenReturn(pagination);
when(table.getTableView()).thenReturn(tableView);
when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
final PluginExecution pluginExecution = mock(PluginExecution.class);
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(Plugin.class))).thenAnswer(mockitoInvocation -> {
final ExportToExcelFilePlugin plugin = (ExportToExcelFilePlugin) mockitoInvocation.getArgument(0);
if (exportFile != null) {
assertEquals(exportFile.getAbsolutePath(), plugin.getFile().getAbsolutePath());
} else {
assertEquals(exportFile, plugin.getFile());
}
assertEquals(pagination, plugin.getPagination());
assertEquals(tableView, plugin.getTable());
assertEquals(42, plugin.getRowsPerPage());
assertEquals(GRAPH_ID, plugin.getSheetName());
assertEquals(expectedExportOnlySelectedRows, plugin.isSelectedOnly());
return pluginExecution;
});
spiedExportActionHandler.handle(actionEvent);
// Wait for the export job to complete
spiedExportActionHandler.getLastExport().get();
fileChooserMockedStatic.verify(() -> FileChooser.openSaveDialog(exportFileChooser));
if (userCancelsRequest) {
verifyNoInteractions(pluginExecution);
} else {
verify(pluginExecution).executeNow((Graph) null);
}
verify(actionEvent).consume();
}
}
use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class PreferenceMenuNGTest method verifyPageSizeAction.
/**
* Verifies that when a page size menu item is clicked, the preferences will
* be updated as well as the pagination and the table will be refreshed. If
* the page size that was clicked is the current page size, then no actions
* should be taken.
*
* @param pageSizeMenuItem a page size menu item
* @param pageSize the page size that the menu item will trigger
* @throws InterruptedException if there is a an issue waiting for the
* JavaFX thread work to complete
*/
private void verifyPageSizeAction(final MenuItem pageSizeMenuItem, final int pageSize) throws InterruptedException {
clearInvocations(activeTableReference, tablePane);
final ActionEvent actionEvent = mock(ActionEvent.class);
final Pagination pagination = mock(Pagination.class);
final UserTablePreferences userTablePreferences = new UserTablePreferences();
userTablePreferences.setMaxRowsPerPage(42);
when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
when(activeTableReference.getPagination()).thenReturn(pagination);
pageSizeMenuItem.getOnAction().handle(actionEvent);
pageSizeMenuItem.getOnAction().handle(actionEvent);
final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(() -> latch.countDown());
latch.await();
// The action was called twice but the update should only happen once as
// it was the same page size. No change for the second action
assertEquals(pageSize, userTablePreferences.getMaxRowsPerPage());
verify(activeTableReference).updatePagination(pageSize, tablePane);
}
Aggregations