Search in sources :

Example 16 with Tuple

use of au.gov.asd.tac.constellation.utilities.datastructure.Tuple in project constellation by constellation-app.

the class PreferencesMenu method loadPreferences.

/**
 * Loads a saved table preferences JSON file and updates the table format
 * (displayed column/column order and sort order) to match the values found.
 * <p/>
 * This method will place a lock on the table to prevent any updates to the
 * preferences whilst this load is happening.
 * <p/>
 * This method will start work on the JavaFX thread to update certain parts
 * of the table like column visibility. Once the method returns it is
 * recommended that the current thread waits for that work to complete
 * before initiating any other actions.
 */
protected void loadPreferences() {
    synchronized (TABLE_LOCK) {
        if (getTableViewTopComponent().getCurrentState() != null) {
            // Load the local table preferences JSON file
            final UserTablePreferences tablePrefs = TableViewPreferencesIoProvider.getPreferences(getTableViewTopComponent().getCurrentState().getElementType());
            // cannot occur with 0 columns
            if (tablePrefs == null || CollectionUtils.isEmpty(tablePrefs.getColumnOrder())) {
                return;
            }
            final List<TableColumn<ObservableList<String>, ?>> newColumnOrder = new ArrayList<>();
            // Loop through column names in the loaded preferences and add the
            // associated columns to newColumnOrder (if found). Also set the
            // found columns to visible.
            tablePrefs.getColumnOrder().forEach(columnName -> getTable().getTableView().getColumns().stream().filter(column -> column.getText().equals(columnName)).forEachOrdered(column -> {
                column.setVisible(true);
                newColumnOrder.add(column);
            }));
            // Populate orderedColumns with entries from column index that match
            // the names of the columns in the loaded preferences.
            final List<Tuple<String, Attribute>> orderedColumns = newColumnOrder.stream().map(tableColumn -> {
                for (final Column column : getTable().getColumnIndex()) {
                    if (tableColumn.getText().equals(column.getTableColumn().getText())) {
                        return column;
                    }
                }
                // column specified in the preferences
                return null;
            }).filter(Objects::nonNull).map(column -> Tuple.create(column.getAttributeNamePrefix(), column.getAttribute())).collect(Collectors.toList());
            // Update the sort preferences
            getActiveTableReference().saveSortDetails(tablePrefs.getSortColumn(), tablePrefs.getSortDirection());
            try {
                // Update the visibile columns and wait for the state plugin to complete its update
                getActiveTableReference().updateVisibleColumns(getTableViewTopComponent().getCurrentGraph(), getTableViewTopComponent().getCurrentState(), orderedColumns, UpdateMethod.REPLACE).get(1000, TimeUnit.MILLISECONDS);
            } catch (final InterruptedException ex) {
                LOGGER.log(Level.WARNING, "Update state plugin was interrupted");
                Thread.currentThread().interrupt();
            } catch (final TimeoutException | ExecutionException ex) {
                LOGGER.log(Level.WARNING, "Update state plugin failed to complete within the alloted time", ex);
            }
            // Update the page size menu selection and page size preferences
            for (final Toggle t : getPageSizeToggle().getToggles()) {
                final RadioMenuItem pageSizeOption = (RadioMenuItem) t;
                if (Integer.parseInt(pageSizeOption.getText()) == tablePrefs.getMaxRowsPerPage()) {
                    pageSizeOption.setSelected(true);
                    getActiveTableReference().getUserTablePreferences().setMaxRowsPerPage(tablePrefs.getMaxRowsPerPage());
                    break;
                }
            }
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) EventHandler(javafx.event.EventHandler) RadioMenuItem(javafx.scene.control.RadioMenuItem) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) UpdateMethod(au.gov.asd.tac.constellation.views.tableview.api.UpdateMethod) TimeoutException(java.util.concurrent.TimeoutException) ActiveTableReference(au.gov.asd.tac.constellation.views.tableview.api.ActiveTableReference) TableViewPreferencesIoProvider(au.gov.asd.tac.constellation.views.tableview.io.TableViewPreferencesIoProvider) Side(javafx.geometry.Side) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) Attribute(au.gov.asd.tac.constellation.graph.Attribute) UserInterfaceIconProvider(au.gov.asd.tac.constellation.utilities.icon.UserInterfaceIconProvider) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) TableViewTopComponent(au.gov.asd.tac.constellation.views.tableview.TableViewTopComponent) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) MenuItem(javafx.scene.control.MenuItem) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Menu(javafx.scene.control.Menu) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ActionEvent(javafx.event.ActionEvent) ToggleGroup(javafx.scene.control.ToggleGroup) ImageView(javafx.scene.image.ImageView) MenuButton(javafx.scene.control.MenuButton) TABLE_LOCK(au.gov.asd.tac.constellation.views.tableview.TableViewTopComponent.TABLE_LOCK) Toggle(javafx.scene.control.Toggle) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) RadioMenuItem(javafx.scene.control.RadioMenuItem) TableColumn(javafx.scene.control.TableColumn) UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) TableColumn(javafx.scene.control.TableColumn) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) Toggle(javafx.scene.control.Toggle) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) TimeoutException(java.util.concurrent.TimeoutException)

Example 17 with Tuple

use of au.gov.asd.tac.constellation.utilities.datastructure.Tuple in project constellation by constellation-app.

the class ActiveTableReferenceNGTest method updateVisibleColumnsAdd.

@Test
public void updateVisibleColumnsAdd() {
    try (MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
        final Graph graph = mock(Graph.class);
        final Attribute attribute = mock(Attribute.class);
        final PluginExecution pluginExecution = mock(PluginExecution.class);
        final List<Tuple<String, Attribute>> paramColumnAttributes = List.of(Tuple.create("paramAttr", attribute));
        final List<Tuple<String, Attribute>> stateColumnAttributes = List.of(Tuple.create("stateAttr", attribute), Tuple.create("paramAttr", attribute));
        final TableViewState tableViewState = new TableViewState();
        tableViewState.setColumnAttributes(stateColumnAttributes);
        pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(Plugin.class))).thenAnswer(executeUpdateStatePlugin(pluginExecution, tableViewState, List.of(Tuple.create("stateAttr", attribute), Tuple.create("paramAttr", attribute), Tuple.create("paramAttr", attribute))));
        activeTableReference.updateVisibleColumns(graph, tableViewState, paramColumnAttributes, UpdateMethod.ADD);
        verify(pluginExecution).executeLater(graph);
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) Graph(au.gov.asd.tac.constellation.graph.Graph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) Test(org.testng.annotations.Test)

Example 18 with Tuple

use of au.gov.asd.tac.constellation.utilities.datastructure.Tuple in project constellation by constellation-app.

the class ActiveTableReferenceNGTest method updateVisibleColumnsReplace.

@Test
public void updateVisibleColumnsReplace() {
    try (MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
        final Graph graph = mock(Graph.class);
        final Attribute attribute = mock(Attribute.class);
        final PluginExecution pluginExecution = mock(PluginExecution.class);
        final List<Tuple<String, Attribute>> paramColumnAttributes = List.of(Tuple.create("paramAttr", attribute));
        final List<Tuple<String, Attribute>> stateColumnAttributes = List.of(Tuple.create("stateAttr1", attribute), Tuple.create("stateAttr2", attribute));
        final TableViewState tableViewState = new TableViewState();
        tableViewState.setColumnAttributes(stateColumnAttributes);
        pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(Plugin.class))).thenAnswer(executeUpdateStatePlugin(pluginExecution, tableViewState, List.of(Tuple.create("paramAttr", attribute))));
        activeTableReference.updateVisibleColumns(graph, tableViewState, paramColumnAttributes, UpdateMethod.REPLACE);
        verify(pluginExecution).executeLater(graph);
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) Graph(au.gov.asd.tac.constellation.graph.Graph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) Test(org.testng.annotations.Test)

Aggregations

Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)18 ArrayList (java.util.ArrayList)7 Attribute (au.gov.asd.tac.constellation.graph.Attribute)6 Graph (au.gov.asd.tac.constellation.graph.Graph)6 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)5 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)5 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)4 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)4 UpdateStatePlugin (au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 AttributeValueMonitor (au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor)3 GraphElement (au.gov.asd.tac.constellation.views.mapview.utilities.GraphElement)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)2 AttributeCountMonitor (au.gov.asd.tac.constellation.graph.monitor.AttributeCountMonitor)2 GlobalMonitor (au.gov.asd.tac.constellation.graph.monitor.GlobalMonitor)2 StructureMonitor (au.gov.asd.tac.constellation.graph.monitor.StructureMonitor)2