blob: 7cfb418a0e69d87d9af900bf6c9ac8af7fa51f20 (
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
|
/*****************************************************************************
* Copyright (c) 2008 CEA LIST, Obeo.
*
*
* 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:
* Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
* Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
* Jerome BENOIS (Obeo) jerome.benois@obeo.fr - improve to deal with EEF based properties view and model explorer
*
*****************************************************************************/
package org.eclipse.papyrus.uml.properties.profile.ui.section;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.uml.properties.profile.ui.compositeforview.AppliedProfileCompositeWithView;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
/**
* This section is used to apply a profile on packages or model
*
* @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
*/
public class AppliedProfileSection extends AbstractPropertySection {
private AppliedProfileCompositeWithView appliedProfileComposite;
/**
*
* {@inheritDoc}
*/
@Override
public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
super.createControls(parent, tabbedPropertySheetPage);
appliedProfileComposite = new AppliedProfileCompositeWithView(parent, getWidgetFactory());
appliedProfileComposite.createContent();
}
/**
*
*
* @return
*/
@Override
public boolean shouldUseExtraSpace() {
return true;
}
/**
*
* {@inheritDoc}
*/
public void refresh() {
appliedProfileComposite.refresh();
}
/**
*
* {@inheritDoc}
*/
public void setInput(IWorkbenchPart part, ISelection selection) {
super.setInput(part, selection);
if(selection instanceof IStructuredSelection) {
Object input = ((IStructuredSelection)selection).getFirstElement();
if(input instanceof GraphicalEditPart && ((GraphicalEditPart)input).getModel() instanceof View) {
GraphicalEditPart graphicalEditPart = (GraphicalEditPart)input;
View view = (View)graphicalEditPart.getModel();
if(view.getElement() != null) {
appliedProfileComposite.setSelection(selection);
}
} else {
EObject eObject = resolveSemanticObject(input);
if(eObject != null && eObject instanceof EObject) {
appliedProfileComposite.setSelection(selection);
}
}
appliedProfileComposite.setDomain(EditorUtils.getTransactionalEditingDomain());
}
}
/**
* Resolve semantic element
*
* @param object
* the object to resolve
* @return <code>null</code> or the semantic element associated to the specified object
*/
private EObject resolveSemanticObject(Object object) {
if(object instanceof EObject) {
return (EObject)object;
} else if(object instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable)object;
if(adaptable.getAdapter(EObject.class) != null) {
return (EObject)adaptable.getAdapter(EObject.class);
}
}
return null;
}
/**
*
*/
public void dispose() {
super.dispose();
if(appliedProfileComposite != null)
appliedProfileComposite.disposeListeners();
}
}
|