use of org.cytoscape.work.swing.PanelTaskManager in project cytoscape-impl by cytoscape.
the class NetworkSearchMediator method addNetworkSearchTaskFactory.
public void addNetworkSearchTaskFactory(NetworkSearchTaskFactory factory, Map<?, ?> properties) {
if (factory.getId() != null && !factory.getId().trim().isEmpty()) {
try {
synchronized (lock) {
if (factory != null) {
JComponent qc = factory.getQueryComponent();
if (qc != null) {
queryComponents.put(factory, qc);
qc.addPropertyChangeListener(QUERY_PROPERTY, new QueryChangeListener(factory));
qc.addPropertyChangeListener(SEARCH_REQUESTED_PROPERTY, new SearchRequestedListener(factory));
}
JComponent oc = factory.getOptionsComponent();
if (oc == null) {
PanelTaskManager taskManager = serviceRegistrar.getService(PanelTaskManager.class);
oc = taskManager.getConfiguration(factory, factory);
if (oc != null) {
// Make the components smaller and the background white
recursiveDo(oc, c -> makeSmall(c));
recursiveDo(oc, c -> {
if (c instanceof JPanel)
((JPanel) c).setBackground(UIManager.getColor("Table.background"));
});
}
} else {
oc.addPropertyChangeListener(QUERY_PROPERTY, new QueryChangeListener(factory));
// TODO How do we detect changes to tunable fields???
}
if (oc != null)
optionsComponents.put(factory, oc);
}
taskFactories.put(factory.getId(), factory);
}
// Save this flag to a local scope variable first, because it may change before the
// EDT below starts, which would cause the selection of the incorrect default provider
final boolean appsFinishedStarting = this.appsFinishedStarting;
invokeOnEDT(() -> {
updateSearchPanel();
// so the user knows it has been installed correctly and is now available
if (factory != null && appsFinishedStarting)
networkSearchBar.setSelectedProvider(factory);
});
} catch (Exception e) {
logger.error("Cannot install Network Search Provider: " + factory, e);
}
}
}
use of org.cytoscape.work.swing.PanelTaskManager in project cytoscape-impl by cytoscape.
the class LayoutSettingsDialog method getApplyBtn.
private JButton getApplyBtn() {
if (applyBtn == null) {
applyBtn = new JButton(new AbstractAction("Apply Layout") {
@Override
public void actionPerformed(ActionEvent e) {
final Object context = currentLayout.getDefaultLayoutContext();
final PanelTaskManager taskMgr = serviceRegistrar.getService(PanelTaskManager.class);
if (taskMgr.validateAndApplyTunables(context))
taskMgr.execute(currentAction.createTaskIterator());
}
});
}
return applyBtn;
}
use of org.cytoscape.work.swing.PanelTaskManager in project cytoscape-impl by cytoscape.
the class LayoutSettingsDialog method setNetworkView.
void setNetworkView(final CyNetworkView view) {
getApplyBtn().setEnabled(view != null);
if (layoutAttrPnl == null)
return;
boolean haveNodeAttribute = (currentLayout.getSupportedNodeAttributeTypes() != null && currentLayout.getSupportedNodeAttributeTypes().size() > 0);
boolean haveEdgeAttribute = (currentLayout.getSupportedEdgeAttributeTypes() != null && currentLayout.getSupportedEdgeAttributeTypes().size() > 0);
layoutAttrPnl.removeAll();
if (currentLayout.getSupportedEdgeAttributeTypes() != null && currentLayout.getSupportedEdgeAttributeTypes().size() > 0)
layoutEdgeAttrTunable = new LayoutEdgeAttributeTunable();
else if (currentLayout.getSupportedNodeAttributeTypes() != null && currentLayout.getSupportedNodeAttributeTypes().size() > 0)
layoutNodeAttrTunable = new LayoutNodeAttributeTunable();
if (view != null) {
List<String> attributeList = getAttributeList(view.getModel(), currentLayout.getSupportedNodeAttributeTypes(), currentLayout.getSupportedEdgeAttributeTypes());
if (attributeList.size() > 0) {
final PanelTaskManager taskMgr = serviceRegistrar.getService(PanelTaskManager.class);
JPanel panel = null;
if (haveEdgeAttribute) {
layoutEdgeAttrTunable = new LayoutEdgeAttributeTunable();
layoutEdgeAttrTunable.layoutAttribute = new ListSingleSelection<String>(attributeList);
layoutEdgeAttrTunable.layoutAttribute.setSelectedValue(attributeList.get(0));
panel = taskMgr.getConfiguration(null, layoutEdgeAttrTunable);
} else if (haveNodeAttribute) {
layoutNodeAttrTunable = new LayoutNodeAttributeTunable();
layoutNodeAttrTunable.layoutAttribute = new ListSingleSelection<String>(attributeList);
layoutNodeAttrTunable.layoutAttribute.setSelectedValue(attributeList.get(0));
panel = taskMgr.getConfiguration(null, layoutNodeAttrTunable);
}
setPanelsTransparent(panel);
layoutAttrPnl.add(panel);
panel.invalidate();
}
}
}
use of org.cytoscape.work.swing.PanelTaskManager in project cytoscape-impl by cytoscape.
the class LayoutSettingsDialog method saveLayoutContexts.
private void saveLayoutContexts() {
final PanelTaskManager taskMgr = serviceRegistrar.getService(PanelTaskManager.class);
for (CyLayoutAlgorithm layout : tunablesToSave) {
layoutSettingsMgr.saveLayoutContext(taskMgr, layout);
}
tunablesToSave.clear();
}
use of org.cytoscape.work.swing.PanelTaskManager in project cytoscape-impl by cytoscape.
the class LayoutSettingsDialog method getAlgorithmCmb.
private JComboBox<CyLayoutAlgorithm> getAlgorithmCmb() {
if (algorithmCmb == null) {
algorithmCmb = new JComboBox<CyLayoutAlgorithm>();
algorithmCmb.setRenderer(new LayoutAlgorithmListCellRenderer("-- Select algorithm to view settings --"));
algorithmCmb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (initializing)
return;
final Object o = algorithmCmb.getSelectedItem();
if (o instanceof CyLayoutAlgorithm) {
currentLayout = (CyLayoutAlgorithm) o;
final PanelTaskManager taskMgr = serviceRegistrar.getService(PanelTaskManager.class);
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
// Checking if the context has already been charged, if so there is no need to do it again
final Object context = currentLayout.getDefaultLayoutContext();
tunablesToSave.add(currentLayout);
final DynamicTaskFactoryProvisioner factoryProvisioner = serviceRegistrar.getService(DynamicTaskFactoryProvisioner.class);
final TaskFactory provisioner = factoryProvisioner.createFor(wrapWithContext(currentLayout, context));
final JPanel tunablePnl = taskMgr.getConfiguration(provisioner, context);
layoutAttrPnl = new JPanel();
layoutAttrPnl.setLayout(new BoxLayout(layoutAttrPnl, BoxLayout.PAGE_AXIS));
// Transparent if Aqua
layoutAttrPnl.setOpaque(!LookAndFeelUtil.isAquaLAF());
final CyNetworkView view = appMgr.getCurrentNetworkView();
setNetworkView(view);
getAlgorithmPnl().removeAll();
getAlgorithmPnl().add(layoutAttrPnl);
if (tunablePnl != null) {
tunablePnl.setAlignmentX(Component.CENTER_ALIGNMENT);
setPanelsTransparent(tunablePnl);
getAlgorithmPnl().add(tunablePnl);
}
if (currentLayout.getSupportsSelectedOnly() && hasSelectedNodes(view)) {
selectedTunable.selectedNodesOnly = true;
final JPanel panel = taskMgr.getConfiguration(null, selectedTunable);
setPanelsTransparent(panel);
getAlgorithmPnl().add(panel);
}
currentAction = provisioner;
LayoutSettingsDialog.this.pack();
}
}
});
}
return algorithmCmb;
}
Aggregations