I was having ID collision of tab IDs when trying to recreate the same TabSet.
My case is the following : I have 3 Tabs in general, then some action creates a 4th one, some action happens in this 4th tab which is then closed, and I need to relaunch my app and redraw again the 3 general Tabs fetching new info from the database. Everything was working well, except this warning of collision which was not a blocking one anyway.
In order to clean it, I followed Isomorphic's advice from this thread
and tried destroying the TabSet in order to recreate it.
I do:
if (myTabSet != null) {
myTabSet.destroy();
}
myTabSet = new TabSet();
// setting TabSet properties
// creating Tabs and adding them to the TabSet
I noticed, however, in debug, that the TabSet is not being desroyed completely, just some of its properties, and that a new ID is being given to it. As a result, there are no more warnings, the tabs are created, but they're not populated.
My question is : why the TabSet is not becoming null upon destruction, and how can I recreate it with no collision of IDs?
Thanks in advance
I used to have the same problem and fixed it with:
myTabSet.addCloseClickHandler(new CloseClickHandler() {
#Override
public void onCloseClick(TabCloseClickEvent event) {
event.getTab().getPane().destroy();
}
});
Apparently the tabset is not completely destroyed unless you destroy its pane.
Maybe it will work for you !
Related
I am working a bit with blazor right now and got to a pretty weird fault.
So, I´ve got a parent component, which is having a child component and this is having a child component itself, both giving an Object to the child component. Something like that:
Parent.razor
<ChildComponent #bind-Model="Model" ObjectListConverted="ObjectListConverted"/>
#code {
List<Object> ObjectListConverted = new List<Object>();
}
and
Childcomponent.razor
<MyOwnChild Item="#((Item)obj)"/>
So far, so good. Now, there is the interesting thing happening. The Parent and the Childcomponent are both being initialized straight at loading the page. The MyOwnChild-Component can only be loaded after converting some stuff, which happens in the onInitialized()-method of Childcomponent.razor. I checked, if the conversion is working and in fact the MyOwnChild-component is being initialized (which I checked via logging), but it´s not visible. I tried to use a testComponent, just containing a -Tag with some content, but it´s also not displayed. Also checked the html, that´s generated for hidden-divs, either due to css or due to a missassigned hidden attribute, but nothing like that is found.
It´s pretty weird. What´s probably important to know is, that the MyOwnChild is using itself recursive if obj is expanded, but this is false by default.
Additionally it is bound in a bigger context, so the ChildComponent.razor is actually containing two foreach-loops, one with the converted stuff, one with another list, that´s only getting items added on user interaction:
Childcomponent.razor
#foreach (Object obj in ObjectListConverted)
{
if (obj.IsFolder) //This evaluates to true in all cases right now.
{
<MyOwnChild Item="#((Item)obj)"/>
Console.WriteLine("Hey, it´s a folder!"); //This is logged.
}
}
#if (Model.OtherList != null)
{
#foreach (DetailedObject obj in Model.OtherList)
{
if (obj.IsFolder)
{
<MyOwnChild Item="#((Item)obj)"/>
}
}
}
#code {
[Parameter]
List<Object> ObjectListConverted {get; set;}
[Parameter]
Model Model {get; set;} = new Model();
protected override void OnInitialized() {
ObjectListConverted = ConvertToStructuredList(Model.List);
base.StateHasChanged();
}
}
So while the upper version on the MyOwnChild.razor is not displayed at any time at all, though initialized, there´s no problem with it being displayed after adding a new item to the otherList. The inheritance is as follows:
Item:DetailedObject:Object
But I don´t think that´s the problem, cause the extension DetailedObject is only having a additional attribute content, which is not used at all here.
Thanks for help. :)
So I fixed the issue myself now.
It was pretty tricky.
So the problem was as follows:
The ObjectlistConverted in the ChildComponent is a parameter, cause it is planned to be bound to a parents list.
At the state of the error it was not bound yet.
So OnInitialization of the ChildComponent the Parent is giving the empty list to it to prevent the ModelListConverted of being null. As the OnInitialized-method calls the conversion method it changes the ModelListConverted to another reference. Cause it is not bound to the parent, the parent is still holding the old list not updating the reference. When base.StateHasChanged()is called everything is rerendered. The parent sees, that the reference of the childcomponent is not the actual one anymore and gives it the old reference a second time. Cause it is only rerendered and not initialized again, it is not converting the list a second time, preventing the program from throwing a stack overflow error or getting into an endless loop. It´s just taking the empty list now, so right after initializing the MyOwnChild-component it removes it again, cause there´s no item in the list for it anymore.
There are many examples of doing this in axml, but I would like to have a complete binding using code behind. To be honest, I would like to have NO axml, but seems like creating all the controls programmatically is a nightmare.
I first tried the suggestions at:
MvxListView create binding for template layout from code
I have my list binding from code-behind, and I get six rows (so source binding is working); but the cells itself does not bind.
Then at the following url:
Odd issue with MvvmCross, MvxListViewItem on Android
Stuart has the following comment: Have looked through. In this case, I don't think you want to use DelayBind. DelayBind is used to delay the binding action until next time the DataContext is set. In Android's MvxAdapter/MvxListItemView case, the DataContext is passed in the ctor - so DataContext isn't set again until the cell is reused. (This is different to iOS MvxTableDataSource).
So in essence, the only example I see shows DelayBind, which shouldn't work.
Can someone please show me some examples... thanks in advance.
Added reply to Comments:
Cheesebaron, first of all, a huge thank you and respect for all your contributions;
Now, why not use axml? Well, as programmers, we all have our own preferences and way of doing stuff - I guess I am old school where we didn't have any gui designer (not really true).
Real reasons:
Common Style: I have a setup where Core has all the style details, including what all the colors would be. My idea is, each platform would get the style details from core and update accordingly. It's easy for me to create controls with the correct style this way.
Copy-Paste across platform (which then I can even have as linked files if I wanted). For example, I have a login screen with web-like verification, where a red error text appears under a control; overall on that screen I have around 10 items that needs binding. I have already got iOS version working - so starting on Droid, I copied the whole binding section from ios, and it worked perfectly. So, the whole binding, I can make it same across all platform... Any possible error in my way will stop at building, which I think is a major advantage over axml binding. Even the control creation is extremely similar, where I have helpers with same method name.
Ofcourse I understand all the additional layout that has to be handled; to be honest, it's not that bad if one really think it through; I have created a StackPanel for Droid which is based on WP - that internally handles all the layouts for child views; so for LinearLayout, all I do is setup some custom parameters, and let my panel deal with it. Relative is a different story; so far, I have only one screen that's relative, and I can even make it Linear to reduce my additional layout code.
So, from my humble point of view, for my style, code-behind creation allows me to completely copy all my bindings (I do have some custom binding factories to allow that), copy all my control create lines; then only adding those controls to the view is the only part that is different (then again, droid and WP are almost identical). So there is no way I can miss something on one platform and all are forced to be the same. It also allows me to change all the styles for every platform just by changing the core. Finally, any binding error is detected during compile - and I love that.
My original question wasn't about NOT using axml... it was on how to use MvxListView where all the binding is done in code-behind; as I have explained, I got the list binding, but not the item/cell binding working.
Thanks again in advance.
Here is part of my LoginScreen from droid; I think it's acceptable amount of code for being without axml file.
//======================================================================================================
// create and add all controls
//======================================================================================================
var usernameEntry = ControlHelper.GetUITextFieldCustom(this, "Username.", maxLength: 20);
var usernameError = AddErrorLabel<UserAuthorization, string>(vm => ViewModel.Authorization.Username);
var passwordEntry = ControlHelper.GetUITextFieldCustom(this, "Password.", maxLength: 40, secureTextEntry: true);
var passwordError = AddErrorLabel<UserAuthorization, string>(vm => ViewModel.Authorization.Password);
var loginButton = ControlHelper.GetUIButtonMain(this);
var rememberMe = new UISwitch(this);
var joinLink = ControlHelper.GetUIButtonHyperLink(this, textAlignment: UITextAlignment.Center);
var copyRightText = ControlHelper.GetUILabel(this, textAlignment: UITextAlignment.Center);
var copyRightSite = ControlHelper.GetUIButtonHyperLink(this, textAlignment: UITextAlignment.Center);
var layout = new StackPanel(this, Orientation.Vertical)
{
Spacing = 15,
SubViews = new View[]
{
ControlHelper.GetUIImageView(this, Resource.Drawable.logo),
usernameEntry,
usernameError,
passwordEntry,
passwordError,
loginButton,
rememberMe,
joinLink,
ControlHelper.GetSpacer(this, ViewGroup.LayoutParams.MatchParent, weight: 2),
copyRightText,
copyRightSite
}
};
I just came across a similar situation myself using Mvx4.
The first link you mentioned had it almost correct AND when you combine it from Staurts comment in the second link and just remove the surrounding DelayBind call, everything should work out ok -
public class CustomListItemView
: MvxListItemView
{
public MvxListItemView(Context context,
IMvxLayoutInflater layoutInflater,
object dataContext,
int templateId)
: base(context, layoutInflater, dataContext, templateId)
{
var control = this.FindViewById<TextView>(Resource.Id.list_complex_title);
var set = this.CreateBindingSet<CustomListViewItem, YourThing>();
set.Bind(control).To(vm => vm.Title);
set.Apply();
}
}
p.s. I have asked for an Edit to the original link to help others.
Bit of a mystery to me this, but I have a table in libgdx where everything is being positioned in new cells vertically;
I am not using .row() anywhere.
Probably doing something stupid here but I cant see it.
Clues as to what can cause this?
(I'll post the code if needed, but its not that neat, and seeing as I think knowing anything that can cause a newline will help me, it shouldn't necessarily be needed)
edit
Tried to cut the code down to all the bits that happen when an item gets added
Code;
//function that triggers on adding
//SSSNode is a semantic reference for the items details,it just justs made into a label like object
public void addItem(SSSNode itemsnode){
Item newitem = new Item(itemsnode); //Item extends label
allItems.add(newitem);
super.add(newitem).size(60, 30).top().left().fillY().expandY();
//pack();
//super.invalidate();
//super.validate(); (tried doing pack, validate, and none...neither helped)
//update the GUI bar in case the inventory tab isnt there yet
MainExplorationView.usersGUI.setDataVisible(true);
}
The following code is in "usersGUI", which creates and handles the popup called inventory which is whats in the picture and is the table I cant get to behave.
//ensures the interface for the inventory popup is setup and visible
//also refreshes the links
public void setDataVisible(boolean visible){
if (myContents.isVisible!=true){
myContents.isVisible=visible;
refreshlinks();
setupInventory();
}
}
private void refreshlinks() {
super.clearChildren();
super.addActor(backgroundobject);
super.addActor(ME.playersInventory); //re adds the inventory panel table?
int y = 440;
ME.playersInventory.validate(); //revalidated the table (I dumped this almost everywhere in frustration)
//below is not relevant, it updates other items in a onscreen gui
for (InterfaceButton link : allLinks) {
if (link.isVisible==true){
link.setPosition(5,y);
super.addActor(link);
y=y-30;
}
}
backgroundobject.setSize(85, 200);
backgroundobject.setPosition(0,y+20);
}
//ensures inventory is setup once.
public void setupInventory() {
if (setup){
return;
}
Log.info("setupInventory");
ME.playersInventory.setPrefWidth(super.getWidth());
Log.info("width is "+super.getWidth());
ME.playersInventory.setHeight(200);
ME.playersInventory.pack();
float X = myContents.getX();
float Y = myContents.getY()-ME.playersInventory.getHeight();
Log.info("popping up inventory at:"+X+","+Y);
ME.playersInventory.setPosition(X, Y);
super.validate();
setup=true;
}
The full code is also on GitHub;
https://github.com/ThomasWrobel/MeshExplorerGDX
The whole project is a game being made to demo/test and open source distributed semantic database system. The relevant bit is the inventory and the maybe the gui that creates it.
Anyone with good knowledge of LibGDXs workings should I think not need to look any of the code though if theres other things that can tell a table to start a new row. (ie, any layout restrictions that can cause it to happen automatically? )
layout ending the current row was a side effect to make the layout logic simpler. It is now fixed.
Note HorizontalGroup is still a better fit for your use case and has the benefit that you can add/remove actors at any index.
The answer seems to be that layout() causes new rows;
http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=15857&p=68533&hilit=layout#p68533
Adherently this is how its supposed to work, despite the docs not saying that.
When my LongListSelector is scrolled to bottom, I want to automatically load more data from a web service. Just like the Store app does. My problem is that I can't found any event to trigger the load more action.
The recommandation from Microsoft is to use the LongListSelector.ItemRealized event, check if it's the last item (or the Nth last item) in the list to be "realized" and if it is, then it will start fetching new records. In terms of UX, it's best to show a ProgressIndicator on the SystemTray at the time and not try to imitate iOS with inline spinners.
LongListSelector.ItemRealized is actually a very interesting event since it fires when an Item has been data bound to a virtualized ListBoxItem. That means that the LongListSelector virtualization logic thinks it needs to prepare the FrameworkElement to be shown on screen. The ListBoxItem may or may not be on screen yet, but it's a good indication it's getting there.
For a code sample see # http://code.msdn.microsoft.com/wpapps/TwitterSearch-Windows-b7fc4e5e
void resultListBox_ItemRealized(object sender, ItemRealizationEventArgs e)
{
if (!_viewModel.IsLoading && resultListBox.ItemsSource != null && resultListBox.ItemsSource.Count >= _offsetKnob)
{
if (e.ItemKind == LongListSelectorItemKind.Item)
{
if ((e.Container.Content as TwitterSearchResult).Equals(resultListBox.ItemsSource[resultListBox.ItemsSource.Count - _offsetKnob]))
{
Debug.WriteLine("Searching for {0}", _pageNumber);
_viewModel.LoadPage(_searchTerm, _pageNumber++);
}
}
}
}
I am using JTabbedPane with JPanel to display JTable on one tab and text, dropdown and jbutton on other tab.
First time it is working fine but if i minimize or switch screen to other application and come back to my application it display data correct but with a serious problem with tab change in JTabbedPane. Now tab screen goes to blue and don't display the data.(I hope data is there but it is not repainting or refreshing complete window).
Now with blue screen i do the same procedure and change tab in JTabbedPane it shows correct data.
I used repaint but it doesn't work.
Help needed to refresh window or tab correctly.
It may problem of Browser you are using jdic.dll. Try using any other browser to reload your tabbed pane.
I guess this "issue" is an evergreen. I assume, that most people stumble over this issue possibly when implementing JTabbedPane changes (removing and adding of tabs) in the wrong event-method:
For example, if you want to remove a tab and add a new one in the tabbed pane based on a selection in a JComboBox, you have to put your logic into an 'itemStateChanged'-event of the ItemListener added to this combo-box. If you put your tab-change-logic e.g. into an propertyChangeEvent (PropertyChangeListener), you are doing it all wrong and the timing is always messed up for repainting/refreshing tabbed pane UI elements!
If you use the right event-method, you don't even have to call setVisible, revalidate nor repaint. It will all work out perfectly.
Here's a simple example:
JComboBox<String> c_editor = new javax.swing.JComboBox<String>();
c_editor.setModel(new javax.swing.DefaultComboBoxModel<>(
new String[] { "CSV", "EXCEL", "HTML" }
));
c_editor.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
c_editorItemStateChanged(evt);
}
});
...
protected void c_editorItemStateChanged(ItemEvent evt) {
// get the value selected in the combo box
final String val = c_editor.getSelectedItem().toString();
if (tabbed_pane.getTabCount() > 1) {
// remove the panel which is at position 1
tabbed_pane.removeTabAt(1);
}
if (val.equals("CSV")) {
// add the panel for viewing CSV files
tabbed_pane.addTab("CSV Editor", p_csv);
} else if (val.equals("EXCEL")) {
// add the panel for viewing Excel files
tabbed_pane.addTab("Excel Editor", p_excel);
} else if (val.equals("HTML")) {
// add the panel for viewing HTML files
tabbed_pane.addTab("HTML Editor", p_html);
}
}
That's all, nothing else necessary - the UI will update itself. PS: This issue has nothing to do with browsers as suggested by the 'favoured' answer in this thread, it's all about Java Swing GUI's.