Search in sources :

Example 11 with Attribute

use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.

the class FindTopComponent method setDefaultFindCriteriaPanels.

/**
 * add set of find criteria panel based on primary keys, otherwise just add
 * one with the first column in it
 */
private void setDefaultFindCriteriaPanels() {
    final Graph graph = graphNode.getGraph();
    ReadableGraph rg = graph.getReadableGraph();
    try {
        int[] keys = rg.getPrimaryKey(type);
        if (keys.length == 0) {
            addFindCriteriaPanel();
        } else {
            for (int i = 0; i < keys.length; i++) {
                Attribute attr = new GraphAttribute(rg, keys[i]);
                FindRule rule = new FindRule();
                rule.setAttribute(attr);
                if ("boolean".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addBooleanBasedRule(true);
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else if ("color".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addColorBasedRule(Color.BLACK);
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else if ("date".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addDateBasedRule(new Date(), new Date());
                    rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
                } else if (attr.getAttributeType().equalsIgnoreCase(ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME)) {
                    rule.addDateTimeBasedRule(new GregorianCalendar(), new GregorianCalendar());
                    rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
                } else if ("time".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addTimeBasedRule(new GregorianCalendar(), new GregorianCalendar());
                    rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
                } else if ("float".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addFloatBasedRule(0.0F, 0.0F);
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else if ("integer".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addIntegerBasedRule(0, 0);
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else if ("icon".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addIconBasedRule("");
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else {
                    // string
                    rule.addStringBasedRule("", false, false);
                    rule.setOperator(FindTypeOperators.Operator.CONTAINS);
                }
                addFindCriteriaPanel(rule);
            }
        }
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) FindRule(au.gov.asd.tac.constellation.views.find.advanced.FindRule) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 12 with Attribute

use of au.gov.asd.tac.constellation.graph.Attribute 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 {
    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) {
        clearSelection(graph);
    }
    String searchString = regex ? findString : Pattern.quote(findString);
    int caseSensitivity = ignorecase ? Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE : 0;
    Pattern searchPattern = Pattern.compile(searchString, caseSensitivity);
    for (Attribute a : selectedAttributes) {
        for (int i = 0; i < elementCount; i++) {
            int currElement = elementType.getElement(graph, i);
            String value = graph.getStringValue(a.getId(), currElement);
            if (value != null) {
                Matcher match = searchPattern.matcher(value);
                if (matchWholeWord) {
                    found = match.matches();
                } else {
                    found = match.find();
                }
                if (found) {
                    graph.setBooleanValue(selectedAttribute, currElement, true);
                }
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Attribute(au.gov.asd.tac.constellation.graph.Attribute) Matcher(java.util.regex.Matcher)

Example 13 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;
    }
    int elementCount = elementType.getElementCount(graph);
    String searchString = regex ? findString : Pattern.quote(findString);
    int caseSensitivity = ignorecase ? Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE : 0;
    Pattern searchPattern = Pattern.compile(searchString, caseSensitivity);
    for (Attribute a : selectedAttributes) {
        for (int i = 0; i < elementCount; i++) {
            int currElement = elementType.getElement(graph, i);
            String value = graph.getStringValue(a.getId(), currElement);
            if (value != null) {
                Matcher match = searchPattern.matcher(value);
                String newValue = match.replaceAll(replaceString);
                if (!newValue.equals(value)) {
                    graph.setStringValue(a.getId(), currElement, newValue);
                }
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Attribute(au.gov.asd.tac.constellation.graph.Attribute) Matcher(java.util.regex.Matcher)

Example 14 with Attribute

use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.

the class BasicFindPanel method updateComboBox.

// End of variables declaration//GEN-END:variables
private void updateComboBox() {
    dropDownPanel.removeAll();
    resetComboBox();
    selectAll.setEnabled(attributes.size() > 0);
    for (Attribute a : attributes) {
        JCheckBox attrCheckbox = new JCheckBox(a.getName());
        attrCheckbox.addActionListener(e -> {
            JCheckBox temp = (JCheckBox) e.getSource();
            checkBoxValueChanged(temp.getText(), temp.isSelected());
        });
        dropDownPanel.add(attrCheckbox);
    }
    selectAll.setSelected(true);
    toggleCheckAll(true);
}
Also used : JCheckBox(javax.swing.JCheckBox) Attribute(au.gov.asd.tac.constellation.graph.Attribute)

Example 15 with Attribute

use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.

the class BasicFindPanel method updateAttributes.

public void updateAttributes(ArrayList<Attribute> attributes) {
    ArrayList<Attribute> stringAttributes = new ArrayList<>();
    selectedAttributes.clear();
    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)

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