Mar 17 2008

Gwt-Ext screencasts for beginners

Tag: Ext, Gwt, Java, Javascript, Links, Linux, Maps, Programming, Ubuntu, WebAbhijeet Maharana @ 8:51 pm

I have started out with Gwt-Ext and thought I will record some screencasts. These are for beginners who may need a hand when they are starting out and are anxious to jump right into code. The screencasts have been recorded on Ubuntu Feisty with Eclipse Europa.

There are 3 screencasts in avi and ogg format.

  1. First screencast shows the installation of Gwt 1.4 and Cypal Studio for Gwt. Cypal Studio is an Eclipse plugin that automates most of the tasks associated with GWT like adding a module and adding a remote service. In the screencast, I create a Gwt project using this plugin.
  2. Second screencast shows how to add the ExtJS Javascript library (2.0) and Gwt-Ext Java library (2.0.1) to the project. In the screencast, I create a simple Ext form with some text fields and a button.
  3. Third screencast (added on March 22) shows how to send form data back to the server. In the screencast, I validate form fields using regular expressions / Ext Vtype, add a remote service and then save form data in an Oracle database using the remote service.

    You can read this post for installing Oracle 10g XE on Ubuntu Feisty.

All screencasts are hosted at Rapidshare. Sanjiv Jivan, the author of Gwt-Ext has offered to host them at gwt-ext.com. I think the files are quite big and I am not well-versed with audio/video formats and parameters. If you know any way to reduce file size while maintaining the quality of screencasts, do let me know.

Download screencasts from Rapidshare.
Download Eclipse projects shown in the screencasts from Gwt-Ext.com or Rapidshare.

Update:
Sanjiv has been kind to host them at http://www.gwt-ext.com/screencasts/.
I have also edited the gwt-ext wiki accordingly. (See comments)

Related links:
Google Web Toolkit
ExtJS Javascript library
Gwt-Ext
Cypal Studio for Gwt


Jan 21 2008

OpenOffice woes

Tag: Linux, UbuntuAbhijeet Maharana @ 9:10 pm

I am running Ubuntu 7.04 - Feisty Fawn. Applications from OpenOffice.org 2.2 crashed on my face with the error message:

The application cannot be started.
An internal error occurred.
OpenOffice.org 2.2 error

On running it from a terminal, it became evident that the problem was with user settings

$ oowriter
[Java framework] Error in function createUserSettingsDocument (elements.cxx).javaldx failed!
GTK Accessibility Module initialized
[Java framework] Error in function createUserSettingsDocument (elements.cxx).GTK Accessibility Module shutdown
 
** (process:9274): WARNING **: Unknown error forking main binary / abnormal early exit ...

A search for “Error in function createUserSettingsDocument (elements.cxx).javaldx failed!” led me to this thread where the answer was in the 6th post:

Become root, delete “/home/<username>/.openoffice.org2″ and then start OpenOffice. The folder is recreated and all works well.


Jan 07 2008

Ubuntu Feisty + Squid proxy

Tag: Linux, Ubuntu, WebAbhijeet Maharana @ 12:43 am

I have a LAN at home and one of my machines is connected to the Internet. I wanted to share this connection with the other machines.

When I had Ubuntu Edgy earlier, I had set up Internet Connection Sharing, referring this thread at Ubuntuforums.org. Now I am using Feisty and thought I will set up a proxy server this time. So I went with Squid. My installation log (for plain http access) is given below.

  1. Install Squid. Open a terminal and type
  2. sudo apt-get install squid
  3. Set visible_hostname
    If you got the below error message after installation, you will need to set visible_hostname.
  4. FATAL: Could not determine fully qualified hostname.  Please set 'visible_hostname'

    Edit /etc/squid/squid.conf as root and add a hostname (line 2899 on my system - line numbers are wrt the config file that is created when Squid 2.6.5-4 is installed from the Feisty repository)

    visible_hostname newpc
  5. Grant access to machines on your LAN
    Add the following lines to squid.conf to create an acl and grant http_access to it (you can find a commented example around line 2590 in this file). Replace the IP address range as required.

    acl my_network src 192.168.1.0/24
    http_access allow my_network
  6. (Re)start squid
    sudo /etc/init.d/squid restart

Now you can point the browsers on your LAN machines to port 3128 on the machine where squid is running.


Dec 29 2007

Command not found … do the following!

Tag: Linux, UbuntuAbhijeet Maharana @ 11:04 pm

I was working with a script and had to do a quick float calculation. I knew Accessories >> Calculator but wanted a command line utility. Struggling to remember the syntax for using bc, I tried

$ bc 2.38987 + 5.43534
File 2.38987 is unavailable.

Not quite amused with the response, I was wondering if it always has to be as geeky as

echo 2.38987 + 5.43534 | bc

or

bc -i
2.38987 + 5.43534

and not something like

calc 2.38987 + 5.43534

I happened to type ‘calc’ and hit return without really thinking about it, and Ubuntu promptly reported

The program 'calc' is currently not installed.  You can install it by typing:
sudo apt-get install apcalc
Make sure you have the 'universe' component enabled
bash: calc: command not found

I was impressed! It doesn’t just tell me “command not found” but also tells me how to enable it to find it! Given Ubuntu’s packaging and software repository system this may be simple to achieve but these “simple” little things are what make exploring Ubuntu a joy. I took my OS’s advice and in no time I was using “calc 2.38987 + 5.43534″ (I am using Ubuntu 7.04).


Dec 22 2007

Oracle 10g XE + Java on Ubuntu Feisty

Tag: Database, Java, Linux, Programming, UbuntuAbhijeet Maharana @ 3:30 pm

I needed a basic database on my Ubuntu Feisty system and decided to try out Oracle 10g Express Edition. The installation is pretty straightforward. Below is a log of what I did to get it running along with Java code to access the database.

My Setup:

  • AMD 3600+ 64 bit running Ubuntu 7.04 32 bit
    (2.6.20-15-generic kernel)
  • 2GB RAM

Download the .deb file for Oracle Database 10g Express Edition for Linux x86. I have oracle-xe_10.2.0.1_i386.deb which is a bit old now. The official installation guide is located here.

The installation steps are as follows:

  • Step1: Requirements and installation
    In short: 1.5 GB of disk space, 512 MB of RAM with 1GB swap. The Express Edition can use a maximum of 1GB of RAM even if more is available. The minimum and recommended requirements for installation can be found here . The installation went fine on my machine with 2GB of RAM and no swap space.

    Run the .deb. You may need to be connected to the Internet for the dependencies. The installation creates shortcuts under the Applications menu. However, we don’t need to use any at the moment.

    screenshot

  • Step2: Configuring the database
    Run

    sudo /etc/init.d/oracle-xe configure

    Use the default settings for Oracle Application Express (8080) and the database listener (1521) or change the ports if you have other servers using these ports.

    Enter the SYS/SYSTEM password. I used ‘manager’.

    Select ‘n’ for the option for starting the database at boot time since we can conveniently do the same using the created menu items. [See the troubleshooting section below]

    screenshot

    The user starting or stopping the database must be a member of the ‘dba’ group. This can be done from [Gnome Menu] >> System >> Administration >> Users and groups >> Manage groups. Select ‘dba’ and click on properties. Select user(s) to add them to this group.

  • Step3: Administration using the web interface
    Log into Application Express by hitting the URL http://127.0.0.1:8080/apex
    Enter SYSTEM / [password you had entered earlier]. There is a built-in user account HR which needs to be unlocked before it can be used. But, we will create a new account for our use.
    Goto Administration >> Database users >> Create user
    Enter ’scott’ / ‘tiger’ for the username / password and click Create.

    screenshot 1 | screenshot 2

    Log out and log in again as scott.

  • Step4: Create test tables
    Create a table

    • using the object browser
      Object browser >> create >> table

      screenshot 1 | screenshot 2

    • using a SQL Query
      SQl >> SQL Commands >> Enter Command
      You can enter multiple statements in the editor and execute one statement at a time by selecting a statement and hitting CTRL + ENTER.
      CTRL + ENTER works out of the box on Firefox 2.0.0.3. On Opera 9.24, you may need to change some settings. At this point I can’t say what.

      screenshot 1 | screenshot 2 | screenshot 3

  • Step5: Access database from Java

    Save the following code as OracleJdbcDemo.java. It prints values from the first column.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    import java.sql.*;
     
    public class OracleJdbcDemo
    {
    	public OracleJdbcDemo() throws Exception
    	{
    		Class.forName("oracle.jdbc.OracleDriver");
    		String connString = "jdbc:oracle:thin:@localhost:1521:XE";
    		Connection conn = DriverManager.getConnection(connString, "scott", "tiger");
    		Statement stmt = conn.createStatement();
    		ResultSet rs = stmt.executeQuery("select * from student");
    		while(rs.next())
    		{
    			System.out.println(rs.getString(1));
    		}
    	}
     
    	public static void main(String args[]) throws Exception
    	{
    		new OracleJdbcDemo();
    	}
    }

    Compile and run the code by supplying the ojdbc14.jar file in the classpath:

    $ javac OracleJdbcDemo.java
    $ java -cp "/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/jdbc/lib/ojdbc14.jar":. OracleJdbcDemo

    If you have downloaded and installed a JDK yourself, make sure the compiler and interpreter are both from the same installation.
    I have JDK1.6.0 installed on my system and this is the entry in my /home/abhijeet/.bashrc

    export JAVA_HOME="/apps/java/jdk1.6.0"
    export PATH=${JAVA_HOME}|>/bin:${PATH}|>



Troubleshooting


I came across a situation where just after the installation everything worked fine but after a reboot, neither http://localhost:8080/apex nor the Java program worked. However, the database was starting and stopping from the menu options as I was able to connect using the “Run SQL Command Line” utility found in the menu. First few lines of the exception thrown by the program are shown below:

Exception in thread "main" java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
...

I had answered “no” to start the database at boot time since I didn’t want it running when I am not using it. This may or may not be related to the problem above and I did not reinstall selecting “yes” to check.

After searching a little, this is what worked.
Register environment variables and start TNSLISTENER:

$ . /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh
$ sudo /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/tnslsnr

If you get the following error after the first command

/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh: 114: [[: not found
/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh: 114: [[: not found

then edit /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh and change the first line from

#!/bin/sh

to

#!/bin/bash

Wait for sometime after starting the listener and both the web interface and Java program should start working.

[Reference: Oracle forums]


Dec 04 2007

Lively Kernel and Documancer

Tag: Javascript, Links, Linux, Programming, WebAbhijeet Maharana @ 10:47 pm

Lively Kernel

From being used in web pages to add “some” interactivity to being used in a web based “kernel”, Javascript has come a long way. A team at SUN has developed a kernel that provides an execution environment for applications meant for the browser. From the Sun Labs Lively Kernel page, “The Sun Labs Lively Kernel is a new web programming environment developed at Sun Microsystems Laboratories. The Lively Kernel supports desktop-style applications with rich graphics and direct manipulation capabilities, but without the installation or upgrade hassles that conventional desktop applications have.” Written entirely in Javascript, the Lively Kernel emphasizes on treating Web applications as real applications and aims to build a platform using a minimum number of technologies. So its Javascript for most of the things.

It comes with the ‘Morphic’ graphic library which was originally written for the ‘Self’ system at Sun. From the same page, “Morphic is a user interface framework that supports composable graphical objects, along with the machinery required to display and animate these objects, handle user inputs, and manage underlying system resources such as displays, fonts and color maps. A key goal of Morphic is to make it easy to construct and edit interactive graphical objects, both by direct manipulation and from within programs.”

It even includes an IDE that allows JavaScript applications to be inspected and modified from within the system itself. It is currently supported on Safari 3.0.3 public beta release. Runs on Firefox but has a lot of related nasty bugs and locked my browser. IE support is yet to be added.

Screenshot (image is located at SUN’s site)

Related links:

Documancer

This is an invaluable tool in any programmer’s toolkit. It is a documentation browser which supports HTML, DevHelp, Info pages, Manual pages, remote WWW sites and pydoc. But the feature that got me hooked is the full-text search. Specially when it comes to HTML documentation such as those created with javadoc. Documentation for the Java APIs is also available in WinHelp and HTMLHelp formats which enable searching. But for other libraries which use javadoc to generate their documentation, it is a pain to search for something. Specially when you are new to the library. That is where this gem shines.

Its UI is based on Gecko, Mozilla’s HTML rendering engine and it presents documentation of all formats in the same way. It supports bookmarks as well. It is implemented in wxPython and is available for Unix and Windows. It comes with a nice installer which takes care of all dependencies.

Related links:

Apparently, there is another Gecko! (that sells clothes) which comes before the Mozilla page in a Google search for “gecko home page”.


Aug 31 2007

Mousekeys on Linux

Tag: LinuxAbhijeet Maharana @ 11:50 pm

Sometimes, you may need to use the keyboard for controlling the mouse pointer. Such as when your mouse is dead or you are temporarily stuck with an old machine that doesn’t recognise a USB mouse (and you don’t have the other options).

Under Windows, the Mousekeys settings are under Control Panel >> Accessibility Options. On Linux, we have AccessX for this purpose. AccessX is a set of features designed to make X more accessible to users. The site at http://www.math.missouri.edu/~stephen/software has some useful links if you want to know more. AccessX is built into X Window System version R6 and above. So you will not need to install it separately now.

If you want to enable Mousekeys (and many other accessibility features) on your Ubuntu machine, the steps are given below. I did this on Ubuntu and Kubuntu Dapper.

1. Install xkbset written by Stephen Montgomery-Smith (http://www.math.missouri.edu/~stephen/). xkbset is a utility that allows you to interact with the AccessX features of X.

sudo apt-get install xkbset

2. Turn AccessX on. I needed to do this only on Ubuntu.

xkbset a

3. Turn MouseKeys on.

xkbset m

4. After turning Mousekeys on, you can use the numeric keypad to control the pointer. The default settings are as follows:

NUM
1, 2, 3, 4, 6, 7, 8, 9
Direction control
NUM 5 Click
- Switch to right click mode. Press 5 now to right click.

/ Switch to left click mode
0 (INS) Switch to select/drag mode. Now use direction control keys to select/drag stuff
. (DEL) End select/drag

5. If you need to turn off MouseKeys,

xkbset -m

Jun 22 2007

wmctrl

Tag: LinuxAbhijeet Maharana @ 11:57 pm

I came across wmctrl recently which can be to interact with a EWMH/NetWM compatible X Window Manager such as Enlightenment, Icewm, Kwin, Metacity and Sawfish. From the description of wmctrl: “Wmctrl provides command line access to almost all the features defined in the EWMH specification. For example it can maximize windows, make them sticky, set them to be always on top. It can switch and resize desktops and perform many other useful operations.” More information on wmctrl is available at http://www.sweb.cz/tripie/utils/wmctrl/

I installed it on my Ubuntu Edgy system from the repository

sudo apt-get install wmctrl

The usefulness of this program is quite evident. I list some examples below.

  1. Launch a program on a different desktop:
    Create the file LaunchProgram.sh in a folder in your path (I used /usr/bin):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    #!/bin/bash
     
    if [ $# -ne 2 ]
    then
            message="Usage\n\t$0 Program DesktopNumber"
            message="$message \n\nExample\n\t$0 'nautilus /usr' 1"
            zenity --error --text="$message"
    else
            currentDesktop=`wmctrl -d | grep '*' | cut -d' ' -f1`
     
            wmctrl -s $2 && $1
            wmctrl -s $currentDesktop
    fi

    $# is the number of command line arguments passed to the script. We want exactly 2 arguments. $0 is the file’s name which was used to launch the script. The desktop number should be between 0 and (number of desktops - 1). This script assumes that correct values are passed.

    zenity is used to display a dialog with the error message.

    In the output of wmctrl -d, the current desktop has a * next to the desktop number. We use grep to get that line and then extract the desktop number which is the first field (hence -f1). The -d’ ‘ option tells cut that the fields are separated by a single space.

    $1 onwards represent the arguments passed to the script. We switch to the desktop number passed as the second argument and launch the command passed as the first argument.

    Grant execute permission on the script and launch an example:

    chmod a+x LaunchProgram.sh
    LaunchProgram.sh "nautilus /usr/bin" 1


  2. Cycle through desktops:
    There was a requirement to switch desktops automatically at a pre-defined interval. The desktops had running applications (such as vnc clients connected to different computers) which had to be monitored. A shell script combined with wmctrl provides the solution. Adjust the parameter to ’sleep’ as required.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    #!/bin/bash
     
    numberOfDesktops=`wmctrl -d | wc -l`
     
    for (( ; ; ))
    do
            for (( i = 0; i < $numberOfDesktops; i++ ))
            do
                    wmctrl -s $i
                    sleep 10s
            done
    done

    wmctrl -d lists the desktops managed by the window manager (each on a new line). We count the number of lines to get the number of desktops.

  3. Change window properties:
    The -b switch can be used to change a window’s properties. The command below launches a terminal and activates the fullscreen mode (which is not the same as maximizing the window).

    gnome-terminal && wmctrl -r :ACTIVE: -b toggle,fullscreen

    The -r switch is used to select a target window for an action. It accepts, by default, a window name. :ACTIVE: is a special window name string which implies the currently active window. The -b switch is used to add, remove or toggle upto two window properties simultaneously. We are toggling the fullscreen property (which will also get the window out of fullscreen if it is already in that mode).

    I tested the above command with gnome-terminal, nautilus and gthumb. It did not work with gthumb. However, gthumb has a -f switch for the purpose.

    In the command above, I have discounted the possibility of the window becoming inactive before wmctrl had a chance. This can be dealt with by identifying the window in a more specific way.

    gnome-terminal && wmctrl -r "abhijeet@ApplicationServer" -b toggle,fullscreen

    will look for a window with “abhijeet@ApplicationServer” as part of the title. The -F switch can be used for an exact match (exact title and case sensitive).

    If you want to create a launcher to start programs manipulated as above, put this line in the command box:

    bash -c "gnome-terminal && wmctrl -r :ACTIVE: -b toggle,fullscreen"