Skip to content

Commit

Permalink
add common components
Browse files Browse the repository at this point in the history
  • Loading branch information
mkristian committed Mar 12, 2013
1 parent ba508a1 commit 8abe1df
Show file tree
Hide file tree
Showing 26 changed files with 1,079 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rails-gwt/src/main/java/de/mkristian/ixtlan/IxtlanGWT.gwt.xml
@@ -0,0 +1,7 @@
<module>

<inherits name='de.mkristian.gwt.RailsGWT' />

<source path="gwt"/>

</module>
@@ -0,0 +1,41 @@
package de.mkristian.ixtlan.gwt.audits;

import static de.mkristian.gwt.rails.places.RestfulActionEnum.SHOW;

import java.util.List;

import com.google.gwt.place.shared.PlaceController;

import de.mkristian.gwt.rails.views.ReadOnlyListViewImpl;

public abstract class AbstractAuditListViewImpl
extends ReadOnlyListViewImpl<Audit> {

public AbstractAuditListViewImpl(String title, PlaceController places) {
super(title, places);
}

public void reset(List<Audit> models) {
list.removeAllRows();
list.setText(0, 0, "Id");
list.setText(0, 1, "Login");
list.setText(0, 2, "Message");
list.getRowFormatter().addStyleName(0, "gwt-rails-model-list-header");
if (models != null) {
int row = 1;
for(Audit model: models){
setRow(row, model);
row++;
}
}
}

private void setRow(int row, Audit model) {
list.setText(row, 0, model.getId() + "");
list.setText(row, 1, model.getLogin() + "");
list.setText(row, 2, model.getMessage() + "");

list.setWidget(row, 3, newButton(SHOW, model));
}

}
73 changes: 73 additions & 0 deletions rails-gwt/src/main/java/de/mkristian/ixtlan/gwt/audits/Audit.java
@@ -0,0 +1,73 @@
package de.mkristian.ixtlan.gwt.audits;


import java.util.Date;

import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;
import org.fusesource.restygwt.client.Json;
import org.fusesource.restygwt.client.Json.Style;

import de.mkristian.gwt.rails.models.HasToDisplay;
import de.mkristian.gwt.rails.models.Identifiable;

@Json(style = Style.RAILS)
public class Audit implements HasToDisplay, Identifiable {

public final int id;

@Json(name = "created_at")
private final Date createdAt;

private String login;

private String message;

public Audit(){
this(0, null);
}

@JsonCreator
public Audit(@JsonProperty("id") int id,
@JsonProperty("createdAt") Date createdAt){
this.id = id;
this.createdAt = createdAt;
}

public int getId(){
return id;
}

public Date getCreatedAt(){
return createdAt;
}

public String getLogin(){
return login;
}

public void setLogin(String value){
login = value;
}

public String getMessage(){
return message;
}

public void setMessage(String value){
message = value;
}

public int hashCode(){
return id;
}

public boolean equals(Object other){
return (other instanceof Audit) &&
((Audit)other).id == id;
}

public String toDisplay() {
return login;
}
}
@@ -0,0 +1,44 @@
package de.mkristian.ixtlan.gwt.audits;


import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.DateLabel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.NumberLabel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

import de.mkristian.gwt.rails.editors.EnabledEditor;


public class AuditEditor extends EnabledEditor<Audit>{

interface Binder extends UiBinder<Widget, AuditEditor> {}

private static final Binder BINDER = GWT.create(Binder.class);

@Ignore @UiField FlowPanel signature;

@UiField NumberLabel<Integer> id;
@UiField DateLabel createdAt;

@UiField TextBox login;

@UiField TextBox message;

public AuditEditor() {
initWidget(BINDER.createAndBindUi(this));
}

public void resetVisibility() {
this.signature.setVisible(id.getValue() != null && id.getValue() > 0);
}

public void setEnabled(boolean enabled) {
resetVisibility();
this.login.setEnabled(enabled);
this.message.setEnabled(enabled);
}
}
@@ -0,0 +1,30 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder
xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:d="urn:import:com.google.gwt.user.datepicker.client"
xmlns:r="urn:import:de.mkristian.gwt.rails.editors">

<g:FlowPanel>

<g:FlowPanel ui:field="signature" styleName="gwt-rails-model-signature">
<g:Label>id: </g:Label>
<g:NumberLabel ui:field="id" />
<g:Label>created at: </g:Label>
<g:DateLabel ui:field="createdAt" predefinedFormat="DATE_TIME_MEDIUM"/>
</g:FlowPanel>

<g:FlowPanel styleName="gwt-rails-model-fields">
<g:HTMLPanel>
<label name="login">Login</label>
<g:TextBox ui:field="login"/>
</g:HTMLPanel>
<g:HTMLPanel>
<label name="message">Message</label>
<g:TextBox ui:field="message"/>
</g:HTMLPanel>
</g:FlowPanel>

</g:FlowPanel>

</ui:UiBinder>
@@ -0,0 +1,32 @@
package de.mkristian.ixtlan.gwt.audits;

import java.util.List;

import org.fusesource.restygwt.client.Method;

import de.mkristian.gwt.rails.events.ModelEvent;
import de.mkristian.gwt.rails.events.ModelEventHandler;

public class AuditEvent extends ModelEvent<Audit> {

public static final Type<ModelEventHandler<Audit>> TYPE = new Type<ModelEventHandler<Audit>>();

public AuditEvent( Method method, Audit model,
ModelEvent.Action action) {
super( method, model, action );
}

public AuditEvent( Method method, List<Audit> models,
ModelEvent.Action action) {
super( method, models, action );
}

public AuditEvent( Method method, Throwable e ) {
super( method, e );
}

@Override
public Type<ModelEventHandler<Audit>> getAssociatedType() {
return TYPE;
}
}
@@ -0,0 +1,7 @@
package de.mkristian.ixtlan.gwt.audits;


import de.mkristian.gwt.rails.events.ModelEventHandler;

public interface AuditEventHandler extends ModelEventHandler<Audit> {
}
@@ -0,0 +1,76 @@
/*
* ixtlan_gettext - helper to use fast_gettext with datamapper/ixtlan
* Copyright (C) 2012 Christian Meier
*
* This file is part of ixtlan_gettext.
*
* ixtlan_gettext is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* ixtlan_gettext 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with ixtlan_gettext. If not, see <http://www.gnu.org/licenses/>.
*/

package de.mkristian.ixtlan.gwt.audits;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.fusesource.restygwt.client.Method;

import com.google.gwt.event.shared.EventBus;

import de.mkristian.gwt.rails.RemoteNotifier;
import de.mkristian.gwt.rails.caches.RemoteReadOnlyAdapter;
import de.mkristian.gwt.rails.events.ModelEvent;
import de.mkristian.gwt.rails.events.ModelEvent.Action;

@Singleton
public class AuditRemoteReadOnly extends RemoteReadOnlyAdapter<Audit> {

private final AuditsRestService restService;

@Inject
protected AuditRemoteReadOnly( RemoteNotifier notifier,
EventBus eventBus,
AuditsRestService restService ) {
super( eventBus, notifier );
this.restService = restService;
}

@Override
protected ModelEvent<Audit> newEvent(Method method, List<Audit> models, Action action) {
return new AuditEvent( method, models, action );
}

@Override
protected ModelEvent<Audit> newEvent(Method method, Audit model, Action action) {
return new AuditEvent( method, model, action );
}

@Override
protected ModelEvent<Audit> newEvent(Method method, Throwable e) {
return new AuditEvent( method, e );
}

@Override
public void retrieveAll() {
notifier.loading();
restService.index(newRetrieveAllCallback());
}

@Override
public void retrieve(int id) {
notifier.loading();
restService.show(id, newRetrieveCallback());
}
}
@@ -0,0 +1,25 @@
package de.mkristian.ixtlan.gwt.audits;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

import org.fusesource.restygwt.client.MethodCallback;
import org.fusesource.restygwt.client.Options;
import org.fusesource.restygwt.client.RestService;

import de.mkristian.gwt.rails.dispatchers.DefaultDispatcherSingleton;


@Options(dispatcher = DefaultDispatcherSingleton.class)
public interface AuditsRestService extends RestService {

@GET @Path("/audits")
void index(MethodCallback<List<Audit>> callback);

@GET @Path("/audits/{id}")
void show(@PathParam("id") int id, MethodCallback<Audit> callback);

}
@@ -0,0 +1,50 @@
package de.mkristian.ixtlan.gwt.domains;


import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;
import org.fusesource.restygwt.client.Json;
import org.fusesource.restygwt.client.Json.Style;

import de.mkristian.gwt.rails.models.HasToDisplay;
import de.mkristian.gwt.rails.models.Identifiable;

@Json(style = Style.RAILS)
public class Domain implements HasToDisplay, Identifiable {

private final int id;

private final String name;

public Domain(){
this(0, null);
}

@JsonCreator
public Domain(@JsonProperty("id") int id,
@JsonProperty("name") String name){
this.id = id;
this.name = name;
}

public int getId(){
return id;
}

public String getName(){
return name;
}

public int hashCode(){
return id;
}

public boolean equals(Object other){
return (other instanceof Domain) &&
((Domain)other).id == id;
}

public String toDisplay() {
return name;
}
}

0 comments on commit 8abe1df

Please sign in to comment.