View Javadoc

1   /*
2      Copyright 2008 Ramon Servadei
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15   */
16  package fulmine.model.container.events;
17  
18  import fulmine.event.AbstractEvent;
19  import fulmine.event.IEventManager;
20  import fulmine.model.container.IContainer;
21  import fulmine.model.container.IContainer.DataState;
22  
23  /**
24   * Raised when an {@link IContainer} has a change in its state.
25   * 
26   * @see IContainer#getDataState()
27   * @author Ramon Servadei
28   */
29  public final class ContainerStateChangeEvent extends AbstractEvent
30  {
31      /** The container that has been created */
32      private final IContainer container;
33  
34      /** The new state for the container */
35      private final DataState newState;
36  
37      /** The old state for the container */
38      private final DataState oldState;
39  
40      /**
41       * Standard constructor
42       * 
43       * @param context
44       *            the context for event operations
45       * @param container
46       *            the container
47       * @param newState
48       *            the new state
49       * @param oldState
50       *            the old state
51       */
52      public ContainerStateChangeEvent(IEventManager context,
53          IContainer container, DataState newState, DataState oldState)
54      {
55          super();
56          setSource(container);
57          this.container = container;
58          this.newState = newState;
59          this.oldState = oldState;
60      }
61  
62      /**
63       * Get the container for the state change event
64       * 
65       * @return the {@link IContainer} for the state change event
66       */
67      public IContainer getContainer()
68      {
69          return this.container;
70      }
71  
72      public String toIdentityString()
73      {
74          return toString();
75      }
76  
77      /**
78       * Get the new state of the container
79       * 
80       * @return the new state of the container
81       */
82      public DataState getNewState()
83      {
84          return this.newState;
85      }
86  
87      /**
88       * Get the previous state of the container
89       * 
90       * @return the previous state of the container
91       */
92      public DataState getOldState()
93      {
94          return this.oldState;
95      }
96  
97      @Override
98      protected String getAdditionalToString()
99      {
100         return "new state=" + this.newState + ", old state=" + this.oldState;
101     }
102 }