Added custom widget
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-unionwizard-widget@98759 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a77671d6b3
commit
8c2c526825
|
@ -0,0 +1,4 @@
|
|||
<!-- file: ./IconButton.html -->
|
||||
<div class="{style.iconButton}">
|
||||
<div class="{style.iconButtonImage}"></div>
|
||||
</div>
|
|
@ -0,0 +1,47 @@
|
|||
package org.gcube.portlets.user.td.unionwizardwidget.client.custom;
|
||||
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.HasClickHandlers;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.google.gwt.resources.client.ImageResource;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.sencha.gxt.core.client.dom.XDOM;
|
||||
import com.sencha.gxt.widget.core.client.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class IconButton extends Component implements HasClickHandlers {
|
||||
|
||||
private IconButtonAppearance appearance;
|
||||
|
||||
public IconButton() {
|
||||
this((IconButtonAppearance) GWT.create(IconButtonAppearanceDefault.class));
|
||||
}
|
||||
|
||||
public IconButton(IconButtonAppearance appearance) {
|
||||
this.appearance = appearance;
|
||||
|
||||
SafeHtmlBuilder sb = new SafeHtmlBuilder();
|
||||
this.appearance.render(sb);
|
||||
|
||||
setElement(XDOM.create(sb.toSafeHtml()));
|
||||
sinkEvents(Event.ONCLICK);
|
||||
}
|
||||
|
||||
public HandlerRegistration addClickHandler(ClickHandler handler) {
|
||||
return addDomHandler(handler, ClickEvent.getType());
|
||||
}
|
||||
|
||||
|
||||
public void setIcon(ImageResource icon) {
|
||||
appearance.onUpdateIcon(getElement(), icon);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.gcube.portlets.user.td.unionwizardwidget.client.custom;
|
||||
|
||||
import com.google.gwt.resources.client.ImageResource;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||
import com.sencha.gxt.core.client.dom.XElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public interface IconButtonAppearance {
|
||||
void render(SafeHtmlBuilder sb);
|
||||
void onUpdateIcon(XElement parent, ImageResource icon);
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package org.gcube.portlets.user.td.unionwizardwidget.client.custom;
|
||||
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.resources.client.ClientBundle;
|
||||
import com.google.gwt.resources.client.CssResource;
|
||||
import com.google.gwt.resources.client.ImageResource;
|
||||
import com.google.gwt.safehtml.shared.SafeHtml;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.sencha.gxt.core.client.XTemplates;
|
||||
import com.sencha.gxt.core.client.dom.XElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class IconButtonAppearanceDefault implements IconButtonAppearance {
|
||||
|
||||
public interface Template extends XTemplates {
|
||||
@XTemplate(source = "IconButton.html")
|
||||
SafeHtml template(IconButtonStyle style);
|
||||
}
|
||||
|
||||
public interface IconButtonStyle extends CssResource {
|
||||
@ClassName("iconButton")
|
||||
public String getIconButton();
|
||||
|
||||
@ClassName("iconButtonImage")
|
||||
public String getIconButtonImage();
|
||||
|
||||
@ClassName("iconButtonRef")
|
||||
public String getIconButtonRef();
|
||||
|
||||
}
|
||||
|
||||
private final IconButtonStyle style;
|
||||
private final Template template;
|
||||
|
||||
public interface IconButtonResources extends ClientBundle {
|
||||
public static final IconButtonResources INSTANCE = GWT.create(IconButtonResources.class);
|
||||
|
||||
@Source("IconButtonStyle.css")
|
||||
IconButtonStyle style();
|
||||
}
|
||||
|
||||
public IconButtonAppearanceDefault() {
|
||||
this(IconButtonResources.INSTANCE);
|
||||
}
|
||||
|
||||
public IconButtonAppearanceDefault(IconButtonResources resources) {
|
||||
this.style = resources.style();
|
||||
this.style.ensureInjected();
|
||||
|
||||
this.template = GWT.create(Template.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void onUpdateIcon(XElement parent, ImageResource icon) {
|
||||
XElement element = parent.selectNode("." + style.getIconButtonImage());
|
||||
Image image=new Image(icon);
|
||||
Element img=image.getElement();
|
||||
img.setClassName(style.getIconButtonRef());
|
||||
element.appendChild(img);
|
||||
|
||||
}
|
||||
|
||||
public void render(SafeHtmlBuilder sb) {
|
||||
sb.append(template.template(style));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
@CHARSET "UTF-8";
|
||||
|
||||
.iconButton {
|
||||
border: none;
|
||||
font-size: 12px;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.iconButton .iconButtonImage {
|
||||
vertical-align: center;
|
||||
}
|
||||
|
||||
.iconButtonRef {
|
||||
vertical-align: center;
|
||||
cursor: pointer;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
<!-- file: ./IconButton.html -->
|
||||
<div class="{style.iconButton}">
|
||||
<div class="{style.iconButtonImage}"></div>
|
||||
</div>
|
|
@ -0,0 +1,17 @@
|
|||
@CHARSET "UTF-8";
|
||||
|
||||
.iconButton {
|
||||
border: none;
|
||||
font-size: 12px;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.iconButton .iconButtonImage {
|
||||
vertical-align: center;
|
||||
}
|
||||
|
||||
.iconButtonRef {
|
||||
vertical-align: center;
|
||||
cursor: pointer;
|
||||
}
|
Loading…
Reference in New Issue