Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 31f337c7fc2f262e65fddba07e7d7dd4b8863e59 (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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*****************************************************************************
 * Copyright (c) 2013 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.uml.nattable.config;

import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter;
import org.eclipse.nebula.widgets.nattable.data.validate.IDataValidator;
import org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor;
import org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor;
import org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter;
import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.papyrus.infra.nattable.celleditor.AbstractOpenDialogCellEditorButtonAction;
import org.eclipse.papyrus.infra.nattable.celleditor.config.IAxisCellEditorConfiguration;
import org.eclipse.papyrus.infra.nattable.manager.table.ITableAxisElementProvider;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
import org.eclipse.papyrus.uml.nattable.converter.UMLMultiReferenceDisplayConverter;
import org.eclipse.papyrus.uml.nattable.editor.MultiReferenceCellEditor;
import org.eclipse.papyrus.uml.nattable.manager.cell.editor.UMLReferenceTextWithCompletionCellEditor;
import org.eclipse.papyrus.uml.nattable.messages.Messages;
import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils;
import org.eclipse.uml2.uml.DataType;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Type;

/**
 * 
 * This class provides the configuration to edit UML References single and multi-valued with a text editor
 *
 */
public class UMLMultiReferenceTextualCellEditorWithButtonConfiguration implements IAxisCellEditorConfiguration {

	/**
	 * The id of this editor.
	 */
	public static final String ID = "org.eclipse.papyrus.uml.reference.text.with.completion.editor.and.dialog"; //$NON-NLS-1$
	
	/**
	 * 
	 * @see org.eclipse.papyrus.infra.nattable.celleditor.config.IAxisCellEditorConfiguration#handles(org.eclipse.papyrus.infra.nattable.model.nattable.Table, java.lang.Object)
	 *
	 * @param table
	 * @param object
	 * @return
	 */
	@Override
	public boolean handles(Table table, Object object) {
		Object tmp = AxisUtils.getRepresentedElement(object);
		if (tmp instanceof EReference) {
			EReference ref = (EReference) tmp;
			if (ref.isContainment() || !ref.isChangeable() || ref.isDerived()) {
				return false;
			}
			if (!ref.isMany()) {
				return false;
			}
			EClassifier type = ref.getEType();

			// TODO : to test on constraint
			// return type instanceof EClass && UMLPackage.eINSTANCE.getNamedElement().isSuperTypeOf((EClass) type);
			return true;

		} else if (object instanceof String && ((String) object).startsWith(UMLTableUtils.PROPERTY_OF_STEREOTYPE_PREFIX)) {
			String str = (String) tmp;
			Property prop = UMLTableUtils.getRealStereotypeProperty(table.getContext(), str);
			if (prop != null) {
				if (prop.isDerived()) {
					return false;
				}
				Type type = prop.getType();
				if (type instanceof DataType) {
					return false;
				}
				if (!(type instanceof NamedElement)) {
					return false;
				}
				if (!prop.isMultivalued()) {
					return false;
				}
				switch (prop.getAggregation()) {
				case NONE_LITERAL:
				case SHARED_LITERAL:
					return true;
				case COMPOSITE_LITERAL:
				default:
					return false;
				}
			}
		}

		return false;
	}

	/**
	 * 
	 * @see org.eclipse.papyrus.infra.nattable.celleditor.config.IAxisCellEditorConfiguration#getDisplayConvert(org.eclipse.papyrus.infra.nattable.model.nattable.Table, java.lang.Object, org.eclipse.jface.viewers.ILabelProvider)
	 *
	 * @param table
	 * @param axisElement
	 * @param provider
	 * @return
	 */
	@Override
	public IDisplayConverter getDisplayConvert(Table table, Object axisElement, ILabelProvider provider) {
		return new UMLMultiReferenceDisplayConverter();
	}


	/**
	 * 
	 * @see org.eclipse.papyrus.infra.nattable.celleditor.config.IAxisCellEditorConfiguration#getCellPainter(org.eclipse.papyrus.infra.nattable.model.nattable.Table, java.lang.Object)
	 *
	 * @param table
	 * @param axisElement
	 * @return
	 */
	@Override
	public ICellPainter getCellPainter(Table table, Object axisElement) {
		return new TextPainter();
	}




	/**
	 * 
	 * @see org.eclipse.papyrus.infra.nattable.celleditor.config.IAxisCellEditorConfiguration#getICellEditor(org.eclipse.papyrus.infra.nattable.model.nattable.Table, java.lang.Object, org.eclipse.papyrus.infra.nattable.manager.table.ITableAxisElementProvider)
	 *
	 * @param table
	 * @param axisElement
	 * @param elementProvider
	 * @return
	 */
	@Override
	public ICellEditor getICellEditor(Table table, final Object axisElement, final ITableAxisElementProvider elementProvider) {
		UMLReferenceTextWithCompletionCellEditor editor = new UMLReferenceTextWithCompletionCellEditor(table, axisElement, elementProvider);
		editor.setIsMultiValued(true);
		AbstractOpenDialogCellEditorButtonAction openDialogConfiguration = new AbstractOpenDialogCellEditorButtonAction() {
			/**
			 * @see org.eclipse.papyrus.infra.nattable.celleditor.AbstractOpenDialogCellEditorButtonAction#createDialogCellEditor()
			 *
			 * @return
			 */
			@Override
			public AbstractDialogCellEditor createDialogCellEditor() {
				return new MultiReferenceCellEditor(axisElement, elementProvider);
			}

		};
		editor.setOpenDialogCellEditorButtonAction(openDialogConfiguration);
		openDialogConfiguration.setText("..."); //$NON-NLS-1$
		openDialogConfiguration.setTooltipText(Messages.UMLReferenceCellEditorConfiguration_OpenDialogToChooseTheValue);
		return editor;
	}

	/**
	 * 
	 * @see org.eclipse.papyrus.infra.nattable.celleditor.config.IAxisCellEditorConfiguration#getDisplayMode(org.eclipse.papyrus.infra.nattable.model.nattable.Table, java.lang.Object)
	 *
	 * @param table
	 * @param axisElement
	 * @return
	 */
	@Override
	public String getDisplayMode(Table table, Object axisElement) {
		return DisplayMode.EDIT;
	}

	/**
	 * 
	 * @see org.eclipse.papyrus.infra.nattable.celleditor.config.IAxisCellEditorConfiguration#getEditorConfigId()
	 *
	 * @return
	 */
	@Override
	public String getEditorConfigId() {
		return ID;
	}

	/**
	 * 
	 * @see org.eclipse.papyrus.infra.nattable.celleditor.config.IAxisCellEditorConfiguration#getDataValidator(org.eclipse.papyrus.infra.nattable.model.nattable.Table, java.lang.Object)
	 *
	 * @param table
	 * @param axisElement
	 * @return
	 */
	@Override
	public IDataValidator getDataValidator(Table table, Object axisElement) {
		return null;// By default, the system will use the DefautDataValidator//new UMLReferenceDataValidator();
	}

	/**
	 * 
	 * @see org.eclipse.papyrus.infra.nattable.celleditor.config.IAxisCellEditorConfiguration#getEditorDescription()
	 *
	 * @return
	 */
	@Override
	public String getEditorDescription() {
		return "This configuration provides a Text editor with completion for multi references"; //$NON-NLS-1$
	}


}

Back to the top