We are trying to build a GUI framework using GWT. We are finding it hard to implement the cancel functionality in the framework.
Required feature is this:
We have CRUD screens which have pop-ups, grids and so on. When the user changes anything in the GUI and then clicks on cancel() he should be given a notification message saying that something has changed.
Approach that we have tried:
Currently we are trying to keep a hashmap of key vs value of the entire pojo object and trying to compare it against the model which gets updated as and when user changes something. But this is adding lot of unwanted code in every pojo and not working as expected when user adds data directly from the backend.
Is there any elegant way in achieving this functionality? Kindly note that *we are not using Editor framework of GWT *(https://developers.google.com/web-toolkit/doc/latest/DevGuideUiEditors) in our application.
Example:
Suppose I have a pojo like this:
public class Person {
List<Address> address;
PhoneNumber phoneData;
// and so on along with getters and setters
}
How will I write a generic clone method for this? And even if I manage to do that somehow that will lead to lot of code in every pojo (our application has hundreds of them) which doesn't seem right.
Please note that, our pojo gets updated as soon as something is changed in GUI to achieve live binding.
So you have "Save" and "Cancel" buttons in your form?
I would recommend you to change the concept. Update your object properties immediately as user edit them (as in GMail, JIRA and many other modern applications) in an OnChange event handler.
Save all updates to the session stack as UpdateAction objects and let the user undo every single property modification calling UpdateAction.undo() method.
The benefits are:
this design is much more user friendly than "Click "Edit" - update - click "Save"" scenario.
You don't need separate view/edit forms/popup dialogs - just a single form for both viewing and editing.
Related
This is updated version of the question javafx-TableView as combobox popup (Tried and able to achieve partially. need help further)
Based on few inputs I got here and referred some existing custom controls (controlsFX), I started implementing my custom control and achieved most of it but got stuck in middle. So need your support.
I have attached my whole project here for reference.
Let me explain my requirement first.
My real application consists of around 40 to 50 text fields in the scene. Suggesstions should be poped up, based of the text typed by the user in the text fields and user should select something using keyboard and able to tab out to the next text field. The suggesstion popup should be a table view with 2 or more columns. The search can be applied on any 1 column or all columns which should be configured by the user while instantiating the control. Please see the screen shot for your reference.
Now what I have achieved.
I have created a CustomControl with 2 classess which will show a popup with a table view inside below the configured node.
**TableViewPopup.java extends PopupControl
TableViewPopupSkin.java implements Skin<TableViewPopup<T>>**
refering AutoCompletePopup.java and AutoCompletePopupSkin.java from controlsFX project.
This is working as expected (atleast most of the functionalities).
Then I should be able to attach the TableViewPopup to a TextField.
So I created another CustomControl with 2 classess
SearchableTextField.java extends TextField
SearchableTextFieldSkin.java extends TextFieldSkin
So this is the control user will add it to their scene finally and tell this control what tableviewpopup should be displayed when the text changes.
Till here everything works fine.
Where I got stuck or what I want to do?
<SearchableTextField fx:id="personSearchableTextField" referenceDataControlNameToLoad="/view/PersonReferenceDataTableView" />
<SearchableTextField fx:id="vehicleSearchableTextField" referenceDataControlNameToLoad="/view/VehicleReferenceDataTableView" />
In the above code snippet, I have 2 instances of my SearchableTextField each shows 2 different TableViewPopup(one with Person and other with Vehicle).
Now I want to apply different predicates to the tableview's filtered list as the user started typing in the text field.
I have attached a textChangedListener which is inside the SearchableTextFieldSkin class. First of all I dont know how to get the filtered list inside the textChangedListener (Please advice is there any better way.) but somehow I'm referring the filtered list but dont know how to apply the predicates bcoz it may be any different enitties (in my case it may be Person entity or Vehicle entity).
I dont want to check the instances hard coded bcoz in my real application i have around 150 entities.
I also dont want the predicates related logic inside the SearchableTextFieldSkin class. means, i want all my different predicates in a separate file and just want to call them.
Or atleast somehow route the filtering logic from the SearchableTextFieldSkin class.
Please suggest a way and a better way. I really concerened about performance bcoz what i am doing is a c# with dev express components project that i am currently rewriting in java using javafx bcoz the performance is worse like anything in c#.
Thanks in Advance.
I would be trying to keep the Predicates close to, or inside, the controller that needs to use them. PersonController should deal with Person predicates, VehicleController with the Vehicles ones, and also with any logic for deciding which fields are searched etc.
There are a few ways to do what I'm thinking, but they all boil down to passing the search field text back through to the IGenericReferenceDataController implementation, which resets the Predicate on the FilteredList.
You could expose a StringProperty on IGenericReferenceDataController to track the filter text. A helper class that encapsulates the FilteredList and the Predicates for a particular controller, exposes the filterText property and handles the logic for resetting it would be better as that should be fairly generic code that you can plug into the IGenericReferenceDataController keeping it all isolated. Something along the lines of:
public interface FilterHelper {
public StringProperty filterTextProperty();
// any methods to assign filters for columns etc. such as
public void assignCurrentFilter(...);
... etc ...
}
Then get IGenericReferenceDataController to expose it's instance of this class:
public interface IGenericReferenceDataController extends IGenericController {
public FilteredList<?> getInnerTableViewControlDataSource();
public FilterHelper getFilterHelper();
}
You would need to pass that out through TableViewPopupSkin and TableViewPopup until it finally gets to SearchableTextFieldSkin where you can have:
private void registerListeners() {
tableViewPopup.getFilterHelper().filterTextProperty().bind(sourceSearchableTextField.textProperty());
...
}
Your FilterHelper implementation then handles resetting the filter on the list every time the search text changes and SearchableTextField knows nothing.
If there is a faster way to get from SearchableTextFieldSkin to IGenericReferenceDataController you could cut out some of the intermediary methods that just pass the reference along, but I couldn't see any in your code and I don't use fxml so I have no idea what magic might be possible there.
I'm creating my first "bigger" application in Java. As MVC is only pattern I know, I decided to use it. But there's something wrong with this concept.
For example. I need an Action (or generally event) fired from 2 places (from Button in frame and MenuItem). It has to do changes in at least 2 places and in the model.
I've got some ideas, but they seem wrong:
Pass the controller object to every view element, so newly created actions could use controller's methods to modify rest of the application.
Make controller static (for same reasons)
Make controller only model listener
Please tell me how to build it. Or give me some links to some easy to analyse applications.
Source of my project is here, if anyone wants to have a look: https://github.com/Arrvi/ColorExtractor
You are correct to use Action to encapsulate functionality for use by disparate components such as menus and buttons. A spectrum of examples is cited here. As regards MVC, recall that Swing uses a separable model architecture, examined here. In effect, the user is the controller, and not every interaction needs to pass through your application's controller.
My user requires any validation items (e.g. piece of data missing) to be displayed on screen, and not to be actually enforced (i.e. not to be checked to be totally valid) until further along in the process.
To accomplish this, on every save, I'll be checking for the presence of certain data. On initial object creation (of the object to be validated), I'm going to create a list of Validation items referring to specific fields (or their getters) as necessary. I will then be able to run through these items on each and every save, to check whether each item is "Valid" or not. At any point, I'll be able to display validation results to the user, as required.
Does this sound like a sensible approach? Am I missing a standardised way of approaching this task?
Usually validation is not done on save but on change. That simply means you have to attach change listeners to your fields, which then all execute your validation routine.
Listeners are only attached to the fields that are part of
validation.
Validation routine usually builds a list of errors/warnings which can be later presented in your UI
Also using JGoodies Validation will simplify your task. It is the best validation framework for Swing IMO
I hope I can explain.
I don't have a problem, just I want to know how to build my users system control and I want to know if my idea is correct:
My idea:
*One class (file 1) to functions, methods and operations
*Other class (file 2) to swing elements, buttons, textbox, etc.
*But I don't know how connect these two classes.
For example:: I have 2 textbox (user, password) and one button, then when press the button, send data of each textbox(file 2) to a function (file 1) and process.
If you have any other choice, I'd read it.
Thank you in advance
You should use the Model-View-Controller pattern to solve your problem. Basically, your view (the swing files) only know how to display content, and let the user of the class (the controller) subscribe to receive notifications when the content is changed (this is done with swing listeners). When the content is changed the controller can act on it, modify the model if necessary and also update the view (again, using methods provided by the view).
The GUI should never involve functionality. It should only have code that is used to display what you want. This helps create a better architecture.
I am developing a project in a MVC architecture. It should be a simple application to manage some customers.
There are MainModel, MainView and MainController classes which make the main window to show the content of the customers tables and to let the user insert, remove or edit customers.
My problem is that the insert and edit buttons should show some dialog windows to let the user insert and edit some text values and I have some doubts.
I would like to ask you some questions:
Should I use the MVC architecture for each dialog window?
If yes, I have tried doing it but my dialog windows are modal, so my code runs the model, runs the view but it gets blocked in the view and it doesn't run the controller class. How could I solve it?
For example here it gets blocked in the "new InsertCustomerController..." instruction:
CustomerModel customerModel = new CustomerModel();
InsertCustomerView insertCustomerView = new insertCustomerView(customerModel);
new InsertCustomerController(insertCustomerView, customerModel);
Thank you very much.
Irrespective of modality, you can use the observer pattern to keep your dialogs synchronized with the application's model. This example uses a PropertyChangeListener; other approaches are mentioned here.
Although I can't fully tell from your post, I'm not sure you're thinking of MVC the right way. But let's say you have a Customer, CustomerView, and CustomerController class..
Customer could contain all of the business logic related to being a customer-- so it might have methods like setBalance(int newBalance), getBalance(), etc.
The CustomerView class could essentially be a subclass of JPanel or JFrame (since it looks like you're using Swing from your question's tags). This class would be representative of one Customer instance. Maybe you could have a private Customer class variable. This class's responsibilities should only consist of displaying the data to the user contained in its Customer instance as well as allowing them to modify it.
It would be tough to say what the CustomerController would do since I don't know anything about your application, but it could potentially contain ActionListeners and that sort of thing that help to route input and output to the different parts of your model and view.
I did some googling and found a pretty straightforward example you may want to check out: http://www.austintek.com/mvc/
Good luck. Hope this helps.