blob: da434aa0a3d94cb4b6cafe9d1a9e9bbf1c64616c (
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
|
/*****************************************************************************
* Copyright (c) 2016 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.infra.nattable.properties.modelelement;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.papyrus.infra.core.sasheditor.editor.IMultiPageEditorPart;
import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor;
import org.eclipse.papyrus.infra.properties.contexts.DataContextElement;
import org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement;
import org.eclipse.papyrus.infra.ui.util.EditorHelper;
import org.eclipse.ui.IEditorPart;
/**
* The model factory to create {@link NatTableModelElement}s from the current nattable editor.
*
* @since 2.1
*/
public class EObjectInNatTableFactory extends NatTableFactory {
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElementFactory#doCreateFromSource(java.lang.Object, org.eclipse.papyrus.infra.properties.contexts.DataContextElement)
*/
@Override
protected EMFModelElement doCreateFromSource(final Object sourceElement, final DataContextElement context) {
EMFModelElement result = null;
final NatTableEditor nattableEditor = getCurrentNatTableEditor();
if (null != nattableEditor) {
final EditingDomain domain = nattableEditor.getTableEditingDomain();
result = new NatTableModelElement(nattableEditor.getTable(), domain);
} else {
result = super.doCreateFromSource(sourceElement, context);
}
return result;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractEMFModelElementFactory#updateModelElement(org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement, java.lang.Object)
*/
@Override
protected void updateModelElement(final EMFModelElement modelElement, final Object newSourceElement) {
final NatTableEditor nattableEditor = getCurrentNatTableEditor();
if (null != nattableEditor) {
if (modelElement instanceof NatTableModelElement) {
updateTableModelElement((NatTableModelElement) modelElement, nattableEditor.getTable());
}
updateEMFModelElement(modelElement, nattableEditor.getTable());
} else {
super.updateModelElement(modelElement, newSourceElement);
}
}
/**
* This allows to get the current nattable editor when this is available.
*
* @return The current nattable editor if available or <code>null</code>.
*/
protected NatTableEditor getCurrentNatTableEditor() {
NatTableEditor result = null;
final IEditorPart currentEditor = EditorHelper.getCurrentEditor();
if (currentEditor instanceof IMultiPageEditorPart) {
result = ((IMultiPageEditorPart) currentEditor).getActiveEditor().getAdapter(NatTableEditor.class);
} else if (currentEditor instanceof IAdaptable) {
result = ((IAdaptable) currentEditor).getAdapter(NatTableEditor.class);
}
return result;
}
}
|