Search in sources :

Example 11 with Query

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;
}
Also used : Query(org.gephi.filters.api.Query)

Example 12 with Query

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;
}
Also used : Query(org.gephi.filters.api.Query) XMLStreamException(javax.xml.stream.XMLStreamException) GraphModel(org.gephi.graph.api.GraphModel) PropertyEditor(java.beans.PropertyEditor) GraphController(org.gephi.graph.api.GraphController)

Example 13 with Query

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]);
}
Also used : Query(org.gephi.filters.api.Query) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 14 with Query

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]);
}
Also used : Query(org.gephi.filters.api.Query) LinkedList(java.util.LinkedList)

Example 15 with Query

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;
}
Also used : Query(org.gephi.filters.api.Query) FilterBuilder(org.gephi.filters.spi.FilterBuilder) Node(org.openide.nodes.Node) FilterBuilderNode(org.gephi.desktop.filters.library.FilterBuilderNode) AbstractNode(org.openide.nodes.AbstractNode) PasteType(org.openide.util.datatransfer.PasteType) Transferable(java.awt.datatransfer.Transferable) FilterController(org.gephi.filters.api.FilterController) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Aggregations

Query (org.gephi.filters.api.Query)21 FilterBuilder (org.gephi.filters.spi.FilterBuilder)6 FilterController (org.gephi.filters.api.FilterController)4 LinkedList (java.util.LinkedList)3 AbstractNode (org.openide.nodes.AbstractNode)3 Node (org.openide.nodes.Node)3 Transferable (java.awt.datatransfer.Transferable)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)2 IOException (java.io.IOException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 FilterBuilderNode (org.gephi.desktop.filters.library.FilterBuilderNode)2 Graph (org.gephi.graph.api.Graph)2 GraphController (org.gephi.graph.api.GraphController)2 GraphModel (org.gephi.graph.api.GraphModel)2 Serialization (org.gephi.utils.Serialization)2 PasteType (org.openide.util.datatransfer.PasteType)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 PropertyEditor (java.beans.PropertyEditor)1 ArrayList (java.util.ArrayList)1