Search in sources :

Example 1 with FindResultsList

use of au.gov.asd.tac.constellation.views.find2.utilities.FindResultsList in project constellation by constellation-app.

the class BasicFindPlugin method selectFindInResults.

/**
 * Completes the steps required to select the FindResults within the
 * findInCurrentSelectionList. Its split into a separate function to reduce
 * cognitive complexity of the edit function.
 *
 * @param findInCurrentSelection
 * @param findInCurrentSelectionList
 * @param foundResult
 * @param graph
 * @param selectedAttribute
 */
private void selectFindInResults(final boolean findInCurrentSelection, final FindResultsList findInCurrentSelectionList, final FindResultsList foundResult, final GraphWriteMethods graph, final int selectedAttribute) {
    if (findInCurrentSelection && !findInCurrentSelectionList.isEmpty()) {
        clearSelection(graph);
        for (final FindResult fr : findInCurrentSelectionList) {
            graph.setBooleanValue(selectedAttribute, fr.getID(), true);
        }
        foundResult.clear();
        foundResult.addAll(findInCurrentSelectionList);
    }
}
Also used : FindResult(au.gov.asd.tac.constellation.views.find2.utilities.FindResult)

Example 2 with FindResultsList

use of au.gov.asd.tac.constellation.views.find2.utilities.FindResultsList in project constellation by constellation-app.

the class ResetStatePlugin method edit.

/**
 * This edit function retrieves the FindViewConcept MetaAttribute
 * (FindResultsList) and resets the current index back to -1 as the graph
 * element count has changed.
 *
 * @param graph
 * @param interaction
 * @param parameters
 * @throws InterruptedException
 * @throws PluginException
 */
@Override
protected void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final int stateId = FindViewConcept.MetaAttribute.FINDVIEW_STATE.ensure(graph);
    FindResultsList foundResult = graph.getObjectValue(stateId, 0);
    if (foundResult != null) {
        foundResult.setCurrentIndex(STARTING_INDEX);
        graph.setObjectValue(stateId, 0, foundResult);
    }
}
Also used : FindResultsList(au.gov.asd.tac.constellation.views.find2.utilities.FindResultsList)

Example 3 with FindResultsList

use of au.gov.asd.tac.constellation.views.find2.utilities.FindResultsList in project constellation by constellation-app.

the class AdvancedSearchPlugin method selectMatchingAllResults.

/**
 * This is called when the user clicks select all and they are wanted to the
 * search to match all their criteria.
 *
 * @param findAllMatching allOrAny.equals("All")
 * @param findAllMatchingResultsList a list of all matching results
 * @param foundResult the foundResult list
 * @param graph the current graph
 * @param selectedAttribute the selectedAttribute
 */
private void selectMatchingAllResults(final boolean findAllMatching, final FindResultsList findAllMatchingResultsList, final FindResultsList foundResult, final GraphWriteMethods graph, final int selectedAttribute) {
    // if match criteria == all and the results list isnt empty
    if (findAllMatching && !findAllMatchingResultsList.isEmpty()) {
        // if not adding to the current selection, clear the selection
        if (!ADD_TO.equals(currentSelection)) {
            clearSelection(graph);
        }
        // if select all, loop through all find results and select them
        if (selectAll) {
            for (final FindResult fr : findAllMatchingResultsList) {
                graph.setBooleanValue(selectedAttribute, fr.getID(), true);
            }
        }
        // clear the found result and add the findAllmatching results to it
        foundResult.clear();
        foundResult.addAll(findAllMatchingResultsList);
    }
}
Also used : FindResult(au.gov.asd.tac.constellation.views.find2.utilities.FindResult)

Example 4 with FindResultsList

use of au.gov.asd.tac.constellation.views.find2.utilities.FindResultsList in project constellation by constellation-app.

the class AdvancedSearchPlugin method selectFindInResults.

/**
 * This is called when the user wanted to find the results in their current
 * selection.
 *
 * @param findInCurrentSelection
 * @param findInCurrentSelectionList
 * @param foundResult
 * @param graph
 * @param selectedAttribute
 */
private void selectFindInResults(final boolean findInCurrentSelection, final FindResultsList findInCurrentSelectionList, final FindResultsList foundResult, final GraphWriteMethods graph, final int selectedAttribute) {
    // if currenet selection = find in and the list isnt empty
    if (findInCurrentSelection && !findInCurrentSelectionList.isEmpty()) {
        // clear the seleection
        clearSelection(graph);
        // loop through the list selecting all find results
        for (final FindResult fr : findInCurrentSelectionList) {
            graph.setBooleanValue(selectedAttribute, fr.getID(), true);
        }
        // clear the foundResult and add the findIncurrentSelection list to it
        foundResult.clear();
        foundResult.addAll(findInCurrentSelectionList);
    }
}
Also used : FindResult(au.gov.asd.tac.constellation.views.find2.utilities.FindResult)

Example 5 with FindResultsList

use of au.gov.asd.tac.constellation.views.find2.utilities.FindResultsList in project constellation by constellation-app.

the class AdvancedSearchPlugin method edit.

@Override
protected void edit(GraphWriteMethods graph, PluginInteraction interaction, PluginParameters parameters) throws InterruptedException, PluginException {
    // Retrieve the existing FindResultList Meta attribute
    final int stateId = FindViewConcept.MetaAttribute.FINDVIEW_STATE.ensure(graph);
    FindResultsList foundResult = graph.getObjectValue(stateId, 0);
    /**
     * If it doesn't exist or is null, create a new list with the starting
     * index and the current find parameters. If it does exist, create a
     * list with the correct index and the current find parameters
     */
    if (foundResult == null) {
        foundResult = new FindResultsList(STARTING_INDEX, this.parameters, graph.getId());
    } else {
        /**
         * This is delicate, so don't change. This process, captures the
         * users previous search and their current search, compares the 2 to
         * see if they are the same. If yes then get the previous index of
         * the last foundResult. If its different reset the index. The
         * parameters are instantiated as new variables as there were
         * manipulation issues elsewhere causing this process to fail.
         */
        final FindResultsList oldList = new FindResultsList(STARTING_INDEX, foundResult.getAdvancedSearchParameters(), foundResult.getGraphId());
        final AdvancedSearchParameters oldparameters = oldList.getAdvancedSearchParameters();
        final AdvancedSearchParameters newParamters = new AdvancedSearchParameters(this.parameters);
        final int newIndex = getIndex(newParamters, oldparameters, foundResult.getCurrentIndex());
        foundResult = new FindResultsList(newIndex, newParamters, oldList.getGraphId());
    }
    foundResult.clear();
    graph.setObjectValue(stateId, 0, foundResult);
    final int elementCount = elementType.getElementCount(graph);
    // do this if add to selection
    if (IGNORE.equals(currentSelection)) {
        clearSelection(graph);
    }
    findInCurrentSelectionList = new FindResultsList(graph.getId());
    final FindResultsList findAllMatchingResultsList = new FindResultsList(graph.getId());
    final int selectedAttribute = graph.getAttribute(elementType, VisualConcept.VertexAttribute.SELECTED.getName());
    final Set<FindResult> findResultSet = new HashSet<>();
    /**
     * This loops through all existing graph elements, then loops through
     * all criteria values, then determines what data type the criteria
     * value corresponds to and proceeds the search based on that data type.
     *
     * For example if the data type of the criteria value was a string, it
     * would continue the search as if the graph element attribute in
     * question is a string
     */
    for (int i = 0; i < elementCount; i++) {
        // tracking number to see if a elements value matches all of the
        // users input critera
        int matchesAllCount = 0;
        // get the current element and its unique id
        final int currElement = elementType.getElement(graph, i);
        final long uid = elementType.getUID(graph, currElement);
        // loop through all of the criteriaValues
        for (final FindCriteriaValues values : criteriaList) {
            // get the int value of the current attribute
            int attributeInt = graph.getAttribute(elementType, values.getAttribute());
            // if the attribute int is greater than 0 it exists on this graph
            if (attributeInt >= 0) {
                /**
                 * matches will change to false if the attributes value
                 * matches the given critera.
                 */
                boolean matches = false;
                // Determine what data type to treat the search as
                switch(values.getAttributeType()) {
                    case StringAttributeDescription.ATTRIBUTE_NAME:
                        matches = searchAsString(values, attributeInt, currElement, graph);
                        break;
                    case FloatAttributeDescription.ATTRIBUTE_NAME:
                        matches = searchAsFloat(values, attributeInt, currElement, graph);
                        break;
                    case BooleanAttributeDescription.ATTRIBUTE_NAME:
                        matches = searchAsBoolean(values, attributeInt, currElement, graph);
                        break;
                    case ColorAttributeDescription.ATTRIBUTE_NAME:
                        matches = searchAsColor(values, attributeInt, currElement, graph);
                        break;
                    case ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME:
                        matches = searchAsDateTime(values, attributeInt, currElement, graph);
                        break;
                    case IconAttributeDescription.ATTRIBUTE_NAME:
                        matches = searchAsIcon(values, attributeInt, currElement, graph);
                        break;
                    default:
                        break;
                }
                // if a match was found
                if (matches) {
                    // increase the matchesAllCount by 1
                    matchesAllCount++;
                    // If the serach is select all and match critera = any
                    if (selectAll && ANY.equals(allOrAny)) {
                        // If the current selection = ignore or add to
                        if ((IGNORE.equals(currentSelection) || ADD_TO.equals(currentSelection))) {
                            // set the elements selection attribute to true
                            graph.setBooleanValue(selectedAttribute, currElement, true);
                            // add a new find result to the found results list
                            // of the element
                            foundResult.add(new FindResult(currElement, uid, elementType));
                        // if the current selection = find in and the graph element is already selected
                        } else if (FIND_IN.equals(currentSelection) && graph.getBooleanValue(selectedAttribute, currElement)) {
                            // add a new FindResult of the graph element to the findInCurrentSelection list
                            findInCurrentSelectionList.add(new FindResult(currElement, uid, elementType));
                        // if the current selection = remove from and the graph element is already selected
                        } else if (REMOVE_FROM.equals(currentSelection) && graph.getBooleanValue(selectedAttribute, currElement)) {
                            // set the graph element selection attribute to false
                            graph.setBooleanValue(selectedAttribute, currElement, false);
                            // add a new find result to the found results list
                            // of the element
                            foundResult.add(new FindResult(currElement, uid, elementType));
                        }
                    }
                    // if not select all and the match criteria = any
                    if (!selectAll && ANY.equals(allOrAny)) {
                        // add a new find result to the found results list
                        // of the element
                        foundResult.add(new FindResult(currElement, uid, elementType));
                    }
                }
            }
            /**
             * if match criteria = all and the attributes values match all
             * of the criteria.
             */
            if (allOrAny.equals(ALL) && matchesAllCount == criteriaList.size()) {
                // add a new find result to the found results list
                // of the element
                foundResult.add(new FindResult(currElement, uid, elementType));
                findResultSet.add(new FindResult(currElement, uid, elementType));
                // if the attribute is already selected
                if (graph.getBooleanValue(selectedAttribute, currElement)) {
                    // add it to the find in current selection list
                    findInCurrentSelectionList.add(new FindResult(currElement, uid, elementType));
                }
            }
        }
    }
    findAllMatchingResultsList.addAll(findResultSet);
    // if Find in select all the find in results
    if (FIND_IN.equals(currentSelection)) {
        selectFindInResults(FIND_IN.equals(currentSelection), findInCurrentSelectionList, foundResult, graph, selectedAttribute);
    // if remove from, deselect all the remove from results
    } else if (REMOVE_FROM.equals(currentSelection)) {
        removeFindInResults(REMOVE_FROM.equals(currentSelection), findInCurrentSelectionList, foundResult, graph, selectedAttribute);
    // if select all, select all the results that match all criteria
    } else if (selectAll) {
        selectMatchingAllResults(ALL.equals(allOrAny), findAllMatchingResultsList, foundResult, graph, selectedAttribute);
    }
    // if the user clicked find next or prev
    if (!selectAll) {
        // Clean the find results list to only contain unique graph elements
        final List<FindResult> distinctValues = foundResult.stream().distinct().collect(Collectors.toList());
        foundResult.clear();
        foundResult.addAll(distinctValues);
        /**
         * If the list isn't empty, and the user clicked find next,
         * increment the found lists index by 1, otherwise decrement it by
         * 1. Set the element at the specified index to selected.
         */
        if (!foundResult.isEmpty()) {
            if (selectNext) {
                foundResult.incrementCurrentIndex();
            } else {
                foundResult.decrementCurrentIndex();
            }
            final int elementId = foundResult.get(foundResult.getCurrentIndex()).getID();
            graph.setBooleanValue(selectedAttribute, elementId, true);
        }
        graph.setObjectValue(stateId, 0, foundResult);
    }
    // If no results are found, set the meta attribute to null
    graph.setObjectValue(stateId, 0, foundResult.isEmpty() ? null : foundResult);
}
Also used : FindCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues) AdvancedSearchParameters(au.gov.asd.tac.constellation.views.find2.components.advanced.utilities.AdvancedSearchParameters) FindResultsList(au.gov.asd.tac.constellation.views.find2.utilities.FindResultsList) FindResult(au.gov.asd.tac.constellation.views.find2.utilities.FindResult) HashSet(java.util.HashSet)

Aggregations

FindResult (au.gov.asd.tac.constellation.views.find2.utilities.FindResult)9 FindResultsList (au.gov.asd.tac.constellation.views.find2.utilities.FindResultsList)8 Attribute (au.gov.asd.tac.constellation.graph.Attribute)5 BasicFindReplaceParameters (au.gov.asd.tac.constellation.views.find2.utilities.BasicFindReplaceParameters)5 ArrayList (java.util.ArrayList)3 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)2 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)2 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)2 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)1 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 FindCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues)1 AdvancedSearchParameters (au.gov.asd.tac.constellation.views.find2.components.advanced.utilities.AdvancedSearchParameters)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Test (org.testng.annotations.Test)1