Search in sources :

Example 16 with Attribute

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());
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ReplacePlugin(au.gov.asd.tac.constellation.views.find.ReplacePlugin)

Example 17 with Attribute

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();
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) ArrayList(java.util.ArrayList)

Example 18 with Attribute

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;
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

Example 19 with Attribute

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;
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

Example 20 with Attribute

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;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Attribute(au.gov.asd.tac.constellation.graph.Attribute) Matcher(java.util.regex.Matcher)

Aggregations

Attribute (au.gov.asd.tac.constellation.graph.Attribute)94 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)55 ArrayList (java.util.ArrayList)30 Test (org.testng.annotations.Test)23 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)18 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)15 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)13 Graph (au.gov.asd.tac.constellation.graph.Graph)12 BasicFindReplaceParameters (au.gov.asd.tac.constellation.views.find2.utilities.BasicFindReplaceParameters)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObservableList (javafx.collections.ObservableList)8 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)7 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)7 TableColumn (javafx.scene.control.TableColumn)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)6 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)5 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)5 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)5 JsonFactory (com.fasterxml.jackson.core.JsonFactory)5