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.input; 029 030import org.opencms.gwt.client.CmsCoreProvider; 031import org.opencms.gwt.client.I_CmsHasInit; 032import org.opencms.gwt.client.Messages; 033import org.opencms.gwt.client.ui.CmsPushButton; 034import org.opencms.gwt.client.ui.I_CmsAutoHider; 035import org.opencms.gwt.client.ui.I_CmsButton.Size; 036import org.opencms.gwt.client.ui.input.form.CmsWidgetFactoryRegistry; 037import org.opencms.gwt.client.ui.input.form.I_CmsFormWidgetFactory; 038 039import java.util.Map; 040 041import com.google.common.base.Optional; 042import com.google.gwt.event.dom.client.ClickEvent; 043import com.google.gwt.event.dom.client.ClickHandler; 044import com.google.gwt.event.logical.shared.ValueChangeHandler; 045import com.google.gwt.user.client.ui.Composite; 046import com.google.gwt.user.client.ui.FlowPanel; 047 048/** 049 * The vfs-link widget.<p> 050 * 051 * @since 8.0.0 052 */ 053public class CmsVfsLinkWidget extends Composite implements I_CmsFormWidget, I_CmsHasInit, I_CmsHasGhostValue { 054 055 /** The widget type. */ 056 public static final String WIDGET_TYPE = "vfslink"; 057 058 /** The browse button. */ 059 protected CmsPushButton m_browseButton; 060 061 /** The textbox containing the currently selected path. */ 062 protected CmsTextBox m_textbox; 063 064 /** The vfs-selector popup. */ 065 //protected CmsVfsSelector m_vfsSelector; 066 067 /** The widget panel. */ 068 private FlowPanel m_main; 069 070 /** 071 * Constructor.<p> 072 */ 073 public CmsVfsLinkWidget() { 074 075 m_main = new FlowPanel(); 076 initWidget(m_main); 077 078 m_textbox = new CmsTextBox(); 079 m_main.add(m_textbox); 080 m_browseButton = new CmsPushButton(); 081 m_browseButton.setText(Messages.get().key(Messages.GUI_BROWSE_0)); 082 m_browseButton.setTitle(Messages.get().key(Messages.GUI_BROWSE_0)); 083 m_browseButton.addClickHandler(new ClickHandler() { 084 085 public void onClick(ClickEvent event) { 086 087 openSelector(getSelectorUrl()); 088 } 089 }); 090 091 /*m_textbox.addFocusHandler(new FocusHandler() { 092 093 public void onFocus(FocusEvent arg0) { 094 095 openSelector(getSelectorUrl()); 096 } 097 });*/ 098 m_main.add(m_browseButton); 099 } 100 101 /** 102 * Initializes this class.<p> 103 */ 104 public static void initClass() { 105 106 // registers a factory for creating new instances of this widget 107 CmsWidgetFactoryRegistry.instance().registerFactory(WIDGET_TYPE, new I_CmsFormWidgetFactory() { 108 109 /** 110 * @see org.opencms.gwt.client.ui.input.form.I_CmsFormWidgetFactory#createWidget(java.util.Map, com.google.common.base.Optional) 111 */ 112 public I_CmsFormWidget createWidget(Map<String, String> widgetParams, Optional<String> defaultValue) { 113 114 return new CmsVfsLinkWidget(); 115 } 116 }); 117 } 118 119 /** 120 * Adds a style-name to the browse button.<p> 121 * 122 * @param styleName the style name 123 */ 124 public void addButtonStyle(String styleName) { 125 126 m_browseButton.addStyleName(styleName); 127 } 128 129 /** 130 * Adds a style-name to the input text-box.<p> 131 * 132 * @param styleName the style name 133 */ 134 public void addInputStyleName(String styleName) { 135 136 m_textbox.addStyleName(styleName); 137 } 138 139 /** 140 * Adds a value change handler.<p> 141 * 142 * @param handler the handler to add 143 */ 144 public void addValueChangeHandler(ValueChangeHandler<String> handler) { 145 146 m_textbox.addValueChangeHandler(handler); 147 } 148 149 /** 150 * @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#getApparentValue() 151 */ 152 public String getApparentValue() { 153 154 return getFormValueAsString(); 155 } 156 157 /** 158 * @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#getFieldType() 159 */ 160 public FieldType getFieldType() { 161 162 return FieldType.STRING; 163 } 164 165 /** 166 * @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#getFormValue() 167 */ 168 public Object getFormValue() { 169 170 return m_textbox.getFormValue(); 171 } 172 173 /** 174 * @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#getFormValueAsString() 175 */ 176 public String getFormValueAsString() { 177 178 return m_textbox.getFormValueAsString(); 179 } 180 181 /** 182 * @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#isEnabled() 183 */ 184 public boolean isEnabled() { 185 186 return m_textbox.isEnabled(); 187 } 188 189 /** 190 * Removes a style-name from the browse button.<p> 191 * 192 * @param styleName the style name 193 */ 194 public void removeButtonStyle(String styleName) { 195 196 m_browseButton.removeStyleName(styleName); 197 } 198 199 /** 200 * Removes a style-name from the input text-box.<p> 201 * 202 * @param styleName the style name 203 */ 204 public void removeInputStyle(String styleName) { 205 206 m_textbox.removeStyleName(styleName); 207 } 208 209 /** 210 * @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#reset() 211 */ 212 public void reset() { 213 214 m_textbox.reset(); 215 } 216 217 /** 218 * @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#setAutoHideParent(org.opencms.gwt.client.ui.I_CmsAutoHider) 219 */ 220 public void setAutoHideParent(I_CmsAutoHider autoHideParent) { 221 222 // do nothing 223 } 224 225 /** 226 * Set the browse button size.<p> 227 * 228 * @param size the button size 229 */ 230 public void setButtonSize(Size size) { 231 232 m_browseButton.setSize(size); 233 } 234 235 /** 236 * @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#setEnabled(boolean) 237 */ 238 public void setEnabled(boolean enabled) { 239 240 m_textbox.setEnabled(enabled); 241 } 242 243 /** 244 * @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#setErrorMessage(java.lang.String) 245 */ 246 public void setErrorMessage(String errorMessage) { 247 248 // do nothing 249 } 250 251 /** 252 * @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#setFormValueAsString(java.lang.String) 253 */ 254 public void setFormValueAsString(String value) { 255 256 m_textbox.setFormValueAsString(value); 257 m_textbox.fireValueChangedEvent(); 258 259 } 260 261 /** 262 * @see org.opencms.gwt.client.ui.input.I_CmsHasGhostValue#setGhostMode(boolean) 263 */ 264 public void setGhostMode(boolean ghostMode) { 265 266 m_textbox.setGhostMode(ghostMode); 267 } 268 269 /** 270 * @see org.opencms.gwt.client.ui.input.I_CmsHasGhostValue#setGhostValue(java.lang.String, boolean) 271 */ 272 public void setGhostValue(String value, boolean isGhostMode) { 273 274 m_textbox.setGhostValue(value, isGhostMode); 275 } 276 277 /** 278 * Returns the URL to the link selector popup.<p> 279 * 280 * @return the URL to the link selector popup 281 */ 282 protected String getSelectorUrl() { 283 284 StringBuffer result = new StringBuffer(128); 285 result.append(CmsCoreProvider.get().link("/system/workplace/views/explorer/tree_fs.jsp")); 286 result.append("?type=vfswidget&includefiles=true&showsiteselector=true&projectaware=false&treesite="); 287 result.append(CmsCoreProvider.get().getSiteRoot()); 288 return result.toString(); 289 } 290 291 /** 292 * Opens the vfs-selector.<p> 293 * 294 * @param selectorUrl the URL to the link selector popup 295 */ 296 protected native void openSelector(String selectorUrl)/*-{ 297 var newwin = $wnd 298 .open( 299 selectorUrl, 300 "file_selector", 301 "toolbar=no,location=no,directories=no,status=yes,menubar=0,scrollbars=yes,resizable=yes,top=150,left=660,width=300,height=450"); 302 if (newwin != null) { 303 if (newwin.opener == null) { 304 newwin.opener = $wnd.self; 305 } 306 } else { 307 @org.opencms.gwt.client.util.CmsDomUtil::showPopupBlockerMessage()(); 308 return; 309 } 310 newwin.focus(); 311 var self = this; 312 $wnd.setFormValue = function(fileName) { 313 self.@org.opencms.gwt.client.ui.input.CmsVfsLinkWidget::setFormValueAsString(Ljava/lang/String;)(fileName); 314 } 315 }-*/; 316 317}