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.gwt.client.ui; 029 030import org.opencms.ade.contenteditor.shared.CmsEditorConstants; 031import org.opencms.gwt.client.CmsCoreProvider; 032import org.opencms.gwt.client.Messages; 033import org.opencms.gwt.client.rpc.CmsRpcAction; 034import org.opencms.gwt.client.ui.I_CmsButton.ButtonColor; 035import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle; 036import org.opencms.gwt.shared.CmsListInfoBean; 037import org.opencms.util.CmsUUID; 038 039import com.google.gwt.event.dom.client.ClickEvent; 040import com.google.gwt.event.dom.client.ClickHandler; 041import com.google.gwt.user.client.Command; 042import com.google.gwt.user.client.rpc.AsyncCallback; 043 044/** 045 * A dialog used to select the create mode for new contents created from a collector list.<p> 046 */ 047public class CmsCreateModeSelectionDialog extends CmsPopup { 048 049 /** The callback which is called with the create mode selected by the user. */ 050 AsyncCallback<String> m_callback; 051 052 /** 053 * Creates a new dialog instance.<p> 054 * 055 * @param info the resource information for the selected collector list entry 056 * @param createModeCallback the callback to call with the result 057 */ 058 public CmsCreateModeSelectionDialog(CmsListInfoBean info, final AsyncCallback<String> createModeCallback) { 059 060 super(""); 061 setCaption(messageCaption()); 062 m_callback = createModeCallback; 063 setModal(true); 064 setGlassEnabled(true); 065 CmsCreateModeSelectionView main = new CmsCreateModeSelectionView(); 066 main.getLabel().setText(messageAskMode()); 067 068 CmsListItemWidget item = new CmsListItemWidget(info); 069 main.getInfoBox().add(item); 070 setMainContent(main); 071 addButtons(); 072 Command closeCommand = new Command() { 073 074 public void execute() { 075 076 createModeCallback.onFailure(null); 077 } 078 }; 079 addDialogClose(closeCommand); 080 } 081 082 /** 083 * Shows the dialog for the given collector list entry.<p> 084 * 085 * @param referenceId the structure id of the collector list entry 086 * @param createModeCallback the callback which should be called with the selected create mode 087 */ 088 public static void showDialog(final CmsUUID referenceId, final AsyncCallback<String> createModeCallback) { 089 090 CmsRpcAction<CmsListInfoBean> action = new CmsRpcAction<CmsListInfoBean>() { 091 092 @Override 093 public void execute() { 094 095 start(0, true); 096 CmsCoreProvider.getVfsService().getPageInfo(referenceId, this); 097 098 } 099 100 @Override 101 protected void onResponse(CmsListInfoBean result) { 102 103 stop(false); 104 Boolean isFolder = result.getIsFolder(); 105 if ((isFolder != null) && isFolder.booleanValue()) { 106 createModeCallback.onSuccess(null); 107 } else { 108 (new CmsCreateModeSelectionDialog(result, createModeCallback)).center(); 109 } 110 111 } 112 }; 113 action.execute(); 114 115 } 116 117 /** 118 * Message accessor.<p> 119 * 120 * @return the message 121 */ 122 public String messageAskMode() { 123 124 return Messages.get().key(Messages.GUI_CREATE_MODE_ASK_0); 125 } 126 127 /** 128 * Message accessor.<p> 129 * 130 * @return the message 131 */ 132 public String messageCaption() { 133 134 return Messages.get().key(Messages.GUI_CREATE_MODE_CAPTION_0); 135 } 136 137 /** 138 * Message accessor.<p> 139 * 140 * @return the message 141 */ 142 public String messageCopy() { 143 144 return Messages.get().key(Messages.GUI_CREATE_MODE_BUTTON_COPY_0); 145 } 146 147 /** 148 * Message accessor.<p> 149 * 150 * @return the message 151 */ 152 public String messageNew() { 153 154 return Messages.get().key(Messages.GUI_CREATE_MODE_BUTTON_NEW_0); 155 } 156 157 /** 158 * Adds the dialog buttons.<p> 159 */ 160 protected void addButtons() { 161 162 addButton(createButton(messageNew(), ButtonColor.BLUE, null)); 163 addButton(createButton(messageCopy(), ButtonColor.GREEN, CmsEditorConstants.MODE_COPY)); 164 165 } 166 167 /** 168 * Creates a button used to select a create mode.<p> 169 * 170 * @param text the button text 171 * @param color the button color 172 * @param result the create mode selected by the button 173 * 174 * @return the newly created button 175 */ 176 protected CmsPushButton createButton(String text, ButtonColor color, final String result) { 177 178 CmsPushButton button = new CmsPushButton(); 179 button = new CmsPushButton(); 180 button.setText(text); 181 button.setUseMinWidth(true); 182 button.setButtonStyle(ButtonStyle.TEXT, color); 183 button.addClickHandler(new ClickHandler() { 184 185 public void onClick(ClickEvent e) { 186 187 CmsCreateModeSelectionDialog.this.hide(); 188 m_callback.onSuccess(result); 189 } 190 }); 191 return button; 192 193 } 194 195}