All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencms.setup.ui.CmsSetupErrorDialog Maven / Gradle / Ivy

/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.setup.ui;

import org.opencms.ui.A_CmsUI;
import org.opencms.ui.CmsVaadinUtils;
import org.opencms.ui.FontOpenCms;
import org.opencms.ui.components.CmsBasicDialog;
import org.opencms.ui.components.CmsCopyToClipboardButton;
import org.opencms.ui.components.OpenCmsTheme;
import org.opencms.util.CmsUUID;

import org.apache.commons.lang3.exception.ExceptionUtils;

import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Window.CloseEvent;
import com.vaadin.ui.Window.CloseListener;
import com.vaadin.v7.shared.ui.label.ContentMode;
import com.vaadin.v7.ui.Label;

/**
 * Dialog used to display error stack traces in the workplace.

*/ public class CmsSetupErrorDialog extends CmsBasicDialog { /** Serial version id. */ private static final long serialVersionUID = 1L; /** The select text button. */ private CmsCopyToClipboardButton m_copyText; /** The details component. */ private CssLayout m_details; /** The toggle details button. */ private Button m_detailsButton; /** Label to display. */ private Label m_errorLabel; /** Error message label. */ private Label m_errorMessage; /** Hidden stack trace element. */ private Label m_hiddenStack; /** Warning icon. */ private Label m_icon; /** The OK button. */ private Button m_okButton; /** The dialog context. */ private Runnable m_onClose; /** The dialog window. */ private Window m_window; /** * Creates a new instance.

* * @param message the error message * @param t the error to be displayed * @param onClose executed on close * @param window the dialog window if available */ public CmsSetupErrorDialog(String message, String details, Runnable onClose, final Window window) { m_onClose = onClose; m_window = window; CmsVaadinUtils.readAndLocalizeDesign(this, null, null); m_icon.setContentMode(ContentMode.HTML); m_icon.setValue(FontOpenCms.ERROR.getHtml()); m_errorLabel.setContentMode(ContentMode.PREFORMATTED); final String labelId = "label" + new CmsUUID().toString(); m_hiddenStack.setId(labelId); m_hiddenStack.setValue(details); m_errorLabel.setValue(details); m_errorLabel.addStyleName(OpenCmsTheme.FULL_WIDTH_PADDING); m_errorMessage.setContentMode(ContentMode.HTML); m_errorMessage.setValue(message); m_copyText.setSelector("#" + labelId); m_details.setVisible(false); m_okButton.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { onClose(); } }); m_detailsButton.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { toggleDetails(); } }); if (m_window != null) { m_window.addCloseListener(new CloseListener() { private static final long serialVersionUID = 1L; public void windowClose(CloseEvent e) { onClose(); } }); } } /** * Shows error dialog, manually supplying details instead of getting them from an exception stack trace. * * @param message the error message * @param details the details */ public static void showErrorDialog(String message, String details) { Window window = prepareWindow(DialogWidth.wide); window.setCaption("Error"); window.setContent(new CmsSetupErrorDialog(message, details, null, window)); A_CmsUI.get().addWindow(window); } /** * Shows the error dialog.

* * @param message the error message * @param t the error to be displayed */ public static void showErrorDialog(String message, Throwable t) { showErrorDialog(message, t, null); } /** * Shows the error dialog.

* * @param message the error message * @param t the error to be displayed * @param onClose executed on close */ public static void showErrorDialog(String message, Throwable t, Runnable onClose) { Window window = prepareWindow(DialogWidth.wide); window.setCaption("Error"); window.setContent( new CmsSetupErrorDialog(message, message + "\n\n" + ExceptionUtils.getStackTrace(t), onClose, window)); A_CmsUI.get().addWindow(window); } /** * Shows the error dialog.

* * @param t the error to be displayed */ public static void showErrorDialog(Throwable t) { showErrorDialog(t.getLocalizedMessage(), t, null); } /** * Shows the error dialog.

* * @param t the error to be displayed * @param onClose executed on close */ public static void showErrorDialog(Throwable t, Runnable onClose) { showErrorDialog(t.getLocalizedMessage(), t, onClose); } /** * Called on dialog close.

*/ void onClose() { if (m_onClose != null) { m_onClose.run(); } if (m_window != null) { m_window.close(); } } /** * Toggles the details visibility.

*/ void toggleDetails() { m_details.setVisible(!m_details.isVisible()); if (m_window != null) { m_window.center(); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy