[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Keeping track of JTable changes

Posted on 2006-06-17
10
Medium Priority
?
533 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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 …
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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.
Suggested Courses

656 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