Revision 37814

View differences:

branches/v2_0_0_prep/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/UndoTableExtension.java
25 25
import org.gvsig.andami.messages.NotificationManager;
26 26
import org.gvsig.andami.plugins.Extension;
27 27
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
28
import org.gvsig.fmap.dal.exception.DataException;
29 28
import org.gvsig.fmap.dal.feature.FeatureStore;
30 29
import org.gvsig.tools.undo.UndoException;
31 30

  
......
61 60
                FeatureStore fs = table.getModel().getStore();
62 61
                try {
63 62
                    fs.undo();
64
                    fs.getFeatureSelection().deselectAll();
65
                } catch (DataException e) {
66
                    NotificationManager.addError(e);
67 63
                } catch (UndoException e) {
68 64
                    NotificationManager.addError(e);
69 65
                }
70

  
71 66
            }
72 67
            table.getModel().setModified(true);
73 68
        }
branches/v2_0_0_prep/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/RedoTableExtension.java
25 25
import org.gvsig.andami.messages.NotificationManager;
26 26
import org.gvsig.andami.plugins.Extension;
27 27
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
28
import org.gvsig.fmap.dal.exception.DataException;
29 28
import org.gvsig.fmap.dal.feature.FeatureStore;
30 29
import org.gvsig.tools.undo.RedoException;
31 30

  
......
62 61
            if (tabla.getModel().getStore().isEditing()) {
63 62
                FeatureStore fs = tabla.getModel().getStore();
64 63
                try {
65
                    fs.redo();
66
                    fs.getFeatureSelection().deselectAll();
67
                } catch (DataException e) {
68
                    NotificationManager.addError(e);
64
                    fs.redo();                    
69 65
                } catch (RedoException e) {
70
                    // TODO Auto-generated catch block
71
                    e.printStackTrace();
66
                     NotificationManager.addError(e);
72 67
                }
73 68
            }
74 69
            tabla.getModel().setModified(true);
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/gui/command/CommandStackDialog.java
39 39
	
40 40
	private int lowLimit;
41 41
	private int currentValue = -1;
42
	private int currentSliderValue = -1;
42 43
	private JPanel sliderPanel = null;
43 44
	protected boolean refreshing;
44 45
	private JPanel centerPanel = null;
......
143 144

  
144 145
		commandTable.addMouseListener(new java.awt.event.MouseAdapter() {
145 146
			public void mousePressed(java.awt.event.MouseEvent e) {
146
				int newpos = commandTable.getSelectedRow();				
147
				commandTableModel.setPos(newpos);				
148
				PluginServices.getMainFrame().enableControls();
147
				int newpos = commandTable.getSelectedRow();	
148
				if (newpos >= 0){
149
    				commandTableModel.setPos(newpos);				
150
    				PluginServices.getMainFrame().enableControls();
151
				}
149 152
			}
150 153
		});
151 154
	}
......
242 245
		        ((getTable().getRowCount())*getTable().getRowHeight())));
243 246

  
244 247
		commandSlider.addChangeListener(new javax.swing.event.ChangeListener() {
245
				public void stateChanged(javax.swing.event.ChangeEvent e) {
248
				public synchronized void stateChanged(javax.swing.event.ChangeEvent e) {
246 249
				    if (!refreshing){
247
				        int value = getTablePosFromSlider();                    
248
				        if (currentValue != value){
249
				            refreshing = true;
250
				        int value = getTablePosFromSlider();  
251
				        //currentSliderValue controls the same event thrown by the
252
				        //slider. currentValue controls the event thrown by the table
253
				        if (currentSliderValue != value){
254
				            refreshing = true;	
255
				            currentSliderValue = value;
250 256
				            commandTableModel.setPos(value);
251 257
				            refreshing = false;    
252 258
				        }
......
267 273
	    //The bottom part of the slider starts in 100: take the reverse value
268 274
	    value = (commandTableModel.getRowCount() - 1) - value;
269 275
	    
276
	    if (value == -1){
277
	        return 0;
278
	    }
270 279
	    return value;
271 280
	}
272 281
	
......
355 364
			if (FeatureStoreNotification.AFTER_INSERT.equals(type) ||
356 365
                FeatureStoreNotification.AFTER_DELETE.equals(type) ||
357 366
                FeatureStoreNotification.AFTER_UPDATE.equals(type) ||
358
                FeatureStoreNotification.SELECTION_CHANGE.equals(type)) {                   
367
                FeatureStoreNotification.SELECTION_CHANGE.equals(type) ||
368
                FeatureStoreNotification.AFTER_REDO.equals(type) ||
369
                FeatureStoreNotification.AFTER_UNDO.equals(type)) {                   
359 370
			    commandRepaint();
360 371
			}			
361 372
		}
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/gui/command/CommandTableModel.java
15 15
public class CommandTableModel extends AbstractTableModel{
16 16
    private static final Logger LOG = 
17 17
        LoggerFactory.getLogger(CommandTableModel.class);
18
    private UndoRedoStack cr;
19 18
    
20
    public CommandTableModel(UndoRedoStack cr) {
21
        this.cr = cr;
19
    private UndoRedoStack undoRedoStack;
20
        
21
    public CommandTableModel(UndoRedoStack undoRedoStack) {
22
        this.undoRedoStack = undoRedoStack;
22 23
	}
23 24

  
24 25
	public int getPos() {
25
		if ((cr == null) || cr.getUndoInfos() == null){
26
		if ((undoRedoStack == null) || undoRedoStack.getUndoInfos() == null){
26 27
		    return 0;
27 28
		}
28
	    return cr.getUndoInfos().size() - 1;
29
	    return undoRedoStack.getUndoInfos().size() - 1;
29 30
	}
30 31
	
31 32
	public int getColumnCount() {
......
33 34
	}
34 35
	
35 36
	public int getRowCount() {
36
		if ((cr == null) || cr.getUndoInfos() == null || cr.getRedoInfos() == null){
37
		if ((undoRedoStack == null) || undoRedoStack.getUndoInfos() == null || undoRedoStack.getRedoInfos() == null){
37 38
		    return 0;
38 39
		}
39
		return cr.getRedoInfos().size() + cr.getUndoInfos().size();
40
		return undoRedoStack.getRedoInfos().size() + undoRedoStack.getUndoInfos().size();
40 41
	}
41 42
	
42 43
	@SuppressWarnings("unchecked")
43 44
    public Object getValueAt(int i, int j) {
44
		Command[] undos=(Command[])cr.getUndoInfos().toArray(new Command[0]);
45
		Command[] redos=(Command[])cr.getRedoInfos().toArray(new Command[0]);
45
		Command[] undos=(Command[])undoRedoStack.getUndoInfos().toArray(new Command[0]);
46
		Command[] redos=(Command[])undoRedoStack.getRedoInfos().toArray(new Command[0]);
46 47
		if (i<undos.length){
47 48
			//System.out.println("undo i=" + i + " index=" + (undos.length-1-i));
48 49
			return undos[undos.length-1-i];
......
54 55
	
55 56
	public void setPos(int newpos) {
56 57
		try {
58
		    int currentPos = getPos();
57 59
			if (newpos > getPos()) {
58
				cr.redo(newpos - getPos());
60
				undoRedoStack.redo(newpos - getPos());
59 61
			}else if (newpos < getPos()) {
60
				cr.undo(getPos() - newpos);
62
				undoRedoStack.undo(getPos() - newpos);
61 63
			}
62 64
		} catch (RedoException e) {
63 65
			LOG.error("Error executing the command", e);

Also available in: Unified diff