Search in sources :

Example 1 with PanelTaskManager

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);
        }
    }
}
Also used : PanelTaskManager(org.cytoscape.work.swing.PanelTaskManager) JPanel(javax.swing.JPanel) JComponent(javax.swing.JComponent)

Example 2 with PanelTaskManager

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;
}
Also used : PanelTaskManager(org.cytoscape.work.swing.PanelTaskManager) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) AbstractAction(javax.swing.AbstractAction)

Example 3 with PanelTaskManager

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();
        }
    }
}
Also used : PanelTaskManager(org.cytoscape.work.swing.PanelTaskManager) JPanel(javax.swing.JPanel) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection)

Example 4 with PanelTaskManager

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();
}
Also used : PanelTaskManager(org.cytoscape.work.swing.PanelTaskManager) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm)

Example 5 with PanelTaskManager

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;
}
Also used : PanelTaskManager(org.cytoscape.work.swing.PanelTaskManager) JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) DynamicTaskFactoryProvisioner(org.cytoscape.task.DynamicTaskFactoryProvisioner) CyApplicationManager(org.cytoscape.application.CyApplicationManager) ActionListener(java.awt.event.ActionListener) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) NetworkViewTaskFactory(org.cytoscape.task.NetworkViewTaskFactory) TaskFactory(org.cytoscape.work.TaskFactory) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Aggregations

PanelTaskManager (org.cytoscape.work.swing.PanelTaskManager)8 JPanel (javax.swing.JPanel)4 Properties (java.util.Properties)3 ActionEvent (java.awt.event.ActionEvent)2 CyApplicationManager (org.cytoscape.application.CyApplicationManager)2 CyLayoutAlgorithm (org.cytoscape.view.layout.CyLayoutAlgorithm)2 ActionListener (java.awt.event.ActionListener)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 AbstractAction (javax.swing.AbstractAction)1 BoxLayout (javax.swing.BoxLayout)1 JButton (javax.swing.JButton)1 JComponent (javax.swing.JComponent)1 AppManagerAction (org.cytoscape.app.internal.action.AppManagerAction)1 CitationsAction (org.cytoscape.app.internal.action.CitationsAction)1 AppManager (org.cytoscape.app.internal.manager.AppManager)1 UpdateManager (org.cytoscape.app.internal.net.UpdateManager)1 WebQuerier (org.cytoscape.app.internal.net.WebQuerier)1 AddAllowOriginHeader (org.cytoscape.app.internal.net.server.AddAllowOriginHeader)1 AppGetResponder (org.cytoscape.app.internal.net.server.AppGetResponder)1