Thursday, August 9, 2012

ExtJS 4: Force POST request in forms


To force post request in form, you have to specify the following property in the proxy:

    actionMethods: {
        create : 'POST' ,
        read   : 'POST' ,
        update : 'POST' ,
        destroy: 'POST'
    }

If you want apply this to all your models/stores, you can create your own proxy:

Ext.define( "My.data.AjaxProxy",{
      extend: "Ext.data.proxy.Ajax" ,
      alias: "proxy.myAjaxProxy" ,
      actionMethods: "POST" ,
});

An using it in your model/store:

proxy: {
      type: "myAjaxProxy" ,
      ...
}

Tuesday, February 28, 2012

I would like to use a static member named 'name' in my class

I would like to use a static member named 'name' in my class :

app.js
Ext.define("MyClass", {
      statics: {
            myVar: "toto",
            name: "could not be found"
      }
});
Ext.onReady(function(){
      console.log("MyClass.myVar = ", MyClass.myVar);
      console.log("MyClass.name = ", MyClass.name);
});

output
MyClass.myVar = toto
MyClass.name = 

But this member is not set as you can see if you execute the previous code. "Ext.Base" has a method 'getName()' and I think this is the source of my problem.
The only workaround I have found for the moment is the following:

app.js
Ext.namespace('MyClass');
MyClass.myVar = "toto";
MyClass.name = "Could not be found";
Ext.onReady(function(){
      console.log("MyClass.myVar = ", MyClass.myVar);
      console.log("MyClass.name = ", MyClass.name);
});

Monday, February 13, 2012

Create a child component in a grid cell


This is a useful function that add an Ext component to a grid cell.
The function returns an HTML block and use a deferred function which add a Ext component to this div element.

/**
 * create a Ext component in a grid
 * @param
 *          - className {String}: the class name of the component to create
 *          - config (optional) {Object}: the configuration of the component to create
 */
addGridComponent: function(options){
      if (options.className){
            // create a unique ID
            var id = Ext.id();
            // create a function which the call will be defer
            Ext.defer(function(){
                  var config = {renderTo: id};
                  // add parameter options to render property
                  if (options.config){
                        Ext.apply(config, options.config);
                  }
                  Ext.create(options.className, config);
            }, 25);
            return (Ext.String.format('
', id));
      }
}


Monday, February 6, 2012

Kill a Windows process with Java


I would like to kill a process in Java for an application in Java 1.4. ; I don't want to (can't) add some custom libraries so I will use 'Runtime' class to execute a DOS command:
tasklist: allow me to recover all processes running.
taskkill: allow me to destroy a process by its ID.

This is a Java class which will use these both commands to do the job:

KillProcess.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


public class KillProcess {
      public static final int FIRST_COLUMN_LENGTH = 26;
      
      /**
      * pass all statements which must be found in the process description
      *     process definition columns are:
      *            - Image Name
      *            - PID
      *            - Session Name
      *            - Session#
      *            - Mem Usage
      *            - Status
      *            - User Name
      *            - CPU Time
      *            - Window Title
      * @param args {String[]}: statements which must be found in the process description
      * @throws IOException
      */
      public static void kill(String[] args) throws IOException{
            int processId = 0;
            // recover a file output from the DOS command 'tasklist'
            // which list all running processes
            Process process = Runtime.getRuntime().exec("tasklist /v");
            InputStream inputstream = process.getInputStream();
            InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
            BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
            String line;
            while ((line = bufferedreader.readLine()) != null) {
                  boolean blnFound = true;
                  // loop on all statements to verify if the line contains it
                  for (int i=0;ilength;i++){
                        if (line.indexOf(args[i])<0){
                              blnFound = false;
                        }
                  }
                  if (blnFound){
                        line = line.substring(FIRST_COLUMN_LENGTH);
                        while(line.charAt(0)==' '){
                              line=line.substring(1);
                        }
                        String strProcessId = line.substring(0, line.indexOf(' '));
                        processId = Integer.parseInt(strProcessId);
                  }
            }
            // verify the process has been found
            if (processId!=0){
                  // kill the process via 'taskkill'
                  Runtime.getRuntime().exec("taskkill /pid " + processId + " /f");
                  System.out.println("The process "+processId+" has been killed!");
            } else{
                  System.out.println("Process not found!");
            }
      }
      public static void main(String[] args) throws IOException{
            kill(args);
      }
}

This is an example of class use which will kill my IrfanView process ...

java KillProcess i_view32.exe IrfanView

Saturday, January 28, 2012

Easy Duplicate Finder


Easy Duplicate Finder is a tool to suppress duplicate files on your hard drive. It's available for free at the following URL:
/!\ Be careful to uncheck 'Ask toolbar' added in the install wizard (if you don't like additional toolbar in your browser) !


Tuesday, January 3, 2012

ColorZilla génère vos fonds en dégradés

En plus d'une extension Firefox très utile, ColorZilla nous fournit un outlis pour générer le code CSS de vos fonds en dégradés !

http://www.colorzilla.com/gradient-editor/

L'option est diponible depuis l'extension Firefox : cliquez sur 'CSS Gradiant Generator...'.