blob: d163bbe2d37bff9d9fb3a9fc51fe28270f8a3b2b (
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
|
/*****************************************************************************
* 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:
* Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.properties.ui.modelelement;
import java.util.Set;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.papyrus.infra.constraints.runtime.ConstraintEngine;
import org.eclipse.papyrus.infra.properties.contexts.View;
import org.eclipse.papyrus.infra.properties.ui.creation.CreationContext;
import org.eclipse.papyrus.infra.properties.ui.creation.EcorePropertyEditorFactory;
import org.eclipse.papyrus.infra.properties.ui.runtime.PropertiesRuntime;
import org.eclipse.swt.widgets.Control;
/**
* A ReferenceFactory used to instantiate EObjects.
*/
public class EObjectDirectEditingValueFactory extends EcorePropertyEditorFactory {
/**
* Constructor.
*
* @param referenceIn
* The {@link EReference}.
*/
public EObjectDirectEditingValueFactory(final EReference referenceIn) {
super(referenceIn);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.infra.properties.ui.creation.PropertyEditorFactory#createObject(org.eclipse.swt.widgets.Control, java.lang.Object, java.lang.Object)
*/
@Override
protected Object createObject(final Control widget, final Object context, final Object source) {
if (source == null) {
return null;
}
IStructuredSelection selection = new StructuredSelection(source);
ConstraintEngine<View> constraintEngine = PropertiesRuntime.getConstraintEngine();
Set<View> views = constraintEngine.getDisplayUnits(selection);
if (!views.isEmpty()) {
CreationContext creationContext = getCreationContext(context);
creationContext.pushCreatedElement(source);
creationContext.popCreatedElement(source);
}
return source;
}
}
|