1 | /* |
2 | * Copyright 2007, SDQ, IPD, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.usage.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.usage.part.PalladioComponentModelUsageDiagramEditorPlugin; |
26 | import de.uka.ipd.sdq.pcmbench.propertytabs.PalladioAdapterFactoryContentProvider; |
27 | |
28 | /** |
29 | * @generated |
30 | */ |
31 | public class PalladioComponentModelPropertySection extends |
32 | AdvancedPropertySection implements IPropertySourceProvider { |
33 | |
34 | /** |
35 | * @generated not |
36 | */ |
37 | public IPropertySource getPropertySource(Object object) { |
38 | if (object instanceof IPropertySource) { |
39 | return (IPropertySource) object; |
40 | } |
41 | AdapterFactory af = getAdapterFactory(object); |
42 | if (af != null) { |
43 | return new PalladioAdapterFactoryContentProvider(af) |
44 | .getPropertySource(object); |
45 | } |
46 | if (object instanceof IAdaptable) { |
47 | return (IPropertySource) ((IAdaptable) object) |
48 | .getAdapter(IPropertySource.class); |
49 | } |
50 | return null; |
51 | } |
52 | |
53 | /** |
54 | * @generated |
55 | */ |
56 | protected IPropertySourceProvider getPropertySourceProvider() { |
57 | return this; |
58 | } |
59 | |
60 | /** |
61 | * Modify/unwrap selection. |
62 | * @generated |
63 | */ |
64 | protected Object transformSelection(Object selected) { |
65 | |
66 | if (selected instanceof EditPart) { |
67 | Object model = ((EditPart) selected).getModel(); |
68 | return model instanceof View ? ((View) model).getElement() : null; |
69 | } |
70 | if (selected instanceof View) { |
71 | return ((View) selected).getElement(); |
72 | } |
73 | if (selected instanceof IAdaptable) { |
74 | View view = (View) ((IAdaptable) selected).getAdapter(View.class); |
75 | if (view != null) { |
76 | return view.getElement(); |
77 | } |
78 | } |
79 | return selected; |
80 | } |
81 | |
82 | /** |
83 | * @generated |
84 | */ |
85 | public void setInput(IWorkbenchPart part, ISelection selection) { |
86 | if (selection.isEmpty() |
87 | || false == selection instanceof StructuredSelection) { |
88 | super.setInput(part, selection); |
89 | return; |
90 | } |
91 | final StructuredSelection structuredSelection = ((StructuredSelection) selection); |
92 | ArrayList transformedSelection = new ArrayList(structuredSelection |
93 | .size()); |
94 | for (Iterator it = structuredSelection.iterator(); it.hasNext();) { |
95 | Object r = transformSelection(it.next()); |
96 | if (r != null) { |
97 | transformedSelection.add(r); |
98 | } |
99 | } |
100 | super.setInput(part, new StructuredSelection(transformedSelection)); |
101 | } |
102 | |
103 | /** |
104 | * @generated not |
105 | */ |
106 | protected AdapterFactory getAdapterFactory(Object object) { |
107 | return PalladioComponentModelUsageDiagramEditorPlugin.getInstance() |
108 | .getItemProvidersAdapterFactory(); |
109 | // if (getEditingDomain() instanceof AdapterFactoryEditingDomain) { |
110 | // return ((AdapterFactoryEditingDomain) getEditingDomain()) |
111 | // .getAdapterFactory(); |
112 | // } |
113 | // TransactionalEditingDomain editingDomain = TransactionUtil |
114 | // .getEditingDomain(object); |
115 | // if (editingDomain != null) { |
116 | // return ((AdapterFactoryEditingDomain) editingDomain) |
117 | // .getAdapterFactory(); |
118 | // } |
119 | // return null; |
120 | } |
121 | |
122 | } |