blob: d60e8f71f96cc2b273e7577ee7859185c1745df1 (
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
|
/**
*
*/
package org.eclipse.papyrus.infra.ui.editorsfactory;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.graphics.Image;
/**
* Concrete implementation of the {@link IPageIconsRegistry}. This
* implementation allows to add and remove {@link IPageIconsRegistry}.
*
*
* @author cedric dumoulin
*/
public class PageIconsRegistry implements IPageIconsRegistryExtended {
/** list of registered icon factories */
protected List<IEditorIconFactory> pageIcons = new ArrayList<IEditorIconFactory>();
/**
* Constructor.
*
* @param editorFactoryRegistry
* @param servicesRegistry
*/
public PageIconsRegistry() {
}
/**
* Walk each registered {@link IEditorFactory} to find the one handling the
* specified pageIdentifier. Call the corresponding method in the found
* pageIdentifier.
*
* TODO Throw an exception to report errors.
*
* @see org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IPageModelFactory#createIPageModel(java.lang.Object)
*/
@Override
public Image getEditorIcon(Object pageIdentifier) {
for (IEditorIconFactory factory : getPageIcons()) {
if (factory.isPageModelFactoryFor(pageIdentifier)) {
{
// return factory.getEditorIcon(pageIdentifier);
return factory.getEditorIcon(pageIdentifier);
}
}
}
// no editor found !
// TODO Throw an exception.
// throw new EditorNotFoundException("No editor registered for '" +
// pageIdentifier + "'.");
return null;
}
/**
* @return the editorFactories
*/
protected List<IEditorIconFactory> getPageIcons() {
return pageIcons;
}
/**
* Add the specified {@link IEditorFactory}
*
* @param editorIconFactory
*/
public void add(IEditorIconFactory editorIconFactory) {
// This should never happen
if (editorIconFactory == null) {
throw new RuntimeException("Parameter should not be null."); //$NON-NLS-1$
}
pageIcons.add(editorIconFactory);
}
/**
* Remove the specified {@link IEditorFactory}
*
* @param editorIconFactory
*/
public void remove(IEditorIconFactory editorIconFactory) {
pageIcons.remove(editorIconFactory);
}
/**
* Return the path to the icon ressource.
*
* @see org.eclipse.papyrus.infra.ui.editorsfactory.IPageIconsRegistryExtended#getEditorURLIcon(java.lang.Object)
*
* @param model
* @return
*/
@Override
public String getEditorURLIcon(Object model) {
for (IEditorIconFactory factory : getPageIcons()) {
if (factory.isPageModelFactoryFor(model)) {
{
if (factory instanceof IEditorIconFactoryExtended) {
return ((IEditorIconFactoryExtended) factory).getURLMainIcon(model);
}
}
}
}
return "";
}
@Override
public void dispose() {
for (IEditorIconFactory factory : pageIcons) {
factory.dispose();
}
}
}
|