Saturday, January 8, 2011

Change default behaivior of typeAhead in a Ext-Gwt Combobox

Recently I encountered with a incident where I had to filter the list of a Ext-Gwt combo box so that the list get fetched with the options which 'contains' the typed characters. Typeahead in Ext-Gwt combo box can be enabled by setting typeahead attribute true.
combo.setTypeAhead(boolean typeAhead);
But the default behaviour of the typeahead is to fetch the combo box list with the options which 'starting' with the typed characters. I had to get my brain troubled in searching the resources on the internet over few hours. but I couldn't find the solution.

Later, Hasith Yaggahavita; the team leader found the solution by going through the Gwt combo box source. What he had done was to extend the Gwt combo box component and to override the protected method onTypeAhead() to do nothing. Then he had written a custom StoreFilter with the logic to filter options which 'contains' the typed characters.

A sample code for the above implementation would be as follows

import com.gwtext.client.widgets.form.ComboBox
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.store.StoreFilter;

public class ContainsTypeAheadComboBox extends ComboBox {

    public ContainsTypeAheadComboBoxComponent() {
        setMinChars(1);
        setQueryDelay(300);
        setTriggerAction(TriggerAction.ALL);
    }

    public void setRpcProxy(RpcProxy> proxy) {
        ListLoader> loader = new BaseListLoader>(proxy);
        ListStore listStore = new ListStoreExt(loader);
        listStore.addFilter(new ContainsStoreFilter());
        setStore(listStore);
    }

    @Override
    protected void onTypeAhead() {
        //this method is overriden to avoid typeahead
        //feature selecting the first data item in to combo box text field
    }

    /**
     * The Class extending ListStore to ignore the 'beginsWith' behavior
     */
    class ListStoreExt extends ListStore {     

        public ListStoreExt(ListLoader> loader) {
            super(loader);
            this.filtersEnabled = true;
        }

        @Override
        public void filter(String property, String beginsWith)
        {
            // ignore the 'beginsWith' string since we filter for 'contains'
            super.filter(property);
        }
    }
  
    /**
     * The Class that filter according to 'contains' instead of 'beginswith'
     */
    class ContainsStoreFilter implements StoreFilter {

        public boolean select(Store store, ComboBox parent, ComboBox item, String property) {
            String v = getRawValue();
            if ( v == null || "".equals(v)) {
                return true;
            }
            if (item != null && item.getText() != null) {
                return item.getText().toLowerCase().indexOf(v.toLowerCase()) >= 0;
            }
            return false;
        }
    }
}

Reference Ext-Gwt combo box:
http://gwt-ext.com/docs/2.0.4/com/gwtext/client/widgets/form/ComboBox.html

What are the Symptoms of Swine Flu

As swine flu spreads fast throughout the country, it is important to know the symptoms of the disease so you can recognize it in yourself and others at an early stage. The following information is extracted from an email I got recently

Usually symptoms of swine flu have generally proved mild. However a small number of patients may develop more serious illness. Many of these people have other underlying health conditions, such as heart or lung disease, that put them at increased risk.

Typical symptoms are:

* A sudden fever - 100 degrees F or above
* A sudden cough

Other symptoms may include:

* Headaches
* Tiredness
* Chills
* Cough and sneezing
* Headache
* Weakness and fatigue
* Aching muscles and joints
* Sore throat
* Runny nose
* Diarrhea or stomach upset
* Loss of appetite

You must see a doctor immediately if:

* you have a serious existing illness that weakens your immune system, such as cancer
* you are pregnant
* you have a sick child under one
* your condition suddenly gets much worse
* your condition is still getting worse after seven days (five for a child)

High-risk groups
For most people, swine flu is a mild illness. Some people get better by staying in bed, drinking plenty of water and taking over-the-counter flu medication.

However, some groups of people are more at risk of serious illness if they catch swine flu, and will need to start taking antiviral medication as it is confirmed that they have it.

It is already known that you are particularly at risk if you have:

* chronic (long-term) lung disease,
* chronic heart disease,
* chronic kidney disease,
* chronic liver disease,
* chronic neurological disease (neurological disorders include motor neurone disease, multiple sclerosis and Parkinson's disease),
* immunosuppressant (whether caused by disease or treatment) or
* Diabetes mellitus.

Also at risk are:

* patients who have had drug treatment for asthma within the past three years,
* pregnant women,
* people aged 65 and older, and
* Young children under five.


It is vital that people in these higher-risk groups who catch swine flu get antiviral and start taking them as soon as possible.

As with any sort of influenza, how bad and how long the symptoms last will depend on treatment and the patient's individual circumstances.

Most cases reported in India have been relatively mild, with those affected starting to recover within a week. Persons with swine flu infection should be considered potentially contagious for up to 7 days following illness onset. Persons who continue to be ill longer than 7 days after illness onset should be considered potentially contagious until symptoms have resolved. Children, especially younger children, might potentially be contagious for longer periods.

Saturday, January 16, 2010

30 second Speech by Bryan Dyson (CEO of Coca Cola)

VERY SHORT, MOST EFFECTIVE AND HOW TRUE...

30 second Speech by Bryan Dyson (CEO of Coca Cola)

"Imagine life as a game in which you are juggling some five balls in the air. You name them - Work, Family, Health, Friends and Spirit and you're keeping all of these in the Air.

You will soon understand that work is a rubber ball. If you drop it, it will bounce back.

But the other four Balls - Family, Health, Friends and Spirit - are made of glass. If you drop one of these; they will be irrevocably scuffed, marked, nicked, damaged or even shattered. They will never be the same. You must understand that and strive for it."

WORK EFFICIENTLY DURING OFFICE HOURS AND LEAVE ON TIME. GIVE THE REQUIRED TIME TO YOUR FAMILY, FRIENDS & HAVE PROPER REST.

Monday, November 23, 2009

The Sixth Sence Comming Up!!

WoW.. This is amazing. Must watch

Believe it or not! Here comes the Chrome OS !!

Windows "Magics" and Explenations

Last week, one of my colleague has forwarded some bugs to the company tech talk. Sometimes back, this email was circulating through the web uncovering some bug in Windows calling "Magics"

Here I post those magics and explanations for them.

MAGIC #1
An Indian found that nobody can create a FOLDER anywhere on the Computer
which can be named as "CON". This is something funny and inexplicable...
At Microsoft the whole Team, couldn't answer why this happened!
TRY IT NOW, IT WILL NOT CREATE A "CON" FOLDER

Explanation:
Not only folder named ‘con’. Following names also not possible.
NUL, COM1, COM2, COM3, LPT1, LPT2, LPT3,COM1 to COM9 and LPT1 to LPT9. ( these are systems variables)
But there is a way to create above named folders in windows.

Try these steps.
1) go to run dialog.
2) type cmd/command (command prompt gets opened)
3) go to root directory like C:\ or D:\ etc
4) type md\\.\\c:\\con ....(here is done)
5) check the folder on the respected drive.

This is because MS-DOS Device Driver Names Cannot be Used as File Names
http://support.microsoft.com/kb/74496/en-us

MAGIC #2
For those of you using Windows, do the following:
1.) Open an empty notepad file
2.) Type "Bush hid the facts" (without the quotes)
3.) Save it as whatever you want.
4.) Close it, and re-open it.
Noticed the weird bug? No one can explain!

Explanation:
This is a string parsing bug in the parser. Any string with letters 4-3-3-5 will cause this
http://en.wikipedia.org/wiki/Bush_hid_the_facts

MAGIC #3
Again this is something funny and can't be explained... At Microsoft the
whole Team, including Bill Gates, couldn't answer why this happened!
It was discovered by a Brazilian. Try it out yourself...
Open Microsoft Word and type
=rand (200, 99)
And then press ENTER
And see the magic.....!

Explanation:
This is a documented function in Word
http://support.microsoft.com/kb/212251

Monday, September 14, 2009

University of Moratuwa tops the Top 10 Schools in 2009 and all-time!

University of Moratuwa tops the global Top 10 Schools in 2009 by # of
Accepted Students, with 22 applications:

Sri Lanka - University of Moratuwa - 22
Brazil - University of Campinas / UNICAMP - 12
China - Graduate University of Chinese Academy of Sciences - 11
Romania - Polytechnic University Of Bucharest - 11
Poland - Gdansk University of Technology - 10
Austria - Vienna University of Technology - 9
India - Birla Institute of Technology and Science Pilani, Goa campus - 9
Sweden - Royal Institute of Technology - 9
India - Institute of Technology, Banaras Hindu University - 8
Singapore - National University of Singapore - 8


University of Moratuwa also tops the all time list: Top 10 Schools 2005
- 2009 by # of Accepted Students

Sri Lanka - University of Moratuwa - 79
Brazil - University of Campinas / UNICAMP - 37
Canada - University of Toronto - 34
Austria - Vienna University of Technology - 31
China - Graduate University of Chinese Academy of Sciences - 30
United States - University of Illinois at Urbana-Champaign - 28
Poland - Wroclaw University of Technology - 27
Hungary - Budapest University of Technology and Economics - 21
Canada - Carleton University - 21
Romania - Alexandru Ioan Cuza University of Iasi - 20

Congratulations - great feat indeed!