1 | /* |
2 | * Copyright 2007, IPD, SDQ, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.repository.sheet; |
5 | |
6 | import java.util.ArrayList; |
7 | import java.util.Iterator; |
8 | |
9 | import org.eclipse.core.runtime.IAdaptable; |
10 | import org.eclipse.emf.common.notify.AdapterFactory; |
11 | import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; |
12 | import org.eclipse.emf.edit.provider.IItemPropertySource; |
13 | import org.eclipse.emf.edit.ui.provider.PropertySource; |
14 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
15 | import org.eclipse.emf.transaction.util.TransactionUtil; |
16 | import org.eclipse.gef.EditPart; |
17 | import org.eclipse.gmf.runtime.diagram.ui.properties.sections.AdvancedPropertySection; |
18 | import org.eclipse.gmf.runtime.notation.View; |
19 | import org.eclipse.jface.viewers.ISelection; |
20 | import org.eclipse.jface.viewers.StructuredSelection; |
21 | import org.eclipse.ui.IWorkbenchPart; |
22 | import org.eclipse.ui.views.properties.IPropertySource; |
23 | import org.eclipse.ui.views.properties.IPropertySourceProvider; |
24 | |
25 | import de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelRepositoryDiagramEditorPlugin; |
26 | |
27 | /** |
28 | * @generated |
29 | */ |
30 | public class PalladioComponentModelPropertySection extends |
31 | AdvancedPropertySection implements IPropertySourceProvider { |
32 | |
33 | /** |
34 | * @generated |
35 | */ |
36 | public IPropertySource getPropertySource(Object object) { |
37 | if (object instanceof IPropertySource) { |
38 | return (IPropertySource) object; |
39 | } |
40 | AdapterFactory af = getAdapterFactory(object); |
41 | if (af != null) { |
42 | IItemPropertySource ips = (IItemPropertySource) af.adapt(object, |
43 | IItemPropertySource.class); |
44 | if (ips != null) { |
45 | return new PropertySource(object, ips); |
46 | } |
47 | } |
48 | if (object instanceof IAdaptable) { |
49 | return (IPropertySource) ((IAdaptable) object) |
50 | .getAdapter(IPropertySource.class); |
51 | } |
52 | return null; |
53 | } |
54 | |
55 | /** |
56 | * @generated |
57 | */ |
58 | protected IPropertySourceProvider getPropertySourceProvider() { |
59 | return this; |
60 | } |
61 | |
62 | /** |
63 | * Modify/unwrap selection. |
64 | * @generated |
65 | */ |
66 | protected Object transformSelection(Object selected) { |
67 | |
68 | if (selected instanceof EditPart) { |
69 | Object model = ((EditPart) selected).getModel(); |
70 | return model instanceof View ? ((View) model).getElement() : null; |
71 | } |
72 | if (selected instanceof View) { |
73 | return ((View) selected).getElement(); |
74 | } |
75 | if (selected instanceof IAdaptable) { |
76 | View view = (View) ((IAdaptable) selected).getAdapter(View.class); |
77 | if (view != null) { |
78 | return view.getElement(); |
79 | } |
80 | } |
81 | return selected; |
82 | } |
83 | |
84 | /** |
85 | * @generated |
86 | */ |
87 | public void setInput(IWorkbenchPart part, ISelection selection) { |
88 | if (selection.isEmpty() |
89 | || false == selection instanceof StructuredSelection) { |
90 | super.setInput(part, selection); |
91 | return; |
92 | } |
93 | final StructuredSelection structuredSelection = ((StructuredSelection) selection); |
94 | ArrayList transformedSelection = new ArrayList(structuredSelection |
95 | .size()); |
96 | for (Iterator it = structuredSelection.iterator(); it.hasNext();) { |
97 | Object r = transformSelection(it.next()); |
98 | if (r != null) { |
99 | transformedSelection.add(r); |
100 | } |
101 | } |
102 | super.setInput(part, new StructuredSelection(transformedSelection)); |
103 | } |
104 | |
105 | /** |
106 | * @generated not |
107 | */ |
108 | protected AdapterFactory getAdapterFactory(Object object) { |
109 | return PalladioComponentModelRepositoryDiagramEditorPlugin |
110 | .getInstance().getItemProvidersAdapterFactory(); |
111 | } |
112 | |
113 | } |