001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (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.sitemap.client.hoverbar; 029 030import org.opencms.ade.sitemap.client.CmsSitemapView; 031import org.opencms.ade.sitemap.client.Messages; 032import org.opencms.ade.sitemap.client.control.CmsSitemapController; 033import org.opencms.ade.sitemap.shared.CmsClientSitemapEntry; 034import org.opencms.ade.sitemap.shared.CmsNewResourceInfo; 035import org.opencms.gwt.client.CmsCoreProvider; 036import org.opencms.gwt.client.ui.CmsConfirmDialog; 037import org.opencms.gwt.client.ui.I_CmsConfirmDialogHandler; 038import org.opencms.util.CmsUUID; 039 040/** 041 * Context menu entry for editing a model page.<p> 042 */ 043public class CmsEditModelPageMenuEntry extends A_CmsSitemapMenuEntry { 044 045 /** 046 * Creates a new instance.<p> 047 * 048 * @param hoverbar the hover bar 049 */ 050 public CmsEditModelPageMenuEntry(CmsSitemapHoverbar hoverbar) { 051 052 super(hoverbar); 053 setLabel(Messages.get().key(Messages.GUI_EDIT_MODELPAGE_CONTEXTMENU_0)); 054 setActive(true); 055 } 056 057 /** 058 * Checks if the model page menu entry should be visible.<p> 059 * 060 * @param id the id of the model page 061 * @return true if the entry should be visible 062 */ 063 public static boolean checkVisible(CmsUUID id) { 064 065 boolean show = false; 066 if (CmsSitemapView.getInstance().getController().isEditable()) { 067 CmsNewResourceInfo info = CmsSitemapView.getInstance().getController().getData().getNewResourceInfoById(id); 068 show = CmsSitemapView.getInstance().isModelPageMode() 069 && (((info != null) && info.isEditable()) || CmsSitemapView.getInstance().isModelGroupEntry(id)); 070 } 071 return show; 072 } 073 074 /** 075 * Opens the editor for a model page menu entry.<p> 076 * 077 * @param resourcePath the resource path of the model page 078 * @param isModelGroup if the given entry is a model group page 079 */ 080 public static void editModelPage(final String resourcePath, boolean isModelGroup) { 081 082 if (CmsSitemapView.getInstance().getController().getData().isShowModelEditConfirm()) { 083 I_CmsConfirmDialogHandler handler = new I_CmsConfirmDialogHandler() { 084 085 public void onClose() { 086 087 // noop 088 } 089 090 public void onOk() { 091 092 openEditor(resourcePath); 093 } 094 }; 095 String dialogTitle; 096 String dialogContent; 097 if (isModelGroup) { 098 dialogTitle = Messages.get().key(Messages.GUI_EDIT_MODEL_GROUPS_CONFIRM_TITLE_0); 099 dialogContent = Messages.get().key(Messages.GUI_EDIT_MODEL_GROUP_CONFIRM_CONTENT_0); 100 } else { 101 dialogTitle = Messages.get().key(Messages.GUI_EDIT_MODELPAGE_CONFIRM_TITLE_0); 102 dialogContent = Messages.get().key(Messages.GUI_EDIT_MODELPAGE_CONFIRM_CONTENT_0); 103 } 104 String buttonText = Messages.get().key(Messages.GUI_EDIT_MODELPAGE_OK_0); 105 106 CmsConfirmDialog dialog = new CmsConfirmDialog(dialogTitle, dialogContent); 107 dialog.getOkButton().setText(buttonText); 108 dialog.setHandler(handler); 109 dialog.center(); 110 } else { 111 openEditor(resourcePath); 112 } 113 } 114 115 /** 116 * Opens the container page editor for the given model resource.<p> 117 * 118 * @param targetPath the model resource path 119 */ 120 static void openEditor(String targetPath) { 121 122 String siteRoot = CmsCoreProvider.get().getSiteRoot(); 123 if (targetPath.startsWith(siteRoot)) { 124 targetPath = targetPath.substring(siteRoot.length()); 125 // prepend slash if necessary 126 if (!targetPath.startsWith("/")) { 127 targetPath = "/" + targetPath; 128 } 129 } 130 CmsSitemapController controller = CmsSitemapView.getInstance().getController(); 131 controller.leaveEditor(targetPath); 132 } 133 134 /** 135 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#execute() 136 */ 137 public void execute() { 138 139 CmsClientSitemapEntry entry = getHoverbar().getEntry(); 140 CmsUUID id = entry.getId(); 141 editModelPage(entry.getSitePath(), !CmsSitemapView.getInstance().isModelPageEntry(id) 142 && !CmsSitemapView.getInstance().isParentModelPageEntry(id)); 143 } 144 145 /** 146 * @see org.opencms.ade.sitemap.client.hoverbar.A_CmsSitemapMenuEntry#onShow() 147 */ 148 @Override 149 public void onShow() { 150 151 CmsUUID id = getHoverbar().getId(); 152 153 boolean show = checkVisible(id); 154 setVisible(show); 155 156 } 157 158}