Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Disabling listgridfields after saving changes not working

    GWT v2.5
    SmartGWT 3.1d EE, (v8.3p_2012-12-28Enterprise Isomorphic-SmartClient-Package-Date: 2012-12-28)
    Browser: IE9
    Environment: Eclipse Indigo
    Java 1.6

    I have a listgrid with a single column grouping. When I check a boolean field and save, it will jump to the other group and I've coded it to disable the whole row. However, it does not disable until I hit my refresh button. I have the disable method being called from the addDataArrivedHandler event. I've verified that it is being called both when the edits are saved and when the refresh is done.

    Code:
    package com.pci.gp.client.screens;
    
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    
    import com.google.gwt.dom.client.Element;
    import com.google.gwt.i18n.client.DateTimeFormat;
    import com.google.gwt.user.client.DOM;
    import com.google.gwt.user.client.Timer;
    import com.pci.gp.client.screens.utils.OnTheHourTimer;
    import com.pci.gp.client.screens.utils.OnTheHourTimerTask;
    import com.smartgwt.client.data.Criteria;
    import com.smartgwt.client.data.DSRequest;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.SortSpecifier;
    import com.smartgwt.client.types.DragDataAction;
    import com.smartgwt.client.types.ExportDisplay;
    import com.smartgwt.client.types.ExportFormat;
    import com.smartgwt.client.types.FetchMode;
    import com.smartgwt.client.types.SortDirection;
    import com.smartgwt.client.types.TitleOrientation;
    import com.smartgwt.client.types.VerticalAlignment;
    import com.smartgwt.client.util.BooleanCallback;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.Button;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Img;
    import com.smartgwt.client.widgets.Label;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.DateTimeItem;
    import com.smartgwt.client.widgets.form.fields.FormItem;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.grid.CellFormatter;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    import com.smartgwt.client.widgets.grid.events.DataArrivedEvent;
    import com.smartgwt.client.widgets.grid.events.DataArrivedHandler;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.layout.LayoutSpacer;
    
    /**
     * This is the GUI for the PCI Block Pricing Quick Quote screen. It provides
     * CRUD for Deal Terms and displays a range of Hour Ending totals up to a 72 hour range.
     * It also provides Printing and Excel exporting for the quick quote grid.
     * 
     * @author dwburns
     * 
     */
    
    public class QuickQuote extends BaseScreen
    {
    	private final ListGrid quickQuoteGrid = new ListGrid();
    	private final DataSource customDS = DataSource.get("quickquote_deal");
    	private final String SCREEN_TITLE = "PCI Block Pricing Quick Quote";
    	private final String LOGO = "pci_transp_logo.gif";
    	// there may be a better way to handle this, but for now this is for building
    	// a list of row numbers that do not have executionDates so that in the save method
    	// we can have a row number reference for setting the executionDate attribute
    	// when the executed checkbox is checked
    	private final ArrayList<Integer> notExecutedList = new ArrayList<Integer>();
    	private Label lastRefresh;
    	private Label statusLabel;
    	private final LayoutSpacer space = new LayoutSpacer();
    	// the refreshTimer refreshes the grid on the hour
    	private final OnTheHourTimer refreshTimer = new OnTheHourTimer(new RefreshTask());
    	private final SelectItem studyField = new SelectItem("study", "Study");
    	private final DateTimeItem startDate = new DateTimeItem("startDate", "Start Hour");
    	private final DateTimeItem endDate = new DateTimeItem("endDate", "End Hour");
    	private ListGridField he1Field = new ListGridField("he1");
    	private ListGridField he2Field = new ListGridField("he2");
    	private ListGridField he3Field = new ListGridField("he3");
    	private ListGridField he4Field = new ListGridField("he4");
    	private ListGridField he5Field = new ListGridField("he5");
    	private ListGridField he6Field = new ListGridField("he6");
    	private ListGridField he7Field = new ListGridField("he7");
    	private ListGridField he8Field = new ListGridField("he8");
    	private ListGridField he9Field = new ListGridField("he9");
    	private ListGridField he10Field = new ListGridField("he10");
    	private ListGridField he11Field = new ListGridField("he11");
    	private ListGridField he12Field = new ListGridField("he12");
    	private ListGridField he13Field = new ListGridField("he13");
    	private ListGridField he14Field = new ListGridField("he14");
    	private ListGridField he15Field = new ListGridField("he15");
    	private ListGridField he16Field = new ListGridField("he16");
    	private ListGridField he17Field = new ListGridField("he17");
    	private ListGridField he18Field = new ListGridField("he18");
    	private ListGridField he19Field = new ListGridField("he19");
    	private ListGridField he20Field = new ListGridField("he20");
    	private ListGridField he21Field = new ListGridField("he21");
    	private ListGridField he22Field = new ListGridField("he22");
    	private ListGridField he23Field = new ListGridField("he23");
    	private ListGridField he24Field = new ListGridField("he24");
    	private ListGridField he25Field = new ListGridField("he25");
    	private ListGridField he26Field = new ListGridField("he26");
    	private ListGridField he27Field = new ListGridField("he27");
    	private ListGridField he28Field = new ListGridField("he28");
    	private ListGridField he29Field = new ListGridField("he29");
    	private ListGridField he30Field = new ListGridField("he30");
    	private ListGridField he31Field = new ListGridField("he31");
    	private ListGridField he32Field = new ListGridField("he32");
    	private ListGridField he33Field = new ListGridField("he33");
    	private ListGridField he34Field = new ListGridField("he34");
    	private ListGridField he35Field = new ListGridField("he35");
    	private ListGridField he36Field = new ListGridField("he36");
    	private ListGridField he37Field = new ListGridField("he37");
    	private ListGridField he38Field = new ListGridField("he38");
    	private ListGridField he39Field = new ListGridField("he39");
    	private ListGridField he40Field = new ListGridField("he40");
    	private ListGridField he41Field = new ListGridField("he41");
    	private ListGridField he42Field = new ListGridField("he42");
    	private ListGridField he43Field = new ListGridField("he43");
    	private ListGridField he44Field = new ListGridField("he44");
    	private ListGridField he45Field = new ListGridField("he45");
    	private ListGridField he46Field = new ListGridField("he46");
    	private ListGridField he47Field = new ListGridField("he47");
    	private ListGridField he48Field = new ListGridField("he48");
    	private ListGridField he49Field = new ListGridField("he49");
    	private ListGridField he50Field = new ListGridField("he50");
    	private ListGridField he51Field = new ListGridField("he51");
    	private ListGridField he52Field = new ListGridField("he52");
    	private ListGridField he53Field = new ListGridField("he53");
    	private ListGridField he54Field = new ListGridField("he54");
    	private ListGridField he55Field = new ListGridField("he55");
    	private ListGridField he56Field = new ListGridField("he56");
    	private ListGridField he57Field = new ListGridField("he57");
    	private ListGridField he58Field = new ListGridField("he58");
    	private ListGridField he59Field = new ListGridField("he59");
    	private ListGridField he60Field = new ListGridField("he60");
    	private ListGridField he61Field = new ListGridField("he61");
    	private ListGridField he62Field = new ListGridField("he62");
    	private ListGridField he63Field = new ListGridField("he63");
    	private ListGridField he64Field = new ListGridField("he64");
    	private ListGridField he65Field = new ListGridField("he65");
    	private ListGridField he66Field = new ListGridField("he66");
    	private ListGridField he67Field = new ListGridField("he67");
    	private ListGridField he68Field = new ListGridField("he68");
    	private ListGridField he69Field = new ListGridField("he69");
    	private ListGridField he70Field = new ListGridField("he70");
    	private ListGridField he71Field = new ListGridField("he71");
    	private ListGridField he72Field = new ListGridField("he72");
    	// this list caches all of the hour ending fields as convenience for mass configuration and processing
    	private ArrayList<ListGridField> heFieldList = new ArrayList<ListGridField>();
    	private DateTimeFormat tz = DateTimeFormat.getFormat("z");
    
    	/**
    	 * Constructor builds the screen and starts the refresh timer
    	 * 
    	 * @param screenName
    	 * @param settings
    	 */
    	public QuickQuote(String screenName, Map<String, List<String>> settings)
    	{
    		super("QuickQuote", screenName, settings);
    		setSize("100%", "100%");
    		space.setWidth(15);
    
    		// addMember(getHeader());
    		addMember(getFilter());
    		// addMember(getStatusPanel());
    		addMember(getGrid());
    		addMember(getInfoPanel());
    		refreshTimer.start();
    	}
    
    	/**
    	 * The header includes the PCI logo and the screen title
    	 * 
    	 * @return
    	 */
    	private HLayout getHeader()
    	{
    		Img logo = new Img(LOGO);
    		logo.setWidth("139px");
    		logo.setHeight("56px");
    		HLayout header = new HLayout();
    		header.addMember(logo);
    		header.setHeight(56);
    		Label title = new Label(SCREEN_TITLE);
    		title.setBaseStyle("quickQuoteTitle");
    		title.setWrap(false);
    		header.addMember(title);
    		return header;
    	}
    
    	/**
    	 * Button Panel includes Save, New, Refresh, Print, and Excel. Click events are defined.
    	 * Event logic is encapsulated in corresponding methods
    	 * 
    	 * @return
    	 */
    	private HLayout getButtonPanel()
    	{
    		HLayout buttonPanel = new HLayout();
    		buttonPanel.setHeight(40);
    
    		Button saveButton = new Button("Save");
    		saveButton.addClickHandler(new ClickHandler()
    		{
    			@Override
    			public void onClick(ClickEvent event)
    			{
    				SC.confirm("Are you sure you want to save?", new BooleanCallback()
    				{
    					public void execute(Boolean value)
    					{
    						if (value != null && value)
    						{
    							save();
    						}
    					}
    				});
    			}
    		});
    		buttonPanel.addMember(space);
    		buttonPanel.addMember(saveButton);
    		buttonPanel.addMember(space);
    		// I don't know why it takes two spaces to lay this out, but it does.
    		buttonPanel.addMember(space);
    
    		IButton newButton = new IButton("Add New");
    		newButton.addClickHandler(new ClickHandler()
    		{
    			public void onClick(ClickEvent event)
    			{
    				quickQuoteGrid.startEditingNew();
    			}
    		});
    		buttonPanel.addMember(newButton);
    		buttonPanel.addMember(space);
    
    		Button refreshButton = new Button("Refresh");
    		refreshButton.addClickHandler(new ClickHandler()
    		{
    			@Override
    			public void onClick(ClickEvent event)
    			{
    				refreshGrid();
    			}
    
    		});
    		buttonPanel.addMember(refreshButton);
    		buttonPanel.addMember(space);
    
    		Button printButton = new Button("Print");
    		printButton.addClickHandler(new ClickHandler()
    		{
    			@Override
    			public void onClick(ClickEvent event)
    			{
    				print();
    			}
    
    		});
    		buttonPanel.addMember(printButton);
    		buttonPanel.addMember(space);
    
    		Button excelButton = new Button("Excel");
    		excelButton.addClickHandler(new ClickHandler()
    		{
    			@Override
    			public void onClick(ClickEvent event)
    			{
    				export();
    			}
    		});
    		buttonPanel.addMember(excelButton);
    
    		return buttonPanel;
    	}
    
    	/**
    	 * Shows the Last Run time and the Last Refreshed time
    	 * 
    	 * @return
    	 */
    	private HLayout getInfoPanel()
    	{
    		HLayout infoPanel = new HLayout();
    		infoPanel.setHeight(20);
    
    		Label lastRunLabel = new Label("Last Study Run On");
    		lastRunLabel.setBaseStyle("boldLabel");
    		lastRunLabel.setValign(VerticalAlignment.TOP);
    		lastRunLabel.setWidth(120);
    		infoPanel.addMember(space);
    		infoPanel.addMember(lastRunLabel);
    
    		Label lastRun = new Label("2/19/2013 8:20");
    		lastRun.setValign(VerticalAlignment.TOP);
    		infoPanel.addMember(lastRun);
    
    		Label lastRefreshLabel = new Label("Last Refreshed On");
    		lastRefreshLabel.setBaseStyle("boldLabel");
    		lastRefreshLabel.setWidth(120);
    		lastRefreshLabel.setValign(VerticalAlignment.TOP);
    		infoPanel.addMember(space);
    		infoPanel.addMember(lastRefreshLabel);
    
    		lastRefresh = new Label(new Date().toString());
    		lastRefresh.setValign(VerticalAlignment.TOP);
    		lastRefresh.setWidth(300);
    		infoPanel.addMember(lastRefresh);
    
    		return infoPanel;
    	}
    
    	/**
    	 * This shows status messages with a fade
    	 * 
    	 * @return
    	 */
    	private HLayout getStatusPanel()
    	{
    		HLayout statusPanel = new HLayout();
    		statusLabel = new Label();
    		statusLabel.setOpacity(0);
    		statusLabel.setAnimateFadeTime(2000);
    		// statusLabel.setBackgroundColor("#9de24f");
    		statusLabel.setWidth(400);
    		statusPanel.setHeight(20);
    		statusPanel.addMember(space);
    		statusPanel.addMember(statusLabel);
    		// statusPanel.addMember(getButtonPanel());
    
    		return statusPanel;
    	}
    
    	/**
    	 * Lays out the filter form with start hour, end hour, and study
    	 * 
    	 * @return
    	 */
    	public HLayout getFilter()
    	{
    
    		HLayout filterPanel = new HLayout();
    
    		filterPanel.setHeight(20);
    		DynamicForm filterForm = new DynamicForm();
    
    		studyField.setValueMap("", "RT_Block", "My Study", "Your Study");
    		studyField.setValue("");
    		studyField.setTitleOrientation(TitleOrientation.LEFT);
    
    		startDate.setValue(new Date());
    		startDate.setWrapTitle(false);
    		startDate.setTitleOrientation(TitleOrientation.LEFT);
    
    		endDate.setValue(new Date());
    		endDate.setWrapTitle(false);
    		endDate.setTitleOrientation(TitleOrientation.LEFT);
    
    		IButton filterButton = new IButton("Apply Filter");
    		filterButton.addClickHandler(new ClickHandler()
    		{
    			@Override
    			public void onClick(ClickEvent event)
    			{
    				filterData();
    			}
    		});
    
    		filterForm.setItems(new FormItem[] { studyField, startDate, endDate });
    		filterForm.setNumCols(6);
    		filterForm.setTitleOrientation(TitleOrientation.TOP);
    		filterPanel.addMember(filterForm);
    		filterPanel.addMember(space);
    		filterPanel.addMember(space);
    		filterPanel.addMember(filterButton);
    		filterPanel.addMember(space);
    		filterPanel.addMember(space);
    		filterPanel.addMember(getButtonPanel());
    		filterPanel.addMember(getStatusPanel());
    
    		return filterPanel;
    	}
    
    	/**
    	 * Builds the Quick Quote grid. Hides all Hour Ending fields by default.
    	 * Hour Ending (HE) fields are loaded into a list and configured in their own method for convenience...
    	 * because their are so many. Unlike the other fields, they are declared and instantiated as class
    	 * attributes so that they can be manipulated by other events.
    	 * 
    	 * 
    	 * @return
    	 */
    	public Canvas getGrid()
    	{
    
    		quickQuoteGrid.setShowAllRecords(true);
    		quickQuoteGrid.setAlternateRecordStyles(true);
    		quickQuoteGrid.setShowAllRecords(true);
    		quickQuoteGrid.setDataSource(customDS);
    		quickQuoteGrid.setCanEdit(true);
    		quickQuoteGrid.setLeaveScrollbarGap(false);
    		quickQuoteGrid.setDataFetchMode(FetchMode.LOCAL);
    		quickQuoteGrid.setAutoFetchData(false);
    		quickQuoteGrid.setAlternateRecordStyles(true);
    		quickQuoteGrid.setCanRemoveRecords(false);
    		quickQuoteGrid.setAutoSaveEdits(false);
    		quickQuoteGrid.setCanReorderRecords(true);
    		quickQuoteGrid.setCanResizeFields(true);
    		quickQuoteGrid.setCanSort(false);
    		quickQuoteGrid.setDragDataAction(DragDataAction.COPY);
    		quickQuoteGrid.setCanAcceptDroppedRecords(true);
    		quickQuoteGrid.setInitialSort(new SortSpecifier[] { new SortSpecifier("executed", SortDirection.DESCENDING), new SortSpecifier("executionDate", SortDirection.ASCENDING), new SortSpecifier("createdOn", SortDirection.ASCENDING) });
    		quickQuoteGrid.setGroupByField("executed");
    		quickQuoteGrid.addDataArrivedHandler(new DataArrivedHandler()
    		{
    
    			@Override
    			public void onDataArrived(DataArrivedEvent event)
    			{
    				disableExecutedRecords();
    
    			}
    
    		});
    
    		ListGridField dealNumField = new ListGridField("dealNum");
    		dealNumField.setWidth(50);
    		dealNumField.setCanEdit(false);
    		// dealNumField.setHeaderBaseStyle("noneditableHeader");
    
    		ListGridField orderNumField = new ListGridField("orderNum");
    		orderNumField.setWidth(50);
    		// orderNumField.setHeaderBaseStyle("noneditableHeader");
    		orderNumField.setCanEdit(false);
    
    		SelectItem buySellSelect = new SelectItem();
    		buySellSelect.setValueMap("B", "S");
    		ListGridField buySellField = new ListGridField("buySell");
    		buySellField.setEditorType(buySellSelect);
    		buySellField.setWidth(50);
    		// buySellField.setHeaderBaseStyle("editableHeader");
    
    		ListGridField counterPartyField = new ListGridField("counterParty");
    		counterPartyField.setWidth(75);
    		// counterPartyField.setHeaderBaseStyle("editableHeader");
    
    		ListGridField executedField = new ListGridField("executed");
    		// executedField.setHeaderBaseStyle("editableHeader");
    		executedField.setWidth("175");
    		// this builds a custom formatter to show an html checkbox when there is no executionDate
    		// and the executiondate string when there is one. There is javascript in the onclick for the checkbox
    		// that sets the id to indicate whether or not the field is check. We need to know this when it's time
    		// to save so that we can know whether or not to set the executedDate to the current date/time.
    		executedField.setCellFormatter(new CellFormatter()
    		{
    
    			@Override
    			public String format(Object value, ListGridRecord record, int rowNum, int colNum)
    			{
    				if (record.getAttributeAsDate("executionDate") == null)
    				{
    					notExecutedList.add(rowNum);
    					// return "<form name='execute' action='' method='get'> <input id='" + rowNum + "unchecked' type='checkbox' name='execute' value='' onclick=\"if(document.getElementById('" + rowNum + "unchecked') == null){document.getElementById('" +
    					// rowNum + "checked').id = '" + rowNum + "unchecked'}else{document.getElementById('" + rowNum + "unchecked').id='" + rowNum + "checked'}; return true\" /></form>";
    					return "<input id='" + rowNum + "unchecked' type='checkbox' name='execute' value='' onclick=\"if(document.getElementById('" + rowNum + "unchecked') == null){document.getElementById('" + rowNum + "checked').id = '" + rowNum +
    							"unchecked'}else{document.getElementById('" + rowNum + "unchecked').id='" + rowNum + "checked'}; return true\" />";
    				}
    				else
    				{
    					return record.getAttributeAsDate("executionDate").toString();
    				}
    			}
    
    		});
    
    		// this is a hidden field that holds the execution date. it's used in the process
    		// of clicking the execute checkbox
    		ListGridField executionDate = new ListGridField("executionDate");
    
    		ListGridField transIdField = new ListGridField("transId");
    		transIdField.setWidth(150);
    		// transIdField.setHeaderBaseStyle("editableHeader");
    
    		ListGridField groupField = new ListGridField("group");
    		// groupField.setHeaderBaseStyle("editableHeader");
    		groupField.setWidth(75);
    
    		ListGridField runIdField = new ListGridField("runId");
    		// runIdField.setHeaderBaseStyle("editableHeader");
    		runIdField.setWidth(75);
    
    		ListGridField traderField = new ListGridField("trader");
    		// traderField.setHeaderBaseStyle("editableHeader");
    		traderField.setWidth(75);
    
    		ListGridField deliveryPointField = new ListGridField("deliveryPoint");
    		deliveryPointField.setWidth(75);
    		// deliveryPointField.setHeaderBaseStyle("editableHeader");
    
    		ListGridField commentField = new ListGridField("comment");
    		commentField.setWidth(150);
    		// commentField.setHeaderBaseStyle("editableHeader");
    
    		ListGridField tradePriceField = new ListGridField("tradePrice");
    		tradePriceField.setWidth(100);
    		// tradePriceField.setHeaderBaseStyle("editableHeader");
    
    		SelectItem evaluateMethodSelect = new SelectItem();
    		evaluateMethodSelect.setValueMap("Pricing Matrix", "Redhawk CC1");
    		ListGridField evaluateMethodField = new ListGridField("evaluateMethod");
    		evaluateMethodField.setEditorType(evaluateMethodSelect);
    		evaluateMethodField.setWidth(100);
    		// evaluateMethodField.setHeaderBaseStyle("editableHeader");
    
    		ListGridField breakEvenField = new ListGridField("breakEven");
    		breakEvenField.setWidth(110);
    		breakEvenField.setCanEdit(false);
    		breakEvenField.setBaseStyle("calcStyle");
    		// breakEvenField.setHeaderBaseStyle("calcStyle");
    
    		ListGridField volumeField = new ListGridField("volume");
    		// volumeField.setHeaderBaseStyle("noneditableHeader");
    		volumeField.setCanEdit(false);
    		volumeField.setWidth(75);
    
    		quickQuoteGrid.setFields(
    				dealNumField,
    				buySellField,
    				counterPartyField,
    				executedField,
    				executionDate,
    				transIdField,
    				groupField,
    				runIdField,
    				traderField,
    				deliveryPointField,
    				commentField,
    				tradePriceField,
    				evaluateMethodField,
    				breakEvenField,
    				volumeField,
    				he1Field,
    				he2Field,
    				he3Field,
    				he4Field,
    				he5Field,
    				he6Field,
    				he7Field,
    				he8Field,
    				he9Field,
    				he10Field,
    				he11Field,
    				he12Field,
    				he13Field,
    				he14Field,
    				he15Field,
    				he16Field,
    				he17Field,
    				he18Field,
    				he19Field,
    				he20Field,
    				he21Field,
    				he22Field,
    				he23Field,
    				he24Field,
    				he25Field,
    				he26Field,
    				he27Field,
    				he28Field,
    				he29Field,
    				he30Field,
    				he31Field,
    				he32Field,
    				he33Field,
    				he34Field,
    				he35Field,
    				he36Field,
    				he37Field,
    				he38Field,
    				he39Field,
    				he40Field,
    				he41Field,
    				he42Field,
    				he43Field,
    				he44Field,
    				he45Field,
    				he46Field,
    				he47Field,
    				he48Field,
    				he49Field,
    				he50Field,
    				he51Field,
    				he52Field,
    				he53Field,
    				he54Field,
    				he55Field,
    				he56Field,
    				he57Field,
    				he58Field,
    				he59Field,
    				he60Field,
    				he61Field,
    				he62Field,
    				he63Field,
    				he64Field,
    				he65Field,
    				he66Field,
    				he67Field,
    				he68Field,
    				he69Field,
    				he70Field,
    				he71Field,
    				he72Field
    				);
    
    		quickQuoteGrid.hideField("executionDate");
    		// this must be done to build the list of hour ending fields for mass processing
    		this.loadHEFields();
    		// now we can configure the fields separately
    		configureHEFields();
    		// we want the hour ending fields to be hidden to start with
    		hideAllHEFields();
    
    		return quickQuoteGrid;
    	}
    
    	/**
    	 * It is a requirement that once a record has been checked Executed that it should
    	 * be disabled from editing
    	 */
    	private void disableExecutedRecords()
    	{
    		int length = quickQuoteGrid.getTotalRows();
    
    		for (int i = 0; i < length; i++)
    		{
    			ListGridRecord record = quickQuoteGrid.getRecord(i);
    			// check to see if the deal has been executed and disable it if it has been
    			if (record.getAttributeAsDate("executionDate") != null)
    			{
    				record.setEnabled(false);
    			}
    		}
    
    	}
    
    	/**
    	 * The basic function is to refresh on command. We first ask the
    	 * grid if there have been any edits and if so we give the user a chance to save them.
    	 * doRefresh() has to be called in an if else so that the sequence of prompting a save
    	 * and the refresh is synchronous, otherwise it refreshes before the user can respond
    	 * to the prompt
    	 * 
    	 */
    	private void refreshGrid()
    	{
    		if (quickQuoteGrid.hasChanges())
    		{
    			SC.ask("Refreshing...you have unsaved changes. Save now?", new BooleanCallback()
    			{
    				public void execute(Boolean value)
    				{
    					if (value != null && value)
    					{
    						quickQuoteGrid.saveAllEdits();
    						showStatus("changes saved successfully");
    						doRefresh();
    					}
    					else
    					{
    						quickQuoteGrid.cancelEditing();
    						quickQuoteGrid.discardAllEdits();
    						doRefresh();
    					}
    				}
    			});
    		}
    		else
    		{
    			doRefresh();
    		}
    
    	}
    
    	/**
    	 * This is a helper method used by refreshGrid(). It should NEVER be called from any other method
    	 */
    	private void doRefresh()
    	{
    		quickQuoteGrid.invalidateCache();
    		showHEFields();
    		disableExecutedRecords();
    		lastRefresh.setContents(new Date().toString());
    	}
    
    	/**
    	 * This controls the status messages. It's all fancy and stuff. It disappears with
    	 * a fade after 5 seconds
    	 * 
    	 * @param message
    	 */
    	private void showStatus(String message)
    	{
    		statusLabel.setContents(message);
    		statusLabel.setAnimateFadeTime(50);
    		statusLabel.animateFade(100);
    		setStatusTimer();
    	}
    
    	/**
    	 * This sets the delay for the status message going away
    	 */
    	private void setStatusTimer()
    	{
    		Timer t = new Timer()
    		{
    			public void run()
    			{
    				statusLabel.setAnimateFadeTime(2000);
    				statusLabel.animateFade(0);
    			}
    		};
    		t.schedule(5000);
    	}
    
    	/**
    	 * The class is used with OnTheHourTimer to run refreshGrid on the hour
    	 * 
    	 * @author dwburns
    	 * 
    	 */
    	private class RefreshTask extends OnTheHourTimerTask
    	{
    		@Override
    		public void run()
    		{
    			refreshGrid();
    		}
    	}
    
    	/**
    	 * There are so many hour ending fields that it would be very cumbersome to configure
    	 * all their properties in one giant block. This method uses the heFieldList to loop through
    	 * and dynamically configure each field.
    	 */
    	private void configureHEFields()
    	{
    		Iterator<ListGridField> it = heFieldList.iterator();
    
    		while (it.hasNext())
    		{
    			ListGridField field = it.next();
    			// field.setHeaderBaseStyle("noneditableHeader");
    			field.setWidth(75);
    			field.setCanEdit(false);
    			field.setCanHide(false);
    		}
    
    	}
    
    	/**
    	 * The Hour Ending fields are shown/hidden based on the date/time range filter. This method
    	 * Loops through the heFieldList, tells the grid to show fields, sets headers and tooltips, until the hour ending reaches
    	 * the limit of the endDate filter or until all the fields are shown. Then it hides the rest in case they were shown in
    	 * the previous fetch
    	 */
    	private void showHEFields()
    	{
    
    		Date startDateValue = startDate.getValueAsDate();
    		startDateValue = new Date(startDateValue.getYear(), startDateValue.getMonth(), startDateValue.getDate(), startDateValue.getHours(), 0);
    		Date endDateValue = endDate.getValueAsDate();
    		endDateValue = new Date(endDateValue.getYear(), endDateValue.getMonth(), endDateValue.getDate(), endDateValue.getHours(), 0);
    		Date currentDateValue = startDateValue;
    		int currHour = startDateValue.getHours();
    		int hourEnding = currHour + 1;
    		int i = 0;
    
    		for (; currentDateValue.before(endDateValue) || currentDateValue.equals(endDateValue) && i < heFieldList.size(); i++)
    		{
    			ListGridField heField = heFieldList.get(i);
    			heField.setHeaderTitle("HE " + hourEnding);
    			heField.setPrompt(currentDateValue.toString());
    			quickQuoteGrid.showField(heField.getName());
    			Date nextDate = new Date(currentDateValue.getTime() + (1000 * 60 * 60));
    			currentDateValue = nextDate;
    			currHour = nextDate.getHours();
    			hourEnding = currHour + 1;
    		}
    		i++;
    		for (; i < heFieldList.size(); i++)
    		{
    			quickQuoteGrid.hideFields(heFieldList.get(i).getName());
    		}
    		quickQuoteGrid.redraw();
    	}
    
    	/**
    	 * Hides all the Hour Ending fields.
    	 */
    	private void hideAllHEFields()
    	{
    		Iterator<ListGridField> it = heFieldList.iterator();
    
    		while (it.hasNext())
    		{
    			ListGridField field = it.next();
    			field.setHeaderTitle("");
    			quickQuoteGrid.hideField(field.getName());
    		}
    	}
    
    	/**
    	 * Loads all Hour Ending fields into a list as a convience for processing
    	 */
    	private void loadHEFields()
    	{
    		heFieldList.add(he1Field);
    		heFieldList.add(he2Field);
    		heFieldList.add(he3Field);
    		heFieldList.add(he4Field);
    		heFieldList.add(he5Field);
    		heFieldList.add(he6Field);
    		heFieldList.add(he7Field);
    		heFieldList.add(he8Field);
    		heFieldList.add(he9Field);
    		heFieldList.add(he10Field);
    		heFieldList.add(he11Field);
    		heFieldList.add(he12Field);
    		heFieldList.add(he13Field);
    		heFieldList.add(he14Field);
    		heFieldList.add(he15Field);
    		heFieldList.add(he16Field);
    		heFieldList.add(he17Field);
    		heFieldList.add(he18Field);
    		heFieldList.add(he19Field);
    		heFieldList.add(he20Field);
    		heFieldList.add(he21Field);
    		heFieldList.add(he22Field);
    		heFieldList.add(he23Field);
    		heFieldList.add(he24Field);
    		heFieldList.add(he25Field);
    		heFieldList.add(he26Field);
    		heFieldList.add(he27Field);
    		heFieldList.add(he28Field);
    		heFieldList.add(he29Field);
    		heFieldList.add(he30Field);
    		heFieldList.add(he31Field);
    		heFieldList.add(he32Field);
    		heFieldList.add(he33Field);
    		heFieldList.add(he34Field);
    		heFieldList.add(he35Field);
    		heFieldList.add(he36Field);
    		heFieldList.add(he37Field);
    		heFieldList.add(he38Field);
    		heFieldList.add(he39Field);
    		heFieldList.add(he40Field);
    		heFieldList.add(he41Field);
    		heFieldList.add(he42Field);
    		heFieldList.add(he43Field);
    		heFieldList.add(he44Field);
    		heFieldList.add(he45Field);
    		heFieldList.add(he46Field);
    		heFieldList.add(he47Field);
    		heFieldList.add(he48Field);
    		heFieldList.add(he49Field);
    		heFieldList.add(he50Field);
    		heFieldList.add(he51Field);
    		heFieldList.add(he52Field);
    		heFieldList.add(he53Field);
    		heFieldList.add(he54Field);
    		heFieldList.add(he55Field);
    		heFieldList.add(he56Field);
    		heFieldList.add(he57Field);
    		heFieldList.add(he58Field);
    		heFieldList.add(he59Field);
    		heFieldList.add(he60Field);
    		heFieldList.add(he61Field);
    		heFieldList.add(he62Field);
    		heFieldList.add(he63Field);
    		heFieldList.add(he64Field);
    		heFieldList.add(he65Field);
    		heFieldList.add(he66Field);
    		heFieldList.add(he67Field);
    		heFieldList.add(he68Field);
    		heFieldList.add(he69Field);
    		heFieldList.add(he70Field);
    		heFieldList.add(he71Field);
    		heFieldList.add(he72Field);
    	}
    
    	/**
    	 * batch saves all edits in the grid and sets a status message. it checks to see if the user
    	 * has flagged a deal term for execution and if so sets the executionDate to the current time
    	 */
    	private void save()
    	{
    		try
    		{
    			Integer[] notExecuted = notExecutedList.toArray(new Integer[notExecutedList.size()]);
    			for (int i = 0; i < notExecuted.length; i++)
    			{
    				Integer recordNum = notExecuted[i];
    				Element checkBox = DOM.getElementById(recordNum + "checked");
    				ListGridRecord record = quickQuoteGrid.getRecord(recordNum);
    				Date executionDate = record.getAttributeAsDate("executionDate");
    				if (checkBox != null && executionDate == null)
    				{
    					quickQuoteGrid.setEditValue(recordNum, "executionDate", new Date());
    					quickQuoteGrid.setEditValue(recordNum, "executed", "Executed");
    				}
    			}
    		}
    		catch (Exception ex)
    		{
    			ex.printStackTrace();
    		}
    		notExecutedList.clear();
    		quickQuoteGrid.saveAllEdits();
    		showStatus("changes saved successfully");
    	}
    
    	/**
    	 * launches a print preview screen for the grid
    	 */
    	private void print()
    	{
    		Canvas.showPrintPreview(quickQuoteGrid);
    	}
    
    	/**
    	 * exports the visible columns of the grid to an CSV file to be viewed in MS Excel
    	 */
    	private void export()
    	{
    		DSRequest dsRequestProperties = new DSRequest();
    		dsRequestProperties.setExportAs(ExportFormat.CSV);
    		dsRequestProperties.setExportDisplay(ExportDisplay.DOWNLOAD);
    
    		quickQuoteGrid.exportData(dsRequestProperties);
    	}
    
    	/**
    	 * Fetches the data with the filter criteria
    	 */
    	private void filterData()
    	{
    		Criteria criteria = new Criteria();
    		criteria.addCriteria("study", studyField.getValueAsString());
    		criteria.addCriteria("startDate", startDate.getValueAsDate());
    		criteria.addCriteria("endDate", endDate.getValueAsDate());
    		quickQuoteGrid.fetchData();
    		showHEFields();
    	}
    
    }

    #2
    Use listGrid.redraw() to refresh to show disabled states. setEnabled() logically updated the record but doesn't visually refresh the row automatically (if it did, in cases like this one, it would lead to lots of redundant redraws).

    Comment


      #3
      Unfortunately, this didn't work. Perhaps it's the placement. I put it in the onDataArrived event right after the disable.

      Code:
      quickQuoteGrid.addDataArrivedHandler(new DataArrivedHandler()
      		{
      
      			@Override
      			public void onDataArrived(DataArrivedEvent event)
      			{
      				disableExecutedRecords();
      				quickQuoteGrid.redraw();
      
      			}
      
      		});

      Comment


        #4
        Can you elaborate on "didn't work"? The expectation would be that styling changes visibly. If it doesn't seem to be working, it really seems likely your code isn't being called.

        Comment


          #5
          I verified that the code is being called with the debugger. No visible change AND the row is still editable. I changed strategies altogether. This all works when there are no groupings. Sounds like a bug to me...the only thing I changed was to turn of the grouping.

          Comment


            #6
            The effect of grouping would be that getRecord(index) would return records according to their appearance in the group tree.

            Since the group tree can start out partly or even wholly collapsed (based on groupStartOpen), your code would iterate over only the records from one group, or none at all if the group was fully collapsed.

            You can correct your code to work with getOriginalData() to avoid this.

            Comment


              #7
              Ah HA! I did not anticipate that. Thanks.

              Comment

              Working...
              X