?
Solved

Keeping track of JTable changes

Posted on 2006-06-17
10
Medium Priority
?
532 Views
Last Modified: 2012-08-13
Hi,
  I am writing an application that displays database tables in a JTable object.  I am using this dialog to allow the user to make changes to the table.  I am having a hard time designing a way to keep track of user changes.  I want to be able to know when the user has made changes so I can save the data to the database.  

Later down the road I also may implement an undo feature and may want to keep track of the user changes in general.  I have not found much documentation on the web and was wondering if anyone would be able to help?

Thanks for all your help!!
0
Comment
Question by:Brock20
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16928128
Just make a copy of your TableModel
0
 

Author Comment

by:Brock20
ID: 16928150
So I should have a copy of the TableModel and then compare the data?  Wouldn't this take up resourses?  I was trying to think of a way to have the model or the view know that something has changed.  Not sure if that is the proper way to do it.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16928164
It depends what you want to do. If you don't need to know what the changes are, but merely that changes did occur, just calculate the hash code before and after
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Brock20
ID: 16928186
1.)  How would I calculate the hash code?

2.)  So if I want to know what the changes are you are suggesting to keep two copies of my model?  Is this expensive?  
0
 
LVL 26

Accepted Solution

by:
ksivananth earned 500 total points
ID: 16928928
if you feel having a copy of the model is expensive, just add nonvisible column( flag tracking changes ) in the model. and you are going to update the flag when there is a change in cell, here the drawback is that the flag is going to tell u that the data got changed even if the user had reverted the changes by updating the changed cell again. But this can be worked around!
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 500 total points
ID: 16929022
>>How would I calculate the hash code?

Iterate the model and add the hashcode of every value

>>Is this expensive?

That would depend on the size of the model
0
 
LVL 1

Assisted Solution

by:FunnyMan
FunnyMan earned 500 total points
ID: 16929891
Hashing's relatively cheap, it's a linear-time algorithm, meaning that it takes about twice as long to run it on a data set that's twice as long.

The better alterantive, though, is to implement TableModelListener and add your class as a listener to the underlying TableModel (via table.getModel().addTableModelListener(this)).  Then you can just watch the TableModelEvents that come past and keep track of them.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 500 total points
ID: 16931027
You shouldn't need two copies of the table model, a TableModelListener as FunnyMan has suggested could easily be used to notify you when a value in the table changes.
When it gets called you can start a thread to perform the required database update.

http://jdj.sys-con.com/read/36636.htm
http://www.oracle.com/technology/products/jdev/howtos/10g/interceptor.html
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question