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-2015 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/** 034 * A basic panel containing a CustomTree. 035 * 036 */ 037public class TreePanel extends StatusGenericPanel 038{ 039 private static final long serialVersionUID = 5650902943430126109L; 040 private JTree tree; 041 042 /** 043 * Default constructor. 044 * 045 */ 046 public TreePanel() 047 { 048 super(); 049 createLayout(); 050 } 051 052 /** 053 * Creates the layout of the panel (but the contents are not populated here). 054 * 055 */ 056 private void createLayout() 057 { 058 GridBagConstraints gbc = new GridBagConstraints(); 059 gbc.fill = GridBagConstraints.BOTH; 060 gbc.weightx = 1.0; 061 gbc.weighty = 1.0; 062 063 tree = new CustomTree(); 064 tree.getSelectionModel().setSelectionMode( 065 TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); 066 tree.setBackground(ColorAndFontConstants.background); 067 tree.setCellRenderer(new TreeCellRenderer()); 068 tree.setShowsRootHandles(true); 069 tree.setScrollsOnExpand(false); 070 add(tree, gbc); 071 } 072 073 /** 074 * Returns the tree contained in the panel. 075 * @return the tree contained in the panel. 076 */ 077 public JTree getTree() 078 { 079 return tree; 080 } 081 082 /** {@inheritDoc} */ 083 public void okClicked() 084 { 085 // No ok button 086 } 087 088 /** {@inheritDoc} */ 089 public GenericDialog.ButtonType getButtonType() 090 { 091 return GenericDialog.ButtonType.NO_BUTTON; 092 } 093 094 /** {@inheritDoc} */ 095 public LocalizableMessage getTitle() 096 { 097 return null; 098 } 099 100 /** {@inheritDoc} */ 101 public Component getPreferredFocusComponent() 102 { 103 return tree; 104 } 105 106 /** {@inheritDoc} */ 107 public void configurationChanged(ConfigurationChangeEvent ev) 108 { 109 } 110}