001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (C) Alkacon Software (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ade.publish.client; 029 030import org.opencms.ade.publish.client.CmsPublishDialog.State; 031import org.opencms.ade.publish.shared.CmsWorkflowAction; 032import org.opencms.gwt.client.CmsCoreProvider; 033import org.opencms.gwt.client.ui.CmsPopup; 034import org.opencms.gwt.client.ui.CmsPushButton; 035 036import java.util.ArrayList; 037import java.util.List; 038 039import com.google.gwt.dom.client.Style.Unit; 040import com.google.gwt.event.dom.client.ClickEvent; 041import com.google.gwt.event.dom.client.ClickHandler; 042import com.google.gwt.user.client.Window; 043import com.google.gwt.user.client.ui.HorizontalPanel; 044import com.google.gwt.user.client.ui.Label; 045import com.google.gwt.user.client.ui.Panel; 046 047/** 048 * A confirmation message dialog which can be displayed after the publish dialog has been closed.<p> 049 */ 050public class CmsPublishConfirmationDialog extends CmsPopup { 051 052 /** The link which is opened after the dialog is finished. */ 053 private String m_closeLink; 054 055 /** Flag indicating whether current user is a workplace user. */ 056 private boolean m_isWorkplaceUser; 057 058 /** The panel which contains the dialog contents. */ 059 private Panel m_panel = new HorizontalPanel(); 060 061 /** 062 * Creates a new publish confirmation dialog.<p> 063 * 064 * @param dialog the publish dialog instance 065 * @param closeLink the link to open after the dialog is finished 066 */ 067 public CmsPublishConfirmationDialog(CmsPublishDialog dialog, String closeLink) { 068 069 super(); 070 setModal(true); 071 setGlassEnabled(true); 072 CmsPublishDialog.State state = dialog.getState(); 073 m_closeLink = closeLink; 074 m_isWorkplaceUser = CmsCoreProvider.get().getUserInfo().isWorkplaceUser(); 075 String message = "-"; 076 if (state == State.success) { 077 CmsWorkflowAction lastAction = dialog.getLastAction(); 078 if (lastAction.isPublish()) { 079 message = getMessage( 080 m_isWorkplaceUser ? Messages.GUI_CONFIRMATION_PUBLISH_0 : Messages.GUI_CONFIRMATION_PUBLISH_NOWP_0); 081 } else { 082 message = getMessage( 083 m_isWorkplaceUser 084 ? Messages.GUI_CONFIRMATION_WORKFLOW_1 085 : Messages.GUI_CONFIRMATION_WORKFLOW_NOWP_1, 086 lastAction.getLabel()); 087 } 088 } else if (state == State.failure) { 089 message = dialog.getFailureMessage(); 090 } 091 Label label = new Label(message); 092 label.getElement().getStyle().setPaddingLeft(10, Unit.PX); 093 m_panel.getElement().getStyle().setPadding(10, Unit.PX); 094 m_panel.getElement().getStyle().setHeight(150, Unit.PX); 095 Label checkmark = new Label(); 096 checkmark.addStyleName(I_CmsPublishLayoutBundle.INSTANCE.publishCss().checkmark()); 097 m_panel.add(checkmark); 098 m_panel.add(label); 099 100 setMainContent(m_panel); 101 setCaption(getMessage(Messages.GUI_CONFIRMATION_CAPTION_0)); 102 for (CmsPushButton button : getButtons()) { 103 addButton(button); 104 } 105 } 106 107 /** 108 * Produces the buttons for this dialog.<p> 109 * 110 * @return a list of buttons that should be displayed 111 */ 112 protected List<CmsPushButton> getButtons() { 113 114 CmsPushButton workplaceButton = new CmsPushButton(); 115 workplaceButton.setText(getMessage(Messages.GUI_CONFIRMATION_WORKPLACE_BUTTON_0)); 116 workplaceButton.addClickHandler(new ClickHandler() { 117 118 @SuppressWarnings("synthetic-access") 119 public void onClick(ClickEvent e) { 120 121 Window.Location.assign(m_closeLink); 122 } 123 }); 124 List<CmsPushButton> result = new ArrayList<CmsPushButton>(); 125 if (m_isWorkplaceUser) { 126 result.add(workplaceButton); 127 } 128 return result; 129 } 130 131 /** 132 * Helper method to get a localized message.<p> 133 * 134 * @param key the message key 135 * @param args the message parameters 136 * 137 * @return the localized message 138 */ 139 protected String getMessage(String key, Object... args) { 140 141 return Messages.get().getBundle().key(key, args); 142 } 143 144}