Search in sources :

Example 41 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.

the class CyTableManagerImpl method deleteTableInternal.

void deleteTableInternal(final long suid, boolean force) {
    CyTable table;
    synchronized (lock) {
        table = tables.get(suid);
        if (table == null) {
            return;
        }
    }
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    eventHelper.fireEvent(new TableAboutToBeDeletedEvent(this, table));
    synchronized (lock) {
        table = tables.get(suid);
        if (table == null) {
            return;
        }
        if (!force && (table.getMutability() != Mutability.MUTABLE)) {
            throw new IllegalArgumentException("can't delete an immutable table.");
        }
        if (table instanceof CyTableImpl)
            ((CyTableImpl) table).removeAllVirtColumns();
        tables.remove(suid);
    }
    eventHelper.fireEvent(new TableDeletedEvent(this));
    logger.debug("CyTable removed: table ID = " + table.getSUID());
    table = null;
}
Also used : TableDeletedEvent(org.cytoscape.model.events.TableDeletedEvent) CyTable(org.cytoscape.model.CyTable) CyEventHelper(org.cytoscape.event.CyEventHelper) TableAboutToBeDeletedEvent(org.cytoscape.model.events.TableAboutToBeDeletedEvent)

Example 42 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.

the class RenderingEngineManagerTest method setUp.

@Before
public void setUp() throws Exception {
    final CyEventHelper eventHelper = mock(CyEventHelper.class);
    final CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
    manager = new RenderingEngineManagerImpl(serviceRegistrar);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) RenderingEngineManagerImpl(org.cytoscape.view.presentation.internal.RenderingEngineManagerImpl) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) Before(org.junit.Before)

Example 43 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.

the class BrowserTable method selectFromTable.

private void selectFromTable() {
    final TableModel model = this.getModel();
    if (model instanceof BrowserTableModel == false)
        return;
    final BrowserTableModel btModel = (BrowserTableModel) model;
    if (btModel.getViewMode() != BrowserTableModel.ViewMode.ALL)
        return;
    final CyTable table = btModel.getDataTable();
    final CyColumn pKey = table.getPrimaryKey();
    final String pKeyName = pKey.getName();
    final int[] rowsSelected = getSelectedRows();
    if (rowsSelected.length == 0)
        return;
    final int selectedRowCount = getSelectedRowCount();
    final Set<CyRow> targetRows = new HashSet<CyRow>();
    for (int i = 0; i < selectedRowCount; i++) {
        // getting the row from data table solves the problem with hidden or
        // moved SUID column. However, since the rows might be sorted we
        // need to convert the index to model
        final ValidatedObjectAndEditString selected = (ValidatedObjectAndEditString) btModel.getValueAt(convertRowIndexToModel(rowsSelected[i]), pKeyName);
        targetRows.add(btModel.getRow(selected.getValidatedObject()));
    }
    // Clear selection for non-global table
    final CyTableManager tableManager = serviceRegistrar.getService(CyTableManager.class);
    if (tableManager.getGlobalTables().contains(table) == false) {
        List<CyRow> allRows = btModel.getDataTable().getAllRows();
        try {
            ignoreRowSetEvents = true;
            for (CyRow row : allRows) {
                final Boolean val = row.get(CyNetwork.SELECTED, Boolean.class);
                if (targetRows.contains(row)) {
                    row.set(CyNetwork.SELECTED, true);
                    continue;
                }
                if (val != null && (val == true))
                    row.set(CyNetwork.SELECTED, false);
            }
            final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
            final CyNetworkView curView = applicationManager.getCurrentNetworkView();
            if (curView != null) {
                final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
                eventHelper.flushPayloadEvents();
                curView.updateView();
            }
        } finally {
            ignoreRowSetEvents = false;
        }
        repaint();
    }
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) CyColumn(org.cytoscape.model.CyColumn) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) CyRow(org.cytoscape.model.CyRow) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CyTableManager(org.cytoscape.model.CyTableManager) CyNetworkView(org.cytoscape.view.model.CyNetworkView) TableModel(javax.swing.table.TableModel) HashSet(java.util.HashSet)

Example 44 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.

the class TestProxySettings method run.

@Override
public void run(TaskMonitor tm) {
    tm.setProgress(0.0);
    final CyProperty<Properties> proxyProps = getProxyProperties();
    final Properties props = proxyProps.getProperties();
    storeProxySettings(props);
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    for (String key : oldSettings.keySet()) {
        if (!oldSettings.get(key).equals(props.get(key))) {
            eventHelper.fireEvent(new PropertyUpdatedEvent(proxyProps));
            break;
        }
    }
    oldSettings.clear();
    tm.setProgress(1.0);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) PropertyUpdatedEvent(org.cytoscape.property.PropertyUpdatedEvent) Properties(java.util.Properties)

Example 45 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.

the class DeleteSelectedNodesAndEdgesTask method run.

@Override
public void run(final TaskMonitor taskMonitor) {
    taskMonitor.setProgress(0.0);
    List<CyNode> nodeList = tunables.getNodeList(false);
    List<CyEdge> edgeList = tunables.getEdgeList(false);
    if (tunables.getNetwork() != null)
        network = tunables.getNetwork();
    // Delete from the base network so that our changes can be undone:
    if (nodeList == null && edgeList == null) {
        selectedNodes = CyTableUtil.getNodesInState(network, "selected", true);
        taskMonitor.setProgress(0.1);
        selectedEdges = new HashSet<CyEdge>(CyTableUtil.getEdgesInState(network, "selected", true));
    } else {
        if (nodeList != null && nodeList.size() > 0)
            selectedNodes = nodeList;
        else
            selectedNodes = new ArrayList<CyNode>();
        if (edgeList != null && edgeList.size() > 0)
            selectedEdges = new HashSet<CyEdge>(edgeList);
        else
            selectedEdges = new HashSet<CyEdge>();
    }
    taskMonitor.setProgress(0.2);
    // Make sure we're not loosing any edges for a possible undo!
    for (CyNode selectedNode : selectedNodes) selectedEdges.addAll(network.getAdjacentEdgeList(selectedNode, CyEdge.Type.ANY));
    taskMonitor.setProgress(0.3);
    final UndoSupport undoSupport = serviceRegistrar.getService(UndoSupport.class);
    final CyNetworkViewManager netViewMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    undoSupport.postEdit(new DeleteEdit((CySubNetwork) network, selectedNodes, selectedEdges, netViewMgr, vmMgr, eventHelper));
    // Delete the actual nodes and edges:
    network.removeEdges(selectedEdges);
    taskMonitor.setProgress(0.7);
    network.removeNodes(selectedNodes);
    taskMonitor.setProgress(0.9);
    // Update network views
    final Collection<CyNetworkView> views = netViewMgr.getNetworkViews(network);
    for (final CyNetworkView netView : views) netView.updateView();
    taskMonitor.setProgress(1.0);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) ArrayList(java.util.ArrayList) CyEdge(org.cytoscape.model.CyEdge) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) HashSet(java.util.HashSet)

Aggregations

CyEventHelper (org.cytoscape.event.CyEventHelper)63 CyNetworkView (org.cytoscape.view.model.CyNetworkView)19 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)19 CyNode (org.cytoscape.model.CyNode)15 UndoSupport (org.cytoscape.work.undo.UndoSupport)14 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)13 ArrayList (java.util.ArrayList)11 CyApplicationManager (org.cytoscape.application.CyApplicationManager)11 CyNetwork (org.cytoscape.model.CyNetwork)10 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)10 Test (org.junit.Test)10 Task (org.cytoscape.work.Task)9 CyTable (org.cytoscape.model.CyTable)8 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)8 TaskIterator (org.cytoscape.work.TaskIterator)8 CyEdge (org.cytoscape.model.CyEdge)7 CyRow (org.cytoscape.model.CyRow)7 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)5 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)5