use of org.cytoscape.work.util.ListSingleSelection in project cytoscape-api by cytoscape.
the class AbstractCyNetworkReader method getTargetColumns.
private final ListSingleSelection<String> getTargetColumns(final CyNetwork network) {
final CyTable selectedTable = network.getTable(CyNode.class, CyRootNetwork.SHARED_ATTRS);
final List<String> colNames = new ArrayList<>();
for (CyColumn col : selectedTable.getColumns()) {
// Exclude SUID from the mapping key list
if (!col.getName().equalsIgnoreCase(CyIdentifiable.SUID) && !col.getName().endsWith(".SUID") && (col.getType() == String.class || col.getType() == Integer.class || col.getType() == Long.class))
colNames.add(col.getName());
}
if (colNames.isEmpty() || (colNames.size() == 1 && colNames.contains(CyRootNetwork.SHARED_NAME)))
return new ListSingleSelection<>();
sort(colNames);
return new ListSingleSelection<>(colNames);
}
use of org.cytoscape.work.util.ListSingleSelection in project cytoscape-impl by cytoscape.
the class NetworkCollectionHelper method getTargetColumns.
public ListSingleSelection<String> getTargetColumns(final CyNetwork network) {
final CyTable selectedTable = network.getTable(CyNode.class, CyRootNetwork.SHARED_ATTRS);
final List<String> colNames = new ArrayList<>();
for (CyColumn col : selectedTable.getColumns()) {
// Exclude SUID from the mapping key list
if (!col.getName().equalsIgnoreCase(CyIdentifiable.SUID) && !col.getName().endsWith(".SUID") && (col.getType() == String.class || col.getType() == Integer.class || col.getType() == Long.class))
colNames.add(col.getName());
}
if (colNames.isEmpty() || (colNames.size() == 1 && colNames.contains(CyRootNetwork.SHARED_NAME)))
return new ListSingleSelection<>();
sort(colNames);
ListSingleSelection<String> targetColumns = new ListSingleSelection<>(colNames);
if (targetColumns.getPossibleValues().contains(CyRootNetwork.SHARED_NAME))
targetColumns.setSelectedValue(CyRootNetwork.SHARED_NAME);
return targetColumns;
}
use of org.cytoscape.work.util.ListSingleSelection in project cytoscape-impl by cytoscape.
the class NetworkCollectionHelper method init.
void init() {
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
final CyRootNetworkManager rootNetMgr = serviceRegistrar.getService(CyRootNetworkManager.class);
// initialize the network Collection
name2RootMap = getRootNetworkMap();
final List<String> rootNames = new ArrayList<>();
rootNames.addAll(name2RootMap.keySet());
if (!rootNames.isEmpty()) {
sort(rootNames);
rootNames.add(0, CREATE_NEW_COLLECTION_STRING);
}
rootNetworkList = new ListSingleSelection<>(rootNames);
final CyNetwork net = appMgr != null ? appMgr.getCurrentNetwork() : null;
final CyRootNetwork rootNet = net != null ? rootNetMgr.getRootNetwork(net) : null;
final String rootNetName = rootNet != null ? rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class) : CREATE_NEW_COLLECTION_STRING;
if (rootNames.contains(rootNetName))
rootNetworkList.setSelectedValue(rootNetName);
else if (rootNames.contains(CREATE_NEW_COLLECTION_STRING))
rootNetworkList.setSelectedValue(CREATE_NEW_COLLECTION_STRING);
if (rootNet != null)
targetColumnList = getTargetColumns(rootNet);
else
targetColumnList = new ListSingleSelection<>();
// initialize renderer list
final List<NetworkViewRenderer> renderers = new ArrayList<>();
final Set<NetworkViewRenderer> rendererSet = appMgr.getNetworkViewRendererSet();
// so the combo-box does not appear to the user, since there is nothing to select anyway.
if (rendererSet.size() > 1) {
renderers.addAll(rendererSet);
Collections.sort(renderers, new Comparator<NetworkViewRenderer>() {
@Override
public int compare(NetworkViewRenderer r1, NetworkViewRenderer r2) {
return r1.toString().compareToIgnoreCase(r2.toString());
}
});
}
rendererList = new ListSingleSelection<>(renderers);
final NetworkViewRenderer defViewRenderer = appMgr.getDefaultNetworkViewRenderer();
if (defViewRenderer != null && renderers.contains(defViewRenderer))
rendererList.setSelectedValue(defViewRenderer);
}
use of org.cytoscape.work.util.ListSingleSelection in project cytoscape-impl by cytoscape.
the class LoadMultipleNetworksTask method init.
private void init() {
// otherwise let the reader's tunables handle it.
if (readers != null && readers.size() > 1) {
// Initialize column list
if (rootNetwork != null)
setTargetColumnList(getTargetColumns(rootNetwork));
else
setTargetColumnList(new ListSingleSelection<>());
// Initialize renderer list
final List<NetworkViewRenderer> renderers = new ArrayList<>();
NetworkViewRenderer defViewRenderer = null;
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
final Set<NetworkViewRenderer> rendererSet = applicationManager.getNetworkViewRendererSet();
// so the combo-box does not appear to the user, since there is nothing to select anyway.
if (rendererSet.size() > 1) {
renderers.addAll(rendererSet);
Collections.sort(renderers, new Comparator<NetworkViewRenderer>() {
@Override
public int compare(NetworkViewRenderer r1, NetworkViewRenderer r2) {
return r1.toString().compareToIgnoreCase(r2.toString());
}
});
}
defViewRenderer = applicationManager.getDefaultNetworkViewRenderer();
rendererList = new ListSingleSelection<>(renderers);
if (defViewRenderer != null && renderers.contains(defViewRenderer))
rendererList.setSelectedValue(defViewRenderer);
}
}
use of org.cytoscape.work.util.ListSingleSelection in project cytoscape-impl by cytoscape.
the class LoadMultipleNetworksTask method run.
@Override
public void run(TaskMonitor taskMonitor) throws Exception {
this.taskMonitor = taskMonitor;
if (readers == null && readers.isEmpty())
throw new IllegalArgumentException("No network reader specified.");
taskMonitor.setTitle("Import Networks");
taskMonitor.setProgress(0.0);
final String rootNetName = rootNetwork != null ? rootNetwork.getRow(rootNetwork).get(CyRootNetwork.NAME, String.class) : null;
final String targetColumn = targetColumnList != null ? targetColumnList.getSelectedValue() : null;
final NetworkViewRenderer renderer = rendererList != null ? rendererList.getSelectedValue() : null;
final float total = readers.size();
int count = 1;
for (Entry<String, CyNetworkReader> entry : readers.entrySet()) {
if (cancelled)
return;
final CyNetworkReader r = entry.getValue();
if (r instanceof AbstractCyNetworkReader) {
AbstractCyNetworkReader ar = (AbstractCyNetworkReader) r;
if (rootNetName != null) {
ListSingleSelection<String> ls = new ListSingleSelection<>(Collections.singletonList(rootNetName));
ls.setSelectedValue(rootNetName);
ar.setRootNetworkList(ls);
} else {
// Force "create new collection"
ar.setRootNetworkList(new ListSingleSelection<>(Collections.emptyList()));
ar.setTargetColumnList(new ListSingleSelection<>(Collections.emptyList()));
}
if (targetColumn != null) {
ListSingleSelection<String> ls = new ListSingleSelection<>(Collections.singletonList(targetColumn));
ls.setSelectedValue(targetColumn);
ar.setTargetColumnList(ls);
}
if (renderer != null) {
ListSingleSelection<NetworkViewRenderer> ls = new ListSingleSelection<>(Collections.singletonList(renderer));
ls.setSelectedValue(renderer);
ar.setNetworkViewRendererList(ls);
}
}
name = entry.getKey();
loadNetwork(r);
taskMonitor.setProgress(count / total);
count++;
}
}
Aggregations