Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 29c0729dd817d06f51d62f9012b9082290d5f8a0 (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
/*
 * 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:
 *    Artem Tikhomirov (Borland) - initial API and implementation
 */
«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»

«DEFINE Class FOR gmfgen::GenCustomPropertyTab»
	«EXPAND xpt::Common::copyright FOR sheet.editorGen-»
package «sheet.packageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «className» extends «EXPAND extendsList» «EXPAND implementsClause»{

«EXPAND getPropertySourceMethod»
«IF sheet.readOnly»
«EXPAND createReadonlyControlsMethod»
«ENDIF»
«EXPAND getPropertySourceProviderMethod»
«EXPAND transfromSelectionMethod»
«EXPAND setInputMethod»
«EXPAND getAdapterFactoryMethod»

«EXPAND additions»
}
«ENDDEFINE»

«DEFINE extendsList FOR gmfgen::GenCustomPropertyTab»org.eclipse.gmf.runtime.diagram.ui.properties.sections.AdvancedPropertySection«ENDDEFINE»
«DEFINE implementsClause FOR gmfgen::GenCustomPropertyTab»implements org.eclipse.ui.views.properties.IPropertySourceProvider«ENDDEFINE»

«DEFINE getPropertySourceMethod FOR gmfgen::GenCustomPropertyTab-»
	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.ui.views.properties.IPropertySource getPropertySource(Object object) {
		if (object instanceof org.eclipse.ui.views.properties.IPropertySource) {
			return (org.eclipse.ui.views.properties.IPropertySource) object;
		}
		org.eclipse.emf.common.notify.AdapterFactory af = getAdapterFactory(object);
		if (af != null) {
			org.eclipse.emf.edit.provider.IItemPropertySource ips = (org.eclipse.emf.edit.provider.IItemPropertySource) af.adapt(object, org.eclipse.emf.edit.provider.IItemPropertySource.class);
			if (ips != null) {
				return new org.eclipse.emf.edit.ui.provider.PropertySource(object, ips);
			}
		}
		if (object instanceof org.eclipse.core.runtime.IAdaptable) {
			return (org.eclipse.ui.views.properties.IPropertySource) ((org.eclipse.core.runtime.IAdaptable) object).getAdapter(org.eclipse.ui.views.properties.IPropertySource.class);
		}
		return null;
	}
«ENDDEFINE»

«DEFINE createReadonlyControlsMethod FOR gmfgen::GenCustomPropertyTab»
	«EXPAND xpt::Common::generatedMemberComment»
	public void createControls(org.eclipse.swt.widgets.Composite parent, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage aTabbedPropertySheetPage) {
		super.createControls(parent, aTabbedPropertySheetPage);
		class ROEntry extends org.eclipse.gmf.runtime.emf.ui.properties.sections.UndoableModelPropertySheetEntry {
			ROEntry(org.eclipse.core.commands.operations.IOperationHistory operationHistory) {
				super(operationHistory);
			}
			public org.eclipse.jface.viewers.CellEditor getEditor(org.eclipse.swt.widgets.Composite parentComposite) {
				return null; // do not allow editing
			}
			protected org.eclipse.gmf.runtime.emf.ui.properties.sections.PropertySheetEntry createChildEntry() {
				return new ROEntry(getOperationHistory());
			}
		};
		ROEntry root = new ROEntry(org.eclipse.core.commands.operations.OperationHistoryFactory.getOperationHistory()); 
		root.setPropertySourceProvider(getPropertySourceProvider());
		page.setRootEntry(root);
	}
«ENDDEFINE»

«DEFINE getPropertySourceProviderMethod FOR gmfgen::GenCustomPropertyTab»
	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.ui.views.properties.IPropertySourceProvider getPropertySourceProvider() {
		return this; 
	}
«ENDDEFINE»

«DEFINE transfromSelectionMethod FOR gmfgen::GenCustomPropertyTab»
	«EXPAND xpt::Common::generatedMemberComment('Modify/unwrap selection.')»
	protected Object transformSelection(Object selected) {
«IF 'domain' = iD /*perhaps, override setInput should obey same condition?*/-»
		«EXPAND transfromSelectionMethodBodyDefault-»
«ENDIF-»
		return selected;
	}
«ENDDEFINE»

«DEFINE transfromSelectionMethodBodyDefault FOR gmfgen::GenCustomPropertyTab»
		if (selected instanceof org.eclipse.gef.EditPart) {
			Object model = ((org.eclipse.gef.EditPart) selected).getModel();
			return model instanceof org.eclipse.gmf.runtime.notation.View ? ((org.eclipse.gmf.runtime.notation.View) model).getElement() : null;
		}
		if (selected instanceof org.eclipse.gmf.runtime.notation.View) {
			return ((org.eclipse.gmf.runtime.notation.View) selected).getElement();
		}
		if (selected instanceof org.eclipse.core.runtime.IAdaptable) {
			org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) ((org.eclipse.core.runtime.IAdaptable) selected).getAdapter(org.eclipse.gmf.runtime.notation.View.class);
			if (view != null) {
				return view.getElement();
			}
		}
«ENDDEFINE»

«DEFINE setInputMethod FOR gmfgen::GenCustomPropertyTab»
	«EXPAND xpt::Common::generatedMemberComment»
	public void setInput(org.eclipse.ui.IWorkbenchPart part, org.eclipse.jface.viewers.ISelection selection) {
		if (selection.isEmpty() || false == selection instanceof org.eclipse.jface.viewers.StructuredSelection) {
			super.setInput(part, selection);
			return;
		}
		final org.eclipse.jface.viewers.StructuredSelection structuredSelection = ((org.eclipse.jface.viewers.StructuredSelection) selection);
		java.util.ArrayList transformedSelection = new java.util.ArrayList(structuredSelection.size());
		for (java.util.Iterator it = structuredSelection.iterator();  it.hasNext();) {
			Object r = transformSelection(it.next());
			if (r != null) {
				transformedSelection.add(r);
			}
		}
		super.setInput(part, new org.eclipse.jface.viewers.StructuredSelection(transformedSelection));
	}
«ENDDEFINE»

«DEFINE getAdapterFactoryMethod FOR gmfgen::GenCustomPropertyTab»
	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.emf.common.notify.AdapterFactory getAdapterFactory(Object object) {
		if (getEditingDomain() instanceof org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) {
			return ((org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) getEditingDomain()).getAdapterFactory();
		}
		org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain = org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(object);
		if (editingDomain != null) {
			return ((org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) editingDomain).getAdapterFactory();
		}
		return null;
	}
«ENDDEFINE»

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

Back to the top