Index: platform/web/trunk/wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/ui/widget/GenericTray.java =================================================================== --- platform/web/trunk/wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/ui/widget/GenericTray.java (revision 0) +++ platform/web/trunk/wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/ui/widget/GenericTray.java (revision 0) @@ -0,0 +1,162 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This 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 software 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. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package com.xpn.xwiki.wysiwyg.client.ui.widget; + +import com.google.gwt.user.client.ui.ClickListener; +import com.google.gwt.user.client.ui.ClickListenerCollection; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HasHorizontalAlignment; +import com.google.gwt.user.client.ui.HasVerticalAlignment; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.PushButton; +import com.google.gwt.user.client.ui.SourcesClickEvents; +import com.google.gwt.user.client.ui.UIObject; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; +import com.xpn.xwiki.wysiwyg.client.ui.Images; + +public class GenericTray extends Composite implements ClickListener, SourcesClickEvents +{ + private final ClickListenerCollection clickListeners = new ClickListenerCollection(); + + private final VerticalPanel mainPanel; + + private final HorizontalPanel topPanel; + + private final HTML title; + + private Widget buttons; + + private final PushButton closeButton; + + private Widget content; + + public GenericTray() + { + title = new HTML(); + title.addStyleName("title"); + + closeButton = new PushButton(Images.INSTANCE.close().createImage()); + closeButton.setTitle("Close"); + closeButton.setStyleName("closeButton"); + + topPanel = new HorizontalPanel(); + topPanel.add(title); + topPanel.add(closeButton); + topPanel.setCellVerticalAlignment(title, HasVerticalAlignment.ALIGN_MIDDLE); + topPanel.setCellHorizontalAlignment(title, HasHorizontalAlignment.ALIGN_CENTER); + topPanel.setCellHorizontalAlignment(closeButton, HasHorizontalAlignment.ALIGN_RIGHT); + topPanel.addStyleName("topPanel"); + + mainPanel = new VerticalPanel(); + mainPanel.add(topPanel); + + initWidget(mainPanel); + addStyleName("genericTray"); + } + + /** + * {@inheritDoc} + * + * @see UIObject#setTitle(String) + */ + public void setTitle(String title) + { + this.title.setText(title); + } + + /** + * {@inheritDoc} + * + * @see UIObject#getTitle() + */ + public String getTitle() + { + return title.getText(); + } + + public void setButtons(Widget widget) + { + if (buttons != null) { + topPanel.remove(buttons); + } + if (widget != null) { + topPanel.insert(widget, 1); + } + buttons = widget; + topPanel.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_LEFT); + } + + public void setContent(Widget widget) + { + if (content != null) { + mainPanel.remove(content); + } + if (widget != null) { + mainPanel.add(widget); + } + content = widget; + mainPanel.setCellHorizontalAlignment(content, HasHorizontalAlignment.ALIGN_CENTER); + } + + public void show() + { + // TODO implement this method + } + + public void close() + { + // TODO implement this method + } + + /** + * {@inheritDoc} + * + * @see SourcesClickEvents#addClickListener(com.google.gwt.user.client.ui.ClickListener) + */ + public void addClickListener(ClickListener listener) + { + clickListeners.add(listener); + } + + /** + * {@inheritDoc} + * + * @see SourcesClickEvents#removeClickListener(ClickListener) + */ + public void removeClickListener(ClickListener listener) + { + clickListeners.remove(listener); + } + + /** + * {@inheritDoc} + * + * @see ClickListener#onClick(Widget) + */ + public void onClick(Widget sender) + { + if (sender == closeButton) { + clickListeners.fireClick(this); + close(); + } + } +}