Announcement

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

    Hilites do not match gird data

    Hilites do not match gird data

    All I want to do is color the entire row, based on one field.
    I reworked your Simulated Stock Quotes Example in the EE showcase to use hilites.

    First a button to launch a window
    Code:
    IButton button = new IButton("launch window");        
    button.addClickHandler(new ClickHandler()
    {
    	int count = 1;
      @Override
    	public void onClick(ClickEvent clickEvent)
    	{
    		new GuiWidgetLab("window" + count++).show();
    	}
    });
    Click the button -> launch window 0 -> The servlet turns on updates for the next 90 seconds -> the updates go into the datasource -> the data updates -> the hilites update.
    wait for the updates to end.
    Click the button -> launch window 1 -> The servlet turns on updates for the next 90 seconds -> the updates go into the datasource -> the data updates -> the hilites update in all windows ( in window 1 they are correct. Window 0 they are not.)
    wait for the updates to end.
    Click the button -> launch window 2 -> The servlet turns on updates for the next 90 seconds -> the updates go into the datasource -> the data updates -> the hilites update in all windows ( in window 2 they are correct. Window 0 and window 1, they are not. )

    The end state of the hilites for windows 0 and 1, is normally wrong (green rows with negitive change values, or red rows with positive), and windoww 1 doesn't match window 0.

    The latest window, the hilite state is correct.


    Code:
    /*
     * Isomorphic SmartGWT web presentation layer
     * Copyright (c) 2011 Isomorphic Software, Inc.
     *
     * OWNERSHIP NOTICE
     * Isomorphic Software owns and reserves all rights not expressly granted in this source code,
     * including all intellectual property rights to the structure, sequence, and format of this code
     * and to all designs, interfaces, algorithms, schema, protocols, and inventions expressed herein.
     *
     *  If you have any questions, please email <sourcecode@isomorphic.com>.
     *
     *  This entire comment must accompany any portion of Isomorphic Software source code that is
     *  copied or moved from this file.
     */
    
    
    import com.google.gwt.core.client.JavaScriptObject;
    import com.google.gwt.user.client.Timer;
    import com.smartgwt.client.data.*;
    import com.smartgwt.client.rpc.Messaging;
    import com.smartgwt.client.rpc.MessagingCallback;
    import com.smartgwt.client.rpc.RPCManager;
    import com.smartgwt.client.rpc.RPCRequest;
    import com.smartgwt.client.types.DSOperationType;
    import com.smartgwt.client.types.OperatorId;
    import com.smartgwt.client.util.JSOHelper;
    import com.smartgwt.client.widgets.Button;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.List;
    
    public class GuiWidgetLab extends Window
    {
        private ListGrid stockQuotesGrid;
    
        public GuiWidgetLab(String title)
        {
            super();
            setTitle(title);
            setWidth("50%");
            setHeight("50%");
            final long startParameter = System.currentTimeMillis();
    
            // Grid and button below it
            setMembersMargin(10);
            setPadding(10);
    
            stockQuotesGrid = new ListGrid();
            stockQuotesGrid.setWidth(600);
            stockQuotesGrid.setHeight(300);
            stockQuotesGrid.setShowAllRecords(true);
            stockQuotesGrid.setDataSource(StockQuotesDS.getInstance());
            stockQuotesGrid.setAutoFetchData(true);
            stockQuotesGrid.enableHiliting();
            stockQuotesGrid.setCanEditHilites(false);
            stockQuotesGrid.setIncludeHilitesInSummaryFields(true);
    
    
            List<ListGridField> fieldList = new ArrayList<>(StockQuotesDS.getInstance().getFields().length);
            fieldList.add(new ListGridField("id"));
            fieldList.add(new ListGridField("name"));
            fieldList.add(new ListGridField("symbol"));
            fieldList.add(new ListGridField("lastValue"));
            fieldList.add(new ListGridField("changeValue"));
            fieldList.add(new ListGridField("openValue"));
            fieldList.add(new ListGridField("dayHighValue"));
            fieldList.add(new ListGridField("dayLowValue"));
            ListGridField lastUpdatedField = new ListGridField("lastUpdated");
            lastUpdatedField.setHidden(true);
            fieldList.add(lastUpdatedField);
    
            ListGridField[] fields = fieldList.toArray(new ListGridField[fieldList.size()]);
            stockQuotesGrid.setFields(fields);
            stockQuotesGrid.setHilites(buildHilites(fields));
            addItem(stockQuotesGrid);
    
            final Button generateUpdatesButton = new Button("Generate more updates");
            generateUpdatesButton.setWidth(200);
            generateUpdatesButton.addClickHandler(new ClickHandler()
            {
                @Override
                public void onClick(ClickEvent event)
                {
                    generateUpdates(startParameter, generateUpdatesButton);
                }
            });
            addItem(generateUpdatesButton);
            // receive messages from the stockQuotes channel and update data grid
            Messaging.subscribe("stockQuotes" + startParameter, new MessagingCallback() {
                @Override
                public void execute(Object data) {
                    updateStockQuotes(data);
                }
            });
    
            generateUpdates(startParameter, generateUpdatesButton);
        }
    
        /**
         * We get id and changeValue only from server - combine it with the record
         * in the grid to get the rest of the fields
         *
         * @param data
         */
        @SuppressWarnings("unchecked")
        private void updateStockQuotes(Object data) {
            List<List<?>> stockData = (List<List<?>>) JSOHelper
                    .convertToJava((JavaScriptObject) data);
            List<Record> newStockData = new ArrayList<Record>();
            // prepare data for grid manually using received data from servlet
            // we receive only 'id' and 'change percent' data here
            for (List<?> recordData : stockData) {
                float change = ((Number) recordData.get(1)).floatValue();
                if (change != 0) {
                    final Integer id = (Integer) recordData.get(0);
                    Record record = stockQuotesGrid.getDataAsRecordList().find("id", id);
                    float lastValue = record.getAttributeAsFloat("lastValue");
                    float newChangeValue = change * lastValue / 100;
                    float newLastValue = newChangeValue + lastValue;
                    record.setAttribute("changeValue", newChangeValue);
                    record.setAttribute("lastValue", newLastValue);
                    record.setAttribute("dayHighValue",
                            Math.max(record.getAttributeAsFloat("dayHighValue"), newLastValue));
                    record.setAttribute("dayLowValue",
                            Math.min(record.getAttributeAsFloat("dayLowValue"), newLastValue));
                    record.setAttribute("lastUpdated", new Date());
                    newStockData.add(record);
    
                    new Timer()
                    {
                        @Override
                        public void run()
                        {
                            Record record = stockQuotesGrid.getDataAsRecordList().find("id", id);
                            if(record.getAttribute("lastUpdated") != null)
                            {
                                Date lastUpdated = record.getAttributeAsDate("lastUpdated");
                                long delta = System.currentTimeMillis() - lastUpdated.getTime();
                                if(delta >= blinkPeriod)
                                {
                                    record.setAttribute("lastUpdated", (Date) null);
                                }
                                DSResponse dsResponse = new DSResponse();
                                Record[] toUpdate = new Record[] {record};
                                dsResponse.setData(toUpdate);
    
                                DSRequest dsRequest = new DSRequest();
                                dsRequest.setOperationType(DSOperationType.UPDATE);
                                // broadcast the change - the grid will notice this automatically (and so would other
                                // components showing the same record)
                                StockQuotesDS.getInstance().updateCaches(dsResponse, dsRequest);
    
                            }
                        }
                    }.schedule(blinkPeriod);
                }
            }
    
            DSResponse dsResponse = new DSResponse();
            dsResponse.setData((Record[]) newStockData.toArray(new Record[newStockData.size()]));
    
            DSRequest dsRequest = new DSRequest();
            dsRequest.setOperationType(DSOperationType.UPDATE);
            // broadcast the change - the grid will notice this automatically (and so would other
            // components showing the same record)
            StockQuotesDS.getInstance().updateCaches(dsResponse, dsRequest);
        }
        private int blinkPeriod = 2000;
    
        private void generateUpdates(final long startParameter, final Button generateUpdatesButton) {
            generateUpdatesButton.disable();
            RPCRequest request = new RPCRequest();
            // we tells servlet which channel it should use for sending data
            request.setActionURL("examples/StockQuotes/generate?sp=" + startParameter);
            RPCManager.sendRequest(request);
            // block button repeat click for 90 seconds - time while servlet
            // will send data to us
            new Timer() {
                public void run() {
                    generateUpdatesButton.enable();
                }
            }.schedule(90000);
        }
    
    
        public static Hilite[] buildHilites(ListGridField... fields)
        {
            String [] names = new String[fields.length];
            int i = 0;
            for(ListGridField field: fields)
            {
                names[i] = field.getName();
                i++;
            }
            return buildHilites(names);
        }
    
        public static Hilite[] buildHilites(String... fields)
        {
            List<Hilite> lites= buildHilitesList(fields);
            return lites.toArray(new Hilite[lites.size()]);
        }
    
        public static List<Hilite> buildHilitesList(String... fields)
        {
            List<Hilite> lites= new ArrayList<>();
            lites.add(buildHilite("#000000", "#FF0000", fields, new Criterion("changeValue", OperatorId.LESS_THAN, 0f) ));
            lites.add(buildHilite("#000000", "#00FF00", fields, new Criterion("changeValue", OperatorId.GREATER_THAN, 0f)));
            lites.add(buildHilite("#000000", "#FFFFFF", fields, new Criterion("changeValue", OperatorId.EQUALS, 0f)));
            lites.add(buildHiliteNull("#000000", "#FFFFFF", fields, "lastUpdated"));
            return lites;
        }
    
        public static Hilite buildHilite(String textColor, String bkgrndColor, String[] hiliteFields, Criterion ... criterions)
        {
            Hilite build = new Hilite();
            build.setTextColor(textColor);
            build.setBackgroundColor(bkgrndColor);
            build.setFieldNames(hiliteFields);
            if(criterions == null || criterions.length <= 0 )
            {
                return build;
            }
            AdvancedCriteria criteria = new AdvancedCriteria(OperatorId.OR, criterions);
            build.setCriteria(criteria);
            return build;
        }
        public static Hilite buildHiliteNull(String textColor, String bkgrndColor, String[] hiliteFields, String criteriaField)
        {
            Hilite build = new Hilite();
            build.setTextColor(textColor);
            build.setBackgroundColor(bkgrndColor);
            build.setFieldNames(hiliteFields);
    
            List<Criterion> criterionList = new ArrayList<>(1);
                criterionList.add(new Criterion(criteriaField, OperatorId.IS_NULL ));
            AdvancedCriteria criteria = new AdvancedCriteria(OperatorId.OR, criterionList.toArray(new Criterion[criterionList.size()]));
            build.setCriteria(criteria);
            return build;
        }
    
    
    }


    1. SmartClient Version: v9.1p_2014-12-12/PowerEdition Deployment (built 2014-12-12)

    2. FF 33.1.1
    Chrome 39.0.2171.95m

    3. - 5. n/a

    6. see above

    #2
    It looks like you are expecting the servlet to publish updates to all 3 browsers, but it's not designed to do that. Note how each instance of the sample subscribes to it's own unique channel name based on the timestamp when the sample was started, and likewise, passes that timestamp to the servlet so that updates are generated only on that channel.

    Comment


      #3
      Who said anything about 3 browsers? Run all 3 in the same browser with the same session.

      Then the client code parses the new data, gets the old record from the grid,
      interweaves the new data into the old, then publishes the change via the datasource:
      StockQuotesDS.getInstance().updateCaches(dsResponse, dsRequest);

      The windows would have to share the same datasource to share the same data.

      Code:
       
           private void updateStockQuotes(Object data) {
              List<List<?>> stockData = (List<List<?>>) JSOHelper
                      .convertToJava((JavaScriptObject) data);
              List<Record> newStockData = new ArrayList<Record>();
              // prepare data for grid manually using received data from servlet
              // we receive only 'id' and 'change percent' data here
              for (List<?> recordData : stockData) {
                  float change = ((Number) recordData.get(1)).floatValue();
                  if (change != 0) {
                      final Integer id = (Integer) recordData.get(0);
                      Record record = stockQuotesGrid.getDataAsRecordList().find("id", id);
                      float lastValue = record.getAttributeAsFloat("lastValue");
                      float newChangeValue = change * lastValue / 100;
                      float newLastValue = newChangeValue + lastValue;
                      record.setAttribute("changeValue", newChangeValue);
                      record.setAttribute("lastValue", newLastValue);
                      record.setAttribute("dayHighValue",
                              Math.max(record.getAttributeAsFloat("dayHighValue"), newLastValue));
                      record.setAttribute("dayLowValue",
                              Math.min(record.getAttributeAsFloat("dayLowValue"), newLastValue));
                      record.setAttribute("lastUpdated", new Date());
                      newStockData.add(record);
      
                      new Timer()
                      {
                          @Override
                          public void run()
                          {
                              Record record = stockQuotesGrid.getDataAsRecordList().find("id", id);
                              if(record.getAttribute("lastUpdated") != null)
                              {
                                  Date lastUpdated = record.getAttributeAsDate("lastUpdated");
                                  long delta = System.currentTimeMillis() - lastUpdated.getTime();
                                  if(delta >= blinkPeriod)
                                  {
                                      record.setAttribute("lastUpdated", (Date) null);
                                  }
                                  DSResponse dsResponse = new DSResponse();
                                  Record[] toUpdate = new Record[] {record};
                                  dsResponse.setData(toUpdate);
      
                                  DSRequest dsRequest = new DSRequest();
                                  dsRequest.setOperationType(DSOperationType.UPDATE);
                                  // broadcast the change - the grid will notice this automatically (and so would other
                                  // components showing the same record)
                                  StockQuotesDS.getInstance().updateCaches(dsResponse, dsRequest);
      
                              }
                          }
                      }.schedule(blinkPeriod);
                  }
              }
      
              DSResponse dsResponse = new DSResponse();
              dsResponse.setData((Record[]) newStockData.toArray(new Record[newStockData.size()]));
      
              DSRequest dsRequest = new DSRequest();
              dsRequest.setOperationType(DSOperationType.UPDATE);
              // broadcast the change - the grid will notice this automatically (and so would other
              // components showing the same record)
              StockQuotesDS.getInstance().updateCaches(dsResponse, dsRequest);
          }

      Code:
      
      

      Comment


        #4
        Sorry for the confusion about "3 browsers". To clarify, each Window subscribes separately, but all ListGrids receive the updates since updateCaches() is being used and they all share a DataSource.

        But the problem is your call to updateStockQuotes() uses the data from the current Window's grid, and calculates deltas and highs based on that the current Window's data, but then publishes those updates to all grids, which at that point have different data. This means the updates don't make sense for the previous Windows - they basically corrupt the data.

        Comment


          #5
          If what you are saying was true:

          I would suspect that the grid that was receiving the updates would update the datasouce mis-aligning the other 2.

          Also I would suspect that each grid would display different values, yet they all display the same data. (That part is correct at least) The Hilite state changes, but not correctly.


          Keeping It such that only one grid is receiving updates, (let's not make this harder by allowing all grids to update at once) click the "generate more updates" button on window 0 or 1.

          The last grid created is the only correct one, Destroying a newer grid cause the grid created prior to the newly destroyed one to display correctly.

          Comment


            #6
            Yes, any one grid you update will mess up the other two.

            And they will all display the same data because they all receive the same updateCaches() calls.

            The problem is, when each grid receives updates, it will make a different assessment of whether a field value has actually changed, and thus refresh or not refresh the hilites, differently from other grids.

            Comment


              #7
              1/3

              Okay Refactor the Data Source to client only
              Add a result set, so that there is a source for the correct data.
              Add the lastUpdated field just for complete correctness.

              Code:
              class StockQuotesDS extends DataSource {
                  // The DataSource would normally be defined external to any classes that use it.  
              
                  private static StockQuotesDS instance = null;
              
                  public static StockQuotesDS getInstance() {
                      if (instance == null) {
                          instance = new StockQuotesDS("stockQuotesDS_DS");
                      }
                      return instance;
                  }
                  private static ResultSet resultSet = null;
              
                  public static ResultSet getResultSet() {
                      if (resultSet == null) {
                          resultSet = new ResultSet(getInstance());
                          resultSet.getRange(0, resultSet.getLength());
                      }
                      return resultSet;
                  }
              
                  public StockQuotesDS(String id) {
                      setID(id);
                      setRecordXPath("/List/stockQuotes");
                      setClientOnly(true);
              
                      DataSourceField idField = new DataSourceField("id", FieldType.INTEGER, "Id");
                      idField.setHidden(Boolean.TRUE);
                      idField.setPrimaryKey(Boolean.TRUE);
                      DataSourceField nameField = new DataSourceField("name", FieldType.TEXT, "Name");
                      nameField.setAttribute("width", 200);
                      DataSourceField symbolField = new DataSourceField("symbol", FieldType.TEXT, "Symbol");
                      DataSourceField lastValueField = new DataSourceField("lastValue", FieldType.FLOAT, "Last");
                      lastValueField.setDecimalPrecision(2);
                      DataSourceField changeValueField = new DataSourceField("changeValue", FieldType.FLOAT, "Change");
                      changeValueField.setDecimalPrecision(2);
                      DataSourceField openValueField = new DataSourceField("openValue", FieldType.FLOAT, "Open");
                      DataSourceField dayHighValueField = new DataSourceField("dayHighValue", FieldType.FLOAT, "DayHigh");
                      dayHighValueField.setDecimalPrecision(2);
                      DataSourceField dayLowValueField = new DataSourceField("dayLowValue", FieldType.FLOAT, "DayLow");
                      dayLowValueField.setDecimalPrecision(2);
                      DataSourceField lastUpdated = new DataSourceField("lastUpdated", FieldType.DATETIME, "LastUpdated");
                      lastUpdated.setHidden(true);
              
                      setFields(idField, nameField, symbolField, lastValueField, changeValueField, openValueField, dayHighValueField, dayLowValueField, lastUpdated);
                      setDataURL("ds/test_data/stockQuotes.data.xml");
                  }

              Comment


                #8
                2/3

                First bind to the result set instead of the auto fetching.
                Second Remove the updates from the constructor, to aid update control.
                Third toss in some buttons to see what they do.
                Fourth ensure the grid is destroyed.
                Lastly use the result set to get the data for updates.

                Code:
                  public GuiWidgetLab(String title)
                    {
                        super();
                        setTitle(title);
                        setWidth("50%");
                        setHeight("50%");
                        final long startParameter = System.currentTimeMillis();
                
                        // Grid and button below it
                        setMembersMargin(10);
                        setPadding(10);
                
                        stockQuotesGrid = new ListGrid();
                        stockQuotesGrid.setWidth(600);
                        stockQuotesGrid.setHeight(300);
                        stockQuotesGrid.setShowAllRecords(true);
                        stockQuotesGrid.setDataSource(StockQuotesDS.getInstance());
                        //stockQuotesGrid.setAutoFetchData(true);
                		        // bind the grid to the result set
                        stockQuotesGrid.setData(StockQuotesDS.getResultSet());
                		
                        stockQuotesGrid.enableHiliting();
                        stockQuotesGrid.setCanEditHilites(false);
                        stockQuotesGrid.setIncludeHilitesInSummaryFields(true);
                
                
                        List<ListGridField> fieldList = new ArrayList<>(StockQuotesDS.getInstance().getFields().length);
                        fieldList.add(new ListGridField("id"));
                        fieldList.add(new ListGridField("name"));
                        fieldList.add(new ListGridField("symbol"));
                        fieldList.add(new ListGridField("lastValue"));
                        fieldList.add(new ListGridField("changeValue"));
                        fieldList.add(new ListGridField("openValue"));
                        fieldList.add(new ListGridField("dayHighValue"));
                        fieldList.add(new ListGridField("dayLowValue"));
                        ListGridField lastUpdatedField = new ListGridField("lastUpdated");
                		//expose All the data
                        //lastUpdatedField.setHidden(true);
                        fieldList.add(lastUpdatedField);
                
                        ListGridField[] fields = fieldList.toArray(new ListGridField[fieldList.size()]);
                        stockQuotesGrid.setFields(fields);
                        stockQuotesGrid.setHilites(buildHilites(fields));
                        addItem(stockQuotesGrid);
                
                        final Button generateUpdatesButton = new Button("Generate more updates");
                        generateUpdatesButton.setWidth(200);
                        generateUpdatesButton.addClickHandler(new ClickHandler()
                        {
                            @Override
                            public void onClick(ClickEvent event)
                            {
                                generateUpdates(startParameter, generateUpdatesButton);
                            }
                        });
                		
                		
                        final Button redrawButton = new Button("Redraw");
                        redrawButton.setWidth(200);
                        redrawButton.addClickHandler(new ClickHandler()
                        {
                            @Override
                            public void onClick(ClickEvent event)
                            {
                                stockQuotesGrid.redraw();
                            }
                        });
                        addItem(redrawButton);
                
                        final Button rowRefresh = new Button("rowRefresh");
                        rowRefresh.setWidth(200);
                        rowRefresh.addClickHandler(new ClickHandler()
                        {
                            @Override
                            public void onClick(ClickEvent event)
                            {
                                for (int i = 0; i< stockQuotesGrid.getTotalRows(); i++)
                                {
                                    stockQuotesGrid.refreshRow(i);
                                }
                            }
                        });
                        addItem(rowRefresh);
                
                        final Button redataGrid = new Button("redataGrid");
                        redataGrid.setWidth(200);
                        redataGrid.addClickHandler(new ClickHandler()
                        {
                            @Override
                            public void onClick(ClickEvent event)
                            {
                                stockQuotesGrid.setData(StockQuotesDS.getResultSet());
                
                            }
                        });
                        addItem(redataGrid);
                
                
                
                		
                        addItem(generateUpdatesButton);
                        // receive messages from the stockQuotes channel and update data grid
                        Messaging.subscribe("stockQuotes" + startParameter, new MessagingCallback() {
                            @Override
                            public void execute(Object data) {
                                updateStockQuotes(data);
                            }
                        });
                		
                		addCloseClickHandler(new CloseClickHandler()
                        {
                            @Override
                            public void onCloseClick(CloseClickEvent closeClickEvent)
                            {
                                destroy();
                            }
                        });
                
                
                        // move from showcase to test case.
                //        generateUpdates(startParameter, generateUpdatesButton);
                    }
                
                    /**
                     * We get id and changeValue only from server - combine it with the record
                     * in the grid to get the rest of the fields
                     *
                     * @param data
                     */
                    @SuppressWarnings("unchecked")
                    private void updateStockQuotes(Object data) {
                        List<List<?>> stockData = (List<List<?>>) JSOHelper
                                .convertToJava((JavaScriptObject) data);
                        List<Record> newStockData = new ArrayList<Record>();
                        // prepare data for grid manually using received data from servlet
                        // we receive only 'id' and 'change percent' data here
                        for (List<?> recordData : stockData) {
                            float change = ((Number) recordData.get(1)).floatValue();
                            if (change != 0) {
                                final Integer id = (Integer) recordData.get(0);
                                ResultSet set = StockQuotesDS.getResultSet();
                //                Record record = stockQuotesGrid.getDataAsRecordList().find("id", id);
                                Record record = set.find("id", id);
                                float lastValue = record.getAttributeAsFloat("lastValue");
                                float newChangeValue = change * lastValue / 100;
                                float newLastValue = newChangeValue + lastValue;
                                record.setAttribute("changeValue", newChangeValue);
                                record.setAttribute("lastValue", newLastValue);
                                record.setAttribute("dayHighValue",
                                        Math.max(record.getAttributeAsFloat("dayHighValue"), newLastValue));
                                record.setAttribute("dayLowValue",
                                        Math.min(record.getAttributeAsFloat("dayLowValue"), newLastValue));
                                record.setAttribute("lastUpdated", new Date());
                                newStockData.add(record);
                
                                new Timer()
                                {
                                    @Override
                                    public void run()
                                    {
                                        Record record = stockQuotesGrid.getDataAsRecordList().find("id", id);
                                        if(record.getAttribute("lastUpdated") != null)
                                        {
                                            Date lastUpdated = record.getAttributeAsDate("lastUpdated");
                                            long delta = System.currentTimeMillis() - lastUpdated.getTime();
                                            if(delta >= blinkPeriod)
                                            {
                                                record.setAttribute("lastUpdated", (Date) null);
                                            }
                                            DSResponse dsResponse = new DSResponse();
                                            Record[] toUpdate = new Record[] {record};
                                            dsResponse.setData(toUpdate);
                
                                            DSRequest dsRequest = new DSRequest();
                                            dsRequest.setOperationType(DSOperationType.UPDATE);
                                            // broadcast the change - the grid will notice this automatically (and so would other
                                            // components showing the same record)
                                            StockQuotesDS.getInstance().updateCaches(dsResponse, dsRequest);
                
                                        }
                                    }
                                }.schedule(blinkPeriod);
                            }
                        }
                
                        DSResponse dsResponse = new DSResponse();
                        dsResponse.setData((Record[]) newStockData.toArray(new Record[newStockData.size()]));
                
                        DSRequest dsRequest = new DSRequest();
                        dsRequest.setOperationType(DSOperationType.UPDATE);
                        // broadcast the change - the grid will notice this automatically (and so would other
                        // components showing the same record)
                        StockQuotesDS.getInstance().updateCaches(dsResponse, dsRequest);
                    }

                Comment


                  #9
                  3/3

                  Now I can open 2 windows with no updates being generated, thus they should make independent assessment of whether a field value has actually changed, starting at the same state arriving at the same result. And they should stay in sync.

                  Activate updates: They stay roughly in sync, wait for the updates to finish.

                  Now open the third window. Which should pull the same data from the result set and appears to be in the same state as the other 2.

                  Activate updates: 1 and 2 are in sync and wrong. 3 is correct.

                  Wait for the updates to finish
                  Destroy window 3
                  Activate updates: 1 and 2 are in sync and correct.

                  How is it that Window 3 Changes the assessment of the hilite state of windows 1 and 2? How does it reset the assessment of the hilite state of windows 1 and 2 when it is destroyed?

                  -------------------------------------------------------------------------------
                  All I want to do is color the entire row, based on one field.

                  Comment


                    #10
                    Your technique for declaring the hilite is fine, but you keep writing broken test cases.

                    The problem here is basically the same as last time: some of the grids are receiving updates which the grids detect as not changing the value of the hilited field.

                    This time, you've done this in two separate ways!

                    1. updateStockQuotes() actually grabs the record from one of the grids and modifies it in place. So when the grid receives the update, it finds it's cached record already has the changes

                    2. all grids have the exact same dataset, so the first grid to receive the update information could detect a delta, but the rest won't, since the first grid will already have updated the ResultSet.

                    Comment


                      #11
                      A short summary of our current architecture:

                      Server side:
                      CDI events are observed on the entities behind the data source, they are converted to maps, and sent to clients using an RTMS channel.
                      [code]
                      Map data = ds.getProperties(o);
                      ...
                      ISCMessageDispatcher.instance().send(new ISCMessage(Constants.DATASOURCE_CHANNEL, message));
                      [\code]

                      On the client
                      we reconstuct the data from the rtms message.
                      [code]
                      private void updateDsCache(DataSource ds, ListGridRecord[] data, DSOperationType type) {
                      DSResponse response = new DSResponse();
                      response.setData(data);
                      DSRequest request = new DSRequest();
                      request.setDataSource(ds.getID());
                      request.setOperationType(type);
                      ds.updateCaches(response, request);
                      [\code]
                      Note that the entire record is sent and no grid or result set is queried for the data.


                      I now need to add into this architecture, 2 similar views of a new entity.
                      Given that there are multiple fields and all the rows in both views.
                      I chose list grids and the 2 list grids have near identical configuration, except which fields are displayed.
                      I have a requirement to draw users attention to rows based on the state of the one field.
                      It was suggested to change the background color for the row.
                      I chose hilites to accomplish that, since the field in the criteria for the hilites is in both grids.

                      Given the architecture above, How would you accomplish this using anything in your framework?


                      Here is the current configuration:
                      [code]
                      grid = new ListGrid()
                      grid.setCanExpandRecords(true);
                      grid.setCanExpandMultipleRecords(false);

                      grid.setSelectionType(SelectionStyle.SIMPLE);
                      grid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
                      grid.setCanSelectAll(true);
                      grid.setReselectOnUpdate(true);
                      grid.setReselectOnUpdateNotifications(SelectionNotificationType.NONE);
                      grid.addSelectionUpdatedHandler(new SelectionUpdatedHandler()
                      {
                      ...
                      });
                      grid.setOverflow(Overflow.VISIBLE);
                      grid.setBodyOverflow(Overflow.VISIBLE);

                      grid.setDataSource(ds);
                      grid.setCanEdit(false);
                      grid.setAutoFetchData(true);
                      grid.setAutoFitWidthApproach(AutoFitWidthApproach.VALUE);

                      grid.enableHiliting();
                      grid.setCanEditHilites(false);
                      grid.setIncludeHilitesInSummaryFields(true);

                      ... Fields are constructed here

                      ListGridField[] gridFields = fields.toArray(new ListGridField[fields.size()]);
                      grid.setFields(gridFields);
                      grid.setHilites(new HiliteFactory().ViewHilites(gridFields));
                      [\code]

                      Comment


                        #12
                        What you're already doing in your samples is fine: just apply hilites. The grid will automatically update the hilites when you call updateCaches().

                        You seem to think that this won't work; in fact each of your attempts at standalone samples has had one flaw or another that we've pointed out. The code you've outlined here would not have any of those problems.

                        Comment

                        Working...
                        X