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
|
/*****************************************************************************
* Copyright (c) 2015 CEA LIST and others.
*
* 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:
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.nattable.config;
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor;
import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider;
import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.papyrus.infra.nattable.celleditor.config.ICellAxisConfiguration;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.manager.table.ITableAxisElementProvider;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IdAxis;
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
import org.eclipse.papyrus.uml.nattable.dataprovider.UMLStereotypeSingleEnumerationComboBoxDataProvider;
import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Type;
/**
* The cell editor configuration for the UML Stereotype single UML Enumeration value.
*/
public class UMLStereotypeSingleUMLEnumerationCellEditorConfiguration implements ICellAxisConfiguration {
/**
* The id of this editor.
*/
private static final String ID = "org.eclipse.papyrus.uml.nattable.celleditor.configuration.UMLStereotypeSingleUMLEnumerationCellEditorConfiguration.ComboBox";//$NON-NLS-1$
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.uml.nattable.config.MultiBooleanCellEditorConfiguration#getConfigurationId()
*/
@Override
public String getConfigurationId() {
return ID;
}
/**
* @see org.eclipse.papyrus.infra.nattable.configuration.IPapyrusNatTableConfiguration#getConfigurationDescription()
*
* @return
*/
@Override
public String getConfigurationDescription() {
return "This configuration provides a multi editor for a single UML Enumeration type"; //$NON-NLS-1$
}
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.infra.nattable.celleditor.config.ICellAxisConfiguration#handles(org.eclipse.papyrus.infra.nattable.model.nattable.Table, java.lang.Object)
*/
@Override
public boolean handles(final Table table, final Object axisElement) {
boolean result = false;
final String id = AxisUtils.getPropertyId(axisElement);
if (id != null && id.startsWith(UMLTableUtils.PROPERTY_OF_STEREOTYPE_PREFIX)) {
Property prop = UMLTableUtils.getRealStereotypeProperty(table.getContext(), id);
if (prop != null && !prop.isMultivalued()) {
Type type = prop.getType();
result = type instanceof Enumeration;
}
}
return result;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.infra.nattable.celleditor.config.ICellAxisConfiguration#configureCellEditor(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry, java.lang.Object, java.lang.String)
*/
@Override
public void configureCellEditor(final IConfigRegistry configRegistry, final Object axis, final String configLabel) {
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new TextPainter(), DisplayMode.EDIT, configLabel);
final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new ComboBoxCellEditor(getComboDataProvider(modelManager.getTable(), axis, modelManager.getTableAxisElementProvider())), DisplayMode.EDIT, configLabel);
}
/**
* Return the combo data provider. This method is not in the interface, because it can't be generalized to all editors. It is used only by
* ComboBox
*
* @param table
* the edited table
* @param axisElement
* the axis element
* @param elementProvider
* the element provider
* @return
* the combo data provider
*/
protected IComboBoxDataProvider getComboDataProvider(final Table table, final Object axisElement, final ITableAxisElementProvider elementProvider) {
IComboBoxDataProvider comboDataProvider = null;
final String id;
if (axisElement instanceof IdAxis) {
id = ((IdAxis) axisElement).getElement();
} else if (axisElement instanceof String) {
id = (String) axisElement;
} else {
id = null;
}
if (null != id) {// it is a stereotype property
comboDataProvider = new UMLStereotypeSingleEnumerationComboBoxDataProvider(axisElement, elementProvider);
}
return comboDataProvider;
}
}
|