Search in sources :

Example 16 with Query

use of org.gephi.filters.api.Query in project gephi by gephi.

the class FiltersPanel method initEvents.

private void initEvents() {
    resetButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            FilterController controller = Lookup.getDefault().lookup(FilterController.class);
            for (Query query : filterModel.getQueries()) {
                controller.remove(query);
            }
            // uiModel.setSelectedQuery(null);
            controller.selectVisible(null);
            controller.filterVisible(null);
            ((FiltersExplorer) libraryTree).setup(manager, filterModel, uiModel);
            stopButton.setVisible(false);
            filterButton.setVisible(true);
        }
    });
    filterButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // selectButton.setSelected(false);
            if (uiModel.getSelectedQuery() != null) {
                FilterController controller = Lookup.getDefault().lookup(FilterController.class);
                controller.filterVisible(uiModel.getSelectedRoot());
                stopButton.setSelected(false);
                stopButton.setVisible(true);
                filterButton.setVisible(false);
            }
        }
    });
    stopButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            FilterController controller = Lookup.getDefault().lookup(FilterController.class);
            controller.filterVisible(null);
            controller.selectVisible(null);
            stopButton.setVisible(false);
            filterButton.setSelected(true);
            filterButton.setVisible(true);
        }
    });
    selectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            FilterController controller = Lookup.getDefault().lookup(FilterController.class);
            if (controller.getModel().isSelecting()) {
                controller.selectVisible(null);
            } else {
                if (uiModel.getSelectedQuery() != null) {
                    controller.selectVisible(uiModel.getSelectedRoot());
                }
            }
        }
    });
    exportColumnButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (uiModel.getSelectedQuery() != null) {
                FilterController controller = Lookup.getDefault().lookup(FilterController.class);
                NotifyDescriptor.InputLine question = new NotifyDescriptor.InputLine(NbBundle.getMessage(FiltersPanel.class, "FiltersPanel.exportColumn.input"), NbBundle.getMessage(FiltersPanel.class, "FiltersPanel.exportColumn.input.title"));
                if (DialogDisplayer.getDefault().notify(question) == NotifyDescriptor.OK_OPTION) {
                    String input = question.getInputText();
                    if (input != null && !input.isEmpty()) {
                        controller.exportToColumn(input, uiModel.getSelectedRoot());
                    }
                }
            }
        }
    });
    exportWorkspaceButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (uiModel.getSelectedQuery() != null) {
                FilterController controller = Lookup.getDefault().lookup(FilterController.class);
                controller.exportToNewWorkspace(uiModel.getSelectedRoot());
            }
        }
    });
    exportLabelVisible.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (uiModel.getSelectedQuery() != null) {
                FilterController controller = Lookup.getDefault().lookup(FilterController.class);
                controller.exportToLabelVisible(uiModel.getSelectedRoot());
            }
        }
    });
    updateEnabled(false);
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) ActionListener(java.awt.event.ActionListener) Query(org.gephi.filters.api.Query) ActionEvent(java.awt.event.ActionEvent) FilterController(org.gephi.filters.api.FilterController)

Example 17 with Query

use of org.gephi.filters.api.Query in project gephi by gephi.

the class RootNode method getDropType.

@Override
public PasteType getDropType(Transferable t, int action, int index) {
    final Node dropNode = NodeTransfer.node(t, DnDConstants.ACTION_COPY_OR_MOVE);
    if (t.isDataFlavorSupported(FilterBuilderNode.DATA_FLAVOR)) {
        try {
            final FilterBuilder fb = (FilterBuilder) t.getTransferData(FilterBuilderNode.DATA_FLAVOR);
            return new PasteType() {

                @Override
                public Transferable paste() throws IOException {
                    FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
                    Query f = filterController.createQuery(fb);
                    filterController.add(f);
                    return null;
                }
            };
        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        }
    } else if (dropNode != null && dropNode instanceof SavedQueryNode) {
        return new PasteType() {

            @Override
            public Transferable paste() throws IOException {
                SavedQueryNode node = (SavedQueryNode) dropNode;
                FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
                filterController.add(node.getQuery());
                return null;
            }
        };
    } else if (dropNode != null && dropNode instanceof QueryNode && ((QueryNode) dropNode).getQuery().getParent() != null) {
        return new PasteType() {

            @Override
            public Transferable paste() throws IOException {
                QueryNode queryNode = (QueryNode) dropNode;
                FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
                filterController.removeSubQuery(queryNode.getQuery(), queryNode.getQuery().getParent());
                filterController.add(queryNode.getQuery());
                return null;
            }
        };
    }
    return null;
}
Also used : Query(org.gephi.filters.api.Query) SavedQueryNode(org.gephi.desktop.filters.library.SavedQueryNode) FilterBuilder(org.gephi.filters.spi.FilterBuilder) SavedQueryNode(org.gephi.desktop.filters.library.SavedQueryNode) Node(org.openide.nodes.Node) SavedQueryNode(org.gephi.desktop.filters.library.SavedQueryNode) 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) IOException(java.io.IOException)

Example 18 with Query

use of org.gephi.filters.api.Query in project gephi by gephi.

the class FilterControllerImpl method add.

@Override
public void add(Query query) {
    AbstractQueryImpl absQuery = ((AbstractQueryImpl) query);
    absQuery = absQuery.getRoot();
    if (!model.hasQuery(absQuery)) {
        model.addFirst(absQuery);
        // Init filters with default graph
        Graph graph;
        if (model != null && model.getGraphModel() != null) {
            graph = model.getGraphModel().getGraph();
        } else {
            GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel(model.getWorkspace());
            graph = graphModel.getGraph();
        }
        for (Query q : query.getDescendantsAndSelf()) {
            Filter filter = q.getFilter();
            if (filter instanceof NodeFilter || filter instanceof EdgeFilter || filter instanceof ElementFilter) {
                FilterProcessor filterProcessor = new FilterProcessor();
                filterProcessor.init(filter, graph);
            }
        }
    }
}
Also used : Graph(org.gephi.graph.api.Graph) Query(org.gephi.filters.api.Query) GraphModel(org.gephi.graph.api.GraphModel) GraphController(org.gephi.graph.api.GraphController)

Example 19 with Query

use of org.gephi.filters.api.Query in project gephi by gephi.

the class FilterControllerImpl method setValue.

@Override
public void setValue(FilterProperty property, Object value, Callback callback) {
    if (model != null) {
        Query query = model.getQuery(property.getFilter());
        if (query == null) {
            callback.setValue(value);
            return;
        }
        AbstractQueryImpl rootQuery = ((AbstractQueryImpl) query).getRoot();
        FilterThread filterThread;
        if ((filterThread = model.getFilterThread()) != null && model.getCurrentQuery() == rootQuery) {
            if (Thread.currentThread().equals(filterThread)) {
                // Called inside of the thread, in init for instance. Update normally.
                callback.setValue(value);
                model.updateParameters(query);
            } else {
                // The query is currently being filtered by the thread, or finished to do it
                filterThread.addModifier(new PropertyModifier(query, property, value, callback));
                filterThread.setRootQuery(rootQuery);
            }
        } else {
            // Update normally
            callback.setValue(value);
            model.updateParameters(query);
        }
    } else {
        callback.setValue(value);
    }
}
Also used : PropertyModifier(org.gephi.filters.FilterThread.PropertyModifier) Query(org.gephi.filters.api.Query)

Example 20 with Query

use of org.gephi.filters.api.Query in project gephi by gephi.

the class FilterModelPersistenceProvider method writeXML.

public void writeXML(XMLStreamWriter writer, FilterModelImpl model) throws XMLStreamException {
    writer.writeStartElement("autorefresh");
    writer.writeAttribute("value", String.valueOf(model.isAutoRefresh()));
    writer.writeEndElement();
    // Queries
    writer.writeStartElement("queries");
    queryId = 0;
    for (Query query : model.getQueries()) {
        writeQuery("query", writer, model, query, -1);
    }
    writer.writeEndElement();
    // Saved queries
    writer.writeStartElement("savedqueries");
    for (Query query : model.getLibrary().getLookup().lookupAll(Query.class)) {
        writeQuery("savedquery", writer, model, query, -1);
    }
    writer.writeEndElement();
}
Also used : Query(org.gephi.filters.api.Query)

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