Project

General

Profile

4170_15.patch

Sergey Ivanovskiy, 05/28/2020 05:57 PM

Download (36.6 KB)

View differences:

rules/annotations/ocx_conversion.rules 2020-05-27 22:23:56 +0000
354 354
         <action>mapRef.put("key", "NodeKey")</action>
355 355
         <action>mapRef.put("index", "TreeNodeIndex")</action>
356 356
         <action>mapRef.put("text", "NodeText")</action>
357
         <action>mapRef.put("selectedimage", "ExpandNodeIcon")</action>
357
         <action>mapRef.put("selectedimage", "SelectedNodeIcon")</action>
358 358
         <action>mapRef.put("image", "NodeIcon")</action>
359 359
         <action>aliasMap.put("COM.GOLDENCODE.P2J.UI.TREENODEFACE", mapRef)</action>
360 360
      </rule>
rules/convert/builtin_functions.rules 2020-05-28 13:40:00 +0000
624 624
         </rule>
625 625
         
626 626
         <rule>ftype == prog.kw_load_pic
627
            <action>methodText = "com.goldencode.p2j.ui.ocx.ListImage.newInstance"</action>
627
            <action>methodText = "com.goldencode.p2j.ui.ocx.PictureObject.loadPicture"</action>
628 628
            <action>methodType = java.static_method_call</action>
629 629
         </rule>
630 630
         
src/com/goldencode/p2j/ui/TreeNodeCollection.java 2020-05-28 15:31:31 +0000
79 79
        Iterable<T>,
80 80
        RemoveNode
81 81
{
82
   /** The index out of bounds error message reason */
83
   String INDEX_OUT_OF_BOUNDS = "Index out of bounds";
84
   
85
   /** The invalid key error message reason */
86
   String INVALID_KEY = "Invalid key";
87
   
88
   /** Key is not unique in collection error message reason */
89
   String KEY_NOT_UNIQUE = "Key is not unique in collection";
90
   
91
   /** The type mismatch the error message reason */
92
   String TYPE_MISMATCH = "Type mismatch.";
93
   
94 82
   /**
95 83
    * Creates a new node and inserts it as the first item in the collection.
96 84
    *
......
218 206
    *           The label of the new node
219 207
    * @param    nodeIcon
220 208
    *           The node icon 1-based index within its tree images list
221
    * @param    expandNodeIcon
222
    *           The expand node icon 1-based index within its tree images list
209
    * @param    selectedNodeIcon
210
    *           The node icon 1-based index within its tree images list
223 211
    * 
224 212
    * @return   The handle to the new node.
225 213
    */
......
229 217
              character key,
230 218
              character text,
231 219
              NumberType nodeIcon,
232
              NumberType expandNodeIcon);
220
              NumberType selectedNodeIcon);
233 221

  
234 222
   /**
235 223
    * Adds a new tree node as a last node relative to the root tree node. This node has a default
src/com/goldencode/p2j/ui/TreeNodeCollectionResource.java 2020-05-28 16:54:19 +0000
75 75

  
76 76
import com.goldencode.p2j.util.*;
77 77

  
78
import static com.goldencode.p2j.util.ErrorManager.ErrorReasons.*;
79

  
78 80
import java.util.*;
79 81

  
80 82
/**
......
336 338
      if (nodeIndex == null || nodeIndex.isUnknown())
337 339
      {
338 340
         // throw Invalid key 4GL error
339
         ErrorManager.throwErrorWhileProcessingComponentProperty("Item", INVALID_KEY);
341
         ErrorManager.throwErrorWhileProcessingComponentProperty("Item",
342
                                                                 INVALID_KEY.getReason());
340 343
         
341 344
         return new handle();
342 345
      }
......
348 351
      if (node == null)
349 352
      {
350 353
         // throw Index out of bounds 4GL error
351
         ErrorManager.throwErrorWhileProcessingComponentProperty("Item", INDEX_OUT_OF_BOUNDS);
354
         ErrorManager.throwErrorWhileProcessingComponentProperty("Item",
355
                                                                 INDEX_OUT_OF_BOUNDS.getReason());
352 356
         
353 357
         return new handle();
354 358
      }
......
368 372
      if (nodeIndex == null || nodeIndex.isUnknown())
369 373
      {
370 374
         // throw Invalid key 4GL error
371
         ErrorManager.throwErrorWhileProcessingComponentProperty("remove", INVALID_KEY);
375
         ErrorManager.throwErrorWhileProcessingComponentProperty("remove",
376
                                                                 INVALID_KEY.getReason());
372 377
         
373 378
         return;
374 379
      }
......
380 385
      if (node == null)
381 386
      {
382 387
         // throw Index out of bounds 4GL error
383
         ErrorManager.throwErrorWhileProcessingComponentProperty("remove", INDEX_OUT_OF_BOUNDS);
388
         ErrorManager.throwErrorWhileProcessingComponentProperty("remove",
389
                                                                 INDEX_OUT_OF_BOUNDS.getReason());
384 390
         
385 391
         return;
386 392
      }
......
480 486
         if (relative == null)
481 487
         {
482 488
            // throw Index out of bound error.
483
            ErrorManager.throwErrorWhileProcessingComponentProperty("ADD", INDEX_OUT_OF_BOUNDS);
489
            ErrorManager.throwErrorWhileProcessingComponentProperty("ADD",
490
                                                                    INDEX_OUT_OF_BOUNDS.getReason());
484 491
            
485 492
            return new handle();
486 493
         }
......
492 499
      
493 500
      if (key == null || key.isUnknown())
494 501
      {
495
         ErrorManager.throwErrorWhileProcessingComponentProperty("ADD", INVALID_KEY);
502
         ErrorManager.throwErrorWhileProcessingComponentProperty("ADD", INVALID_KEY.getReason());
496 503
         
497 504
         return new handle();
498 505
      }
......
501 508
      
502 509
      if (treeNode != null)
503 510
      {
504
         ErrorManager.throwErrorWhileProcessingComponentProperty("ADD", KEY_NOT_UNIQUE);
511
         ErrorManager.throwErrorWhileProcessingComponentProperty("ADD", KEY_NOT_UNIQUE.getReason());
505 512
         
506 513
         return new handle();
507 514
      }
......
529 536
    *           The label of the new node
530 537
    * @param    nodeIcon
531 538
    *           The node icon index within its tree images list, 1-based index
532
    * @param    expandNodeIcon
539
    * @param    selectedNodeIcon
533 540
    *           The expand node icon index within its tree images list, 1-based index
534 541
    * 
535 542
    * @return   The handle to the new node.
......
540 547
                     character key,
541 548
                     character text,
542 549
                     NumberType nodeIcon,
543
                     NumberType expandNodeIcon)
550
                     NumberType selectedNodeIcon)
544 551
   {
545 552
      handle hNode = add(anchorIndex, relationType, key, text);
546 553
      
......
548 555
      {
549 556
         TreeNodeFace node = hNode.unwrapTreeNodeFace();
550 557
         
551
         integer nodeIconCopy = new integer(nodeIcon);
552
         
553
         nodeIconCopy.decrement();
554
         
555
         node.setNodeIcon(nodeIconCopy);
556
         
557
         integer expandNodeIconCopy = new integer(expandNodeIcon);
558
         
559
         expandNodeIconCopy.decrement();
560
         
561
         node.setExpandNodeIcon(expandNodeIconCopy);
558
         node.setNodeIcon(nodeIcon);
559
         
560
         node.setExpandNodeIcon(nodeIcon);
561
         
562
         node.setSelectedNodeIcon(selectedNodeIcon);
563
         
564
         tree.pushNodes();
562 565
      }
563 566
      
564 567
      return hNode;
src/com/goldencode/p2j/ui/TreeNodeEntry.java 2020-05-26 20:10:27 +0000
92 92

  
93 93
   /** Icon image id */
94 94
   public int iconId = -1;
95
   
96
   /** The icon image id for the selected node */
97
   public int selectedIconId = -1;
95 98

  
96 99
   /** Leaf or non-leaf node flag */
97 100
   public boolean hasChildren;
src/com/goldencode/p2j/ui/TreeNodeFace.java 2020-05-28 15:44:14 +0000
186 186
    * Setter for the NODE-ICON attribute. The attribute holds the id of the image displayed as the
187 187
    * leaf-node or collapsed icon, depending whether this is a leaf-node or not. The image must be first
188 188
    * created with the call to {@link TreeView#createImage(character)} or built-in image ids can
189
    * be used. For more details see {@link TreeView#createSubNode}.
189
    * be used. For more details see {@link TreeView#createSubNode}. If ImageList is used by
190
    * this node tree, then imageId means 1-based index of this image within its image list.
190 191
    *
191 192
    * @param   imageId
192 193
    *          the attribute value.
......
207 208
   void setNodeIcon(BaseDataType imageId);
208 209

  
209 210
   /**
211
    * Getter for the SelectedImage attribute. The attribute holds the id of the image displayed when
212
    * this node is selected.
213
    *
214
    * @return   The attribute value.
215
    */
216
   @LegacyAttribute(name = "SelectedImage")
217
   integer getSelectedNodeIcon();
218

  
219
   /**
220
    * Setter for the SelectedImage attribute. The attribute holds the id of the image displayed when
221
    * this node is selected.
222
    *
223
    * @param    imageId
224
    *           The attribute value.
225
    */
226
   @LegacyAttribute(name = "SelectedImage", setter = true)
227
   void setSelectedNodeIcon(NumberType imageId);
228

  
229
   /**
230
    * Setter for the SelectedImage attribute. The attribute holds the id of the image displayed when
231
    * this node is selected.
232
    *
233
    * @param    imageId
234
    *           The attribute value.
235
    */
236
   @LegacyAttribute(name = "SelectedImage", setter = true)
237
   void setSelectedNodeIcon(BaseDataType imageId);
238

  
239
   /**
210 240
    * Getter for the EXPAND-NODE-ICON attribute. The attribute holds the id of the image displayed as the
211 241
    * expanded icon.
212 242
    *
src/com/goldencode/p2j/ui/TreeNodeResource.java 2020-05-28 21:03:40 +0000
77 77

  
78 78
import com.goldencode.p2j.util.*;
79 79

  
80
import static com.goldencode.p2j.util.ErrorManager.ErrorReasons.*;
81

  
80 82
/**
81 83
 * Tree Node resource implementation base class.
82 84
 */
......
102 104

  
103 105
   /** Expand icon id */
104 106
   private int expandIconId = -1;
107
   
108
   /** The icon id for the selected node */
109
   private int selectedIconId = -1;
105 110

  
106 111
   /** Flag for leaf or non-leaf node */
107 112
   private boolean hasChildren;
......
186 191
      if (newKey == null || newKey.isUnknown())
187 192
      {
188 193
         ErrorManager.throwErrorWhileProcessingComponentProperty("KEY",
189
                                                                 TreeNodeCollection.TYPE_MISMATCH);
194
                                                                 TYPE_MISMATCH.getReason());
190 195
         
191 196
         ErrorManager.throwErrorUnableToSetComHandleProperty();
192 197
         
......
205 210
      if (treeNode != null)
206 211
      {
207 212
         ErrorManager.throwErrorWhileProcessingComponentProperty("KEY",
208
                                                                 TreeNodeCollection.KEY_NOT_UNIQUE);
213
                                                                 KEY_NOT_UNIQUE.getReason());
209 214
      }
210 215
      
211 216
      String oldKeyValue = key;
......
388 393
   @Override
389 394
   public void setNodeIcon(NumberType imageId)
390 395
   {
396
      imageId = tree.makeZeroBasedIndex(imageId);
397
      
391 398
      int id = imageId != null && !imageId.isUnknown() ? tree.getImageId(imageId) : -1;
399
      
392 400
      if (id != iconId)
393 401
      {
394 402
         _setNodeIcon(id);
403
         
404
         if (expandIconId == -1)
405
         {
406
            _setExpandNodeIcon(id);
407
         }
408
         
395 409
         tree.pushNodes();
396 410
      }
397 411
   }
......
416 430
   }
417 431

  
418 432
   /**
433
    * Returns the global icon id for the selected tree node.
434
    * 
435
    * @return   The global icon id for the selected tree node
436
    */
437
   @Override
438
   public integer getSelectedNodeIcon()
439
   {
440
      return selectedIconId < 0 ? new integer() : new integer(selectedIconId);
441
   }
442

  
443
   /**
444
    * Sets the icon id for the selected tree node. If the images list is used, then the given imageId is
445
    * 1-based index within its images list.
446
    * 
447
    * @param    imageId
448
    *           The image id for the selected tree node
449
    */
450
   @Override
451
   public void setSelectedNodeIcon(NumberType imageId)
452
   {
453
      imageId = tree.makeZeroBasedIndex(imageId);
454
      
455
      int id = imageId != null && !imageId.isUnknown() ? tree.getImageId(imageId) : -1;
456
      if (id != selectedIconId)
457
      {
458
         _setSelectedNodeIcon(id);
459
         tree.pushNodes();
460
      }
461
   }
462

  
463
   /**
464
    * Sets the icon id for the selected tree node. If the images list is used, then the given imageId is
465
    * 1-based index within its images list.
466
    * 
467
    * @param    imageId
468
    *           The image id for the selected tree node
469
    */
470
   @Override
471
   public void setSelectedNodeIcon(BaseDataType imageId)
472
   {
473
      integer id = new integer();
474
      
475
      id.assign(imageId);
476
      
477
      setSelectedNodeIcon(id);
478
   }
479

  
480
   /**
419 481
    * Getter for the EXPAND-NODE-ICON attribute. The attribute holds the id of the image displayed as the
420 482
    * expanded icon.
421 483
    *
......
424 486
   @Override
425 487
   public integer getExpandNodeIcon()
426 488
   {
427
      return iconId < 0 ? new integer() : new integer(expandIconId);
489
      return expandIconId < 0 ? new integer() : new integer(expandIconId);
428 490
   }
429 491

  
430 492
   /**
......
439 501
   @Override
440 502
   public void setExpandNodeIcon(NumberType imageId)
441 503
   {
504
      imageId = tree.makeZeroBasedIndex(imageId);
505
      
442 506
      int id = imageId != null && !imageId.isUnknown() ? tree.getImageId(imageId) : -1;
507
      
443 508
      if (id != expandIconId)
444 509
      {
445 510
         _setExpandNodeIcon(id);
......
774 839
   }
775 840

  
776 841
   /**
842
    * Sets icon for the selected node.
843
    *
844
    * @param   imgId
845
    *          Image id.
846
    */
847
   void _setSelectedNodeIcon(int imgId)
848
   {
849
      selectedIconId = imgId;
850
   }
851

  
852
   /**
777 853
    * Getter for the hadChildren flag.
778 854
    *
779 855
    * @return  value
......
866 942
      entry.expandIconId = expandIconId;
867 943
      entry.hasChildren = hasChildren;
868 944
      entry.tooltip = tooltip;
945
      entry.selectedIconId = selectedIconId;
946
      System.out.println(String.format("nodeId=%d key=%s iconId=%d expandIconId=%d selectedIconId=%d", nodeId, key, iconId, expandIconId, selectedIconId));
869 947
   }
870 948
}
src/com/goldencode/p2j/ui/TreeWidgetBase.java 2020-05-28 21:12:54 +0000
1872 1872
      }
1873 1873

  
1874 1874
      ArrayList<TNodeEntry> result = new ArrayList<>();
1875
      
1875 1876
      TreeNodeCollectionResource coll = rootNode._getNodes(false);
1876 1877
      if (coll != null)
1877 1878
      {
......
2281 2282

  
2282 2283
         if (imageList != null && !imageList.isUnknown())
2283 2284
         {
2285
            
2284 2286
            ImageList list = (ImageList) imageList.getResource();
2285 2287
            integer[] imgIds = list.getImageIds();
2286 2288
            if (i >= 0 && i < imgIds.length)
......
2312 2314
   }
2313 2315

  
2314 2316
   /**
2317
    * Calculates 0-based index based on the given image id. 
2318
    *  
2319
    * @param    imgIndex
2320
    *           The image index that holds 1-based index if the images list is used. If the predefined
2321
    *           images are used, then imageId is 0-based.
2322
    * 
2323
    * @return   The 0-based index or unknown if null value is given.
2324
    */
2325
   integer makeZeroBasedIndex(NumberType imgIndex)
2326
   {
2327
      integer index = new integer();
2328
      
2329
      if (imgIndex == null)
2330
      {
2331
         return index;
2332
      }
2333
      
2334
      index.assign(imgIndex);
2335
      
2336
      if (config.imageListId != -1 && !index.isUnknown())
2337
      {
2338
         index.decrement();
2339
      }
2340
      
2341
      return index;
2342
   }
2343
   
2344
   /**
2315 2345
    * Push the specified widget attribute change to the client-side.
2316 2346
    *
2317 2347
    * @param   fname
src/com/goldencode/p2j/ui/client/gui/theme/ClassicTheme.java 2020-05-28 16:47:52 +0000
6481 6481
      int imgId = node.value.expanded && node.value.expandIconId != -1 ?
6482 6482
                  node.value.expandIconId :
6483 6483
                  node.value.iconId;
6484

  
6484
      
6485
      if (nodeSelected)
6486
      {
6487
         if (node.value.selectedIconId != -1)
6488
         {
6489
            imgId = node.value.selectedIconId;
6490
         }
6491
         else
6492
         {
6493
            imgId = node.value.iconId;
6494
         }
6495
      }
6496
      
6485 6497
      if (imgId != -1)
6486 6498
      {
6487 6499
         ImageWrapper img = null;
6488
         TreeConfig.StockImage stockImage = TreeConfig.StockImage.fromId(imgId);
6489
         if (stockImage != null)
6490
         {
6491
            switch (stockImage)
6492
            {
6493
               case EXPANDED_NODE:
6494
                  img = getImage("treeview-node-expanded.png", true);
6495
                  break;
6496
               case COLLAPSED_NODE:
6497
                  img = getImage("treeview-node-collapsed.png", true);
6498
                  break;
6499
               case LEAF_NODE:
6500
                  img = getImage("treeview-node-leaf.png", true);
6501
                  break;
6502
            }
6503
         }
6504
         else
6505
         {
6506
            img = ImageHelper.getGlobalImage(imageListId != -1 ? imageListId : tree.getId().asInt(), imgId);
6507
         }
6508

  
6500
         
6501
         if (imageListId != -1)
6502
         {
6503
            img = ImageHelper.getGlobalImage(imageListId, imgId);
6504
         }
6505
         
6506
         if (img == null)
6507
         {
6508
            TreeConfig.StockImage stockImage = TreeConfig.StockImage.fromId(imgId);
6509
            
6510
            if (stockImage != null)
6511
            {
6512
               switch (stockImage)
6513
               {
6514
                  case EXPANDED_NODE:
6515
                     img = getImage("treeview-node-expanded.png", true);
6516
                     break;
6517
                  case COLLAPSED_NODE:
6518
                     img = getImage("treeview-node-collapsed.png", true);
6519
                     break;
6520
                  case LEAF_NODE:
6521
                     img = getImage("treeview-node-leaf.png", true);
6522
                     break;
6523
               }
6524
            }
6525
            else
6526
            {
6527
               img = ImageHelper.getGlobalImage(tree.getId().asInt(), imgId);
6528
            }
6529
         }
6530
         
6509 6531
         if (img != null)
6510 6532
         {
6511 6533
            int w = img.getWidth();
src/com/goldencode/p2j/ui/ocx/ComInterface.java 2020-05-26 11:16:20 +0000
113 113
   @Override
114 114
   public boolean valid()
115 115
   {
116
      if (parent != null)
117
      {
118
         return parent.valid();
119
      }
120
      
121
      return false;
116
      return parent != null && parent.valid();
122 117
   }
123 118

  
124 119
   /**
src/com/goldencode/p2j/ui/ocx/IImage.java 2020-05-26 12:49:06 +0000
152 152
   /**
153 153
    * Get the image Picture
154 154
    * 
155
    * @return image bytes.
155
    * @return   The picture comhandle
156 156
    */
157
   public memptr getPicture();
157
   public comhandle getPicture();
158 158

  
159 159
   /**
160 160
    * Set the image Picture
161 161
    * 
162
    * @param   data
163
    *          image bytes.
162
    * @param    data
163
    *           The picture comhandle
164 164
    */
165
   public void setPicture(memptr data);
165
   public void setPicture(comhandle data);
166 166
   
167 167
   /**
168 168
    * Get any extra data needed for your program.
src/com/goldencode/p2j/ui/ocx/ListImage.java 2020-05-27 04:58:42 +0000
80 80
extends ComInterface
81 81
implements IImage
82 82
{
83
   /** The image index within its parent ImageListWidget, 1-based index */
84
   private integer index;
85
   
86
   /** The system file path to the binary image */
87
   private character key;
83
   /** The 4GL pictute object */
84
   private comhandle picture;
85
   
86
   /** The extra data associated with this image */
87
   private BaseDataType tag;
88
   
89
   /** Self instance reference */
90
   private comhandle self;
88 91
   
89 92
   /**
90 93
    * Constructor.
......
94 97
    */
95 98
   private ListImage(GenericWidget parent)
96 99
   {
100
      this(parent, null);
101
   }
102

  
103
   /**
104
    * Constructor.
105
    * 
106
    * @param   parent
107
    *          Parent widget.
108
    */
109
   private ListImage(GenericWidget parent, comhandle picture)
110
   {
97 111
      super(IImage.class.getName(), parent);
98
   }
99
   
100
   /**
101
    * Create a detached instance of an image that can be attached to a widget later.
102
    * 
103
    * @param   pathToImage
104
    *          The file system path to the image file.
105
    */
106
   private ListImage(character pathToImage)
107
   {
108
      super(IImage.class.getName(), null);
109 112
      
110
      key = pathToImage;
113
      setPicture(picture);
111 114
   }
112 115

  
113 116
   /**
......
118 121
    *          
119 122
    * @return a new instance wrapped in a comhandle.
120 123
    */
121
   public static comhandle newInstance(GenericWidget parent)
122
   {
123
      return new comhandle(new ListImage(parent));
124
   }
125

  
126
   /**
127
    * Creates a detached instance of an image
128
    * 
129
    * @param    pathToImage
130
    *           The file system path to the image file.
131
    * 
132
    * @return   a new instance wrapped in a comhandle.
133
    */
134
   public static comhandle newInstance(String pathToImage)
135
   {
136
      return newInstance(new character(pathToImage));
137
   }
138

  
139
   /**
140
    * Creates a detached instance of an image
141
    * 
142
    * @param    pathToImage
143
    *           The file system path to the image file.
144
    * 
145
    * @return   a new instance wrapped in a comhandle.
146
    */
147
   public static comhandle newInstance(character pathToImage)
148
   {
149
      return new comhandle(new ListImage(pathToImage));
150
   }
151

  
152
   //public static comhandle newInstance
124
   public static comhandle newInstance(GenericWidget parent, comhandle picture)
125
   {
126
      ListImage comObject = new ListImage(parent, picture);
127
      comhandle selfReference = new comhandle(comObject);
128
      comObject.self = selfReference;
129
      
130
      return selfReference;
131
   }
132

  
153 133
   /**
154 134
    * {@inheritDoc}
155 135
    */
......
174 154
   @ComProperty(name = "INDEX")
175 155
   public integer getIndex()
176 156
   {
177
      return this.index;
157
      ListImages listImages = getListImages();
158
      
159
      int index = listImages.findIndex(self);
160
      
161
      if (index != -1)
162
      {
163
         return new integer(index + 1);
164
      }
165
      
166
      return new integer();
178 167
   }
179 168

  
180 169
   /**
......
183 172
   @ComProperty(name = "INDEX")
184 173
   public void setIndex(integer index)
185 174
   {
186
      this.index = index;
187 175
   }
188 176

  
189 177
   /**
......
192 180
   @ComProperty(name = "INDEX")
193 181
   public void setIndex(int index)
194 182
   {
195
      this.index = new integer(index);
196 183
   }
197 184

  
198 185
   /**
......
201 188
   @ComProperty(name = "KEY")
202 189
   public character getKey()
203 190
   {
204
      if (key == null)
205
      {
206
         return new character();
207
      }
191
      ListImages listImages = getListImages();
208 192
      
209
      return key;
193
      return new character(listImages.findKey(self));
210 194
   }
211 195

  
212 196
   /**
......
215 199
   @ComProperty(name = "KEY")
216 200
   public void setKey(character key)
217 201
   {
218
      this.key = key;
219 202
   }
220 203
   
221 204
   /**
......
224 207
   @ComProperty(name = "KEY")
225 208
   public void setKey(String key)
226 209
   {
227
      this.key = new character(key);
228
   }
229

  
230
   /**
231
    * {@inheritDoc}
232
    */
233
   @ComProperty(name = "PICTURE")
234
   public memptr getPicture()
235
   {
236
      return new memptr();
237
   }
238

  
239
   /**
240
    * {@inheritDoc}
241
    */
242
   @ComProperty(name = "PICTURE")
243
   public void setPicture(memptr data)
244
   {
245
      // nop
210
   }
211

  
212
   /**
213
    * {@inheritDoc}
214
    */
215
   @ComProperty(name = "PICTURE")
216
   public comhandle getPicture()
217
   {
218
      return picture;
219
   }
220

  
221
   /**
222
    * {@inheritDoc}
223
    */
224
   @ComProperty(name = "PICTURE")
225
   public void setPicture(comhandle picture)
226
   {
227
      this.picture = picture;
246 228
   }
247 229

  
248 230
   /**
......
251 233
   @ComProperty(name = "TAG")
252 234
   public BaseDataType getTag()
253 235
   {
254
      return new character();
236
      return tag;
255 237
   }
256 238

  
257 239
   /**
......
260 242
   @ComProperty(name = "TAG")
261 243
   public void setTag(BaseDataType tag)
262 244
   {
263
      // nop
245
      this.tag = tag;
264 246
   }
265 247
   
266 248
   /**
267
    * Attach this iamge to the parent widget.
249
    * Unwrap list images object.
268 250
    * 
269
    * @param    parent
270
    *           The parent widget
251
    * @return   The ListImages instance, the container of list image objects.
271 252
    */
272
   public void setParent(GenericWidget parent)
253
   private ListImages getListImages()
273 254
   {
274
      this.parent = parent;
255
      if (parent instanceof ImageListWidget)
256
      {
257
         return ((ImageListWidget) parent).getListImages().unwrapListImages();
258
      }
259
      
260
      return null;
275 261
   }
276 262
}
src/com/goldencode/p2j/ui/ocx/ListImages.java 2020-05-27 04:56:12 +0000
64 64

  
65 65
package com.goldencode.p2j.ui.ocx;
66 66

  
67
import java.util.LinkedHashMap;
68
import java.util.LinkedList;
69
import java.util.List;
70
import java.util.Map;
71
import java.util.Map.Entry;
72
import java.util.Optional;
73

  
67 74
import com.goldencode.p2j.comauto.*;
68 75
import com.goldencode.p2j.ui.*;
69 76
import com.goldencode.p2j.util.*;
70 77

  
78
import static com.goldencode.p2j.util.ErrorManager.ErrorReasons.*;
79

  
71 80
/**
72 81
 * A server side implementation of IImages COM interface 
73 82
 * 
......
79 88
extends ComInterface
80 89
implements IImages
81 90
{
91
   
92
   private Map<String, comhandle> keysToImages = new LinkedHashMap<>();
93
   
94
   private List<comhandle> images = new LinkedList<>();
95
   
82 96
   /**
83 97
    * Constructor.
84 98
    * 
......
93 107
   /**
94 108
    * Factory method.
95 109
    * 
96
    * @param   parent
97
    *          Parent widget.
110
    * @param    parent
111
    *           The image list parent widget.
98 112
    *          
99
    * @return a new instance wrapped in a comhandle.
113
    * @return   The new instance wrapped by comhandle.
100 114
    */
101 115
   public static handle newInstance(GenericWidget parent)
102 116
   {
......
109 123
   @ComMethod(name = "ADD")
110 124
   public comhandle add(integer index, character key, comhandle picture)
111 125
   {
112
      character pathToImage;
113
      
114
      IImage unwrappedImage;
115
      
116
      if (picture != null && picture.getResource() instanceof IImage)
117
      {
118
         unwrappedImage = (IImage) picture.getResource();
119
         pathToImage = unwrappedImage.getKey();
120
      }
121
      else
122
      {
123
         unwrappedImage = null;
124
         pathToImage = key;
125
      }
126
      
127
      ImageListWidget w = (ImageListWidget) parent;
128
      
129
      // returned 0-based index
130
      integer indexOfImage = w.addImage(pathToImage);
131
      
132
      indexOfImage.increment();
133
      
134
      if (unwrappedImage != null)
135
      {
136
         unwrappedImage.setIndex(indexOfImage);
137
         
138
         if (unwrappedImage instanceof ListImage)
139
         {
140
            ((ListImage) unwrappedImage).setParent(parent);
141
         }
142
      }
143
      
144
      return picture;
126
      if (key == null || key.isUnknown())
127
      {
128
         return new comhandle();
129
      }
130
      
131
      if (keysToImages.containsKey(key.getValue()))
132
      {
133
         ErrorManager.throwErrorWhileProcessingComponentProperty("ADD", KEY_NOT_UNIQUE.getReason());
134
         
135
         return new comhandle();
136
      }
137
      
138
      comhandle imageObj = ListImage.newInstance(parent, picture);
139
      
140
      images.add(imageObj);
141
      
142
      keysToImages.put(key.getValue(), imageObj);
143
      
144
      if (picture != null && picture.getResource() instanceof PictureObject)
145
      {
146
         PictureObject pictureObject = (PictureObject) picture.getResource();
147
         
148
         ((ImageListWidget) parent).addImage(new character(pictureObject.getImagePath()));
149
      }
150
      
151
      return imageObj;
145 152
   }
146 153

  
147 154
   /**
......
173 180
   @ComProperty(name = "ITEM")
174 181
   public comhandle getItem(character key)
175 182
   {
176
      return new comhandle();
183
      if (key == null || key.isUnknown())
184
      {
185
         return new comhandle();
186
      }
187
      
188
      return getItem(key.getValue());
177 189
   }
178 190

  
179 191
   /**
......
182 194
   @ComProperty(name = "ITEM")
183 195
   public comhandle getItem(int index)
184 196
   {
185
      ImageListWidget w = (ImageListWidget) parent;
186
      
187
      integer[]  images = w.getImageIds();
188
      
189
      if (index <= 0 && index > images.length)
197
      if (index <= 0 && index > images.size())
190 198
      {
191 199
         return new comhandle();
192 200
      }
193 201
      
194
      comhandle image = ListImage.newInstance(parent);
195
      
196
      ((IImage) image.getResource()).setIndex(index);
197
      
198
      // TODO get image path
199
      return image;
202
      return images.get(index - 1);
200 203
   }
201 204

  
202 205
   /**
......
205 208
   @ComProperty(name = "ITEM")
206 209
   public comhandle getItem(String key)
207 210
   {
208
      return new comhandle();
211
      if (key == null)
212
      {
213
         return new comhandle();
214
      }
215
      
216
      return keysToImages.get(key);
209 217
   }
210 218

  
211 219
   /**
......
223 231
   @ComProperty(name = "COUNT")
224 232
   public integer getCount()
225 233
   {
226
      ImageListWidget w = (ImageListWidget) parent;
227
      
228
      return new integer(w.getImageIds().length);
234
      return new integer(images.size());
229 235
   }
230 236

  
231 237
   /**
......
263 269
   {
264 270
      // nop      
265 271
   }
272
   
273
   public String findKey(comhandle imageReference)
274
   {
275
      Entry<String, comhandle> found = findKeyValueEntry(imageReference);
276
      
277
      if (found != null)
278
      {
279
         return found.getKey();
280
      }
281
      
282
      return null;
283
   }
284
   
285
   public int findIndex(comhandle imageReference)
286
   {
287
      return images.indexOf(imageReference);
288
   }
289
   
290
   private Entry<String, comhandle> findKeyValueEntry(comhandle imageReference)
291
   {
292
      Optional<Entry<String, comhandle>> found = keysToImages.entrySet().stream().filter(
293
               entry -> entry.getValue() == imageReference).findFirst();
294
      
295
      if (found.isPresent())
296
      {
297
         return found.get();
298
      }
299
      
300
      return null;
301
   }
266 302
}
src/com/goldencode/p2j/ui/ocx/PictureObject.java 2020-05-27 04:56:23 +0000
1
/*
2
** Module   : PictureObject.java
3
** Abstract : Represents 4GL picture object.
4
**
5
** Copyright (c) 2020, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ---------------------------------Description----------------------------------
8
** 001 SBI 20200525 Added 4GL picture object implementation.
9
*/
10

  
11
/*
12
** This program is free software: you can redistribute it and/or modify
13
** it under the terms of the GNU Affero General Public License as
14
** published by the Free Software Foundation, either version 3 of the
15
** License, or (at your option) any later version.
16
**
17
** This program is distributed in the hope that it will be useful,
18
** but WITHOUT ANY WARRANTY; without even the implied warranty of
19
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
** GNU Affero General Public License for more details.
21
**
22
** You may find a copy of the GNU Affero GPL version 3 at the following
23
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
24
** 
25
** Additional terms under GNU Affero GPL version 3 section 7:
26
** 
27
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
28
**   terms apply to the works covered under the License.  These additional terms
29
**   are non-permissive additional terms allowed under Section 7 of the GNU
30
**   Affero GPL version 3 and may not be removed by you.
31
** 
32
**   0. Attribution Requirement.
33
** 
34
**     You must preserve all legal notices or author attributions in the covered
35
**     work or Appropriate Legal Notices displayed by works containing the covered
36
**     work.  You may not remove from the covered work any author or developer
37
**     credit already included within the covered work.
38
** 
39
**   1. No License To Use Trademarks.
40
** 
41
**     This license does not grant any license or rights to use the trademarks
42
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
43
**     of Golden Code Development Corporation. You are not authorized to use the
44
**     name Golden Code, FWD, or the names of any author or contributor, for
45
**     publicity purposes without written authorization.
46
** 
47
**   2. No Misrepresentation of Affiliation.
48
** 
49
**     You may not represent yourself as Golden Code Development Corporation or FWD.
50
** 
51
**     You may not represent yourself for publicity purposes as associated with
52
**     Golden Code Development Corporation, FWD, or any author or contributor to
53
**     the covered work, without written authorization.
54
** 
55
**   3. No Misrepresentation of Source or Origin.
56
** 
57
**     You may not represent the covered work as solely your work.  All modified
58
**     versions of the covered work must be marked in a reasonable way to make it
59
**     clear that the modified work is not originating from Golden Code Development
60
**     Corporation or FWD.  All modified versions must contain the notices of
61
**     attribution required in this license.
62
*/
63

  
64
package com.goldencode.p2j.ui.ocx;
65

  
66
import com.goldencode.p2j.comauto.*;
67
import com.goldencode.p2j.ui.*;
68
import com.goldencode.p2j.util.character;
69
import com.goldencode.p2j.util.comhandle;
70

  
71

  
72
/**
73
 * Represents 4GL picture object.
74
 */
75
public class PictureObject extends ComObject
76
{
77
   /** Stores the file system path to the picture */
78
   private final String imagePath;
79

  
80
   /** The global image identifier */
81
   private final int imageId;
82

  
83
   /**
84
    * Creates immutable instance of this picture object
85
    * 
86
    * @param    path
87
    *           The file system path to the image file.
88
    */
89
   public PictureObject(String path)
90
   {
91
      this.imagePath = path;
92
      
93
      id(WidgetId.nextID().asInt());
94
      
95
      this.imageId = LogicalTerminal.loadGlobalImage(id().intValue(), path);
96
   }
97

  
98
   /**
99
    * Loads the picture object and returns the comhandle
100
    * 
101
    * @param    path
102
    *           The file system path to the image file.
103
    * 
104
    * @return   The comhandle to the picture object.
105
    */
106
   public static comhandle loadPicture(String path)
107
   {
108
      return new comhandle(new PictureObject(path));
109
   }
110

  
111
   /**
112
    * Returns this class simple name.
113
    * 
114
    * @return   "OlePictureObject"
115
    */
116
   @Override
117
   public String getActivexName()
118
   {
119
      return getClass().getSimpleName();
120
   }
121

  
122
   /**
123
    * Tests if there is an image given by this image path.
124
    * 
125
    * @return    True if there is an image given by this image path, otherwise false
126
    */
127
   @Override
128
   public boolean valid()
129
   {
130
      return this.imageId != -1;
131
   }
132

  
133
   /**
134
    * Tests if the image resource doesn't exist.
135
    */
136
   @Override
137
   public boolean unknown()
138
   {
139
      return !valid();
140
   }
141

  
142
   /**
143
    * Gets the system path to this image
144
    * 
145
    * @return   The image path
146
    */
147
   public String getImagePath()
148
   {
149
      return imagePath;
150
   }
151

  
152
   /**
153
    * Gets the global image identifier
154
    * 
155
    * @return   The global image identifier
156
    */
157
   public int getImageId()
158
   {
159
      return imageId;
160
   }
161
}
src/com/goldencode/p2j/util/ErrorManager.java 2020-05-26 15:08:03 +0000
3176 3176
         }
3177 3177
      }
3178 3178
   }
3179
   
3179

  
3180
   /**
3181
    * Enumerates known error reasons in object collections.
3182
    */
3183
   public static enum ErrorReasons
3184
   {
3185
      /** The index out of bounds error message reason */
3186
      INDEX_OUT_OF_BOUNDS("Index out of bounds"),
3187
      
3188
      /** The invalid key error message reason */
3189
      INVALID_KEY("Invalid key"),
3190
      
3191
      /** Key is not unique in collection error message reason */
3192
      KEY_NOT_UNIQUE("Key is not unique in collection"),
3193
      
3194
      /** The type mismatch the error message reason */
3195
      TYPE_MISMATCH("Type mismatch.");
3196
      
3197
      /** The error description */
3198
      private final String reason;
3199
      
3200
      /**
3201
       * Creates new enumeration constant from the given error description.
3202
       * 
3203
       * @param    reason
3204
       *           The error description
3205
       */
3206
      private ErrorReasons(String reason)
3207
      {
3208
         this.reason = reason;
3209
      }
3210

  
3211
      /**
3212
       * Returns the error description.
3213
       * 
3214
       * @return   The error description.
3215
       */
3216
      public String getReason()
3217
      {
3218
         return reason;
3219
      }
3220
   }
3221

  
3180 3222
   /**
3181 3223
    * Stores the data related to a single error.
3182 3224
    */