Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 68c08dad5d1f23452349bcb2a8c52ae8975de85e (plain) (blame)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Copyright (c) 2002 IBM Corporation and others.
* All rights reserved.   This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
* 
* Contributors:
*   IBM - Initial API and implementation
*   Jens Lukowski/Innoopract - initial renaming/restructuring
* 
*/
package org.eclipse.wst.sse.core;

/**
 * This is an early version of a class that may change over the 
 * next few milestones.
 */


public class ModelLifecycleEvent {
	// this list is for "public" consumption
	public static final int MODEL_SAVED = 0x0001;
	public static final int MODEL_RELEASED = 0x00002;
	public static final int MODEL_DOCUMENT_CHANGED = 0x0003;
	public static final int MODEL_DIRTY_STATE = 0x0004;

	// TODO: finish support for these
	// following not implemented yet
	//public static final int MODEL_REINITIALIZED = 0x0005;
	//public static final int MODEL_RELOADED = 0x0006;
	//public static final int ADAPTERS_NOTIFIED = 0x0007;
	//public static final int MODEL_RESOURCE_MOVED = 0x0008;
	//public static final int MODEL_RESOURCE_DELETED = 0x0009;

	// This list (upper two bytes) is for only internal mechanisms and subclasses
	// For simplicity they are "masked out" when client calls getType()
	protected static final int PRE_EVENT = 0x0100;
	protected static final int POST_EVENT = 0x0200;


	private IStructuredModel fModel;
	private int fType;


	private final static int MASK = 0x00FF;

	public ModelLifecycleEvent() {
		super();
	}

	public ModelLifecycleEvent(int type) {
		this();
		fType = type;
	}

	public ModelLifecycleEvent(IStructuredModel structuredModel, int type) {
		this(type);
		fModel = structuredModel;
	}

	public IStructuredModel getModel() {

		return fModel;
	}

	public int getType() {

		// for now, we'll mask type to "public" ones this easy 
		// way ... but I know there must be a better way
		return fType & MASK;
	}

	public String toString() {
		String result = null;
		result = "ModelLifecycleEvent: " + debugString(fType); //$NON-NLS-1$
		return result;
	}

	private String debugString(int type) {
		String result = null;
		switch (type & MASK) {
			case MODEL_SAVED :
				result = "MODEL_SAVED"; //$NON-NLS-1$
				break;
			case MODEL_RELEASED :
				result = "MODEL_RELEASED"; //$NON-NLS-1$
				break;
			case MODEL_DOCUMENT_CHANGED :
				result = "MODEL_DOCUMENT_CHANGED"; //$NON-NLS-1$
				break;
			case MODEL_DIRTY_STATE :
				result = "MODEL_DIRTY_STATE"; //$NON-NLS-1$
				break;
			/*        case MODEL_REINITIALIZED :
			 result = "MODEL_REINITIALIZED";
			 break;
			 case MODEL_RELOADED :
			 result = "MODEL_RELOADED";
			 break;
			 case ADAPTERS_NOTIFIED :
			 result = "ADAPTERS_NOTIFIED";
			 break;
			 case MODEL_RESOURCE_MOVED :
			 result = "MODEL_RESOURCE_MOVED";
			 break;
			 case MODEL_RESOURCE_DELETED :
			 result = "MODEL_RESOURCE_DELETED";
			 break;
			 */
			default :
				throw new IllegalStateException("ModelLifecycleEvent did not have valid type"); //$NON-NLS-1$
		}
		return result;
	}

	protected int getInternalType() {

		return fType;
	}

}

Back to the top