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