Show StoryCardGrid.java syntax highlighted
package ucalgary.ebe.webui.client.ui;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
import ucalgary.ebe.webui.client.WebUI2ServiceConnection;
import ucalgary.ebe.webui.client.data.StoryCardWeb;
import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.FocusListener;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
public class StoryCardGrid extends Grid {
private HashMap lookup = new HashMap();
private static final String FLOAT_PATTERN = "\\d+(\\.{1}\\d+)?";
private WebUI2ServiceConnection con;
public StoryCardGrid(WebUI2ServiceConnection con, Vector storycards) {
super(1, 10);
this.con = con;
this.createStoryGridHeader();
for(int i = 0; i < storycards.size(); i++) {
this.addStoryCard((StoryCardWeb)storycards.get(i));
}
}
/**
* Creates a treeitem for a storycard
*
* @param storycard
* @return
*/
public void addStoryCard(StoryCardWeb storycard) {
this.resizeRows(this.getRowCount() + 1);
int row = this.getRowCount() - 1;
//ADD STORYCARD ICON
Image story_image = new Image("images/icon_new_story.gif");
story_image.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
// TODO Auto-generated method stub
System.out.println("Edit Storycard");
}
});
this.setWidget(row, 0, story_image);
//ADD STORYCARD NAME TEXTBOX
TextBoxWithID storyname_textbox = new TextBoxWithID(storycard.getId());
storyname_textbox.setText(storycard.getName());
storyname_textbox.addFocusListener(new FocusListener() {
public void onChange(Widget sender) {
TextBoxWithID tb = (TextBoxWithID)sender;
getConnection().updateStoryCardName(tb.getId(), tb.getText());
}
public void onFocus(Widget sender) {
// TODO Auto-generated method stub
}
public void onLostFocus(Widget sender) {
TextBoxWithID tb = (TextBoxWithID)sender;
getConnection().updateStoryCardName(tb.getId(), tb.getText());
}
});
this.setWidget(row, 1, storyname_textbox);
//ADD STORYCARD DESCRIPTION TEXTBOX
TextBoxWithID desc_box = new TextBoxWithID(storycard.getId());
desc_box.setText(storycard.getDescription());
desc_box.addFocusListener(new FocusListener() {
public void onChange(Widget sender) {
TextBoxWithID tb = (TextBoxWithID)sender;
getConnection().updateStoryCardDescription(tb.getId(), tb.getText());
}
public void onFocus(Widget sender) {
// TODO Auto-generated method stub
}
public void onLostFocus(Widget sender) {
TextBoxWithID tb = (TextBoxWithID)sender;
getConnection().updateStoryCardDescription(tb.getId(), tb.getText());
}
});
this.setWidget(row, 2, desc_box);
//ADD STORYCARD BESTCASE TEXTBOX
TextBoxWithID best_box = new TextBoxWithID(storycard.getId(), String.valueOf(storycard.getBestCaseEstimate()));
best_box.setText(String.valueOf(storycard.getBestCaseEstimate()));
best_box.addChangeListener(new ChangeListener() {
public void onChange(Widget sender) {
TextBoxWithID tb = (TextBoxWithID)sender;
if(!tb.getText().matches(FLOAT_PATTERN)) {
tb.setText(tb.getContent());
} else {
tb.setContent(tb.getText());
getConnection().updateStoryCardBestCaseEstimate(tb.getId(), Float.valueOf(tb.getText()).floatValue());
}
}
public void onFocus(Widget sender) {
// TODO Auto-generated method stub
}
public void onLostFocus(Widget sender) {
TextBoxWithID tb = (TextBoxWithID)sender;
if(!tb.getText().matches(FLOAT_PATTERN)) {
tb.setText(tb.getContent());
} else {
tb.setContent(tb.getText());
getConnection().updateStoryCardBestCaseEstimate(tb.getId(), Float.valueOf(tb.getText()).floatValue());
}
}
});
this.setWidget(row, 3, best_box);
//ADD STORYCARD MOSTLIKELY TEXTBOX
TextBoxWithID most_box = new TextBoxWithID(storycard.getId(), String.valueOf(storycard.getMostlikelyEstimate()));
most_box.setText(String.valueOf(storycard.getMostlikelyEstimate()));
most_box.addChangeListener(new ChangeListener() {
public void onChange(Widget sender) {
TextBoxWithID tb = (TextBoxWithID)sender;
if(!tb.getText().matches(FLOAT_PATTERN)) {
tb.setText(tb.getContent());
} else {
tb.setContent(tb.getText());
getConnection().updateStoryCardMostLikelyEstimate(tb.getId(), Float.valueOf(tb.getText()).floatValue());
}
}
public void onFocus(Widget sender) {
// TODO Auto-generated method stub
}
public void onLostFocus(Widget sender) {
TextBoxWithID tb = (TextBoxWithID)sender;
if(!tb.getText().matches(FLOAT_PATTERN)) {
tb.setText(tb.getContent());
} else {
tb.setContent(tb.getText());
getConnection().updateStoryCardMostLikelyEstimate(tb.getId(), Float.valueOf(tb.getText()).floatValue());
}
}
});
this.setWidget(row, 4, most_box);
//ADD STORYCARD WORSTCASE TEXTBOX
TextBoxWithID worst_box = new TextBoxWithID(storycard.getId(), String.valueOf(storycard.getWorstCaseEstimate()));
worst_box.setText(String.valueOf(storycard.getWorstCaseEstimate()));
worst_box.addChangeListener(new ChangeListener() {
public void onChange(Widget sender) {
TextBoxWithID tb = (TextBoxWithID)sender;
if(!tb.getText().matches(FLOAT_PATTERN)) {
tb.setText(tb.getContent());
} else {
tb.setContent(tb.getText());
getConnection().updateStoryCardWorstCaseEstimate(tb.getId(), Float.valueOf(tb.getText()).floatValue());
}
}
public void onFocus(Widget sender) {
// TODO Auto-generated method stub
}
public void onLostFocus(Widget sender) {
TextBoxWithID tb = (TextBoxWithID)sender;
if(!tb.getText().matches(FLOAT_PATTERN)) {
tb.setText(tb.getContent());
} else {
tb.setContent(tb.getText());
getConnection().updateStoryCardWorstCaseEstimate(tb.getId(), Float.valueOf(tb.getText()).floatValue());
}
}
});
this.setWidget(row, 5, worst_box);
//ADD STORYCARD ACTUAL EFFORT TEXTBOX
TextBoxWithID actual_box = new TextBoxWithID(storycard.getId(), String.valueOf(storycard.getActualEffort()));
actual_box.setText(String.valueOf(storycard.getActualEffort()));
actual_box.addChangeListener(new ChangeListener() {
public void onChange(Widget sender) {
TextBoxWithID tb = (TextBoxWithID)sender;
if(!tb.getText().matches(FLOAT_PATTERN)) {
tb.setText(tb.getContent());
} else {
tb.setContent(tb.getText());
getConnection().updateStoryCardActualEffort(tb.getId(), Float.valueOf(tb.getText()).floatValue());
}
}
public void onFocus(Widget sender) {
// TODO Auto-generated method stub
}
public void onLostFocus(Widget sender) {
TextBoxWithID tb = (TextBoxWithID)sender;
if(!tb.getText().matches(FLOAT_PATTERN)) {
tb.setText(tb.getContent());
} else {
tb.setContent(tb.getText());
getConnection().updateStoryCardActualEffort(tb.getId(), Float.valueOf(tb.getText()).floatValue());
}
}
});
this.setWidget(row, 6, actual_box);
//ADD COMPLETE ICON
ImageWithID story_complete_image = new ImageWithID("images/icon_complete.gif", storycard.getId(), row);
story_complete_image.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
ImageWithID img = (ImageWithID)sender;
getConnection().updateStoryCardComplete(img.getId(), true);
//set the row to different color or remove it
}
});
this.setWidget(row, 7, story_complete_image);
//ADD DELETE ICON
// ImageWithID story_delete_image = new ImageWithID("images/icon_delete.gif", storycard.getId(), row);
ImageWithID story_delete_image = new ImageWithID("images/icon_delete.gif", storycard.getId());
this.lookup.put(new Long(storycard.getId()), new Integer(row));
story_delete_image.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
try {
ImageWithID img = (ImageWithID)sender;
getConnection().deleteStoryCard(img.getId());
// removeRow(img.getRow());
removeStoryCard(img.getId());
} catch(Exception e) {
e.printStackTrace();
}
}
});
this.setWidget(row, 8, story_delete_image);
//ADD START ICON
ImageWithID story_in_progress_image = new ImageWithID("images/icon_in_progress.gif", storycard.getId());
story_in_progress_image.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
ImageWithID img = (ImageWithID)sender;
getConnection().updateStoryCardInProgress(img.getId(), true);
}
});
this.setWidget(row, 9, story_in_progress_image);
}
/**
* Adjusts the row numbers asigned to storycards when one of them is removed, removes the
* card from the grid and the hashmap
*
* @param id
*/
private void removeStoryCard(long id) {
try {
int row = ((Integer)this.lookup.get(new Long(id))).intValue();
Iterator rows = this.lookup.values().iterator();
while(rows.hasNext()) {
int r = ((Integer)rows.next()).intValue();
if(r > row) {
r -= 1;
this.lookup.put(new Long(id), new Integer(r));
}
}
this.lookup.remove(new Integer(row));
this.removeRow(row);
} catch(Exception e) {
e.printStackTrace();
}
}
/**
* Creates the header line for the storycards
*
* @return
*/
private void createStoryGridHeader() {
this.setBorderWidth(1);
this.setText(0, 1, "Name");
this.setText(0, 2, "Description");
this.setText(0, 3, "Best");
this.setText(0, 4, "Most");
this.setText(0, 5, "Worst");
this.setText(0, 6, "Actual");
}
public WebUI2ServiceConnection getConnection() {
return this.con;
}
}
See more files for this project here