blob: f9cd16b48e4114164a60500ec12b7790295352e7 (
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
|
/*****************************************************************************
* Copyright (c) 2010 Atos Origin.
*
*
* 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:
* Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.documentation.view;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.papyrus.documentation.IDocumentationChangedListener;
import org.eclipse.ui.IWorkbenchPart;
public class DocumentionPartHandlerRegistry {
private static class DocumentionPartHandlerRegistryHolder {
public static final DocumentionPartHandlerRegistry instance = new DocumentionPartHandlerRegistry();
}
public static DocumentionPartHandlerRegistry getInstance() {
return DocumentionPartHandlerRegistryHolder.instance;
}
private static final String DOCUMENTATIONPARTHANDLER_EXTENSION_ID = "org.eclipse.papyrus.documentation.view.documentationPartHandler"; //$NON-NLS-1$
private static final String DOCUMENTATIONPARTHANDLER_ID = "documentationPartHandler"; //$NON-NLS-1$
private Set<IDocumentationPartHandler> documentationPartHandlers = new HashSet<IDocumentationPartHandler>();
private Set<IDocumentationChangedListener> documentationChangedListeners = new HashSet<IDocumentationChangedListener>();
private DocumentionPartHandlerRegistry() {
initializeMap();
}
public IDocumentationPartHandler getDocumentationPartHandler(IWorkbenchPart part) {
for (IDocumentationPartHandler documentationPartHandler : documentationPartHandlers) {
if (documentationPartHandler.canHandlePart(part)) {
return documentationPartHandler;
}
}
return null;
}
private void initializeMap() {
// Reading data from plugins
IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(DOCUMENTATIONPARTHANDLER_EXTENSION_ID);
for(int i = 0; i < configElements.length; i++) {
initializeOne(configElements[i]);
}
}
private void initializeOne(IConfigurationElement iConfigurationElement) {
try {
IDocumentationPartHandler documentationPartHandler = (IDocumentationPartHandler)iConfigurationElement.createExecutableExtension(DOCUMENTATIONPARTHANDLER_ID);
documentationPartHandlers.add(documentationPartHandler);
} catch (Throwable e) {
e.printStackTrace();
}
}
/**
* {@inheritDoc}
*/
public void registerDocumentationChangedListener(IDocumentationChangedListener listener) {
documentationChangedListeners.add(listener);
}
/**
* {@inheritDoc}
*/
public void unregisterDocumentationChangedListener(IDocumentationChangedListener listener) {
documentationChangedListeners.remove(listener);
}
/**
* {@inheritDoc}
*/
public Set<IDocumentationChangedListener> getRegisteredDocumentationChangedListeners() {
return documentationChangedListeners;
}
}
|