/* * This library is part of OpenCms - * the Open Source Content Management System * * Copyright (c) Alkacon Software GmbH (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.gwt.client.ui; import org.opencms.gwt.client.CmsCoreProvider; import org.opencms.gwt.client.Messages; import org.opencms.gwt.client.rpc.CmsRpcAction; import org.opencms.gwt.client.ui.I_CmsButton.ButtonColor; import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle; import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle; import org.opencms.gwt.shared.CmsListInfoBean; import org.opencms.gwt.shared.CmsListInfoBean.LockIcon; import org.opencms.gwt.shared.CmsLockReportInfo; import org.opencms.util.CmsUUID; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.logical.shared.CloseEvent; import com.google.gwt.event.logical.shared.CloseHandler; import com.google.gwt.event.logical.shared.OpenEvent; import com.google.gwt.event.logical.shared.OpenHandler; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.ui.FlowPanel; /** * The lock report dialog.<p> * * @since 8.0.1 */ public final class CmsLockReportDialog extends CmsPopup { /** * Handles the scroll panel height.<p> */ private class HeightHandler implements CloseHandler<CmsListItemWidget>, OpenHandler<CmsListItemWidget> { /** * Constructor.<p> */ protected HeightHandler() { // nothing to do } /** * @see com.google.gwt.event.logical.shared.CloseHandler#onClose(com.google.gwt.event.logical.shared.CloseEvent) */ public void onClose(CloseEvent<CmsListItemWidget> event) { adjustHeight(); } /** * @see com.google.gwt.event.logical.shared.OpenHandler#onOpen(com.google.gwt.event.logical.shared.OpenEvent) */ public void onOpen(OpenEvent<CmsListItemWidget> event) { adjustHeight(); } } /** The dialog width. */ private static int DIALOG_WIDTH = 450; /** The text metrics key. */ private static final String TEXT_METRICS_KEY = "CMS_LOCK_REPORT_DIALOG_METRICS"; /** The close button. */ private CmsPushButton m_closeButton; /** Command executed on resource unlock. */ private Command m_onUnlock; /** The resource item widget. */ private CmsListItemWidget m_resourceItem; /** The scroll panel. */ private FlowPanel m_scrollPanel; /** The structure id of the resource to report on. */ private CmsUUID m_structureId; /** The unlock button. */ private CmsPushButton m_unlockButton; /** * Constructor.<p> * * @param structureId the structure id of the resource to unlock * @param the command to execute on unlock of the resource */ private CmsLockReportDialog(CmsUUID structureId, Command onUnlock) { super(Messages.get().key(Messages.GUI_LOCK_REPORT_TITLE_0), DIALOG_WIDTH); m_structureId = structureId; m_onUnlock = onUnlock; m_closeButton = new CmsPushButton(); m_closeButton.setText(Messages.get().key(Messages.GUI_CANCEL_0)); m_closeButton.setUseMinWidth(true); m_closeButton.setButtonStyle(ButtonStyle.TEXT, ButtonColor.BLUE); m_closeButton.addClickHandler(new ClickHandler() { /** * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent) */ public void onClick(ClickEvent event) { hide(); } }); addButton(m_closeButton); addDialogClose(null); m_unlockButton = new CmsPushButton(); m_unlockButton.setText(Messages.get().key(Messages.GUI_UNLOCK_ALL_0)); m_unlockButton.setUseMinWidth(true); m_unlockButton.setButtonStyle(ButtonStyle.TEXT, ButtonColor.RED); m_unlockButton.addClickHandler(new ClickHandler() { /** * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent) */ public void onClick(ClickEvent event) { unlock(); } }); m_unlockButton.setVisible(false); addButton(m_unlockButton); setGlassEnabled(true); } /** * Opens the lock report dialog for the given resource.<p> * * @param structureId the structure id of the resource * @param onUnlock the command to execute after the has been unlocked */ public static void openDialogForResource(final CmsUUID structureId, Command onUnlock) { final CmsLockReportDialog dialog = new CmsLockReportDialog(structureId, onUnlock); CmsRpcAction<CmsLockReportInfo> action = new CmsRpcAction<CmsLockReportInfo>() { @Override public void execute() { CmsCoreProvider.getVfsService().getLockReportInfo(structureId, this); } @Override public void onFailure(Throwable t) { dialog.hide(); super.onFailure(t); } @Override protected void onResponse(CmsLockReportInfo result) { dialog.initContent(result); } }; dialog.center(); action.execute(); } /** * Adjusts the height of the scroll panel.<p> */ protected void adjustHeight() { if ((m_scrollPanel != null) && (m_resourceItem != null)) { m_scrollPanel.getElement().getStyle().setPropertyPx( "maxHeight", getAvailableHeight(m_resourceItem.getOffsetHeight())); } center(); } /** * Returns the structure id of the resource to report on.<p> * * @return the structure id */ protected CmsUUID getStructureId() { return m_structureId; } /** * Initializes the dialog content with the give report info.<p> * * @param reportInfo the report info */ protected void initContent(CmsLockReportInfo reportInfo) { FlowPanel content = new FlowPanel(); m_resourceItem = new CmsListItemWidget(reportInfo.getResourceInfo()); HeightHandler heightHandler = new HeightHandler(); m_resourceItem.addOpenHandler(heightHandler); m_resourceItem.addCloseHandler(heightHandler); content.add(m_resourceItem); m_scrollPanel = new FlowPanel(); m_scrollPanel.setStyleName(I_CmsLayoutBundle.INSTANCE.generalCss().border()); m_scrollPanel.addStyleName(I_CmsLayoutBundle.INSTANCE.generalCss().cornerAll()); m_scrollPanel.addStyleName(I_CmsLayoutBundle.INSTANCE.dialogCss().logReportScrollPanel()); CmsMessageWidget message = new CmsMessageWidget(); m_scrollPanel.add(message); CmsList<CmsListItem> list = null; // only show the unlock button if the resource or a descending resource is locked if (!reportInfo.getLockedResourceInfos().isEmpty() || ((reportInfo.getResourceInfo().getLockIcon() != null) && (reportInfo.getResourceInfo().getLockIcon() != LockIcon.NONE))) { m_unlockButton.setVisible(true); message.setMessageText(Messages.get().key(Messages.GUI_LOCK_REPORT_UNLOCK_MESSAGE_0)); list = new CmsList<CmsListItem>(); for (CmsListInfoBean lockedInfo : reportInfo.getLockedResourceInfos()) { CmsListItemWidget listItemWidget = new CmsListItemWidget(lockedInfo); listItemWidget.addOpenHandler(heightHandler); listItemWidget.addCloseHandler(heightHandler); list.addItem(new CmsListItem(listItemWidget)); } m_scrollPanel.add(list); } else { message.setMessageText(Messages.get().key(Messages.GUI_LOCK_REPORT_NOTHING_LOCKED_0)); } content.add(m_scrollPanel); this.setMainContent(content); if (isShowing()) { m_resourceItem.truncate(TEXT_METRICS_KEY, DIALOG_WIDTH); if (list != null) { list.truncate(TEXT_METRICS_KEY, DIALOG_WIDTH); } adjustHeight(); } } /** * Executed on unlock.<p> */ protected void onUnlock() { if (m_onUnlock != null) { m_onUnlock.execute(); } hide(); } /** * Unlocks the resource and all descending resources.<p> */ protected void unlock() { CmsRpcAction<Void> action = new CmsRpcAction<Void>() { @Override public void execute() { CmsCoreProvider.getVfsService().forceUnlock(getStructureId(), this); } @Override public void onFailure(Throwable t) { hide(); super.onFailure(t); } @Override protected void onResponse(Void result) { onUnlock(); } }; m_closeButton.disable(Messages.get().key(Messages.GUI_LOADING_0)); m_unlockButton.disable(Messages.get().key(Messages.GUI_LOADING_0)); action.execute(); } }