Project

General

Profile

6038-20220204.02.patch

Marian Edu, 02/04/2022 12:52 PM

Download (12.8 KB)

View differences:

new/src/com/goldencode/p2j/ui/ComboBoxWidget.java 2022-02-04 17:24:34 +0000
90 90
**                           if the SCREEN-VALUE is still unknown. 
91 91
**     AL2 20220122          Allow set of unknown value to simple and drop-down modes.
92 92
**         20220124          Moved screen-value validity check in ControlSetEntity.
93
**         20220204          Extend screen-value validation to update the value same as in 4GL.
93 94
*/ 
94 95
/*
95 96
** This program is free software: you can redistribute it and/or modify
......
1323 1324
   }
1324 1325
   
1325 1326
   /**
1326
    * Set the current value in the screen buffer of the backing data for
1327
    * this widget.  If the given value is <code>null</code> then this
1328
    * widget will be set to the uninitialized value.
1329
    *
1330
    * @param    value
1331
    *           The new value for the widget, use <code>null</code> to set
1332
    *           the value as uninitialized.
1333
    */
1334
   @Override
1335
   protected void setScreenValueInt(character value)
1336
   {
1337
      if (!internalScreenValueUsage && !value.isUnknown() && value.getValue().isEmpty())
1338
      {
1339
         value = new character();
1340
      }
1341
      
1342
      super.setScreenValueInt(value);
1343
   }
1344
   
1345
   /**
1346 1327
    * Store array of items into config.
1347 1328
    * 
1348 1329
    * @param    items
......
1579 1560
   @Override
1580 1561
   boolean setScreenValue(ScreenBuffer frameBuf, Object value, boolean inUIStmt)
1581 1562
   {
1582
      if (!internalScreenValueUsage || inUIStmt)
1563
      if (!(value instanceof character))
1583 1564
      {
1584
         // it is valid to assign unknown value (?) only to character drop-down and simple combo-box
1585
         // for default and drop-down-list combo-box, the old screen-value should be kept
1586
         if (value == null ||
1587
            (value instanceof BaseDataType   && 
1588
            !(value instanceof character)    && 
1589
            ((BaseDataType) value).isUnknown()))
1590
         {
1591
            return false;
1592
         }
1593
         
1594
         boolean pairs = (config.pairs != null && config.pairs);
1595
         if ((!pairs || !getScreenValue().isUnknown())      && 
1596
             (value instanceof character)                   && 
1597
             (!((character) value).isUnknown())             &&
1598
             ((character) value).toJavaType().length() == 0)
1599
         {
1600
            // in pair mode an empty string is not allowed if the SCREEN-VALUE is already assigned to  
1601
            // something else, even if an empty string exists 
1602
            // in non-pair mode, an empty string is never allowed.
1603
            return false;
1604
         }
1565
         // we can't set non-character value to selection list
1566
         return false;
1605 1567
      }
1606
      
1568

  
1607 1569
      return super.setScreenValue(frameBuf, value, inUIStmt);
1608 1570
   }
1609 1571

  
......
1619 1581
   protected boolean isValidScreenValue(character value)
1620 1582
   {
1621 1583
      ComboBoxConfig.Mode mode = getAttr("mode", () -> config.mode);
1622
      if (mode == SIMPLE || mode == DROP_DOWN)
1584
      if (mode == SIMPLE || mode == DROP_DOWN || value.isUnknown() || TextOps.isEmpty(value))
1623 1585
      {
1624
         // unknown is a valid screen value for a SIMPLE or DROP-DOWN combo-box widget
1625
         // the screen value to be set shouldn't be part of the item list
1586
         // for a SIMPLE or DROP-DOWN combo-box widget anything works
1587
         // unknown or empty string (or only spaces) clear selection for LIST
1626 1588
         return true;
1627 1589
      }
1628 1590

  
......
1694 1656
         setScreenValueInt(new character(" "));
1695 1657
      }
1696 1658
   }
1659
   
1660
   /**
1661
    * Validate the value(s) for SCREEN-VALUE attribute. If valid the passed in
1662
    * value will be updated to reflect the resulting value.
1663
    * 
1664
    * - empty string will set the value to unknown, unless a valid item value.
1665
    * - for unknown the result can be empty string if a valid item value.
1666
    * - first item found that match the value is used (case insensitive)
1667
    * 
1668
    * @param value
1669
    *        The to be validated as SCREEN-VALUE attribute.
1670
    * 
1671
    * @return <code>true</code> if the value is a valid screen-value.
1672
    */
1673
   @Override
1674
   boolean validateScreenValue(character value)
1675
   {
1676
      if (super.validateScreenValue(value))
1677
      {
1678
         // if valid update the screen-value 
1679
         if (value.isUnknown())
1680
         {
1681
            // looks like when unknown it tries to find an empty item first
1682
            value.assign("");
1683
         }
1684
         
1685
         ControlSetItem[] items = getAttr("items", () -> config.items);
1686
         
1687
         for (ControlSetItem item : items)
1688
         {
1689
            // item found, update value if different case
1690
            if (CompareOps._isEqual(value, item.getCharacterValue()))
1691
            {
1692
               value.assign(item.getCharacterValue());
1693
               return true;
1694
            }
1695
         }
1696
         
1697
         // if value is empty and no matching item found reset to unknown
1698
         if (TextOps.isEmpty(value))
1699
         {
1700
            value.setUnknown();
1701
         }
1702
         
1703
         return true;
1704
      }
1705
      return false;
1706
   }
1697 1707
}
new/src/com/goldencode/p2j/ui/ControlSetEntity.java 2022-02-04 17:19:39 +0000
2857 2857
   {
2858 2858
      if (inUIStmt || !internalScreenValueUsage)
2859 2859
      {
2860
         if (value instanceof character && !validateScreenValue((character) value))
2860
         if (value instanceof character)
2861 2861
         {
2862
            return false;
2862
            character val = new character((character) value);
2863
            
2864
            if (!validateScreenValue((character) val))
2865
            {
2866
               return false;
2867
            }
2868
            // the value might have been updated by validation
2869
            return super.setScreenValue(frameBuf, val, inUIStmt);
2863 2870
         }
2864 2871
      }
2865 2872
      
......
2867 2874
   }
2868 2875
   
2869 2876
   /**
2870
    * Validate the value(s) for SCREEN-VALUE attribute.
2877
    * Validate the value(s) for SCREEN-VALUE attribute. The value passed as
2878
    * input might be updated by specific widget validation.
2871 2879
    * 
2872 2880
    * @param value
2873
    * The to be validated as SCREEN-VALUE attribute.
2881
    *        The to be validated as SCREEN-VALUE attribute.
2874 2882
    * 
2875 2883
    * @return <code>true</code> if the value is a valid screen-value.
2876 2884
    */
new/src/com/goldencode/p2j/ui/RadioSetWidget.java 2022-02-04 17:32:08 +0000
61 61
**     EVL 20210309          Fixed set screen value for several conditions when screen buffer is not updating.
62 62
**     VVT 20220115          System-wide warningAlreadyRealized() method is now used to handle attempts to
63 63
**                           set attribute of a realized widget. See also #5937-32.
64
**     ME  20220204          Reuse/extend the screen-value validation from base class.
64 65
*/ 
65 66
/*
66 67
** This program is free software: you can redistribute it and/or modify
......
1323 1324
      
1324 1325
      return super.getScreenValue(initialized, bdt, fmt, ignoreFormat);
1325 1326
   }
1327

  
1328
   /**
1329
    * Check if the tested value is in the control-set values.
1330
    * Unknown is not valid, empty string is ignored if not a valid value.
1331
    *
1332
    * @param    value
1333
    *           The tested value
1334
    *
1335
    * @return   True if the tested value is in the control-set values, otherwise false.
1336
    */
1337
   @Override
1338
   protected boolean isValidScreenValue(character value)
1339
   {
1340
      return !value.isUnknown() && (TextOps.isEmpty(value) || super.isValidScreenValue(value));
1341
   }
1326 1342
   
1327 1343
   /**
1328
    * Internal worker for setting the SCREEN-VALUE on a per-widget basis.
1329
    * 
1330
    * @param   frameBuf
1331
    *          The frame buffer where to save the value.
1332
    * @param   value
1333
    *          The value to be set via SCREEN-VALUE attribute.
1334
    * @param   inUIStmt
1335
    *          Flag indicating this call originates from a UI statement.
1336
    *          
1337
    * @return  <code>true</code> if the caller can proceed, as the screen-value can be set.
1344
    * Validate the value(s) for SCREEN-VALUE attribute. If valid the passed in
1345
    * value will be updated to reflect the resulting value.
1346
    * 
1347
    * - empty string will set the value to unknown, unless a valid item value.
1348
    * - for unknown the result can be empty string if a valid item value.
1349
    * 
1350
    * @param value
1351
    *        The to be validated as SCREEN-VALUE attribute.
1352
    * 
1353
    * @return <code>true</code> if the value is a valid screen-value.
1338 1354
    */
1339 1355
   @Override
1340
   boolean setScreenValue(ScreenBuffer frameBuf, Object value, boolean inUIStmt)
1356
   boolean validateScreenValue(character value)
1341 1357
   {
1342
      if (frameBuf.getWidgetValue(getId()) != null)
1343
      {
1344
         if (value instanceof character && "".equals(((character) value).toJavaType()))
1345
         {
1346
            return false;
1347
         }
1348
      }
1349
      
1350
      if (value instanceof BaseDataType && !isValidScreenValue(character.valueOf((BaseDataType) value)))
1351
      {
1352
         // show warning if it is from "set screen-value" statements but not from UI statements
1353
         if (!inUIStmt)
1354
         {
1355
            ErrorManager.recordOrShowError(4058, String.format(
1356
                     "Attribute SCREEN-VALUE for the %s %s has an invalid value of %s", type(),
1357
                     widgetName(), ((BaseDataType) value).isUnknown() ? "UNKNOWN" : value), false);
1358
         }
1358
      if (super.validateScreenValue(value))
1359
      {
1360
         ControlSetItem[] items = getAttr("items", () -> config.items);
1359 1361
         
1360
         return false;
1361
      }
1362
      
1363
      return super.setScreenValue(frameBuf, value, inUIStmt);
1364
   }
1365

  
1366
   /**
1367
    * Set the current value in the screen buffer of the backing data for this widget. If the given
1368
    * value is <code>null</code> then this widget will be set to the uninitialized value.
1369
    *
1370
    * @param    value
1371
    *           The new value for the widget, use <code>null</code> to set the value as uninitialized.
1372
    */
1373
   @Override
1374
   protected void setScreenValueInt(character value)
1375
   {
1376
      if (value != null && "".equals(value.toStringMessage()))
1377
      {
1378
         // return silently
1379
         return;
1380
      }
1381
      
1382
      super.setScreenValueInt(value);
1383
   }
1384

  
1362
         for (ControlSetItem item : items)
1363
         {
1364
            // item found, update value if different case
1365
            if (CompareOps._isEqual(value, item.getCharacterValue()))
1366
            {
1367
               value.assign(item.getCharacterValue());
1368
               return true;
1369
            }
1370
         }
1371
      }
1372
      return false;
1373
   }
1374
   
1385 1375
   /**
1386 1376
    * Report missing argument for replace().
1387 1377
    * 
new/src/com/goldencode/p2j/ui/client/RadioSet.java 2022-02-04 11:51:48 +0000
143 143
**     EVL 20210309          Adding saving the currently selected button index.
144 144
**     CA  20210803          If WINDOW:KEEP-FRAME-Z-ORDER is set, a DISPLAY can 'move-to-top' certain widgets.
145 145
**     AL2 20211213          Set the current node when refreshing items list (only when not ChUI).
146
**     ME  20220104          When setting screen-value select first item that match.
146 147
*/
147 148

  
148 149
/*
......
403 404
         character btnValue = new character(button.getValue());
404 405
         character charValue = new character(value);
405 406
         
407
         // first entry that matches (case insensitive)
406 408
         if (btnValue.equals(charValue))
409
         {
407 410
            selectButton(button);
411
            return;
412
         }
408 413
      }
409 414
   }
410 415

  
new/src/com/goldencode/p2j/ui/client/gui/ComboBoxGuiImpl.java 2022-02-04 06:44:33 +0000
93 93
**     CA  20210805 The entry-field for a combo-box must always be 'on top' of the combo-box.
94 94
**     CA  20210818 Fixed setHidden, setVisible, moveToTop and moveToBottom for SIMPLE and DROP-DOWN mode. 
95 95
**     VVT 20220126 Updated after methods 'index' and 'select(int)' were renamed in DefaultList. See #5937.
96
**     ME  20220204 Unknown screen-value is shown as empty string instead of question mark.
96 97
*/
97 98

  
98 99
/*
......
982 983

  
983 984
         if (entryField != null)
984 985
         {
985
            entryField.setValue(listValue ? new character(model().selected()) : value);
986
            if (listValue)
987
            {
988
               entryField.setValue(new character(model().selected()));
989
            }
990
            else 
991
            {
992
               // unknown is shown as empty string instead of question mark
993
               entryField.setValue(value.isUnknown() ? new character("") : value);
994
            }
986 995
         }
987 996
      }
988 997
   }