001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.ui.sitemap; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.CmsResource; 032import org.opencms.file.CmsResourceFilter; 033import org.opencms.i18n.CmsLocaleGroupService; 034import org.opencms.main.CmsException; 035import org.opencms.main.CmsLog; 036import org.opencms.main.OpenCms; 037import org.opencms.ui.A_CmsUI; 038import org.opencms.ui.CmsVaadinUtils; 039import org.opencms.ui.I_CmsDialogContext; 040import org.opencms.ui.components.CmsBasicDialog; 041import org.opencms.ui.components.CmsResourceInfo; 042import org.opencms.util.CmsUUID; 043 044import java.util.ArrayList; 045import java.util.Arrays; 046import java.util.Locale; 047 048import org.apache.commons.logging.Log; 049 050import com.vaadin.ui.Button; 051import com.vaadin.ui.Button.ClickEvent; 052import com.vaadin.ui.Button.ClickListener; 053import com.vaadin.v7.ui.HorizontalLayout; 054import com.vaadin.v7.ui.Label; 055 056/** 057 * Dialog to confirm detaching a resource from a locale group.<p> 058 */ 059public class CmsUnlinkDialog extends CmsBasicDialog { 060 061 /** The log instance for this class. */ 062 private static final Log LOG = CmsLog.getLog(CmsUnlinkDialog.class); 063 064 /** The serial version id. */ 065 private static final long serialVersionUID = 1L; 066 067 /** The cancel button. */ 068 protected Button m_cancelButton; 069 070 /** The dialog context. */ 071 protected I_CmsDialogContext m_context; 072 073 /** The locale comparison context. */ 074 protected I_CmsLocaleCompareContext m_localeContext; 075 076 /** The label with the confirmation message. */ 077 protected Label m_messageLabel; 078 079 /** The OK button. */ 080 protected Button m_okButton; 081 082 /** The other resource.*/ 083 protected CmsResource m_otherResource; 084 085 /** The container for the resource boxes. */ 086 protected HorizontalLayout m_resourceBoxContainer; 087 088 /** 089 * Creates a new instance.<p> 090 * 091 * @param context the dialog context 092 * @param otherResource the other resource 093 */ 094 public CmsUnlinkDialog(I_CmsDialogContext context, CmsResource otherResource) { 095 096 super(); 097 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 098 m_context = context; 099 m_otherResource = otherResource; 100 CmsResource leftResource = m_context.getResources().get(0); 101 try { 102 if (leftResource.isFolder()) { 103 CmsResource defaultFile = context.getCms().readDefaultFile( 104 leftResource, 105 CmsResourceFilter.IGNORE_EXPIRATION); 106 if (defaultFile != null) { 107 leftResource = defaultFile; 108 } 109 } 110 } catch (CmsException e) { 111 LOG.error(e.getLocalizedMessage(), e); 112 } 113 CmsResource rightResource = m_otherResource; 114 CmsResourceInfo left = new CmsResourceInfo(leftResource); 115 CmsResourceInfo right = new CmsResourceInfo(rightResource); 116 Locale leftLocale = OpenCms.getLocaleManager().getDefaultLocale(context.getCms(), leftResource); 117 Locale rightLocale = OpenCms.getLocaleManager().getDefaultLocale(context.getCms(), rightResource); 118 119 left.getTopLine().setValue("[" + leftLocale.toString().toUpperCase() + "] " + left.getTopLine().getValue()); 120 right.getTopLine().setValue("[" + rightLocale.toString().toUpperCase() + "] " + right.getTopLine().getValue()); 121 122 m_resourceBoxContainer.addComponent(left); 123 m_resourceBoxContainer.addComponent(right); 124 125 m_okButton.addClickListener(new ClickListener() { 126 127 private static final long serialVersionUID = 1L; 128 129 public void buttonClick(ClickEvent event) { 130 131 onClickOk(); 132 } 133 }); 134 135 m_cancelButton.addClickListener(new ClickListener() { 136 137 private static final long serialVersionUID = 1L; 138 139 public void buttonClick(ClickEvent event) { 140 141 onClickCancel(); 142 } 143 }); 144 145 } 146 147 /** 148 * Called when the Cancel button is clicked.<p> 149 */ 150 protected void onClickCancel() { 151 152 m_context.finish(new ArrayList<CmsUUID>()); 153 154 } 155 156 /** 157 * Called when the OK button is clicked.<p> 158 */ 159 protected void onClickOk() { 160 161 CmsResource res1 = m_context.getResources().get(0); 162 CmsResource res2 = m_otherResource; 163 try { 164 CmsObject cms = A_CmsUI.getCmsObject(); 165 CmsLocaleGroupService groupService = cms.getLocaleGroupService(); 166 groupService.detachLocaleGroup(res1, res2); 167 m_context.finish(Arrays.asList(m_context.getResources().get(0).getStructureId())); 168 } catch (Exception e) { 169 LOG.error(e.getLocalizedMessage()); 170 m_context.error(e); 171 } 172 173 } 174 175}