use of au.gov.asd.tac.constellation.views.find2.utilities.FindResult in project constellation by constellation-app.
the class FindViewStateIoProvider method readObject.
@Override
public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods writableGraph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, final ImmutableObjectCache cache) throws IOException {
if (!jnode.isNull()) {
// Get the findResultsList variables
final int currentIndex = jnode.get("currentIndex").asInt();
final String graphID = jnode.get("graphID").asText();
// Get the basic find replace parameters
final String findString = jnode.get("findString").asText();
final String replaceString = jnode.get("replaceString").asText();
final String graphElementString = jnode.get("graphElement").asText();
final GraphElementType graphElement = GraphElementType.getValue(graphElementString);
final Boolean standardText = jnode.get("standardText").asBoolean();
final Boolean regEx = jnode.get("regEx").asBoolean();
final Boolean ignoreCase = jnode.get("ignoreCase").asBoolean();
final Boolean exactMatch = jnode.get("exactMatch").asBoolean();
final Boolean findInSelection = jnode.get("findInSelection").asBoolean();
final Boolean addToSelection = jnode.get("addToSelection").asBoolean();
final Boolean removeFromSelection = jnode.get("removeFromSelection").asBoolean();
final Boolean replaceInSelected = jnode.get("replaceInSelected").asBoolean();
final Boolean searchAllGraphs = jnode.get("searchAllGraphs").asBoolean();
// Get the selected attributes
final List<Attribute> selectedAttributes = new ArrayList<>();
final ArrayNode selectedAttributesArray = (ArrayNode) jnode.withArray("selectedAttributes");
for (int i = 0; i < selectedAttributesArray.size(); i++) {
if (selectedAttributesArray.get(i).isNull()) {
selectedAttributes.add(null);
} else {
int attributeInt = writableGraph.getAttribute(graphElement, selectedAttributesArray.get(i).asText());
selectedAttributes.add(new GraphAttribute(writableGraph, attributeInt));
}
}
// Create the basic find replace parameter object with the variables
final BasicFindReplaceParameters parameters = new BasicFindReplaceParameters(findString, replaceString, graphElement, selectedAttributes, standardText, regEx, ignoreCase, exactMatch, findInSelection, addToSelection, removeFromSelection, replaceInSelected, searchAllGraphs);
// Get the find results
final List<FindResult> findResults = new ArrayList<>();
final ArrayNode findResultsArray = (ArrayNode) jnode.withArray("findResults");
for (int i = 0; i < findResultsArray.size(); i = i + 3) {
findResults.add(findResultsArray.get(i).isNull() ? null : new FindResult(findResultsArray.get(i).asInt(), findResultsArray.get(i + 1).asInt(), GraphElementType.getValue(findResultsArray.get(i + 2).asText())));
}
// Create the findResultList object
final FindResultsList findResultList = new FindResultsList(currentIndex, parameters, graphID);
// Add the find results to the findResultsList
findResultList.addAll(findResults);
writableGraph.setObjectValue(attributeId, elementId, findResultList);
}
}
use of au.gov.asd.tac.constellation.views.find2.utilities.FindResult 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.FindResult 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.FindResult 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