use of au.gov.asd.tac.constellation.views.find2.utilities.FindResultsList in project constellation by constellation-app.
the class BasicFindPlugin method edit.
@Override
protected void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
// 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 they were
* manipulation issues elsewhere causing this process to fail.
*/
final FindResultsList oldList = new FindResultsList(STARTING_INDEX, foundResult.getSearchParameters(), foundResult.getGraphId());
final BasicFindReplaceParameters oldparameters = oldList.getSearchParameters();
final BasicFindReplaceParameters newParamters = new BasicFindReplaceParameters(this.parameters);
int newIndex = getIndex(newParamters, oldparameters, foundResult.getCurrentIndex());
foundResult = new FindResultsList(newIndex, newParamters, oldList.getGraphId());
}
foundResult.clear();
graph.setObjectValue(stateId, 0, foundResult);
if (findString.isEmpty()) {
findString = "^$";
regex = true;
}
boolean found;
final int selectedAttribute = graph.getAttribute(elementType, VisualConcept.VertexAttribute.SELECTED.getName());
final int elementCount = elementType.getElementCount(graph);
// do this if add to selection
if (!addToSelection && !removeFromCurrentSelection && !findInCurrentSelection) {
clearSelection(graph);
}
final FindResultsList findInCurrentSelectionList = new FindResultsList(graph.getId());
final FindResultsList removeFromCurrentSelectionList = new FindResultsList(graph.getId());
final String searchString = regex ? findString : Pattern.quote(findString);
final int caseSensitivity = ignorecase ? Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE : 0;
final Pattern searchPattern = Pattern.compile(searchString, caseSensitivity);
/**
* Loop through all selected attributes, get the current element of the
* selected type and its value, check the value isn't null, then compare
* the value with the find string based on the search preferences. If
* that element matches the search criteria, change its selected value
* to true if selecting all. Otherwise create a FindResult and add that
* find result to the foundResults list
*/
for (final Attribute a : selectedAttributes) {
// if the attribute exists on the current graph
if (graph.getAttribute(elementType, a.getName()) >= 0) {
// for all elements on the graph of the given type
for (int i = 0; i < elementCount; i++) {
// get the current element
final int currElement = elementType.getElement(graph, i);
// get string value of it graph elements attribute
final String value = graph.getStringValue(graph.getAttribute(elementType, a.getName()), currElement);
// if the value isnt null
if (value != null) {
// Determine if the find string matches the attribute
// string
Matcher match = searchPattern.matcher(value);
found = matchWholeWord ? match.matches() : match.find();
if (found) {
// get the UID of the element and the graph
final long uid = elementType.getUID(graph, currElement);
// their current selection
if (findInCurrentSelection || removeFromCurrentSelection) {
// if the element is selected
if (graph.getBooleanValue(selectedAttribute, currElement)) {
// Add the element to the find in and
// remove from list
findInCurrentSelectionList.add(new FindResult(currElement, uid, elementType));
removeFromCurrentSelectionList.add(new FindResult(currElement, uid, elementType));
}
}
// matching element
if (selectAll && !findInCurrentSelection && !removeFromCurrentSelection) {
graph.setBooleanValue(selectedAttribute, currElement, true);
}
// add the graph element to the foundResult list
foundResult.add(new FindResult(currElement, uid, elementType));
}
}
}
}
}
/**
* If findIncurrentSelection is true, clear the current selection and
* loop through the list of found elements and set them to selected.
*/
selectFindInResults(findInCurrentSelection, findInCurrentSelectionList, foundResult, graph, selectedAttribute);
/**
* If removeFromCurrentlySelection is true, loop through the list of
* found elements and set their selection status to false.
*/
selectRemoveFromResults(removeFromCurrentSelection, removeFromCurrentSelectionList, foundResult, graph, selectedAttribute);
/**
* If the user clicked find next or find previous
*/
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 (getNext) {
foundResult.incrementCurrentIndex();
} else {
foundResult.decrementCurrentIndex();
}
final int elementId = foundResult.get(foundResult.getCurrentIndex()).getID();
graph.setBooleanValue(selectedAttribute, elementId, !removeFromCurrentSelection);
}
graph.setObjectValue(stateId, 0, foundResult);
}
// If no results are found, set the meta attribute to null
graph.setObjectValue(stateId, 0, foundResult.isEmpty() ? null : foundResult);
}
use of au.gov.asd.tac.constellation.views.find2.utilities.FindResultsList in project constellation by constellation-app.
the class BasicFindPlugin method selectRemoveFromResults.
/**
* Completes the steps required to deselected the FindResults within the
* removeFromCurrentSelectionList. Its split into a separate function to
* reduce cognitive complexity of the edit function.
*
* @param removeFromCurrentSelection
* @param removeFromCurrentSelectionList
* @param foundResult
* @param graph
* @param selectedAttribute
*/
private void selectRemoveFromResults(final boolean removeFromCurrentSelection, final FindResultsList removeFromCurrentSelectionList, final FindResultsList foundResult, final GraphWriteMethods graph, final int selectedAttribute) {
if (removeFromCurrentSelection && !removeFromCurrentSelectionList.isEmpty()) {
for (final FindResult fr : removeFromCurrentSelectionList) {
graph.setBooleanValue(selectedAttribute, fr.getID(), false);
if (getNext) {
foundResult.clear();
foundResult.addAll(removeFromCurrentSelectionList);
break;
}
}
foundResult.clear();
foundResult.addAll(removeFromCurrentSelectionList);
}
}
use of au.gov.asd.tac.constellation.views.find2.utilities.FindResultsList in project constellation by constellation-app.
the class AdvancedSearchPlugin method removeFindInResults.
/**
* This is called when the user wanted to remove the results from their
* current selection.
*
* @param findInCurrentSelection
* @param findInCurrentSelectionList
* @param foundResult
* @param graph
* @param selectedAttribute
*/
private void removeFindInResults(final boolean findInCurrentSelection, final FindResultsList removeFromCurrentSelectionList, final FindResultsList foundResult, final GraphWriteMethods graph, final int selectedAttribute) {
if (findInCurrentSelection && !removeFromCurrentSelectionList.isEmpty()) {
// loop through all results and de select them
for (final FindResult fr : removeFromCurrentSelectionList) {
graph.setBooleanValue(selectedAttribute, fr.getID(), false);
}
// clear the foundResult and add the findIncurrentSelection list to it
foundResult.clear();
foundResult.addAll(removeFromCurrentSelectionList);
}
}
Aggregations