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.actions; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.CmsResource; 032import org.opencms.i18n.CmsLocaleGroup; 033import org.opencms.i18n.CmsLocaleGroupService; 034import org.opencms.main.CmsLog; 035import org.opencms.main.OpenCms; 036import org.opencms.ui.CmsVaadinUtils; 037import org.opencms.ui.I_CmsDialogContext; 038import org.opencms.ui.Messages; 039import org.opencms.ui.contextmenu.CmsMenuItemVisibilityMode; 040import org.opencms.ui.contextmenu.CmsMenuItemVisibilitySingleOnly; 041import org.opencms.ui.contextmenu.CmsStandardVisibilityCheck; 042import org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility; 043import org.opencms.ui.sitemap.CmsLocaleLinkTargetSelectionDialog; 044import org.opencms.ui.sitemap.I_CmsLocaleCompareContext; 045 046import java.util.List; 047import java.util.Locale; 048 049import org.apache.commons.logging.Log; 050 051/** 052 * Workplace action for the 'Link locale variant' dialog.<p> 053 */ 054public class CmsLinkLocaleVariantAction extends A_CmsWorkplaceAction { 055 056 /** The action id. */ 057 public static final String ACTION_ID = "linklocale"; 058 059 /** The action visibility. */ 060 public static final I_CmsHasMenuItemVisibility VISIBILITY = new CmsMenuItemVisibilitySingleOnly( 061 CmsStandardVisibilityCheck.DEFAULT_DEFAULTFILE); 062 063 /** Logger instance for this class. */ 064 private static final Log LOG = CmsLog.getLog(CmsLinkLocaleVariantAction.class); 065 066 /** 067 * @see org.opencms.ui.actions.I_CmsWorkplaceAction#executeAction(org.opencms.ui.I_CmsDialogContext) 068 */ 069 public void executeAction(final I_CmsDialogContext context) { 070 071 try { 072 final CmsResource resource = context.getResources().get(0); 073 final CmsLocaleGroupService groupService = context.getCms().getLocaleGroupService(); 074 final CmsResource localizationRoot = groupService.findLocalizationRoot(resource); 075 final CmsLocaleGroup localeGroup = groupService.readLocaleGroup(localizationRoot); 076 CmsLocaleLinkTargetSelectionDialog dlg = new CmsLocaleLinkTargetSelectionDialog( 077 context, 078 new I_CmsLocaleCompareContext() { 079 080 public Locale getComparisonLocale() { 081 082 return OpenCms.getLocaleManager().getDefaultLocale(context.getCms(), getRoot()); 083 } 084 085 public CmsLocaleGroup getLocaleGroup() { 086 087 return localeGroup; 088 } 089 090 public CmsResource getRoot() { 091 092 return localizationRoot; 093 } 094 095 public Locale getRootLocale() { 096 097 return OpenCms.getLocaleManager().getDefaultLocale(context.getCms(), getRoot()); 098 } 099 100 public void refreshAll() { 101 102 // ignore 103 } 104 }); 105 String title = CmsVaadinUtils.getMessageText(Messages.GUI_LOCALECOMPARE_LINK_LOCALE_VARIANT_0); 106 context.start(title, dlg); 107 } catch (Exception e) { 108 LOG.error(e.getLocalizedMessage(), e); 109 context.error(e); 110 } 111 } 112 113 /** 114 * @see org.opencms.ui.actions.I_CmsWorkplaceAction#getId() 115 */ 116 public String getId() { 117 118 return ACTION_ID; 119 } 120 121 /** 122 * @see org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility#getVisibility(org.opencms.file.CmsObject, java.util.List) 123 */ 124 public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, List<CmsResource> resources) { 125 126 if (resources.size() > 0) { 127 CmsResource resource = resources.get(0); 128 if (cms.getLocaleGroupService().getMainLocale(resource.getRootPath()) == null) { 129 return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; 130 } 131 } 132 return VISIBILITY.getVisibility(cms, resources); 133 } 134 135 /** 136 * @see org.opencms.ui.actions.A_CmsWorkplaceAction#getTitleKey() 137 */ 138 @Override 139 protected String getTitleKey() { 140 141 return Messages.GUI_LOCALECOMPARE_LINK_LOCALE_VARIANT_0; 142 } 143 144}