Header Ad

Monday, September 22, 2014

GWT Popup Example

 The following code is a example for GWT custom Popup.


import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.RootPanel;
public class MainPanel extends EntryPoint
{
    public MainPanel()
    {
       
    }

    @Override
    public void onModuleLoad()
    {
            Button b1 = new Button("Click Me!!!");
            b1.addClickHandler(new ClickHandler() {
              public void onClick(ClickEvent event) {
                // Instantiate the popup and show it.
                  SamplePopup popup = new SamplePopup();
                    popup.setGlassEnabled(true);
                    popup.center();
                    popup.show();
              }
            });

            RootPanel.get().add(b1);
    }

}

The above MailPanel which extends GWT EntryPoint, basically to provide a view to load GWT components. A buttob "b1" with label "Click me to show popup"
will be added to the view. A onclick handler is added to the button "b1", where this will show the popup with a view of SamplePopup.

The samplePopup will be as shown below.

<ui:UiBinder
  xmlns:ui='urn:ui:com.google.gwt.uibinder'
  xmlns:g='urn:import:com.google.gwt.user.client.ui'>

  <g:HTMLPanel>
    <div>A popup with this data will be shown.</div>

   </g:HTMLPanel>

</ui:UiBinder>

 
   

A popup with this data will be shown.


  



SamplePopui.java

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.IFrameElement;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;

public class SamplePopup extends PopupPanel {
   
    @UiTemplate("SamplePopup.ui.xml")
    interface Binder extends UiBinder { }
   
   
    @UiField
    Frame flexPopupContainer;
   
    private static final Binder binder = GWT.create(Binder.class);
   
    public SamplePopup() {
        super(true);
        add(binder.createAndBindUi(this));
       
    }
}

Monday, May 5, 2014

How to apply filterFunction to Array Collection in Adobe Flex or Action Script ?

The following is an example that will show you how to apply a fiterFunction to array collection in action script.

var idsList:ArrayCollection=new ArrayCollection(["1","2","3"]);
var nodeId:Number = 2;

var filterByIdFilter:Function = function(item:Number):Boolean
{
    if(item == nodeId) return true;
    return false;
}
idsList.filterFunction = filterByIdFilter;
idsList.refresh();


If the provided nodeId matches with idsList array collection, after applying filterFunction the idsList will be truncated to size "1", otherwise size "0".

Scaling an image to match the content width

To scale an image, so that it should fit 100% of content width. The following is the sample code.



In the above scaleContent, width and maintainAspectRatio are important, we need to define them in order scale the image to 100% width of cotent width.

Tuesday, July 9, 2013

Sorting numeric data having comma seperated values in Adobe Flex?

The following example which is having numeric data with comma(s) for one of the grid column. We need to handle specially in order to sort
this datagrid column where the data is having comma values.

We will use sortCompare function for the datagrid column which is having comma seperated numeric values. This sortCompare function will have
the code for removing comma's from numeric data and performs the sort functionality.

The following sample example with complete implementation.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
        <mx:XMLList id="testdata">
        <testdata> <name>a</name> <testvalue>1,20,000.00</testvalue> </testdata>
        <testdata> <name>aa</name> <testvalue>1,100.00</testvalue> </testdata>
        <testdata> <name>ab</name> <testvalue>1,20,300.00</testvalue> </testdata>
        <testdata> <name>b</name> <testvalue>2</testvalue> </testdata>
        <testdata> <name>ba</name> <testvalue>21.00</testvalue> </testdata>
        <testdata> <name>bb</name> <testvalue>22</testvalue> </testdata>
        <testdata> <name>c</name> <testvalue>3.00</testvalue> </testdata>
        <testdata> <name>d</name> <testvalue>4</testvalue> </testdata>
        <testdata> <name>e</name> <testvalue>5</testvalue> </testdata>
        <testdata> <name>f</name> <testvalue>6</testvalue> </testdata>
        <testdata> <name>g</name> <testvalue>7</testvalue> </testdata>
    </mx:XMLList>
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.collections.Sort;
            import mx.collections.SortField;
            import mx.events.FlexEvent;
            private function sortNumeric(obj1:Object, obj2:Object):int {
                var regExpr:RegExp = /,/g;
                var value1:String = obj1.testvalue;
                var value2:String = obj2.testvalue;
                value1 = value1.replace(regExpr,"");
                value2 = value2.replace(regExpr,"");
           
                if (Number(value1) < Number(value2)) {
                    return -1;
                } else if (Number(value1) > Number(value2)) {
                    return 1;
                } else {
                    return 0;
                }
            }
           
           
           
        ]]>
    </mx:Script>
    <mx:DataGrid x="10" y="10" dataProvider="{testdata}" id="dgTest" width="400" height="300">
        <mx:columns>
            <mx:DataGridColumn headerText="Text" dataField="name" />
            <mx:DataGridColumn headerText="Number as Text" dataField="testvalue" />
            <mx:DataGridColumn headerText="Number as Number" dataField="testvalue" sortCompareFunction="sortNumeric" />
        </mx:columns>
    </mx:DataGrid>
   

</mx:Application>

Windows Commands

Accessibility Controls = access.cpl
Accessibility Wizard = accwiz
Add Hardware Wizard = hdwwiz.cpl
Add/Remove Programs = appwiz.cpl
Administrative Tools = control admintools
Adobe Acrobat ( if installed ) = acrobat
Adobe Distiller ( if installed ) = acrodist
Adobe ImageReady ( if installed ) = imageready
Adobe Photoshop ( if installed ) = photoshop
Automatic Updates = wuaucpl.cpl
Basic Media Player = mplay32
Bluetooth Transfer Wizard = fsquirt

Calculator = calc
Ccleaner ( if installed ) = ccleaner
C: Drive = c:
Certificate Manager = cdrtmgr.msc
Character Map = charmap
Check Disk Utility = chkdsk
Clipboard Viewer = clipbrd
Command Prompt = cmd
Command Prompt = command
Component Services = dcomcnfg
Computer Management = compmgmt.msc
Compare Files = comp
Control Panel = control
Create a shared folder Wizard = shrpubw

Date and Time Properties = timedate.cpl
DDE Shares = ddeshare
Device Manager = devmgmt.msc
Direct X Control Panel ( if installed ) = directx.cpl
Direct X Troubleshooter = dxdiag
Disk Cleanup Utility = cleanmgr
Disk Defragment = dfrg.msc
Disk Partition Manager = diskmgmt.msc
Display Properties = control desktop
Display Properties = desk.cpl
Display Properties (w/Appearance Tab Preselected ) = control color
Dr. Watson System Troubleshooting Utility = drwtsn32
Driver Verifier Utility = verifier

Ethereal ( if installed ) = ethereal
Event Viewer = eventvwr.msc
Files and Settings Transfer Tool = migwiz
File Signature Verification Tool = sigverif
Findfast = findfast.cpl
Firefox = firefox
Folders Properties = control folders
Fonts = fonts
Fonts Folder = fonts
Free Cell Card Game = freecell

Game Controllers = joy.cpl
Group Policy Editor ( xp pro ) = gpedit.msc
Hearts Card Game = mshearts
Help and Support = helpctr
Hyperterminal = hypertrm
Hotline Client = hotlineclient

Iexpress Wizard = iexpress
Indexing Service = ciadv.msc
Internet Connection Wizard = icwonn1
Internet Properties = inetcpl.cpl
Internet Setup Wizard = inetwiz
IP Configuration (Display Connection Configuration) = ipconfig /all
IP Configuration (Display DNS Cache Contents) = ipconfig /displaydns
IP Configuration (Delete DNS Cache Contents) = ipconfig /flushdns
IP Configuration (Release All Connections) = ipconfig /release
IP Configuration (Renew All Connections) = ipconfig /renew
IP Configuration (Refreshes DHCP & Re-Registers DNS) = ipconfig /registerdns
IP Configuration (Display DHCP Class ID) = ipconfig /showclassid
IP Configuration (Modifies DHCP Class ID) = ipconfig /setclassid

Java Control Panel ( if installed ) = jpicpl32.cpl
Java Control Panel ( if installed ) = javaws
Keyboard Properties = control keyboard

Local Security Settings = secpol.msc
Local Users and Groups = lusrmgr.msc
Logs You Out of Windows = logoff

Malicious Software Removal Tool = mrt
Microsoft Access ( if installed ) = access.cpl
Microsoft Chat = winchat
Microsoft Excel ( if installed ) = excel
Microsoft Diskpart = diskpart
Microsoft Frontpage ( if installed ) = frontpg
Microsoft Movie Maker = moviemk
Microsoft Management Console = mmc
Microsoft Narrator = narrator
Microsoft Paint = mspaint
Microsoft Powerpoint = powerpnt
Microsoft Word ( if installed ) = winword
Microsoft Syncronization Tool = mobsync
Minesweeper Game = winmine
Mouse Properties = control mouse
Mouse Properties = main.cpl
MS-Dos Editor = edit
MS-Dos FTP = ftp

Nero ( if installed ) = nero
Netmeeting = conf
Network Connections = control netconnections
Network Connections = ncpa.cpl
Network Setup Wizard = netsetup.cpl
Notepad = notepad
Nview Desktop Manager ( if installed ) = nvtuicpl.cpl

Object Packager = packager
ODBC Data Source Administrator = odbccp32
ODBC Data Source Administrator = odbccp32.cpl
On Screen Keyboard = osk
Opens AC3 Filter ( if installed ) = ac3filter.cpl
Outlook Express = msimn

Paint = pbrush
Password Properties = password.cpl
Performance Monitor = perfmon.msc
Performance Monitor = perfmon
Phone and Modem Options = telephon.cpl
Phone Dialer = dialer
Pinball Game = pinball
Power Configuration = powercfg.cpl
Printers and Faxes = control printers
Printers Folder = printers
Private Characters Editor = eudcedit

Quicktime ( if installed ) = quicktime.cpl
Quicktime Player ( if installed ) = quicktimeplayer

Real Player ( if installed ) = realplay
Regional Settings = intl.cpl
Registry Editor = regedit
Registry Editor = regedit32
Remote Access Phonebook = rasphone
Remote Desktop = mstsc
Removable Storage = ntmsmgr.msc
Removable Storage Operator Requests = ntmsoprq.msc
Resultant Set of Policy ( xp pro ) = rsop.msc

Scanners and Cameras = sticpl.cpl
Scheduled Tasks = control schedtasks
Security Center = wscui.cpl
Services = services.msc
Shared Folders = fsmgmt.msc
Sharing Session = rtcshare
Shuts Down Windows = shutdown
Sounds Recorder = sndrec32
Sounds and Audio = mmsys.cpl
Spider Solitare Card Game = spider
SQL Client Configuration = clicongf
System Configuration Editor = sysedit
System Configuration Utility = msconfig
System File Checker Utility ( Scan Immediately ) = sfc /scannow
System File Checker Utility ( Scan Once At Next Boot ) = sfc /scanonce
System File Checker Utility ( Scan On Every Boot ) = sfc /scanboot
System File Checker Utility ( Return to Default Settings) = sfc /revert
System File Checker Utility ( Purge File Cache ) = sfc /purgecache
System File Checker Utility ( Set Cache Size to Size x ) = sfc /cachesize=x
System Information = msinfo32
System Properties = sysdm.cpl

Task Manager = taskmgr
TCP Tester = tcptest
Telnet Client = telnet
Tweak UI ( if installed ) = tweakui
User Account Management = nusrmgr.cpl
Utility Manager = utilman

Volume Serial Number for C: = label
Volume Control = sndvol32
Windows Address Book = wab
Windows Address Book Import Utility = wabmig
Windows Backup Utility ( if installed ) = ntbackup
Windows Explorer = explorer
Windows Firewall = firewall.cpl
Windows Installer Details = msiexec
Windows Magnifier = magnify

Windows Management Infrastructure = wmimgmt.msc
Windows Media Player = wmplayer
Windows Messenger = msnsgs
Windows Picture Import Wizard (Need camera connected) = wiaacmgr
Windows System Security Tool = syskey
Windows Script host settings = wscript
Widnows Update Launches = wupdmgr
Windows Version ( shows your windows version ) = winver
Windows XP Tour Wizard = tourstart
Wordpad = write
Zoom Utility = igfxzoom

If you found this list of Run Commands useful, please Like and Share to Everyone.!

Tuesday, May 22, 2012

GWT ListBox with auto-select or pre select option.

The following is the sample example for auto selecting a one of the value in GWT List Box.

List lstValues = new ArrayList();
lstValues.add("Value 1");
lstValues.add("Value 2");
lstValues.add("Value 3");
lstValues.add("Value 4");


ListBox lstBox = new ListBox();
for(int i=0;i<lstValues.size();i++)
{
lstBox.addItem(lstValues.get(i));
}

Suppose, if we want to auto-select the GWT List Box with "Value 2", we can do this by the following code

lstBox.setSelectedIndex(1);

This will automatically, select the "Value 2" option of the ListBox.

Saturday, April 14, 2012

SQL Joins

The following diagram will provide simple view of SQL Joins.


Wednesday, April 11, 2012

GWT ScrollPanel Example


The ScrollPanel is a div-based widget that lets you add scroll bars to the panel.

The following is the sample code do declare a GWT ScrollPanel and display in the RootPanel.


String data = "Scroll panel will display the below data. Scroll panel will display the below data.
 Scroll panel will display the below data.
Scroll panel will display the below data.  Scroll panel will display the below data.
";
ScrollPanel scrollPanel = new ScrollPanel(new HTML(data));
scrollPanel.setSize("200px", "120px");
RootPanel.get("sample-demo").add(scrollPanel);

In the above code, we have set the ScrollPanel size as "200px" width and "120px" height.

Tuesday, April 10, 2012

Disabling RIGHTCLICK using JavaScript - How to disable right click using Java Script


Disabling RIGHTCLICK using JavaScript - How to disable right click using Java Script

Copy & Paste below code into <HEAD></HEAD> of your HTML.


<SCRIPT TYPE="text/javascript"> 
<!-- 

var message="Sorry, right-click has been disabled"; 

/////////////////////////////////// 
function clickIE() {
if (document.all) {
(message);
return false;
}
}

function clickNS(e) { 
if (document.layers||(document.getElementById&&!document.all)) { 
if (e.which==2||e.which==3) {
(message);
return false;
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS;
else{
document.onmouseup=clickNS;
document.oncontextmenu=clickIE;
document.oncontextmenu=new Function("return false") 
// --> 
</SCRIPT>

GWT DataGrid - DataGrid creation in GWT


The below will give the brief view of creating or loading a DataGrid in GWT page with data. The class "DataGridExample" has a "Employee" inner class to define the data for loading in "DataGrid".

The EMPLOYEES is the ArrayList having "Employee" class objects. An instance with name "dataGrid" has been created.Two text columns "First Name" and "Last Name" are created and added to the DataGrid.

Finally, you can see the below piece code in the "DataGridExample" class.
    dataGrid.setRowCount(EMPLOYEES.size(), true);
    dataGrid.setRowData(0, EMPLOYEES);

This will define to set the data to the dataGrid with row count.


/**
 * Entry point classes define onModuleLoad().
 */

public class DataGridExample implements EntryPoint {
  
// A simple data type that represents a contact.
  private static class Employee {
    private final String firstName;
    private final String lastName;

    public Employee(String firstName, String lastName) {
      this.firstName = firstName;
      this.lastName = lastName;
    }
  }

  // The list of data to display.
  private static List<Employee> EMPLOYEES = Arrays.asList(new Employee("John",
      "Smith"), new  Employee("Mary", "Lawyer"), new  Employee(
      "Zander", "Pod"));

  public void onModuleLoad() {

    // Create a CellTable.
    DataGrid<Employee> dataGrid = new DataGrid<Employee>();

    // Create firstName column.
    TextColumn<Employee> firstNameColumn = new TextColumn<Employee>() {
      @Override
      public String getValue(Employee employee) {
        return employee.firstName;
      }
    };

    // Make the name column sortable.
    firstName.setSortable(true);
    dataGrid.addColumn(firstName, "First Name");

    // Create lastName column.
    TextColumn<Employee> lastNameColumn = new TextColumn<Employee>() {
      @Override
      public String getValue(Employee employee) {
        return employee.lastName;
      }
    };
    dataGrid.addColumn(lastName, "Last Name");
    
    dataGrid.setRowCount(EMPLOYEES.size(), true);
    dataGrid.setRowData(0, EMPLOYEES);

   }

}

Wednesday, April 4, 2012

Flex Tree Control - how to set Tree control LABEL as CLICKABLE?

The following is sample code to make Tree Control Node label as clickable.

<mx:Script>
    <![CDATA[
        import mx.collections.ICollectionView;
        import mx.events.ListEvent;

        private function tree_itemClick(evt:ListEvent):void {
            var item:Object = Tree(evt.currentTarget).selectedItem;
            if (tree.dataDescriptor.isBranch(item)) {
                tree.expandItem(item, !tree.isItemOpen(item), true);
            }
        }

]]>
</mx:Script>

<mx:XML id="dp">
    <root>
        <folder label="Main Item">
            <folder label="Sub Item1">
                <item label="Sub Item11" />
                <item label="Sub Item21" />
                <item label="Sub Item31" />
                <item label="Sub Item41" />
                <item label="Sub Item51" />
            </folder>
            <item label="Sub Item2" />
            <item label="Sub Item3" />
        </folder>
    </root>
</mx:XML>

<mx:Tree id="tree" dataProvider="{dp}" showRoot="false"  labelField="@label" width="300" rowCount="6"
        itemClick="tree_itemClick(event);" />

In the above code, if we observe "itemClick" has been added to "tree" component. So, if we click on LABEL, itemClick event will be fired. This will call the "tree_itemClick" function, where it has the code to expand the node item.

How to read JSON data using Java


This article will help how to read JSON using java program. By using "JSON-lib" library we can read JSON data.

The following link will provide a detailed explanation about how to use "JSON-lib"

Thank you.

Tuesday, April 3, 2012

Introduction to JSON


JSON( Java Script Object Notation) is a lightweight data interchange format. It is easy to parse and generate. JSON format is completely language independent. But uses conventions that is easy for programmers.

JSON is built on two structures:
  • A collection of name/value pairs.
  • An ordered list of values. Like an array, List, or sequence.

The following sample JSON format. We can easily retrieve the values of below JSON by using keys.
{
      "id": 1,
      "name": "John",
      "designation": "SE"
}

The following is the sample example for LIST of values.

{
  "employees":
  [
    {
      "id": 1,
      "name": "John",
      "designation": "SE"
    },
    {
      "id": 2,
      "name": "Smith",
      "designation": "SE"
    }
  ]
}

Events & Observers in Magento


The following is the command used to get the list of events in magento installed version.

grep -rin -B2 -A2 "Mage::dispatchEvent" app/* > events.txt

In Magentov1.4, nearly 300 events compared to 223 in v1.3 and 140 in v1.2.

The following is the sample example for writing "events".

<events>
  <EVENT_TO_HOOK>
    <observers>
      <module>
        <type>singleton</type>
        <class>company_module_model_observer</class>
        <method>methodToCall</method>
      </module>
    </observers>
  </EVENT_TO_HOOK>  
</events>

Writing multiple observers for same event

We can write multiple observers for same event, like as follows.

    <observers>
      <shipmentsave>
        <type>singleton</type>
        <class>bshipment/observer</class>
        <method>salesOrderShipmentSaveBefore</method>
      </shipmentsave>
    </observers>

   <observers>
      <bshipmentsave>
        <type>singleton</type>
        <class>bshipment/observer</class>
        <method>salesOrderShipmentSaveBefore</method>
      </bshipmentsave>
    </observers>

If we observe in the above XML tags, we have "<shipmentsave>" and "<bshipmentsave>". Where we can write these tags in different modules respectively.

Monday, April 2, 2012

Inline styles in UiBinder of GWT

The following is the sample example for writing inline styles with in the UIBinder file of GWT.

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'>

  <ui:style>
    .setColor { background-color: Skyblue; }
  </ui:style>

  <div class='{style.setColor}'>
    Hello, <span ui:field='nameSpan'/>.
  </div>
</ui:UiBinder>

GWT CellTable - CellTable creation in GWT


The below is sample example for creating a CellTable in GWT.
/**
 * Entry point classes define onModuleLoad().
 */
public class CellTableExample implements EntryPoint {
  // A simple data type that represents a contact.
  private static class Employee {
    private final String firstName;
    private final String lastName;

    public Employee(String firstName, String lastName) {
      this.firstName = firstName;
      this.lastName = lastName;
    }
  }

  // The list of data to display.
  private static List<Employee> EMPLOYEES = Arrays.asList(new Employee("John",
      "Smith"), new Contact("Mary", "Lawyer"), new Contact(
      "Zander", "Pod"));

  public void onModuleLoad() {

    // Create a CellTable.
    CellTable<Employee> table = new CellTable<Employee>();

    // Create firstName column.
    TextColumn<Employee> firstNameColumn = new TextColumn<Employee>() {
      @Override
      public String getValue(Employee employee) {
        return employee.firstName;
      }
    };

    // Make the name column sortable.
    firstName.setSortable(true);
    table.addColumn(firstName, "First Name");

    // Create lastName column.
    TextColumn<Employee> lastNameColumn = new TextColumn<Employee>() {
      @Override
      public String getValue(Employee employee) {
        return employee.lastName;
      }
    };
    table.addColumn(lastName, "Last Name");
    
    table.setRowCount(EMPLOYEES.size(), true);
    table.setRowData(0, EMPLOYEES);

   }

}


 The above example, will create a CellTable with column headings "First Name" and "Last Name". The EMPLOYEES list data will be pulled into the above table.

More information about CellTable with sortable columns and other features can be find here.
https://developers.google.com/web-toolkit/doc/latest/DevGuideUiCellTable