39 /** |
40 /** |
40 * Constructor. |
41 * Constructor. |
41 * |
42 * |
42 * @param form where DFLP is applied. |
43 * @param form where DFLP is applied. |
43 */ |
44 */ |
44 DefaultFormInteraction(Form form) { |
45 DefaultFormInteraction(Form form) |
|
46 { |
45 super(form); |
47 super(form); |
46 } |
48 } |
47 |
49 |
48 final void handleShowCurrentEvent() { |
50 final void handleShowCurrentEvent() |
|
51 { |
49 super.handleShowCurrentEvent(); |
52 super.handleShowCurrentEvent(); |
50 eswtApplyCurrentFocus(); |
53 eswtApplyCurrentFocus(); |
51 } |
54 } |
52 |
55 |
53 final void handleHideCurrentEvent() { |
56 final void handleHideCurrentEvent() |
|
57 { |
54 super.handleHideCurrentEvent(); |
58 super.handleHideCurrentEvent(); |
55 direction = NO_DIRECTION; |
59 direction = NO_DIRECTION; |
56 } |
60 } |
57 |
61 |
58 /* (non-Javadoc) |
62 /* (non-Javadoc) |
59 * @see DefaultFormLayoutPolicy#eswtLayoutForm(int) |
63 * @see DefaultFormLayoutPolicy#eswtLayoutForm(int) |
60 */ |
64 */ |
61 final void eswtLayoutForm(int startIndex) { |
65 final void eswtLayoutForm(int startIndex) |
|
66 { |
62 super.eswtLayoutForm(startIndex); |
67 super.eswtLayoutForm(startIndex); |
63 |
68 |
64 // clear invalid selected item |
69 // clear invalid selected item |
65 eswtCheckCurrentSelectedItem(); |
70 eswtCheckCurrentSelectedItem(); |
66 |
71 |
67 if (currentSelectedItem != null |
72 if(currentSelectedItem != null |
68 && (currentSelectedItem.isFocusable())) { |
73 && (currentSelectedItem.isFocusable())) |
|
74 { |
69 eswtApplyCurrentFocus(); |
75 eswtApplyCurrentFocus(); |
70 } |
76 } |
71 else { |
77 else |
|
78 { |
72 // If there's no item currently selected try to find first |
79 // If there's no item currently selected try to find first |
73 // focusable item and set it current (if found): |
80 // focusable item and set it current (if found): |
74 Item found = eswtGetNextFocusableItem( |
81 Item found = eswtGetNextFocusableItem( |
75 getItem(startIndex - 1), SWT.ARROW_RIGHT); |
82 getItem(startIndex - 1), SWT.ARROW_RIGHT); |
76 if (found != null) { |
83 if(found != null) |
|
84 { |
77 eswtSetCurrentSelectedItem(found, NO_DIRECTION); |
85 eswtSetCurrentSelectedItem(found, NO_DIRECTION); |
78 } |
86 } |
79 else { |
87 else |
|
88 { |
80 eswtApplyCurrentFocus(); |
89 eswtApplyCurrentFocus(); |
81 } |
90 } |
82 } |
91 } |
83 } |
92 } |
84 |
93 |
85 /* (non-Javadoc) |
94 /* (non-Javadoc) |
86 * @see DefaultFormLayoutPolicy#eswtSetCurrentItem(Item) |
95 * @see DefaultFormLayoutPolicy#eswtSetCurrentItem(Item) |
87 */ |
96 */ |
88 boolean eswtSetCurrentItem(Item item) { |
97 boolean eswtSetCurrentItem(Item item) |
|
98 { |
89 boolean ret = super.eswtSetCurrentItem(item); |
99 boolean ret = super.eswtSetCurrentItem(item); |
90 if (ret && item != null && item.isFocusable()) { |
100 if(ret && item != null && item.isFocusable()) |
|
101 { |
91 eswtSetCurrentSelectedItem(item, NO_DIRECTION); |
102 eswtSetCurrentSelectedItem(item, NO_DIRECTION); |
92 Logger.info("eswtSetCurrentItem" + item); |
103 Logger.info("eswtSetCurrentItem" + item); |
93 } |
104 } |
94 return ret; |
105 return ret; |
95 } |
106 } |
101 * needed. The method is called by the Form. |
112 * needed. The method is called by the Form. |
102 * |
113 * |
103 * @param keyCode eSWT key code. |
114 * @param keyCode eSWT key code. |
104 * @param keyType eSWT key type. |
115 * @param keyType eSWT key type. |
105 */ |
116 */ |
106 final void handleKeyEvent(int keyCode, int keyType) { |
117 final void handleKeyEvent(int keyCode, int keyType) |
|
118 { |
107 Logger.method(this, "handleKeyEvent", currentSelectedItem, |
119 Logger.method(this, "handleKeyEvent", currentSelectedItem, |
108 String.valueOf(keyCode), String.valueOf(keyType)); |
120 String.valueOf(keyCode), String.valueOf(keyType)); |
109 |
121 |
110 boolean isDirectionalKey = isDirectionKey(keyCode); |
122 boolean isDirectionalKey = isDirectionKey(keyCode); |
111 if (keyType == SWT.KeyDown && isDirectionalKey) { |
123 if(keyType == SWT.KeyDown && isDirectionalKey) |
|
124 { |
112 eswtCheckCurrentSelectedItem(); |
125 eswtCheckCurrentSelectedItem(); |
113 } |
126 } |
114 |
127 |
115 if (currentSelectedItem != null) { |
128 if(currentSelectedItem != null) |
116 if (getLayouter(currentSelectedItem).eswtOfferKeyEvent( |
129 { |
117 currentSelectedItem, keyCode, keyType)) { |
130 if(getLayouter(currentSelectedItem).eswtOfferKeyEvent( |
|
131 currentSelectedItem, keyCode, keyType)) |
|
132 { |
118 // if the key has been consumed |
133 // if the key has been consumed |
119 return; |
134 return; |
120 } |
135 } |
121 } |
136 } |
122 |
137 |
123 // scrolling/focus traverse only happens on directional key's down event |
138 // scrolling/focus traverse only happens on directional key's down event |
124 if (keyType == SWT.KeyDown && isDirectionalKey) { |
139 if(keyType == SWT.KeyDown && isDirectionalKey) |
|
140 { |
125 // try to find next focusable item |
141 // try to find next focusable item |
126 Item next = eswtGetNextFocusableItem(currentSelectedItem, keyCode); |
142 Item next = eswtGetNextFocusableItem(currentSelectedItem, keyCode); |
127 |
143 |
128 // if no visible & focusable item was found to transfer focus |
144 // if no visible & focusable item was found to transfer focus |
129 if (next == currentSelectedItem) { |
145 if(next == currentSelectedItem) |
|
146 { |
130 // try to scroll a bit |
147 // try to scroll a bit |
131 eswtSetScrollingPosition(getNextScrollingPosition(keyCode), |
148 eswtSetScrollingPosition(getNextScrollingPosition(keyCode), |
132 true); |
149 true); |
133 // find next focusable after scrolling |
150 // find next focusable after scrolling |
134 next = eswtGetNextFocusableItem(currentSelectedItem, keyCode); |
151 next = eswtGetNextFocusableItem(currentSelectedItem, keyCode); |
135 } |
152 } |
136 |
153 |
137 if (next != currentSelectedItem) { |
154 if(next != currentSelectedItem) |
|
155 { |
138 //textfield always have to be fully visible when focused. |
156 //textfield always have to be fully visible when focused. |
139 if (next instanceof TextField) { |
157 if(next instanceof TextField) |
|
158 { |
140 eswtScrollToItem(next); |
159 eswtScrollToItem(next); |
141 } |
160 } |
142 eswtSetCurrentSelectedItem(next, keyCode); |
161 eswtSetCurrentSelectedItem(next, keyCode); |
143 } |
162 } |
144 } |
163 } |
147 /** |
166 /** |
148 * Returns if the parameter is a eSWT directional key code. |
167 * Returns if the parameter is a eSWT directional key code. |
149 * |
168 * |
150 * @param keyCode key code |
169 * @param keyCode key code |
151 */ |
170 */ |
152 private boolean isDirectionKey(int keyCode) { |
171 private boolean isDirectionKey(int keyCode) |
|
172 { |
153 return (keyCode == SWT.ARROW_DOWN || keyCode == SWT.ARROW_UP |
173 return (keyCode == SWT.ARROW_DOWN || keyCode == SWT.ARROW_UP |
154 || keyCode == SWT.ARROW_LEFT || keyCode == SWT.ARROW_RIGHT); |
174 || keyCode == SWT.ARROW_LEFT || keyCode == SWT.ARROW_RIGHT); |
155 } |
175 } |
156 |
176 |
157 /** |
177 /** |
158 * DefaultFormInteraction handler for pointer events.<br> |
178 * DefaultFormInteraction handler for pointer events.<br> |
159 * The method is called by the Form. |
179 * The method is called by the Form. |
160 * |
180 * |
161 * @param x coordinate relative to scrolledComposite |
181 * @param x coordinate relative to scrolledComposite |
162 * @param y coordinate relative to scrolledComposite |
182 * @param y coordinate relative to scrolledComposite |
163 * @param type event type: SWT.MouseDown, SWT.MouseMove, SWT.MouseUp |
183 * @param type event type: SWT.MouseDown, SWT.MouseMove, SWT.MouseUp |
164 */ |
184 */ |
165 final void handlePointerEvent(int x, int y, int type) { |
185 final void handlePointerEvent(int x, int y, int type) |
|
186 { |
166 Logger.method(this, "handlePointerEvent", String.valueOf(x), |
187 Logger.method(this, "handlePointerEvent", String.valueOf(x), |
167 String.valueOf(y), String.valueOf(type)); |
188 String.valueOf(y), String.valueOf(type)); |
168 |
189 |
169 // TODO: change when DirectUI style arrives. |
190 // TODO: change when DirectUI style arrives. |
170 /* |
191 /* |
171 Item item; |
192 Item item; |
172 if (type == SWT.MouseMove) { |
193 if (type == SWT.MouseMove) { |
242 * |
263 * |
243 * @param x coordinate. |
264 * @param x coordinate. |
244 * @param y coordinate. |
265 * @param y coordinate. |
245 * @return Item. |
266 * @return Item. |
246 */ |
267 */ |
247 Item eswtFindItemUnderMouse(int x, int y) { |
268 Item eswtFindItemUnderMouse(int x, int y) |
|
269 { |
248 Row itemRow; |
270 Row itemRow; |
249 for (int i = 0; i < getRowCount(); i++) { |
271 for(int i = 0; i < getRowCount(); i++) |
|
272 { |
250 itemRow = getRow(i); |
273 itemRow = getRow(i); |
251 if (itemRow.getYShift() <= y && y <= itemRow.getBottomPosition()) { |
274 if(itemRow.getYShift() <= y && y <= itemRow.getBottomPosition()) |
|
275 { |
252 LayoutObject lo; |
276 LayoutObject lo; |
253 for (int j = 0; j < itemRow.size(); j++) { |
277 for(int j = 0; j < itemRow.size(); j++) |
|
278 { |
254 lo = itemRow.getLayoutObject(j); |
279 lo = itemRow.getLayoutObject(j); |
255 if (lo.contains(x, y)) { |
280 if(lo.contains(x, y)) |
|
281 { |
256 Logger.info("Item under mouse: " |
282 Logger.info("Item under mouse: " |
257 + lo.getOwningItem()); |
283 + lo.getOwningItem()); |
258 currentlyUnderMouse = lo; |
284 currentlyUnderMouse = lo; |
259 return lo.getOwningItem(); |
285 return lo.getOwningItem(); |
260 } |
286 } |
261 } |
287 } |
262 break; |
288 break; |
280 * @param dir Search direction, one of the arrow key constants defined |
307 * @param dir Search direction, one of the arrow key constants defined |
281 * in class SWT. |
308 * in class SWT. |
282 * |
309 * |
283 * @return Nearest focusable item or null if no item found. |
310 * @return Nearest focusable item or null if no item found. |
284 */ |
311 */ |
285 final Item eswtGetNextFocusableItem(Item fromItem, int dir) { |
312 final Item eswtGetNextFocusableItem(Item fromItem, int dir) |
|
313 { |
286 Item nextItem = fromItem; |
314 Item nextItem = fromItem; |
287 |
315 |
288 switch (dir) { |
316 switch(dir) |
289 case SWT.ARROW_RIGHT: { |
317 { |
290 LayoutObject obj = getLastLayoutObjectOfItem(fromItem); |
318 case SWT.ARROW_RIGHT: |
291 while ((obj = getNextLayoutObjectOfItem(obj, null)) != null) { |
319 { |
292 Item owner = obj.getOwningItem(); |
320 LayoutObject obj = getLastLayoutObjectOfItem(fromItem); |
293 if (owner != null && owner != fromItem |
321 while((obj = getNextLayoutObjectOfItem(obj, null)) != null) |
294 && owner.isFocusable() |
322 { |
295 && isPartiallyVisible(obj, Config.DFI_VISIBILITY_PERCENT)) { |
323 Item owner = obj.getOwningItem(); |
|
324 if(owner != null && owner != fromItem |
|
325 && owner.isFocusable() |
|
326 && isPartiallyVisible(obj, Config.DFI_VISIBILITY_PERCENT)) |
|
327 { |
|
328 nextItem = owner; |
|
329 break; |
|
330 } |
|
331 } |
|
332 break; |
|
333 } |
|
334 |
|
335 case SWT.ARROW_LEFT: |
|
336 { |
|
337 LayoutObject obj = getFirstLayoutObjectOfItem(fromItem); |
|
338 while((obj = getPrevLayoutObjectOfItem(obj, null)) != null) |
|
339 { |
|
340 Item owner = obj.getOwningItem(); |
|
341 if(owner != null && owner != fromItem |
|
342 && owner.isFocusable() |
|
343 && isPartiallyVisible(obj, Config.DFI_VISIBILITY_PERCENT)) |
|
344 { |
|
345 nextItem = owner; |
|
346 break; |
|
347 } |
|
348 } |
|
349 break; |
|
350 } |
|
351 |
|
352 case SWT.ARROW_DOWN: |
|
353 { |
|
354 int minDist = Integer.MAX_VALUE; |
|
355 LayoutObject start = getLastLayoutObjectOfItem(fromItem); |
|
356 LayoutObject obj = start; |
|
357 while((obj = getNextLayoutObjectOfItem(obj, null)) != null) |
|
358 { |
|
359 Item owner = obj.getOwningItem(); |
|
360 if(owner != null && owner != fromItem |
|
361 && owner.isFocusable() && obj.isBelow(start) |
|
362 && isPartiallyVisible(obj, Config.DFI_VISIBILITY_PERCENT)) |
|
363 { |
|
364 int dist = obj.distanceTo(start); |
|
365 if(dist < minDist) |
|
366 { |
|
367 minDist = dist; |
296 nextItem = owner; |
368 nextItem = owner; |
297 break; |
|
298 } |
369 } |
299 } |
370 } |
300 break; |
371 } |
301 } |
372 break; |
302 |
373 } |
303 case SWT.ARROW_LEFT: { |
374 |
304 LayoutObject obj = getFirstLayoutObjectOfItem(fromItem); |
375 case SWT.ARROW_UP: |
305 while ((obj = getPrevLayoutObjectOfItem(obj, null)) != null) { |
376 { |
306 Item owner = obj.getOwningItem(); |
377 int minDist = Integer.MAX_VALUE; |
307 if (owner != null && owner != fromItem |
378 LayoutObject start = getFirstLayoutObjectOfItem(fromItem); |
308 && owner.isFocusable() |
379 LayoutObject obj = start; |
309 && isPartiallyVisible(obj, Config.DFI_VISIBILITY_PERCENT)) { |
380 while((obj = getPrevLayoutObjectOfItem(obj, null)) != null) |
|
381 { |
|
382 Item owner = obj.getOwningItem(); |
|
383 if(owner != null && owner != fromItem |
|
384 && owner.isFocusable() && obj.isAbove(start) |
|
385 && isPartiallyVisible(obj, Config.DFI_VISIBILITY_PERCENT)) |
|
386 { |
|
387 int dist = obj.distanceTo(start); |
|
388 if(dist < minDist) |
|
389 { |
|
390 minDist = dist; |
310 nextItem = owner; |
391 nextItem = owner; |
311 break; |
|
312 } |
392 } |
313 } |
393 } |
314 break; |
394 } |
315 } |
395 break; |
316 |
396 } |
317 case SWT.ARROW_DOWN: { |
397 |
318 int minDist = Integer.MAX_VALUE; |
398 default: |
319 LayoutObject start = getLastLayoutObjectOfItem(fromItem); |
|
320 LayoutObject obj = start; |
|
321 while ((obj = getNextLayoutObjectOfItem(obj, null)) != null) { |
|
322 Item owner = obj.getOwningItem(); |
|
323 if (owner != null && owner != fromItem |
|
324 && owner.isFocusable() && obj.isBelow(start) |
|
325 && isPartiallyVisible(obj, Config.DFI_VISIBILITY_PERCENT)) { |
|
326 int dist = obj.distanceTo(start); |
|
327 if (dist < minDist) { |
|
328 minDist = dist; |
|
329 nextItem = owner; |
|
330 } |
|
331 } |
|
332 } |
|
333 break; |
|
334 } |
|
335 |
|
336 case SWT.ARROW_UP: { |
|
337 int minDist = Integer.MAX_VALUE; |
|
338 LayoutObject start = getFirstLayoutObjectOfItem(fromItem); |
|
339 LayoutObject obj = start; |
|
340 while ((obj = getPrevLayoutObjectOfItem(obj, null)) != null) { |
|
341 Item owner = obj.getOwningItem(); |
|
342 if (owner != null && owner != fromItem |
|
343 && owner.isFocusable() && obj.isAbove(start) |
|
344 && isPartiallyVisible(obj, Config.DFI_VISIBILITY_PERCENT)) { |
|
345 int dist = obj.distanceTo(start); |
|
346 if (dist < minDist) { |
|
347 minDist = dist; |
|
348 nextItem = owner; |
|
349 } |
|
350 } |
|
351 } |
|
352 break; |
|
353 } |
|
354 |
|
355 default: |
|
356 } |
399 } |
357 |
400 |
358 return nextItem; |
401 return nextItem; |
359 } |
402 } |
360 |
403 |
361 /** |
404 /** |
362 * Check if the currentSelectedItem is valid and visible. If not then it |
405 * Check if the currentSelectedItem is valid and visible. If not then it |
363 * sets it to null. |
406 * sets it to null. |
364 */ |
407 */ |
365 final void eswtCheckCurrentSelectedItem() { |
408 final void eswtCheckCurrentSelectedItem() |
366 if (currentSelectedItem != null) { |
409 { |
367 if (currentSelectedItem.getParent() != getForm() |
410 if(currentSelectedItem != null) |
368 || !currentSelectedItem.isVisible()) { |
411 { |
|
412 if(currentSelectedItem.getParent() != getForm() |
|
413 || !currentSelectedItem.isVisible()) |
|
414 { |
369 // we need to find another |
415 // we need to find another |
370 Logger.method(this, "eswtCheckCurrentSelectedItem"); |
416 Logger.method(this, "eswtCheckCurrentSelectedItem"); |
371 eswtSetCurrentSelectedItem(null, NO_DIRECTION); |
417 eswtSetCurrentSelectedItem(null, NO_DIRECTION); |
372 } |
418 } |
373 } |
419 } |
379 * removes focus from old item and then moves focus to new one. |
425 * removes focus from old item and then moves focus to new one. |
380 * |
426 * |
381 * @param item Item to set as current selected. If null, nothing happens. |
427 * @param item Item to set as current selected. If null, nothing happens. |
382 * @param dir Direction which is delivered to layouter. |
428 * @param dir Direction which is delivered to layouter. |
383 */ |
429 */ |
384 void eswtSetCurrentSelectedItem(Item item, int dir) { |
430 void eswtSetCurrentSelectedItem(Item item, int dir) |
385 if (currentSelectedItem != item) { |
431 { |
|
432 if(currentSelectedItem != item) |
|
433 { |
386 Logger.info(this + "::SelectedItem: " |
434 Logger.info(this + "::SelectedItem: " |
387 + currentSelectedItem + " --(" + dir + ")--> " + item); |
435 + currentSelectedItem + " --(" + dir + ")--> " + item); |
388 |
436 |
389 // Save direction |
437 // Save direction |
390 direction = dir; |
438 direction = dir; |
391 // Remove focus from currentSelectedItem and notify its Layouter. |
439 // Remove focus from currentSelectedItem and notify its Layouter. |
392 if (currentSelectedItem != null) { |
440 if(currentSelectedItem != null) |
|
441 { |
393 getLayouter(currentSelectedItem).eswtFocusLost( |
442 getLayouter(currentSelectedItem).eswtFocusLost( |
394 currentSelectedItem); |
443 currentSelectedItem); |
395 } |
444 } |
396 |
445 |
397 // Set new currentSelectedItem, must be focusable or null |
446 // Set new currentSelectedItem, must be focusable or null |
398 currentSelectedItem = item; |
447 currentSelectedItem = item; |
399 |
448 |
400 // Set focus to currentSelectedItem and notify its Layouter. |
449 // Set focus to currentSelectedItem and notify its Layouter. |
401 if (currentSelectedItem != null) { |
450 if(currentSelectedItem != null) |
|
451 { |
402 getLayouter(currentSelectedItem).eswtFocusGained( |
452 getLayouter(currentSelectedItem).eswtFocusGained( |
403 currentSelectedItem, dir); |
453 currentSelectedItem, dir); |
404 } |
454 } |
405 |
455 |
406 // Apply eSWT focus to currentSelectedItem's control |
456 // Apply eSWT focus to currentSelectedItem's control |
407 eswtApplyCurrentFocus(); |
457 eswtApplyCurrentFocus(); |
408 } |
458 } |
414 * removes focus from old item and then moves focus to new one. |
464 * removes focus from old item and then moves focus to new one. |
415 * |
465 * |
416 * @param item Item to set as current selected. If null, nothing happens. |
466 * @param item Item to set as current selected. If null, nothing happens. |
417 * @param dir Direction which is delivered to layouter. |
467 * @param dir Direction which is delivered to layouter. |
418 */ |
468 */ |
419 void eswtSetCurrentSelectedItem(Item item) { |
469 void eswtSetCurrentSelectedItem(Item item) |
420 if (currentSelectedItem != item) { |
470 { |
|
471 if(currentSelectedItem != item) |
|
472 { |
421 Logger.info(this + "::SelectedItem: " |
473 Logger.info(this + "::SelectedItem: " |
422 + currentSelectedItem + " ---> " + item); |
474 + currentSelectedItem + " ---> " + item); |
423 |
475 |
424 // Remove focus from currentSelectedItem and notify its Layouter. |
476 // Remove focus from currentSelectedItem and notify its Layouter. |
425 if (currentSelectedItem != null) { |
477 if(currentSelectedItem != null) |
|
478 { |
426 getLayouter(currentSelectedItem).eswtFocusLost( |
479 getLayouter(currentSelectedItem).eswtFocusLost( |
427 currentSelectedItem); |
480 currentSelectedItem); |
428 } |
481 } |
429 |
482 |
430 // Set new currentSelectedItem, must be focusable or null |
483 // Set new currentSelectedItem, must be focusable or null |
431 currentSelectedItem = item; |
484 currentSelectedItem = item; |
432 |
485 |
433 // Set focus to currentSelectedItem and notify its Layouter. |
486 // Set focus to currentSelectedItem and notify its Layouter. |
434 if (currentSelectedItem != null) { |
487 if(currentSelectedItem != null) |
|
488 { |
435 getLayouter(currentSelectedItem).eswtFocusGained( |
489 getLayouter(currentSelectedItem).eswtFocusGained( |
436 currentSelectedItem, NO_DIRECTION); |
490 currentSelectedItem, NO_DIRECTION); |
437 } |
491 } |
438 |
492 |
439 // Apply eSWT focus to currentSelectedItem's control |
493 // Apply eSWT focus to currentSelectedItem's control |
440 //eswtApplyCurrentFocus(); |
494 //eswtApplyCurrentFocus(); |
441 } |
495 } |
449 * update and layouter notifications are handled in method |
503 * update and layouter notifications are handled in method |
450 * <code>eswtSetCurrentSelectedItem()</code>.<br> |
504 * <code>eswtSetCurrentSelectedItem()</code>.<br> |
451 * If currentSelectedItem is null or form is not shown, this method has no |
505 * If currentSelectedItem is null or form is not shown, this method has no |
452 * effect. |
506 * effect. |
453 */ |
507 */ |
454 void eswtApplyCurrentFocus() { |
508 void eswtApplyCurrentFocus() |
455 if (isFormCurrent()) { |
509 { |
|
510 if(isFormCurrent()) |
|
511 { |
456 // if any of the Item's LayoutObjects is visible |
512 // if any of the Item's LayoutObjects is visible |
457 if (isItemPartiallyVisible(currentSelectedItem)) { |
513 if(isItemPartiallyVisible(currentSelectedItem)) |
|
514 { |
458 Logger.method(this, "ApplyFocus", currentSelectedItem); |
515 Logger.method(this, "ApplyFocus", currentSelectedItem); |
459 eswtSetFocusToFirstControl(currentSelectedItem); |
516 eswtSetFocusToFirstControl(currentSelectedItem); |
460 } |
517 } |
461 else { |
518 else |
|
519 { |
462 Logger.method(this, "ApplyFocus", "dummy"); |
520 Logger.method(this, "ApplyFocus", "dummy"); |
463 formComposite.forceFocus(); |
521 formComposite.forceFocus(); |
464 } |
522 } |
465 } |
523 } |
466 } |
524 } |
469 * If the Item is valid and it is layouted, then sets the Item's first |
527 * If the Item is valid and it is layouted, then sets the Item's first |
470 * LayoutObject focused. |
528 * LayoutObject focused. |
471 * |
529 * |
472 * @param item an item which first LayoutObject is set focused. |
530 * @param item an item which first LayoutObject is set focused. |
473 */ |
531 */ |
474 void eswtSetFocusToFirstControl(Item item) { |
532 void eswtSetFocusToFirstControl(Item item) |
475 if (item != null && item.isFocusable()) { |
533 { |
|
534 if(item != null && item.isFocusable()) |
|
535 { |
476 LayoutObject lo = getFirstLayoutObjectOfItem(item); |
536 LayoutObject lo = getFirstLayoutObjectOfItem(item); |
477 if (lo != null) { |
537 if(lo != null) |
|
538 { |
478 lo.getControl().forceFocus(); |
539 lo.getControl().forceFocus(); |
479 } |
540 } |
480 } |
541 } |
481 } |
542 } |
482 |
543 |
483 /** |
544 /** |
484 * Gets Current selected item. |
545 * Gets Current selected item. |
485 * |
546 * |
486 * @return Current selected item. May also return null. |
547 * @return Current selected item. May also return null. |
487 */ |
548 */ |
488 Item getCurrentSelectedItem() { |
549 Item getCurrentSelectedItem() |
|
550 { |
489 return currentSelectedItem; |
551 return currentSelectedItem; |
490 } |
552 } |
491 |
553 |
492 /** |
554 /** |
493 * Get the direction of scrolling. |
555 * Get the direction of scrolling. |
494 * |
556 * |
495 * @return direction of scrolling. |
557 * @return direction of scrolling. |
496 */ |
558 */ |
497 int getDirection() { |
559 int getDirection() |
|
560 { |
498 return direction; |
561 return direction; |
499 } |
562 } |
500 |
563 |
501 /* (non-Javadoc) |
564 /* (non-Javadoc) |
502 * @see DefaultFormLayoutPolicy#eswtResizeItemAndShift(Item) |
565 * @see DefaultFormLayoutPolicy#eswtResizeItemAndShift(Item) |
503 */ |
566 */ |
504 int eswtResizeItemAndShift(Item item) { |
567 int eswtResizeItemAndShift(Item item) |
|
568 { |
505 // save the state of the last row before resizing and Shifting. |
569 // save the state of the last row before resizing and Shifting. |
506 boolean itemWasVisible = isItemPartiallyVisible(item); |
570 boolean itemWasVisible = isItemPartiallyVisible(item); |
507 |
571 |
508 int newVPosition = super.eswtResizeItemAndShift(item); |
572 int newVPosition = super.eswtResizeItemAndShift(item); |
509 |
573 |
510 if (item == currentSelectedItem) { |
574 if(item == currentSelectedItem) |
511 if (itemWasVisible) { |
575 { |
|
576 if(itemWasVisible) |
|
577 { |
512 int itemTop = getItemTopPosition(item); |
578 int itemTop = getItemTopPosition(item); |
513 int itemBottom = getItemBottomPosition(item); |
579 int itemBottom = getItemBottomPosition(item); |
514 // currentSelectedItem has to be focused if it was focused |
580 // currentSelectedItem has to be focused if it was focused |
515 // before resizing e.g TextField when it is resized by adding a |
581 // before resizing e.g TextField when it is resized by adding a |
516 // new row and it was in the bottom of the Screen. |
582 // new row and it was in the bottom of the Screen. |
517 if (newVPosition <= itemTop |
583 if(newVPosition <= itemTop |
518 && (newVPosition + getFormHeight()) >= itemBottom) { |
584 && (newVPosition + getFormHeight()) >= itemBottom) |
|
585 { |
519 // do not change vPosition; |
586 // do not change vPosition; |
520 } |
587 } |
521 else if (newVPosition > itemTop) { |
588 else if(newVPosition > itemTop) |
|
589 { |
522 newVPosition = itemTop; |
590 newVPosition = itemTop; |
523 } |
591 } |
524 else if ((newVPosition + getFormHeight()) < itemBottom) { |
592 else if((newVPosition + getFormHeight()) < itemBottom) |
|
593 { |
525 newVPosition = itemBottom - getFormHeight(); |
594 newVPosition = itemBottom - getFormHeight(); |
526 } |
595 } |
527 } |
596 } |
528 } |
597 } |
529 return newVPosition; |
598 return newVPosition; |