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; 019 020import java.awt.Component; 021import java.awt.GridBagConstraints; 022import java.util.Collection; 023 024import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent; 025import org.opends.guitools.controlpanel.util.Utilities; 026import org.forgerock.i18n.LocalizableMessage; 027import org.forgerock.i18n.LocalizableMessageBuilder; 028 029/** 030 * Class used to display an collection of error messages. 031 * 032 */ 033public class ErrorPanel extends StatusGenericPanel 034{ 035 private static final long serialVersionUID = -4494826284037288552L; 036 private LocalizableMessage title; 037 /** 038 * Constructor. 039 * @param title the title to be displayed in the dialog. 040 * @param errors the collection of errors to be displayed. 041 */ 042 public ErrorPanel(LocalizableMessage title, Collection<LocalizableMessage> errors) 043 { 044 super(); 045 this.title = title; 046 createLayout(errors); 047 } 048 049 /** {@inheritDoc} */ 050 public LocalizableMessage getTitle() 051 { 052 return title; 053 } 054 055 private void createLayout(Collection<LocalizableMessage> errors) 056 { 057 GridBagConstraints gbc = new GridBagConstraints(); 058 addErrorPane(gbc); 059 060 errorPane.setVisible(true); 061 062 LocalizableMessageBuilder mb = new LocalizableMessageBuilder(); 063 for (LocalizableMessage error : errors) 064 { 065 if (mb.length() > 0) 066 { 067 mb.append("<br>"); 068 } 069 mb.append(error); 070 } 071 072 updateErrorPane(errorPane, title, ColorAndFontConstants.errorTitleFont, 073 mb.toMessage(), ColorAndFontConstants.defaultFont); 074 075 gbc.weighty = 0.0; 076 addBottomGlue(gbc); 077 } 078 079 /** {@inheritDoc} */ 080 public GenericDialog.ButtonType getButtonType() 081 { 082 return GenericDialog.ButtonType.OK; 083 } 084 085 /** {@inheritDoc} */ 086 public void configurationChanged(ConfigurationChangeEvent ev) 087 { 088 } 089 090 /** {@inheritDoc} */ 091 public Component getPreferredFocusComponent() 092 { 093 return null; 094 } 095 096 /** {@inheritDoc} */ 097 public void okClicked() 098 { 099 Utilities.getParentDialog(this).setVisible(false); 100 } 101}