001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 * Portions Copyright 2014-2016 ForgeRock AS. 016 */ 017 018package org.opends.guitools.controlpanel.ui.components; 019 020import java.awt.Component; 021import java.awt.GridBagConstraints; 022 023import javax.swing.JTree; 024import javax.swing.tree.TreeSelectionModel; 025 026import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent; 027import org.opends.guitools.controlpanel.ui.ColorAndFontConstants; 028import org.opends.guitools.controlpanel.ui.GenericDialog; 029import org.opends.guitools.controlpanel.ui.StatusGenericPanel; 030import org.opends.guitools.controlpanel.ui.renderer.TreeCellRenderer; 031import org.forgerock.i18n.LocalizableMessage; 032 033/** A basic panel containing a CustomTree. */ 034public class TreePanel extends StatusGenericPanel 035{ 036 private static final long serialVersionUID = 5650902943430126109L; 037 private JTree tree; 038 039 /** Default constructor. */ 040 public TreePanel() 041 { 042 super(); 043 createLayout(); 044 } 045 046 /** Creates the layout of the panel (but the contents are not populated here). */ 047 private void createLayout() 048 { 049 GridBagConstraints gbc = new GridBagConstraints(); 050 gbc.fill = GridBagConstraints.BOTH; 051 gbc.weightx = 1.0; 052 gbc.weighty = 1.0; 053 054 tree = new CustomTree(); 055 tree.getSelectionModel().setSelectionMode( 056 TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); 057 tree.setBackground(ColorAndFontConstants.background); 058 tree.setCellRenderer(new TreeCellRenderer()); 059 tree.setShowsRootHandles(true); 060 tree.setScrollsOnExpand(false); 061 add(tree, gbc); 062 } 063 064 /** 065 * Returns the tree contained in the panel. 066 * @return the tree contained in the panel. 067 */ 068 public JTree getTree() 069 { 070 return tree; 071 } 072 073 @Override 074 public void okClicked() 075 { 076 // No ok button 077 } 078 079 @Override 080 public GenericDialog.ButtonType getButtonType() 081 { 082 return GenericDialog.ButtonType.NO_BUTTON; 083 } 084 085 @Override 086 public LocalizableMessage getTitle() 087 { 088 return null; 089 } 090 091 @Override 092 public Component getPreferredFocusComponent() 093 { 094 return tree; 095 } 096 097 @Override 098 public void configurationChanged(ConfigurationChangeEvent ev) 099 { 100 } 101}