use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class CellEditorEventHandler method switchMappingType.
private VisualMappingFunction<?, ?> switchMappingType(final VizMapperProperty<?, ?, ?> prop, final VisualProperty<?> vp, final VisualMappingFunctionFactory oldFactory, final VisualMappingFunctionFactory newFactory, final String controllingAttrName, final PropertySheetPanel propertySheetPanel) {
// This is the currently selected Visual Style.
final VisualStyle style = servicesUtil.get(VisualMappingManager.class).getCurrentVisualStyle();
final VisualMappingFunction<?, ?> mapping = style.getVisualMappingFunction(vp);
VisualMappingFunction<?, ?> newMapping = mapping;
final Class<?> newMappingType = newFactory.getMappingFunctionType();
if (mapping == null || mapping.getClass() != newMappingType || !mapping.getMappingColumnName().equals(controllingAttrName)) {
final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
final CyNetwork currentNet = appMgr.getCurrentNetwork();
if (currentNet == null)
return newMapping;
// Mapping does not exist. Need to create new one.
final AttributeSet attrSet = attrProxy.getAttributeSet(currentNet, vp.getTargetDataType());
Class<?> attributeDataType = attrSet.getAttrMap().get(controllingAttrName);
if (attributeDataType == null) {
JOptionPane.showMessageDialog(null, "The current table does not have the selected column (\"" + controllingAttrName + "\").\nPlease select another column.", "Invalid Column.", JOptionPane.WARNING_MESSAGE);
prop.setValue(oldFactory);
return newMapping;
}
if (newMappingType == ContinuousMapping.class) {
if (!Number.class.isAssignableFrom(attributeDataType)) {
JOptionPane.showMessageDialog(null, "Selected column data type is not Number.\nPlease select a numerical column type.", "Incompatible Column Type.", JOptionPane.WARNING_MESSAGE);
prop.setValue(oldFactory);
return newMapping;
}
} else if (newMappingType == DiscreteMapping.class) {
if (attributeDataType == List.class)
attributeDataType = String.class;
}
// Create new mapping
newMapping = newFactory.createVisualMappingFunction(controllingAttrName, attributeDataType, vp);
// Keep old mapping values if the new mapping has the same type
if (oldFactory != null && oldFactory.getMappingFunctionType() == newMappingType)
copyMappingValues(mapping, newMapping);
}
// Disable listeners to avoid unnecessary updates
final PropertySheetTableModel model = (PropertySheetTableModel) propertySheetPanel.getTable().getModel();
final TableModelListener[] modelListeners = model.getTableModelListeners();
for (final TableModelListener tm : modelListeners) model.removeTableModelListener(tm);
vizMapPropertyBuilder.createMappingProperties(newMapping, propertySheetPanel, newFactory);
// Restore listeners
for (final TableModelListener tm : modelListeners) model.addTableModelListener(tm);
return newMapping;
}
use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class CellEditorEventHandler method switchColumn.
@SuppressWarnings("unchecked")
private VisualMappingFunction<?, ?> switchColumn(final VisualMappingFunctionFactory factory, final AttributeComboBoxPropertyEditor editor, final VizMapperProperty<?, ?, ?> prop, final String columnName, final PropertySheetPanel propertySheetPanel) {
final VisualStyle currentStyle = servicesUtil.get(VisualMappingManager.class).getCurrentVisualStyle();
final VisualProperty<?> vp = (VisualProperty<?>) prop.getKey();
VisualMappingFunction<?, ?> mapping = currentStyle.getVisualMappingFunction(vp);
// Ignore if not compatible.
final CyNetworkTableManager netTblMgr = servicesUtil.get(CyNetworkTableManager.class);
final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
Class<? extends CyIdentifiable> type = (Class<? extends CyIdentifiable>) editor.getTargetObjectType();
final CyTable table = netTblMgr.getTable(appMgr.getCurrentNetwork(), type, CyNetwork.DEFAULT_ATTRS);
final CyColumn column = table.getColumn(columnName);
if (column == null) {
JOptionPane.showMessageDialog(null, "The current table does not have the selected column (\"" + columnName + "\").\nPlease select another column.", "Invalid Column.", JOptionPane.WARNING_MESSAGE);
prop.setValue(mapping != null ? mapping.getMappingColumnName() : null);
return mapping;
}
final Class<?> dataType = column.getType();
if (factory != null && (mapping == null || !columnName.equals(mapping.getMappingColumnName()))) {
// Need to create new mapping function
if (ContinuousMapping.class.isAssignableFrom(factory.getMappingFunctionType()) && !Number.class.isAssignableFrom(dataType)) {
JOptionPane.showMessageDialog(null, "Continuous Mapper can be used with numbers only.\nPlease select a numerical column type.", "Incompatible Mapping Type.", JOptionPane.INFORMATION_MESSAGE);
prop.setValue(mapping != null ? mapping.getMappingColumnName() : null);
return mapping;
}
return switchMappingType(prop, vp, factory, factory, columnName, propertySheetPanel);
}
return mapping;
}
use of org.cytoscape.application.CyApplicationManager 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.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class CyNetworkViewManagerImpl method addNetworkView.
@Override
public void addNetworkView(final CyNetworkView view, final boolean setCurrent) {
if (view == null) {
// Do nothing if view is null.
logger.warn("Network view is null.");
return;
}
final CyNetwork network = view.getModel();
final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
synchronized (lock) {
if (!netMgr.networkExists(network.getSUID()))
throw new IllegalArgumentException("Network view cannot be added, because its network (" + network + ") is not registered");
Collection<CyNetworkView> existingSet = networkViewMap.get(network);
if (existingSet == null)
existingSet = new LinkedHashSet<>();
existingSet.add(view);
networkViewMap.put(network, existingSet);
}
fireEvent(new NetworkViewAddedEvent(this, view));
if (setCurrent) {
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
if (// It may be null when running unit tests
applicationManager != null)
applicationManager.setCurrentNetworkView(view);
}
}
use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class CyActivator method start.
@Override
public void start(BundleContext bc) {
final CyServiceRegistrar serviceRegistrar = getService(bc, CyServiceRegistrar.class);
final CySwingApplication cySwingApplicationServiceRef = getService(bc, CySwingApplication.class);
final CyApplicationManager cyApplicationManagerServiceRef = getService(bc, CyApplicationManager.class);
final CyNetworkViewManager cyNetworkViewManagerServiceRef = getService(bc, CyNetworkViewManager.class);
invokeOnEDTAndWait(() -> {
controlPanel = new ControlPanel(serviceRegistrar);
controlPanelAction = new ControlPanelAction(controlPanel, cySwingApplicationServiceRef, cyApplicationManagerServiceRef, cyNetworkViewManagerServiceRef);
}, logger);
registerAllServices(bc, controlPanelAction, new Properties());
registerAllServices(bc, controlPanel, new Properties());
}
Aggregations