List of usage examples for javax.swing.tree DefaultMutableTreeNode getParent
public TreeNode getParent()
From source file:org.kuali.test.creator.TestCreator.java
/** * * @param actionNode/*from w w w.j a va2s .c o m*/ */ public void handleAddEditTestSuite(DefaultMutableTreeNode actionNode) { Platform platform = null; TestSuite testSuite = null; if (actionNode.getUserObject() instanceof Platform) { platform = (Platform) actionNode.getUserObject(); } else { testSuite = (TestSuite) actionNode.getUserObject(); DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) actionNode.getParent(); platform = (Platform) pnode.getUserObject(); } TestSuiteDlg dlg = new TestSuiteDlg(this, platform, testSuite); if (dlg.isSaved()) { saveConfigurationButton.setEnabled(true); saveConfigurationMenuItem.setEnabled(true); if (!dlg.isEditmode()) { testRepositoryTree.addRepositoryNode(dlg.getNewRepositoryObject()); } } }
From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java
private Object getParentUserObject(DefaultMutableTreeNode childNode) { Object retval = null;/*from www. j av a 2s .c om*/ if (childNode.getParent() != null) { DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) childNode.getParent(); retval = pnode.getUserObject(); } return retval; }
From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java
private void moveSuiteTest(DefaultMutableTreeNode suiteTestTargetNode, SuiteTest suiteTest) { if (suiteTestTargetNode != null) { DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) suiteTestTargetNode.getParent(); if (pnode != null) { DefaultMutableTreeNode nodeToMove = findSuiteTestNode(suiteTest); if ((nodeToMove != null) && (nodeToMove != suiteTestTargetNode)) { TestSuite testSuite = (TestSuite) pnode.getUserObject(); SuiteTest[] tests = testSuite.getSuiteTests().getSuiteTestArray(); int pos1 = Utils.getSuiteTestArrayIndex(tests, suiteTest); int pos2 = Utils.getSuiteTestArrayIndex(tests, (SuiteTest) suiteTestTargetNode.getUserObject()); ;//from w w w .j av a 2s.c o m if ((pos1 > -1) && (pos2 > -1) && (pos1 != pos2)) { SuiteTest save = (SuiteTest) tests[pos1].copy(); if (pos1 > pos2) { for (int i = pos2; i < pos1; ++i) { tests[i + 1].set(tests[i]); } } else if (pos1 < pos2) { for (int i = pos1; i < pos2; ++i) { tests[i].set(tests[i + 1]); } } tests[pos2].set(save); getModel().removeNodeFromParent(nodeToMove); getModel().insertNodeInto(nodeToMove, pnode, pnode.getIndex(suiteTestTargetNode)); int indx = 1; for (SuiteTest t : testSuite.getSuiteTests().getSuiteTestArray()) { t.setIndex(indx++); } getMainframe().getSaveConfigurationButton().setEnabled(true); getMainframe().getSaveConfigurationMenuItem().setEnabled(true); } } } } }
From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java
/** * * @param platform// w w w . ja va 2s . c o m */ public void refreshPlatformNode(Platform platform) { DefaultMutableTreeNode node = findPlatformNodeByName(platform.getName()); if (node != null) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); int indx = parent.getIndex(node); getModel().removeNodeFromParent(node); getModel().insertNodeInto(new RepositoryNode(getConfiguration(), platform), parent, indx); getModel().reload(parent); } }
From source file:org.kuali.test.ui.components.sqlquerypanel.DatabasePanel.java
private boolean isCircularReference(DefaultMutableTreeNode node) { boolean retval = false; TableData td = (TableData) node.getUserObject(); DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) node.getParent(); while (!retval && (pnode != null)) { if (pnode.getUserObject() instanceof TableData) { TableData tdata = (TableData) pnode.getUserObject(); retval = td.getDbTableName().equals(tdata.getDbTableName()); }//from w w w . ja va 2 s . c o m pnode = (DefaultMutableTreeNode) pnode.getParent(); } return retval; }
From source file:org.kuali.test.ui.components.sqlquerypanel.DatabasePanel.java
private List<TableData> buildCompleteQueryTableList() { List<TableData> retval = new ArrayList<TableData>(); Set<TableData> hs = new HashSet<TableData>(); for (SelectColumnData scd : sqlSelectPanel.getColumnData()) { TableData td = scd.getTableData(); hs.add(td);//from w w w.java2 s . c o m if (td.getTreeNode() != null) { // run up the tree for each table to make sure // we have all linking tables even if no columns selected // for intermediate tables DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) td.getTreeNode().getParent(); while (pnode != null) { if (pnode.getUserObject() instanceof TableData) { hs.add((TableData) pnode.getUserObject()); } pnode = (DefaultMutableTreeNode) pnode.getParent(); } } } for (WhereColumnData wcd : sqlWherePanel.getColumnData()) { TableData td = wcd.getTableData(); hs.add(td); if (td.getTreeNode() != null) { // run up the tree for each table to make sure // we have all linking tables even if no columns selected // for intermediate tables DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) td.getTreeNode().getParent(); while (pnode != null) { if (pnode.getUserObject() instanceof TableData) { hs.add((TableData) pnode.getUserObject()); } pnode = (DefaultMutableTreeNode) pnode.getParent(); } } } retval.addAll(hs); Collections.sort(retval, new SqlHierarchyComparator()); if (LOG.isDebugEnabled()) { for (TableData td : retval) { int level = -1; if (td.getTreeNode() != null) { level = td.getTreeNode().getLevel(); } LOG.debug("table=" + td.getName() + ", level=" + level); } } return retval; }
From source file:org.kuali.test.ui.components.sqlquerytree.SqlQueryTree.java
/** * * @param node//from www. j a va 2 s . c om * @return */ @Override public String getTooltip(DefaultMutableTreeNode node) { String retval = null; if (node.getUserObject() instanceof TableData) { TableData td = (TableData) node.getUserObject(); DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) node.getParent(); if ((pnode != null) && (pnode.getUserObject() instanceof TableData)) { TableData pdata = (TableData) pnode.getUserObject(); if (StringUtils.isNotBlank(td.getForeignKeyName())) { StringBuilder buf = new StringBuilder(128); buf.append("<html>"); buf.append(Utils.buildHtmlStyle(Constants.HTML_BOLD_UNDERLINE_STYLE, dbPanel.getTableDisplayName(pdata.getName()) + " -> " + dbPanel.getTableDisplayName(td.getName()))); buf.append(Constants.HTML_LINE_BREAK); for (String[] s : td.getLinkColumns()) { buf.append(dbPanel.getColumnDisplayName(pdata.getName(), s[0], false)); buf.append("="); buf.append(dbPanel.getColumnDisplayName(td.getName(), s[1], false)); buf.append(Constants.HTML_LINE_BREAK); } buf.append("</html>"); retval = buf.toString(); } } } return retval; }
From source file:org.mbari.aved.ui.classifier.knowledgebase.ConceptTree.java
/** * Sets the parent node of the currently selected node to be the node * representing the <code>Concept</code> of the specified name. * * @param newParentName The name of the <code>Concept</code> for which the currently selected * node is to become a child.//from www . ja v a 2 s. com */ public void updateTreeNodeParent(String newParentName) { // Get the node being moved DefaultMutableTreeNode conceptNode = (DefaultMutableTreeNode) getSelectionPath().getLastPathComponent(); String conceptNodeName = ((TreeConcept) conceptNode.getUserObject()).getName(); DefaultTreeModel treeModel = (DefaultTreeModel) getModel(); // Remove node from current parent node and update structure DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) conceptNode.getParent(); parentNode.remove(conceptNode); treeModel.nodeStructureChanged(parentNode); // Get the new parent node DefaultMutableTreeNode newParentNode = expandDownToNode(newParentName); TreeConcept treeConcept = (TreeConcept) newParentNode.getUserObject(); boolean parentNeededExpanding = treeConcept.lazyExpand(newParentNode); // Branch on whether parent needed expanding: // - The parent node needed to be expanded. The call to lazyExpand() // updates the parent node's children so we don't need to explicitly add // the new child node. Find and select the new child node. // - The parent node is already expanded, so insert the new child node in // the appropriate slot and select the new child node. if (parentNeededExpanding) { Enumeration children = newParentNode.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement(); String nodeName = ((TreeConcept) node.getUserObject()).getName(); if (nodeName.equals(conceptNodeName)) { setSelectionPath(new TreePath(node.getPath())); break; } } } else { // Insert the node at the appropriate point in the new parent node. int insertPosition = 0; Enumeration children = newParentNode.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement(); String nodeName = ((TreeConcept) node.getUserObject()).getName(); if (0 < nodeName.compareTo(conceptNodeName)) { break; } else { insertPosition++; } } treeModel.insertNodeInto(conceptNode, newParentNode, insertPosition); setSelectionPath(new TreePath(conceptNode.getPath())); } }
From source file:org.objectstyle.cayenne.modeler.ProjectTreeView.java
public void dataNodeChanged(DataNodeEvent e) { DefaultMutableTreeNode node = getProjectModel() .getNodeForObjectPath(new Object[] { mediator.getCurrentDataDomain(), e.getDataNode() }); if (node != null) { if (e.isNameChange()) { positionNode((DefaultMutableTreeNode) node.getParent(), node, Comparators.getDataDomainChildrenComparator()); showNode(node);//from w w w . j a v a 2 s .c o m } else { getProjectModel().nodeChanged(node); // check for DataMap additions/removals... Object[] maps = e.getDataNode().getDataMaps().toArray(); int mapCount = maps.length; // DataMap was linked if (mapCount > node.getChildCount()) { for (int i = 0; i < mapCount; i++) { boolean found = false; for (int j = 0; j < node.getChildCount(); j++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(j); if (maps[i] == child.getUserObject()) { found = true; break; } } if (!found) { DefaultMutableTreeNode newMapNode = new DefaultMutableTreeNode(maps[i], false); positionNode(node, newMapNode, Comparators.getNamedObjectComparator()); break; } } } // DataMap was unlinked else if (mapCount < node.getChildCount()) { for (int j = 0; j < node.getChildCount(); j++) { boolean found = false; DefaultMutableTreeNode child; child = (DefaultMutableTreeNode) node.getChildAt(j); Object obj = child.getUserObject(); for (int i = 0; i < mapCount; i++) { if (maps[i] == obj) { found = true; break; } } if (!found) { removeNode(child); break; } } } } } }
From source file:org.tinymediamanager.ui.tvshows.TvShowPanel.java
/** * Instantiates a new tv show panel.//from ww w . java 2 s . c o m */ public TvShowPanel() { super(); treeModel = new TvShowTreeModel(tvShowList.getTvShows()); tvShowSeasonSelectionModel = new TvShowSeasonSelectionModel(); tvShowEpisodeSelectionModel = new TvShowEpisodeSelectionModel(); // build menu menu = new JMenu(BUNDLE.getString("tmm.tvshows")); //$NON-NLS-1$ JFrame mainFrame = MainWindow.getFrame(); JMenuBar menuBar = mainFrame.getJMenuBar(); menuBar.add(menu); setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("850px:grow"), FormFactory.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"), })); JSplitPane splitPane = new JSplitPane(); splitPane.setContinuousLayout(true); add(splitPane, "2, 2, fill, fill"); JPanel panelTvShowTree = new JPanel(); splitPane.setLeftComponent(panelTvShowTree); panelTvShowTree.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.UNRELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("3px:grow"), FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); textField = EnhancedTextField.createSearchTextField(); panelTvShowTree.add(textField, "4, 1, right, bottom"); textField.setColumns(12); textField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(final DocumentEvent e) { applyFilter(); } @Override public void removeUpdate(final DocumentEvent e) { applyFilter(); } @Override public void changedUpdate(final DocumentEvent e) { applyFilter(); } public void applyFilter() { TvShowTreeModel filteredModel = (TvShowTreeModel) tree.getModel(); if (StringUtils.isNotBlank(textField.getText())) { filteredModel.setFilter(SearchOptions.TEXT, textField.getText()); } else { filteredModel.removeFilter(SearchOptions.TEXT); } filteredModel.filter(tree); } }); final JToggleButton btnFilter = new JToggleButton(IconManager.FILTER); btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options")); //$NON-NLS-1$ panelTvShowTree.add(btnFilter, "6, 1, default, bottom"); JScrollPane scrollPane = new JScrollPane(); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); panelTvShowTree.add(scrollPane, "2, 3, 5, 1, fill, fill"); JToolBar toolBar = new JToolBar(); toolBar.setRollover(true); toolBar.setFloatable(false); toolBar.setOpaque(false); panelTvShowTree.add(toolBar, "2, 1"); // toolBar.add(actionUpdateDatasources); final JSplitButton buttonUpdateDatasource = new JSplitButton(IconManager.REFRESH); // temp fix for size of the button buttonUpdateDatasource.setText(" "); buttonUpdateDatasource.setHorizontalAlignment(JButton.LEFT); // buttonScrape.setMargin(new Insets(2, 2, 2, 24)); buttonUpdateDatasource.setSplitWidth(18); buttonUpdateDatasource.setToolTipText(BUNDLE.getString("update.datasource")); //$NON-NLS-1$ buttonUpdateDatasource.addSplitButtonActionListener(new SplitButtonActionListener() { public void buttonClicked(ActionEvent e) { actionUpdateDatasources.actionPerformed(e); } public void splitButtonClicked(ActionEvent e) { // build the popupmenu on the fly buttonUpdateDatasource.getPopupMenu().removeAll(); buttonUpdateDatasource.getPopupMenu().add(new JMenuItem(actionUpdateDatasources2)); buttonUpdateDatasource.getPopupMenu().addSeparator(); for (String ds : TvShowModuleManager.SETTINGS.getTvShowDataSource()) { buttonUpdateDatasource.getPopupMenu() .add(new JMenuItem(new TvShowUpdateSingleDatasourceAction(ds))); } buttonUpdateDatasource.getPopupMenu().addSeparator(); buttonUpdateDatasource.getPopupMenu().add(new JMenuItem(actionUpdateTvShow)); buttonUpdateDatasource.getPopupMenu().pack(); } }); JPopupMenu popup = new JPopupMenu("popup"); buttonUpdateDatasource.setPopupMenu(popup); toolBar.add(buttonUpdateDatasource); JSplitButton buttonScrape = new JSplitButton(IconManager.SEARCH); // temp fix for size of the button buttonScrape.setText(" "); buttonScrape.setHorizontalAlignment(JButton.LEFT); buttonScrape.setSplitWidth(18); buttonScrape.setToolTipText(BUNDLE.getString("tvshow.scrape.selected")); //$NON-NLS-1$ // register for listener buttonScrape.addSplitButtonActionListener(new SplitButtonActionListener() { @Override public void buttonClicked(ActionEvent e) { actionScrape.actionPerformed(e); } @Override public void splitButtonClicked(ActionEvent e) { } }); popup = new JPopupMenu("popup"); JMenuItem item = new JMenuItem(actionScrape2); popup.add(item); // item = new JMenuItem(actionScrapeUnscraped); // popup.add(item); item = new JMenuItem(actionScrapeSelected); popup.add(item); item = new JMenuItem(actionScrapeNewItems); popup.add(item); buttonScrape.setPopupMenu(popup); toolBar.add(buttonScrape); toolBar.add(actionEdit); JButton btnMediaInformation = new JButton(); btnMediaInformation.setAction(actionMediaInformation); toolBar.add(btnMediaInformation); // install drawing of full with tree = new ZebraJTree(treeModel) { private static final long serialVersionUID = 2422163883324014637L; @Override public void paintComponent(Graphics g) { width = this.getWidth(); super.paintComponent(g); } }; tvShowSelectionModel = new TvShowSelectionModel(tree); TreeUI ui = new TreeUI() { @Override protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) { bounds.width = width - bounds.x; super.paintRow(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf); } }; tree.setUI(ui); tree.setRootVisible(false); tree.setShowsRootHandles(true); tree.setCellRenderer(new TvShowTreeCellRenderer()); tree.setRowHeight(0); scrollPane.setViewportView(tree); JPanel panelHeader = new JPanel() { private static final long serialVersionUID = -6914183798172482157L; @Override public void paintComponent(Graphics g) { super.paintComponent(g); JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getColHeaderColors(), 0, 0, getWidth(), getHeight()); } }; scrollPane.setColumnHeaderView(panelHeader); panelHeader.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("center:20px"), ColumnSpec.decode("center:20px"), ColumnSpec.decode("center:20px") }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, })); JLabel lblTvShowsColumn = new JLabel(BUNDLE.getString("metatag.tvshow")); //$NON-NLS-1$ lblTvShowsColumn.setHorizontalAlignment(JLabel.CENTER); panelHeader.add(lblTvShowsColumn, "2, 1"); JLabel lblNfoColumn = new JLabel(""); lblNfoColumn.setHorizontalAlignment(JLabel.CENTER); lblNfoColumn.setIcon(IconManager.INFO); lblNfoColumn.setToolTipText(BUNDLE.getString("metatag.nfo"));//$NON-NLS-1$ panelHeader.add(lblNfoColumn, "4, 1"); JLabel lblImageColumn = new JLabel(""); lblImageColumn.setHorizontalAlignment(JLabel.CENTER); lblImageColumn.setIcon(IconManager.IMAGE); lblImageColumn.setToolTipText(BUNDLE.getString("metatag.images"));//$NON-NLS-1$ panelHeader.add(lblImageColumn, "5, 1"); JLabel lblSubtitleColumn = new JLabel(""); lblSubtitleColumn.setHorizontalAlignment(JLabel.CENTER); lblSubtitleColumn.setIcon(IconManager.SUBTITLE); lblSubtitleColumn.setToolTipText(BUNDLE.getString("metatag.subtitles"));//$NON-NLS-1$ panelHeader.add(lblSubtitleColumn, "6, 1"); JPanel panel = new JPanel(); panelTvShowTree.add(panel, "2, 5, 3, 1, fill, fill"); panel.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, }, new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); JLabel lblTvShowsT = new JLabel(BUNDLE.getString("metatag.tvshows") + ":"); //$NON-NLS-1$ panel.add(lblTvShowsT, "1, 2, fill, fill"); lblTvShows = new JLabel(""); panel.add(lblTvShows, "3, 2"); JLabel labelSlash = new JLabel("/"); panel.add(labelSlash, "5, 2"); JLabel lblEpisodesT = new JLabel(BUNDLE.getString("metatag.episodes") + ":"); //$NON-NLS-1$ panel.add(lblEpisodesT, "7, 2"); lblEpisodes = new JLabel(""); panel.add(lblEpisodes, "9, 2"); JLayeredPane layeredPaneRight = new JLayeredPane(); layeredPaneRight.setLayout( new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default"), ColumnSpec.decode("default:grow") }, new RowSpec[] { RowSpec.decode("default"), RowSpec.decode("default:grow") })); panelRight = new JPanel(); layeredPaneRight.add(panelRight, "1, 1, 2, 2, fill, fill"); layeredPaneRight.setLayer(panelRight, 0); // glass pane final TvShowExtendedSearchPanel panelExtendedSearch = new TvShowExtendedSearchPanel(treeModel, tree); panelExtendedSearch.setVisible(false); // panelMovieList.add(panelExtendedSearch, "2, 5, 2, 1, fill, fill"); btnFilter.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (panelExtendedSearch.isVisible() == true) { panelExtendedSearch.setVisible(false); } else { panelExtendedSearch.setVisible(true); } } }); // add a propertychangelistener which reacts on setting a filter tree.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if ("filterChanged".equals(evt.getPropertyName())) { if (Boolean.TRUE.equals(evt.getNewValue())) { btnFilter.setIcon(IconManager.FILTER_ACTIVE); btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options.active")); //$NON-NLS-1$ } else { btnFilter.setIcon(IconManager.FILTER); btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options")); //$NON-NLS-1$ } } } }); layeredPaneRight.add(panelExtendedSearch, "1, 1, fill, fill"); layeredPaneRight.setLayer(panelExtendedSearch, 1); splitPane.setRightComponent(layeredPaneRight); panelRight.setLayout(new CardLayout(0, 0)); JPanel panelTvShow = new TvShowInformationPanel(tvShowSelectionModel); panelRight.add(panelTvShow, "tvShow"); JPanel panelTvShowSeason = new TvShowSeasonInformationPanel(tvShowSeasonSelectionModel); panelRight.add(panelTvShowSeason, "tvShowSeason"); JPanel panelTvShowEpisode = new TvShowEpisodeInformationPanel(tvShowEpisodeSelectionModel); panelRight.add(panelTvShowEpisode, "tvShowEpisode"); tree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node != null) { // click on a tv show if (node.getUserObject() instanceof TvShow) { TvShow tvShow = (TvShow) node.getUserObject(); tvShowSelectionModel.setSelectedTvShow(tvShow); CardLayout cl = (CardLayout) (panelRight.getLayout()); cl.show(panelRight, "tvShow"); } // click on a season if (node.getUserObject() instanceof TvShowSeason) { TvShowSeason tvShowSeason = (TvShowSeason) node.getUserObject(); tvShowSeasonSelectionModel.setSelectedTvShowSeason(tvShowSeason); CardLayout cl = (CardLayout) (panelRight.getLayout()); cl.show(panelRight, "tvShowSeason"); } // click on an episode if (node.getUserObject() instanceof TvShowEpisode) { TvShowEpisode tvShowEpisode = (TvShowEpisode) node.getUserObject(); tvShowEpisodeSelectionModel.setSelectedTvShowEpisode(tvShowEpisode); CardLayout cl = (CardLayout) (panelRight.getLayout()); cl.show(panelRight, "tvShowEpisode"); } } else { // check if there is at least one tv show in the model TvShowRootTreeNode root = (TvShowRootTreeNode) tree.getModel().getRoot(); if (root.getChildCount() == 0) { // sets an inital show tvShowSelectionModel.setSelectedTvShow(null); } } } }); addComponentListener(new ComponentAdapter() { @Override public void componentHidden(ComponentEvent e) { menu.setVisible(false); super.componentHidden(e); } @Override public void componentShown(ComponentEvent e) { menu.setVisible(true); super.componentHidden(e); } }); // further initializations init(); initDataBindings(); // selecting first TV show at startup if (tvShowList.getTvShows() != null && tvShowList.getTvShows().size() > 0) { DefaultMutableTreeNode firstLeaf = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) tree.getModel() .getRoot()).getFirstChild(); tree.setSelectionPath(new TreePath(((DefaultMutableTreeNode) firstLeaf.getParent()).getPath())); tree.setSelectionPath(new TreePath(firstLeaf.getPath())); } }