Code Search for Developers
 
 
  

StoryCardGrid.java from MASE: Agile Software Engineering at Krugle


Show StoryCardGrid.java syntax highlighted

package ucalgary.ebe.webui.client.ui;

import java.util.Vector;

import ucalgary.ebe.webui.client.WebUI2ServiceConnection;
import ucalgary.ebe.webui.client.data.StoryCardWeb;

import com.google.gwt.user.client.Window;
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 {
	
	public static final String STYLE_COMPLETED = "webui-StoryCard-Completed";
	public static final String STYLE_COMPLETED_OUT_OF_FOCUS = "webui-StoryCard-Completed-OutOfFocus";
	public static final String STYLE_IN_PROGRESS = "webui-StoryCard-InProgress";
	public static final String STYLE_IN_PROGRESS_OUT_OF_FOCUS = "webui-StoryCard-InProgress-OutOfFocus";
	public static final String STYLE_OUT_OF_FOCUS = "webui-StoryCard-OutOfFocus";
	public static final String STYLE_IN_FOCUS = "webui-StoryCard-InFocus";
	
	private static final String FLOAT_PATTERN = "\\d+(\\.{1}\\d+)?";
	
	private WebUI2ServiceConnection con;
	private Vector checked_storycards = new Vector(); 

	public StoryCardGrid(WebUI2ServiceConnection con, Vector storycards) {
		super(1, 11);
		this.con = con;
		
		this.createStoryGridHeader();
		
		for(int i = 0; i < storycards.size(); i++) {
			this.addStoryCard((StoryCardWeb)storycards.get(i));
		}
		
		this.addStyleName("webui-StoryCardGrid");
		this.setBorderWidth(1);
	}
	
	
	/**
	 * Creates a treeitem for a storycard
	 * 
	 * @param storycard
	 * @return
	 */
	public void addStoryCard(StoryCardWeb storycard) {
		
		this.resizeRows(this.getRowCount() + 1);
		int row = this.getRowCount() - 1;
		
//		RowFormatter rf = this.getRowFormatter();
//		String textboxstyle;
//		if(storycard.isCompleted()) {
//			rf.addStyleName(row, "webui-StoryCard-Completed");
//			textboxstyle = "webui-StoryCard-Completed-OutOfFocus";
//		} else if(storycard.isStarted()) {
//			rf.addStyleName(row, "webui-StoryCard-Started");
//			textboxstyle = "webui-StoryCard-Started-OutOfFocus";
//		} else {
//			textboxstyle = "webui-StoryCard-OutOfFocus";
//		}
		
		
		//ADD STORYCARD ICON
		Image story_image = new Image("images/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.addStyleName("webui-StoryCard-OutOfFocus");

		storyname_textbox.addFocusListener(new FocusListener() {

			public void onFocus(Widget sender) {
				//HIGHLIGHT EDITED FIELD
				sender.addStyleName("webui-StoryCard-InFocus");
				sender.removeStyleName("webui-StoryCard-OutOfFocus");
			}

			public void onLostFocus(Widget sender) {
				//SET FIELD BACK TO NORMAL TABLE DESIGN
				sender.addStyleName("webui-StoryCard-OutOfFocus");
				sender.removeStyleName("webui-StoryCard-InFocus");
				
				//COMMIT CHANGES
				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.addStyleName("webui-StoryCard-OutOfFocus");

		desc_box.addFocusListener(new FocusListener() {

			public void onFocus(Widget sender) {
				//HIGHLIGHT EDITED FIELD
				sender.addStyleName("webui-StoryCard-InFocus");
				sender.removeStyleName("webui-StoryCard-OutOfFocus");
			}

			public void onLostFocus(Widget sender) {
				//SET FIELD BACK TO NORMAL TABLE DESIGN
				sender.addStyleName("webui-StoryCard-OutOfFocus");
				sender.removeStyleName("webui-StoryCard-InFocus");
				
				//COMMIT CHANGES
				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.addStyleName("webui-StoryCard-OutOfFocus");

		best_box.addFocusListener(new FocusListener() {

			public void onFocus(Widget sender) {
				//HIGHLIGHT EDITED FIELD
				sender.addStyleName("webui-StoryCard-InFocus");
				sender.removeStyleName("webui-StoryCard-OutOfFocus");
			}

			public void onLostFocus(Widget sender) {
				//SET FIELD BACK TO NORMAL TABLE DESIGN
				sender.addStyleName("webui-StoryCard-OutOfFocus");
				sender.removeStyleName("webui-StoryCard-InFocus");
				
				//COMMIT CHANGES
				TextBoxWithID tb = (TextBoxWithID)sender;
				
				if(!tb.getText().matches(FLOAT_PATTERN)) {
					tb.setText(tb.getOldText());
				} else {
					tb.setOldText(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.addStyleName("webui-StoryCard-OutOfFocus");

		most_box.addFocusListener(new FocusListener() {

			public void onFocus(Widget sender) {
				//HIGHLIGHT EDITED FIELD
				sender.addStyleName("webui-StoryCard-InFocus");
				sender.removeStyleName("webui-StoryCard-OutOfFocus");
			}

			public void onLostFocus(Widget sender) {
				//SET FIELD BACK TO NORMAL TABLE DESIGN
				sender.addStyleName("webui-StoryCard-OutOfFocus");
				sender.removeStyleName("webui-StoryCard-InFocus");
				
				//COMMIT CHANGES
				TextBoxWithID tb = (TextBoxWithID)sender;
				
				if(!tb.getText().matches(FLOAT_PATTERN)) {
					tb.setText(tb.getOldText());
				} else {
					tb.setOldText(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.addStyleName("webui-StoryCard-OutOfFocus");

		worst_box.addFocusListener(new FocusListener() {

			public void onFocus(Widget sender) {
				//HIGHLIGHT EDITED FIELD
				sender.addStyleName("webui-StoryCard-InFocus");
				sender.removeStyleName("webui-StoryCard-OutOfFocus");
			}

			public void onLostFocus(Widget sender) {
				//SET FIELD BACK TO NORMAL TABLE DESIGN
				sender.addStyleName("webui-StoryCard-OutOfFocus");
				sender.removeStyleName("webui-StoryCard-InFocus");
				
				//COMMIT CHANGES
				TextBoxWithID tb = (TextBoxWithID)sender;
				
				if(!tb.getText().matches(FLOAT_PATTERN)) {
					tb.setText(tb.getOldText());
				} else {
					tb.setOldText(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.addStyleName("webui-StoryCard-OutOfFocus");

		actual_box.addFocusListener(new FocusListener() {

			public void onFocus(Widget sender) {
				//HIGHLIGHT EDITED FIELD
				sender.addStyleName("webui-StoryCard-InFocus");
				sender.removeStyleName("webui-StoryCard-OutOfFocus");
			}

			public void onLostFocus(Widget sender) {
				//SET FIELD BACK TO NORMAL TABLE DESIGN
				sender.addStyleName("webui-StoryCard-OutOfFocus");
				sender.removeStyleName("webui-StoryCard-InFocus");
				
				//COMMIT CHANGES
				TextBoxWithID tb = (TextBoxWithID)sender;
				
				if(!tb.getText().matches(FLOAT_PATTERN)) {
					tb.setText(tb.getOldText());
				} else {
					tb.setOldText(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/complete.gif", storycard.getId());
		story_complete_image.addClickListener(new ClickListener() {

			public void onClick(Widget sender) {
				ImageWithID img =  (ImageWithID)sender;
				getConnection().updateStoryCardStatus(img.getId(), StoryCardWeb.STATUS_COMPLETED);
				//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/delete.gif", storycard.getId());
		story_delete_image.addClickListener(new ClickListener() {

			public void onClick(Widget sender) {
				if(Window.confirm("Deleting this StoryCard is IRREVERSIBLE! Are you really sure?")) {
					try {
						ImageWithID img =  (ImageWithID)sender;
						getConnection().deleteStoryCard(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/in_progress.gif", storycard.getId());
		story_in_progress_image.addClickListener(new ClickListener() {

			public void onClick(Widget sender) {
				ImageWithID img =  (ImageWithID)sender;
				getConnection().updateStoryCardStatus(img.getId(), StoryCardWeb.STATUS_IN_PROGRESS);
			}
			
		});
		this.setWidget(row, 9, story_in_progress_image);
		
		
		//ADD CHECKBOX
		
		CheckBoxWithID story_check = new CheckBoxWithID(storycard.getId());
		this.setWidget(row, 10, story_check);
		this.checked_storycards.add(story_check);
	}

	
	/**
	 * 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;
	}
	
	public Vector getCheckedStoryCardIDs() {
		Vector sc_ids = new Vector();

		for(int i=0; i<checked_storycards.size(); i++) {
			CheckBoxWithID cb = (CheckBoxWithID)checked_storycards.get(i);
			if(cb.isChecked()) {
				sc_ids.add(new Long(cb.getId()));
			}
		}
		
		return sc_ids;

	}
	
	
	
	/**
	 * @author Heini Hamster
	 * 
	 * Colors TextBoxes according to status of storycard
	 *
	 */
	private class ColoringFocusListener implements FocusListener {
		
		private String style;

		public ColoringFocusListener(String style) {
			this.style = style;
		}
		
		public void onFocus(Widget sender) {
			sender.removeStyleName(style);
			sender.addStyleName(STYLE_IN_FOCUS);
			
		}

		public void onLostFocus(Widget sender) {
			sender.removeStyleName(STYLE_IN_FOCUS);
			sender.addStyleName(style);
			
		}
		
	}

}







See more files for this project here

MASE: Agile Software Engineering

The MASE project investigates methods to support the coordination and executable acceptance testing of software projects. Keywords: Agile methods, distributed teams, Extreme Programming. See http://ebe.cpsc.ucalgary.ca/ebe for more information.

Project homepage: http://sourceforge.net/projects/mase
Programming language(s): Java,XML
License: other

  CheckBoxWithID.java
  CreateIterationDialogBox.java
  CreateProjectDialogBox.java
  CreateStoryCardDialogBox.java
  ImageButton.java
  ImageWithID.java
  LoadProjectElement.java
  MoveStoryCardElement.java
  ProjectWhiteBoard.java
  StoryCardGrid.java
  StoryCardParentListBox.java
  TextBoxWithID.java
  WebUIMenu.java