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 2006-2010 Sun Microsystems, Inc. 015 * Portions Copyright 2011-2015 ForgeRock AS. 016 */ 017 018package org.opends.guitools.uninstaller.ui; 019 020import org.opends.quicksetup.CurrentInstallStatus; 021import org.opends.quicksetup.Installation; 022import org.opends.quicksetup.Configuration; 023import org.opends.quicksetup.ui.FieldName; 024import org.opends.quicksetup.ui.GuiApplication; 025import org.opends.quicksetup.ui.QuickSetupStepPanel; 026import org.opends.quicksetup.ui.UIFactory; 027import org.opends.quicksetup.util.Utils; 028 029import javax.swing.*; 030import javax.swing.border.EmptyBorder; 031import java.awt.*; 032import java.util.HashMap; 033import java.util.HashSet; 034import java.util.Set; 035 036import org.forgerock.i18n.LocalizableMessage; 037import org.forgerock.i18n.slf4j.LocalizedLogger; 038import java.io.IOException; 039 040import static org.opends.messages.AdminToolMessages.*; 041 042/** 043 * This is the panel displayed when the user is uninstalling Open DS. It is 044 * basically a panel with the text informing of the consequences of uninstalling 045 * the server and asking for confirmation. 046 * 047 */ 048public class ConfirmUninstallPanel extends QuickSetupStepPanel 049{ 050 private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); 051 052 private static final long serialVersionUID = 81730510134697056L; 053 054 private Set<String> outsideDbs; 055 private Set<String> outsideLogs; 056 057 private HashMap<FieldName, JCheckBox> hmCbs = new HashMap<>(); 058 059 /** 060 * The constructor of this class. 061 * @param application Application this panel represents 062 * @param installStatus the object describing the current installation status. 063 * 064 */ 065 public ConfirmUninstallPanel(GuiApplication application, 066 CurrentInstallStatus installStatus) 067 { 068 super(application); 069 } 070 071 /** {@inheritDoc} */ 072 @Override 073 public Object getFieldValue(FieldName fieldName) 074 { 075 switch (fieldName) 076 { 077 case EXTERNAL_DB_DIRECTORIES: 078 Set<String> s1 = new HashSet<>(); 079 if (outsideDbs.size() > 0 080 && getCheckBox(FieldName.EXTERNAL_DB_DIRECTORIES).isSelected()) 081 { 082 s1.addAll(outsideDbs); 083 } 084 return s1; 085 086 case EXTERNAL_LOG_FILES: 087 Set<String> s2 = new HashSet<>(); 088 if (outsideLogs.size() > 0 089 && getCheckBox(FieldName.EXTERNAL_LOG_FILES).isSelected()) 090 { 091 s2.addAll(outsideLogs); 092 } 093 return s2; 094 default: 095 JCheckBox cb = getCheckBox(fieldName); 096 return cb.isSelected(); 097 } 098 } 099 100 /** {@inheritDoc} */ 101 @Override 102 protected LocalizableMessage getTitle() 103 { 104 return INFO_CONFIRM_UNINSTALL_PANEL_TITLE.get(); 105 } 106 107 /** {@inheritDoc} */ 108 @Override 109 protected Component createInputPanel() 110 { 111 FieldName[] fieldNames = { 112 FieldName.REMOVE_LIBRARIES_AND_TOOLS, 113 FieldName.REMOVE_DATABASES, 114 FieldName.REMOVE_LOGS, 115 FieldName.REMOVE_CONFIGURATION_AND_SCHEMA, 116 FieldName.REMOVE_BACKUPS, 117 FieldName.REMOVE_LDIFS, 118 }; 119 120 LocalizableMessage[] labels = { 121 INFO_REMOVE_LIBRARIES_AND_TOOLS_LABEL.get(), 122 INFO_REMOVE_DATABASES_LABEL.get(), 123 INFO_REMOVE_LOGS_LABEL.get(), 124 INFO_REMOVE_SCHEMA_AND_CONFIGURATION_LABEL.get(), 125 INFO_REMOVE_BACKUPS_LABEL.get(), 126 INFO_REMOVE_LDIFS_LABEL.get() 127 }; 128 129 LocalizableMessage[] tooltips = { 130 INFO_REMOVE_LIBRARIES_AND_TOOLS_TOOLTIP.get(), 131 INFO_REMOVE_DATABASES_TOOLTIP.get(), 132 INFO_REMOVE_LOGS_TOOLTIP.get(), 133 INFO_REMOVE_SCHEMA_AND_CONFIGURATION_TOOLTIP.get(), 134 INFO_REMOVE_BACKUPS_TOOLTIP.get(), 135 INFO_REMOVE_LDIFS_TOOLTIP.get() 136 }; 137 138 for (int i=0; i<fieldNames.length; i++) 139 { 140 JCheckBox cb = UIFactory.makeJCheckBox(labels[i], tooltips[i], 141 UIFactory.TextStyle.INSTRUCTIONS); 142 cb.setSelected(true); 143 hmCbs.put(fieldNames[i], cb); 144 } 145 146 147 JPanel panel = new JPanel(new GridBagLayout()); 148 panel.setOpaque(false); 149 150 GridBagConstraints gbc = new GridBagConstraints(); 151 gbc.insets = UIFactory.getEmptyInsets(); 152 153 JPanel p = new JPanel(new GridBagLayout()); 154 p.setOpaque(false); 155 gbc.weightx = 0.0; 156 gbc.gridwidth = GridBagConstraints.RELATIVE; 157 gbc.anchor = GridBagConstraints.WEST; 158 p.add(UIFactory.makeJLabel(UIFactory.IconType.NO_ICON, 159 INFO_SERVER_PATH_LABEL.get(), 160 UIFactory.TextStyle.PRIMARY_FIELD_VALID), gbc); 161 gbc.gridwidth = GridBagConstraints.REMAINDER; 162 gbc.insets.left = UIFactory.LEFT_INSET_SECONDARY_FIELD; 163 p.add(UIFactory.makeJLabel(UIFactory.IconType.NO_ICON, 164 LocalizableMessage.raw(Utils.getInstallPathFromClasspath()), 165 UIFactory.TextStyle.INSTRUCTIONS), 166 gbc); 167 168 FieldName[] names = { 169 FieldName.REMOVE_LIBRARIES_AND_TOOLS, 170 FieldName.REMOVE_DATABASES, 171 FieldName.REMOVE_LOGS, 172 FieldName.REMOVE_CONFIGURATION_AND_SCHEMA, 173 FieldName.REMOVE_BACKUPS, 174 FieldName.REMOVE_LDIFS 175 }; 176 177 for (int i=0; i<names.length; i++) 178 { 179 gbc.gridwidth = GridBagConstraints.RELATIVE; 180 p.add(Box.createHorizontalGlue(), gbc); 181 gbc.insets.left = 0; 182 gbc.gridwidth = GridBagConstraints.REMAINDER; 183 gbc.insets.left = UIFactory.LEFT_INSET_SECONDARY_FIELD; 184 p.add(getCheckBox(names[i]), gbc); 185 } 186 187 gbc.weightx = 1.0; 188 gbc.fill = GridBagConstraints.NONE; 189 gbc.gridwidth = GridBagConstraints.REMAINDER; 190 gbc.anchor = GridBagConstraints.WEST; 191 gbc.insets.left = 0; 192 193 panel.add(p, gbc); 194 195 Installation installation = Installation.getLocal(); 196 Configuration config = installation.getCurrentConfiguration(); 197 try { 198 outsideDbs = config.getOutsideDbs(); 199 } catch (IOException ioe) { 200 logger.info(LocalizableMessage.raw("Unable to determin outside databases", ioe)); 201 } 202 203 try { 204 outsideLogs = config.getOutsideLogs(); 205 } catch (IOException ioe) { 206 logger.info(LocalizableMessage.raw("Unable to determin outside logs", ioe)); 207 } 208 209 210 gbc.insets.top = UIFactory.TOP_INSET_PRIMARY_FIELD; 211 gbc.fill = GridBagConstraints.HORIZONTAL; 212 gbc.weightx = 1.0; 213 if (outsideDbs.size() > 0) 214 { 215 JPanel dbPanel = createDbPanel(); 216 panel.add(dbPanel, gbc); 217 } 218 219 if (outsideLogs.size() > 0) 220 { 221 JPanel logPanel = createLogPanel(); 222 panel.add(logPanel, gbc); 223 } 224 225 addVerticalGlue(panel); 226 227 return panel; 228 } 229 230 /** {@inheritDoc} */ 231 @Override 232 protected LocalizableMessage getInstructions() 233 { 234 return INFO_CONFIRM_UNINSTALL_PANEL_INSTRUCTIONS.get(); 235 } 236 237 /** 238 * Creates a panel to ask the user if (s)he wants to remove the databases 239 * located outside the installation path. 240 * @return a panel to ask the user if (s)he wants to remove the databases 241 * located outside the installation path. 242 */ 243 private JPanel createDbPanel() 244 { 245 JCheckBox cbOutsideDbs = UIFactory.makeJCheckBox( 246 INFO_DELETE_OUTSIDE_DBS_LABEL.get(), 247 INFO_DELETE_OUTSIDE_DBS_TOOLTIP.get(), 248 UIFactory.TextStyle.INSTRUCTIONS); 249 cbOutsideDbs.setSelected(true); 250 hmCbs.put(FieldName.EXTERNAL_DB_DIRECTORIES, cbOutsideDbs); 251 252 return createOutsidePathPanel(cbOutsideDbs, outsideDbs, 253 INFO_DELETE_OUTSIDE_DBS_MSG.get()); 254 } 255 256 /** 257 * Creates a panel to ask the user if (s)he wants to remove the logs located 258 * outside the installation path. 259 * @return a panel to ask the user if (s)he wants to remove the logs located 260 * outside the installation path. 261 */ 262 private JPanel createLogPanel() 263 { 264 JCheckBox cbOutsideLogs = UIFactory.makeJCheckBox( 265 INFO_DELETE_OUTSIDE_LOGS_LABEL.get(), 266 INFO_DELETE_OUTSIDE_LOGS_TOOLTIP.get(), 267 UIFactory.TextStyle.INSTRUCTIONS); 268 cbOutsideLogs.setSelected(true); 269 hmCbs.put(FieldName.EXTERNAL_LOG_FILES, cbOutsideLogs); 270 271 return createOutsidePathPanel(cbOutsideLogs, outsideLogs, 272 INFO_DELETE_OUTSIDE_LOGS_MSG.get()); 273 } 274 275 private JPanel createOutsidePathPanel(JCheckBox cb, Set<String> paths, 276 LocalizableMessage msg) 277 { 278 JPanel panel = new JPanel(new GridBagLayout()); 279 panel.setOpaque(false); 280 281 GridBagConstraints gbc = new GridBagConstraints(); 282 gbc.insets = UIFactory.getEmptyInsets(); 283 gbc.weightx = 1.0; 284 gbc.gridwidth = GridBagConstraints.REMAINDER; 285 gbc.anchor = GridBagConstraints.WEST; 286 gbc.fill = GridBagConstraints.HORIZONTAL; 287 288 panel.add(UIFactory.makeJLabel(UIFactory.IconType.NO_ICON, msg, 289 UIFactory.TextStyle.INSTRUCTIONS), gbc); 290 DefaultListModel listModel = new DefaultListModel(); 291 for (String path : paths) 292 { 293 listModel.addElement(path); 294 } 295 JList list = UIFactory.makeJList(UIFactory.TextStyle.INSTRUCTIONS); 296 list.setModel(listModel); 297 list.setBackground(UIFactory.CURRENT_STEP_PANEL_BACKGROUND); 298 list.setVisibleRowCount(Math.min(3, listModel.getSize())); 299 JScrollPane scroll = new JScrollPane(list); 300 scroll.setViewportBorder(new EmptyBorder(0, 0, 0, 0)); 301 gbc.insets.left = UIFactory.LEFT_INSET_RADIO_SUBORDINATE; 302 panel.add(scroll, gbc); 303 304 gbc.insets.left = 0; 305 panel.add(cb, gbc); 306 307 return panel; 308 } 309 310 /** 311 * Returns the checkbox corresponding to the provided FieldName. 312 * @param fieldName the FieldName object. 313 * @return the checkbox corresponding to the provided FieldName. 314 */ 315 private JCheckBox getCheckBox(FieldName fieldName) 316 { 317 JCheckBox cb = hmCbs.get(fieldName); 318 if (cb == null) 319 { 320 throw new IllegalArgumentException("The FieldName "+fieldName+ 321 " has no checkbox associated."); 322 } 323 return cb; 324 } 325}