Apache Click on Google App Engine – Hello World Example

Posted by admin | Posted in Cloud Computing, General Programming | Posted on 19-02-2010

1

Hello World!
If this blog would run on App Engine and was build with Apache Click I could finish this tutorial right here :) .
But more seriously, I will describe short step by step tutorial on how to get started with Apache Click on Google App Engine.
I’m assuming that you have GAE plugin for eclipse installed already as well as the latest libraries for Apache Click downloaded somewhere on your machine. (If not look at my previous post on how to get started with Apache Click on Eclipse Galileo (here).

If all is set up, lets get started..


1. Add new GAE type ‘Web Application Project’ (the one with blue google icon)

2. Copy click-2.1.0.jar and click-extras-2.1.0.jar to the lib directory under war/WEB-INF/lib of your GAE project.

3. Click on the project and select ‘Properties’ when you will modify the ‘Java Build Path’.

When changing the build path, select the two libraries you have added to you lib folder in point 2.

4. Delete the auto-generated GAE project stuff, like servlet and index.html files.
5. Create new class called ‘Index’

package com.softwarepassion.clickgae;

import java.util.Date;
import org.apache.click.Page;

public class Index extends Page{
   
    private Date time = new Date();

    public Index() {
        addModel("time", time);
    }

}



Note the package you choose for you newly created class file, it will be needed when modifying config files later.

6. Create click.xml file in the same location where your web.xml file exists.
7. Modify your web.xml file to look similar to the one presented below:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <listener>
         <listener-class>org.apache.click.extras.gae.GoogleAppEngineListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>ClickServlet</servlet-name>
    <servlet-class>org.apache.click.ClickServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>ClickServlet</servlet-name>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.htm</welcome-file>
  </welcome-file-list>
</web-app>

It looks like ordinary web.xml file with one important addition: the listener section.

8. Add content to your click.xml file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<click-app charset="UTF-8">
  <pages>
    <page path="index.htm" classname="com.softwarepassion.clickgae.Index"></page>
  </pages>
  <mode value="development"/>
</click-app>

9. Add index.htm file to the war directory

<html>
  <body>

    <h2>Hello World</h2>

    Hello world from Click at $time

  </body>
</html>

10. Deploy your app to Google App Engine and go to the url: http://yourappname.appspot.com

You should see very simple website with current time printed.

Getting started with Apache Click and Eclipse Galileo

Posted by admin | Posted in Code Snippets, General Programming, Tools | Posted on 18-02-2010

3

Last couple of days I read here and there about Apache Click, which is now in version 2.1.0. It looks preety cool and easy to learn, so I decided to give it a try and see for myself.
I understand that its cool to learn things using vi and shell only, but when you tried many frameworks before, you know how things works, you just want to see how or how not, productive you can be with the new framework, thats why I jump straight to the IDE.
And here, first surprise, with apache click its’ not that easy, well, I’m mean its still easy but I have encountered a few problems, and right now I would like to share the solution.
First of all, I did not tried all the examples in the apache click user guide yet, haven’t build anything usefull and definietly I’m not an Apache Click expert, I think I have figured out how to plug it to Eclipse and I think this is good start :) .


Here you have a few points to build your Apache Click IDE:
1. First of all download latest and greatest Eclipse Galileo from here – choose Eclipse for Java EE developers
2. Download Apache Click libraries from here – choose version 2.1.0
3. Download Apache Click IDE from here – note that it contains Click version 1.5 and it was last updated in November 2008 – maybe I’m missing something here?
4. Unzip your ClickIDE and copy the ‘features’ and ‘plugins’ folders into your Eclipse home directory
5. Unzip your latest click libraries and keep it for later :)
6. Start your Eclipse IDE and create new ‘Dynamic Web Project’

Choose target name, in this case ‘ClickDemo2′, select your target runtime as Tomcat 6+ etc.
7. Under configuration combo box, select custom and click ‘Modify’

8. Select ‘Click’ in Project Facet List and save the configuration as click config

9. Once you have your configuration created, dynamic web project screen should look like in the following screenshot:

10. The rest of the settings you can leave as it is, just click ‘Next’ up to the point when you finish creating new dynamic web project.
11. After your project is created it will have the structure like in the following screen:



Notice that there are click libraries from version 1.5, which is no good, we want to use the latest version which is 2.1.0.
12. Copy the files ‘click-2.1.0.jar’ and ‘click-extras-2.1.0.jar’ into the same lib folder where the old libraries are found.
13. Delete old libraries and refresh the project tree under eclipse (right click on the project node and select ‘Refresh’), now you will see the new libraries come up in the lib folder.
14. Open your web.xml file under ‘WebContent/WEB-INF/’ folder and change the class name of the main Click Servlet, from ‘net.sf.click.ClickServlet’ to ‘org.apache.click.ClickServlet’ in ’servlet-class’ declaration.
15. With Eclipse, select the project node and click ‘New’ -> ‘Other’, choose ‘Click Page’ under ‘click’ directory.

16. Fill out the necessary fields for your new click page as below:

17. Name the file ‘index.htm’ and click ‘Finish’
18. Under the page java source file, fix the Page class by using the page from the: org.apache.click.Page instead of the old path.

package com.softwarepassion;

import java.util.Date;

import org.apache.click.Page;


public class Index extends Page {
   
    private Date time = new Date();
   
    public Index(){
        addModel("time", time);
    }

}

Modify your ‘index.htm’ using html editor to look something like this:

<html>
  <head>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=UTF-8">
    <title>Blank</title>
    $imports
  </head>
  <body>
  $time
  </body>
</html>

19. Start up your project in tomcat. The page should display current time!


Additional Comments:
I know that this is just a quickfix, and I just cannot belive that there is no proper eclipse plugin using the latest click framework, which would be up to date, if you know any, than please comment and save me and my readers precious time.

Thank you.

Jasperberry – the most dynamic reports ever.

Posted by admin | Posted in Code Snippets, General Programming, Tools | Posted on 17-02-2010

8

Today I will describe in short my latest and simplest quick and dirty trick, generating jasper report dynamically. Jasperberry is a component written very quickly to help me
generate pdf report in a situation where I don’t know the number of columns I will have, I don’t know their widths, the data they contain etc, all is generated at runtime dynamically.
I know that there is DynamicJasper project but it seems to be dead, and its dead in a very strange way, I mean, I see that the authors commit new code but there is no chance to get any support unless, I guess, you pay for it.
With dynamic jasper I couldn’t generate report with polish fonts displayed properly, tried many different tricks, no support on the forum, no support on stack overflow, no nothing. After 2 days I have realized that I will write my own library quicker to solve my problem than get an answer from the dynamic jasper community (if there is any).
So here we have: jasperberry!


Don’t expect too much from it but if you want to display simple table with data, dynamic columns, adjustable fonts and colors than this is it.

In fact you don’t have to even know object properties to generate the report, we will use Apache DynaBeans for that:

This is a simple example code snipped showing you how to get started with the simplest and most dynamic reporting library ever (as well as lacking features probably but we hope its enough for simple projects)

This example assumes the following:

1. You want simple report
2. You dont have to know the object which properties you want to display in advance, by this I mean you can create report columns dynamically, and by using apache dyna beans your objects don’t have to even exists. You just dynamically create them and inject them into the report.

Here is an example test class showing you how to use jasperberry, for more info please contact us directly at softberries.com
Code:

public class JRXMLBuilderTest {

    private static List<JBColumnBean> columns;

    public JRXMLBuilderTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
        columns = new ArrayList<JBColumnBean>();
        JBColumnBean col1 = new JBColumnBean();
        JBColumnBean col2 = new JBColumnBean();
        JBColumnBean col3 = new JBColumnBean();
        JBColumnBean col4 = new JBColumnBean();
        JBColumnBean col5 = new JBColumnBean();
        JBColumnBean col6 = new JBColumnBean();
        JBColumnBean col7 = new JBColumnBean();
        col1.setPreferredWidth(60);
        col1.setProperty("name");
        col1.setTitle("ImiÄ™");
        col2.setPreferredWidth(60);
        col2.setProperty("surname");
        col2.setTitle("Nazwisko");
        col3.setPreferredWidth(160);
        col3.setProperty("comment");
        col3.setTitle("Komentarz");
        col4.setPreferredWidth(100);
        col4.setProperty("comment2");
        col4.setTitle("Komentarz");
        col5.setPreferredWidth(100);
        col5.setProperty("comment3");
        col5.setTitle("Komentarz");
        col6.setPreferredWidth(100);
        col6.setProperty("comment4");
        col6.setTitle("Komentarz");
        col7.setPreferredWidth(100);
        col7.setProperty("comment5");
        col7.setTitle("Komentarz");
        columns.add(col1);
        columns.add(col2);
        columns.add(col3);
        columns.add(col4);
        columns.add(col5);
        columns.add(col6);
        columns.add(col7);
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    /** * Test of build method, of class JRXMLBuilder. */
    @Test
    public void testBuild() {
        try {
            System.out.println("build");
            List<JBReportElement> elements = new ArrayList<JBReportElement>();
            //col header font
            JBFont colHeaderFont = new JBFont();
            colHeaderFont.setBold(true);
            colHeaderFont.setSize(10);
            colHeaderFont.setForegroundColor("#555555");
            //detail font
            JBFont detailFont = new JBFont();
            detailFont.setSize(6);
            detailFont.setForegroundColor("#000000");
            detailFont.setPdfEncoding("Cp1257");
            JBPage page = new JBPage();
            JBReport report = new JBReport(page, colHeaderFont, detailFont, "#CCCCFF", "#DEDEDE", "#FFFFFF");
            JBFont titleFont = new JBFont();
            titleFont.setBold(true);
            titleFont.setSize(20);
            titleFont.setForegroundColor("#FF0000");
            titleFont.setPdfEncoding("Cp1257");
            //add title elements
            elements.add(new JBStaticTextElement("Hello World!", 450, 10, 300, titleFont));
            elements.add(new JBImageElement("C:\\\\Documents and Settings\\\\admin\\\\Moje dokumenty\\\\NetBeansProjects\\\\JASPER_BERRY\\\\test.jpg", 0, 0, 350, 242));
            report.setTitleElements(elements);
            JRXMLBuilder instance = new JRXMLBuilder(columns, report);
            boolean expResult = true;
            boolean result = instance.build();
            JasperReport jr = JasperCompileManager.compileReport("jasperberry_by_softberries.jrxml");
            //PREPARE SOME DATA
            DynaProperty[] props = new DynaProperty[columns.size()];
            for (int i = 0; i < columns.size(); i++) {
                props[i] = new DynaProperty(columns.get(i).getProperty(), String.class);
            }
            BasicDynaClass dynaClass = new BasicDynaClass("tester", null, props);
            List<DynaBean> beans = new ArrayList<DynaBean>();
            for (int i = 0; i < 100; i++) {
                DynaBean db = dynaClass.newInstance();
                db.set("name", "Krzysztof " + i);
                db.set("surname", "Grajek " + i);
                db.set("comment", "Komentarz ");
                db.set("comment2", "Komentarz ");
                db.set("comment3", "Komentarz ");
                db.set("comment4", "Komentarz ");
                //
                db.set("comment5", "Komentarz ");
                beans.add(db);
            }
            JasperPrint jp = JasperFillManager.fillReport(jr, null, new JRBeanCollectionDataSource(beans));
            JasperExportManager.exportReportToPdfFile(jp, "jasperberry.pdf");
            assertEquals(expResult, result);
        } catch (Exception ex) {
            Logger.getLogger(JRXMLBuilderTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

You should find similar snippet in a test suite of the project.
The project itself is licensed under LGPL and its available from sourceforge here

Deploy your Java Application with IzPack Installer

Posted by admin | Posted in Code Snippets, General Programming | Posted on 06-02-2010

9

This is a short tutorial on how to create simple IzPack based installation solution on windows platform with all standard features like: desktop shortcut, start menu item shortcut, copying libraries, folders, documentation into one of the ProgramFiles folder on the windows machine.
I had some problems creating windows shortcuts mysefl and I wanted to share the experience so other people can find it quicker.
Here you go.


1. First download and install IzPack itself from: izpack website

2. Prepare the application you want to make installable, I use Netbeans to build most of my Java apps, but I guess for all other ide’s the results after all are the same, we end up with SomeApp.jar file and a bunch of libraries we used to build it.
On the Netbeans platform all the files needed to launch the application we have build end up in ‘dist’ folder as a subfolder of our project main folder. If you have used any libraries to build your desktop application they will be included in the lib folder (yourproject/dist/lib/).

3. Now, once we have all the main ingredients (our application and installer) we need to connect it together. Create the folder anywhere on your machine, and call it for example ’softwarepassion’.

4. Put your jar file together with the ‘lib’ folder into the ’softwarepassion’ catalog.

5. Now we need to add some native libraries for Izpack to be able to add windows shortcuts on the desktop and start menu. Create ‘bin’ folder under the ’softwarepassion’ folder and copy whole ‘native’ content found in your izpack installation into the ‘bin’ folder of your root ’softwarepassion’ catalog.
You can find the native folder inside your IzPack installation directory, normally under: ‘C:\Program Files\IzPack\bin’

6. Create your application icon file and add it to your ’softwarepasison’ catalog. I call mine ‘exe.ico’.

7. Now comes the hardest part to get initially but after you build your first installer it all gets clear and easy :)
We need to prepare two separate xml files: one called ‘install.xml’ and another one called ’shortcutSpec.xml’.

The content of both example files is listed below:

<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>

<!--
   A sample installation file.
   Use it as a base for your own installers :-)
   
   To compile it :
   - go in the bin directory where you installed IzPack
   - call "compile ../sample/install.xml -b ../sample"
-->

<installation version="1.0">

    <!--
       The info section.
       The meaning of the tags should be natural ...
   -->
    <info>
        <appname>SoftwarePassion Application</appname>
        <appversion>1.0</appversion>
        <authors>
            <author name="Softberries Krzysztof Grajek" email="customer.service@softberries.com"/>
        </authors>
        <url>http://www.softwarepassion.com/</url>
    </info>

    <!--
       The gui preferences indication.
       Sets the installer window to 640x480. It will not be able to change the size.
   -->
    <guiprefs width="640" height="480" resizable="yes"/>
    <variables>
        <variable name="DesktopShortcutCheckboxEnabled" value="true"/>
    </variables>
    <!--
       The locale section.
       Asks here to include the English and French langpacks.
   -->
    <locale>
        <langpack iso3="pol"/>
        <langpack iso3="eng"/>
    </locale>

    <!--
       The resources section.
       The ids must be these ones if you want to use the LicencePanel and/or the InfoPanel.
   -->
    <resources>
        <res src="shortcutSpec.xml" id="shortcutSpec.xml"/>
        <res id="LicencePanel.licence" src="Licence.txt"/>
        <res id="InfoPanel.info" src="Readme.txt"/>
    </resources>

    <!--
       The panels section.
       We indicate here which panels we want to use. The order will be respected.
   -->
    <panels>
        <panel classname="HelloPanel"/>
        <panel classname="LicencePanel"/>
        <panel classname="TargetPanel"/>
        <panel classname="PacksPanel"/>
        <panel classname="InstallPanel"/>
        <panel classname="ShortcutPanel"/>
        <panel classname="FinishPanel"/>
    </panels>

    <!--
       The packs section.
       We specify here our packs.
   -->
    <packs>
        <pack name="Base" required="yes">
            <description>The base files</description>
            <file src="Readme.txt" targetdir="$INSTALL_PATH"/>
            <file src="Licence.txt" targetdir="$INSTALL_PATH"/>
            <file src="exe.ico" targetdir="$INSTALL_PATH"/>
            <file src="SoftwarePassionHelloIzPack.jar" targetdir="$INSTALL_PATH"/>
            <fileset dir="lib" targetdir="$INSTALL_PATH\lib">
                <include name="**"/>
            </fileset>
        </pack>
    </packs>
    <native type="izpack" name="ShellLink.dll"/>
    <native type="3rdparty" name="COIOSHelper.dll" stage="both">
        <os family="windows"/>
    </native>
</installation>

And the one for windows shortcuts:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<shortcuts>

    <skipIfNotSupported/>

    <programGroup defaultName="Siemens AWORT" location="applications"/>

      <shortcut
        name="SoftwarePassion Application"
        programGroup="yes"
        desktop="yes"
        applications="no"
        startMenu="yes"
        startup="no"
        target="$INSTALL_PATH\SoftwarePassionHelloIzPack.jar"
        commandLine=""
        description="Software Passion Example App"
        iconFile="$INSTALL_PATH\exe.ico"
        iconIndex="0"
        initialState="noShow">

         <createForPack name="Base"/>

       </shortcut>
 

    <shortcut
           name="Software Passion Example App Uninstaller"
           programGroup="yes"
           desktop="no"
           applications="no"
           startMenu="no"
           startup="no"
           target="$INSTALL_PATH\Uninstaller\uninstaller.jar"
           commandLine=""
           iconFile="%SystemRoot%\system32\SHELL32.dll"
           iconIndex="31"
           description="Uninstall SoftwarePassion Example">

        <createForPack name="Base"/>
    </shortcut>

</shortcuts>

8. Example installation script contains both Readme.txt and Licence.txt which you can add to your ’softwarepassion’ folder.
9. Once you have it all in one place, you should have a structure like in the following screenshot:

izpack_directory

10. Now assuming that your ’softwarepassion’ folder has been placed directly on the c: drive, execute the following command:

C:\Program Files\IzPack\bin>compile c:\softwarepassion\install.xml -b c:\softwarepassion

Assuming that IzPack itself was installed at: C:\Program Files\IzPack

This will produce install.jar file which is your installer.

11. If you dont’ want your end users to click on the ‘jar’ file as not everybody knows they can do that, you can add Izpack launcher app which will launch it automatically, or use another tool to create an executable called launch4j

You have to admit that it was an easy one!!!!!

Happy Installing!


Download example files from here

Add ‘count #’ column to JTable

Posted by admin | Posted in Code Snippets, General Programming, Graphics And Design, Learning Materials | Posted on 05-02-2010

0

Important note first: This is mostly not my code, I was strugling with this problem for some time, I couldn’t google it at all, and one day, I’ve just found it. Now I use it in one of my projects but I cannot find the original post again, therefore I have decided to post it on my blog (slightly modified version of the original) so other people with similar problem will have a better chance of finding the solution.
So, the idea is very simple. The whole point of displaying additional column which is kind of independent from the other columns is to simply use another table. This way you can sort one table by column and the number column will not sort with it. – thats exactly what I was looking for and I guess its kind of popular problem.
Becouse you put two tables in one scroll pane the gui looks like its just one column!


I have created one simple method to apply this technique to any tables in my application (I use JXTable actually but JTable will do as well)

private void addLPColumn(JXTable table, JScrollPane scp){
        JTable rowTable = new RowNumberTable(table);
        scp.setRowHeaderView(rowTable);
        scp.setCorner(JScrollPane.UPPER_LEFT_CORNER, rowTable.getTableHeader());
        scp.repaint();
    }


RowNumberTable is simple one column table displaying the ‘count’ number of rows in the second table.


public class RowNumberTable extends JTable
    implements ChangeListener, PropertyChangeListener
{
    private JTable main;

    public RowNumberTable(JTable table)
    {
        main = table;
        main.addPropertyChangeListener( this );

        setFocusable( false );
        setAutoCreateColumnsFromModel( false );
        setModel( main.getModel() );
        setSelectionModel( main.getSelectionModel() );

        TableColumn column = new TableColumn();
        column.setHeaderValue("Lp.");
        addColumn( column );
        column.setCellRenderer(new RowNumberRenderer());

        getColumnModel().getColumn(0).setPreferredWidth(40);
        setPreferredScrollableViewportSize(getPreferredSize());
    }

    @Override
    public void addNotify()
    {
        super.addNotify();

        Component c = getParent();

        //  Keep scrolling of the row table in sync with the main table.

        if (c instanceof JViewport)
        {
            JViewport viewport = (JViewport)c;
            viewport.addChangeListener( this );
        }
    }

    /*
     *  Delegate method to main table
     */

    @Override
    public int getRowCount()
    {
            if(main != null)
                return main.getRowCount();
            else
                return 0;
    }

    @Override
    public int getRowHeight(int row)
    {
        return main.getRowHeight(row);
    }

    /*
     *  This table does not use any data from the main TableModel,
     *  so just return a value based on the row parameter.
     */

    @Override
    public Object getValueAt(int row, int column)
    {
        return Integer.toString(row + 1);
    }

    /*
     *  Don't edit data in the main TableModel by mistake
     */

    @Override
    public boolean isCellEditable(int row, int column)
    {
        return false;
    }
//
//  Implement the ChangeListener
//
    public void stateChanged(ChangeEvent e)
    {
        //  Keep the scrolling of the row table in sync with main table

        JViewport viewport = (JViewport) e.getSource();
        JScrollPane scrollPane = (JScrollPane)viewport.getParent();
        scrollPane.getVerticalScrollBar().setValue(viewport.getViewPosition().y);
    }
//
//  Implement the PropertyChangeListener
//
    public void propertyChange(PropertyChangeEvent e)
    {
        //  Keep the row table in sync with the main table

        if ("selectionModel".equals(e.getPropertyName()))
        {
            setSelectionModel( main.getSelectionModel() );
        }

        if ("model".equals(e.getPropertyName()))
        {
            setModel( main.getModel() );
        }
    }

    /*
     *  Borrow the renderer from JDK1.4.2 table header
     */

    private static class RowNumberRenderer extends DefaultTableCellRenderer
    {
        public RowNumberRenderer()
        {
            setHorizontalAlignment(JLabel.CENTER);
        }

        public Component getTableCellRendererComponent(
            JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
        {
            if (table != null)
            {
                JTableHeader header = table.getTableHeader();

                if (header != null)
                {
                    setForeground(header.getForeground());
                    setBackground(header.getBackground());
                    setFont(header.getFont());
                }
            }

            if (isSelected)
            {
                setFont( getFont().deriveFont(Font.BOLD) );
            }

            setText((value == null) ? "" : value.toString());
            setBorder(UIManager.getBorder("TableHeader.cellBorder"));

            return this;
        }
    }
}

count_jtable_column

In my case the ‘count’ column is called ‘Lp.’ – in polish



I have created one simple method to apply this technique to any tables in my application (I use JXTable actually but JTable will do as well)

private void addLPColumn(JXTable table, JScrollPane scp){
        JTable rowTable = new RowNumberTable(table);
        scp.setRowHeaderView(rowTable);
        scp.setCorner(JScrollPane.UPPER_LEFT_CORNER, rowTable.getTableHeader());
        scp.repaint();
    }


JXTable and primary key – how to.

Posted by admin | Posted in General Programming | Posted on 07-12-2009

0

swinglabs
Today I will describe in a few words and a couple lines of code how to get the id of the row in JXTable. When working with data coming from database we don’t really want to display the primary key of the object but to hide it. This can cause a small problem once we want to find out for example which item was clicked, ok we can easily find out which row it was but its not always easy to find out which actual object it was especially when using JXTable sorting capabilities.
The whole trick is to get the the corresponding object from the model and not from the view.
Here is a short code snippet to do just that, hope that helps everyone who uses great JXTable component to display some data.

private int getObjectID(JXTable table) {
        int rowx = table.getSelectedRow();
        int resultx = 0;
        if (rowx < 0) {
            return 0;
        }
        resultx = table.convertRowIndexToModel(rowx);
        int id = (Integer) table.getModel().getValueAt(resultx, 0);
        return id;
    }

This works of course assuming that your object index is set as first column in your model (position 0).

Setting up Android development platform on Ubuntu Linux 9.04

Posted by admin | Posted in General Programming, System Administration | Posted on 12-05-2009

20

In this post I will go step by step through the setup of your development box for Android and all its goodness. I start with fresh install of the newest and shinest Ubuntu platform 9.04, which by the way on the first look is just great. I’m a happy owner of G1 for a few months and this is the best phone I ever had so why not start writing some software on it!

Step One.

Before installing anything please run the following command (actually 2 commands)

sudo apt-get update && sudo apt-get upgrade

Install Java! You develop on android or not Java is a must on all my machines :)

$ sudo apt-get install sun-java6-jdk

You can now check your java installation by issuing two commands:

$ java -version
$ javac -version

You should be able to see output stating that you have java 6 installed, huuraaayy!

Step Two.

Download and install Android SDK
You can download the latest android SDK from the android development website (developer.android.com), the link to the latest version is here
After your download completes, unzip the file to the directory of your choice. I copy the whole folder into my home directory but the doesn’t really matter.
Open up your favourite text editor (VIM of course) and add the following line at the very bottom of the .bashrc file:

export PATH=${PATH}:/home/kris/android-sdk-linux_x86-1.5_r1/tools

Stepp Three

Download and Install Eclipse

I wish I could go for the easy one here and download the version using apt-get but unfortunately not as the version in repos is 3.2 and ADT plugin requires version 3.3 or higher. You have to download the eclipse for www.eclipse.org and unpack it. Once unpacked its ready to use!

Step Four

Download and install Eclipse plugin
This is instruction from the developer.android.com with one small modification, instead of https use http:

1. Start Eclipse, then select Help > Software Updates….
2. In the dialog that appears, click the Available Software tab.
3. Click Add Site…
4. Enter the Location:

http://dl-ssl.google.com/android/eclipse/

If you have trouble aqcuiring the plugin, try using “http” in the Location URL, instead of “https” (https is preferred for security reasons).

Click OK.
5. Back in the Available Software view, you should see the plugin listed by the URL, with “Developer Tools” nested within it. Select the checkbox next to Developer Tools and click Install…
6. On the subsequent Install window, “Android DDMS” and “Android Development Tools” should both be checked. Click Next.
7. Read and accept the license agreement, then click Finish.
8. Restart Eclipse.

After executing all the steps above you are ready for Android development. The last step in this tutorial is to run example android projects on your linux dev machine.
If you encounter an error saying :

An error occurred during provisioning.
Cannot connect to keystore.
JKS

Please check your java version. If its set to 1.5 than please run the following command:

sudo update-java-alternatives -s java-6-sun

Once you finish installing required plugins, restart your eclipse and go to Window->Preferences->Android and set up a path to your android SDK

Step Five

Check your configuration

If all went fine you can try to develop Hello World application in android. You can find the instruction on the android development site:
http://developer.android.com/guide/tutorials/hello-world.html

More android tutorials to come!
Enjoy!

Affirma S3 library for C#

Posted by admin | Posted in Cloud Computing, General Programming, Tools | Posted on 06-04-2009

0

Finally I have found S3 library that works in C#. The library was written by Joel Wetzel from Affirma Consulting and I just wanted to spread the word about it.
Once downloaded you are presented with the whole C# Visual Studio solution which contains the library project as well as some example on how to use it.
There is even a simple wrapper written which greatly simplyfies the use of the affirma’s library.
As an example:
1. Create wrapper object (constructor listed)

public ThreeSharpWrapper(String awsAccessKeyId, String awsSecretAccessKey)
        {
            this.config = new ThreeSharpConfig();
            this.config.AwsAccessKeyID = awsAccessKeyId;
            this.config.AwsSecretAccessKey = awsSecretAccessKey;

            this.service = new ThreeSharpQuery(this.config);
        }

and then use it having the following methods:

/// Adds a bucket to an S3 account
public void AddBucket(String bucketName);

 /// Returns a string of XML, describing the contents of a bucket
public String ListBucket(String bucketName);

/// Adds a string to a bucket, as an object
public void AddStringObject(String bucketName, String keyName, String data);

/// Streams a file to a bucket as an object
public void AddFileObject(String bucketName, String keyName, String localfile);

/// Streams a file to a bucket as an object, with encryption
public void AddEncryptFileObject(String bucketName, String keyName, String localfile, String encryptionKey, String encryptionIV);

/// Gets a string object from a bucket, and returns it as a String
public String GetStringObject(String bucketName, String keyName);

/// Gets a file object from a bucket, and streams it to disk
public void GetFileObject(String bucketName, String keyName, String localfile);

/// Gets a file object from a bucket, streaming it to disk, with decryption
public void GetDecryptFileObject(String bucketName, String keyName, String localfile, String encryptionKey, String encryptionIV);

/// Copies an object from a source location to a destination location
public void CopyObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey);

/// Generates a URL to access an S3 object in a bucket
public String GetUrl(String bucketName, String keyName);

/// Deletes an object from a bucket
public void DeleteObject(String bucketName, String keyName);

/// Deletes a bucket from an S3 account
public void DeleteBucket(String bucketName);

/// Changes the request payer value for the specified bucket
public String PaymentChange(String bucketName, PaymentChangeRequest.Payer payer);

/// Gets the request payer value for the specified bucket
public String PaymentGet(String bucketName);

The library is dead easy to use and most importantly it works (comparing to other S3 libraries I’ve found). Great work Joel!
You can download the solution zip from here or directly from the codeplex hosting the project here

Do we really need stackoverflow?

Posted by admin | Posted in General Programming | Posted on 05-05-2008

0

Uhhh, ohhh, have you seen or rather heard about stackoverflow.com? If not, you are probably just a medicore programmer and don’t follow the newest stuff happening on the net! (just kidding). For those who never heard, stackoverflow.com is a new web site, kind of a forum which doesn’t exist yet, but will be created (no one knows when but sometime in the future). The site is an idea of Joel Spolsky and Jeff Atwood. If at least one of those names ring the bell in your head, well, maybe you are not that bad programmer after all :) . Personally, I have never heard about Jeff but after I googled his blog I have to admit, I see this blog quite often. Talking about Joel, well, he is kind of my guru, I read his blog regularly and got his book even, but the whole stackoverflow.com idea for me, is exactly what it says, it is just a kind of internet overflow, another forum on the net. The only positive thing I can think of, is just a great promotion this site has. I like the guys but are they serious? Are they going to create another programming forum?
The site doesn’t exist yet (just a welcome page so far) but you can listen to their podcasts to get an ‘understanding’ of the whole idea. I have heard all three podcasts so far, beside the fact, that they don’t work on my shuffle ipod, I can only say this is nothing new or innovative.
I was thinking about it and I think, I know why they do this! If you know Joel a bit and you hear Jeff or read his blog, you will quickly understand that they technology of choice is .NET, one might argue that no, no Joel thinks about Mono, has his own ‘wasabi’ staff but hey, everyone has to concentrate on something on the daily basis and their choice is .Net, correct me if I’m wrong.
If you have ever programmed in more ‘open’ languages like Java or straight C/C++ you know what is the real power of the language – COMMUNITY. I do program a bit in C# for a year now and I really like it but when you look for a solution to the problem you either find something very old or have to stick to MSDN, there is no community, it feels like if you are on your own, and that makes me do everything to not to program in .Net.
Perfect example Sun Java Forum, I grow up on this forum, in my opinion is the best programming forum ever created with its duke dollars and vivid community.
Do you think they can do something better that that, well I hope to be surprised but to be frank, I don’t think so, I think it is just a crazy (although successfull) FogCreek products promotion.
Am I wrong? What do you think?

You can listen to the podcast and read comments at: http://blog.stackoverflow.com/

Crocodile Reader Project Started

Posted by admin | Posted in General Programming | Posted on 01-04-2008

0

My first C# open source project has been officially started. The project is named Crocodile and was created to read my feeds while on the tube (If you live in London like me or any other city with underground trains you know the pain). I belive that the whole RSS/Atom idea is great and allows me to gather everything, what I want to read on the net, in one place, but some things were annoying me and that’s why I come up with the Crocodile. First of all I couldn’t find any feed reader to download the feeds for me in a way I want them to be downloaded (more on that in a sec), secondly my favourite feed from DZone includes the link not to the web page I want to actually read but to DZone web page with small description (same as in the feed) and a thumbnail/link to the original, submitted web page. Dzone (www.dzone.com) feeds annoyed me so much that this was one of the main reasons I have started the whole Crocodile idea. So what the Crocodile is? Its very simple and small app using browser component found in .Net to see the pages associaged with the feed. The idea is to download the whole pages together with css, js etc and save them for offline browsing. So far the project is still in alpha but it works to the degree making the app usable. Nothing special in that so far but the best idea is the feature called ‘Cleaners’ and ‘Filters’. Cleaners (works so far only for DZone and is completly hardcoded) convert the link found in the feed to the original page submitted to dzone website – if you use DZone you know what I mean) and displays the original web sites instead of full of adverts DZone pages. Second idea called ‘Filters’ not implemented yet at all, would parse all feed items descriptions and display only the feeds filtered with keywords previously entered by the user.
For anyone interested please visit the project web site: http://crocodile.sourceforge.net.

Short tutorial for all offline DZone fans:

  1. Install the Crocodile app found at http://crocodile.sourceforge.net
  2. Run .msi installer and keep pressing next (nothing special here)
  3. When you run Crocodile, click on the small cross green button to add new subscription
  4. Enter ‘dzone’ in the subscription name and ‘http://feeds.dzone.com/dzone/frontpage?format=xml’ as the url address
  5. Confirm by clicking ‘Ok’
  6. In your subscriptions panel click ‘dzone’ and wait for your feed items to be populated.
  7. Clicking on each item would display the page associated with the feed item
  8. Click orange up arrow button to ‘Clean’. This will convert all links found in the feed to links pointing to original web sites submitted to Dzone
  9. Now you are ready to browse the original pages submitted to Dzone by clicking on each feed item found in the list.
  10. You can download the pages for offline browsing (pages are saved as .mht archives).
  11. Minimizing Crocodile puts it in the system tray where it updates the feeds periodically.


Full applicaton screenshot is available from sourceforge.

Please be aware that this software has just been born and is quite messy (sometimes crashes, sometimes behaves strangely) I just wanted to share the dzone feature as quickly as I have made it and it works for me. If you want to share your time on Crocodile development please contact me either through this blog or sourcefoge web site any help would be appreciated. The Crocodile sources are available from svn repo.