blob: faa58e2eb00f51dbf6c5853c1d69b4f04b57733f (
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
|
/*****************************************************************************
* Copyright (c) 2010 CEA LIST.
*
*
* 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:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.properties.tabbed.profile;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
import org.eclipse.uml2.uml.Element;
/**
* Basic Papyrus implementation for property view section. Each section in papyrus should override
* this section, not {@link AbstractViewSection}.
*/
public class AbstractViewSection extends AbstractPropertySection {
protected org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart editPart;
protected IMultiDiagramEditor editor;
protected TransactionalEditingDomain editingDomain;
protected EObject eObject;
/**
* {@inheritDoc}
*/
public void setInput(IWorkbenchPart part, ISelection selection) {
super.setInput(part, selection);
Object input = ((IStructuredSelection)selection).getFirstElement();
// look for modelManager
if(input instanceof org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart) {
editPart = ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)input);
eObject=editPart.resolveSemanticElement();
}
else{
eObject= resolveSemanticObject(input);
}
if(part instanceof IEditingDomainProvider) {
editingDomain = (TransactionalEditingDomain)((IEditingDomainProvider)part).getEditingDomain();
}
}
/**
* Get the {@link TransactionalEditingDomain} from the {@link IMultiDiagramEditor}.
* @param editor
* @return
*/
protected TransactionalEditingDomain getTransactionalEditingDomain(IMultiDiagramEditor editor) {
try {
return editor.getServicesRegistry().getService(TransactionalEditingDomain.class);
} catch (ServiceException e) {
// TODO Log instead of showing the trace.
e.printStackTrace();
return null;
}
}
/**
*
* @return the select uml element of null if not
*/
protected Element getElement(){
if(eObject instanceof Element){
return ((Element)eObject);
}
return null;
}
/**
* 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;
}
}
|