Skip to content

Commit c030075

Browse files
committed
Fixed issue with EntityListView handling of invalidate(). For some reason revalidateLater() is insufficient in this case as, if the component is being scrolled it could be painted in an inconsistent state. This may point to a problem with revalidateLater() which I will investigate, but for now fixing it by changing call to revalidate().
1 parent 0ee40cf commit c030075

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

bin/CodeRAD.cn1lib

255 Bytes
Binary file not shown.

src/com/codename1/rad/controllers/FormController.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package com.codename1.rad.controllers;
77

88
import com.codename1.ui.Button;
9+
import com.codename1.ui.CN;
910
import com.codename1.ui.Command;
1011
import com.codename1.ui.Component;
1112
import com.codename1.ui.ComponentSelector;
@@ -269,12 +270,24 @@ public Form getView() {
269270
/**
270271
* Goes back to previous form. The previous form is always the parent controller's
271272
* form, if the parent controller is a FormController.
273+
*
274+
* If the current controller is an instance of {@link AutoCloseable},
275+
* then this will first attempt to call {@link AutoCloseable#close() } on the current form first. If it throws an exception,
276+
* then that exception will be swallowed, but the showBack() action will be cancelled.
272277
*/
273278
public void back() {
274279
Controller parent = getParent();
275280
if (parent != null) {
276281
FormController fc = parent.getFormController();
277282
if (fc != null) {
283+
if (this instanceof AutoCloseable) {
284+
AutoCloseable ac = (AutoCloseable)this;
285+
try {
286+
ac.close();
287+
} catch (Exception ex) {
288+
return;
289+
}
290+
}
278291
fc.getView().showBack();
279292
}
280293
}
@@ -284,7 +297,25 @@ public void show() {
284297
getView().show();
285298
}
286299

300+
/**
301+
* Shows this controller's form using the "back" animation. If the current controller is an instance of {@link AutoCloseable},
302+
* then this will first attempt to call {@link AutoCloseable#close() } on the current form first. If it throws an exception,
303+
* then that exception will be swallowed, but the showBack() action will be cancelled.
304+
*/
287305
public void showBack() {
306+
Form currForm = CN.getCurrentForm();
307+
if (currForm != null) {
308+
ViewController currentController = getViewController(currForm);
309+
if (currentController instanceof AutoCloseable) {
310+
AutoCloseable ac = (AutoCloseable)currentController;
311+
try {
312+
ac.close();
313+
} catch (Exception ex) {
314+
return;
315+
}
316+
}
317+
}
318+
288319
getView().showBack();
289320
}
290321

src/com/codename1/rad/propertyviews/LabelPropertyView.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.codename1.rad.models.PropertySelector;
1717
import com.codename1.rad.models.Tag;
1818
import com.codename1.rad.models.TextFormatterAttribute;
19+
import com.codename1.rad.text.TextFormatter;
1920
import com.codename1.rad.ui.UI;
2021
import com.codename1.rad.ui.image.PropertyImageRenderer;
2122
import com.codename1.rad.ui.image.RoundImageRenderer;
@@ -108,7 +109,7 @@ private String _getText() {
108109

109110
protected String getText() {
110111
String out = _getText();
111-
TextFormatterAttribute formatter = (TextFormatterAttribute)getField().findAttribute(TextFormatterAttribute.class);
112+
TextFormatterAttribute formatter = (TextFormatterAttribute)getField().findInheritedAttribute(TextFormatterAttribute.class);
112113
if (formatter != null) {
113114
return formatter.getValue().format(out);
114115
}
@@ -118,6 +119,7 @@ protected String getText() {
118119
@Override
119120
public void update() {
120121
String oldVal = getComponent().getText();
122+
121123
String newVal = iconOnly ? "" : getText();
122124

123125
if (!Objects.equals(oldVal, newVal)) {

src/com/codename1/rad/ui/entityviews/EntityListView.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ private void handleTransactionEvent(EntityList.TransactionEvent te) {
297297
update();
298298
Form f = getComponentForm();
299299
if (f != null) {
300-
revalidateLater();
300+
// Important: We seem to need revalidate() here rather than revalidateLater()
301+
// because if an animation is in progress, the component may just disappear for a
302+
// moment.
303+
revalidate();
301304
}
302305
return;
303306
}

0 commit comments

Comments
 (0)