Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.temp.common.shared.utils;

/**
 * A Class to replace two booleans: Saved (unchanged) and Update (New vs Updating).
 * <p/>
 * This class carries two states about some other object:
 * <OL>
 * <LI> which CRUD operation is currently active</LI>
 * <LI> is the other object in a "changed" state</LI>
 * </OL>
 *
 * @author georgs
 */
public class DataState {
    /**
     * CRUD w/ supporting change management support flags
     */
    public enum Operation {
        Create( false, true ), //
        Read( false, false ), //
        Update( false, true ), //
        Delete( true, false );

        private boolean initialChangedState;
        private boolean allowsOtherChanges;

        Operation( boolean initialChangedState, boolean allowsOtherChanges ) {
            this.initialChangedState = initialChangedState;
            this.allowsOtherChanges = allowsOtherChanges;
        }

        public boolean getInitialChangedState() {
            return initialChangedState;
        }

        public boolean allowsOtherChanges() {
            return allowsOtherChanges;
        }
    }

    private Operation operation;
    private boolean changed;

    public DataState() {
        resetToRead();
    }

    public Operation getOperation() {
        return operation;
    }

    private void setOperation( Operation operation ) {
        this.operation = operation;
        resetChanges();
    }

    public void resetToCreate() {
        setOperation( Operation.Create );
    }

    public void resetToRead() {
        setOperation( Operation.Read );
    }

    public void resetToUpdate() {
        setOperation( Operation.Update );
    }

    public void resetToDelete() {
        setOperation( Operation.Delete );
    }

    public boolean isCreate() {
        return operation.equals( Operation.Create );
    }

    public boolean isRead() {
        return operation.equals( Operation.Read );
    }

    public boolean isUpdate() {
        return operation.equals( Operation.Update );
    }

    public boolean isDelete() {
        return operation.equals( Operation.Delete );
    }

    public void resetChanges() {
        changed = operation.getInitialChangedState();
    }

    public boolean isChanged() {
        return changed;
    }

    public void changed() {
        if ( !operation.allowsOtherChanges ) {
            throw new IllegalStateException( "The " + operation + " does NOT allow the data to be changed!" );
        }
        changed = true;
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/common/shared/utils/DataState.java

Diff revisions: vs.
Revision Author Commited Message
964 GeorgeS picture GeorgeS Fri 01 Aug, 2014 03:18:23 +0000

!