Solved

Keeping track of JTable changes

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

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Jpanels and Jframe 8 28
netstat -ano | find "8000" and taskkill /f /pid 2984 3 30
difference of if loops 23 39
fibonacci ten numbers 4 24
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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.

919 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now