Instantiate a TreeViewer before opening a dialog - dialog

I have a TreeViewer inside a jface Dialog window.
The treeViewer needs to be populated with a large number of items with the setInput().And so it takes quite a bit of time for the tree to show, each time the dialog window is opened.
I want to know if there is any way to instantiate and save the treeViewer beforehand, so that the when the dialog window is opened, the treeViewer is just added to the dialog window and it is instantly visible.

I don't recall ever seeing anything try to do this. Creating the tree has to be done in the UI thread so this would still be difficult to do without stalling the UI.
There are various things you can do:
The model objects that the content provider provides can be built at any time since they are not UI objects. So you could get these in the background before the dialog is displayed.
You can use a virtual tree using the SWT.VIRTUAL style and an ILazyTreeContentProvider to delay building parts of the tree until they are needed.
If the code is in an Eclipse plugin you can use org.eclipse.ui.progress.DeferredTreeContentManager to defer building parts of the tree (there isn't much documentation on this method).

Related

Are InputComponents and Dialogs incompatible?

In the simple Dialog below:
// choice of layout has no impact:
Container cont=new Container(new TextModeLayout(3, 1));
//Container cont=new Container(new BoxLayout(BoxLayout.Y_AXIS));
TextComponent firstName=new TextComponent().label("First Name").text(person.firstname);
TextComponent lastName=new TextComponent().label("Last Name").text(person.lastname);
TextComponent cost=new TextComponent().label("Cost per Session").text(person.getCostString());
cost.getField().setConstraint(TextArea.DECIMAL);
// NOTE HERE
// doesn't work: // works:
cont.add(firstName); // cont.add(firstName.getField());
cont.add(lastName); // cont.add(lastName.getField());
cont.add(cost); // cont.add(cost.getField());
Dialog.show("Edit Client", cont, new Command(CANCEL), new Command(OK));
Nothing appears in the Dialog unless I add the TextField instead of the TextComponent to my container at the NOTE HERE comment. This means I lose the nice appearance of the labelled input fields (yes I know I could label them myself, but they wouldn't look as good on different devices). My choice of layout manager at the top does not affect this issue (I've tried several). I can't find evidence online to conclude there's an incompatibility here, adding TextComponents and other InputComponents works fine on a Form, just not in a Dialog.
I'm having the same problem in another Dialog that uses PickerComponents. The PickerComponent doesn't appear unless I add the Picker itself, and then the Picker spawned from a Dialog looks all wrong. I'm hoping the simpler code question above will answer this quandary as well.
It's worth noting I've made no theme changes and this problem is noted in both the Android and Apple skins as well as on an actual Android phone. Thanks in advance for any help!
You shouldn't do input in a Dialog as it creates a very problematic user experience. If you would like things to look like they are in a dialog you can use styles and layouts to make a Form feel like a Dialog but you shouldn't use a Dialog.
The reason this fails is a bit complicated but here are the high level problems with using a dialog:
Dialogs don't grow implicitly - This is a huge problem for text input as the component needs space to resize with input and even more so for the animated TextComponent which needs to shift things around. The size of a Dialog is determined when it's shown and that's a big problem
This becomes a bigger problem on Android where the screen resizes during input and distorts the dialog completely. It's one of those things you'll only see on the device because it's really hard to simulate the virtual keyboard.
Scrollability is hard in a Dialog and text components need a scrollable parent so you can scroll between the various edit components
Picker component uses a form of Dialog to show input and this can collide with your dialog
Dialogs are hard to get right for suspend/resume behavior. Suspend/resume happens when the app is minimized or sent to the background. E.g. say you have an incoming call while typing in the dialog. When you go back to the app we want to show the last form. If we show the dialog it will block and we won't know which parent form to show anyway. So when an app is suspended dialogs are just disposed in the default code generated in the main class. It makes more sense.

Browser Window in each method of test case? Using coded ui

I am new to coded UI, is it good practice to initialize Browser Window in each method of test case. For example i have two methods in my test case, I am trying to find control in each method, for that i write browser window in each method, can i write like that.
I don't see an issue with that approach.
Are you trying to reduce code/setup statements?
It really depends, you could have a test class with many test methods. however have a method attributed with ClassInitialize to launch the browser one time (and set the option to not destroy the window after each test) and keep reusing the same window. Then, possibly, have a method to close the window attributed with ClassCleanup.
Then in a test, you should only potentially need to use the NavigateTo method at the start of your tests to be on the right page.
Do you have test requirements dealing with sessions or saved data?
You may need to actively close down a window after a test and programmatically empty caches. Then in this aspect, I would be using BrowserWindow.Launch typically and letting CodedUi automatically destroy the window if i forgot to call close on the window.

Coded ui objects in UIMap

I have a question regarding coded ui UIMap.
Every time I record an action on the same application, coded ui generates a new object for the same window in the application.
It looks like:
UIAdminWindow
UIAdminWindow1
UIAdminWindow2
and so on...
every window class holds different buttons, even though it's the same window.
Thus it's very hard to keep code maintenance.
What i would like is that every time i perform actions and records on a window, even if not at the same time, the already generated class for this window, will be updated with the new controls.
any suggestions to why it happens?
Thanks a lot!
You can clean up your UIMaps by doing two things:
Use the UIMap Toolbox (from codeplex) to move controls within the UIMap so they are all under one control tree.
When you have duplicate UI controls, go to the properties for the action that references the duplicate control and change the UI Control property to point to the original control in the UIMap.
The duplicate trees should now be unreferenced and you can delete it from your map, keeping things clean.
And yes, it's a pain to do, but it's worth it for maintainability.
In UIMap.uitest you can change the action name and the control name for better maintenance.
For example: you can set UIAdminWindow as FirstAcessWindow or other name that will express comfortably the control or the action.
What I can guess is that there is some randomly generated content or element identification data such as class or title that may be causing it. This may be caused by different username for example. Also you can update the element from UI map element tree.

Saving the states of JavaFX controls on exit

I have a bunch of control objects (TextBoxes, to be precise) that get injected into my code using the #FXML annotation during the FXML load.
I would like to save the states of these controls, specifically the text values, when the user closes the Scene by clicking the close box on the title bar.
However, when I trap the CloseRequest event in an OnCloseRequest handler I find that the values of the control variables are null (the original injection works, so this is something that happens in between the loading of the FXML and the calling of OnCloseRequest).
Can anyone explain this behavior and/or suggest how I can get the functionality that I want?
TIA
onCloseRequest is
Called when there is an external request to close this Window. ...
(from Javadoc). One of the meanings of "external request" is when you close the window through OS native window close button. The closeRequest event is not triggered through the programmatic stage.close() or stage.hide() calls. So consider to handle onHiding or onHidden events.
Otherwise post your OnCloseRequest handler code.

How can I calculate the client area of an MFC CDialog without displaying it?

How can I obtain the Window Rect of a CDialog which is based on a dialog template. The dialog is not and can not be visible
It might be tricky with CDialog, because if you dont show the CDialog, the window handle is not created and you cant call GetClientRect.
Might i suggest calling CreateDialogIndirect instead to create the dialog, then you can get the client rect. You dont need to show the dialog. I think as long as the window handle is created, the GetClientRect should work. I am not an expert though and its been many years since i have written MFC code.
Well...
In Windows API-land, you could load the resource yourself (FindResourceEx, LoadResource), understand the binary structure of the dialog template resource (some clues at http://blogs.msdn.com/oldnewthing/archive/2004/06/22/162360.aspx), convert the size of the dialog in the dialog template from dialog units to pixels (check out http://msdn.microsoft.com/en-us/library/ms645475(VS.85).aspx).
I'd be curious why you'd want to do this, though.

Resources