Search in sources :

Example 21 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class NetworkMainPanel method addNetwork.

// // Private Methods // //
protected SubNetworkPanel addNetwork(final CySubNetwork network) {
    final CyRootNetwork rootNetwork = network.getRootNetwork();
    RootNetworkPanel rootNetPanel = getRootNetworkPanel(rootNetwork);
    if (rootNetPanel == null) {
        rootNetPanel = getRootNetworkListPanel().addItem(rootNetwork);
        setKeyBindings(rootNetPanel);
        new NetworkDropListener(rootNetwork);
        final RootNetworkPanel item = rootNetPanel;
        item.addPropertyChangeListener("expanded", e -> {
            // Deselect its selected subnetworks first
            if (e.getNewValue() == Boolean.FALSE) {
                final List<AbstractNetworkPanel<?>> selectedItems = getSelectedItems();
                if (!selectedItems.isEmpty()) {
                    selectedItems.removeAll(item.getAllItems());
                    setSelectedItems(selectedItems);
                }
            }
            updateCollapseExpandButtons();
        });
        item.addPropertyChangeListener("selected", e -> {
            if (!ignoreSelectionEvents) {
                final boolean selected = (boolean) e.getNewValue();
                final Set<CyRootNetwork> oldSelection = getSelectedRootNetworks();
                if (// Then it did not belong to the old selection value
                selected)
                    oldSelection.remove(item.getModel().getNetwork());
                else
                    // It means it was selected before
                    oldSelection.add(item.getModel().getNetwork());
                fireSelectedRootNetworksChange(oldSelection);
            }
        });
        firePropertyChange("rootNetworkPanelCreated", null, item);
    }
    final SubNetworkPanel subNetPanel = rootNetPanel.addItem(network);
    setKeyBindings(subNetPanel);
    subNetPanel.addPropertyChangeListener("selected", (PropertyChangeEvent e) -> {
        if (!ignoreSelectionEvents) {
            updateNetworkSelectionLabel();
            final boolean selected = (boolean) e.getNewValue();
            final Set<CyNetwork> oldSelection = getSelectedNetworks(false);
            if (// Then it did not belong to the old selection value
            selected)
                oldSelection.remove(subNetPanel.getModel().getNetwork());
            else
                // It means it was selected before
                oldSelection.add(subNetPanel.getModel().getNetwork());
            fireSelectedSubNetworksChange(oldSelection);
        }
    });
    // TODO Uncomment when multiple views support is enabled
    // subNetPanel.getViewIconLabel().addMouseListener(new MouseAdapter() {
    // @Override
    // public void mousePressed(MouseEvent e) {
    // maybeShowViewPopup(subNetPanel);
    // }
    // });
    firePropertyChange("subNetworkPanelCreated", null, subNetPanel);
    // Scroll to new item
    rootNetPanel.expand();
    scrollTo(network);
    nameTables.put(network.getDefaultNetworkTable(), network);
    nodeEdgeTables.put(network.getDefaultNodeTable(), network);
    nodeEdgeTables.put(network.getDefaultEdgeTable(), network);
    return subNetPanel;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) CyNetwork(org.cytoscape.model.CyNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 22 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class NetworkMainPanel method getSubNetworkPanel.

SubNetworkPanel getSubNetworkPanel(final CyNetwork net) {
    if (net instanceof CySubNetwork) {
        final CySubNetwork subNet = (CySubNetwork) net;
        final CyRootNetwork rootNet = subNet.getRootNetwork();
        final RootNetworkPanel rootNetPanel = getRootNetworkPanel(rootNet);
        if (rootNetPanel != null)
            return rootNetPanel.getItem(subNet);
    }
    return null;
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 23 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class TableBrowserToolBar method createNewAttribute.

private void createNewAttribute(final String type, boolean isShared) {
    try {
        final String[] existingAttrs = getAttributeArray();
        String newAttribName = null;
        do {
            newAttribName = JOptionPane.showInputDialog(this, "Column Name: ", "Create New " + type + " Column", JOptionPane.QUESTION_MESSAGE);
            if (newAttribName == null)
                return;
            newAttribName = newAttribName.trim();
            if (newAttribName.isEmpty()) {
                JOptionPane.showMessageDialog(null, "Column name must not be blank.", "Error", JOptionPane.ERROR_MESSAGE);
                newAttribName = null;
            } else if (Arrays.binarySearch(existingAttrs, newAttribName) >= 0) {
                JOptionPane.showMessageDialog(null, "Column " + newAttribName + " already exists.", "Error", JOptionPane.ERROR_MESSAGE);
                newAttribName = null;
            }
        } while (newAttribName == null);
        final CyTable attrs;
        if (isShared) {
            final CyNetwork network = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
            if (network instanceof CySubNetwork) {
                final CyRootNetwork rootNetwork = ((CySubNetwork) network).getRootNetwork();
                CyTable sharedTable = null;
                if (this.objType == CyNode.class)
                    sharedTable = rootNetwork.getSharedNodeTable();
                else if (this.objType == CyEdge.class)
                    sharedTable = rootNetwork.getSharedEdgeTable();
                else if (this.objType == CyNetwork.class)
                    sharedTable = rootNetwork.getSharedNetworkTable();
                else
                    throw new IllegalStateException("Object type is not valid.  This should not happen.");
                attrs = sharedTable;
            } else {
                throw new IllegalArgumentException("This is not a CySubNetwork and there is no shared table.");
            }
        } else {
            attrs = browserTableModel.getDataTable();
        }
        if (type.equals("String"))
            attrs.createColumn(newAttribName, String.class, false);
        else if (type.equals("Floating Point"))
            attrs.createColumn(newAttribName, Double.class, false);
        else if (type.equals("Integer"))
            attrs.createColumn(newAttribName, Integer.class, false);
        else if (type.equals("Long Integer"))
            attrs.createColumn(newAttribName, Long.class, false);
        else if (type.equals("Boolean"))
            attrs.createColumn(newAttribName, Boolean.class, false);
        else if (type.equals("String List"))
            attrs.createListColumn(newAttribName, String.class, false);
        else if (type.equals("Floating Point List"))
            attrs.createListColumn(newAttribName, Double.class, false);
        else if (type.equals("Integer List"))
            attrs.createListColumn(newAttribName, Integer.class, false);
        else if (type.equals("Long Integer List"))
            attrs.createListColumn(newAttribName, Long.class, false);
        else if (type.equals("Boolean List"))
            attrs.createListColumn(newAttribName, Boolean.class, false);
        else
            throw new IllegalArgumentException("unknown column type \"" + type + "\".");
    } catch (IllegalArgumentException e) {
        JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 24 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class ClipboardImpl method pasteNode.

// TODO: Need to figure out how to copy LOCAL_ATTRS, SHARED_ATTRS, and HIDDEN_ATTRS
// The latter is easy.  The second two are both part of the DEFAULT_ATTRS, but it's
// not clear how to create a local attribute specifically....
private CyNode pasteNode(CyNetworkView sourceView, CyNetworkView targetView, CyNode node, Map<CyRow, CyRow> rowMap) {
    CyNetwork sourceNetwork = sourceView.getModel();
    CyRootNetwork sourceRoot = ((CySubNetwork) sourceNetwork).getRootNetwork();
    CySubNetwork targetNetwork = (CySubNetwork) targetView.getModel();
    CyRootNetwork targetRoot = targetNetwork.getRootNetwork();
    CyNode newNode = null;
    // 3) We're copying nodes to a new location in the same network
    if (sourceRoot != targetRoot) {
        // Case 1: Different roots
        newNode = targetNetwork.addNode();
        // Copy the attributes over
        rowMap.put(oldSharedRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.DEFAULT_ATTRS));
        rowMap.put(oldLocalRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.LOCAL_ATTRS));
        rowMap.put(oldHiddenRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.HIDDEN_ATTRS));
    } else if (!targetNetwork.containsNode(node)) {
        // Case 2: different subnetwork, same root
        targetNetwork.addNode(node);
        newNode = node;
        // rowMap.put(oldSharedRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.DEFAULT_ATTRS));
        rowMap.put(oldLocalRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.LOCAL_ATTRS));
        rowMap.put(oldHiddenRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.HIDDEN_ATTRS));
    } else {
        // Case 3: Copying the node to the same network
        // newNode = targetNetwork.addNode();
        // Copy in the hidden attributes
        newNode = targetNetwork.addNode();
        rowMap.put(oldHiddenRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.HIDDEN_ATTRS));
        // Copy in the local attributes
        rowMap.put(oldLocalRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.LOCAL_ATTRS));
    // Copy in the default attributes
    // rowMap.put(oldSharedRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.DEFAULT_ATTRS));
    // targetNetwork.addNode(node);
    }
    return newNode;
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 25 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class CyGroupManagerImpl method updateGroupAttribute.

private void updateGroupAttribute(CyGroup group) {
    CyRootNetwork rootNet = group.getRootNetwork();
    // Get the network row
    CyRow rhRow = rootNet.getRow(rootNet, CyNetwork.HIDDEN_ATTRS);
    if (rhRow.getTable().getColumn(GROUP_LIST_ATTRIBUTE) == null) {
        rhRow.getTable().createListColumn(GROUP_LIST_ATTRIBUTE, Long.class, false);
    }
    List<Long> groupSUIDs = new ArrayList<Long>();
    for (CyGroup g : getGroupSet(rootNet)) {
        groupSUIDs.add(g.getGroupNode().getSUID());
    }
    rhRow.set(GROUP_LIST_ATTRIBUTE, groupSUIDs);
}
Also used : CyGroup(org.cytoscape.group.CyGroup) ArrayList(java.util.ArrayList) CyRow(org.cytoscape.model.CyRow) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Aggregations

CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)83 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)37 CyNetwork (org.cytoscape.model.CyNetwork)36 CyNode (org.cytoscape.model.CyNode)28 CyEdge (org.cytoscape.model.CyEdge)15 CyRow (org.cytoscape.model.CyRow)15 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)15 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)13 CyTable (org.cytoscape.model.CyTable)11 CyNetworkView (org.cytoscape.view.model.CyNetworkView)11 CyGroup (org.cytoscape.group.CyGroup)7 HashSet (java.util.HashSet)6 Dimension (java.awt.Dimension)4 IOException (java.io.IOException)4 CyNetworkManager (org.cytoscape.model.CyNetworkManager)4 Image (java.awt.Image)3 BufferedImage (java.awt.image.BufferedImage)3 CyApplicationManager (org.cytoscape.application.CyApplicationManager)3 CyEventHelper (org.cytoscape.event.CyEventHelper)3