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.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 super(); 096 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 097 m_context = context; 098 m_otherResource = otherResource; 099 CmsResource leftResource = m_context.getResources().get(0); 100 try { 101 if (leftResource.isFolder()) { 102 CmsResource defaultFile = context.getCms().readDefaultFile( 103 leftResource, 104 CmsResourceFilter.IGNORE_EXPIRATION); 105 if (defaultFile != null) { 106 leftResource = defaultFile; 107 } 108 } 109 } catch (CmsException e) { 110 LOG.error(e.getLocalizedMessage(), e); 111 } 112 CmsResource rightResource = m_otherResource; 113 CmsResourceInfo left = new CmsResourceInfo(leftResource); 114 CmsResourceInfo right = new CmsResourceInfo(rightResource); 115 Locale leftLocale = OpenCms.getLocaleManager().getDefaultLocale(context.getCms(), leftResource); 116 Locale rightLocale = OpenCms.getLocaleManager().getDefaultLocale(context.getCms(), rightResource); 117 118 left.getTopLine().setValue("[" + leftLocale.toString().toUpperCase() + "] " + left.getTopLine().getValue()); 119 right.getTopLine().setValue("[" + rightLocale.toString().toUpperCase() + "] " + right.getTopLine().getValue()); 120 121 m_resourceBoxContainer.addComponent(left); 122 m_resourceBoxContainer.addComponent(right); 123 124 m_okButton.addClickListener(new ClickListener() { 125 126 private static final long serialVersionUID = 1L; 127 128 public void buttonClick(ClickEvent event) { 129 130 onClickOk(); 131 } 132 }); 133 134 m_cancelButton.addClickListener(new ClickListener() { 135 136 private static final long serialVersionUID = 1L; 137 138 public void buttonClick(ClickEvent event) { 139 140 onClickCancel(); 141 } 142 }); 143 144 } 145 146 /** 147 * Called when the Cancel button is clicked.<p> 148 */ 149 protected void onClickCancel() { 150 151 m_context.finish(new ArrayList<CmsUUID>()); 152 153 } 154 155 /** 156 * Called when the OK button is clicked.<p> 157 */ 158 protected void onClickOk() { 159 160 CmsResource res1 = m_context.getResources().get(0); 161 CmsResource res2 = m_otherResource; 162 try { 163 CmsObject cms = A_CmsUI.getCmsObject(); 164 CmsLocaleGroupService groupService = cms.getLocaleGroupService(); 165 groupService.detachLocaleGroup(res1, res2); 166 m_context.finish(Arrays.asList(m_context.getResources().get(0).getStructureId())); 167 } catch (Exception e) { 168 LOG.error(e.getLocalizedMessage()); 169 m_context.error(e); 170 } 171 172 } 173 174}