use of org.gephi.filters.api.Query in project gephi by gephi.
the class SavedQueryNode method getQueryName.
private String getQueryName(Query query) {
String res = query.getName();
if (query.getPropertiesCount() > 0) {
res += "(";
for (int i = 0; i < query.getPropertiesCount(); i++) {
res += "'" + query.getPropertyValue(i).toString() + "'";
res += (i + 1 < query.getPropertiesCount()) ? "," : "";
}
}
if (query.getChildren() != null) {
if (query.getPropertiesCount() == 0) {
res += "(";
} else {
res += ",";
}
for (Query child : query.getChildren()) {
res += getQueryName(child);
res += ",";
}
if (res.endsWith(",")) {
res = res.substring(0, res.length() - 1);
}
}
res += ")";
return res;
}
use of org.gephi.filters.api.Query in project gephi by gephi.
the class FilterModelPersistenceProvider method readQuery.
private Query readQuery(XMLStreamReader reader, FilterModelImpl model) throws XMLStreamException {
String builderClassName = reader.getAttributeValue(null, "builder");
String filterClassName = reader.getAttributeValue(null, "filter");
FilterBuilder builder = null;
for (FilterBuilder fb : model.getLibrary().getLookup().lookupAll(FilterBuilder.class)) {
if (fb.getClass().getName().equals(builderClassName)) {
if (filterClassName != null) {
if (fb.getFilter(model.getWorkspace()).getClass().getName().equals(filterClassName)) {
builder = fb;
break;
}
} else {
builder = fb;
break;
}
}
}
if (builder == null) {
for (CategoryBuilder catBuilder : Lookup.getDefault().lookupAll(CategoryBuilder.class)) {
for (FilterBuilder fb : catBuilder.getBuilders(model.getWorkspace())) {
if (fb.getClass().getName().equals(builderClassName)) {
if (filterClassName != null) {
if (fb.getFilter(model.getWorkspace()).getClass().getName().equals(filterClassName)) {
builder = fb;
break;
}
} else {
builder = fb;
break;
}
}
}
}
}
if (builder != null) {
//Create filter
Filter filter = builder.getFilter(model.getWorkspace());
Query query;
if (filter instanceof Operator) {
query = new OperatorQueryImpl((Operator) filter);
} else {
query = new FilterQueryImpl(builder, filter);
}
FilterProperty property = null;
boolean end = false;
while (reader.hasNext() && !end) {
Integer eventType = reader.next();
if (eventType.equals(XMLEvent.START_ELEMENT)) {
String name = reader.getLocalName();
if ("parameter".equalsIgnoreCase(name)) {
int index = Integer.parseInt(reader.getAttributeValue(null, "index"));
property = query.getFilter().getProperties()[index];
}
} else if (eventType.equals(XMLStreamReader.CHARACTERS) && property != null) {
try {
PropertyEditor editor = property.getPropertyEditor();
if (editor == null) {
editor = PropertyEditorManager.findEditor(property.getValueType());
}
if (editor != null) {
String textValue = reader.getText();
if (editor instanceof AttributeColumnPropertyEditor) {
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = gc.getGraphModel(model.getWorkspace());
((AttributeColumnPropertyEditor) editor).setGraphModel(graphModel);
}
editor.setAsText(textValue);
property.setValue(editor.getValue());
model.updateParameters(query);
if (editor instanceof AttributeColumnPropertyEditor) {
((AttributeColumnPropertyEditor) editor).setGraphModel(null);
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
property = null;
if ("query".equalsIgnoreCase(reader.getLocalName())) {
end = true;
}
}
}
return query;
}
return null;
}
use of org.gephi.filters.api.Query in project gephi by gephi.
the class FilterModelImpl method getAllQueries.
public Query[] getAllQueries() {
List<Query> result = new ArrayList<>();
LinkedList<Query> stack = new LinkedList<>();
stack.addAll(queries);
while (!stack.isEmpty()) {
Query q = stack.pop();
result.add(q);
stack.addAll(Arrays.asList(q.getChildren()));
}
return result.toArray(new Query[0]);
}
use of org.gephi.filters.api.Query in project gephi by gephi.
the class AbstractQueryImpl method getQueries.
@Override
public Query[] getQueries(Class<? extends Filter> filterClass) {
List<Query> r = new LinkedList<>();
LinkedList<Query> stack = new LinkedList<>();
stack.add(this);
while (!stack.isEmpty()) {
Query q = stack.pop();
r.add(q);
stack.addAll(Arrays.asList(q.getChildren()));
}
for (Iterator<Query> itr = r.iterator(); itr.hasNext(); ) {
Query q = itr.next();
if (!q.getFilter().getClass().equals(filterClass)) {
itr.remove();
}
}
return r.toArray(new Query[0]);
}
use of org.gephi.filters.api.Query in project gephi by gephi.
the class SlotNode method getDropType.
@Override
public PasteType getDropType(final Transferable t, int action, int index) {
final Node dropNode = NodeTransfer.node(t, DnDConstants.ACTION_COPY_OR_MOVE);
if (dropNode != null && dropNode instanceof QueryNode) {
Query q = ((QueryNode) dropNode).getQuery();
if (!Arrays.asList(q.getDescendantsAndSelf()).contains(parent)) {
// Check if not parent
return new PasteType() {
@Override
public Transferable paste() throws IOException {
QueryNode queryNode = (QueryNode) dropNode;
FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
filterController.setSubQuery(parent, queryNode.getQuery());
return null;
}
};
}
} else if (t.isDataFlavorSupported(FilterBuilderNode.DATA_FLAVOR)) {
return new PasteType() {
@Override
public Transferable paste() throws IOException {
try {
FilterBuilder builder = (FilterBuilder) t.getTransferData(FilterBuilderNode.DATA_FLAVOR);
FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
Query query = filterController.createQuery(builder);
filterController.setSubQuery(parent, query);
} catch (UnsupportedFlavorException ex) {
Exceptions.printStackTrace(ex);
}
return null;
}
};
}
return null;
}
Aggregations