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-2009 Sun Microsystems, Inc. 015 * Portions Copyright 2014-2015 ForgeRock AS. 016 */ 017 018package org.opends.guitools.controlpanel.ui; 019 020import static org.opends.messages.AdminToolMessages.*; 021 022import java.util.ArrayList; 023import java.util.Collection; 024import java.util.HashSet; 025import java.util.LinkedHashSet; 026import java.util.SortedSet; 027import java.util.TreeSet; 028 029import org.opends.guitools.controlpanel.datamodel.BackendDescriptor; 030import org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor; 031import org.opends.guitools.controlpanel.datamodel.ServerDescriptor; 032import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent; 033import org.opends.guitools.controlpanel.task.DeleteBaseDNAndBackendTask; 034import org.opends.guitools.controlpanel.task.Task; 035import org.opends.guitools.controlpanel.util.Utilities; 036import org.forgerock.i18n.LocalizableMessage; 037import org.forgerock.i18n.LocalizableMessageBuilder; 038 039/** 040 * The panel displayed when the user clicks on 'Delete Backend...' in the 041 * browse entries dialog. 042 * 043 */ 044public class DeleteBackendPanel extends DeleteBaseDNPanel 045{ 046 private static final long serialVersionUID = 8744925738292396658L; 047 048 /** {@inheritDoc} */ 049 public LocalizableMessage getTitle() 050 { 051 return INFO_CTRL_PANEL_DELETE_BACKEND_TITLE.get(); 052 } 053 054 /** 055 * Returns the no backend found label. 056 * @return the no backend found label. 057 */ 058 protected LocalizableMessage getNoElementsFoundLabel() 059 { 060 return INFO_CTRL_PANEL_NO_BACKENDS_FOUND_LABEL.get(); 061 } 062 063 /** 064 * Returns the list label. 065 * @return the list label. 066 */ 067 protected LocalizableMessage getListLabel() 068 { 069 return INFO_CTRL_PANEL_SELECT_BACKENDS_TO_DELETE.get(); 070 } 071 072 /** {@inheritDoc} */ 073 public void configurationChanged(ConfigurationChangeEvent ev) 074 { 075 ServerDescriptor desc = ev.getNewDescriptor(); 076 final SortedSet<String> newElements = new TreeSet<>(); 077 for (BackendDescriptor backend : desc.getBackends()) 078 { 079 if (!backend.isConfigBackend()) 080 { 081 newElements.add(backend.getBackendID()); 082 } 083 } 084 updateList(newElements); 085 updateErrorPaneAndOKButtonIfAuthRequired(desc, 086 isLocal() ? 087 INFO_CTRL_PANEL_AUTHENTICATION_REQUIRED_FOR_BACKEND_DELETE.get() : 088 INFO_CTRL_PANEL_CANNOT_CONNECT_TO_REMOTE_DETAILS.get(desc.getHostname())); 089 } 090 091 /** {@inheritDoc} */ 092 public void okClicked() 093 { 094 final LinkedHashSet<LocalizableMessage> errors = new LinkedHashSet<>(); 095 ProgressDialog progressDialog = new ProgressDialog( 096 Utilities.createFrame(), 097 Utilities.getParentDialog(this), getTitle(), getInfo()); 098 @SuppressWarnings("deprecation") 099 Object[] backends = list.getSelectedValues(); 100 ArrayList<BackendDescriptor> backendsToDelete = new ArrayList<>(); 101 for (Object o : backends) 102 { 103 String id = (String)o; 104 for (BackendDescriptor backend : 105 getInfo().getServerDescriptor().getBackends()) 106 { 107 if (backend.getBackendID().equalsIgnoreCase(id)) 108 { 109 backendsToDelete.add(backend); 110 break; 111 } 112 } 113 } 114 DeleteBaseDNAndBackendTask newTask = new DeleteBaseDNAndBackendTask( 115 getInfo(), progressDialog, backendsToDelete, 116 new HashSet<BaseDNDescriptor>()); 117 for (Task task : getInfo().getTasks()) 118 { 119 task.canLaunch(newTask, errors); 120 } 121 if (errors.isEmpty()) 122 { 123 LocalizableMessage confirmationMessage = getConfirmationMessage(backendsToDelete); 124 if (displayConfirmationDialog( 125 INFO_CTRL_PANEL_CONFIRMATION_REQUIRED_SUMMARY.get(), 126 confirmationMessage)) 127 { 128 launchOperation(newTask, 129 INFO_CTRL_PANEL_DELETING_BACKENDS_SUMMARY.get(), 130 INFO_CTRL_PANEL_DELETING_BACKENDS_COMPLETE.get(), 131 INFO_CTRL_PANEL_DELETING_BACKENDS_SUCCESSFUL.get(), 132 ERR_CTRL_PANEL_DELETING_BACKENDS_ERROR_SUMMARY.get(), 133 ERR_CTRL_PANEL_DELETING_BACKENDS_ERROR_DETAILS.get(), 134 null, 135 progressDialog); 136 progressDialog.setVisible(true); 137 Utilities.getParentDialog(this).setVisible(false); 138 } 139 } 140 if (!errors.isEmpty()) 141 { 142 displayErrorDialog(errors); 143 } 144 } 145 146 private LocalizableMessage getConfirmationMessage( 147 Collection<BackendDescriptor> backendsToDelete) 148 { 149 LocalizableMessageBuilder mb = new LocalizableMessageBuilder(); 150 mb.append(INFO_CTRL_PANEL_CONFIRMATION_DELETE_BACKENDS_DETAILS.get()); 151 for (BackendDescriptor backend : backendsToDelete) 152 { 153 mb.append("<br> - ").append(backend.getBackendID()); 154 } 155 mb.append("<br><br>"); 156 mb.append(INFO_CTRL_PANEL_DO_YOU_WANT_TO_CONTINUE.get()); 157 return mb.toMessage(); 158 } 159} 160