Example usage for javax.swing.tree DefaultTreeCellRenderer DefaultTreeCellRenderer

List of usage examples for javax.swing.tree DefaultTreeCellRenderer DefaultTreeCellRenderer

Introduction

In this page you can find the example usage for javax.swing.tree DefaultTreeCellRenderer DefaultTreeCellRenderer.

Prototype

public DefaultTreeCellRenderer() 

Source Link

Document

Creates a DefaultTreeCellRenderer .

Usage

From source file:de.codesourcery.eve.skills.ui.components.impl.ItemBrowserComponent.java

@Override
protected JPanel createPanel() {

    final JPanel result = new JPanel();
    result.setLayout(new GridBagLayout());

    treeModelBuilder = new MarketGroupTreeModelBuilder(dataModel);

    treeModelBuilder.attach(itemTree);/*from   ww w  .  ja v  a  2 s .  c  o m*/

    itemTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            if (e.getPath() != null) {
                treeSelectionChanged((ITreeNode) e.getPath().getLastPathComponent());
            } else {
                treeSelectionChanged(null);
            }
        }
    });

    itemTree.setCellRenderer(new DefaultTreeCellRenderer() {
        public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel,
                boolean expanded, boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            final ITreeNode node = (ITreeNode) value;
            if (node.getValue() instanceof MarketGroup) {
                setText(((MarketGroup) node.getValue()).getName());
            } else if (node.getValue() instanceof InventoryType) {
                setText(((InventoryType) node.getValue()).getName());
            }
            return this;
        };
    });

    // text area
    itemDetails.setLineWrap(true);
    itemDetails.setWrapStyleWord(true);
    itemDetails.setEditable(false);

    // context menu
    final PopupMenuBuilder menuBuilder = new PopupMenuBuilder();
    menuBuilder.addItem("Refine...", new AbstractAction() {

        @Override
        public boolean isEnabled() {
            return getSelectedType() != null && selectionProvider.getSelectedItem() != null;
        }

        private InventoryType getSelectedType() {
            final TreePath selection = itemTree.getSelectionPath();
            if (selection != null && selection.getPathCount() > 0) {
                final ITreeNode node = (ITreeNode) selection.getLastPathComponent();
                if (node.getValue() instanceof InventoryType) {
                    return (InventoryType) node.getValue();
                }
            }
            return null;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            final ICharacter currentCharacter = selectionProvider.getSelectedItem();
            final InventoryType t = getSelectedType();
            if (t != null && currentCharacter != null) {

                final RefiningComponent comp = new RefiningComponent(currentCharacter);
                comp.setModal(true);
                comp.setItemsToRefine(Collections.singletonList(new ItemWithQuantity(getSelectedType(), 1)));
                ComponentWrapper.wrapComponent(comp).setVisible(true);
            }

        }
    });
    menuBuilder.attach(itemTree);

    result.add(new JScrollPane(itemTree), constraints(0, 0).resizeBoth().end());
    result.add(new JScrollPane(itemDetails), constraints(1, 0).resizeBoth().end());
    return result;
}

From source file:de.codesourcery.jasm16.ide.ui.views.WorkspaceExplorer.java

private JPanel createPanel() {
    treeModel = createTreeModel();/* ww  w .ja v a  2 s  . c  om*/
    tree.setModel(treeModel);
    setColors(tree);
    tree.setRootVisible(false);

    //      for (int i = 0; i < tree.getRowCount(); i++) {
    //         tree.expandRow(i);
    //      }

    tree.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                final WorkspaceTreeNode selection = getSelectedNode();
                if (selection != null) {
                    deleteResource(selection);
                }
            } else if (e.getKeyCode() == KeyEvent.VK_F5) {
                refreshWorkspace(null);
            }
        }
    });

    tree.addMouseListener(new MouseAdapter() {

        public void mouseClicked(java.awt.event.MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                final TreePath path = tree.getPathForLocation(e.getX(), e.getY());
                if (path != null) {
                    final WorkspaceTreeNode selected = (WorkspaceTreeNode) path.getLastPathComponent();
                    final IAssemblyProject project = getProject(selected);
                    try {
                        if (project != null) {
                            onTreeNodeLeftClick(project, selected);
                        } else {
                            System.err.println("Unable to locate project for " + selected);
                        }
                    } catch (IOException e1) {
                        LOG.error("mouseClicked(): Internal error", e1);
                    }
                }
            }
        }
    });

    final TreeSelectionListener selectionListener = new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {

        }
    };

    tree.getSelectionModel().addTreeSelectionListener(selectionListener);

    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        public Color getTextSelectionColor() {
            return Color.GREEN;
        };

        public java.awt.Color getTextNonSelectionColor() {
            return Color.GREEN;
        };

        public Color getBackgroundSelectionColor() {
            return Color.BLACK;
        };

        public Color getBackgroundNonSelectionColor() {
            return Color.BLACK;
        };

        public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel,
                boolean expanded, boolean leaf, int row, boolean hasFocus) {

            java.awt.Component result = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
                    row, hasFocus);

            String label = value.toString();
            Color color = getTextColor();
            if (value instanceof WorkspaceTreeNode) {
                if (value instanceof ProjectNode) {
                    final ProjectNode projectNode = (ProjectNode) value;
                    final IAssemblyProject project = projectNode.getValue();
                    label = project.getName();

                    if (project.isClosed()) {
                        color = Color.LIGHT_GRAY;
                    } else {
                        if (projectNode.hasCompilationErrors()) {
                            color = Color.RED;
                        }
                    }
                } else if (value instanceof FileNode) {
                    FileNode fn = (FileNode) value;
                    label = fn.getValue().getName();
                    switch (fn.type) {
                    case DIRECTORY:
                        if (fn.hasCompilationErrors()) {
                            color = Color.RED;
                        }
                        break;
                    case OBJECT_FILE:
                        label = "[O] " + label;
                        break;
                    case EXECUTABLE:
                        label = "[E] " + label;
                        break;
                    case SOURCE_CODE:
                        label = "[S] " + label;
                        if (fn.hasCompilationErrors()) {
                            color = Color.RED;
                        }
                        break;
                    default:
                        // ok
                    }
                }
            }
            setForeground(color);
            setText(label);
            return result;
        };

    });

    setupPopupMenu();

    final JScrollPane pane = new JScrollPane(tree);
    setColors(pane);

    final JPanel result = new JPanel();
    result.setLayout(new GridBagLayout());
    GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH);
    setColors(result);
    result.add(pane, cnstrs);
    return result;
}

From source file:GenealogyExample.java

public GenealogyTree(Person graphNode) {
    super(new GenealogyModel(graphNode));
    getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    Icon personIcon = null;/*from  w  ww  .  j a  va  2  s  . co  m*/
    renderer.setLeafIcon(personIcon);
    renderer.setClosedIcon(personIcon);
    renderer.setOpenIcon(personIcon);
    setCellRenderer(renderer);
}

From source file:com.mirth.connect.client.ui.LibraryResourcesPanel.java

private void initComponents(Channel channel) {
    setBackground(UIConstants.BACKGROUND_COLOR);

    AbstractMutableTreeTableNode channelNode = new DefaultMutableTreeTableNode(
            new ConnectorEntry("Channel", -1, null));

    AbstractMutableTreeTableNode channelScriptsNode = new DefaultMutableTreeTableNode(
            new ConnectorEntry("Channel Scripts", null, null));
    channelScriptsNode//  ww w  . j a  va2  s. c om
            .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Deploy Script", null, null, false)));
    channelScriptsNode
            .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Undeploy Script", null, null, false)));
    channelScriptsNode
            .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Preprocessor Script", null, null, false)));
    channelScriptsNode.add(
            new DefaultMutableTreeTableNode(new ConnectorEntry("Postprocessor Script", null, null, false)));
    channelScriptsNode
            .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Attachment Script", null, null, false)));
    channelScriptsNode
            .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Batch Script", null, null, false)));
    channelNode.add(channelScriptsNode);

    AbstractMutableTreeTableNode sourceConnectorNode = new DefaultMutableTreeTableNode(
            new ConnectorEntry("Source Connector", 0, channel.getSourceConnector().getTransportName()));
    sourceConnectorNode.add(new DefaultMutableTreeTableNode(
            new ConnectorEntry("Receiver", channel.getSourceConnector().getMetaDataId(),
                    channel.getSourceConnector().getTransportName(), false)));
    sourceConnectorNode.add(new DefaultMutableTreeTableNode(
            new ConnectorEntry("Filter / Transformer Script", channel.getSourceConnector().getMetaDataId(),
                    channel.getSourceConnector().getTransportName(), false)));
    channelNode.add(sourceConnectorNode);

    for (Connector destinationConnector : channel.getDestinationConnectors()) {
        AbstractMutableTreeTableNode destinationConnectorNode = new DefaultMutableTreeTableNode(
                new ConnectorEntry(destinationConnector.getName(), destinationConnector.getMetaDataId(),
                        destinationConnector.getTransportName()));
        destinationConnectorNode
                .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Filter / Transformer Script",
                        destinationConnector.getMetaDataId(), destinationConnector.getTransportName(), false)));
        destinationConnectorNode.add(new DefaultMutableTreeTableNode(new ConnectorEntry("Dispatcher",
                destinationConnector.getMetaDataId(), destinationConnector.getTransportName(), false)));
        destinationConnectorNode
                .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Response Transformer Script",
                        destinationConnector.getMetaDataId(), destinationConnector.getTransportName(), false)));
        channelNode.add(destinationConnectorNode);
    }

    treeTable = new MirthTreeTable();

    DefaultTreeTableModel model = new SortableTreeTableModel(channelNode);
    model.setColumnIdentifiers(Arrays.asList(new String[] { "Library Context" }));
    treeTable.setTreeTableModel(model);

    treeTable.setRootVisible(true);
    treeTable.setDragEnabled(false);
    treeTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    treeTable.getTreeSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    treeTable.setRowHeight(UIConstants.ROW_HEIGHT);
    treeTable.setFocusable(true);
    treeTable.setOpaque(true);
    treeTable.getTableHeader().setReorderingAllowed(false);
    treeTable.setEditable(false);
    treeTable.setSortable(false);
    treeTable.addTreeSelectionListener(this);
    treeTable.getSelectionModel().addListSelectionListener(this);
    treeTable.putClientProperty("JTree.lineStyle", "Horizontal");
    treeTable.setShowGrid(true, true);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        treeTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR));
    }

    final String toolTipText = "<html>Select which context(s) to include library resources in.<br/>Libraries can be included everywhere (the Channel node),<br/>on channel-level scripts (the Channel Scripts node), and<br/>on specific source or destination connectors.</html>";

    treeTable.setTreeCellRenderer(new DefaultTreeCellRenderer() {
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                boolean expanded, boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
            setToolTipText(toolTipText);
            setEnabled(((ConnectorEntry) ((AbstractMutableTreeTableNode) value).getUserObject()).enabled);
            return this;
        }
    });

    treeTable.setOpenIcon(null);
    treeTable.setClosedIcon(null);
    treeTable.setLeafIcon(null);
    treeTable.getColumnExt(0).setToolTipText(toolTipText);

    treeTableScrollPane = new JScrollPane(treeTable);

    resourceTable = new MirthTable();
    resourceTable.setModel(new RefreshTableModel(new Object[] { "", "Name", "Type" }, 0) {
        @Override
        public boolean isCellEditable(int row, int column) {
            return column == SELECTED_COLUMN;
        }
    });
    resourceTable.setDragEnabled(false);
    resourceTable.setRowSelectionAllowed(false);
    resourceTable.setRowHeight(UIConstants.ROW_HEIGHT);
    resourceTable.setFocusable(false);
    resourceTable.setOpaque(true);
    resourceTable.getTableHeader().setReorderingAllowed(false);
    resourceTable.setEditable(true);
    resourceTable.setSortable(false);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        resourceTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR));
    }

    resourceTable.getColumnModel().getColumn(SELECTED_COLUMN).setMinWidth(20);
    resourceTable.getColumnModel().getColumn(SELECTED_COLUMN).setMaxWidth(20);
    resourceTable.getColumnModel().getColumn(SELECTED_COLUMN).setCellRenderer(new CheckBoxRenderer());
    resourceTable.getColumnModel().getColumn(SELECTED_COLUMN).setCellEditor(new CheckBoxEditor());

    resourceTable.getColumnModel().getColumn(TYPE_COLUMN).setMinWidth(75);
    resourceTable.getColumnModel().getColumn(TYPE_COLUMN).setMaxWidth(200);

    resourceTableScrollPane = new JScrollPane(resourceTable);
}

From source file:ca.sqlpower.architect.swingui.enterprise.SecurityPanel.java

public SecurityPanel(SPServerInfo serverInfo, Action closeAction, Dialog d, ArchitectSession session) {
    this.closeAction = closeAction;

    splitpane = new JSplitPane();
    panel = new JPanel();

    ArchitectClientSideSession clientSideSession = ArchitectClientSideSession.getSecuritySessions()
            .get(serverInfo.getServerAddress());

    //Displaying an indeterminate progress bar in place of the split pane
    //until the security session has loaded fully.
    if (clientSideSession.getUpdater().getRevision() <= 0) {
        JLabel messageLabel = new JLabel("Opening");
        JProgressBar progressBar = new JProgressBar();
        progressBar.setIndeterminate(true);

        DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("pref:grow, 5dlu, pref"));
        builder.setDefaultDialogBorder();
        builder.append(messageLabel, 3);
        builder.nextLine();//ww w . j ava  2 s.c  o m
        builder.append(progressBar, 3);

        UpdateListener l = new UpdateListener() {

            @Override
            public void workspaceDeleted() {
                //do nothing
            }

            @Override
            public boolean updatePerformed(AbstractNetworkConflictResolver resolver) {
                panel.removeAll();
                panel.add(splitpane);
                dialog.pack();
                refreshTree();
                return true;
            }

            @Override
            public boolean updateException(AbstractNetworkConflictResolver resolver, Throwable t) {
                //do nothing, the error will be handled elsewhere
                return true;
            }

            @Override
            public void preUpdatePerformed(AbstractNetworkConflictResolver resolver) {
                //do nothing
            }
        };

        clientSideSession.getUpdater().addListener(l);
        panel.add(builder.getPanel());
    }
    this.securityWorkspace = clientSideSession.getWorkspace();
    this.username = serverInfo.getUsername();
    this.dialog = d;
    this.session = session;

    try {
        digester = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }

    rootNode.add(usersNode);
    rootNode.add(groupsNode);

    rightSidePanel = new JPanel();

    tree = new JTree(rootNode);
    tree.addTreeSelectionListener(treeListener);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setCellRenderer(new DefaultTreeCellRenderer() {
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
                boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
            if (userObject instanceof User) {
                setIcon(USER_ICON);
            } else if (userObject instanceof Group) {
                setIcon(GROUP_ICON);
            }
            return this;
        }
    });

    treePane = new JScrollPane(tree);
    treePane.setPreferredSize(new Dimension(200, treePane.getPreferredSize().height));

    tree.addMouseListener(popupListener);

    splitpane.setRightComponent(rightSidePanel);
    splitpane.setLeftComponent(treePane);

    if (clientSideSession.getUpdater().getRevision() > 0) {
        panel.removeAll();
        panel.add(splitpane);
    }

    refreshTree();

    try {
        tree.setSelectionPath(new TreePath(usersNode.getFirstChild()));
    } catch (NoSuchElementException e) {
    } // This just means that the node has no children, so we cannot expand the path.
}

From source file:com.mirth.connect.client.ui.LibraryResourcesDialog.java

private void initComponents(Channel channel) {
    setLayout(new MigLayout("insets 12, novisualpadding, hidemode 3, fill", "", "[][]8[]8[]"));
    setBackground(UIConstants.BACKGROUND_COLOR);
    getContentPane().setBackground(getBackground());

    AbstractMutableTreeTableNode channelNode = new DefaultMutableTreeTableNode(
            new ConnectorEntry("Channel", -1, null));

    AbstractMutableTreeTableNode channelScriptsNode = new DefaultMutableTreeTableNode(
            new ConnectorEntry("Channel Scripts", null, null));
    channelScriptsNode/*from w ww.j  a  va2s. c  o m*/
            .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Deploy Script", null, null, false)));
    channelScriptsNode
            .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Undeploy Script", null, null, false)));
    channelScriptsNode
            .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Preprocessor Script", null, null, false)));
    channelScriptsNode.add(
            new DefaultMutableTreeTableNode(new ConnectorEntry("Postprocessor Script", null, null, false)));
    channelScriptsNode
            .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Attachment Script", null, null, false)));
    channelScriptsNode
            .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Batch Script", null, null, false)));
    channelNode.add(channelScriptsNode);

    AbstractMutableTreeTableNode sourceConnectorNode = new DefaultMutableTreeTableNode(
            new ConnectorEntry("Source Connector", 0, channel.getSourceConnector().getTransportName()));
    sourceConnectorNode.add(new DefaultMutableTreeTableNode(
            new ConnectorEntry("Receiver", channel.getSourceConnector().getMetaDataId(),
                    channel.getSourceConnector().getTransportName(), false)));
    sourceConnectorNode.add(new DefaultMutableTreeTableNode(
            new ConnectorEntry("Filter / Transformer Script", channel.getSourceConnector().getMetaDataId(),
                    channel.getSourceConnector().getTransportName(), false)));
    channelNode.add(sourceConnectorNode);

    for (Connector destinationConnector : channel.getDestinationConnectors()) {
        AbstractMutableTreeTableNode destinationConnectorNode = new DefaultMutableTreeTableNode(
                new ConnectorEntry(destinationConnector.getName(), destinationConnector.getMetaDataId(),
                        destinationConnector.getTransportName()));
        destinationConnectorNode
                .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Filter / Transformer Script",
                        destinationConnector.getMetaDataId(), destinationConnector.getTransportName(), false)));
        destinationConnectorNode.add(new DefaultMutableTreeTableNode(new ConnectorEntry("Dispatcher",
                destinationConnector.getMetaDataId(), destinationConnector.getTransportName(), false)));
        destinationConnectorNode
                .add(new DefaultMutableTreeTableNode(new ConnectorEntry("Response Transformer Script",
                        destinationConnector.getMetaDataId(), destinationConnector.getTransportName(), false)));
        channelNode.add(destinationConnectorNode);
    }

    treeTable = new MirthTreeTable();

    DefaultTreeTableModel model = new SortableTreeTableModel(channelNode);
    model.setColumnIdentifiers(Arrays.asList(new String[] { "Library Context" }));
    treeTable.setTreeTableModel(model);

    treeTable.setRootVisible(true);
    treeTable.setDragEnabled(false);
    treeTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    treeTable.getTreeSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    treeTable.setRowHeight(UIConstants.ROW_HEIGHT);
    treeTable.setFocusable(true);
    treeTable.setOpaque(true);
    treeTable.getTableHeader().setReorderingAllowed(false);
    treeTable.setEditable(false);
    treeTable.setSortable(false);
    treeTable.addTreeSelectionListener(this);
    treeTable.getSelectionModel().addListSelectionListener(this);
    treeTable.putClientProperty("JTree.lineStyle", "Horizontal");
    treeTable.setShowGrid(true, true);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        treeTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR));
    }

    final String toolTipText = "<html>Select which context(s) to include library resources in.<br/>Libraries can be included everywhere (the Channel node),<br/>on channel-level scripts (the Channel Scripts node), and<br/>on specific source or destination connectors.</html>";

    treeTable.setTreeCellRenderer(new DefaultTreeCellRenderer() {
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                boolean expanded, boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
            setToolTipText(toolTipText);
            setEnabled(((ConnectorEntry) ((AbstractMutableTreeTableNode) value).getUserObject()).enabled);
            return this;
        }
    });

    treeTable.setOpenIcon(null);
    treeTable.setClosedIcon(null);
    treeTable.setLeafIcon(null);
    treeTable.getColumnExt(0).setToolTipText(toolTipText);

    add(new JScrollPane(treeTable), "grow, h 60%");

    resourceTable = new MirthTable();
    resourceTable.setModel(new RefreshTableModel(new Object[] { "", "Name", "Type" }, 0) {
        @Override
        public boolean isCellEditable(int row, int column) {
            return column == SELECTED_COLUMN;
        }
    });
    resourceTable.setDragEnabled(false);
    resourceTable.setRowSelectionAllowed(false);
    resourceTable.setRowHeight(UIConstants.ROW_HEIGHT);
    resourceTable.setFocusable(false);
    resourceTable.setOpaque(true);
    resourceTable.getTableHeader().setReorderingAllowed(false);
    resourceTable.setEditable(true);
    resourceTable.setSortable(false);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        resourceTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR));
    }

    resourceTable.getColumnModel().getColumn(SELECTED_COLUMN).setMinWidth(20);
    resourceTable.getColumnModel().getColumn(SELECTED_COLUMN).setMaxWidth(20);
    resourceTable.getColumnModel().getColumn(SELECTED_COLUMN).setCellRenderer(new CheckBoxRenderer());
    resourceTable.getColumnModel().getColumn(SELECTED_COLUMN).setCellEditor(new CheckBoxEditor());

    resourceTable.getColumnModel().getColumn(TYPE_COLUMN).setMinWidth(75);
    resourceTable.getColumnModel().getColumn(TYPE_COLUMN).setMaxWidth(200);

    add(new JScrollPane(resourceTable), "newline, grow, h 40%");

    add(new JSeparator(), "newline, grow");

    JPanel buttonPanel = new JPanel(new MigLayout("insets 0, novisualpadding, hidemode 3"));
    buttonPanel.setBackground(getBackground());

    okButton = new JButton("OK");
    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            okButtonActionPerformed();
        }
    });
    buttonPanel.add(okButton, "w 48!");

    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelButtonActionPerformed();
        }
    });
    buttonPanel.add(cancelButton, "w 48!");

    add(buttonPanel, "newline, right");
}

From source file:com.mirth.connect.client.ui.DashboardPanel.java

/**
 * Makes the status table with all current server information.
 *//*from   w  w w  . j  a  va  2 s  .  c  o  m*/
public void makeStatusTable() {
    List<String> columns = new ArrayList<String>();

    for (DashboardColumnPlugin plugin : LoadedExtensions.getInstance().getDashboardColumnPlugins().values()) {
        if (plugin.isDisplayFirst()) {
            columns.add(plugin.getColumnHeader());
        }
    }

    columns.addAll(Arrays.asList(defaultColumns));

    for (DashboardColumnPlugin plugin : LoadedExtensions.getInstance().getDashboardColumnPlugins().values()) {
        if (!plugin.isDisplayFirst()) {
            columns.add(plugin.getColumnHeader());
        }
    }

    DashboardTreeTableModel model = new DashboardTreeTableModel();
    model.setColumnIdentifiers(columns);
    model.setNodeFactory(new DefaultDashboardTableNodeFactory());

    for (DashboardTablePlugin plugin : LoadedExtensions.getInstance().getDashboardTablePlugins().values()) {
        dashboardTable = plugin.getTable();

        if (dashboardTable != null) {
            break;
        }
    }

    defaultVisibleColumns.addAll(columns);

    if (dashboardTable == null) {
        dashboardTable = new MirthTreeTable("dashboardPanel", defaultVisibleColumns);
    }

    dashboardTable.setColumnFactory(new DashboardTableColumnFactory());
    dashboardTable.setTreeTableModel(model);
    dashboardTable.setDoubleBuffered(true);
    dashboardTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    dashboardTable.setHorizontalScrollEnabled(true);
    dashboardTable.packTable(UIConstants.COL_MARGIN);
    dashboardTable.setRowHeight(UIConstants.ROW_HEIGHT);
    dashboardTable.setOpaque(true);
    dashboardTable.setRowSelectionAllowed(true);
    dashboardTable.setSortable(true);
    dashboardTable.putClientProperty("JTree.lineStyle", "Horizontal");
    dashboardTable.setAutoCreateColumnsFromModel(false);
    dashboardTable.setShowGrid(true, true);
    dashboardTable.restoreColumnPreferences();
    dashboardTable.setMirthColumnControlEnabled(true);

    dashboardTable.setTreeCellRenderer(new DefaultTreeCellRenderer() {
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
                boolean leaf, int row, boolean hasFocus) {
            JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row,
                    hasFocus);

            TreePath path = dashboardTable.getPathForRow(row);
            if (path != null) {
                AbstractDashboardTableNode node = ((AbstractDashboardTableNode) path.getLastPathComponent());
                if (node.isGroupNode()) {
                    setIcon(UIConstants.ICON_GROUP);
                } else {
                    DashboardStatus status = node.getDashboardStatus();
                    if (status.getStatusType() == StatusType.CHANNEL) {
                        setIcon(UIConstants.ICON_CHANNEL);
                    } else {
                        setIcon(UIConstants.ICON_CONNECTOR);
                    }
                }
            }

            return label;
        }
    });
    dashboardTable.setLeafIcon(UIConstants.ICON_CONNECTOR);
    dashboardTable.setOpenIcon(UIConstants.ICON_CHANNEL);
    dashboardTable.setClosedIcon(UIConstants.ICON_CHANNEL);

    dashboardTableScrollPane.setViewportView(dashboardTable);

    dashboardTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent event) {
            checkSelectionAndPopupMenu(event);
        }

        @Override
        public void mouseReleased(MouseEvent event) {
            checkSelectionAndPopupMenu(event);
        }

        @Override
        public void mouseClicked(MouseEvent event) {
            int clickedRow = dashboardTable.rowAtPoint(new Point(event.getX(), event.getY()));
            if (clickedRow == -1) {
                return;
            }

            TreePath path = dashboardTable.getPathForRow(clickedRow);
            if (path != null && ((AbstractDashboardTableNode) path.getLastPathComponent()).isGroupNode()) {
                return;
            }

            if (event.getClickCount() >= 2 && dashboardTable.getSelectedRowCount() == 1
                    && dashboardTable.getSelectedRow() == clickedRow) {
                parent.doShowMessages();
            }
        }
    });

    dashboardTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            /*
             * MIRTH-3199: Only update the panel plugin if the selection is finished. This does
             * mean that the logs aren't updated live when adding to or removing from a
             * currently adjusting selection, but it's much more efficient when it comes to the
             * number of requests being done from the client. Plus, it actually will still
             * update while a selection is adjusting if the refresh interval on the dashboard
             * elapses. We can change this so that plugins are updated during a selection
             * adjustment, but it would first require a major rewrite of the connection log /
             * status column plugin.
             */
            updatePopupMenu(!event.getValueIsAdjusting());
        }
    });
}

From source file:base.BasePlayer.AddGenome.java

public AddGenome() {
    super(new BorderLayout());

    makeGenomes();/*from  w w w. ja v a2  s.  com*/
    tree = new JTree(root);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    sizeError.setForeground(Draw.redColor);
    sizeError.setVisible(true);
    treemodel = (DefaultTreeModel) tree.getModel();
    remscroll = new JScrollPane(remtable);
    tree.setCellRenderer(new DefaultTreeCellRenderer() {
        private static final long serialVersionUID = 1L;
        private Icon collapsedIcon = UIManager.getIcon("Tree.collapsedIcon");
        private Icon expandedIcon = UIManager.getIcon("Tree.expandedIcon");
        //   private Icon leafIcon = UIManager.getIcon("Tree.leafIcon");
        private Icon addIcon = UIManager.getIcon("Tree.closedIcon");

        //        private Icon saveIcon = UIManager.getIcon("OptionPane.informationIcon");
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                boolean expanded, boolean isLeaf, int row, boolean focused) {
            Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row,
                    focused);

            if (!isLeaf) {

                //setFont(getFont().deriveFont(Font.PLAIN));
                if (expanded) {
                    setIcon(expandedIcon);
                } else {
                    setIcon(collapsedIcon);
                }

                /*   if(((DefaultMutableTreeNode) value).getUserObject().toString().equals("Annotations")) {
                      this.setFocusable(false);
                      setFont(getFont().deriveFont(Font.BOLD));
                      setIcon(null);
                   }
                */
            } else {
                if (((DefaultMutableTreeNode) value).getUserObject().toString().equals("Annotations")) {

                    //      setFont(getFont().deriveFont(Font.PLAIN));
                    setIcon(null);
                } else if (((DefaultMutableTreeNode) value).getUserObject().toString().startsWith("Add new")) {

                    //       setFont(getFont().deriveFont(Font.PLAIN));

                    setIcon(addIcon);
                } else {
                    //      setFont(getFont().deriveFont(Font.ITALIC));
                    setIcon(null);
                    //   setIcon(leafIcon);
                }

            }

            return c;
        }
    });
    tree.addMouseListener(this);
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            try {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

                if (node == null)
                    return;

                selectedNode = node;

                if (node.isLeaf()) {
                    checkUpdates.setEnabled(false);
                } else {
                    checkUpdates.setEnabled(true);
                }
                if (node.toString().startsWith("Add new") || node.toString().equals("Annotations")) {
                    remove.setEnabled(false);
                } else {
                    remove.setEnabled(true);
                }
                genometable.clearSelection();
                download.setEnabled(false);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
    tree.setToggleClickCount(1);
    tree.setRootVisible(false);
    treescroll = new JScrollPane(tree);
    checkGenomes();
    genomeFileText = new JLabel("Select reference fasta-file");
    annotationFileText = new JLabel("Select annotation gff3-file");
    genomeName = new JTextField("Give name of the genome");
    openRef = new JButton("Browse");
    openAnno = new JButton("Browse");
    add = new JButton("Add");
    download = new JButton("Download");
    checkEnsembl = new JButton("Ensembl fetch");
    checkEnsembl.setMinimumSize(Main.buttonDimension);
    checkEnsembl.addActionListener(this);
    getLinks = new JButton("Get file links.");
    remove = new JButton("Remove");
    checkUpdates = new JButton("Check updates");
    download.setEnabled(false);
    getLinks.setEnabled(false);
    getLinks.addActionListener(this);
    remove.setEnabled(false);
    download.addActionListener(this);
    remove.addActionListener(this);
    panel.setBackground(Draw.sidecolor);
    checkUpdates.addActionListener(this);
    this.setBackground(Draw.sidecolor);
    frame.getContentPane().setBackground(Draw.sidecolor);
    GridBagConstraints c = new GridBagConstraints();

    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(2, 4, 2, 4);
    c.gridwidth = 2;
    genometable.setSelectionMode(0);
    genometable.setShowGrid(false);
    remtable.setSelectionMode(0);
    remtable.setShowGrid(false);
    JScrollPane scroll = new JScrollPane();
    scroll.getViewport().setBackground(Color.white);
    scroll.getViewport().add(genometable);

    remscroll.getViewport().setBackground(Color.white);

    genometable.addMouseListener(this);
    remtable.addMouseListener(this);
    //   panel.add(welcomeLabel,c);
    //   c.gridy++;
    c.anchor = GridBagConstraints.NORTHWEST;
    panel.add(new JLabel("Download genome reference and annotation"), c);
    c.gridx++;
    c.anchor = GridBagConstraints.NORTHEAST;
    panel.add(checkEnsembl, c);
    c.anchor = GridBagConstraints.NORTHWEST;
    c.weightx = 1;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.gridx = 0;
    c.gridy++;
    //c.fill = GridBagConstraints.NONE;
    panel.add(scroll, c);
    c.gridy++;
    c.fill = GridBagConstraints.NONE;
    panel.add(download, c);
    c.gridx = 1;
    panel.add(sizeError, c);
    c.gridx = 1;
    panel.add(getLinks, c);
    c.gridy++;
    c.gridx = 0;
    c.fill = GridBagConstraints.BOTH;
    panel.add(new JLabel("Add/Remove installed genomes manually"), c);
    c.gridy++;
    panel.add(treescroll, c);
    c.gridy++;

    c.fill = GridBagConstraints.NONE;
    c.gridwidth = 1;
    remove.setMinimumSize(Main.buttonDimension);
    panel.add(remove, c);
    c.gridx = 1;
    panel.add(checkUpdates, c);
    checkUpdates.setMinimumSize(Main.buttonDimension);
    checkUpdates.setEnabled(false);
    c.gridwidth = 2;
    c.gridx = 0;
    c.gridy++;
    try {
        if (Main.genomeDir != null) {
            genomedirectory.setText(Main.genomeDir.getCanonicalPath());
        }

        genomedirectory.setEditable(false);
        genomedirectory.setBackground(Color.white);
        genomedirectory.setForeground(Color.black);
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    panel.add(new JLabel("Genome directory:"), c);
    c.gridy++;
    panel.add(genomedirectory, c);
    /*   c.fill = GridBagConstraints.BOTH;
       c.gridy++;
       panel.add(new JLabel("Add genome manually"),c);
       c.gridy++;   
       c.gridwidth = 2;      
       panel.add(new JSeparator(),c);
       c.gridwidth = 1;
       c.gridy++;
       panel.add(genomeFileText, c);
       c.fill = GridBagConstraints.NONE;
       c.gridx = 1;
       panel.add(openRef, c);      
               
       c.gridx = 0;
       openRef.addActionListener(this);
       c.gridy++;
       panel.add(annotationFileText,c);
       c.gridx=1;
       panel.add(openAnno, c);
       c.gridy++;
               
       panel.add(add,c);
            
       openAnno.addActionListener(this);
       add.addActionListener(this);
       add.setEnabled(false);
       */
    add(panel, BorderLayout.NORTH);
    if (Main.drawCanvas != null) {
        setFonts(Main.menuFont);
    }
    /*   html.append("<a href=http:Homo_sapiens_GRCh37:Ensembl_genes> Homo sapiens GRCh37 with Ensembl</a> or <a href=http:Homo_sapiens_GRCh37:RefSeq_genes>RefSeq</a> gene annotations<br>");
       html.append("<a href=http:Homo_sapiens_GRCh38:Ensembl_genes> Homo sapiens GRCh38 with Ensembl</a> or <a href=http:Homo_sapiens_GRCh38:RefSeq_genes>RefSeq</a> gene annotations<br><br>");
               
       html.append("<a href=http:Mus_musculus_GRCm38:Ensembl_genes> Mus musculus GRCm38 with Ensembl</a> or <a href=http:Mus_musculus_GRCm38:RefSeq_genes>RefSeq</a> gene annotations<br>");
       html.append("<a href=http:Rattus_norvegicus:Ensembl_genes> Rattus norvegicus with Ensembl gene annotations</a><br>");
       html.append("<a href=http:Saccharomyces_cerevisiae:Ensembl_genes> Saccharomyces cerevisiae with Ensembl gene annotation</a><br>");               
       html.append("<a href=http:Ciona_intestinalis:Ensembl_genes> Ciona intestinalis with Ensembl gene annotation</a><br>");
       Object[] row = {"Homo_sapiens_GRCh37"};
       Object[] row = {"Homo_sapiens_GRCh38"};
               
       model.addRow(row);
       /*   genomeName.setPreferredSize(new Dimension(300,20));
       this.add(genomeName);
       this.add(new JSeparator());
               
       this.add(openRef);
       openRef.addActionListener(this);
       this.add(genomeFileText);
       this.add(openAnno);
       openAnno.addActionListener(this);
       this.add(annotationFileText);
       this.add(add);
       add.addActionListener(this);
       if(annotation) {
          openRef.setVisible(false);
          genomeFileText.setVisible(false);
          genomeName.setEditable(false);
       }
       genomeFileText.setEditable(false);
       annotationFileText.setEditable(false);*/
}

From source file:net.sf.taverna.t2.workbench.views.results.workflow.RenderedResultComponent.java

/**
 * Update the component based on the node selected from the
 * ResultViewComponent tree./*from  w  w  w . ja  va  2s .  c  o  m*/
 */
public void updateResult() {
    if (recognisedRenderersForMimeType == null)
        recognisedRenderersForMimeType = new ArrayList<>();
    if (otherRenderers == null)
        otherRenderers = new ArrayList<>();

    // Enable the combo box
    renderersComboBox.setEnabled(true);

    /*
     * Update the 'save result' buttons appropriately as the result node had
     * changed
     */
    for (int i = 0; i < saveButtonsPanel.getComponents().length; i++) {
        JButton saveButton = (JButton) saveButtonsPanel.getComponent(i);
        SaveIndividualResultSPI action = (SaveIndividualResultSPI) saveButton.getAction();
        // Update the action with the new result reference
        action.setResultReference(path);
        saveButton.setEnabled(true);
    }

    if (DataBundles.isValue(path) || DataBundles.isReference(path)) {
        // Enable refresh button
        refreshButton.setEnabled(true);

        List<MimeType> mimeTypes = new ArrayList<>();
        try (InputStream inputstream = getInputStream(path)) {
            mimeTypes.addAll(getMimeTypes(inputstream));
        } catch (IOException e) {
            logger.warn("Error getting mimetype", e);
        }

        if (mimeTypes.isEmpty())
            // If MIME types is empty - add "plain/text" MIME type
            mimeTypes.add(new MimeType("text/plain"));
        else if (mimeTypes.size() == 1 && mimeTypes.get(0).toString().equals("chemical/x-fasta")) {
            /*
             * If MIME type is recognised as "chemical/x-fasta" only then
             * this might be an error from MIME magic (i.e., sometimes it
             * recognises stuff that is not "chemical/x-fasta" as
             * "chemical/x-fasta" and then Seq Vista renderer is used that
             * causes errors) - make sure we also add the renderers for
             * "text/plain" and "text/xml" as it is most probably just
             * normal xml text and push the "chemical/x-fasta" to the bottom
             * of the list.
             */
            mimeTypes.add(0, new MimeType("text/plain"));
            mimeTypes.add(1, new MimeType("text/xml"));
        }

        for (MimeType mimeType : mimeTypes) {
            List<Renderer> renderersList = rendererRegistry.getRenderersForMimeType(mimeType.toString());
            for (Renderer renderer : renderersList)
                if (!recognisedRenderersForMimeType.contains(renderer))
                    recognisedRenderersForMimeType.add(renderer);
        }
        // if there are no renderers then force text/plain
        if (recognisedRenderersForMimeType.isEmpty())
            recognisedRenderersForMimeType = rendererRegistry.getRenderersForMimeType("text/plain");

        /*
         * Add all other available renderers that are not recognised to be
         * able to handle the MIME type of the result
         */
        otherRenderers = new ArrayList<>(rendererRegistry.getRenderers());
        otherRenderers.removeAll(recognisedRenderersForMimeType);

        mimeList = new String[recognisedRenderersForMimeType.size() + otherRenderers.size()];
        rendererList = new ArrayList<>();

        /*
         * First add the ones that can handle the MIME type of the result
         * item
         */
        for (int i = 0; i < recognisedRenderersForMimeType.size(); i++) {
            mimeList[i] = recognisedRenderersForMimeType.get(i).getType();
            rendererList.add(recognisedRenderersForMimeType.get(i));
        }
        // Then add the other renderers just in case
        for (int i = 0; i < otherRenderers.size(); i++) {
            mimeList[recognisedRenderersForMimeType.size() + i] = otherRenderers.get(i).getType();
            rendererList.add(otherRenderers.get(i));
        }

        renderersComboBox.setModel(new DefaultComboBoxModel<String>(mimeList));

        if (mimeList.length > 0) {
            int index = 0;

            // Find the index of the current MIME type for this output port.
            for (int i = 0; i < mimeList.length; i++)
                if (mimeList[i].equals(lastUsedMIMEtype)) {
                    index = i;
                    break;
                }

            int previousindex = renderersComboBox.getSelectedIndex();
            renderersComboBox.setSelectedIndex(index);
            /*
             * force rendering as setSelectedIndex will not fire an
             * itemstatechanged event if previousindex == index and we still
             * need render the result as we may have switched from a
             * different result item in a result list but the renderer index
             * stayed the same
             */
            if (previousindex == index)
                renderResult(); // draw the rendered result component
        }

    } else if (DataBundles.isError(path)) {
        // Disable refresh button
        refreshButton.setEnabled(false);

        // Hide wrap text check box - only works for actual data
        wrapTextCheckBox.setVisible(false);

        // Reset the renderers as we have an error item
        recognisedRenderersForMimeType = null;
        otherRenderers = null;

        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Error Trace");

        try {
            ErrorDocument errorDocument = DataBundles.getError(path);
            try {
                buildErrorDocumentTree(root, errorDocument);
            } catch (IOException e) {
                logger.warn("Error building error document tree", e);
            }
        } catch (IOException e) {
            logger.warn("Error getting the error document", e);
        }

        JTree errorTree = new JTree(root);
        errorTree.setCellRenderer(new DefaultTreeCellRenderer() {
            @Override
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                    boolean expanded, boolean leaf, int row, boolean hasFocus) {
                Component renderer = null;
                if (value instanceof DefaultMutableTreeNode) {
                    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
                    Object userObject = treeNode.getUserObject();
                    if (userObject instanceof ErrorDocument)
                        renderer = renderErrorDocument(tree, selected, expanded, leaf, row, hasFocus,
                                (ErrorDocument) userObject);
                }
                if (renderer == null)
                    renderer = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row,
                            hasFocus);
                if (renderer instanceof JLabel) {
                    JLabel label = (JLabel) renderer;
                    label.setIcon(null);
                }
                return renderer;
            }

            private Component renderErrorDocument(JTree tree, boolean selected, boolean expanded, boolean leaf,
                    int row, boolean hasFocus, ErrorDocument errorDocument) {
                return super.getTreeCellRendererComponent(tree,
                        "<html>" + escapeHtml(errorDocument.getMessage()) + "</html>", selected, expanded, leaf,
                        row, hasFocus);
            }
        });

        renderersComboBox.setModel(new DefaultComboBoxModel<>(new String[] { ERROR_DOCUMENT }));
        renderedResultPanel.removeAll();
        renderedResultPanel.add(errorTree, CENTER);
        repaint();
    }
}

From source file:net.sf.taverna.t2.workbench.views.results.processor.RenderedProcessorResultComponent.java

/**
 * Update the component based on the node selected from the
 * ResultViewComponent tree./*from w  ww. j a va  2  s .c om*/
 */
public void updateResult() {
    if (recognisedRenderersForMimeType == null)
        recognisedRenderersForMimeType = new ArrayList<>();
    if (otherRenderers == null)
        otherRenderers = new ArrayList<>();

    ProcessorResultTreeNode result = (ProcessorResultTreeNode) node;

    // Reference to the result data
    path = result.getReference();

    // Enable the combo box
    renderersComboBox.setEnabled(true);

    /*
     * Update the 'save result' buttons appropriately as the result node had
     * changed
     */
    for (int i = 0; i < saveButtonsPanel.getComponents().length; i++) {
        JButton saveButton = (JButton) saveButtonsPanel.getComponent(i);
        SaveIndividualResultSPI action = (SaveIndividualResultSPI) (saveButton.getAction());
        // Update the action with the new result reference
        action.setResultReference(path);
        saveButton.setEnabled(true);
    }

    if (DataBundles.isValue(path) || DataBundles.isReference(path)) {
        // Enable refresh button
        refreshButton.setEnabled(true);

        List<MimeType> mimeTypes = new ArrayList<>();
        try (InputStream inputstream = RendererUtils.getInputStream(path)) {
            mimeTypes.addAll(getMimeTypes(inputstream));
        } catch (IOException e) {
            logger.warn("Error getting mimetype", e);
        }

        if (mimeTypes.isEmpty()) {
            // If MIME types is empty - add "plain/text" MIME type
            mimeTypes.add(new MimeType("text/plain"));
        } else if (mimeTypes.size() == 1 && mimeTypes.get(0).toString().equals("chemical/x-fasta")) {
            /*
             * If MIME type is recognised as "chemical/x-fasta" only then
             * this might be an error from MIME magic (i.e., sometimes it
             * recognises stuff that is not "chemical/x-fasta" as
             * "chemical/x-fasta" and then Seq Vista renderer is used that
             * causes errors) - make sure we also add the renderers for
             * "text/plain" and "text/xml" as it is most probably just
             * normal xml text and push the "chemical/x-fasta" to the bottom
             * of the list.
             */
            mimeTypes.add(0, new MimeType("text/plain"));
            mimeTypes.add(1, new MimeType("text/xml"));
        }

        for (MimeType mimeType : mimeTypes)
            for (Renderer renderer : rendererRegistry.getRenderersForMimeType(mimeType.toString()))
                if (!recognisedRenderersForMimeType.contains(renderer))
                    recognisedRenderersForMimeType.add(renderer);
        // if there are no renderers then force text/plain
        if (recognisedRenderersForMimeType.isEmpty())
            recognisedRenderersForMimeType = rendererRegistry.getRenderersForMimeType("text/plain");

        /*
         * Add all other available renderers that are not recognised to be
         * able to handle the MIME type of the result
         */
        otherRenderers = rendererRegistry.getRenderers();
        otherRenderers.removeAll(recognisedRenderersForMimeType);

        mimeList = new String[recognisedRenderersForMimeType.size() + otherRenderers.size()];
        rendererList = new ArrayList<>();

        /*
         * First add the ones that can handle the MIME type of the result
         * item
         */
        for (int i = 0; i < recognisedRenderersForMimeType.size(); i++) {
            mimeList[i] = recognisedRenderersForMimeType.get(i).getType();
            rendererList.add(recognisedRenderersForMimeType.get(i));
        }
        // Then add the other renderers just in case
        for (int i = 0; i < otherRenderers.size(); i++) {
            mimeList[recognisedRenderersForMimeType.size() + i] = otherRenderers.get(i).getType();
            rendererList.add(otherRenderers.get(i));
        }

        renderersComboBox.setModel(new DefaultComboBoxModel<>(mimeList));

        if (mimeList.length > 0) {
            int index = 0;

            // Find the index of the current MIME type for this output port.
            for (int i = 0; i < mimeList.length; i++)
                if (mimeList[i].equals(lastUsedMIMEtype)) {
                    index = i;
                    break;
                }

            int previousindex = renderersComboBox.getSelectedIndex();
            renderersComboBox.setSelectedIndex(index);
            /*
             * force rendering as setSelectedIndex will not fire an
             * itemstatechanged event if previousindex == index and we still
             * need render the result as we may have switched from a
             * different result item in a result list but the renderer index
             * stayed the same
             */
            if (previousindex == index)
                renderResult(); // draw the rendered result component
        }
    } else if (DataBundles.isError(path)) {
        // Disable refresh button
        refreshButton.setEnabled(false);

        @SuppressWarnings("unused")
        ErrorDocument errorDocument;
        try {
            errorDocument = DataBundles.getError(path);
        } catch (IOException e) {
            logger.warn("Error getting the error document", e);
        }

        // Reset the renderers as we have an error item
        recognisedRenderersForMimeType = null;
        otherRenderers = null;

        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Error Trace");

        // TODO handle error documents
        // ResultsUtils.buildErrorDocumentTree(root, errorDocument, referenceService);

        JTree errorTree = new JTree(root);

        errorTree.setCellRenderer(new DefaultTreeCellRenderer() {
            @Override
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                    boolean expanded, boolean leaf, int row, boolean hasFocus) {
                Component renderer = null;
                if (value instanceof DefaultMutableTreeNode) {
                    Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
                    if (userObject instanceof ErrorDocument)
                        renderer = getErrorDocumentRenderer(tree, selected, expanded, leaf, row, hasFocus,
                                (ErrorDocument) userObject);
                }
                if (renderer == null)
                    renderer = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row,
                            hasFocus);
                if (renderer instanceof JLabel) {
                    JLabel label = (JLabel) renderer;
                    label.setIcon(null);
                }
                return renderer;
            }

            private Component getErrorDocumentRenderer(JTree tree, boolean selected, boolean expanded,
                    boolean leaf, int row, boolean hasFocus, ErrorDocument errorDocument) {
                return super.getTreeCellRendererComponent(tree,
                        "<html>" + escapeHtml(errorDocument.getMessage()) + "</html>", selected, expanded, leaf,
                        row, hasFocus);
            }
        });

        renderersComboBox.setModel(new DefaultComboBoxModel<>(new String[] { ERROR_DOCUMENT }));
        renderedResultPanel.removeAll();
        renderedResultPanel.add(errorTree, CENTER);
        repaint();
    }
}