Tuesday, October 4, 2011

Rearrangine extjs windows in cascade [ as we do in ..for example..windows7]

Click the image to view demo

Download files from here: windowRearrange.js  and  windowRearrange.html

Air: getting current user name

well , for this you can use following technique:
1)File path to user directory [in windows user director name = user name]
2) parse the path to get user name [last string has user name ie: c:\..\..\username]


 var userFolder:String = File.userDirectory.nativePath;
 var userName:String = userFolder.substr(userFolder.lastIndexOf(File.separator) + 1);

Extjs: Chaning tip text: acessing thumb value while dragging

  1. initComponent: function () {
  2.         this.tipText = function(thumb){
  3.             return Ext.String.format(thumb.value+" is the current thumb value");
  4.         };
  5.         this.callParent();
  6.     }

Saturday, October 1, 2011

Extjs error: "me.events is undefined" when you fire event to an object

>> make sure that you ahve done addEvents("yourEvent")  for your object

Extjs error: while setting tree/rendering tree nodes error: record undefined

while setting tree/rendering tree nodes error: record undefined
>>Make sure objects you used as tree nodes do not have duplicate id,

"me.events is undefined" when you file event to an object
>> make sure that you ahve done addEvents("yourEvent")  for your object

Monday, September 19, 2011

Flex AdvancedDatagrid, changing renderers

You can change columerenderer and the grouping colume renderer as following:
<components:CustomDataGrid variableRowHeight="true" folderClosedIcon="{null}" folderOpenIcon="{null}" groupItemRenderer="MyGroupingItemRenderer"  groupRowHeight="100">
            <mx:GroupingCollection id="gc" source="{someArray/arrayCollection}" >
                        <mx:GroupingField id="groupingField" name="groupField" compareFunction="{MyCompareFunction()}" descending="true"/>
        <components:columns >
            <mx:AdvancedDataGridColumn   itemRenderer="MyColumeRnnderer" />
    public class MyGroupingItemRenderer extends AdvancedDataGridGroupItemRenderer {

Thursday, September 15, 2011

PHP and SQLITE [executing sqlite query using PDO]

public function execute($query) {
         $base= new PDO('sqlite:'.$dbname.'');
         $preparedStatement = $base->prepare($query);
            while($tmp = $preparedStatement->fetch(PDO::FETCH_ASSOC)) {
                $array[$i] = $tmp;
            return $array;

Latest Deadline first

  • among tasks without successors select the task with the latest deadline
  • remove this task from the precedence graph and put it into a stack
  • repeat until all tasks are in the stack
  • the stack represents the order in which tasks should be scheduled

Wednesday, September 14, 2011

Adobe Air: Problem while reading „ and “

Solution: use UTF-32 encoding
var fs:FileStream = new FileStream();
var string:String = fs.readMultiByte(fs.bytesAvailable, "UTF-32");

Sunday, September 11, 2011

Air: change / specify runtime location of air application [way to run air application in machine with out runtime installation]

Only way is to use adl.exe while running your applicaiton. With normal installer you cannot do so. So idea is to 1)use a bat file to manually specify your applicaiton.xml location and adobe run time location.
2) If you do'nt like console then  wire a program for you own that does what bat file does but with out console visible. I have written such program in c++. If you need it just leave a comment .

reading a file in C [reading line]

#include <stdio.h>
int main ()
  FILE * pFile;
  char lines[2][200];
  int i=0;
  int j=0;
  int c;
  int n = 0;
   //clear file
  for(int i=0;i<2;i++) {
      for(int j=0;j<200;j++) {
              lines[i][j] = '\0';
  pFile=fopen ("name.txt","r");
  if (pFile==NULL) perror ("Error opening file");
    do {
      c = fgetc (pFile);
      if (c == '$') n++;
        if(c== '\n') {
              printf("new line begins\n");
       lines[i][j] = c;
        printf ("%c",lines[i][j]);
    } while (c != EOF);
    fclose (pFile);
   printf("line1 %s \n",lines[0]);
   printf("line2 %s \n",lines[1]);
  return 0;

Saturday, September 10, 2011

Extjs tree filter [filtering tree items in extjs 4 ]

Download  source code from here:  treeDemp.html, treeDemo1.js  [Note: you will need extjs 4]
Click the image to see demo
The main idea is for each keyup in the text box i do following:

  1. tree.getRootNode().cascadeBy(function() { // descends into child nodes
  2.    if(!(this.data.qtip.indexOf(txt.getValue())>-1)) {//Now do the actual filtering
  3.         console.log("remove");
  4.         removeArray[i] = this;//cannot call this.remove() here as cascadeBy() tends to traverse all the nodes and if node is removed it gives error
  5.         i++;
  6.    }
  8. });
  9. for(var j=0;j<i;j++) {
  10.         removeArray[j].remove();//do actual removing, but unforunately once //removed,,there is not a easy way to add back to same location so , here i //simply regenrate whole tree again at line 53 : setnode(tree)
  11. }
Detail code given below:

  1. Ext.application({
  2.     name: 'treeFilterDemo',
  3.     appFolder: 'app',
  4.     requires: [  'Ext.form.Panel','Ext.container.Viewport',
  5.                  'Ext.tab.Panel','Ext.tree.Panel','Ext.data.TreeStore','Ext.layout.container.Border'
  6.              ],
  7.      setnode:function(tree){
  8.                 var node = {text:'', qtip:'',expanded:true, leaf:false, children:[]};
  10.                 var node1_1 = {text:'apple_1', qtip:'apple_1',expanded:true, leaf:true, children:[]};
  11.                 var node1_2 = {text:'apple_2', qtip:'apple_2',expanded:true, leaf:true, children:[]};
  12.                 var node1 = {text:'apple', qtip:'apple,apple_1,apple_2',expanded:true, leaf:false, children:[node1_1,node1_2]};
  13.                 var node2_1 = {text:'apricoat_1', qtip:'apricoat_1',expanded:true, leaf:true, children:[]};
  14.                 var node2_2 = {text:'apricoat_2', qtip:'apricoat_2',expanded:true, leaf:true, children:[]};
  15.                 var node2 = {text:'apricoat', qtip:'apricoat,apricoat_1,apricoat_2',expanded:true, leaf:false, children:[node2_1,node2_2]};
  16.                 node.children = [node1,node2];
  17.                 tree.setRootNode(node);
  18.         },
  19.     launch: function() {
  20.                 var setNodeFn = this.setnode;
  21.                 var tree =  Ext.create('Ext.tree.Panel', {
  22.                 myRootNodes:[],
  23.                 region:'center',
  24.                 hideHeaders: true,
  25.                 rootVisible: false,
  26.                 expandedNodes:[],
  27.                  viewConfig: {
  28.                     plugins: {
  29.                         ptype: 'treeviewdragdrop',
  30.                         appendOnly: true
  31.                     }
  32.                 },
  33.                 height: 350,
  34.                 width: 400,
  35.                 });
  36.                 var textField = {xtype:'textfield',
  37.                 prompt:'serach',
  38.                 name: 'name',
  39.                 region:'north',
  40.                 value:'Type filter text',
  41.                 enableKeyEvents:true,
  42.                 listeners:{
  43.                     focus:{fn:function (view, record, item, index, even) {
  44.                    this.setValue("");
  46.                     }},
  47.                     keyup:{
  48.                                 fn:function(view, record, item, index, even){
  49.                                 var txt= this;
  50.                                 setNodeFn(tree);
  51.                                 var removeArray = [];
  52.                                 var i=0;
  53.                                                         tree.getRootNode().cascadeBy(function() { // descends into child nodes
  54.                                                            if(!(this.data.qtip.indexOf(txt.getValue())>-1)) {//Now do the actual filtering
  55.                                                                 console.log("remove");
  56.                                                                 removeArray[i] = this;//cannot call this.remove() here as cascadeBy() tens to traverse all the nodes and if node is removed it gives error
  57.                                                                 i++;
  58.                                                            }
  60.                                                         });
  61.                                                         for(var j=0;j<i;j++) {
  62.                                                                 removeArray[j].remove();//do actual removing, but unforunately once removed,,there is not a easy way to add back to same location so , here i simply regenrate whole tree again at line 53 : setnode(tree)
  64.                                                         }
  65.                         }
  66.                     }
  68.                  }
  69.                };
  70.                 this.setnode(tree);
  71.         Ext.create('Ext.container.Viewport', {
  72.             items: [
  73. textField,tree
  74.             ]
  75.         });
  76.     }
  77. });

Friday, September 9, 2011

Solution for the problem with: drag drop not accepted in HBox in Flex

private function dragEnterHandler(event:DragEvent):void {
   if (event.dragSource.hasFormat("some format"))
     DragManager.acceptDragDrop(event.currentTarget as UIComponent);


private function dragDropHandler(event:DragEvent):void {
<mx:HBox id="v1" width="100%"  height="100%" label="dd" dragDrop="dragDropHandler(event);" dragEnter="dragEnterHandler(event);">
Here drop is not accepted by Hbox
solution: Just set the background of the container like: backgroundColor="#ffffff"
<mx:HBox id="v1" width="100%" backgroundColor="#ffffff" height="100%" label="dd" dragDrop="dragDropHandler(event);" dragEnter="dragEnterHandler(event);">

Handeling text overflow in Flex Alert

//your code//
var a:Alert = Alert.show("..long..text....");
private function handelOverFlow(alert:Alert,maxHeight:int):void {
   var array:Array = alert.getChildren();
   var uiCom:UIComponent = array[0];
   var txtField:UITextField = uiCom.getChildAt(0) as UITextField;
   var box:Box = new Box();
   //if AlertForm (uiCom) has more height then desired height
   if(uiCom.height>maxHeight) {
     uiCom.height = maxHeight;
     box.width = uiCom.width;
     box.height = maxHeight - 50;

problem while generating web application in web ratio

I had problem in generating web application from web ratio. I would like to share the solution i found,, because other may also face same problem
After viewing the description , Problem seems to be to fact that, i had my tomcat directory in my “Program File” and web ration was in some other directory and my Operating system [windows 7] denied the write to that folder.
[my webratio did'nt had tomcat installation in it, because i denies installation of tomcat as i already had one]
In the project outline view, select the project
In the project property view, you will find the “output path”
Change this path to some other location
[Once deployed , you can just copy the deployed folder to tomcat "webapp" folder manually and restart the tomcat]

work arround for: “ArgumentError: Error #2082: Connect failed because the object is already connected” in Flex, Air

This error can occur for three reasons:
1) The string value passed to the connection Name parameter was null.
Pass a non-null value.
2) The value passed to the connection Name parameter contained a colon
(:). Colons are used as special characters to separate the superdomain
from the connectionName string in the send() method, not the
3) The LocalConnection instance is already connected.
Following solution is for 3)
idea: For every exception thrown for reconnect create a nw connection.

/*while initializing the connection call connect() method,, and use variable "connectionName" while invoking methods as: localConnection.send(_connectionName,"methodName");*/
private var _connectionName:String = “swf2AIR”;
private function connect():void {
   try {
   catch(e:*) {
      _connectionName = _connectionName+”1″;;

Red5 hello world [Java - flex communication] implementation

Requirement for gives example are: red5 server [i used : red5-0.9.1], Eclipse [example contains eclipse projects]
Note: before running example, unzip it and view read me
Download example here

EXTJS Error : strange error in border.js

make sure you imported 'Ext.layout.container.Border'

EXTJS Error : me.dockedItems is undefined:

one main reason is that, in your init function you did not called "callParent()".
"callParent()" should be called usually at the end of your init function

adobe air :: File handling

  • The static properties included in File class :
File.applicationStorageDirectory  A unique storage directory unique for each installed AIR application
File.applicationDirectory  Directory where the application is installed and it is read only
File.desktopDirectory  Desktop directory of the User
File.documentsDirectory  Documents directory of the user
File.userDirectory  User Directory
  • saving file:
  1. var bytearray:ByteArray = new ByteArray();
  2. var fileToCopy:File = new File("url of file");
  3. var newFile:File = new File("url of file to be created");
  4. var fileStream:FileStream = new FileStream();
  5. fileStream.open(file,FileMode.READ);
  6. fileStream.readBytes(bytearray);//getting bytes
  7. var newFileStream :FileStream = new FileStream()
  8. newFileStream.openAsync( newFile, FileMode.WRITE );
  9. newFileStream.writeBytes(bytearray);//filling bytes
  10. newFileStream.close();
  • Updating file
public function update(value:String,url:String,startIndex:int = 0):void
   var file:File = new File(url);
   var fs:FileStream = new FileStream();
   fs.position = startIndex;
  • Getting current directory in air:
  1. NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvokeEvent);
  2. public function onInvokeEvent(invocation:InvokeEvent):void {
  3.         var currentDir:File = invocation.currentDirectory;
  4. }

  • File systems's tutorial:

Thursday, September 8, 2011

Amf (open amf) hello world [Flex - java communication] implementation

This example demonstrate the flex – java communication using open amf
1) openamf [i used openamf-1.0RC12]
2) eclipse [i used 3.4 (example contains eclipse project)]
3) tomcat server [i used 6.0]
Download example project amf helloworld.zip
Unzip the project, and view read me. There are 2 projects inside, one client and one server project.To run just import them in you eclipse and run it.

Minimal cut set and Fault tree analysis

Fault tree: Fault tree diagrams represent the logical relationship between sub-system and component failures and how they combine to cause system failures. The TOP event of a fault tree represents a system event of interest and is connected by logical gates to component failures known as basic events.

Figure is a fault tree: a tree where A,B,C,D,E,F are sets of fault events that can cause software to fail.
Here, minimal events for software to fail is {A,C},{B,C}.... These {A,C},{B,C} are the minimal cut set [a minimal set of events to cause failure, whose further sub set do not cause failure]

Conclusion: We should always strive to make minimal cut set as big as possible. In above figure  the desirable minimal cut set would be {A,B,C,D,E,F}
Why? :
Say was have minimal cut sets : {A,C},{B,C},{A,C},{A,E},{A,F}
So, Probability to fail = P{A,C}+P{B,C}+P{A,C}+P{A,F}
When mininal cut set is{A,B,C,D,E,F}
Probability to fail = P{A,B,C,D,E,F}
                          = P(A)*P(B)*P(C)*P(D)*P(E)*P(F)

Therefor, P(A)*P(B)*P(C)*P(D)*P(E)*P(F) < P(A)*P(B)+P(B)*P(C)+P(A)*P(C)+P(A)*P(F)

DWR hello world example implementation : sending – reciving objects

  • Put dwr.jar in your Project's lib.
  • Put the Commons Logging Jar in your Projects's lib. ( Dwr uses Apache Commons Logging )
  • Add the configuration settings in your web.xml for the DWR Servlet.
  • Add the debugging parameters for the DWR Servlet during the development phase.
  • Add the dwr.xml under WEB-INF and configure it to expose your Java Classes.
  • Add the converters in dwr.xml to ensure the conversion of Java POJOs to JavaScript Objects & vice versa.
  • Include the reference to all the JavaScript libraries required in your JSPs.

Download example here
It’s an eclipse project, you can just download and import the project and run

Strategy Pattern Implementation – java

[image source: http://wikipedia.org]
Get implementation here : strategy_pattern.zip   [It's an eclipse java project]

stateful example in extjs [saving tree selection in extjs]

First read this:  http://dev.sencha.com/deploy/ext-4.0.2a/docs/#/api/Ext.state.Stateful-cfg-stateful
Following example demonstrate simple way to save a selected item in tree:


           this.tree = Ext.create(‘Ext.tree.Panel’, {
    viewConfig: {
        plugins: {
            ptype: ‘treeviewdragdrop’,
            appendOnly: true
    height: 350,
    width: 400,
    stateEvents: ['saveSelectedItem'],
    rootVisible: false,
    mySelectedItem:”,//my own added Variable
    getState : function () {
        /*this is place where we state what things are to be saved*/
        /*we return thing to be save in format key:value*/
        return {
            mySelectedItem: this.mySelectedItem
    applyState : function (state) {
        /*this is place where we recover the saved state*/
        console.log(“Previosuly selected “+state.mySelectedItem);
       itemclick:{fn:function (view, record, item, index, even) {
            console.log(“saving item:”+record.data.text);
            this.mySelectedItem =  record.data.text;