Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 68daef73e8a9c9574c175357f78867ea77a9a474 (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
/*
 * Copyright (c) 2007 Borland Software Corporation
 * 
 * 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:
 *    Dmitry Stadnik (Borland) - initial API and implementation
 */

«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»

«DEFINE EditPartProvider FOR gmfgen::GenDiagram-»
«EXPAND xpt::Common::copyright FOR editorGen-»
package «providersPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «editPartProviderClassName»
		extends org.eclipse.gmf.runtime.diagram.ui.services.editpart.AbstractEditPartProvider {

	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.gef.EditPartFactory factory;

	«EXPAND xpt::Common::generatedMemberComment»
	private boolean allowCaching;

	«EXPAND xpt::Common::generatedMemberComment»
	private java.lang.ref.WeakReference cachedPart;

	«EXPAND xpt::Common::generatedMemberComment»
	private java.lang.ref.WeakReference cachedView;

	«EXPAND xpt::Common::generatedMemberComment»
	public «editPartProviderClassName»() {
		setFactory(new «getEditPartFactoryQualifiedClassName()»());
		setAllowCaching(true);
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public final org.eclipse.gef.EditPartFactory getFactory() {
		return factory;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected void setFactory(org.eclipse.gef.EditPartFactory factory) {
		this.factory = factory;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public final boolean isAllowCaching() {
		return allowCaching;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected synchronized void setAllowCaching(boolean allowCaching) {
		this.allowCaching = allowCaching;
		if (!allowCaching) {
			cachedPart = null;
			cachedView = null;
		}
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart createEditPart(
			org.eclipse.gmf.runtime.notation.View view) {
		org.eclipse.gef.EditPart part = factory.createEditPart(null, view);
		if (part instanceof org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) {
			return (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) part;
		}
		return null;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart getCachedPart(
			org.eclipse.gmf.runtime.notation.View view) {
		if (cachedView != null && cachedView.get() == view) {
			return (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) cachedPart.get();
		}
		return null;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public synchronized org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart createGraphicEditPart(
			org.eclipse.gmf.runtime.notation.View view) {
		if (isAllowCaching()) {
			org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart part = getCachedPart(view);
			cachedPart = null;
			cachedView = null;
			if (part != null) {
				return part;
			}
		}
		return createEditPart(view);
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public synchronized boolean provides(org.eclipse.gmf.runtime.common.core.service.IOperation operation) {
		if (operation instanceof org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateGraphicEditPartOperation) {
			org.eclipse.gmf.runtime.notation.View view =
					((org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation) operation).getView();
			if (!«getEditPartQualifiedClassName()».MODEL_ID.equals(
					«getVisualIDRegistryQualifiedClassName()».getModelID(view))) {
				return false;
			}
			if (isAllowCaching() && getCachedPart(view) != null) {
				return true;
			}
			org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart part = createEditPart(view);
			if (part != null) {
				if (isAllowCaching()) {
					cachedPart = new java.lang.ref.WeakReference(part);
					cachedView = new java.lang.ref.WeakReference(view);
				}
				return true;
			}
		}
		return false;
	}
	«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»

Back to the top