use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.
the class FindTopComponent method performReplace.
private void performReplace() {
final ArrayList<Attribute> selectedAttributes = replacePanel.getSelectedAttributes();
final String findString = replacePanel.getFindString();
final String replaceString = replacePanel.getReplaceString();
final Boolean regex = replacePanel.getRegex();
final Boolean ignoreCase = replacePanel.getIgnorecase();
final ReplacePlugin replacePlugin = new ReplacePlugin(type, selectedAttributes, findString, replaceString, regex, ignoreCase);
PluginExecution.withPlugin(replacePlugin).executeLater(graphNode.getGraph());
}
use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.
the class ReplacePanel method updateAttributes.
public void updateAttributes(ArrayList<Attribute> attributes) {
ArrayList<Attribute> stringAttributes = new ArrayList<>();
for (Attribute a : attributes) {
if ("string".equals(a.getAttributeType())) {
stringAttributes.add(a);
}
}
this.attributes = stringAttributes;
Collections.sort(this.attributes, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
updateComboBox();
}
use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.
the class FindStateIOProvider method getRule.
/**
* Helper method that deserialises an individual rule from a JSON node.
*
* @param graph The graph that is being loaded.
* @param node The node that contains an individual FindRule.
* @return A single FindRule.
*/
private static FindRule getRule(final GraphReadMethods graph, final JsonNode node) {
final FindRule rule = new FindRule();
final int attrID = graph.getAttribute(GraphElementType.getValue(node.get(ELMT).asText()), node.get(ATTR).asText());
if (attrID != Graph.NOT_FOUND) {
final Attribute attr = new GraphAttribute(graph, attrID);
rule.setAttribute(attr);
rule.setOperator(FindTypeOperators.Operator.getTypeEnum(node.get(OPER).textValue()));
rule.setType(FindTypeOperators.Type.getTypeEnum(node.get(TYPE).textValue()));
rule.setHeld(node.get(HOLD).asBoolean());
rule.setArgs(getArguments(node.get(ARGS)));
return rule;
}
return null;
}
use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.
the class GraphAttributePlugin method retrieveAttributes.
/**
* Helper method that performs the attribute query operation.
* <p>
* Sets any found attributes to an internal variable which can be later
* returned through use of the <code>getAttributes()</code> method.
*
* @param graph The graph to retrieve attributes for.
*
* @see Graph
*/
private void retrieveAttributes(final GraphReadMethods graph) {
final long amc = graph.getAttributeModificationCounter();
attributes.clear();
final int attrCount = graph.getAttributeCount(type);
for (int position = 0; position < attrCount; position++) {
final int attr = graph.getAttribute(type, position);
final Attribute candidate = new GraphAttribute(graph, attr);
attributes.add(candidate);
}
attributeModificationCounter = amc;
}
use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.
the class ReplacePlugin method edit.
@Override
protected void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
if (findString.isEmpty()) {
findString = "^$";
regex = true;
}
final int selectedAttribute = graph.getAttribute(elementType, VisualConcept.VertexAttribute.SELECTED.getName());
final int elementCount = elementType.getElementCount(graph);
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 replace string based on the search preferences. If
* that element matches the search criteria, change its matching part of
* the value to the replace string.
*/
for (final Attribute a : selectedAttributes) {
// If the attribute exists on the graph
if (graph.getAttribute(elementType, a.getName()) >= 0) {
// for each element of the given type
for (int i = 0; i < elementCount; i++) {
// get the current graph element
final int currElement = elementType.getElement(graph, i);
// get string value of it graph elements attribute
final String value = graph.getStringValue(a.getId(), currElement);
// get the selected value of that graph element
boolean selected = graph.getBooleanValue(selectedAttribute, currElement);
// If the value isnt null
if (value != null) {
final Matcher match = searchPattern.matcher(value);
final String newValue = match.replaceAll(replaceString);
if (!newValue.equals(value)) {
// if replace in selected is false
if (!replaceIn) {
// set the string of the element types attribute
// to the new value
graph.setStringValue(a.getId(), currElement, newValue);
if (replaceNext) {
return;
}
} else {
// if selected is false
if (selected) {
// set the string of the element types attribute
// to the new value
graph.setStringValue(a.getId(), currElement, newValue);
if (replaceNext) {
return;
}
}
}
}
}
}
}
}
}
Aggregations