How can I add a badge to a tab in CodenameOne? - codenameone

I tried this code:
FloatingActionButton badge = FloatingActionButton.createBadge("33");
badge.bindFabToContainer(tabs.getTabComponentAt(3), Component.RIGHT, Component.TOP);
However for some reason I get a
java.lang.IllegalArgumentException: Component is already contained in Container
exception.
I tried also:
tabs.getTabsContainer().getComponentAt(3)
without success.

Bind creates a new container that should be added instead of the component. This won't work for a case like tabs where the button be added when you add a tab component. You are also relying on internal behavior of looking up a specific tab which is pretty fragile to begin with.
You can use the approach listed here which shows how you can create a completely custom component to represent a tab.

Related

troubleshooting steps when React.memo() not working?

I have a component with some tabs. Each tab selector loads its own datagrid. After a tab has been selected and its datagrid has been loaded, the datagrid should be essentially cached so that toggling away and back to the tab should simply write out the previous datagrid that was loaded/cached. The datagrid entity that gets loaded for each tab/entity essentially looks like this:
<MyDataGrid entity={entity} />
I've wrapped the datagrid component definition with the memo() function like this:
const MyDataGrid = memo((props: IncludeListProps): React.ReactElement => {
debugger;
});
However, the debugger breakpoint is getting hit within the component every time. What is the sequence of steps that you would use to go about troubleshooting something like this?
UPDATE
Providing some additional info based on comments below. A tab strip on top refreshes the display div underneath. So yes the props of MyDataGrid change (eg props.entity.id).
But what I need to do is figure out the best way to cache/memoize each MyDataGrid created per tab. I'm thinking maybe a div collection where each div will be reserved to hold MyDataGrid for a specific tab. Then divs will display inline/none based on the current tab selection. Does this seem like the most straightforward approach?

Reference retrieval of a ButtonGroup instance

I have created an instance of ButtonGroup and associated that to two RadioButtons. The RadioButtons are added to a Container and the Container added to a Form screen. When the "Back" button is pressed, I want to clear the ButtonGroup selection and reset certain variable instances.
I want to place the code in the ActionListener I have made for the "Back" function. My question is how to retrieve the reference of the ButtonGroup in order to clearSelection()?
Generally we recommend recreating the Form instead of caching it if you intend to "reset it" so I'd avoid this.
If you still want to go in this direction check out getButtonGroup() in RadioButton. You can also set a new group with the setter method.
You can use setUnselectAllowed(true) then invoke setSelected(false) on both buttons. Then restore default selection behavior using setUnselectAllowed(false).
While looking at animateLayout() method of ComponentSelector for another issue that I had, I realized that I may use this Class to obtain Component object references jQuery style elegantly. Very powerful and useful concept for codename one.
should adding or removing components trigger a repaint?

Access a component inside a Tab component

I'm new using Codename One. I'm doing an app which have a Form, that has a Tab component with 14 tabs inside, every tab has a gridlayout with 42 buttons, and I want to change a property in one button.
The problem is that I don't know how to reach that button.
tabG.getContentPane().components.get(index)
tabG is the tab component, and I can reach the tab that I need, but after that I don't know how to reach the button index I want to change.
I tried
tabG.getContentPane().components.get(index).components.get(indexbutton)
But even can't compile this code.
I'll apprecciate any help.
When you create the tab you need to prepare information to find the component later. E.g. if all tabs derive from the same class then just do something like:
MyBaseContainer cnt = (MyBaseContainer)tabs.getTabComponentAt(index);
Button theButtonINeed cnt.getMyImportantButton();
If this is more complicated you can use setName() or putClientProperty to prepare hints for you during form construction.

TestRecorder with MaterialCommand in Toolbar

In a test-class, is there any way to invoke Buttons inside the toolbar, without a name (""), which were added like this?
getToolbar().addMaterialCommandToRightBar("", FontImage.MATERIAL_PICTURE_AS_PDF, e -> createPDF());
Or can I somehow tell the test-class to show a specific form ?(which is happening when I click the button without a label).
The test recorder is not generating any code in that case. It seems that it is only working with buttons, which have a non-empty String as name, as they are simply invoked by
clickButtonByLabel("Label");
The test recorder was written before the Toolbar existed, we tried to update it for the Toolbar recently but this proved to be pretty difficult.
We have this issue that covers this bug. As a workaround you can post the command directly in the code of the test.

Extjs ownerCt undefined

I created a new component in my grid's listeners: beforeload, and when i called .show() on it, the debugger showed that d.ownerCt is undefined. Any suggestions?
ownerCt is set automatically by the framework as soon as a component is added to a container. It seems that you're calling show() manually indicating that your component is not part of a container hierarchy.
See ownerCt in the Ext JS documentation (here Ext JS 6 classic, but that concept hasn't changed).
This Component's owner Container (is set automatically when this
Component is added to a Container).
Important. This is not a universal upwards navigation pointer. It
indicates the Container which owns and manages this Component if any.
There are other similar relationships such as the button which
activates a menu, or the menu item which activated a submenu, or the
column header which activated the column menu.
These differences are abstracted away by the up method.
Note: to access items within the Container see itemId.

Resources