use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class VirtualColumnAdder method handleEvent.
public void handleEvent(ColumnCreatedEvent e) {
CyTable src = e.getSource();
List<CyTable> targets;
synchronized (lock) {
targets = tables.get(src);
}
String srcName = e.getColumnName();
CyColumn srcCol = src.getColumn(srcName);
for (CyTable tgt : targets) tgt.addVirtualColumn(srcName, srcName, src, CyIdentifiable.SUID, srcCol.isImmutable());
}
use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class CyTableImpl method setListX.
private final void setListX(final Object key, final String columnName, final Object value) {
Object newValue;
final Object rawValue;
synchronized (lock) {
final String normalizedColName = normalizeColumnName(columnName);
final CyColumn column = types.get(normalizedColName);
CyRow row = rows.get(key);
final Class<?> type = column.getListElementType();
if (value instanceof CyListImpl) {
rawValue = value;
} else if (value instanceof List) {
final List list = (List) value;
if (!list.isEmpty())
checkType(list.get(0));
List<?> listData = columnFactory.createList(type, list);
rawValue = new CyListImpl(type, listData, eventHelper, row, column, this);
} else if (!(value instanceof Equation)) {
throw new IllegalArgumentException("value is a " + value.getClass().getName() + " and not a List for column '" + columnName + "'.");
} else if (!EqnSupport.listEquationIsCompatible((Equation) value, type)) {
throw new IllegalArgumentException("value is not a List equation of a compatible type for column '" + columnName + "'.");
} else {
rawValue = value;
}
final VirtualColumn virtColumn = virtualColumnMap.get(normalizedColName);
if (virtColumn != null) {
virtColumn.setValue(key, rawValue);
newValue = virtColumn.getListValue(key);
} else {
ColumnData keyToValueMap = attributes.get(normalizedColName);
// TODO this is an implicit addRow - not sure if we want to refactor this or not
keyToValueMap.put(key, rawValue);
if (rawValue instanceof Equation) {
final StringBuilder errorMsg = new StringBuilder();
newValue = EqnSupport.evalEquation((Equation) rawValue, suid, interpreter, currentlyActiveAttributes, columnName, errorMsg, this);
lastInternalError = errorMsg.toString();
} else {
newValue = rawValue;
}
}
}
if (fireEvents)
eventHelper.addEventPayload((CyTable) this, new RowSetRecord(getRow(key), columnName, newValue, rawValue), RowsSetEvent.class);
}
use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class ControlPanel method handleEvent.
@Override
public void handleEvent(RowsSetEvent e) {
if (loadingSession)
return;
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
final CyNetworkView currentView = appMgr.getCurrentNetworkView();
if (currentView == null)
return;
final CyTable tbl = e.getSource();
final CyNetworkTableManager netTblMgr = serviceRegistrar.getService(CyNetworkTableManager.class);
final CyNetwork net = netTblMgr.getNetworkForTable(tbl);
if (net == null || !net.equals(currentView.getModel()) || !tbl.equals(net.getDefaultNodeTable()))
return;
final Collection<RowSetRecord> selectedRecords = e.getColumnRecords(CyNetwork.SELECTED);
if (!selectedRecords.isEmpty())
updatePanels();
}
use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class FitLabelMappingGenerator method generateMap.
@Override
public <T> Map<T, V> generateMap(final Set<T> tableValues) {
// Generate map for the current network view.
final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
final CyNetworkView networkView = appMgr.getCurrentNetworkView();
// If current view is not available, simply return empty map.
if (networkView == null)
return Collections.emptyMap();
// If given set is empty, return empty map.
if (tableValues == null || tableValues.isEmpty())
return Collections.emptyMap();
// This only works with NAME column.
final T testName = tableValues.iterator().next();
if (testName instanceof String == false)
throw new IllegalArgumentException("This generator only works with 'name' column.");
final CyNetwork network = networkView.getModel();
final CyTable nodeTable = networkView.getModel().getDefaultNodeTable();
final VisualMappingManager vmMgr = servicesUtil.get(VisualMappingManager.class);
final VisualStyle style = vmMgr.getCurrentVisualStyle();
// Check label size mapping exists or not
final VisualMappingFunction<?, Integer> fontSizeMapping = style.getVisualMappingFunction(BasicVisualLexicon.NODE_LABEL_FONT_SIZE);
// Use default label width for checking. TODO: should we use mapping?
final Double maxLabelWidth = style.getDefaultValue(BasicVisualLexicon.NODE_LABEL_WIDTH);
final Map<T, V> valueMap = new HashMap<T, V>();
for (final T attrVal : tableValues) {
final Collection<CyRow> rows = nodeTable.getMatchingRows(CyNetwork.NAME, attrVal);
CyRow row = null;
if (rows.isEmpty() == false)
row = rows.iterator().next();
else
continue;
final Long suid = row.get(CyIdentifiable.SUID, Long.class);
final View<CyNode> nodeView = networkView.getNodeView(network.getNode(suid));
if (nodeView == null)
continue;
final String labelText = nodeView.getVisualProperty(BasicVisualLexicon.NODE_LABEL);
final int textLen = labelText.length();
final int fontSize;
if (fontSizeMapping == null)
fontSize = style.getDefaultValue(BasicVisualLexicon.NODE_LABEL_FONT_SIZE);
else
fontSize = nodeView.getVisualProperty(BasicVisualLexicon.NODE_LABEL_FONT_SIZE);
final Double width = fontSize * textLen * 0.7;
if (maxLabelWidth > width)
valueMap.put(attrVal, (V) width);
else
valueMap.put(attrVal, (V) maxLabelWidth);
}
return valueMap;
}
use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class C2CEditor method setValue.
@Override
@SuppressWarnings("unchecked")
public void setValue(final Object value) {
if (value instanceof ContinuousMapping == false)
throw new IllegalArgumentException("Value should be ContinuousMapping: this is " + value);
final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
final CyNetwork currentNetwork = appMgr.getCurrentNetwork();
if (currentNetwork == null)
return;
mapping = (ContinuousMapping<K, V>) value;
Class<? extends CyIdentifiable> type = (Class<? extends CyIdentifiable>) mapping.getVisualProperty().getTargetDataType();
final CyNetworkTableManager netTblMgr = servicesUtil.get(CyNetworkTableManager.class);
final CyTable attr = netTblMgr.getTable(appMgr.getCurrentNetwork(), type, CyNetwork.DEFAULT_ATTRS);
final VisualMappingManager vmMgr = servicesUtil.get(VisualMappingManager.class);
editorPanel = new C2CMappingEditorPanel<K, V>(vmMgr.getCurrentVisualStyle(), mapping, attr, servicesUtil);
}
Aggregations