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.gwt.shared.CmsCoreData.AdeContext; 033import org.opencms.ui.I_CmsDialogContext; 034import org.opencms.ui.I_CmsDialogContextWithAdeContext; 035import org.opencms.ui.I_CmsUpdateListener; 036import org.opencms.ui.components.extensions.CmsGwtDialogExtension; 037import org.opencms.ui.contextmenu.CmsMenuItemVisibilityMode; 038import org.opencms.ui.contextmenu.CmsStandardVisibilityCheck; 039import org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility; 040import org.opencms.util.CmsUUID; 041import org.opencms.workplace.explorer.Messages; 042 043import java.util.HashMap; 044import java.util.List; 045import java.util.Map; 046 047import com.google.common.collect.Lists; 048import com.vaadin.ui.UI; 049 050/** 051 * The direct publish dialog action.<p> 052 */ 053public class CmsDirectPublishDialogAction extends A_CmsWorkplaceAction implements I_CmsADEAction { 054 055 /** The action id. */ 056 public static final String ACTION_ID = "directpublish"; 057 058 /** The action visibility. */ 059 public static final I_CmsHasMenuItemVisibility VISIBILITY = CmsStandardVisibilityCheck.PUBLISH; 060 061 /** 062 * @see org.opencms.ui.actions.I_CmsWorkplaceAction#executeAction(org.opencms.ui.I_CmsDialogContext) 063 */ 064 public void executeAction(final I_CmsDialogContext context) { 065 066 if (!hasBlockingLocks(context)) { 067 CmsGwtDialogExtension extension = new CmsGwtDialogExtension( 068 UI.getCurrent(), 069 new I_CmsUpdateListener<String>() { 070 071 public void onUpdate(List<String> updatedItems) { 072 073 List<CmsUUID> updatedIds = Lists.newArrayList(); 074 for (String item : updatedItems) { 075 updatedIds.add(new CmsUUID(item)); 076 } 077 context.finish(updatedIds); 078 079 } 080 }); 081 extension.openPublishDialog(context.getResources()); 082 } 083 } 084 085 /** 086 * @see org.opencms.ui.actions.I_CmsADEAction#getCommandClassName() 087 */ 088 @Override 089 public String getCommandClassName() { 090 091 return "org.opencms.gwt.client.ui.contextmenu.CmsEmbeddedAction"; 092 } 093 094 /** 095 * @see org.opencms.ui.actions.I_CmsWorkplaceAction#getId() 096 */ 097 public String getId() { 098 099 return ACTION_ID; 100 } 101 102 /** 103 * @see org.opencms.ui.actions.I_CmsADEAction#getJspPath() 104 */ 105 @Override 106 public String getJspPath() { 107 108 return null; 109 } 110 111 /** 112 * @see org.opencms.ui.actions.I_CmsADEAction#getParams() 113 */ 114 @Override 115 public Map<String, String> getParams() { 116 117 Map<String, String> result = new HashMap<String, String>(); 118 result.put("dialogId", CmsDirectPublishDialogAction.class.getName()); 119 return result; 120 } 121 122 /** 123 * @see org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility#getVisibility(org.opencms.file.CmsObject, java.util.List) 124 */ 125 public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, List<CmsResource> resources) { 126 127 return VISIBILITY.getVisibility(cms, resources); 128 } 129 130 /** 131 * @see org.opencms.ui.actions.A_CmsWorkplaceAction#getVisibility(org.opencms.ui.I_CmsDialogContext) 132 */ 133 @Override 134 public CmsMenuItemVisibilityMode getVisibility(I_CmsDialogContext context) { 135 136 if (context instanceof I_CmsDialogContextWithAdeContext) { 137 AdeContext adeContext = ((I_CmsDialogContextWithAdeContext)context).getAdeContext(); 138 if ((adeContext == AdeContext.publish) || (adeContext == AdeContext.sitemapeditor)) { 139 return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; 140 } 141 } 142 return super.getVisibility(context); 143 } 144 145 /** 146 * @see org.opencms.ui.actions.I_CmsADEAction#isAdeSupported() 147 */ 148 @Override 149 public boolean isAdeSupported() { 150 151 return true; 152 } 153 154 /** 155 * @see org.opencms.ui.actions.A_CmsWorkplaceAction#getTitleKey() 156 */ 157 @Override 158 protected String getTitleKey() { 159 160 return Messages.GUI_EXPLORER_CONTEXT_PUBLISH_0; 161 } 162}