Header Ad

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