Showing posts with label GWT. Show all posts
Showing posts with label GWT. Show all posts

Tuesday, July 21, 2015

GWT Scheduler.scheduleDeferred implementation

Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
    @Override    public void execute() {
        render();    }
});

Friday, June 19, 2015

GWT - ListBox with Enum vs ValueListBox implementation example


public class EnumListBoxEditor<T extends Enum<T>> implements IsWidget, LeafValueEditor<T> {

    private ListBox listBox;    private Class<T> enumType;
    public EnumListBoxEditor(Class<T> tClass) {
        listBox = new ListBox();        this.enumType = tClass;        for(T e : enumType.getEnumConstants()) {
            listBox.addItem(e.name());        }
    }

    @Override    public Widget asWidget() {
        return listBox;    }

    @Override    public void setValue(T language) {
        listBox.setSelectedIndex(language.ordinal());    }

    @Override    public T getValue() {
        int index = listBox.getSelectedIndex();        T result = null;        for (T e : enumType.getEnumConstants()) {
            String itemName = listBox.getValue(index);            if (e.name().equals(itemName)) {
               result = e;            }
        }
        return result;    }

    public void setEnabled(boolean isEnabled){
        listBox.setEnabled(isEnabled);    }

}

Thus this approach is acceptable the best way to use ListBox with any Enum or bean that implement HasLabel interface is ValueListBox component e.g.:

@UiField(provided = true)
ValueListBox<TeamDTO> team;
 
this.team = new ValueListBox<TeamDTO>(new HasLabelRenderer<TeamDTO>(), new IdentityProvidesKey<TeamDTO>());
 
public class HasLabelRenderer<T extends HasLabel> extends AbstractRenderer<T>{

    @Override    public String render(HasLabel object) {
        return object == null ? "" : object.getLabel();    }

}
 
public class IdentityProvidesKey<T extends Identity> implements ProvidesKey<T> {
    @Override    public Object getKey(T item) {
        return item == null ? null: item.getId();    }
}

Tuesday, June 2, 2015

JAVA GWT - entity persistence approach

== IDENTITY ==
import java.io.Serializable;

public interface Identity<T extends Serializable> extends Serializable{
    T getId();
    void setId(T id);
}

Tuesday, May 19, 2015

GWT DataGrid with LeafValueEditor

====== UIBINDER =======

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
             xmlns:g='urn:import:com.google.gwt.user.client.ui'
             xmlns:b.grid='urn:import:org.gwtbootstrap3.client.ui.gwt'
             xmlns:b='urn:import:org.gwtbootstrap3.client.ui' >

Wednesday, May 13, 2015

Monday, May 11, 2015

Could not reserve enough space for object heap

Here is the errors during the Maven build:

Error occurred during initialization of VM 
Could not reserve enough space for object heap 
Error: Could not create the Java Virtual Machine. 
Error: A fatal exception has occurred. Program will exit. 
Picked up _JAVA_OPTIONS: -Duser.home=C:\Users\Andre

In order to fix this, add an extra parameter to _JAVA_OPTIONS sys environment:
-Xmx512m

So it should look something like this:
_JAVA_OPTIONS: -Duser.home=C:\Users\Andre -Xmx512m

Issues with user.home during Maven build

If you have issue with incorrect property user.home during Maven build set this sys environment:

_JAVA_OPTIONS=C:\Users\username

More of it here:
http://stackoverflow.com/questions/1501235/change-user-home-system-property

Friday, May 8, 2015

GWT - how dynamically change a static css of theme in GWT Dev Mode

We know that all static resources e.g. images, css should be kept in project structure in static way e.g. through resource or public packages. This principle supposes that these kind of resources rarely will be changed. But if in your RIA GWT project you have to override some theme's css by some custom-style.css and see the result lets say "right now" in Dev Mode there would be the problem because if both css stored statically you can not dynamically see the result of the change just by refreshing the browser page e.g. F5.

If you want to see your css changes dynamically in GWT Dev Mode you have to inject your e.g. custom-style.css through ClientBundle somewhere in the beginning e.g. onModuleLoad().

===== Create this class inside resource package in you java src ====
 
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.resources.client.CssResource.NotStrict;

/**
 * Created by panoand on 08/05/2015.
 */
public interface AppResources extends ClientBundle {

    AppResources INSTANCE = GWT.create(AppResources.class);

    @Source("css/custom-style.css")
    @NotStrict
    CssResource foo();
}

===== In your EntryPoint class put it inside onLoadModule() methode =====
AppResources.INSTANCE.foo().ensureInjected();







Thursday, May 7, 2015

GWT project settings

=========== app-client =================

<?xml version="1.0" encoding="UTF-8"?>
<project
        xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

GWT - LeafValueEditor implementation for RadioButton widget with Enum type

package com.paniov.bitwitwebapp.client.widgets.editors;

import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.uibinder.client.UiConstructor;
import org.gwtbootstrap3.client.ui.RadioButton;
import org.gwtbootstrap3.client.ui.html.Div;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Paniov on 06.05.15.
 */
public class EnumRadiobuttonEditor extends Div implements LeafValueEditor<ButtonsType> {

Wednesday, May 6, 2015

GWT - links on ListEditor example code

https://sites.google.com/site/mygwtexamples/home/ui/listeditor

https://goo.gl/J5wCvQ

GWT - SelectActionCell. ActionCell with options menu

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.BrowserEvents;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import org.gwtbootstrap3.client.ui.constants.ButtonSize;
import org.gwtbootstrap3.client.ui.constants.ButtonType;

import java.util.*;

public class SelectActionCell<T> extends AbstractCell<T> {

Friday, May 1, 2015

Google DI Guice - @ImplementedBy

The content below is taken from here:
http://blog.decaresystems.ie/2007/06/14/juicy-code-with-google-guice-part-4/
All parts about GUICE from the same source:
Part 2 – First Code
Part 3 – Dependency Injection
Part 4 – @ImplementedBy and Annotating Bindings
Part 5 – Custom Providers and Conclusions
As I mentioned in the previous blog entries, you configure Google Guice by creating a class that implements the Module interface or better, one that extends AbstractModule class. In this class you specify the bindings that logically connects implementations to interfaces. However, there’s a way that lets you create the bindings using annotations without needing to write the code in a Module implementation. You can do that using the@ImplementedBy annotation decorating an interface.
Let’s see a quick example:
1
2
3
4
5
6
7
8
import com.google.inject.ImplementedBy;
@ImplementedBy(MobilePhone.class)
public interface Phone {
public void ring();
}
The simple interface above is decorated with the @ImplementedBy annotation and the name of the implementer is specified as a single attribute.
1
2
3
4
5
6
7
public class MobilePhone implements Phone {
public void ring() {
System.out.println("It's playing some annoying melody...");
}
}