JTable design to synchronize with back-end data-structure?

I have a JTable which is loaded from a data-structure using table model.The data-structure is of the format NavigableMap>.An example data is:

Table Format:
Range f1,v1 f2,v2 f3,v3 f4,v4
12.1-30.2 30,true 32,false 45,true 50,false
30.2-45.6 30,true 32.4,true 45,true 50.1,true
The above data format is represented in the DS as

DS Format:
Key Value
12.1 <<30,true>,<32,false>,<45,true>,<50,false>>
30.2 <<30,true>,<32.4,true>,<45,true>,<50.1,true>>
45.6 null
I have managed to represent the above given data in Jtable using table-model.Once the data is loaded from the DS to the table I have to allow user edit.Now this is where I have problem.My doubt is whether is should keep the data structure synchronized with the changes in the table or should i recreate the DS from the table once the user finish editing and then replace it with the old one.

I would recreate your DS once the user is finised editing the table.

 

You can always create a custom editor to display a popup dialog where you have two separate text fields for each value of the range. Then you can edit each field as a double value within your specified range and recreate the formatted string before saving it to the model. Here's an old example I have lying around to get you started:

 

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

 

/*

 * The editor button that brings up the dialog.

 */

//public class TablePopupEditor extends AbstractCellEditor

public class TablePopupEditor extends DefaultCellEditor

    implements TableCellEditor

{

    private PopupDialog popup;

    private String currentText = "";

    private JButton editorComponent;

 

    public TablePopupEditor()

    {

        super(new JTextField());

 

        setClickCountToStart(2);

 

        //  Use a JButton as the editor component

 

        editorComponent = new JButton();

        editorComponent.setBackground(Color.white);

        editorComponent.setBorderPainted(false);

        editorComponent.setContentAreaFilled( false );

 

        //  Set up the dialog where we do the actual editing

 

        popup = new PopupDialog();

    }

}