Search in sources :

Example 1 with CompositeFilter

use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.

the class FilterMainPanel method updateCMBAttributes.

/*
	 * Update the attribute list in the attribute combobox based on the settings in the 
	 * current selected filter
	 */
private void updateCMBAttributes() {
    DefaultComboBoxModel cbm;
    cbm = ((DefaultComboBoxModel) cmbAttributes.getModel());
    cbm.removeAllElements();
    cbm.addElement(attributesSeperator);
    CompositeFilter selectedFilter = (CompositeFilter) cmbFilters.getSelectedItem();
    if (selectedFilter == null) {
        return;
    }
    CyNetwork network = selectedFilter.getNetwork();
    if (network == null) {
        return;
    }
    List<String> av;
    av = getCyAttributesList(network, "node");
    for (int i = 0; i < av.size(); i++) {
        cbm.addElement(av.get(i));
    }
    av = getCyAttributesList(network, "edge");
    for (int i = 0; i < av.size(); i++) {
        cbm.addElement(av.get(i));
    }
    cbm.addElement(filtersSeparator);
    Vector<CompositeFilter> allFilters = modelLocator.getFilters();
    if (allFilters != null) {
        for (int i = 0; i < allFilters.size(); i++) {
            Object fi;
            fi = allFilters.elementAt(i);
            if (fi != selectedFilter) {
                cbm.addElement(fi);
            }
        }
    }
}
Also used : CompositeFilter(org.cytoscape.filter.internal.filters.model.CompositeFilter) CyNetwork(org.cytoscape.model.CyNetwork) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 2 with CompositeFilter

use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.

the class FilterMainPanel method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    Object _actionObject = e.getSource();
    // handle Button events
    if (_actionObject instanceof JButton) {
        JButton _btn = (JButton) _actionObject;
        if (_btn == btnApplyFilter) {
            CompositeFilter theFilterToApply = (CompositeFilter) cmbFilters.getSelectedItem();
            final CyNetwork currentNetwork = applicationManager.getCurrentNetwork();
            if (currentNetwork == null)
                return;
            theFilterToApply.setNetwork(currentNetwork);
            FilterUtil.doSelection(theFilterToApply, applicationManager);
        }
        if (_btn == btnAddFilterWidget) {
            // btnAddFilterWidget is clicked!
            CompositeFilter selectedFilter = (CompositeFilter) cmbFilters.getSelectedItem();
            FilterSettingPanel theSettingPanel = filter2SettingPanelMap.get(selectedFilter);
            if (cmbAttributes.getSelectedItem() instanceof String) {
                String selectItem = (String) cmbAttributes.getSelectedItem();
                if (selectItem.equalsIgnoreCase(filtersSeparator) || selectItem.equalsIgnoreCase(attributesSeperator)) {
                    return;
                }
            }
            if (cmbAttributes.getSelectedItem().toString().startsWith("node.") || cmbAttributes.getSelectedItem().toString().startsWith("edge.")) {
                // "node" or "edge"
                String attributeType = cmbAttributes.getSelectedItem().toString().substring(0, 4);
                String attributeName = cmbAttributes.getSelectedItem().toString().substring(5);
                if (CyAttributesUtil.isNullAttribute(applicationManager.getCurrentNetwork(), attributeType, attributeName)) {
                    JOptionPane.showMessageDialog(this, "All the values for this column are NULL.", "Can not create filter", JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }
            theSettingPanel.addNewWidget(cmbAttributes.getSelectedItem());
        }
        if (_btn == btnSelectAll) {
            CyNetwork cyNetwork = applicationManager.getCurrentNetwork();
            SelectUtil.selectAllNodes(cyNetwork);
            SelectUtil.selectAllEdges(cyNetwork);
        }
        if (_btn == btnDeSelect) {
            CyNetwork cyNetwork = applicationManager.getCurrentNetwork();
            SelectUtil.unselectAllNodes(cyNetwork);
            SelectUtil.unselectAllEdges(cyNetwork);
        }
    }
    if (_actionObject instanceof JMenuItem) {
        CyNetwork cyNetwork = applicationManager.getCurrentNetwork();
        JMenuItem _menuItem = (JMenuItem) _actionObject;
        if (_menuItem == newFilterMenuItem || _menuItem == newTopologyFilterMenuItem || _menuItem == newNodeInteractionFilterMenuItem || _menuItem == newEdgeInteractionFilterMenuItem) {
            String filterType = "Composite";
            if (_menuItem == newTopologyFilterMenuItem) {
                filterType = "Topology";
                if (cyNetwork != null) {
                    SelectUtil.unselectAllNodes(cyNetwork);
                }
            }
            if (_menuItem == newNodeInteractionFilterMenuItem) {
                filterType = "NodeInteraction";
                if (cyNetwork != null) {
                    SelectUtil.unselectAllNodes(cyNetwork);
                }
            }
            if (_menuItem == newEdgeInteractionFilterMenuItem) {
                filterType = "EdgeInteraction";
                if (cyNetwork != null) {
                    SelectUtil.unselectAllNodes(cyNetwork);
                }
            }
            String newFilterName = "";
            while (true) {
                newFilterName = JOptionPane.showInputDialog(this, "New filter name", "New Filter Name", JOptionPane.INFORMATION_MESSAGE);
                if (newFilterName == null) {
                    // user clicked "cancel"
                    break;
                }
                if (newFilterName.trim().equals("")) {
                    Object[] options = { "OK" };
                    JOptionPane.showOptionDialog(this, "Filter name is empty.", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
                    continue;
                }
                if (org.cytoscape.filter.internal.filters.util.FilterUtil.isFilterNameDuplicated(modelLocator.getFilters(), newFilterName)) {
                    Object[] options = { "OK" };
                    JOptionPane.showOptionDialog(this, "Filter name already existed.", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
                    continue;
                }
                break;
            }
            if ((newFilterName != null) && (!newFilterName.trim().equals(""))) {
                createNewFilter(newFilterName, filterType);
            // pcs.firePropertyChange("NEW_FILTER_CREATED", "", "");
            // // TODO: Port this
            // if (FilterPlugin.shouldFireFilterEvent) {
            // PropertyChangeEvent evt = new PropertyChangeEvent(this, "NEW_FILTER_CREATED", null, null);
            // Cytoscape.getPropertyChangeSupport().firePropertyChange(evt);
            // }
            }
        } else if (_menuItem == deleteFilterMenuItem) {
            CompositeFilter theSelectedFilter = (CompositeFilter) cmbFilters.getSelectedItem();
            if (theSelectedFilter == null) {
                return;
            }
            Object[] options = { "YES", "CANCEL" };
            int userChoice = JOptionPane.showOptionDialog(this, "Are you sure you want to delete " + theSelectedFilter.getName() + "?", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
            if (userChoice == 1) {
                // user clicked CANCEL
                return;
            }
            deleteFilter(theSelectedFilter);
        // // TODO: Port this?  No one listens for these events
        // if (FilterPlugin.shouldFireFilterEvent) {
        // PropertyChangeEvent evt = new PropertyChangeEvent(this, "FILTER_DELETED", null, null);
        // Cytoscape.getPropertyChangeSupport().firePropertyChange(evt);
        // }
        } else if (_menuItem == renameFilterMenuItem) {
            CompositeFilter theSelectedFilter = (CompositeFilter) cmbFilters.getSelectedItem();
            if (theSelectedFilter == null) {
                return;
            }
            renameFilter();
        // // TODO: Port this?  No one listens for these events
        // if (FilterPlugin.shouldFireFilterEvent) {
        // PropertyChangeEvent evt = new PropertyChangeEvent(this, "FILTER_RENAMED", null, null);
        // Cytoscape.getPropertyChangeSupport().firePropertyChange(evt);
        // }
        } else if (_menuItem == duplicateFilterMenuItem) {
            CompositeFilter theSelectedFilter = (CompositeFilter) cmbFilters.getSelectedItem();
            if (theSelectedFilter == null) {
                return;
            }
            duplicateFilter();
        // // TODO: Port this?  No one listens for these events
        // if (FilterPlugin.shouldFireFilterEvent) {
        // PropertyChangeEvent evt = new PropertyChangeEvent(this, "FILTER_DUPLICATED", null, null);
        // Cytoscape.getPropertyChangeSupport().firePropertyChange(evt);
        // }
        }
    }
    // JMenuItem event
    updateInteractionMenuItemStatus();
    updateView();
}
Also used : CompositeFilter(org.cytoscape.filter.internal.filters.model.CompositeFilter) JButton(javax.swing.JButton) CyNetwork(org.cytoscape.model.CyNetwork) JMenuItem(javax.swing.JMenuItem)

Example 3 with CompositeFilter

use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.

the class FilterMainPanel method updateCMBFilters.

private void updateCMBFilters() {
    Vector<CompositeFilter> filters = modelLocator.getFilters();
    DefaultComboBoxModel cbm = (DefaultComboBoxModel) cmbFilters.getModel();
    cbm.removeAllElements();
    if (filters != null) {
        for (CompositeFilter cf : filters) {
            cbm.addElement(cf);
        }
    }
    if (filters == null || filters.size() == 0) {
        replaceFilterSettingPanel(null);
    }
}
Also used : CompositeFilter(org.cytoscape.filter.internal.filters.model.CompositeFilter) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 4 with CompositeFilter

use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.

the class FilterMainPanel method itemStateChanged.

@Override
public void itemStateChanged(ItemEvent e) {
    Object source = e.getSource();
    if (source instanceof JComboBox) {
        JComboBox cmb = (JComboBox) source;
        if (cmb == cmbFilters) {
            CompositeFilter selectedFilter = (CompositeFilter) cmbFilters.getSelectedItem();
            if (selectedFilter == null) {
                this.btnApplyFilter.setEnabled(false);
                this.btnAddFilterWidget.setEnabled(false);
                return;
            } else {
                this.btnAddFilterWidget.setEnabled(true);
                this.btnApplyFilter.setEnabled(true);
            }
            CyNetwork cyNetwork = applicationManager.getCurrentNetwork();
            selectedFilter.setNetwork(cyNetwork);
            replaceFilterSettingPanel(selectedFilter);
            if (cyNetwork != null) {
                SelectUtil.unselectAllNodes(cyNetwork);
            }
            if (cmbFilters.getSelectedItem() instanceof TopologyFilter || cmbFilters.getSelectedItem() instanceof InteractionFilter) {
                // do not apply TopologyFilter or InteractionFilter automatically
                return;
            }
            // If network size is greater than pre-defined threshold, don't apply it automatically
            if (FilterUtil.isDynamicFilter(selectedFilter)) {
                FilterUtil.doSelection(selectedFilter, applicationManager);
            }
            updateView();
            refreshAttributeCMB();
        } else if (cmb == cmbAttributes) {
            Object selectObject = cmbAttributes.getSelectedItem();
            if (selectObject != null) {
                String selectItem = selectObject.toString();
                // Disable the Add button if "--Table Column--" or "-- Filter ---" is selected
                if (selectItem.equalsIgnoreCase(filtersSeparator) || selectItem.equalsIgnoreCase(attributesSeperator)) {
                    btnAddFilterWidget.setEnabled(false);
                } else {
                    btnAddFilterWidget.setEnabled(true);
                }
            }
        }
    }
}
Also used : NodeInteractionFilter(org.cytoscape.filter.internal.filters.model.NodeInteractionFilter) EdgeInteractionFilter(org.cytoscape.filter.internal.filters.model.EdgeInteractionFilter) InteractionFilter(org.cytoscape.filter.internal.filters.model.InteractionFilter) CompositeFilter(org.cytoscape.filter.internal.filters.model.CompositeFilter) JComboBox(javax.swing.JComboBox) CyNetwork(org.cytoscape.model.CyNetwork) TopologyFilter(org.cytoscape.filter.internal.filters.model.TopologyFilter)

Example 5 with CompositeFilter

use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.

the class FilterMainPanel method renameFilter.

private void renameFilter() {
    CompositeFilter theFilter = (CompositeFilter) cmbFilters.getSelectedItem();
    String oldFilterName = theFilter.getName();
    String newFilterName = "";
    while (true) {
        Vector<String> nameVect = new Vector<String>();
        nameVect.add(oldFilterName);
        EditNameDialog theDialog = new EditNameDialog("Edit Filter Name", "Please enter a new Filter name:", nameVect, 300, 170);
        theDialog.setLocationRelativeTo(this);
        theDialog.setVisible(true);
        newFilterName = nameVect.elementAt(0);
        if ((newFilterName == null) || newFilterName.trim().equals("") || newFilterName.equals(oldFilterName)) {
            return;
        }
        if (FilterUtil.isFilterNameDuplicated(modelLocator.getFilters(), newFilterName)) {
            Object[] options = { "OK" };
            JOptionPane.showOptionDialog(this, "Filter name already existed.", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
            continue;
        }
        break;
    }
    // while loop
    theFilter.setName(newFilterName);
    cmbFilters.setSelectedItem(theFilter);
    refreshFilterSelectCMB();
}
Also used : CompositeFilter(org.cytoscape.filter.internal.filters.model.CompositeFilter) Vector(java.util.Vector)

Aggregations

CompositeFilter (org.cytoscape.filter.internal.filters.model.CompositeFilter)25 ArrayList (java.util.ArrayList)5 File (java.io.File)4 IOException (java.io.IOException)4 LinkedHashSet (java.util.LinkedHashSet)4 Vector (java.util.Vector)3 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)3 EdgeInteractionFilter (org.cytoscape.filter.internal.filters.model.EdgeInteractionFilter)3 NodeInteractionFilter (org.cytoscape.filter.internal.filters.model.NodeInteractionFilter)3 TopologyFilter (org.cytoscape.filter.internal.filters.model.TopologyFilter)3 CyNetwork (org.cytoscape.model.CyNetwork)3 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 AdvancedSetting (org.cytoscape.filter.internal.filters.model.AdvancedSetting)2 AtomicFilter (org.cytoscape.filter.internal.filters.model.AtomicFilter)2 CyFilter (org.cytoscape.filter.internal.filters.model.CyFilter)2 InteractionFilter (org.cytoscape.filter.internal.filters.model.InteractionFilter)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1