Search in sources :

Example 51 with CyNetwork

use of org.cytoscape.model.CyNetwork 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 52 with CyNetwork

use of org.cytoscape.model.CyNetwork 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 53 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class FilterMainPanel method updateFeedbackTableModel.

private void updateFeedbackTableModel() {
    String netName = null;
    String nodeCount = null;
    String edgeCount = null;
    final CyNetwork net = applicationManager.getCurrentNetwork();
    if (net != null) {
        netName = net.getRow(net).get(CyNetwork.NAME, String.class);
        nodeCount = net.getNodeCount() + "(" + net.getDefaultNodeTable().countMatchingRows(CyNetwork.SELECTED, true) + ")";
        edgeCount = net.getEdgeCount() + "(" + net.getDefaultEdgeTable().countMatchingRows(CyNetwork.SELECTED, true) + ")";
    }
    tblFeedBack.getModel().setValueAt(netName, 0, 0);
    tblFeedBack.getModel().setValueAt(nodeCount, 0, 1);
    tblFeedBack.getModel().setValueAt(edgeCount, 0, 2);
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork)

Example 54 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class FilterMainPanel method enableForNetwork.

/**
 * Enable select/deselect buttons if the current network exists and is not null.
 */
private void enableForNetwork() {
    CyNetwork n = applicationManager.getCurrentNetwork();
    if (n == null) {
        this.btnSelectAll.setEnabled(false);
        this.btnDeSelect.setEnabled(false);
        btnApplyFilter.setVisible(false);
    } else {
        this.btnSelectAll.setEnabled(true);
        this.btnDeSelect.setEnabled(true);
        btnApplyFilter.setVisible(true);
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork)

Example 55 with CyNetwork

use of org.cytoscape.model.CyNetwork 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)

Aggregations

CyNetwork (org.cytoscape.model.CyNetwork)517 CyNode (org.cytoscape.model.CyNode)183 CyNetworkView (org.cytoscape.view.model.CyNetworkView)129 CyEdge (org.cytoscape.model.CyEdge)108 Test (org.junit.Test)107 ArrayList (java.util.ArrayList)87 CyTable (org.cytoscape.model.CyTable)75 CyApplicationManager (org.cytoscape.application.CyApplicationManager)70 CyIdentifiable (org.cytoscape.model.CyIdentifiable)57 CyRow (org.cytoscape.model.CyRow)48 HashSet (java.util.HashSet)45 CyNetworkManager (org.cytoscape.model.CyNetworkManager)40 HashMap (java.util.HashMap)35 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)35 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)32 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)31 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)30 AbstractNetworkReaderTest (org.cytoscape.io.internal.read.AbstractNetworkReaderTest)27 TaskIterator (org.cytoscape.work.TaskIterator)27 List (java.util.List)26