Search in sources :

Example 6 with ListMultipleSelection

use of org.cytoscape.work.util.ListMultipleSelection in project cytoscape-impl by cytoscape.

the class ListMultipleTunableHandler method processArg.

public Object processArg(String arg) throws Exception {
    ListMultipleSelection lss = (ListMultipleSelection) getValue();
    String[] options = arg.split("(?<!\\\\),");
    if (options.length > 0) {
        if (Arrays.asList(options).contains("\\,")) {
            for (int i = 0; i < options.length; i++) if (options[i].equals("\\,")) {
                options[i] = ",";
                break;
            }
        }
    }
    // At this point, we have an array of strings, but the tunable might
    // not be a string tunable.  Create a list of appropriately typed
    // values by using toString() to match
    List<Object> optionList = new ArrayList<Object>();
    for (Object t : lss.getPossibleValues()) {
        for (String s : options) {
            if (s.equals(t.toString())) {
                optionList.add(t);
                break;
            }
        }
    }
    lss.setSelectedValues(optionList);
    return lss;
}
Also used : ListMultipleSelection(org.cytoscape.work.util.ListMultipleSelection)

Example 7 with ListMultipleSelection

use of org.cytoscape.work.util.ListMultipleSelection in project cytoscape-impl by cytoscape.

the class MapTableToNetworkTablesTask method initTunable.

private void initTunable(CyNetworkManager networkManage) {
    final List<TableType> options = new ArrayList<TableType>();
    for (TableType type : TableType.values()) options.add(type);
    dataTypeOptions = new ListSingleSelection<TableType>(options);
    dataTypeOptions.setSelectedValue(TableType.NODE_ATTR);
    for (CyNetwork net : networkManage.getNetworkSet()) {
        String netName = net.getRow(net).get(CyNetwork.NAME, String.class);
        name2NetworkMap.put(netName, net);
    }
    List<String> names = new ArrayList<String>();
    names.addAll(name2NetworkMap.keySet());
    if (names.isEmpty())
        networkList = new ListMultipleSelection<String>(NO_NETWORKS);
    else
        networkList = new ListMultipleSelection<String>(names);
}
Also used : ArrayList(java.util.ArrayList) ListMultipleSelection(org.cytoscape.work.util.ListMultipleSelection) CyNetwork(org.cytoscape.model.CyNetwork)

Example 8 with ListMultipleSelection

use of org.cytoscape.work.util.ListMultipleSelection in project cytoscape-impl by cytoscape.

the class MergeTablesTask method initTunable.

private final void initTunable(final CyTableManager tabelMgr, final CyNetworkManager networkManager) {
    final List<CyTable> listOfTables = new ArrayList<>();
    final List<Object> listOfUTables = new ArrayList<>();
    for (CyTable tempTable : tabelMgr.getGlobalTables()) {
        if (tempTable.isPublic()) {
            listOfTables.add(tempTable);
            listOfUTables.add(tempTable);
        }
    }
    final Set<CyNetwork> networkSet = networkManager.getNetworkSet();
    if (!networkSet.isEmpty()) {
        whereMergeTable = new ListSingleSelection<>(NETWORK_COLLECTION, NETWORK_SELECTION, UNASSIGNED_TABLE);
        whereMergeTable.setSelectedValue(NETWORK_COLLECTION);
        final List<TableType> options = new ArrayList<>();
        for (TableType type : TableType.values()) options.add(type);
        dataTypeTargetForNetworkCollection = new ListSingleSelection<>(options);
        dataTypeTargetForNetworkCollection.setSelectedValue(TableType.NODE_ATTR);
        dataTypeTargetForNetworkList = new ListSingleSelection<>(options);
        dataTypeTargetForNetworkList.setSelectedValue(TableType.NODE_ATTR);
        for (CyNetwork net : networkSet) {
            String netName = net.getRow(net).get(CyNetwork.NAME, String.class);
            name2NetworkMap.put(netName, net);
        }
        final List<String> names = new ArrayList<>();
        names.addAll(name2NetworkMap.keySet());
        sort(names);
        if (names.isEmpty())
            targetNetworkList = new ListMultipleSelection<>(NO_NETWORKS);
        else
            targetNetworkList = new ListMultipleSelection<>(names);
        for (CyNetwork net : networkSet) {
            final CyRootNetwork rootNet = rootNetworkManager.getRootNetwork(net);
            if (!name2RootMap.containsValue(rootNet))
                name2RootMap.put(rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class), rootNet);
        }
        final List<String> rootNames = new ArrayList<>();
        rootNames.addAll(name2RootMap.keySet());
        sort(rootNames);
        targetNetworkCollection = new ListSingleSelection<>(rootNames);
        if (!rootNames.isEmpty()) {
            targetNetworkCollection.setSelectedValue(rootNames.get(0));
            targetKeyNetworkCollection = getKeyColumnList(name2RootMap.get(targetNetworkCollection.getSelectedValue()), dataTypeTargetForNetworkCollection.getSelectedValue(), CyRootNetwork.SHARED_ATTRS);
        }
        for (CyNetwork network : networkSet) {
            listOfTables.add(network.getDefaultNodeTable());
            listOfTables.add(network.getDefaultEdgeTable());
        }
    } else {
        whereMergeTable = new ListSingleSelection<>(UNASSIGNED_TABLE);
        whereMergeTable.setSelectedValue(UNASSIGNED_TABLE);
    }
    sourceTable = new ListSingleSelection<>(listOfTables);
    if (!isTableGlobal(sourceTable.getSelectedValue())) {
        mergeType = new ListSingleSelection<>(COPY_COLUMNS);
    } else {
        mergeType = new ListSingleSelection<>(COPY_COLUMNS, LINK_COLUMNS);
        mergeType.setSelectedValue(COPY_COLUMNS);
    }
    sourceMergeColumns = getColumnList(sourceTable.getSelectedValue());
    sourceMergeKey = getKeyColumnList(sourceTable.getSelectedValue());
    if (listOfUTables.size() > 1) {
        if (listOfUTables.contains(sourceTable.getSelectedValue()))
            listOfUTables.remove(sourceTable.getSelectedValue());
        unassignedTable = new ListSingleSelection<>(listOfUTables);
        targetMergeKey = getKeyColumnList((CyTable) unassignedTable.getSelectedValue());
    } else {
        listOfUTables.clear();
        listOfUTables.add(NO_TABLES);
        targetMergeKey = new ListSingleSelection<>(NO_TABLES);
        unassignedTable = new ListSingleSelection<>(listOfUTables);
    }
}
Also used : ArrayList(java.util.ArrayList) ListMultipleSelection(org.cytoscape.work.util.ListMultipleSelection) CyNetwork(org.cytoscape.model.CyNetwork) CyTable(org.cytoscape.model.CyTable) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 9 with ListMultipleSelection

use of org.cytoscape.work.util.ListMultipleSelection in project cytoscape-impl by cytoscape.

the class MergeTablesTask method getColumnList.

private ListMultipleSelection<String> getColumnList(final CyTable table) {
    String tempName = null;
    final List<String> colNames = new ArrayList<>();
    for (CyColumn col : table.getColumns()) {
        tempName = col.getName();
        if (!tempName.matches(CyRootNetwork.SHARED_NAME) && !tempName.matches(CyRootNetwork.NAME) && !tempName.matches(CyRootNetwork.SUID) && !tempName.matches(CyRootNetwork.SELECTED))
            colNames.add(tempName);
    }
    sort(colNames);
    ListMultipleSelection<String> columns = new ListMultipleSelection<>(colNames);
    return columns;
}
Also used : ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn) ListMultipleSelection(org.cytoscape.work.util.ListMultipleSelection)

Example 10 with ListMultipleSelection

use of org.cytoscape.work.util.ListMultipleSelection in project cytoscape-impl by cytoscape.

the class MergeTablesTaskFactoryImpl method createTaskIterator.

@Override
public TaskIterator createTaskIterator(final CyTable sourceTable, final CyTable targetTable, List<String> sourceColumnsList, String sourceKeyColumn, boolean mergeColumnVirtual, boolean mapToNetworks, boolean selectedNetworksOnly, List<CyNetwork> networkList, CyRootNetwork rootNetwork, CyColumn targetJoinColumn, Class<? extends CyIdentifiable> type) {
    TableType tableType = getTableType(type);
    if (tableType == null)
        throw new IllegalArgumentException("The specified type " + type + " is not acceptable.");
    ListSingleSelection<TableType> tableTypes = new ListSingleSelection<TableType>(tableType);
    tableTypes.setSelectedValue(tableType);
    List<String> networkNames = new ArrayList<String>();
    if (networkList != null) {
        for (CyNetwork net : networkList) {
            networkNames.add(net.getRow(net).get(CyNetwork.NAME, String.class));
        }
    }
    ListMultipleSelection<String> networksListTunable = new ListMultipleSelection<String>(networkNames);
    networksListTunable.setSelectedValues(networkNames);
    List<String> rootNetworkNames = new ArrayList<String>();
    ListSingleSelection<String> rootNetworkList = new ListSingleSelection<String>();
    if (rootNetwork != null) {
        rootNetworkNames.add(rootNetwork.getRow(rootNetwork).get(CyNetwork.NAME, String.class));
        rootNetworkList = new ListSingleSelection<String>(rootNetworkNames);
        rootNetworkList.setSelectedValue(rootNetworkNames.get(0));
    }
    List<String> columnNames = new ArrayList<String>();
    ListSingleSelection<String> columnNamesList = new ListSingleSelection<String>();
    if (targetJoinColumn != null) {
        columnNames.add(targetJoinColumn.getName());
        columnNamesList = new ListSingleSelection<String>(columnNames);
        columnNamesList.setSelectedValue(columnNames.get(0));
    }
    final Map<String, Object> m = new HashMap<String, Object>();
    ListSingleSelection<String> chooser = new ListSingleSelection<String>(MergeTablesTask.NETWORK_COLLECTION, MergeTablesTask.NETWORK_SELECTION, MergeTablesTask.UNASSIGNED_TABLE);
    if (mapToNetworks) {
        if (selectedNetworksOnly)
            chooser.setSelectedValue(MergeTablesTask.NETWORK_SELECTION);
        else
            chooser.setSelectedValue(MergeTablesTask.NETWORK_COLLECTION);
    } else
        chooser.setSelectedValue(MergeTablesTask.UNASSIGNED_TABLE);
    ListSingleSelection<CyTable> sourceTableList = new ListSingleSelection<CyTable>(sourceTable);
    sourceTableList.setSelectedValue(sourceTable);
    ListSingleSelection<Object> targetTableList;
    if (targetTable != null) {
        targetTableList = new ListSingleSelection<Object>(targetTable);
        targetTableList.setSelectedValue(targetTable);
    } else {
        targetTableList = new ListSingleSelection<Object>(MergeTablesTask.NO_TABLES);
        targetTableList.setSelectedValue(MergeTablesTask.NO_TABLES);
    }
    ListMultipleSelection<String> sourceColNames = new ListMultipleSelection<String>(sourceColumnsList);
    sourceColNames.setSelectedValues(sourceColumnsList);
    ListSingleSelection<String> sourceColumn = new ListSingleSelection<String>(sourceKeyColumn);
    sourceColumn.setSelectedValue(sourceKeyColumn);
    m.put("MergeType", mergeColumnVirtual);
    m.put("SourceMergeKey", sourceColumn);
    m.put("TargetMergeKey", columnNamesList);
    m.put("SourceTable", sourceTableList);
    m.put("UnassignedTable", targetTableList);
    m.put("SourceMergeColumns", sourceColNames);
    m.put("WhereMergeTable", chooser);
    m.put("TargetNetworkList", networksListTunable);
    m.put("TargetKeyNetworkCollection", columnNamesList);
    m.put("TargetNetworkCollection", rootNetworkList);
    m.put("DataTypeTargetForNetworkCollection", tableTypes);
    m.put("DataTypeTargetForNetworkList", tableTypes);
    return tunableSetter.createTaskIterator(createTaskIterator(), m);
}
Also used : TableType(org.cytoscape.task.internal.table.MapTableToNetworkTablesTask.TableType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ListMultipleSelection(org.cytoscape.work.util.ListMultipleSelection) CyNetwork(org.cytoscape.model.CyNetwork) CyTable(org.cytoscape.model.CyTable) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection)

Aggregations

ListMultipleSelection (org.cytoscape.work.util.ListMultipleSelection)13 ArrayList (java.util.ArrayList)10 CyNetwork (org.cytoscape.model.CyNetwork)7 ListSingleSelection (org.cytoscape.work.util.ListSingleSelection)6 HashMap (java.util.HashMap)5 CyTable (org.cytoscape.model.CyTable)4 TableType (org.cytoscape.task.internal.table.MapTableToNetworkTablesTask.TableType)3 List (java.util.List)2 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)2 Properties (java.util.Properties)1 EdgeList (org.cytoscape.command.util.EdgeList)1 NodeList (org.cytoscape.command.util.NodeList)1 CyColumn (org.cytoscape.model.CyColumn)1 TableType (org.cytoscape.task.internal.table.ImportTableDataTask.TableType)1 TunableSetter (org.cytoscape.work.TunableSetter)1 BoundedInteger (org.cytoscape.work.util.BoundedInteger)1 Test (org.junit.Test)1