Search in sources :

Example 6 with AdvancedCriteriaBorderPane

use of au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane in project constellation by constellation-app.

the class AdvancedFindTabNGTest method testFindNextAction.

/**
 * Test of findNextAction method, of class AdvancedFindTab.
 */
@Test
public void testFindNextAction() {
    System.out.println("findNextAction");
    setupGraph();
    // Create a controller mock and do nothing on retriveMatchingElements()
    FindViewController mockController = mock(FindViewController.class);
    mockController.init(spyTopComponent);
    doNothing().when(mockController).retrieveAdvancedSearch(Mockito.eq(false), Mockito.eq(true));
    GraphElementType graphElementType = GraphElementType.VERTEX;
    /**
     * Create temporary advancedFindMock, pane, criteriaPaneList,
     * LookForChoiceBox, findCriteriaValuesList and a stringCriteriaValue
     */
    AdvancedFindTab advancedFindMock = mock(AdvancedFindTab.class);
    StringCriteriaPanel tempPane = new StringCriteriaPanel(advancedTab, "Identifer", graphElementType);
    tempPane.setSearchFieldText("hello");
    final List<AdvancedCriteriaBorderPane> criteriaPaneList = new ArrayList<>();
    criteriaPaneList.add(tempPane);
    final ChoiceBox<String> lookForChoiceBox = new ChoiceBox<>();
    lookForChoiceBox.getItems().add("Node");
    lookForChoiceBox.getSelectionModel().select(0);
    final List<FindCriteriaValues> findCriteriaValues = new ArrayList<>();
    final StringCriteriaValues stringCriteriaValue = new StringCriteriaValues("string", "Identifer", "Is", "hello", false, false);
    findCriteriaValues.add(stringCriteriaValue);
    // When each function is called return the temporarily created elements above
    when(advancedFindMock.getCorrespondingCriteriaList(graphElementType)).thenReturn(criteriaPaneList);
    when(advancedFindMock.getCriteriaValues(criteriaPaneList)).thenReturn(findCriteriaValues);
    when(advancedFindMock.getLookForChoiceBox()).thenReturn(lookForChoiceBox);
    // Do real call on findAllAction
    doCallRealMethod().when(advancedFindMock).findNextAction();
    // Do nothing on updateAdvancedSearchParameters()
    doNothing().when(advancedFindMock).updateAdvancedSearchParameters(graphElementType);
    /**
     * Create a static mock of the FindViewController. Call the
     * findNextAction() then verify that updateAdvancedSearchParameters and
     * retrieveAdvancedSearch were all called once.
     */
    try (MockedStatic<FindViewController> mockedStatic = Mockito.mockStatic(FindViewController.class)) {
        mockedStatic.when(() -> FindViewController.getDefault()).thenReturn(mockController);
        advancedFindMock.findNextAction();
        verify(advancedFindMock, times(1)).updateAdvancedSearchParameters(graphElementType);
        verify(mockController, times(1)).retrieveAdvancedSearch(false, true);
    }
}
Also used : ArrayList(java.util.ArrayList) StringCriteriaPanel(au.gov.asd.tac.constellation.views.find2.components.advanced.StringCriteriaPanel) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) AdvancedCriteriaBorderPane(au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane) StringCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues) ChoiceBox(javafx.scene.control.ChoiceBox) FindCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues) FindViewController(au.gov.asd.tac.constellation.views.find2.FindViewController) Test(org.testng.annotations.Test)

Example 7 with AdvancedCriteriaBorderPane

use of au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane in project constellation by constellation-app.

the class FloatCriteriaPanelNGTest method testGetCriteriaValues.

/**
 * Test of getCriteriaValues method, of class FloatCriteriaPanel.
 */
@Test
public void testGetCriteriaValues() {
    System.out.println("getCriteriaValues");
    setupGraph();
    AdvancedFindTab parentComponent = spy(advancedTab);
    final GraphElementType type = GraphElementType.VERTEX;
    FloatCriteriaPanel floatCriteriaPanel = new FloatCriteriaPanel(parentComponent, "x", type);
    floatCriteriaPanel.getFilterChoiceBox().getSelectionModel().select("Is Between");
    floatCriteriaPanel.getSearchField().setText("22");
    floatCriteriaPanel.getSearchFieldTwo().setText("44");
    final List<AdvancedCriteriaBorderPane> tempList = new ArrayList<>();
    final GridPane tempGrid = new GridPane();
    tempList.add(floatCriteriaPanel);
    tempGrid.add(tempList.get(0), 0, 0);
    when(parentComponent.getCorrespondingCriteriaList(Mockito.eq(type))).thenReturn(tempList);
    when(parentComponent.getCorrespondingGridPane(Mockito.eq(type))).thenReturn(tempGrid);
    final List<AdvancedCriteriaBorderPane> criteriaList = parentComponent.getCorrespondingCriteriaList(type);
    final FindCriteriaValues result = criteriaList.get(0).getCriteriaValues();
    final FloatCriteriaValues floatResult = (FloatCriteriaValues) result;
    assertEquals(floatResult.getAttribute(), "x");
    assertEquals(floatResult.getAttributeType(), "float");
    assertEquals(floatResult.getFilter(), "Is Between");
    assertEquals(floatResult.getFloatValuePrimary(), 22f);
    assertEquals(floatResult.getFloatValueSecondary(), 44f);
}
Also used : FindCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues) GridPane(javafx.scene.layout.GridPane) AdvancedFindTab(au.gov.asd.tac.constellation.views.find2.components.AdvancedFindTab) ArrayList(java.util.ArrayList) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) FloatCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FloatCriteriaValues) Test(org.testng.annotations.Test)

Example 8 with AdvancedCriteriaBorderPane

use of au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane in project constellation by constellation-app.

the class AdvancedFindTab method updateGridColours.

/**
 * Updates the grid colors to cycle between #4d4d4d and #222222. This
 * ensures every odd advancedCriteriaBorderPane is #4d4d4d and every even is
 * #222222
 *
 * @param type
 */
private void updateGridColours(final GraphElementType type) {
    int i = 0;
    final List<AdvancedCriteriaBorderPane> criteriaList = getCorrespondingCriteriaList(type);
    for (final AdvancedCriteriaBorderPane criteriaPane : criteriaList) {
        criteriaPane.setStyle(i % 2 == 0 ? "-fx-background-color: #4d4d4d;" : "-fx-background-color: #222222;");
        i++;
    }
}
Also used : AdvancedCriteriaBorderPane(au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane)

Example 9 with AdvancedCriteriaBorderPane

use of au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane in project constellation by constellation-app.

the class AdvancedFindTab method deleteCriteriaPane.

/**
 * This removes the advanced criteriaborderpane from both the UI list and
 * the background list.
 *
 * @param pane
 * @param type
 */
public void deleteCriteriaPane(final AdvancedCriteriaBorderPane pane, final GraphElementType type, final int index) {
    // Retrieve the corresponding criteria list and grid pane for the type
    final List<AdvancedCriteriaBorderPane> criteriaList = getCorrespondingCriteriaList(type);
    final GridPane gridPane = getCorrespondingGridPane(type);
    // clear everything
    criteriaList.remove(pane);
    gridPane.getChildren().remove(pane);
    gridPane.getChildren().removeAll(gridPane.getChildren());
    // re add all criteriapanes with the one at the specified index removed
    int i = 0;
    for (final AdvancedCriteriaBorderPane cirteriaPane : criteriaList) {
        if (i == index) {
            i++;
        }
        gridPane.add(cirteriaPane, 0, i);
        i++;
    }
    // update the grid colours to match the new list order
    updateGridColours(type);
}
Also used : GridPane(javafx.scene.layout.GridPane) AdvancedCriteriaBorderPane(au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane)

Example 10 with AdvancedCriteriaBorderPane

use of au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane in project constellation by constellation-app.

the class AdvancedFindTab method changeCriteriaPane.

/**
 * This is called when the user changes the selected attribute type of a
 * specific criteria pane. For example if the user changes the attribute
 * from "Label" to "Color".
 *
 * @param criteriaPane
 * @param type
 * @param attributeName
 */
public void changeCriteriaPane(final AdvancedCriteriaBorderPane criteriaPane, final GraphElementType type, final String attributeName, final boolean updateUI) {
    if (!updateUI) {
        final List<AdvancedCriteriaBorderPane> criteriaList = getCorrespondingCriteriaList(type);
        final GridPane gridPane = getCorrespondingGridPane(type);
        // For each of the panes in the criteriaList.
        for (final AdvancedCriteriaBorderPane pane : criteriaList) {
            // list of attributes it contains.
            if (criteriaPane == pane) {
                final int paneIndex = criteriaList.indexOf(pane);
                final List<Attribute> attributeList = new ArrayList<>(pane.getAttributesList());
                // delete the pane
                deleteCriteriaPane(pane, type, paneIndex);
                // for each of the attributes within the attribute list
                for (final Attribute a : attributeList) {
                    // if the new attribute requested == a.getName
                    if (attributeName == a.getName()) {
                        // Add a new CriteriaPane of the attributType passed
                        // at the index the pane was originaly on.
                        // Select the attributeName of the type passed
                        criteriaList.add(paneIndex, getNewCriteriaPanel(a.getAttributeType(), attributeName, type));
                        gridPane.add(criteriaList.get(paneIndex), 0, paneIndex);
                        pane.getTypeChoiceBox().getSelectionModel().select(attributeName);
                        GridPane.setHgrow(criteriaList.get(paneIndex), Priority.ALWAYS);
                        // update the colours of the list to match
                        updateGridColours(type);
                        return;
                    }
                }
            }
        }
    }
}
Also used : GridPane(javafx.scene.layout.GridPane) Attribute(au.gov.asd.tac.constellation.graph.Attribute) ArrayList(java.util.ArrayList) AdvancedCriteriaBorderPane(au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane)

Aggregations

AdvancedCriteriaBorderPane (au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane)10 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)9 ArrayList (java.util.ArrayList)9 FindCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues)8 GridPane (javafx.scene.layout.GridPane)8 Test (org.testng.annotations.Test)8 StringCriteriaPanel (au.gov.asd.tac.constellation.views.find2.components.advanced.StringCriteriaPanel)5 AdvancedFindTab (au.gov.asd.tac.constellation.views.find2.components.AdvancedFindTab)4 StringCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues)4 FindViewController (au.gov.asd.tac.constellation.views.find2.FindViewController)3 ChoiceBox (javafx.scene.control.ChoiceBox)3 Attribute (au.gov.asd.tac.constellation.graph.Attribute)1 BooleanCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.BooleanCriteriaValues)1 ColourCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.ColourCriteriaValues)1 FloatCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FloatCriteriaValues)1