blob: 42477b8344a26e699aeb97bed6feefd6cc741122 (
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
|
/*****************************************************************************
* Copyright (c) 2015 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.nattable.xtext.integration.celleditor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.papyrus.infra.gmfdiag.extensionpoints.editors.Activator;
import org.eclipse.papyrus.infra.gmfdiag.extensionpoints.editors.configuration.IDirectEditorConfiguration;
import org.eclipse.papyrus.infra.gmfdiag.extensionpoints.editors.utils.DirectEditorsUtil;
import org.eclipse.papyrus.infra.gmfdiag.extensionpoints.editors.utils.IDirectEditorsIds;
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.xtext.integration.DefaultXtextDirectEditorConfiguration;
/**
* ICellEditor implementation that wraps a SWT Text control to
* support text editing. This is also the default editor in NatTable if you
* didn't configure something else.
*/
public abstract class AbstractXtextCellEditor extends
AbstractNatTableXTextCellEditor {
/**
* Creates the default TextCellEditor that does not commit on pressing the
* up/down arrow keys and will not move the selection on committing a value
* by pressing enter.
*/
public AbstractXtextCellEditor(final Table table,
final Object axisElement,
final ITableAxisElementProvider elementProvider) {
super(table, axisElement, elementProvider);
}
/**
*
* @see org.eclipse.papyrus.infra.nattable.xtext.integration.celleditor.AbstractNatTableXTextCellEditor#createXTextEditorConfiguration()
*
* @return
*/
protected DefaultXtextDirectEditorConfiguration createXTextEditorConfiguration() {
int columnIndex = this.layerCell.getColumnIndex();
int rowIndex = this.layerCell.getRowIndex();
Object row = this.elementProvider.getRowElement(rowIndex);
Object column = this.elementProvider.getColumnElement(columnIndex);
row = AxisUtils.getRepresentedElement(row);
column = AxisUtils.getRepresentedElement(column);
return getConfigurationFromEditedEObject(row, column);
}
/**
* This allow to get the configuration for edited object.
*
* @param editedEObject
* The edited object.
* @return The {@link DefaultXtextDirectEditorConfiguration} corresponding the the edited object.
*/
protected DefaultXtextDirectEditorConfiguration getConfigurationFromEditedEObject(Object row, Object column) {
if (row instanceof EObject && column instanceof EStructuralFeature) {
final Object editedEObject = ((EObject) row).eGet((EStructuralFeature) column);
if (editedEObject != null && editedEObject instanceof EObject) {
IPreferenceStore store = Activator.getDefault()
.getPreferenceStore();
String semanticClassName = ((EObject) editedEObject).eClass().getInstanceClassName();
String key = IDirectEditorsIds.EDITOR_FOR_ELEMENT
+ semanticClassName;
String languagePreferred = store.getString(key);
if (languagePreferred != null && !languagePreferred.equals("")) { //$NON-NLS-1$
IDirectEditorConfiguration configuration = DirectEditorsUtil
.findEditorConfiguration(languagePreferred, (EObject) editedEObject);
if (configuration instanceof DefaultXtextDirectEditorConfiguration) {
DefaultXtextDirectEditorConfiguration xtextConfiguration = (DefaultXtextDirectEditorConfiguration) configuration;
xtextConfiguration.preEditAction(editedEObject);
return xtextConfiguration;
}
}
}
}
return null;
}
}
|