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);
}
}
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);
}
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++;
}
}
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);
}
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;
}
}
}
}
}
}
Aggregations