integrated switchbutton widget

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/notifications@82954 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-10-10 15:25:22 +00:00
parent 7cedfb2df2
commit 101ea953b1
11 changed files with 19 additions and 211 deletions

View File

@ -5,6 +5,9 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="switch-button-widget-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/switch-button-widget/switch-button-widget">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="notifications"/>
</wb-module>

10
pom.xml
View File

@ -69,6 +69,11 @@
<artifactId>gcube-widgets</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>switch-button-widget</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
@ -79,6 +84,11 @@
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>

View File

@ -1,137 +0,0 @@
package org.gcube.portlets.user.notifications.client.view.switchbutton;
import static com.google.gwt.query.client.GQuery.$;
import org.gcube.portlets.user.gcubewidgets.client.elements.Div;
import org.gcube.portlets.user.gcubewidgets.client.elements.Span;
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.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.query.client.Function;
import com.google.gwt.query.client.css.CSS;
import com.google.gwt.query.client.css.Length;
import com.google.gwt.query.client.css.RGBColor;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HasName;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.Widget;
public class SwitchButton extends Composite implements HasName, HasValue<Boolean>{
private static SwitchButtonUiBinder uiBinder = GWT
.create(SwitchButtonUiBinder.class);
interface SwitchButtonUiBinder extends UiBinder<Widget, SwitchButton> {
}
@UiField FocusPanel switchContainer;
@UiField Div switcherButton;
@UiField Span labelOff;
@UiField Span labelOn;
private String name;
private Boolean value;
private Boolean valueChangeHandlerInitialized = Boolean.FALSE;
public SwitchButton() {
name = DOM.createUniqueId();
initWidget(uiBinder.createAndBindUi(this));
value = false;
$(switcherButton).css(CSS.LEFT.with(Length.px(-1)));
ensureDomEventHandlers();
}
public SwitchButton(boolean initialValue) {
this();
setValue(initialValue);
}
@Override
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<Boolean> handler) {
// Is this the first value change handler? If so, time to add handlers
if (!valueChangeHandlerInitialized) {
valueChangeHandlerInitialized = true;
}
return addHandler(handler, ValueChangeEvent.getType());
}
@Override
public Boolean getValue() {
return value;
}
/**
* Checks or unchecks the switch button box, firing {@link ValueChangeEvent} if
* appropriate.
* <p>
* Note that this <em>does not</em> set the value property of the checkbox
* input element wrapped by this widget. For access to that property, see
* {@link #setFormValue(String)}
*
* @param value true to set on, false to set off; null value implies false
*/
@Override
public void setValue(Boolean value) {
if (value == null) {
value = Boolean.FALSE;
}
Boolean oldValue = getValue();
if (value.equals(oldValue)) {
return;
}
this.value = value;
if (!value) {
$(switcherButton).animate("left: -1", 250);
labelOff.setStyleName("switch-button-label on");
labelOn.setStyleName("switch-button-label off");
} else {
$(switcherButton).animate("left: 12", 250);
labelOff.setStyleName("switch-button-label off");
labelOn.setStyleName("switch-button-label on");
}
}
/**
* Checks or unchecks the switch button box, firing {@link ValueChangeEvent} if
* appropriate.
* <p>
*
* @param value true to set on, false to set off; null value implies false
* @param fireEvents If true, and value has changed, fire a
* {@link ValueChangeEvent}
*/
@Override
public void setValue(Boolean value, boolean fireEvents) {
setValue(value);
if (fireEvents) {
ValueChangeEvent.fire(this, value);
}
}
protected void ensureDomEventHandlers() {
switchContainer.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
setValue(!value);
ValueChangeEvent.fire(SwitchButton.this, getValue());
}
});
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
}

View File

@ -1,13 +0,0 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:e="urn:import:org.gcube.portlets.user.gcubewidgets.client.elements"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel>
<e:Span styleName="switch-button-label on" ui:field="labelOff">OFF</e:Span>
<g:FocusPanel ui:field="switchContainer" styleName="switch-button-background">
<e:Div ui:field="switcherButton" styleName="switch-button-button"></e:Div>
</g:FocusPanel>
<e:Span styleName="switch-button-label off" ui:field="labelOn">ON</e:Span>
<div style="clear: left;"></div>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -8,8 +8,8 @@ import java.util.HashMap;
import org.gcube.portal.databook.shared.NotificationChannelType;
import org.gcube.portal.databook.shared.NotificationType;
import org.gcube.portlets.user.gcubewidgets.client.elements.Span;
import org.gcube.portlets.user.notifications.client.view.switchbutton.SwitchButton;
import org.gcube.portlets.user.notifications.shared.NotificationPreference;
import org.gcube.portlets.widgets.switchbutton.client.SwitchButton;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.ValueChangeEvent;

View File

@ -1,6 +1,6 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:w="urn:import:org.gcube.portlets.user.notifications.client.view.switchbutton"
xmlns:w="urn:import:org.gcube.portlets.widgets.switchbutton.client"
xmlns:e="urn:import:org.gcube.portlets.user.gcubewidgets.client.elements"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel>

View File

@ -7,8 +7,8 @@ import java.util.ArrayList;
import org.gcube.portal.databook.shared.NotificationChannelType;
import org.gcube.portal.databook.shared.NotificationType;
import org.gcube.portlets.user.gcubewidgets.client.elements.Span;
import org.gcube.portlets.user.notifications.client.view.switchbutton.SwitchButton;
import org.gcube.portlets.user.notifications.shared.NotificationPreference;
import org.gcube.portlets.widgets.switchbutton.client.SwitchButton;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.ValueChangeEvent;

View File

@ -1,7 +1,7 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:e="urn:import:org.gcube.portlets.user.gcubewidgets.client.elements"
xmlns:w="urn:import:org.gcube.portlets.user.notifications.client.view.switchbutton"
xmlns:w="urn:import:org.gcube.portlets.widgets.switchbutton.client"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel>
<table class="single-notification-table">

View File

@ -9,10 +9,10 @@
<!-- To Comment out -->
<!-- <set-property name="user.agent" value="gecko1_8" /> -->
<inherits name='com.google.gwt.query.Query' />
<!-- Other module inherits -->
<!-- inherits gCube Widgets Library -->
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />
<inherits name='org.gcube.portlets.widgets.switchbutton.SwitchButton' />
<inherits name='org.gcube.portal.databook.GCubeSocialNetworking' />
<!-- Specify the app entry point class. -->
<entry-point

View File

@ -1,5 +1,4 @@
@import url(switchbutton.css);
table {
border-collapse: separate !important;
border-spacing: 0;

View File

@ -1,54 +0,0 @@
/* Switch Button */
.switch-button-label {
float: left;
font-size: 10pt;
cursor: pointer;
}}
.switch-button-label.off {
color: #adadad;
}
.switch-button-label.on {
color: #0088CC;
}
.switch-button-background {
float: left;
position: relative;
background: #ccc;
border: 1px solid #aaa;
margin: 1px 10px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
cursor: pointer;
width: 25px;
height: 11px;
outline-style: none; /* this avoid the tabindex property to sorround this element with a (maybe dotted) rectangle*/
}
.switch-button-button {
position: absolute;
width: 12px;
height: 11px;
left: 12px;
top : -1px;
background: #FAFAFA;
border: 1px solid #aaa;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}