Java table arraylist modification - java

Basically it's a task to manage properties, and I am doing a much more complex solution than it is required. It is just the last bit where I struggle.
To give you an idea of what we have:
Properties (superclass)
PropertiesToLet(extends Properties)
PropertiesToSell(extends Properties)
EstateAgent (GUI to manage the properties)
So the part I am struggling with is basically the EstateAgent class.
What I wrote so far: http://pastebin.com/0qieM67j
That a about 500 lines - But I need help with the theoretical part not the programming part - because I dont want you to do my coursework - I just need the solution how to approach that.
The lines I am struggling with are from:
55 to 113
Its about a table that I create and insert rows into it. Each row represents a property. It could be a propertyToLet or a propertyToSell object. Those properties come from my ArrayList<Property> properties.
The inserting row and showing the table is fine and it is working the way it should. So there is problem with the code. I apologize for the code structure - but we are limited in the submission - so we cannot submit more than 4 files those file are obviously the named classes - so I cannot extend any more classes or files to the project.
So what I want to do now is: Editing a property.
I have the row that represents a property. It is showing me the position in the arrayList and all the values that I can get.
So now there are a few more possibilities.:
Add and Remove a tenant from a PropertyToLet
base on a tenant you can collect the rent and pay the rent and see how much rent is left to pay.
Add and Remove a purchaser from a PropertyToSell (the sold will then change according if there is a purchaser or not)
So basically there are several ways how to continue from here. For instance it could be a behaviour like this:
RightClick on the property opens a context menu where the mouse is and I can choose other options such as: Remove Tenant, Add Tenant, Collect Rent, Show Rent Owed, Add a purchaser, Remove a purchaser ---- ofcourse depending on what kind of property it is.
Double click on a row => edit the property ( have a look at this screenshot)
it shows a window that I use to add a property - I could add all the values in the field and that button changes to "Update Property"
That would be one solution another one would be:
- Edit the cell of the row => changes the value of the property (they will inspect the object and see if that really changed and not just the row value)
That are my ideas of how to inject the last steps of bringing the functionality into the application.
So here are my questions:
And than I need an outside opinion what is easier and faster to implement in this very limited task. The way of opening the existing add window and change it to an edit window - I don't want to have redundant code!
Or changing the value by editing the cell so that the values in the arraylist change.
I need some help with the approach what is easier and what is better.
I really appreciate any help here!
I am looking forward to see some answers.
EDIT
I finished the popup Menu thank you for your help. I edited the question as wel.

Since jdk5, the recommended way to attach a JPopupMenu to a component is
component.setComponentPopupMenu(menu)
This popup is automatically shown when a user gesture (mouse or keyboard) is interpreted as popup trigger - which may vary across OSs.
As to selecting a row on right (popup-trigger) mouseEvent: it's not done by default in Swing, but seems to be the norm nowadays for (near-)native applications (on vista) - arguably a but in Swing. Volunteers to report, anybody ;-)

Related

Options menu for one cell in java table

Welcome
In this table, I made the column mentioned cells editable to let the users make the needed value as they want ...
But they told me the values of this column can take just one of the values: 25,50,75,100, so, they asked me I make an options menu (like it is mention in the pic) allow them to choose directly the needed value and working fast.
So, how can I solve it, please!
(note: I'm working with java swing)
It's not the same question, but you can take a look on solution from below question:
How do I create a right click context menu in Java Swing?
you should create such listener, and add it to your Cell / Table.
you can take a look on below question to understand how to add listener to your Cell (it's not obvious :/)
JTable cell listener?

Select from a UI list and perform an action

we're building a small chat app for an assignement in our university. I have a question regarding how I can implement something.
This is our ui. The big white part is a jTabbedPane where conversations the user is participating in will appear. The two small ones are where active groups and active users will appear.
I found out that I can populate a jcombobox from a linkedlist using .toArray. I don't know what ui element to use, in order to display the list elements one under the other, and being "selectable" (only one at a time). The concept is that the user will select a group and press "Join", to, well, join.
This is what I have in my as to how it will look in the end.
Any pointers and advice in general would be greatly appreciated.
It looks like you're wanting to use either a JTable or a JList -- one with a custom renderer, a renderer that displays both the group name and its "status"(?).
If a JTable, then your key job is to create a TableModel that will accept your data well, either by using the DefaultTableModel (the easiest way to do this), or by creating your own model derived from the AbstractTableModel (a little more difficult, but more flexible).
For a more detailed answer, consider providing pertinent code, preferably as a minimal example program or MCVE.

Java GUI architecture for larger project

I want to make an app, which will work as interface to several servers.
Why: In web iface provided by default (and we cannot change it) are few things we miss, few could be done better and for sure automation of some stuff would make the job easier.
What do I have: almost finished classes for communication with web interface of a server app.
GUI description:
For some kind of version 0.1: text field for username, radio button to select server and one "go" button. Then several (4-12) action buttons to operate on data, 2x text area with results, one label with some text data - I can manage this.
Then I need to view the data - grid MxN which will load the data, expected size: 7-15 columns, usually 10 rows or less, but rarely it can go over 1k (or even more, but I don't need all to be visible to the user in that case).
What I need: simply an advice.
I wish to start with a simple version (and I'm working on that already, but I'm stuck on too many things - 95% cos and absolutely new to GUI and 5% cos I'm new to java).
I've checked many tutorials, but they're all simple.
Real questions:
1) Verify. In MVC controller should handle all user actions - is it done by view's method which is something like button.addActionListener(param); anotherButton.addActionListener(paramp; ...?
1b) I've seen all implemented via one (nested) class, which was then checking source or smth - is that ok? There will be a lots of buttons etc.
2) How to implement the data grid, when I need to take actions on click / dbl click?
4) First row is header, the rest should be scroll able - should it be in the grid or outside (its own grid):
4a) How to make sure header's size (width) will be the same as in data (I don't want to set up straight size)
4b) I failed to create anything scrollable so far, but thats my bad I guess. How to ensure header will hold on a place and the rest can be scrolled?
5) How should be "data update" implemented? I've got JPanel from which I remove grid component and then I make new one and add data into it (simple, but perhapss there is another way). One of first enhancements will be sorting - use the same way I used for new content?
Thanks a lot for any answer, I know this is not very specific, but example I've found are too simple.
I plan a lots of enhancements, but thats in the future and I don't mind to rework GUI/Controller several times, at least, I'll practise, but I don't want to finish one part of the code and realise I've got to rewrite half of a controller and 1/4 of a view to make it possible.
Note: I plan to use this at work as my tool (if things go right, I could make 25-50% of my work by few clicks :-)
So I really mean this).
Note#2: I'm not new to programing, but I've never created GUI (which is why I've got GUI with menu bar with 2 items and 3 components and almost done web-iface connections).
Note#:3 dragable data header, tabbed data view - thats the plan for the future :-)
MVC in Swing is examined here; use nested classes for ease in prototyping and creating an mcve for future questions; as the need arises, nested classes can be promoted to separate classes having package-private access.
Use JTable; its flyweight implementation of renderers is good for organizing data by row and column.
Item three does not exist, but "always remember to translate cell coordinates" if you plan to drag columns or sort rows.
Use a JScrollPane to keep the table header stationary.
Update the TableModel, and the listening view will update itself in response.
If you are interested not only from the event/messaging architecture, but also on handling mouse/keyboard input, hovering detection, widgets, temporary menus, form re-sizing with widget alignment, dragging and dropping etc. I can advice you to look at this question and my answer with helpful resources.

Tracking data offset of data in a table to retrieve the previous/next subset on table scroll

I am writing a browser based application using GWT and making use of websql (yes, I know it is deprecated). I have created a custom table widget (based on FlexTable) and enabled it to scroll with the help of some CSS trickery. What I am striving to achieve (without much success) is that when the user scrolls to the start/end of the current data in the table, an event is fired and the next subset of X rows is returned from the websql DB and replaces the data currently in the table. In order for this to work, I need to keep track of the data offset in the table widget so that I can pass this to the query and use the limit and offset functions of SQL to return the required data. However, I just cannot seem to get the logic right to implement the data offset tracker within the widget. Another complication is that I need the table to be able to scroll 'into the past' (so to speak), so that it can retrieve data from before the initial start point when the table loads.
I have been at this for a number of days now and just cannot seem to get it right. So I was wondering/hoping that someone might be able to point me in the right direction (PLEASE!).
Thanks in advance
Tim
I am not sure why this is causing a problem.
int page = 0;
// when you hit the bottom
page++;
loadData(page);
// when you hit the top
if (page > 0) {
page--;
loadData(page);
}
Tim I think it is not a good idea controlling the scroll with CSS trickery.
I have done something similar soon and controlling all the logic (pagination, scroll positions,...).
What I suggest to use is a gwt's scrollPanel, a HasData widget (like a cellList) your custom AbstractCell (class which is rendered for each row of your list) and asyncDataProvider ( which gives you the onRangeChange handler for asking to your server when the range data display has changed).
You can force/fire that event when in scrollPanel.addScrollHandler detects you are arriving to the end.
If you want to see all of this in action have a look into (click on source code): http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellList
EDIT [according comment below]:
A. If you want to override the data (in the example is X+X+X...) with the new retrieved just maintain always the same range of data displayed [display.setVisibleRange(0, newPageSize);], and start from 0 when you render the new data (on your RangeChange listener).
B. If you need to have control over up and down scrolls instead of taking advantage of the used events internally on the cellList (basically onRangeChange), you can create your custom events and fire them (this option could be easier for your colleagues for understanding everything). And do not worry about controlling up and down scrolls, inside the ShowMorePagerPanel.java you can see a simple example of knowing up and down controls.
Anyway, I did not explain more detailed because I did not see you very convinced to use CellList approach (and I was using my tablet :D ).
If you change your mind, just let me know and I write for you a proper example step by step (this part could be tricky, so if you are lost it is normal ;) ).

find and select in JTable

Hi am creating an application in which I am using JTable to listing of file or folder names.
My question is:
How can I find and Search a Particular file or folder in JTable like in Windows.
In windows directory listing when we press any key then we can see that file or folder start with that character is selected and if we again press same key then next file/folder is selected with start with that character.
If you can use 3th party code, I would suggest to take a look at the SwingX project. Their JXTable, JXTree, JXList and some other classes provide an implementation of the Searchable interface, which makes creating a search widget a breeze.
And if that is even too difficult, they provide out-of-the-box a JXFindPanel which provides a UI to search a Searchable
If you can (and you're willing to) use third party UI components, the Open Source JIDE Common Layer offers a few nice components: e.g. you might like FolderChooser which has an automatic find-as-you-type functionality.
Here's the link: JIDE Common Layer. If you click the "RUN IT" button you can see a sample via Java Web Start.
I've used many JIDE components (only the open source ones) in my projects and avoided reinventing the wheel many times.
Hope this might help you.
You want an action happen when a key is typed ?
-> add a keyListener to your table
You want to know which row is valid
-> query your datamodel connected to your jtable
You want a selected row to change ?
-> in the keytyped implementation of your listener change the selection
table.getSelectionModel().setSelectionInterval(1,1);
Since I don't know something about how did you implement your code logics, JTable implemented Sorting and Filtering
but you describtions talking about JTreeTable
I would consider writing a custom TableCellRenderer, responsible for highlighting any matching letters in the String being rendered. When someone updates the search text field the simplest approach is going to then be to repaint the entire JTable to show the updated "match state" of the table cells.

Categories

Resources