Zagura’s blog

June 16, 2009

How to convince the SmartGWT ListGrid to automatically fetch from the server only the data it displays

Filed under: English,Java,Programming,Web — puthre @ 7:29 pm

Since I was looking all over the net how to do this and I only found pieces of information, here is an example:

JAVA:
  1. public class OperationsGrid extends ListGrid{
  2.     OperationsGrid(){
  3.         super();
  4.         TreeGridField accNoField = new TreeGridField("accountNo", 150);
  5.         TreeGridField commentField = new TreeGridField("comment"150);
  6.  
  7.         setFields(accNoField,commentField);
  8.         setHeight100();
  9.         setWidth100();
  10.         setAutoFetchData(true);
  11.         setAlternateRecordStyles(true);
  12.         setDataSource(OperationsDS.getInstance());
  13.         setShowFilterEditor(true);
  14.     }
  15. }

JAVA:
  1. public class OperationsDS extends DataSource{
  2.     static OperationsDS instance = null;
  3.      static OperationsDS getInstance(){
  4.         if(instance == null){
  5.             instance = new OperationsDS();
  6.         }
  7.          return instance;
  8.     }
  9.  
  10.     OperationsDS(){
  11.  
  12.         setDataURL(xpath);
  13.         DataSourceTextField noField = new DataSourceTextField("accountNo", "Account Number", 128);
  14.         DataSourceTextField commentField = new DataSourceTextField("comment", "Comment", 128);
  15.  
  16.         noField.setRequired(true);
  17.         noField.setPrimaryKey(true);
  18.  
  19.         setFields(noField,commentField);
  20.         setDataFormat(DSDataFormat.JSON);
  21.         setRecordXPath("response/result");
  22.         setClientOnly(false);
  23.     }
  24.      @Override
  25.      protected Object transformRequest(DSRequest dsRequest){
  26.          String url = null;
  27.  
  28.          if(dsRequest.getOperationType().equals(DSOperationType.FETCH)){
  29.              dsRequest.setActionURL(getDataURL()+"&start="+dsRequest.getStartRow()+"&end="+dsRequest.getEndRow());
  30.          }
  31.          return super.transformRequest(dsRequest);
  32.      }
  33.      @Override
  34.     protected void transformResponse(DSResponse response, DSRequest request,
  35.             Object data) {
  36.         DSOperationType operationType = request.getOperationType();
  37.  
  38.         if (operationType == DSOperationType.FETCH) {
  39.             JSONArray info = XMLTools.selectObjects(data, "/response/resultInfo/numTotalRows");
  40.             Integer total = (int)Math.round(info.get(0).isNumber().doubleValue());
  41.  
  42.             info = XMLTools.selectObjects(data, "/response/resultInfo/startRow");
  43.             Integer start = (int)Math.round(info.get(0).isNumber().doubleValue());
  44.  
  45.             info = XMLTools.selectObjects(data, "/response/resultInfo/endRow");
  46.             Integer end = (int)Math.round(info.get(0).isNumber().doubleValue());
  47.  
  48.             if(total != null)
  49.                 response.setTotalRows(total);
  50.             if(start != null)
  51.                 response.setStartRow(start);
  52.             if(end != null)
  53.                 response.setEndRow(end);
  54.         } else {
  55.             super.transformResponse(response, request, data);
  56.         }
  57.  
  58.     }
  59. }

In this example the server outputs in JSON format and returns the the current start row, current end row and total number of rows in response/resultInfo.
Basically you need to override transformRequest and transformResponse. In transformRequest you should add the start and end row to the requestURL and in transformResponse you should set the startRow, endRow, and totalRows, provided that you receive this information from your server. Also don't forget to setAutoFetchData(true) on the grid.

Hope this helps somebody.

June 5, 2009

MySQL Java SQLException error codes enum

Filed under: English,Java,Programming — puthre @ 4:02 pm

Because I had this problem and I could not find a list of MySQL error codes on the Internet, I've decided to implement my own MySQL error codes enum. It is based on MySQL 5.1.35 sources, include/mysqld_ername.h file.
Now I can do something like this:

JAVA:
  1. catch (SQLException e) {
  2.                         if(e.getErrorCode() == MySQLExceptionCode.ER_DUP_ENTRY.getErrorCode()){
  3.                                  r = Result.DUPLICATE_ACCOUNT_NO;
  4.                         } else
  5.                                  r = Result.DATABASE_ERROR;
  6. }

You can find the java file here.

May 15, 2009

Download completed. You can now disconnect from the Internet.

Filed under: English,Fun — puthre @ 5:15 pm

screenshot.jpg

January 28, 2009

Midnight Commander Returns

Filed under: English,Linux — puthre @ 11:23 pm

The development for Midnight Commander seems to be revived. There is a new site that supports it's development at http://www.midnight-commander.org They are keeping the sources on a git repository and they accept patches.

This is good news for me, as I have some old issues with Midnight Commander and this might stimulate me to fix them :)

November 25, 2008

Cifs problem in Gentoo

Filed under: English,Linux — puthre @ 11:32 am

If you encounter the following error when you try to mount a cifs filesystem:
CIFS VFS: cifs_mount failed w/return code = -22

try to:
#emerge mount-cifs

I did not find any indications on the net that a separate package should be installed in order to use cifs.

Later Update: same problem in ubuntu, you need to install smbfs
#apt-get install smbfs

November 23, 2008

GWTpedia

Filed under: English,Linux,Programming,Web — puthre @ 7:47 pm

gwtpedialogo.png

As I started to look at GWT and its related widgets, tutorials and utilities, I thought that it might be an idea to put the information together into a Wiki site. This way, GWTpedia.com was born. Everyone is free to edit.

November 12, 2008

Word generator

Filed under: English,Fun,Linux,Programming — puthre @ 5:47 pm

Here is a python script to generate words using Markov chains. The archive also contains some dictionaries (English, Romanian, Romanian names). This is similar with http://www.fourteenminutes.com/fun/words/ but you have the possibility to use your own word dictionaries.

February 7, 2008

Publish your ssh public key on remote sites made easy

Filed under: Linux — puthre @ 11:54 am

Here is a script to easy publish your ssh2 public key to the remote sites you frequently connect to.

Example:
sshpubkey.sh user@example.com

You will now be able to connect to example.com from your machine without entering the password.

January 9, 2008

Midnight Commander Color Themes

Filed under: Linux — puthre @ 3:58 pm

Here is a script to easy change the default blue scheme of Midnight Commander.

Unpack the archive and do:

./mc_change_theme.sh puthre.theme

To revert to the default scheme just:

./mc_change_theme.sh default.theme

The script will modify your ~/.mc/ini file. Please make sure that Midnight Commander is not running when you change your theme.

Here is how a theme file looks:
BASE_COLOR=lightgray,blue
NORMAL=lightgray,blue
SELECTED=black,cyan
MARKED=yellow,blue
MARKSELECT=yellow,cyan
ERRORS=white,red
MENU=white,cyan
REVERSE=black,lightgray
DNORMAL=black,lightgray
DFOCUS=black,cyan
DHOTNORMAL=blue,lightgray
DHOTFOCUS=blue,cyan
VIEWUNDERLINE=brightred,blue
MENUHOT=yellow,cyan
MENUSEL=white,black
MENUHOTSEL=yellow,black
HELPNORMAL=black,lightgray
HELPITALIC=red,lightgray
HELPBOLD=blue,lightgray
HELPLINK=black,cyan
HELPSLINK=yellow,blue
GAUGE=white,black
INPUT=black,cyan
DIRECTORY=white,blue
EXECUTABLE=brightgreen,blue
LINK=lightgray,blue
STALELINK=brightred,blue
DEVICE=brightmagenta,blue
CORE=red,blue
SPECIAL=black,blue
EDITNORMAL=lightgray,blue
EDITBOLD=yellow,blue
EDITMARKED=black,cyan
ERRDHOTNORMAL=yellow,red
ERRDHOTFOCUS=yellow,lightgray

Here is the result:
mc.png

July 10, 2007

Problems emerging device-mapper.1.02.19 with confcache on Gentoo

Filed under: English,Linux — puthre @ 3:10 pm

Disable confcache in /etc/make.conf if you are getting this when trying to emerge device-mapper.1.02.19 on Gentoo:
checking target system type... config.sub: missing argument
Try `config.sub --help' for more information.
configure: error: /bin/sh autoconf/config.sub failed

!!! Please attach the following file when filing a report to bugs.gentoo.org:
!!! /var/tmp/portage/sys-fs/device-mapper-1.02.19/work/device-mapper.1.02.19/config.log

!!! ERROR: sys-fs/device-mapper-1.02.19 failed.
Call stack:
ebuild.sh, line 1621: Called dyn_compile
ebuild.sh, line 973: Called qa_call 'src_compile'
ebuild.sh, line 44: Called src_compile
device-mapper-1.02.19.ebuild, line 22: Called econf '--sbindir=/sbin' '--disable-selinux'
ebuild.sh, line 578: Called die

!!! econf failed
!!! If you need support, post the topmost build error, and the call stack if relevant.
!!! A complete build log is located at '/var/tmp/portage/sys-fs/device-mapper-1.02.19/temp/build.log'.

« Previous PageNext Page »

Powered by WordPress