Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1e9ef702e0c274d15ce95648400b15f15c90a73c (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*****************************************************************************
 * Copyright (c) 2009 CEA LIST & LIFL 
 *
 *    
 * 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:
 *  Cedric Dumoulin  Cedric.dumoulin@lifl.fr - Initial API and implementation
 *
 *****************************************************************************/

package org.eclipse.papyrus.infra.core.sasheditor.internal;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.internal.dnd.IDropTarget;

/**
 * Common ancestor of Panel Parts. Panels are sashes and folders.
 * 
 * @author cedric dumoulin
 */
public abstract class AbstractPanelPart extends AbstractPart {

	/**
	 * Parent of this part.
	 */
	protected IPanelParent parent;

	/**
	 * Constructor.
	 * 
	 * @param parent
	 *        Parent of the Pane.
	 */
	public AbstractPanelPart(IPanelParent parent) {
		super(parent.getSashWindowContainer());
	}

	/**
	 * Create the SWT controls. This method is called by the SWT parent.
	 * 
	 * @param container
	 */
	abstract public void createPartControl(Composite container);

	/**
	 * Dispose all nested SWT controls.
	 */
	abstract public void dispose();

	/**
	 * Visit the part.
	 * 
	 * @param visitor
	 */
	abstract public boolean visit(IPartVisitor visitor);

	/**
	 * Synchronize the part and its children with the models in contentProvider.
	 * 
	 * @param existingParts
	 *        List of already existing part before the synchronization.
	 */
	abstract public void synchronize2(PartLists existingParts);

	/**
	 * Return true is the part is for the specified raw model. Return false
	 * otherwise.
	 * 
	 * @param rawModel
	 * @return
	 */
	abstract public boolean isPartFor(Object rawModel);

	/**
	 * Orphan this node. The parent is set to null, but control is left
	 * unchanged. The node can be reattached with reparent(). Change garbage
	 * state to {@link GarbageState.ORPHANED}. This method as no effect if the
	 * Tile has already been reparented.
	 */
	public void orphan() {
		// orphan only if we are in UNCHANGED state
		if(garbageState == GarbageState.UNVISITED) {
			garbageState = GarbageState.ORPHANED;
			parent = null;
		}
	}

	/**
	 * Mark this Page as UNCHANGED. The PAge should be in the COLLECTED state.
	 * 
	 * @see
	 * @return the parent
	 */
	public void unchanged() {
		// orphan only if we are in COLLECTED state
		if(garbageState == GarbageState.UNVISITED || garbageState == GarbageState.ORPHANED) {
			garbageState = GarbageState.UNCHANGED;
		} else {
			// Bad state, this is an internal error
			// TODO : log a warning ?
			throw new IllegalStateException("Try to change state from " + garbageState.toString() + " to UNCHANGED. This is forbidden.");
		}
	}

	/**
	 * Change the parent of the Part. The parent is changed, and the control is
	 * attached to the parent control. Change garbage state to {@link GarbageState.REPARENTED}.
	 * 
	 * @param newParent
	 *        The new parent to which the part should be attached.
	 */
	abstract public void reparent(IPanelParent newParent, Composite swtParent);

	/**
	 * Collect all the parts. The method is called recursively in the tree of
	 * parts.
	 * 
	 * @param parts
	 *        The list into which parts are added.
	 */
	abstract public void fillPartMap(PartLists parts);

	/**
	 * Traverses the tree to find the part that intersects the given point
	 * 
	 * @param toFind
	 *        Point in display coordinate
	 * @return the part that intersects the given point
	 * @throws NotFoundException
	 */
	abstract public AbstractPart findPart(Point toFind) throws NotFoundException;

	/**
	 * Find the part associated to the provided control.
	 * 
	 * @param control
	 * @return
	 */
	abstract public AbstractPart findPart(Object control);

	/**
	 * Locates the part that intersects the given point and that have the
	 * expected type
	 * 
	 * @param toFind
	 *        Position in Display coordinate.
	 * @return
	 */
	abstract public AbstractPart findPartAt(Point toFind, Class<?> expectedTileType);

	/* ***************************************************** */
	/* Drag and Drop methods */
	/* ***************************************************** */

	/**
	 * Return the swt Control associated to this part.
	 */
	abstract public Composite getControl();

	/**
	 * Get the drop target. Used by the drag tab mechanism.
	 */
	abstract public IDropTarget getDropTarget(Object draggedObject, TabFolderPart sourcePart, Point position);

}

Back to the top