Wednesday, April 29, 2009

Eclipse Ganymede J2EE: Maven2 Plugin

I had hard time installing all Maven2 plugin features, so I selected only few required:


Eclipse Ganymede J2EE plugins

I noticed that I have problems installing plugins after I restart the Eclipse (Update Manager changes) so i have to install them all in one shot without restart:

SVN:
http://subclipse.tigris.org/update_1.6.x

Google AppEngine:
http://dl.google.com/eclipse/plugin/3.4

Maven2:
http://m2eclipse.sonatype.org/update/ 

I actually had to delete the eclipse folder and expand it from the tar, then I install all plugins each time saying NO to restart of Eclipse. After the last plugin installation I restart the Eclipse and all works fine. 


Google AppEngine - Eclipse Ganymede Installation


  • Verify installation of Eclipse Ganymede IDE for J2EE development 
  • open Help -> Software Updates ...
  • add new site http://dl.google.com/eclipse/plugin/3.4


Friday, April 24, 2009

Google project hosting

You can host your projects using code.google.com SVN repository.

  1. sign up to your google account
  2. go to http://code.google.com/hosting/
  3. click "Create a new project"
  4. go to "Source" Tab
  5. check out the code using command line SVN, or Eclipse SVN plugin (tigris)
  6. add your files (when you copy from previous SVN project remove all .SVN folders )
  7. commit



Tuesday, April 21, 2009

Java String parser

To split a String into words (tokens) where delimiter is white space...


 String delims = "[ ]+"

 String[] tokens = someLongString.split(delims);


Now you can look thru the tokens and do comparisons, etc.

Monday, April 20, 2009

CSS: centering DIV

Specify the width of the container and set margins to AUTO.


.background {
background-image: url("images/map_bg.png");
background-repeat: no-repeat;
height: 900px;
width: 860px;
margin-left: auto;
margin-right: auto;
}


<body><div class="background">The centered content is here

Thursday, April 16, 2009

Using Composite Class

The main advantage of extending the Composite class instead of extending another widget is that using the Composite class will hide all of the methods and properties of the wrapped widget. For example, instead of extending a VerticalPanel where a widget can be added, extending Composite that is initialized with a VerticalPanel will prevent the user of the custom widget from adding to the panel.

Monday, April 13, 2009

Tour De Flex

Wednesday, April 8, 2009

Interactive Map Implementation

To create an interactive map where a user can highlight a state, a red border appears around the state he/she has selected.

Example:

When user clicks on the highlighted state, which is Oregon in above picture, the highlighted state's map shows:


Download below jquery.maphighlight.min.js and jquery-1.2.3.pack.js locally and include thier paths on your file system
 - Create an DE.html file which corresponds to the state's name:


 - Create an index.html file and include:


Function To Censor String

Here is a function that censors a string, but leaves in all of the punctuation. It searches for strings of letters and numbers and if it matches "badword", will replace it with "[censored]".

public String censorString(String originalString)

{

StringBuffer orig = new StringBuffer(originalString);


Pattern p = Pattern.compile("[0-9/A-Z/a-z]+");

Matcher m = p.matcher(orig);

StringBuffer censor = new StringBuffer();

boolean result = m.find();

while (result)

{

String match = originalString.substring(m.start(), m.end());

if(match.equals("badword"))

m.appendReplacement(censor, "[censored]");

result = m.find();

}

m.appendTail(censor);

return censor.toString();

}

Monday, April 6, 2009

Adding maven and SVN plugin to Eclipse 2.4.2

To add maven plugin:

Go Help menu in your Eclipse IDE 
Select Software Updates
Click on Add Site and enter http://m2eclipse.sonatype.org/update/

To add SVN plugin:

Go Help menu in your Eclipse IDE 
Select Software Updates
Click on Add Site and enter http://subclipse.tigris.org/update_1.4.x
To see your SVN repository view, go to Window menu 
Select Show View and select SVN Repository

Friday, April 3, 2009

GWT Client Side Date / Calculate Age

Because GWT doesn't support the Calendar class on the client side (as of 1.6.3), getting the parts of the current date can be accomplished like this:

Date today = new Date();

Integer currentYear = new Integer(DateTimeFormat.getFormat("yyyy").format(today));

Integer currentMonth = new Integer(DateTimeFormat.getFormat("M").format(today));

Integer currentDay = new Integer(DateTimeFormat.getFormat("d").format(today));

Age calculating function:

public static int calculateAge(Date dob)

{

Date today = new Date();

Integer currentYear = new Integer(DateTimeFormat.getFormat("yyyy").format(today));

Integer currentMonth = new Integer(DateTimeFormat.getFormat("M").format(today));

Integer currentDay = new Integer(DateTimeFormat.getFormat("d").format(today));

Integer dobYear = new Integer(DateTimeFormat.getFormat("yyyy").format(dob));

Integer dobMonth = new Integer(DateTimeFormat.getFormat("M").format(dob));

Integer dobDay = new Integer(DateTimeFormat.getFormat("d").format(dob));

int age = currentYear - dobYear;

if((dobMonth > currentMonth) || (currentMonth == dobMonth && dobDay > currentDay))

age--;

return age;

}

Thursday, April 2, 2009

GWT: using Timer as in Tread sleep()

You can use the timer to put the application to sleep, or in this case to change content every 3 seconds.



    private String currentImage = "1.png";

    private int refreshIntervalMilliseconds = 3000;

    public void onModuleLoad()
    {
params = CommonUtils.parseParamString();

Timer t = new Timer()
{
    public void run()
    {
if (currentImage.equals("1.png"))
    currentImage = "2.png";
else if (currentImage.equals("2.png"))
    currentImage = "3.png";
else if (currentImage.equals("3.png"))
    currentImage = "4.png";
else if (currentImage.equals("4.png"))
    currentImage = "1.png";
RootPanel.get("content").clear();
RootPanel.get("content").add(new Label("Current time: " + new Date()));
RootPanel.get("content").add(new Image("images/" + currentImage));
System.out.println("Putting system to sleep for " + refreshIntervalMilliseconds / 1000 + " seconds. currentImage = " + currentImage);
    }
};
t.scheduleRepeating(refreshIntervalMilliseconds);
    }