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 2006-2008 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027 028package org.opends.quicksetup.ui; 029 030import java.awt.GridBagConstraints; 031import java.awt.GridBagLayout; 032import java.awt.event.ActionEvent; 033import java.awt.event.ActionListener; 034import java.util.HashSet; 035 036import javax.swing.Box; 037import javax.swing.JButton; 038import javax.swing.JPanel; 039import javax.swing.text.JTextComponent; 040 041import org.forgerock.i18n.LocalizableMessage; 042import org.opends.quicksetup.ButtonName; 043import org.opends.quicksetup.CurrentInstallStatus; 044import org.opends.quicksetup.event.ButtonActionListener; 045import org.opends.quicksetup.event.ButtonEvent; 046import static org.opends.messages.QuickSetupMessages.*; 047 048/** 049 * This class is a panel that contains an error message and a quit button. 050 * It is used for instance when we try to install Open DS but it is already 051 * installed. 052 * 053 */ 054public class QuickSetupErrorPanel extends QuickSetupPanel 055{ 056 private static final long serialVersionUID = 1765037717593522233L; 057 058 private HashSet<ButtonActionListener> buttonListeners = new HashSet<>(); 059 060 private JButton quitButton; 061 private JButton continueButton; 062 063 /** 064 * Constructor of the QuickSetupErrorPanel. 065 * @param application Application this panel represents 066 * @param installStatus the current install status. 067 */ 068 public QuickSetupErrorPanel(GuiApplication application, 069 CurrentInstallStatus installStatus) 070 { 071 this(application, installStatus.getInstallationMsg()); 072 continueButton.setVisible(installStatus.canOverwriteCurrentInstall()); 073 } 074 075 /** 076 * Constructor of the QuickSetupErrorPanel. 077 * @param application Application this panel represents 078 * @param msg the error message to display formatted in HTML. 079 */ 080 public QuickSetupErrorPanel(GuiApplication application, 081 LocalizableMessage msg) 082 { 083 super(application); 084 JPanel p1 = new JPanel(new GridBagLayout()); 085 p1.setBackground(UIFactory.CURRENT_STEP_PANEL_BACKGROUND); 086 p1.setBorder(UIFactory.DIALOG_PANEL_BORDER); 087 GridBagConstraints gbc = new GridBagConstraints(); 088 gbc.gridwidth = GridBagConstraints.RELATIVE; 089 gbc.anchor = GridBagConstraints.NORTHWEST; 090 gbc.insets = UIFactory.getCurrentStepPanelInsets(); 091 p1.add(UIFactory.makeJLabel(UIFactory.IconType.WARNING_LARGE, null, 092 UIFactory.TextStyle.NO_STYLE), gbc); 093 gbc.weightx = 1.0; 094 gbc.gridwidth = GridBagConstraints.REMAINDER; 095 gbc.fill = GridBagConstraints.BOTH; 096 gbc.insets.left = 0; 097 JTextComponent tf = 098 UIFactory.makeHtmlPane(msg, 099 UIFactory.INSTRUCTIONS_FONT); 100 tf.setOpaque(false); 101 tf.setEditable(false); 102 p1.add(tf, gbc); 103 104 gbc.weighty = 1.0; 105 gbc.fill = GridBagConstraints.VERTICAL; 106 p1.add(Box.createVerticalGlue(), gbc); 107 108 JPanel p2 = new JPanel(new GridBagLayout()); 109 p2.setOpaque(false); 110 gbc.fill = GridBagConstraints.HORIZONTAL; 111 gbc.weightx = 1.0; 112 gbc.insets = UIFactory.getEmptyInsets(); 113 gbc.gridwidth = 3; 114 p2.add(Box.createHorizontalGlue(), gbc); 115 quitButton = 116 UIFactory.makeJButton(INFO_QUIT_BUTTON_LABEL.get(), 117 INFO_QUIT_BUTTON_INSTALL_TOOLTIP.get()); 118 119 final ButtonName fQuitButtonName = ButtonName.QUIT; 120 121 ActionListener quitListener = new ActionListener() 122 { 123 public void actionPerformed(ActionEvent ev) 124 { 125 ButtonEvent be = new ButtonEvent(ev.getSource(), fQuitButtonName); 126 for (ButtonActionListener li : buttonListeners) 127 { 128 li.buttonActionPerformed(be); 129 } 130 } 131 }; 132 quitButton.addActionListener(quitListener); 133 134 continueButton = 135 UIFactory.makeJButton(INFO_CONTINUE_BUTTON_LABEL.get(), 136 INFO_CONTINUE_BUTTON_INSTALL_TOOLTIP.get()); 137 final ButtonName fContinueButtonName = ButtonName.CONTINUE_INSTALL; 138 139 ActionListener continueListener = new ActionListener() 140 { 141 public void actionPerformed(ActionEvent ev) 142 { 143 ButtonEvent be = new ButtonEvent(ev.getSource(), fContinueButtonName); 144 for (ButtonActionListener li : buttonListeners) 145 { 146 li.buttonActionPerformed(be); 147 } 148 } 149 }; 150 continueButton.addActionListener(continueListener); 151 152 gbc.fill = GridBagConstraints.NONE; 153 gbc.weightx = 0.0; 154 155 gbc.gridwidth = GridBagConstraints.RELATIVE; 156 p2.add(continueButton, gbc); 157 continueButton.setVisible(false); 158 159 gbc.insets.left = UIFactory.HORIZONTAL_INSET_BETWEEN_BUTTONS; 160 gbc.gridwidth = GridBagConstraints.REMAINDER; 161 p2.add(quitButton, gbc); 162 163 setLayout(new GridBagLayout()); 164 setBackground(UIFactory.DEFAULT_BACKGROUND); 165 setOpaque(true); 166 gbc.insets = UIFactory.getEmptyInsets(); 167 gbc.fill = GridBagConstraints.BOTH; 168 gbc.gridwidth = GridBagConstraints.REMAINDER; 169 gbc.weightx = 1.0; 170 gbc.weighty = 1.0; 171 add(p1, gbc); 172 gbc.weighty = 0.0; 173 gbc.insets = UIFactory.getButtonsPanelInsets(); 174 add(p2, gbc); 175 } 176 177 /** 178 * Adds a button listener. All the button listeners will be notified when 179 * the buttons are clicked (by the user or programatically). 180 * @param l the ButtonActionListener to be added. 181 */ 182 public void addButtonActionListener(ButtonActionListener l) 183 { 184 buttonListeners.add(l); 185 } 186 187 /** 188 * Removes a button listener. 189 * @param l the ButtonActionListener to be removed. 190 */ 191 public void removeButtonActionListener(ButtonActionListener l) 192 { 193 buttonListeners.remove(l); 194 } 195 196 /** 197 * Returns the quit button. 198 * @return the quit button. 199 */ 200 public JButton getQuitButton() 201 { 202 return quitButton; 203 } 204 205 /** 206 * Returns the continue install button. 207 * @return the continue install button. 208 */ 209 public JButton getContinueInstallButton() 210 { 211 return continueButton; 212 } 213}