Showing posts with label by Uki D. Lucas. Show all posts
Showing posts with label by Uki D. Lucas. Show all posts

GWT: how to make your Composite widget clickable

by implementing HasClickHandlers

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.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;

public class IconWithText extends Composite implements StyleConstants, HasClickHandlers
{
HorizontalPanel widget;

public IconWithText(String iconStyleName, String text)
{
widget = new HorizontalPanel();
widget.setStyleName(STYLE_WIDGET);
HTML icon = new HTML("");
icon.setStyleName(iconStyleName);
widget.add(icon);

Label label = new Label(text);
label.setStyleName("label_for_icon");
widget.add(label);
initWidget(widget);
}

public HandlerRegistration addClickHandler(ClickHandler handler)
{
return addDomHandler(handler, ClickEvent.getType());
}

}



As an Amazon Associate I earn from qualifying purchases.

CSS sprites

CSS sprites are a great way to SPEED UP your application, and simplify the design changes. You save in two ways:

1) amount of HTTP calls, each call has a relatively large overhead compared to small icon file it fetches
2) putting many small files into single saves a lot of "weight" as well

Take example of these icons, each about 37 kb...


When combined into a single file they weight ONLY 49 kb, that is from about total of 250 kb, including all other icons I have put into it.


You want to put your files into a narrow image to make it convenient for yourself, you will use your favorite graphic tool (Pixelmator, Photoshop) to measure where the icon starts. I made all my icons 30 pixel tall.

Here I am interested in Facebook (heart icon) and I see that it starts at about 1264 pixels (X coordinate), since Y is ALWAYS at 0 pixels, and width and height are 30 pixel, that is all I need...


Finally, I write a simple to understand CSS style:

.icon_favorite {

background: url("images/icons001.png") no-repeat;

background-position: -928px 0px;

width: 30px;

height: 30px;

cursor: pointer;

}


.icon_facebook {

background: url("images/icons001.png") no-repeat;

background-position: -1264px 0px;

width: 30px;

height: 30px;

cursor: pointer;

}


.icon_edit {

background: url("images/icons001.png") no-repeat;

background-position: -1299px 0px;

width: 30px;

height: 30px;

cursor: pointer;

}


Then GWT code to use that style, notice I use HTML, not Image for that icon.


HTML submitToFacebook = new HTML("");

submitToFacebook.setStyleName("icon_facebook");

submitToFacebook.setTitle("Click to post this recipe on Facebook");

...

HTML edit = new HTML("");

edit.setStyleName("edit_facebook");

edit.setTitle("Click to edit this recipe");

...


And that is it...



Updated (after receiving some feedback):

I still like the CSS sprites solution because it gives a full control to the graphic (HTML/CSS) designer, but GWT developers should definitely take a look at ImageBundle.




As an Amazon Associate I earn from qualifying purchases.

How to separate UI from code in GWT

1. Create a general structure in HTML with all DIVs that represent major widgets


<script type="text/javascript" language="javascript" src="myapp/myapp.nocache.js"></script>
</head>
<body>

<div id="header">
<h1>Welcome to My App</h1>
<div id="facebook_login"></div>
</div>
<div id="tool_tip"></div>

<table id="main_content">
<tr>
<td id="left_column">
<div id="list_of_products"></div>
</td>
...

2. Style the widgets in CSS

#header h1 {
background-color: yellow;
border-style: dotted;
font-size: xx-large;
}

3. Build the widgets in Java. Note: widgets are composites of various HTML elements and can have their own CSS styling.

RootPanel.get("facebook_login").clear();
RootPanel.get("facebook_login").add(new FbLogin(session));



As an Amazon Associate I earn from qualifying purchases.

MySQL Database backup (mysqldump) from command line

As the database grows in size the convenient GUI tools became too slow, at some point it is easier to log in to the database server and do it from the command line...
mysqldump --user MY_USER_NAME -p DB_NAME> /var/www/UNIQUE_NAME_AND_DATE.sql
Enter password: MY_PASSWORD
#compress, you can also use gzip
tar cvzf UNIQUE_NAME_AND_DATE.sql.tar UNIQUE_NAME_AND_DATE.sql
# delete sql
rm /var/www/UNIQUE_NAME_AND_DATE.sql
#download:
http://www.DOMAIN_NAME.com/UNIQUE_NAME_AND_DATE.sql.tar
# after transfer delete
rm /var/www/UNIQUE_NAME_AND_DATE.sql.tar


As an Amazon Associate I earn from qualifying purchases.

Upgrade to Snow Leopard Mac OS X 10.6

The upgrade went OK, took about 1 hour (actually I fell asleep and left it to install itself).

Installation cleared about 12 Gb of space on my hard drive, which is a good thing for me.

After the installation I had to do the following:

- install new GlobeTrotter Connect for my AT&T card, thankfully I have WI-FI at home. See instructions in the earlier post.
- restore Java 1.5.0 from my Time Machine to get GWT working again. See instructions in the earlier post.
- Growl for Mail.app



As an Amazon Associate I earn from qualifying purchases.

You must use a Java 1.5 runtime to use GWT Hosted Mode on Mac OS X.

After the upgrade to Snow Leopard Mac OS X 10.6 I got the following error in GWT Eclipse console:

You must use a Java 1.5 runtime to use GWT Hosted Mode on Mac OS X.

I FIXED this issue by restoring Java 1.5 from my Time Machine in following steps:

1) Verify that Java 1.5.0 is missing from Snow Leopard
1.5.0 -> CurrentJDK
CurrentJDK -> 1.6

uki@Uki:/System/Library/Frameworks/JavaVM.framework/Versions $ ls -alt
total 48
drwxr-xr-x 11 root wheel 374 Sep 19 00:18 .
drwxr-xr-x 11 root wheel 374 Sep 19 00:18 ..
drwxr-xr-x 8 root wheel 272 Sep 19 00:17 A
lrwxr-xr-x 1 root wheel 1 Sep 19 00:17 Current -> A
lrwxr-xr-x 1 root wheel 5 Sep 19 00:17 1.6 -> 1.6.0
drwxr-xr-x 7 root wheel 238 Sep 19 00:17 1.6.0
lrwxr-xr-x 1 root wheel 3 Sep 19 00:17 CurrentJDK -> 1.6
lrwxr-xr-x 1 root wheel 5 Sep 19 00:17 1.3 -> 1.3.1
lrwxr-xr-x 1 root wheel 10 Sep 19 00:17 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Sep 19 00:17 1.5.0 -> CurrentJDK
drwxr-xr-x 3 root wheel 102 Jul 20 18:35 1.3.1
uki@Uki:/System/Library/Frameworks/JavaVM.framework/Versions $

2) Restore Java 1.5.0 from your Time Machine (if you have no backup, shame on you!)


3) Create a symbolic link (sudo ln -s 1.5.0/ CurrentJDK)


uki@Uki:/System/Library/Frameworks/JavaVM.framework/Versions $ sudo ln -s 1.5.0/ CurrentJDK

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
uki@Uki:/System/Library/Frameworks/JavaVM.framework/Versions $ ls -alt
total 40
drwxr-xr-x 11 root wheel 374 Sep 19 06:38 .
lrwxr-xr-x 1 root wheel 6 Sep 19 06:38 CurrentJDK -> 1.5.0/
drwxr-xr-x 11 root wheel 374 Sep 19 00:18 ..
drwxr-xr-x 8 root wheel 272 Sep 19 00:17 A
lrwxr-xr-x 1 root wheel 1 Sep 19 00:17 Current -> A
lrwxr-xr-x 1 root wheel 5 Sep 19 00:17 1.6 -> 1.6.0
drwxr-xr-x 7 root wheel 238 Sep 19 00:17 1.6.0
lrwxr-xr-x 1 root wheel 5 Sep 19 00:17 1.3 -> 1.3.1
lrwxr-xr-x 1 root wheel 10 Sep 19 00:17 1.5 -> CurrentJDK
drwxr-xr-x 3 root wheel 102 Jul 20 18:35 1.3.1
drwxr-xr-x 8 root wheel 272 May 7 2008 1.5.0
uki@Uki:/System/Library/Frameworks/JavaVM.framework/Versions $

4) Verify that you have the right set up

uki@Uki:/System/Library/Frameworks/JavaVM.framework/Versions $ java -version
java version "1.5.0_20"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_20-b02-315)
Java HotSpot(TM) Client VM (build 1.5.0_20-141, mixed mode, sharing)
uki@Uki:/System/Library/Frameworks/JavaVM.framework/Versions $

The GWT will work now, I will switch to Java 1.6 AFTER GWT release next update.



As an Amazon Associate I earn from qualifying purchases.

com.google.gwt.user.client.rpc.SerializationException

When getting the following exception while fetching objects to the front end:

Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'org.datanucleus.store.appengine.query.StreamingQueryResult' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.


Even when I know the object is Serializable....

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class RecipeStep implements Serializable
{
    public RecipeStep()
    {
    }



All I had to do is to REWRITE the returned LIST:

    public List<RecipeStep> fetch(Long recipeId)
    {
      ...
    steps = (List<RecipeStep>) pm.newQuery(query).execute();
...


List<RecipeStep> returnList = new ArrayList<RecipeStep>();
for(RecipeStep step: steps)
{
    returnList.add(step);
}
return returnList;
    }













As an Amazon Associate I earn from qualifying purchases.

pair programming

Here are a steps I would like the team to follow while developing:

1. Create a wiki topic on what you are planning to do and explain these steps to someone before starting writing the code
2. Have a buddy spend at least a part of the day pair-programming with you, return the favor the next day.
3. Make sure to do a code-review daily and explain how the features work
4. Test your buddy's code and have them test yours. Use the wiki list as the start
5. Post screenshots on wiki early on and have client read thru them, make sure you get feedback (so you know they have read it)
6. Update the test list for the project
7. Assume that UAT testing is NOT for developers but for the CLIENT, there should be no surprises or code changes but then.

This list came up from the our experience and feedback from my developers (thanks to Phil W. for your thoughts)...

In the past development cycle I cave in to the fact that we had a large number of tasks and a limited, geo-dispersed team so I abandoned the practice of pair programming. The result was a prolonged period of
"bug fixes" and late, stressful build.

With the pair programing, we sometimes had a few of issues, but we never spent so much time on fixing bugs. It was almost a deja vu of the previous projects, of which many have failed.

As a project manager I have to take a full responsibility for this failure, and correct the problems.

Pair programming fosters:

- better understanding of the "big picture" by the whole team
- essential questions asked early on in the development cycle
- lack of procrastination with development
- more time spent actually developing vs. browsing the web, or daydreaming

Single developer programming leads to:

- lack of team work
- developers working on hard issues burn out and loose motivation
- developers "sand bag", or inflate the time required to accomplish the task
- developers take it "personally" and get hurt emotionally when client criticize their work
- when the developers finally quits, no one knows how things work



As an Amazon Associate I earn from qualifying purchases.

Gtug



As an Amazon Associate I earn from qualifying purchases.

Gtug Jay Williams



As an Amazon Associate I earn from qualifying purchases.

Gtug



As an Amazon Associate I earn from qualifying purchases.

Gtug



As an Amazon Associate I earn from qualifying purchases.

Gtug



As an Amazon Associate I earn from qualifying purchases.

Google Technology meeting on Wednesday, Aug. 12, 2009

Agenda:


Events


As an Amazon Associate I earn from qualifying purchases.

MailServe for Mac

MailServe is a great application if you want to send email from your Mac

It is wise to STOP it when you don't need to use it, for that OPTION-click on "Restart Postfix" icon in the TOP RIGHT, then make sure all the lights are RED on the bottom.









As an Amazon Associate I earn from qualifying purchases.

Ethernet vs. WI-FI vs. VPN

I was testing the speed of my Comcast cable wondering how much the WI-FI and VPN connection slow me down and the results actually suprised me:

Ethernet directly via cable
15.6 down
6 Mbps up

Ethernet with VPN connected:
15.6 Mbps down
6.6 Mbps up

WIFI (via Apple Airport Base Station 802.1g, not "n" )
16.0 down
5.8 Mbsp

As you can see the speed is the same (+/- small variation), so being tethered on the cable does not help anything really.

http://ukitech.blogspot.com/2009/07/test-your-internet-speed-in-chicago.html


Finally AT&T 3G card:

1.845 Mbps download speed

0.966 Mbps upload speed


As you can see the 3G is NOT a replacement for Cable.



As an Amazon Associate I earn from qualifying purchases.

AppEngine data viewer in hosted mode



If you are frustrated that you cannot view your data in the AppEngine GWT in hosted mode, follow these steps:

Update Google AppEngine SDK to the newest version (Java 1.2.2 as of this writing):


















Open:



The next (most alloying step) is to insert at least one record for each object you want to save:






public UserDao()
{
init();
}

private void init()
{
User user = fetchFacebook(new Long(764XXXXXX));
if (user != null)
return;

User uki = new User("Uki D. Lucas");
uki.setFacebookUID(new Long(764XXXXXX));
save(uki);
}













There is a List and Delete options, I suppose the Edit and Add are coming soon.


As an Amazon Associate I earn from qualifying purchases.

apt quotation..