Search in sources :

Example 51 with CyApplicationManager

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;
}
Also used : DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) CyNetwork(org.cytoscape.model.CyNetwork) CyApplicationManager(org.cytoscape.application.CyApplicationManager) AttributeSet(org.cytoscape.view.vizmap.gui.internal.model.AttributeSet) PropertySheetTableModel(com.l2fprod.common.propertysheet.PropertySheetTableModel) TableModelListener(javax.swing.event.TableModelListener) List(java.util.List) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager)

Example 52 with CyApplicationManager

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;
}
Also used : CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) CyColumn(org.cytoscape.model.CyColumn) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) VisualProperty(org.cytoscape.view.model.VisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 53 with CyApplicationManager

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);
}
Also used : CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyApplicationManager(org.cytoscape.application.CyApplicationManager) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Example 54 with CyApplicationManager

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) NetworkViewAddedEvent(org.cytoscape.view.model.events.NetworkViewAddedEvent)

Example 55 with CyApplicationManager

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());
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CySwingApplication(org.cytoscape.application.swing.CySwingApplication) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) ControlPanel(org.cytoscape.view.manual.internal.control.view.ControlPanel) Properties(java.util.Properties) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) ControlPanelAction(org.cytoscape.view.manual.internal.control.actions.ControlPanelAction)

Aggregations

CyApplicationManager (org.cytoscape.application.CyApplicationManager)80 CyNetwork (org.cytoscape.model.CyNetwork)40 CyNetworkView (org.cytoscape.view.model.CyNetworkView)30 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)18 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)16 CyNetworkManager (org.cytoscape.model.CyNetworkManager)14 CyEventHelper (org.cytoscape.event.CyEventHelper)12 CyTable (org.cytoscape.model.CyTable)12 ArrayList (java.util.ArrayList)11 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)10 CyNode (org.cytoscape.model.CyNode)9 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)9 Test (org.junit.Test)9 HashSet (java.util.HashSet)8 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)8 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)8 TaskIterator (org.cytoscape.work.TaskIterator)8 HashMap (java.util.HashMap)7 CyGroupManager (org.cytoscape.group.CyGroupManager)7 CyTableManager (org.cytoscape.model.CyTableManager)7