Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 7a979136bf11049d5a94f87c1877847ca1e33897 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*******************************************************************************
 * Copyright (c) 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
 *******************************************************************************/
/*
 * Created on Mar 23, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.eclipse.jst.j2ee.navigator.internal.workingsets;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jst.j2ee.navigator.internal.plugin.J2EENavigatorPlugin;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.wst.common.navigator.internal.plugin.WorkbenchNavigatorPlugin;
import org.eclipse.wst.common.navigator.internal.views.extensions.RegistryReader;

/**
 * @author Admin
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ComponentWorkingSetRegistry {
	private static final ComponentWorkingSetRegistry INSTANCE = new ComponentWorkingSetRegistry();
	private static boolean isInitialized = false;
	private static final String[] NO_DESCRIPTORS = new String[0];
	private List commonWorkingSetDescriptors = new ArrayList();

	/**
	 * 
	 */
	public ComponentWorkingSetRegistry() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	public void init() {
		new ComponentWorkingSetRegistryReader().readRegistry();
	}

	/**
	 *  
	 */
	public static ComponentWorkingSetRegistry getInstance() {
		if (isInitialized)
			return INSTANCE;
		synchronized (INSTANCE) {
			if (!isInitialized) {
				INSTANCE.init();
				isInitialized = true;
			}
		}
		return INSTANCE;
	}
	
	/**
	 * @param aDesc
	 */
	private void addCommonWorkingSetDescriptor(ComponentWorkingSetDescriptor aDesc) {
		if (aDesc == null)
			return;
		synchronized (commonWorkingSetDescriptors) {
			boolean bValue = commonWorkingSetDescriptors.contains(aDesc);
			if (bValue == false) {
				commonWorkingSetDescriptors.add(aDesc);
			}
		}
	}
	
	public ComponentWorkingSetDescriptor[] getComponentWorkingSetDescriptors() {
		ComponentWorkingSetDescriptor[] descriptors = new ComponentWorkingSetDescriptor[commonWorkingSetDescriptors.size()];
		return (ComponentWorkingSetDescriptor[])commonWorkingSetDescriptors.toArray(descriptors);
		
	}
	
	public boolean containsId(String id) {
		ComponentWorkingSetDescriptor descriptor = null;
		for (int x=0; x< commonWorkingSetDescriptors.size(); ++x) {
			descriptor = (ComponentWorkingSetDescriptor)commonWorkingSetDescriptors.get(x);
			if (descriptor.getId().equals(id)) 
				return true;
		}
		return false;
	}
	
	class ComponentWorkingSetRegistryReader extends RegistryReader {

		private static final String COMPONENT_WORKING_SET = "componentWorkingSet"; //$NON-NLS-1$


		ComponentWorkingSetRegistryReader() {
			super(J2EENavigatorPlugin.PLUGIN_ID, COMPONENT_WORKING_SET);
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.wst.common.navigator.internal.views.extensions.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement)
		 */
		protected boolean readElement(IConfigurationElement anElement) {
			if (COMPONENT_WORKING_SET.equals(anElement.getName())) {
				try {
					addCommonWorkingSetDescriptor(new ComponentWorkingSetDescriptor(anElement));
					return true;
				} catch (WorkbenchException e) {
					//	 log an error since its not safe to open a dialog here
					WorkbenchNavigatorPlugin.log("Unable to create common working set descriptor.", e.getStatus());//$NON-NLS-1$
				}
			}
			return false;
		}
	}

	/**
	 * @param editPageId
	 * @param typeId
	 * @return
	 */
	public ComponentWorkingSetDescriptor getWorkingSetDescriptor(String editPageId, String typeId) {
		ComponentWorkingSetDescriptor[] descriptors = getComponentWorkingSetDescriptors();
		ComponentWorkingSetDescriptor descriptor = null;
		for (int x=0; x< descriptors.length ; ++x) {
			descriptor = descriptors[x];
			if (descriptor.getId().equals(editPageId) 
					&& descriptor.getTypeId().equals(typeId))
				return descriptor;
		}
		return null;
	}

}

Back to the top