/*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.gwt.client.ui.input;
import org.opencms.gwt.client.CmsCoreProvider;
import org.opencms.gwt.client.I_CmsHasInit;
import org.opencms.gwt.client.ui.CmsPushButton;
import org.opencms.gwt.client.ui.I_CmsAutoHider;
import org.opencms.gwt.client.ui.css.I_CmsImageBundle;
import org.opencms.gwt.client.ui.input.form.CmsWidgetFactoryRegistry;
import org.opencms.gwt.client.ui.input.form.I_CmsFormWidgetFactory;
import java.util.Map;
import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.Cursor;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Composite;
/**
* A widget for selecting a resource from an ADE gallery dialog.<p>
*
* @since 8.0.0
*/
public class CmsGalleryField extends Composite implements I_CmsFormWidget, I_CmsHasInit, I_CmsHasGhostValue {
/** The widget type. */
public static final String WIDGET_TYPE = "gallery";
/** The textbox containing the currently selected path. */
protected CmsTextBox m_textbox;
/** The HTML id of the field. */
private String m_id;
/**
* Constructs a new gallery widget.<p>
*/
public CmsGalleryField() {
CmsTextBox box = new CmsTextBox();
m_id = box.getId();
m_textbox = box;
box.addClickHandler(new ClickHandler() {
/**
* @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent)
*/
public void onClick(ClickEvent event) {
openGalleryDialog();
}
});
initWidget(box);
}
/**
* Initializes this class.<p>
*/
public static void initClass() {
// registers a factory for creating new instances of this widget
CmsWidgetFactoryRegistry.instance().registerFactory(WIDGET_TYPE, new I_CmsFormWidgetFactory() {
/**
* @see org.opencms.gwt.client.ui.input.form.I_CmsFormWidgetFactory#createWidget(java.util.Map)
*/
public I_CmsFormWidget createWidget(Map<String, String> widgetParams) {
return new CmsGalleryField();
}
});
}
/**
* @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#getApparentValue()
*/
public String getApparentValue() {
return getFormValueAsString();
}
/**
* @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#getFieldType()
*/
public FieldType getFieldType() {
return FieldType.STRING;
}
/**
* @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#getFormValue()
*/
public Object getFormValue() {
return m_textbox.getFormValue();
}
/**
* @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#getFormValueAsString()
*/
public String getFormValueAsString() {
return m_textbox.getFormValueAsString();
}
/**
* @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#isEnabled()
*/
public boolean isEnabled() {
return m_textbox.isEnabled();
}
/**
* @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#reset()
*/
public void reset() {
m_textbox.reset();
}
/**
* @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#setAutoHideParent(org.opencms.gwt.client.ui.I_CmsAutoHider)
*/
public void setAutoHideParent(I_CmsAutoHider autoHideParent) {
// do nothing
}
/**
* @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#setEnabled(boolean)
*/
public void setEnabled(boolean enabled) {
m_textbox.setEnabled(enabled);
}
/**
* @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#setErrorMessage(java.lang.String)
*/
public void setErrorMessage(String errorMessage) {
// do nothing
}
/**
* @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#setFormValueAsString(java.lang.String)
*/
public void setFormValueAsString(String value) {
m_textbox.setFormValueAsString(value);
}
/**
* @see org.opencms.gwt.client.ui.input.I_CmsHasGhostValue#setGhostMode(boolean)
*/
public void setGhostMode(boolean ghostMode) {
m_textbox.setGhostMode(ghostMode);
}
/**
* @see org.opencms.gwt.client.ui.input.I_CmsHasGhostValue#setGhostValue(java.lang.String, boolean)
*/
public void setGhostValue(String value, boolean isGhostMode) {
m_textbox.setGhostValue(value, isGhostMode);
}
/**
* Creates the URL for the gallery dialog IFrame.<p>
*
* @return the URL for the gallery dialog IFrame
*/
protected String buildGalleryUrl() {
String basePath = "/system/modules/org.opencms.ade.galleries/gallery.jsp";
return CmsCoreProvider.get().link(basePath + "?dialogmode=widget&fieldid=" + m_id);
}
/**
* Internal method which opens the gallery dialog.<p>
*/
protected void openGalleryDialog() {
String title = org.opencms.gwt.client.Messages.get().key(
org.opencms.gwt.client.Messages.GUI_GALLERY_SELECT_DIALOG_TITLE_0);
final CmsFramePopup popup = new CmsFramePopup(title, buildGalleryUrl());
popup.setCloseHandler(new Runnable() {
public void run() {
m_textbox.setGhostMode(false);
}
});
popup.setId(m_id);
popup.getFrame().setSize("700px", "490px");
popup.center();
CmsPushButton button = new CmsPushButton(I_CmsImageBundle.INSTANCE.style().closeIcon());
Style style = button.getElement().getStyle();
style.setRight(4, Unit.PX);
style.setTop(0, Unit.PX);
style.setPosition(Position.ABSOLUTE);
style.setCursor(Cursor.POINTER);
button.addClickHandler(new ClickHandler() {
/**
* @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent)
*/
public void onClick(ClickEvent event) {
popup.hide();
}
});
popup.insertFront(button);
}
}