Skip to main content
summaryrefslogtreecommitdiffstats
blob: 47bc51b0f8a59503ca142e20417506d9ded0d06c (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
/*******************************************************************************
 * Copyright (c) 2003, 2005 IBM Corporation and others.
 * 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:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.common.internal.emfworkbench.edit;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jem.util.RegistryReader;
import org.eclipse.wst.common.internal.emfworkbench.integration.EMFWorkbenchEditPlugin;


/**
 * @author mdelder
 */
class EditModelExtensionRegistry extends RegistryReader {

	private static EditModelExtensionRegistry INSTANCE = null;

	public static final String EDIT_MODEL_EXT_ELEMENT = "editModelExtension"; //$NON-NLS-1$
	public static final String EDIT_MODEL_ID_ATTR = "editModelID"; //$NON-NLS-1$
	public static final String GROUP_ID_ATTR = "functionGroupID"; //$NON-NLS-1$


	private Map extensions = null;

	protected EditModelExtensionRegistry() {
		super(EMFWorkbenchEditPlugin.ID, EMFWorkbenchEditPlugin.EDIT_MODEL_EXTENSION_REGISTRY_EXTENSION_POINT);
	}

	public static EditModelExtensionRegistry getInstance() {
		if (INSTANCE == null) {
			INSTANCE = new EditModelExtensionRegistry();
			INSTANCE.readRegistry();
		}
		return INSTANCE;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.wst.common.frameworks.internal.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement)
	 */
	public boolean readElement(IConfigurationElement element) {

		boolean result = false;
		Collection extensionsByID = null;
		EditModelExtension editModelExtension = null;
		if (element.getName().equals(EDIT_MODEL_EXT_ELEMENT)) {
			editModelExtension = new EditModelExtension(element);
			extensionsByID = (Collection) getExtensions().get(editModelExtension.getEditModelID());
			if (extensionsByID == null) {
				extensionsByID = new ArrayList();
				getExtensions().put(editModelExtension.getEditModelID(), extensionsByID);
			}
			extensionsByID.add(editModelExtension);
			result = true;
		}
		return result;
	}

	protected Map getExtensions() {
		if (extensions == null)
			extensions = new HashMap();
		return extensions;
	}

	/**
	 * @return
	 */
	public Collection getEditModelResources(Object editModelID) {
		//TODO - Cache the resources
		Collection editModelResources = new ArrayList();
		Collection editModelExtensions = (Collection) getExtensions().get(editModelID);

		if (editModelExtensions == null || editModelExtensions.size() == 0)
			return Collections.EMPTY_LIST;
		Iterator itr = editModelExtensions.iterator();
		while (itr.hasNext()) {
			EditModelExtension ext = (EditModelExtension) itr.next();
			editModelResources.addAll(ext.getResources());
		}
		return (!editModelExtensions.isEmpty()) ? editModelResources : Collections.EMPTY_LIST;
	}

}

Back to the top