Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 2272020490ab0ca9674c83258c2a8a0afdf89bee (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
/*******************************************************************************
 * Copyright (c) 2007, 2008 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
 * 
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.utility.model.event;

import org.eclipse.jpt.utility.model.Model;

/**
 * A "tree change" event gets delivered whenever a model changes a "bound"
 * or "constrained" tree. A TreeChangeEvent is sent as an
 * argument to the TreeChangeListener.
 * 
 * Normally a TreeChangeEvent is accompanied by the tree name and a path
 * to the part of the tree that was changed.
 * 
 * Provisional API: This class is part of an interim API that is still
 * under development and expected to change significantly before reaching
 * stability. It is available at this early stage to solicit feedback from
 * pioneering adopters on the understanding that any code that uses this API
 * will almost certainly be broken (repeatedly) as the API evolves.
 */
public class TreeChangeEvent extends ChangeEvent {

	/** Name of the tree that changed. */
	private final String treeName;

    /**
     * Path to the parent of the part of the tree that was changed.
     * May be empty, if not known or if the entire tree changed.
     */
	protected final Object[] path;

	private static final Object[] EMPTY_PATH = new Object[0];

	private static final long serialVersionUID = 1L;


	// ********** constructors **********

	/**
	 * Construct a new tree change event.
	 *
	 * @param source The object on which the event initially occurred.
	 * @param treeName The programmatic name of the tree that was changed.
	 * @param path The path to the part of the tree that was changed.
	 */
	public TreeChangeEvent(Model source, String treeName, Object[] path) {
		super(source);
		if ((treeName == null) || (path == null)) {
			throw new NullPointerException();
		}
		this.treeName = treeName;
		this.path = path;
	}
	
	/**
	 * Construct a new tree change event.
	 *
	 * @param source The object on which the event initially occurred.
	 * @param treeName The programmatic name of the tree that was changed.
	 */
	public TreeChangeEvent(Model source, String treeName) {
		this(source, treeName, EMPTY_PATH);
	}
	

	// ********** standard state **********

	/**
	 * Return the programmatic name of the tree that was changed.
	 */
	public String getTreeName() {
		return this.treeName;
	}

	@Override
	public String getAspectName() {
		return this.treeName;
	}

	/**
	 * Return the path to the part of the tree that was changed.
	 * May be empty, if not known.
	 */
	public Object[] getPath() {
		return this.path;
	}


	// ********** cloning **********

	@Override
	public TreeChangeEvent cloneWithSource(Model newSource) {
		return new TreeChangeEvent(newSource, this.treeName, this.path);
	}

	/**
	 * Return a copy of the event with the specified source
	 * replacing the current source and the tree name.
	 */
	public TreeChangeEvent cloneWithSource(Model newSource, String newTreeName) {
		return new TreeChangeEvent(newSource, newTreeName, this.path);
	}

}

Back to the top