0

Changing the date and time on all files within a folder structure

Source : http://www.bradleymedia.org/touch-subfolders/

This is easily achieved by combining the touch command with the Linux find command using the dash exec action like :-

find * -exec touch {} \;
 
 
A better approach is to use the touch command with the dash t switch and specify 
an actual date and time. The example below will set all files to being modified at
ten a.m. on the 29th of Feb 2012.
 
find * -exec touch -t 201202291000 {} \; 
0

GXT Grid Anchor Cell

In previous post, I wrote about my solution to render image & link in grid cell.
This is the generic class to handle it.

import java.util.HashSet;
import java.util.Set;

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sencha.gxt.core.client.ValueProvider;

public class AnchorLinkCell<T> extends AbstractCell<T> {

    String imgURL = "";
    String styleClass = "";
    AsyncCallback<T> callback;
    ValueProvider<T, String> vp;

    public AnchorLinkCell(String imgURL, ValueProvider<T, String> vp, String styleClass, AsyncCallback<T> callback) {
        this.imgURL = imgURL;
        this.callback = callback;
        this.styleClass = styleClass;
        this.vp = vp;
    }

    @Override
    public void render(com.google.gwt.cell.client.Cell.Context context, T value, SafeHtmlBuilder sb) {
        sb.appendHtmlConstant("<div class=\"" + this.styleClass + "\" style='cursor: pointer'/>");
        if (imgURL != "") {
            sb.appendHtmlConstant("<img src='" + imgURL + "' style='cursor: pointer'/> ");
        }
        sb.append(SafeHtmlUtils.fromTrustedString(this.vp.getValue(value)));
        sb.appendHtmlConstant("</div>");
    }

    @Override
    public Set<String> getConsumedEvents() {
        Set<String> events = new HashSet<String>();
        events.add("click");
        return events;
    }

    @Override
    public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context, Element parent, T value, NativeEvent event, ValueUpdater<T> valueUpdater) {
        // TODO Auto-generated method stub
        super.onBrowserEvent(context, parent, value, event, valueUpdater);
        if (parent.getFirstChildElement().isOrHasChild(Element.as(event.getEventTarget()))) {
            this.callback.onSuccess(value);
        }
    }
}


Steps :

1. Declare column config with bean parameters and set the value as the identity of the bean.
ColumnConfig<PremiseBean, PremiseBean> prm_companyColumn = new ColumnConfig<PremiseBean, PremiseBean>(props.identity(), 150,"Company Name");
        

2. This can be done by adding an identity value provider in the property access interface.
IdentityValueProvider<PremiseBean> identity();


3. Declare the AnchorLinkCell and set the column cell.
AnchorLinkCell<PremiseBean> acLink=new AnchorLinkCell<PremiseBeanHelper.PremiseBean>("images/icons/add.png",props.prm_name(), "myLinkStyleNameinCSS", new AsyncCallback<PremiseBean>() {

    @Override
    public void onFailure(Throwable caught) {
        Application.handleException(caught);                
    }

    @Override
    public void onSuccess(PremiseBean result) {
        Info.display("AnchorLinkCall Test", result.getPk());                                
    }
});

prm_companyColumn.setCell(acLink);

4. Do the rest steps for the grid


0

GXT3 Grid Cell with clickable Image and hyperlink

Reference:
  1. http://stackoverflow.com/questions/18951897/gwt-imagecell-change-image-dynamically-in-a-datagrid-or-celltable
  2. http://stackoverflow.com/questions/4691801/how-can-i-render-a-clickabletextcell-as-an-anchor-in-a-gwt-celltable
  3. http://www.gwtproject.org/doc/latest/DevGuideUiCustomCells.html#cell-onBrowserEvent
I want to make the cell table in a grid to show icon and link in a column.
I tried to use anchor but unsuccessful. The cell grid only render text & image but not the event.
I found a solution using ImageCell.
Steps :

1. Set columnconfig
2. Declare ImageCell object
3. override render subroutine
4. Override getConsumedEvents - to expose click event
5.Override onBrowserEvent to handle the event

In this example, it's only handle the first child element, so I just group the image & link in a div.


ColumnConfig<PremiseBean, String> prm_nameColumn = new ColumnConfig<PremiseBean, String>(props.prm_name(), 150, "Name");
        
ImageCell ic = new ImageCell() {

    @Override
    public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) {
        sb.appendHtmlConstant("<div class=\"myClickableCellTestStyle\" style='cursor: pointer'/>");
        sb.appendHtmlConstant("<img src='images/icons/add.png' style='cursor: pointer'/> ");
        sb.append(SafeHtmlUtils.fromTrustedString(value));
        sb.appendHtmlConstant("</div>");
    }

    @Override
    public Set<String> getConsumedEvents() {
        Set<String> events = new HashSet<String>();
        events.add("click");
        return events;
    }

    @Override
    public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater) {
        super.onBrowserEvent(context, parent, value, event, valueUpdater);
        if (parent.getFirstChildElement().isOrHasChild(Element.as(event.getEventTarget()))) {
            Console.writeLine("OnEvent");
            Info.display("Test", value);
        }
    }
};
prm_nameColumn.setCell(ic);


add style to css.


.myClickableCellTestStyle{
    text-decoration:underline;
}
0

Focal Length Calculator

Just for my reference about Focal Length Calculator.

 http://www.giangrandi.ch/optics/lenses/focalcalc.html

1

GXT3 Whole Grid Filtering

This the code to perform the whole grid filtering

pagingGridControl.getStore().addFilter(new StoreFilter() {
  @Override
  public boolean select(Store store, Object parent, Object item) {
    if(txtKeyword.getValue()==null){
      return true;
    }else{
      if(txtKeyword.getValue().trim().equals("")){
        return true;
      }
      
      Cheap_Sale_AllowedBean obj=(Cheap_Sale_AllowedBean) item;
      String sKeyword=txtKeyword.getValue();
      AutoBean<Cheap_Sale_AllowedBean> bean = AutoBeanUtils.getAutoBean(obj);
      Map<String,Object> map= AutoBeanUtils.getAllProperties(bean);
      for (String s : map.keySet()) {
        //Console.writeLine(s + "=" + map.get(s));
        if(map.get(s) !=null){
          if(map.get(s).toString().toLowerCase().indexOf(sKeyword) > -1){
            Console.writeLine(s + "=" + map.get(s));    
            return true;
          }
        }
      }          
    }
    return false;
  }
});

pagingGridControl.getStore().setEnableFilters(true);

The store filters must be enabled.

Source : http://www.sencha.com/forum/showthread.php?270023-Grid-Search

0

Textfield blur event not triggered when click on button's icon.

I read the GXT forum and just realize that Textfield blur event is not triggered when a button with icon is clicked on the icon. I found a temporary solution to handle this situation. Before submit the data, the textField finishEditing() function must be called.

Here is the code from my project. I'm going to put it in my library after this.


int widgetCount=toolbar.getWidgetCount();
for(int i=0; i < widgetCount;i ++){
  Widget w=toolbar.getWidget(i);
  if(w.getClass().equals(TextField.class)){
    TextField t=(TextField) w;
    t.finishEditing();                       
  }
}

Source : http://www.sencha.com/forum/showthread.php?258421-Field-and-blur-event
0

GXT3 Input Maxlength

I just migrated from GXT2 to GXT3.
Most of my previous code does not work and I got a problem to fix MAXLENGTH input element.
Luckily, the solution is very simple. Here is the code

textbox.getCell().getInputElement(textbox.getElement()).setMaxLength(maxLength);

This code worked for TextField, TextArea, NumberField<Integer> and NumberField<Double>.

But for NumberField, this syntax must be applied after the value has been set. If not, the maxlength attaribute will be removed.

Source : http://www.sencha.com/forum/showthread.php?178262-Setting-max-length-on-TextField
0

Handling POST Content-Length (PHP) Warning

I got problem when the file upload make the POST size exceed post_max_size setting.
I had disable the error report but the warning kept appearing.
Finally I found a solution.

In my case, I disabled all the PHP warning message using .htaccess.
To disable all errors from .htaccess use :
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0
From http://ca2.php.net/manual/en/ini.core.php#ini.post-max-size
If the size of post data is greater than post_max_size, 
the $_POST and $_FILES superglobals are empty. 
This can be tracked in various ways, e.g. by passing
the $_GET variable to the script processing the data,
i.e. , and then checking if $_GET['processed'] is 
set.


Here is the example to handle it in PHP:
if(empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ //catch file overload error...
  return $this->returnErrorMessage("File size exceed limit !!!");
}

Source : 
1. http://stackoverflow.com/questions/12872515/php-warning-demolishes-json-response
2.http://stackoverflow.com/questions/2133652/how-to-gracefully-handle-files-that-exceed-phps-post-max-size
0

Multi Form Button Binding

I have to break the form into 2 columns that need to use a separate form panels.
But FormButtonBinding not support more than 1 form panels. So I decided to write a new one based on GXT FormButtonBinding

package com.vcari.client;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.google.gwt.user.client.Timer;

/**
 * Monitors the valid state of a form and enabled / disabled all buttons.
 */
public class MultiFormButtonBinding {

  // private FormPanel panel;
  private List<FormPanel> panels = new ArrayList<FormPanel>();
  private Timer timer;
  private int interval = 500;
  private Listener<ComponentEvent> listener;
  private List<Button> buttons;

  public MultiFormButtonBinding(List<FormPanel> panels) {
    this.panels = panels;

    buttons = new ArrayList<Button>();
    timer = new Timer() {
      @Override
      public void run() {
        MultiFormButtonBinding.this.checkPanel();
      }
    };
    listener = new Listener<ComponentEvent>() {
      public void handleEvent(ComponentEvent be) {
        if (be.getType() == Events.Attach) {
          MultiFormButtonBinding.this.startMonitoring();
        } else if (be.getType() == Events.Detach) {
          MultiFormButtonBinding.this.stopMonitoring();
        }
      }
    };

    for (FormPanel formPanel : panels) {
      formPanel.addListener(Events.Attach, listener);
      formPanel.addListener(Events.Detach, listener);
      if (formPanel.isAttached()) {
        startMonitoring();
      }
    }

    // panel.addListener(Events.Attach, listener);
    // panel.addListener(Events.Detach, listener);

  }

  public void addButton(Button button) {
    buttons.add(button);
  }

  public int getInterval() {
    return interval;
  }

  public void removeButton(Button button) {
    buttons.remove(button);
  }

  public void setInterval(int interval) {
    this.interval = interval;
  }

  public void startMonitoring() {
    for (FormPanel formPanel : panels) {
      if (formPanel.isAttached()) {
        timer.run();
        timer.scheduleRepeating(interval);
        break;
      }      
    }    
  }

  public void stopMonitoring() {
    timer.cancel();
  }

  protected boolean checkPanel() {
    boolean v=true;
    for (FormPanel formPanel : panels) {
      boolean v1 = formPanel.isValid(true);
      v=v && v1;
      
    }  
    
    for (Button button : buttons) {
      if (v != button.isEnabled()) {
        button.setEnabled(v);
      }
    }
    return v;
  }

}

Example :

List<FormPanel> panels=new ArrayList<FormPanel>();
panels.add(form);
panels.add(form2);
MultiFormButtonBinding buttonBinding=new MultiFormButtonBinding(panels);
buttonBinding.addButton(btnSubmit);
0

GXT Form AutoFocus

I have a login form and want it focus on the username textfield when it loads.
The solution is very simple, just need to set an event (onFocus) for the container.


 addListener(Events.OnFocus, new Listener<ComponentEvent>() {
    public void handleEvent(ComponentEvent e) {
        txtFldUsername.focus();
    }
});


Source : http://code.google.com/p/topcat/source/browse/trunk/Code/TopCAT/src/main/java/uk/ac/stfc/topcat/gwt/client/widget/LoginWidget.java?r=74
0

GWT/GXT UTF-8

One of my project require to use Thai character (UTF-8).
The solution is very simple. In order to use internationalized characters, make sure that the host HTML file contains the charset=utf8 content type in the meta tag in the header:

<meta http-equiv="content-type" content="text/html;charset=utf-8" />


Source : https://developers.google.com/web-toolkit/doc/latest/DevGuideI18n#DevGuideStaticStringInternationalization
0

GXT Grid Column Word Wrap

I would like to apply word wrap to a single column.
Just need to set a custom renderer.  
 
cm.getColumnById("proddesc").setRenderer(new GridCellRenderer<ModelData>() {
  @Override
  public Object render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
    return "<div style=\"white-space:normal !important;\">"+ model.get(property) +"</div>";
  }
});
Source : http://stackoverflow.com/questions/2106104/word-wrap-grid-cells-in-ext-js
0

Linux Backup / Clone Disk

I want to clone my entire disk to to new disk using Linux.
I just need to write a simple command using dd and specify if (input file / disk) and of (output file).

dd if=/dev/sda of=/dev/sdb
 
To get get the current progress of disk copy / cloning 
I need to know the process id of dd process. 
Using command belows I can get the process id.

ps aux | grep -i dd

To make the progress shown on the console I need to write the following command

kill -SIGUSR1 


Reference :

http://www.thegeekstuff.com/2010/10/dd-command-examples/
http://serverfault.com/questions/4906/using-dd-for-disk-cloning
0

Linux - Sync time using google web server

Reference : http://superuser.com/questions/307158/how-to-use-ntpdate-behind-a-proxy

I got problem to sync time on my Linux controllers using ntpdate because they are under proxies & firewall. I found a simple solution and it's using google web server time.
Execute this
sudo date -s "$(wget -S "http://www.google.com/" 2>&1 | grep -E '^[[:space:]]*[dD]ate:' | sed 's/^[[:space:]]*[dD]ate:[[:space:]]*//' | head -1l | awk '{print $1, $3, $2, $5 ,"GMT", $4 }' | sed 's/,//')"
if the timezone is not configured yet, simply run this command
ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime 
or using wizard
dpkg-reconfigure tzdata
0

Skip MySQL temp table

I have a problem where MySQL has taken a long time to copy the data to a temporary table.
I found a solution at:

http://stackoverflow.com/questions/7532307/skip-copying-to-tmp-table-on-disk-mysql

But in this problem, I changed the / tmpfs to / dev / shm.
More information about the / dev / shm can be found here

http://www.cyberciti.biz/tips/what-is-devshm-and-its-practical-usage.html

Step I:

1. Change the configuration of MySQL to use / dev / shm as temp tables directory

2. Change tmp_table_size = 2K
 
Copyright © peyotest