3853N/A/*
3853N/A * CDDL HEADER START
3853N/A *
3853N/A * The contents of this file are subject to the terms of the
3853N/A * Common Development and Distribution License, Version 1.0 only
3853N/A * (the "License"). You may not use this file except in compliance
3853N/A * with the License.
3853N/A *
3853N/A * You can obtain a copy of the license at
3853N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
3853N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
3853N/A * See the License for the specific language governing permissions
3853N/A * and limitations under the License.
3853N/A *
3853N/A * When distributing Covered Code, include this CDDL HEADER in each
3853N/A * file and include the License file at
3853N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
3853N/A * add the following below this CDDL HEADER, with the fields enclosed
3853N/A * by brackets "[]" replaced with your own identifying information:
3853N/A * Portions Copyright [yyyy] [name of copyright owner]
3853N/A *
3853N/A * CDDL HEADER END
3853N/A *
3853N/A *
4500N/A * Copyright 2008-2009 Sun Microsystems, Inc.
3853N/A */
3853N/A
3853N/Apackage org.opends.guitools.controlpanel.ui;
3853N/A
3853N/Aimport static org.opends.messages.AdminToolMessages.*;
3853N/A
3853N/Aimport java.util.ArrayList;
3853N/Aimport java.util.Collection;
3853N/Aimport java.util.HashSet;
3853N/Aimport java.util.LinkedHashSet;
3853N/Aimport java.util.SortedSet;
3853N/Aimport java.util.TreeSet;
3853N/A
3853N/Aimport org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
3853N/Aimport org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor;
3853N/Aimport org.opends.guitools.controlpanel.datamodel.ServerDescriptor;
3853N/Aimport org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
3853N/Aimport org.opends.guitools.controlpanel.task.DeleteBaseDNAndBackendTask;
3853N/Aimport org.opends.guitools.controlpanel.task.Task;
3853N/Aimport org.opends.guitools.controlpanel.util.Utilities;
3853N/Aimport org.opends.messages.Message;
3853N/Aimport org.opends.messages.MessageBuilder;
3853N/A
3853N/A/**
3853N/A * The panel displayed when the user clicks on 'Delete Backend...' in the
3853N/A * browse entries dialog.
3853N/A *
3853N/A */
3853N/Apublic class DeleteBackendPanel extends DeleteBaseDNPanel
3853N/A{
3853N/A private static final long serialVersionUID = 8744925738292396658L;
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public Message getTitle()
3853N/A {
3853N/A return INFO_CTRL_PANEL_DELETE_BACKEND_TITLE.get();
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the no backend found label.
3853N/A * @return the no backend found label.
3853N/A */
3853N/A protected Message getNoElementsFoundLabel()
3853N/A {
3853N/A return INFO_CTRL_PANEL_NO_BACKENDS_FOUND_LABEL.get();
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the list label.
3853N/A * @return the list label.
3853N/A */
3853N/A protected Message getListLabel()
3853N/A {
3853N/A return INFO_CTRL_PANEL_SELECT_BACKENDS_TO_DELETE.get();
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public void configurationChanged(ConfigurationChangeEvent ev)
3853N/A {
3853N/A ServerDescriptor desc = ev.getNewDescriptor();
3853N/A final SortedSet<String> newElements = new TreeSet<String>();
3853N/A for (BackendDescriptor backend : desc.getBackends())
3853N/A {
3853N/A if (!backend.isConfigBackend())
3853N/A {
3853N/A newElements.add(backend.getBackendID());
3853N/A }
3853N/A }
3853N/A updateList(newElements);
4500N/A updateErrorPaneAndOKButtonIfAuthRequired(desc,
4500N/A isLocal() ?
4500N/A INFO_CTRL_PANEL_AUTHENTICATION_REQUIRED_FOR_BACKEND_DELETE.get() :
4500N/A INFO_CTRL_PANEL_CANNOT_CONNECT_TO_REMOTE_DETAILS.get(desc.getHostname()));
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public void okClicked()
3853N/A {
3853N/A final LinkedHashSet<Message> errors = new LinkedHashSet<Message>();
3853N/A ProgressDialog progressDialog = new ProgressDialog(
4832N/A Utilities.createFrame(),
3853N/A Utilities.getParentDialog(this), getTitle(), getInfo());
5902N/A @SuppressWarnings("deprecation")
3853N/A Object[] backends = list.getSelectedValues();
3853N/A ArrayList<BackendDescriptor> backendsToDelete =
3853N/A new ArrayList<BackendDescriptor>();
3853N/A for (Object o : backends)
3853N/A {
3853N/A String id = (String)o;
3853N/A for (BackendDescriptor backend :
3853N/A getInfo().getServerDescriptor().getBackends())
3853N/A {
3853N/A if (backend.getBackendID().equalsIgnoreCase(id))
3853N/A {
3853N/A backendsToDelete.add(backend);
3853N/A break;
3853N/A }
3853N/A }
3853N/A }
3853N/A DeleteBaseDNAndBackendTask newTask = new DeleteBaseDNAndBackendTask(
3853N/A getInfo(), progressDialog, backendsToDelete,
3853N/A new HashSet<BaseDNDescriptor>());
3853N/A for (Task task : getInfo().getTasks())
3853N/A {
3853N/A task.canLaunch(newTask, errors);
3853N/A }
3853N/A if (errors.isEmpty())
3853N/A {
3853N/A Message confirmationMessage = getConfirmationMessage(backendsToDelete);
3853N/A if (displayConfirmationDialog(
3853N/A INFO_CTRL_PANEL_CONFIRMATION_REQUIRED_SUMMARY.get(),
3853N/A confirmationMessage))
3853N/A {
3853N/A launchOperation(newTask,
3853N/A INFO_CTRL_PANEL_DELETING_BACKENDS_SUMMARY.get(),
3853N/A INFO_CTRL_PANEL_DELETING_BACKENDS_COMPLETE.get(),
3853N/A INFO_CTRL_PANEL_DELETING_BACKENDS_SUCCESSFUL.get(),
3853N/A ERR_CTRL_PANEL_DELETING_BACKENDS_ERROR_SUMMARY.get(),
3853N/A ERR_CTRL_PANEL_DELETING_BACKENDS_ERROR_DETAILS.get(),
3853N/A null,
3853N/A progressDialog);
3853N/A progressDialog.setVisible(true);
3853N/A Utilities.getParentDialog(this).setVisible(false);
3853N/A }
3853N/A }
3853N/A if (errors.size() > 0)
3853N/A {
3853N/A displayErrorDialog(errors);
3853N/A }
3853N/A }
3853N/A
3853N/A private Message getConfirmationMessage(
3853N/A Collection<BackendDescriptor> backendsToDelete)
3853N/A {
3853N/A MessageBuilder mb = new MessageBuilder();
3853N/A mb.append(INFO_CTRL_PANEL_CONFIRMATION_DELETE_BACKENDS_DETAILS.get());
3853N/A for (BackendDescriptor backend : backendsToDelete)
3853N/A {
3853N/A mb.append("<br> - "+backend.getBackendID());
3853N/A }
3853N/A mb.append("<br><br>");
3853N/A mb.append(INFO_CTRL_PANEL_DO_YOU_WANT_TO_CONTINUE.get());
3853N/A return mb.toMessage();
3853N/A }
3853N/A}
3853N/A