Search in sources :

Example 1 with InteractionFilter

use of org.cytoscape.filter.internal.filters.model.InteractionFilter 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 2 with InteractionFilter

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

the class FilterMainPanel method replaceFilterSettingPanel.

/*
	 * Hide the visible filterSettingPanel, if any, and show the new FilterSettingPanel for
	 * the given filter.
	 */
private void replaceFilterSettingPanel(CompositeFilter pNewFilter) {
    if (pNewFilter == null) {
        pnlFilterDefinition.setVisible(false);
        lbPlaceHolder_pnlFilterDefinition.setVisible(true);
        return;
    }
    FilterSettingPanel next;
    next = filter2SettingPanelMap.get(pNewFilter);
    // we can exit now and avoid hiding and showing the same panel.
    if ((next != null) && (next == currentFilterSettingPanel)) {
        return;
    }
    // Hide the existing FilterSettingPanel, if any
    if (currentFilterSettingPanel != null) {
        currentFilterSettingPanel.setVisible(false);
    }
    currentFilterSettingPanel = next;
    if (currentFilterSettingPanel == null || currentFilterSettingPanel.hasNullIndexChildFilter()) {
        currentFilterSettingPanel = new FilterSettingPanel(quickFind, this, pNewFilter, modelLocator, applicationManager, eventHelper);
        // Update the HashMap
        filter2SettingPanelMap.put(pNewFilter, currentFilterSettingPanel);
    }
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.gridwidth = 3;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    gridBagConstraints.insets = new Insets(7, 0, 0, 0);
    if (pNewFilter instanceof TopologyFilter) {
        lbAttribute.setVisible(false);
        btnAddFilterWidget.setVisible(false);
        cmbAttributes.setVisible(false);
        pnlFilterDefinition.setBorder(BorderFactory.createTitledBorder("Topology Filter Definition"));
    } else if (pNewFilter instanceof InteractionFilter) {
        lbAttribute.setVisible(false);
        btnAddFilterWidget.setVisible(false);
        cmbAttributes.setVisible(false);
        pnlFilterDefinition.setBorder(BorderFactory.createTitledBorder("Interaction Filter Definition"));
    } else {
        lbAttribute.setVisible(true);
        btnAddFilterWidget.setVisible(true);
        cmbAttributes.setVisible(true);
        pnlFilterDefinition.setBorder(BorderFactory.createTitledBorder("Filter Definition"));
    }
    pnlFilterDefinition.add(currentFilterSettingPanel, gridBagConstraints);
    pnlFilterDefinition.setVisible(true);
    currentFilterSettingPanel.setVisible(true);
    lbPlaceHolder_pnlFilterDefinition.setVisible(false);
    this.repaint();
}
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) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) TopologyFilter(org.cytoscape.filter.internal.filters.model.TopologyFilter)

Example 3 with InteractionFilter

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

the class FilterReader method getFilterFromStrList.

private CompositeFilter getFilterFromStrList(List<String> strList, Collection<CompositeFilter> filters) {
    boolean isTopologyFilter = false;
    boolean isInteractionFilter = false;
    if (strList.get(0).startsWith("<TopologyFilter>")) {
        isTopologyFilter = true;
    }
    if (strList.get(0).startsWith("<InteractionFilter>")) {
        isInteractionFilter = true;
    }
    List<String> advSettingStrVect = new ArrayList<String>();
    List<String> filterStrVect = new ArrayList<String>();
    // Seperate AdvancedSetting from the rest
    int startIndex = -1, endIndex = -1;
    String line = null;
    for (int i = 0; i < strList.size(); i++) {
        line = strList.get(i);
        if (line.startsWith("<AdvancedSetting>")) {
            startIndex = i;
        }
        if (line.startsWith("</AdvancedSetting>")) {
            endIndex = i;
            break;
        }
    }
    advSettingStrVect.addAll(strList.subList(startIndex + 1, endIndex));
    filterStrVect.addAll(strList.subList(1, startIndex));
    filterStrVect.addAll(strList.subList(endIndex + 1, strList.size()));
    CompositeFilter retFilter = new CompositeFilter(ServicesUtil.cyApplicationManagerServiceRef);
    retFilter.setAdvancedSetting(getAdvancedSettingFromStr(advSettingStrVect));
    if (isTopologyFilter) {
        retFilter = new TopologyFilter(ServicesUtil.cyApplicationManagerServiceRef);
        retFilter.setAdvancedSetting(getAdvancedSettingFromStr(advSettingStrVect));
        getTopologyFilterFromStr((TopologyFilter) retFilter, filterStrVect, filters);
        return retFilter;
    }
    if (isInteractionFilter) {
        AdvancedSetting advSetting = getAdvancedSettingFromStr(advSettingStrVect);
        if (advSetting.isNodeChecked()) {
            retFilter = new NodeInteractionFilter(ServicesUtil.cyApplicationManagerServiceRef);
        } else {
            // advSetting.isEdgeChecked() == true
            retFilter = new EdgeInteractionFilter(ServicesUtil.cyApplicationManagerServiceRef);
        }
        retFilter.setAdvancedSetting(advSetting);
        getInteractionFilterFromStr((InteractionFilter) retFilter, filterStrVect, filters);
        return retFilter;
    }
    Collection<CompositeFilter> allFilters = new LinkedHashSet<CompositeFilter>();
    for (int i = 0; i < filterStrVect.size(); i++) {
        line = filterStrVect.get(i);
        if (line.startsWith("name=")) {
            String name = line.substring(5);
            retFilter.setName(name);
        }
        if (line.startsWith("Negation=true")) {
            retFilter.setNegation(true);
        }
        if (line.startsWith("Negation=false")) {
            retFilter.setNegation(false);
        }
        if (line.startsWith("StringFilter=")) {
            String _stringFilterValue = line.substring(13);
            String[] _values = _stringFilterValue.split(":");
            // controllingAttribute+":" + negation+ ":"+searchStr+":"+index_type;
            StringFilter _strFilter = new StringFilter(quickFind);
            _strFilter.setParent(retFilter);
            _strFilter.setControllingAttribute(_values[0]);
            _strFilter.setNegation((new Boolean(_values[1])).booleanValue());
            // handle the case where ':' is part of the search string
            String _searchStr = _stringFilterValue.substring(_values[0].length() + _values[1].length() + 2, _stringFilterValue.length() - _values[_values.length - 1].length() - 1);
            _strFilter.setSearchStr(_searchStr);
            _strFilter.setIndexType((new Integer(_values[_values.length - 1])).intValue());
            retFilter.addChild(_strFilter);
        }
        if (line.startsWith("NumericFilter=")) {
            String[] _values = line.substring(14).split(":");
            // controllingAttribute + ":" + negation+ ":"+lowBound+":" +
            // highBound+ ":"+index_type;
            // Determine data type of the attribute
            String dataType = "int";
            if (_values[2].indexOf(".") >= 0 || _values[2].indexOf("E") >= 0 || _values[3].indexOf(".") >= 0 || _values[3].indexOf("E") >= 0) {
                dataType = "double";
            }
            if (dataType.equalsIgnoreCase("double")) {
                NumericFilter<Double> _numFilter = new NumericFilter<Double>(quickFind);
                _numFilter.setParent(retFilter);
                _numFilter.setControllingAttribute(_values[0]);
                _numFilter.setNegation((new Boolean(_values[1])).booleanValue());
                _numFilter.setLowBound(Double.valueOf(_values[2]));
                _numFilter.setHighBound(Double.valueOf(_values[3]));
                _numFilter.setIndexType((new Integer(_values[4])).intValue());
                retFilter.addChild(_numFilter);
            } else {
                // dataType = "int"
                NumericFilter<Integer> _numFilter = new NumericFilter<Integer>(quickFind);
                _numFilter.setParent(retFilter);
                _numFilter.setControllingAttribute(_values[0]);
                _numFilter.setNegation((new Boolean(_values[1])).booleanValue());
                _numFilter.setLowBound(Integer.valueOf(_values[2]));
                _numFilter.setHighBound(Integer.valueOf(_values[3]));
                _numFilter.setIndexType((new Integer(_values[4])).intValue());
                retFilter.addChild(_numFilter);
            }
        }
        if (line.startsWith("CompositeFilter=")) {
            // e.g. CompositeFilter=AAA:true
            String[] _values = line.substring(16).split(":");
            String name = _values[0].trim();
            String notValue = _values[1].trim();
            // get the reference CompositeFilter
            CompositeFilter cmpFilter = null;
            for (CompositeFilter cf : allFilters) {
                if (cf.getName().equalsIgnoreCase(name)) {
                    cmpFilter = cf;
                    break;
                }
            }
            if (cmpFilter != null) {
                retFilter.addChild(cmpFilter, (new Boolean(notValue)).booleanValue());
            }
        }
        if (line.startsWith("TopologyFilter=")) {
            // e.g. TopologyFilter=AAA:true
            String[] _values = line.substring(15).split(":");
            String name = _values[0].trim();
            String notValue = _values[1].trim();
            // get the reference TopologyFilter
            TopologyFilter topoFilter = null;
            for (CompositeFilter cf : allFilters) {
                if (cf.getName().equalsIgnoreCase(name)) {
                    topoFilter = (TopologyFilter) cf;
                    break;
                }
            }
            if (topoFilter != null) {
                retFilter.addChild(topoFilter, (new Boolean(notValue)).booleanValue());
            }
        }
        if (line.startsWith("InteractionFilter=")) {
            // e.g. InteractionFilter=AAA:true
            String[] _values = line.substring(15).split(":");
            String name = _values[0].trim();
            String notValue = _values[1].trim();
            // get the reference InteractionFilter
            InteractionFilter interactionFilter = null;
            for (CompositeFilter cf : allFilters) {
                if (cf.getName().equalsIgnoreCase(name)) {
                    interactionFilter = (InteractionFilter) cf;
                    break;
                }
            }
            if (interactionFilter != null) {
                retFilter.addChild(interactionFilter, (new Boolean(notValue)).booleanValue());
            }
        }
    }
    return retFilter;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CompositeFilter(org.cytoscape.filter.internal.filters.model.CompositeFilter) NumericFilter(org.cytoscape.filter.internal.filters.model.NumericFilter) ArrayList(java.util.ArrayList) EdgeInteractionFilter(org.cytoscape.filter.internal.filters.model.EdgeInteractionFilter) AdvancedSetting(org.cytoscape.filter.internal.filters.model.AdvancedSetting) NodeInteractionFilter(org.cytoscape.filter.internal.filters.model.NodeInteractionFilter) InteractionFilter(org.cytoscape.filter.internal.filters.model.InteractionFilter) EdgeInteractionFilter(org.cytoscape.filter.internal.filters.model.EdgeInteractionFilter) NodeInteractionFilter(org.cytoscape.filter.internal.filters.model.NodeInteractionFilter) StringFilter(org.cytoscape.filter.internal.filters.model.StringFilter) TopologyFilter(org.cytoscape.filter.internal.filters.model.TopologyFilter)

Aggregations

EdgeInteractionFilter (org.cytoscape.filter.internal.filters.model.EdgeInteractionFilter)3 InteractionFilter (org.cytoscape.filter.internal.filters.model.InteractionFilter)3 NodeInteractionFilter (org.cytoscape.filter.internal.filters.model.NodeInteractionFilter)3 TopologyFilter (org.cytoscape.filter.internal.filters.model.TopologyFilter)3 CompositeFilter (org.cytoscape.filter.internal.filters.model.CompositeFilter)2 GridBagConstraints (java.awt.GridBagConstraints)1 Insets (java.awt.Insets)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 JComboBox (javax.swing.JComboBox)1 AdvancedSetting (org.cytoscape.filter.internal.filters.model.AdvancedSetting)1 NumericFilter (org.cytoscape.filter.internal.filters.model.NumericFilter)1 StringFilter (org.cytoscape.filter.internal.filters.model.StringFilter)1 CyNetwork (org.cytoscape.model.CyNetwork)1