Skip to main content
summaryrefslogtreecommitdiffstats
blob: b1228331051e5b3db70efdfde07c2f20312cacd8 (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
/*****************************************************************************
 * Copyright (c) 2011 CEA LIST.
 *
 *    
 * 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:
 *  Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.properties.table.modelelement;


import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.databinding.FeaturePath;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.TableInstance;
import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance2.TableInstance2;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.papyrus.properties.modelelement.EMFModelElement;
import org.eclipse.papyrus.properties.table.provider.CustomizationContentProvider;
import org.eclipse.papyrus.properties.table.provider.CustomizationLabelProvider;
import org.eclipse.papyrus.properties.table.provider.FacetLabelProvider;
import org.eclipse.papyrus.properties.table.provider.FillingQueriesContentProvider;
import org.eclipse.papyrus.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.widgets.providers.IStaticContentProvider;




public class PapyrusTableModelElement extends EMFModelElement {

	/** these 3 value are used for the preference of the display of the localCustom in the property view */
	/** any local customization is displayed */
	public static final int NO_LOCALS = 0;

	/** only one of the local customization is displayed */
	public static final int ONLY_ONE_LOCALS = NO_LOCALS + 1;

	/** all local customizations are displayed */
	public static final int ALL_LOCALS = ONLY_ONE_LOCALS + 1;

	/** the property path for the customization */
	public static final String TABLE_CUSTOMIZATIONS = "table.customizations"; //$NON-NLS-1$

	/** the property path for the customization */
	public static final String TABLE_FACETS2 = "table.facets2"; //$NON-NLS-1$

	/** the property path for the customization */
	public static final String TABLE_FILLING_QUERIES = "fillingQueries"; //$NON-NLS-1$

	public static final String TABLE_CONTEXT = "table.context"; //$NON-NLS-1$

	/** the current value of the preference for the display of the local customization */
	private static int local_preference = ALL_LOCALS;

	/**
	 * 
	 * Constructor.
	 * 
	 * @param source
	 */
	public PapyrusTableModelElement(final EObject source) {
		super(source);
	}

	/**
	 * 
	 * Constructor.
	 * 
	 * @param source
	 * @param domain
	 */
	public PapyrusTableModelElement(final EObject source, final EditingDomain domain) {
		super(source, domain);
	}

	/**
	 * 
	 * @see org.eclipse.papyrus.properties.modelelement.EMFModelElement#getContentProvider(java.lang.String)
	 * 
	 * @param propertyPath
	 * @return
	 */
	@Override
	public IStaticContentProvider getContentProvider(final String propertyPath) {
		if(TABLE_FILLING_QUERIES.equals(propertyPath)) {
			FeaturePath featurePath = getFeaturePath(TABLE_CONTEXT);
			EObject table = getSource(featurePath);
			Assert.isTrue(table instanceof TableInstance);
			return new FillingQueriesContentProvider((TableInstance)table);
		}
		if(TABLE_CUSTOMIZATIONS.equals(propertyPath)) {
			FeaturePath featurePath = getFeaturePath(TABLE_CUSTOMIZATIONS);
			EStructuralFeature feature = getFeature(featurePath);
			return new CustomizationContentProvider(feature, getSource(featurePath), local_preference);
		}
		return super.getContentProvider(propertyPath);
	}

	/**
	 * 
	 * @see org.eclipse.papyrus.properties.modelelement.EMFModelElement#getLabelProvider(java.lang.String)
	 * 
	 * @param propertyPath
	 * @return
	 */
	@Override
	public ILabelProvider getLabelProvider(final String propertyPath) {
		if(TABLE_CUSTOMIZATIONS.equals(propertyPath)) {
			FeaturePath featurePath = getFeaturePath(TABLE_CUSTOMIZATIONS);
			EObject table = getSource(featurePath);
			Assert.isTrue(table instanceof TableInstance2);
			return new CustomizationLabelProvider((TableInstance2)table, local_preference);
		}
		if(TABLE_FACETS2.equals(propertyPath)) {
			return new FacetLabelProvider();
		}
		return super.getLabelProvider(propertyPath);
	}

	/**
	 * 
	 * @see org.eclipse.papyrus.properties.modelelement.EMFModelElement#getValueFactory(java.lang.String)
	 * 
	 * @param propertyPath
	 * @return
	 */
	@Override
	public ReferenceValueFactory getValueFactory(final String propertyPath) {
		//allow to disabled the edition of the filling queries
		if(TABLE_FILLING_QUERIES.equals(propertyPath)) {
			return null;
		}
		return super.getValueFactory(propertyPath);
	}
}

Back to the top