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