Solved

Keeping track of JTable changes

Posted on 2006-06-17
10
531 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 125 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 125 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 125 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 125 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

691 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