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();
}
}
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);
}
}
}
}
}
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);
}
}
}
}
}
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);
}
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();
}
Aggregations