What is the best way to control application screens in SWT?

I am creating a standalone SWT desktop application that contains about 10 different screens (several wizards, help, forms, etc.). Some elements on the screen do not change at all (for example, title, background, etc.), and there is a work area that changes depending on what is pressed, etc.

What is the best way to control application screens? Do I need to create a full screen at startup, and then show / hide them depending on what I clicked? Or do I need to dynamically create these screens?

Also, I could not find a way to show / hide Composite , do I need to dispose it and then create it again?

What is the best practice? I am new to SWT development outside of Eclipse, so any help would be helpful.

+4
source share
1 answer

The decision whether to create screens in front or to create them at the first display is the decision that needs to be made for each application. If there is a good chance that all screens will need to be used for a certain application launch, and the number of screens will be low (10 screens are relatively small), then you can create them at the application launch, so that the user interface is faster when the application loads.

If you use bindings, you may need to develop a deletion strategy (even if you use only bindings), so you don't have too many events.

The control has a setVisible (boolean) method (and the Composite inherits from Control), which you can use to show and hide the component. Please note that this will prevent the composite from showing on the screen, the layout manager will still allocate empty space for it. Many SWT layouts have the ability to exclude the control from the layout, which will get rid of empty space. For example, if you use a GridLayout, then you set the exception variable for the GridData object to true when you hide this control.

Another option is to use StackLayout. This allows you to stack a bunch of composites on top of each other, and then choose which one is on top. This can be useful for you if you have static areas and a workspace as you described. I would put the header, footer and empty composition using StackLayout in the class file. Then I placed every screen that would be displayed in the workspace in my classes. You can either expand these Composite screen classes and then customize yourself in the constructor or you can use the factory method to customize the screen. Any of these is common and acceptable practice and comes down to taste.

+5
source

Source: https://habr.com/ru/post/1307426/


All Articles