Search in sources :

Example 16 with CyEventHelper

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

the class HideFromSelectionTask method run.

@Override
public void run(final TaskMonitor tm) {
    tm.setProgress(0.0);
    final CyNetwork network = view.getModel();
    final List<CyIdentifiable> elements = new ArrayList<>();
    List<CyNode> nodes = null;
    List<CyEdge> edges = null;
    if (hideNodes) {
        nodes = CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, selectionValue);
        elements.addAll(nodes);
    }
    tm.setProgress(0.1);
    if (hideEdges) {
        edges = CyTableUtil.getEdgesInState(network, CyNetwork.SELECTED, selectionValue);
        elements.addAll(edges);
    }
    final UndoSupport undoSupport = serviceRegistrar.getService(UndoSupport.class);
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    undoSupport.postEdit(new HideEdit(description, view, elements, false, eventHelper, vmMgr));
    tm.setProgress(0.4);
    if (nodes != null)
        HideUtils.setVisibleNodes(nodes, false, view);
    tm.setProgress(0.6);
    if (edges != null)
        HideUtils.setVisibleEdges(edges, false, view);
    tm.setProgress(0.8);
    VisualStyle style = vmMgr.getVisualStyle(view);
    for (CyIdentifiable e : elements) {
        View<? extends CyIdentifiable> ev = null;
        if (e instanceof CyNode)
            ev = view.getNodeView((CyNode) e);
        else if (e instanceof CyEdge)
            ev = view.getEdgeView((CyEdge) e);
        if (ev != null)
            style.apply(network.getRow(e), ev);
    }
    view.updateView();
    tm.setProgress(1.0);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 17 with CyEventHelper

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

the class PopupMenuHelper method selectElementsFromSelectedRows.

private void selectElementsFromSelectedRows(final JTable table, final Class<? extends CyIdentifiable> tableType) {
    final Thread t = new Thread() {

        @Override
        public void run() {
            final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
            final CyNetwork net = applicationManager.getCurrentNetwork();
            if (net != null) {
                final BrowserTableModel tableModel = (BrowserTableModel) table.getModel();
                final int[] selectedRows = table.getSelectedRows();
                final Set<CyRow> targetRows = new HashSet<CyRow>();
                for (final int rowIndex : selectedRows) {
                    // 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) tableModel.getValueAt(table.convertRowIndexToModel(rowIndex), CyNetwork.SUID);
                    targetRows.add(tableModel.getRow(selected.getValidatedObject()));
                }
                final CyTable cyTable = tableType == CyNode.class ? net.getDefaultNodeTable() : net.getDefaultEdgeTable();
                for (final CyRow cyRow : cyTable.getAllRows()) cyRow.set(CyNetwork.SELECTED, targetRows.contains(cyRow));
                final CyNetworkView view = applicationManager.getCurrentNetworkView();
                if (view != null) {
                    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
                    eventHelper.flushPayloadEvents();
                    view.updateView();
                }
            }
        }
    };
    t.start();
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) Point(java.awt.Point) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet)

Example 18 with CyEventHelper

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

the class DGraphView method select.

public void select(Collection<? extends CyIdentifiable> nodesOrEdges, Class<? extends CyIdentifiable> type, boolean selected) {
    if (nodesOrEdges.isEmpty())
        return;
    List<RowSetRecord> records = new ArrayList<>();
    CyTable table = type.equals(CyNode.class) ? getModel().getDefaultNodeTable() : getModel().getDefaultEdgeTable();
    // Disable events
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    eventHelper.silenceEventSource(table);
    try {
        for (final CyIdentifiable nodeOrEdge : nodesOrEdges) {
            CyRow row = getModel().getRow(nodeOrEdge);
            row.set(CyNetwork.SELECTED, selected);
            // Add to paylod
            records.add(new RowSetRecord(row, CyNetwork.SELECTED, selected, selected));
        }
    } finally {
        eventHelper.unsilenceEventSource(table);
    }
    // Update the selection before firing the event to prevent race conditions
    updateSelection(type, records);
    // Only now it can fire the RowsSetEvent
    fireRowsSetEvent(table, records, eventHelper);
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyTable(org.cytoscape.model.CyTable) CyEventHelper(org.cytoscape.event.CyEventHelper) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) CyRow(org.cytoscape.model.CyRow) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 19 with CyEventHelper

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

the class TableEventHelperFacade method fireEvent.

@Override
public <E extends CyEvent<?>> void fireEvent(final E event) {
    final CyEventHelper eventHelper = getEventHelper();
    // always propagate the actual event
    eventHelper.fireEvent(event);
    // make sure the source is something we care about
    Object source = event.getSource();
    if (!(source instanceof CyTable))
        return;
    Reference<LocalTableFacade> reference;
    synchronized (lock) {
        reference = facadeMap.get((CyTable) source);
    }
    if (reference == null)
        return;
    LocalTableFacade facade = reference.get();
    if (facade == null)
        return;
    // create a new event for the facade table based on the actual event
    CyEvent<?> facadeEvent = null;
    if (event instanceof TableTitleChangedEvent) {
        TableTitleChangedEvent e = (TableTitleChangedEvent) event;
        facadeEvent = new TableTitleChangedEvent(facade, e.getOldTitle());
    } else if (event instanceof TablePrivacyChangedEvent) {
        facadeEvent = new TablePrivacyChangedEvent(facade);
    } else if (event instanceof ColumnNameChangedEvent) {
        ColumnNameChangedEvent e = (ColumnNameChangedEvent) event;
        facadeEvent = new ColumnNameChangedEvent(facade, e.getOldColumnName(), e.getNewColumnName());
    } else if (event instanceof ColumnDeletedEvent) {
        ColumnDeletedEvent e = (ColumnDeletedEvent) event;
        facadeEvent = new ColumnDeletedEvent(facade, e.getColumnName());
    } else if (event instanceof ColumnCreatedEvent) {
        ColumnCreatedEvent e = (ColumnCreatedEvent) event;
        facadeEvent = new ColumnCreatedEvent(facade, e.getColumnName());
    }
    // fire the new facade event
    if (facadeEvent != null)
        eventHelper.fireEvent(facadeEvent);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) CyTable(org.cytoscape.model.CyTable) TableTitleChangedEvent(org.cytoscape.model.events.TableTitleChangedEvent) ColumnNameChangedEvent(org.cytoscape.model.events.ColumnNameChangedEvent) ColumnDeletedEvent(org.cytoscape.model.events.ColumnDeletedEvent) TablePrivacyChangedEvent(org.cytoscape.model.events.TablePrivacyChangedEvent) ColumnCreatedEvent(org.cytoscape.model.events.ColumnCreatedEvent)

Example 20 with CyEventHelper

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

the class RenderingEngineManagerImpl method removeRenderingEngine.

@Override
public void removeRenderingEngine(final RenderingEngine<?> renderingEngine) {
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    eventHelper.fireEvent(new RenderingEngineAboutToBeRemovedEvent(this, renderingEngine));
    synchronized (lock) {
        final View<?> viewModel = renderingEngine.getViewModel();
        final Collection<RenderingEngine<?>> currentEngines = renderingEngineMap.get(viewModel);
        if (currentEngines != null) {
            currentEngines.remove(renderingEngine);
        }
    }
    renderingEngine.dispose();
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) RenderingEngine(org.cytoscape.view.presentation.RenderingEngine) RenderingEngineAboutToBeRemovedEvent(org.cytoscape.view.presentation.events.RenderingEngineAboutToBeRemovedEvent)

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