View Javadoc
1   /*
2    * Metis: Java Data Framework
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.metis.data;
18  
19  /**
20   * Enumeration of edit states of DataItem and DataList objects in a view.
21   */
22  public enum MetisDataEditState {
23      /**
24       * No changes made.
25       */
26      CLEAN,
27  
28      /**
29       * Non-validated changes made.
30       */
31      DIRTY,
32  
33      /**
34       * Only valid changes made.
35       */
36      VALID,
37  
38      /**
39       * Object is in error.
40       */
41      ERROR;
42  
43      /**
44       * Combine With another edit state.
45       *
46       * @param pState edit state to combine with
47       * @return the combined state
48       */
49      public MetisDataEditState combineState(final MetisDataEditState pState) {
50          switch (this) {
51              case ERROR:
52                  return this;
53              case DIRTY:
54                  return pState == ERROR
55                          ? pState
56                          : this;
57              case VALID:
58                  return pState != CLEAN
59                          ? pState
60                          : this;
61              case CLEAN:
62              default:
63                  return pState;
64          }
65      }
66  }