Search in sources :

Example 1 with AppConflict

use of org.cytoscape.app.internal.task.ResolveAppConflictTask.AppConflict in project cytoscape-impl by cytoscape.

the class AppConflictHandler method setTunableDirectly.

@Override
public boolean setTunableDirectly(Window possibleParent) {
    try {
        AppConflict conflict = (AppConflict) getValue();
        Map<App, App> appsToReplace = conflict.getAppsToReplace();
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
        JLabel title = new JLabel("The following " + (appsToReplace.size() == 1 ? "app" : "apps") + " will be replaced:");
        title.setAlignmentX(Component.LEFT_ALIGNMENT);
        panel.add(title);
        panel.add(Box.createVerticalStrut(title.getPreferredSize().height));
        String deps = "";
        for (Entry<App, App> entry : appsToReplace.entrySet()) {
            deps += entry.getKey().getAppName() + " (to be installed: " + entry.getKey().getVersion() + ", " + entry.getValue().getVersion() + " currently installed)\n";
        }
        deps = deps.substring(0, deps.length() - 1);
        JTextArea textArea = new JTextArea(deps);
        textArea.setRows(Math.min(appsToReplace.size(), 10));
        textArea.setEditable(false);
        // disables text selection
        textArea.setHighlighter(null);
        textArea.setBorder(null);
        textArea.setOpaque(false);
        JScrollPane scrollPane = new JScrollPane(textArea);
        scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT);
        scrollPane.setBorder(null);
        scrollPane.getViewport().setOpaque(false);
        scrollPane.setOpaque(false);
        panel.add(scrollPane);
        panel.add(Box.createVerticalStrut(title.getPreferredSize().height));
        JLabel message = new JLabel("Continue?");
        message.setAlignmentX(Component.LEFT_ALIGNMENT);
        panel.add(message);
        Dimension size = panel.getPreferredSize();
        if (size.width > 600) {
            size.width = 600;
            panel.setPreferredSize(size);
        }
        int response = JOptionPane.showConfirmDialog(possibleParent, panel, "Replace " + (appsToReplace.size() == 1 ? "App" : "Apps"), JOptionPane.OK_CANCEL_OPTION);
        conflict.setReplaceApps(response);
    } catch (IllegalAccessException e) {
        logger.warn("Error accessing conflict object", e);
    } catch (InvocationTargetException e) {
        logger.warn("Exception thrown by conflict object", e);
    }
    return true;
}
Also used : App(org.cytoscape.app.internal.manager.App) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) InvocationTargetException(java.lang.reflect.InvocationTargetException) AppConflict(org.cytoscape.app.internal.task.ResolveAppConflictTask.AppConflict)

Aggregations

Dimension (java.awt.Dimension)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BoxLayout (javax.swing.BoxLayout)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTextArea (javax.swing.JTextArea)1 App (org.cytoscape.app.internal.manager.App)1 AppConflict (org.cytoscape.app.internal.task.ResolveAppConflictTask.AppConflict)1