Project

General

Profile

6038-20220204.patch

Marian Edu, 02/04/2022 07:19 AM

Download (11.6 KB)

View differences:

new/src/com/goldencode/p2j/ui/ComboBoxWidget.java 2022-02-04 06:42:58 +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.
1662
    * 
1663
    * If valid the SCREEN-VALUE will be updated to reflect the resulting value.
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
    * 
1667
    * @param value
1668
    *        The to be validated as SCREEN-VALUE attribute.
1669
    * 
1670
    * @return <code>true</code> if the value is a valid screen-value.
1671
    */
1672
   @Override
1673
   boolean validateScreenValue(character value)
1674
   {
1675
      if (super.validateScreenValue(value))
1676
      {
1677
         // if valid update the screen-value 
1678
         if (value.isUnknown())
1679
         {
1680
            // looks like when unknown it tries to find an empty item first
1681
            value.assign("");
1682
         }
1683
         
1684
         ControlSetItem[] items = getAttr("items", () -> config.items);
1685
         
1686
         for (ControlSetItem item : items)
1687
         {
1688
            // item found, update value if different case
1689
            if (CompareOps._isEqual(value, item.getCharacterValue()))
1690
            {
1691
               value.assign(item.getCharacterValue());
1692
               return true;
1693
            }
1694
         }
1695
         
1696
         // if value empty and not valid value reset to unknown
1697
         if (TextOps.isEmpty(value))
1698
         {
1699
            value.setUnknown();
1700
         }
1701
         
1702
         return true;
1703
      }
1704
      return false;
1705
   }
1697 1706
}
new/src/com/goldencode/p2j/ui/RadioSetWidget.java 2022-02-04 11:53:23 +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
   }
1326
   
1327
   /**
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.
1338
    */
1339
   @Override
1340
   boolean setScreenValue(ScreenBuffer frameBuf, Object value, boolean inUIStmt)
1341
   {
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
         }
1359
         
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 1327

  
1385 1328
   /**
1386 1329
    * Report missing argument for replace().
......
1414 1357
            false);
1415 1358
      return new logical(false);
1416 1359
   }
1360
   
1361
   /**
1362
    * Check if the tested value is in the control-set values.
1363
    * Unknown is not valid, empty string is ignored if not a valid value.
1364
    *
1365
    * @param    value
1366
    *           The tested value
1367
    *
1368
    * @return   True if the tested value is in the control-set values, otherwise false.
1369
    */
1370
   @Override
1371
   protected boolean isValidScreenValue(character value)
1372
   {
1373
      return !value.isUnknown() && (TextOps.isEmpty(value) || super.isValidScreenValue(value));
1374
   }
1375
   
1376
   /**
1377
    * Validate the value(s) for SCREEN-VALUE attribute.
1378
    * 
1379
    * If valid the SCREEN-VALUE will be updated to reflect the resulting value.
1380
    * - empty string will set the value to unknown, unless a valid item value.
1381
    * - for unknown the result can be empty string if a valid item value.
1382
    * 
1383
    * @param value
1384
    *        The to be validated as SCREEN-VALUE attribute.
1385
    * 
1386
    * @return <code>true</code> if the value is a valid screen-value.
1387
    */
1388
   @Override
1389
   boolean validateScreenValue(character value)
1390
   {
1391
      if (super.validateScreenValue(value))
1392
      {
1393
         ControlSetItem[] items = getAttr("items", () -> config.items);
1394
         
1395
         for (ControlSetItem item : items)
1396
         {
1397
            // item found, update value if different case
1398
            if (CompareOps._isEqual(value, item.getCharacterValue()))
1399
            {
1400
               value.assign(item.getCharacterValue());
1401
               return true;
1402
            }
1403
         }
1404
      }
1405
      return false;
1406
   }
1417 1407
}
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
   }