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);
}
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();
}
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);
}
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);
}
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();
}
Aggregations