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: 916c9a74c410474670fd63abe4a9b7ad12f8854b (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
/***************************************************************************************************
 * Copyright (c) 2003, 2004 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.jst.j2ee.internal.delete;


import java.util.Vector;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.jst.j2ee.applicationclient.internal.creation.ApplicationClientNatureRuntime;
import org.eclipse.jst.j2ee.internal.project.IEJBNatureConstants;
import org.eclipse.jst.j2ee.internal.project.IWebNatureConstants;
import org.eclipse.jst.j2ee.internal.project.J2EENature;


public class J2EEDeleteResourceListener implements IResourceChangeListener {
	// the following are projects that are already being deleted, so ignore them.
	static protected Vector WARProjects = new Vector();
	static protected Vector EJBProjects = new Vector();
	static protected Vector AppClientProjects = new Vector();

	public J2EEDeleteResourceListener() {
		super();
	}

	/**
	 * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent)
	 */
	public void resourceChanged(IResourceChangeEvent event) {
		System.err.println("Hello, world!"); //$NON-NLS-1$
		IResource resource = event.getResource();
		if (resource instanceof IProject) {
			IProject project = (IProject) resource;
			try {
				if (J2EENature.hasRuntime(project, IEJBNatureConstants.NATURE_ID)) {
					if (!EJBProjects.contains(project)) {
						System.err.println("Hello, world!- EJB"); //$NON-NLS-1$
						showEJBOptions(project);
					}
				} else if (project.hasNature(IWebNatureConstants.J2EE_NATURE_ID)) {
					if (!WARProjects.contains(project)) {
						System.err.println("Hello, world!- WAR"); //$NON-NLS-1$
						showWAROptions(project);
					}
				} else if (ApplicationClientNatureRuntime.hasRuntime(project)) {
					if (!AppClientProjects.contains(project)) {
						System.err.println("Hello, world!- AppClient"); //$NON-NLS-1$
						showAppClientOptions(project);
					}
				}
			} catch (Throwable t) {
			}
		}
	}

	protected void showEJBOptions(IProject project) {
		showOptions(project);
	}

	protected void showWAROptions(IProject project) {
		showOptions(project);
	}

	protected void showAppClientOptions(IProject project) {
		showOptions(project);
	}

	protected void showOptions(IProject project) {
		System.err.println("Showing options for " + project.toString()); //$NON-NLS-1$
	}

	static public synchronized void addProject(IProject project) {
		try {
			if (J2EENature.hasRuntime(project, IEJBNatureConstants.NATURE_ID)) {
				EJBProjects.add(project);
			} else if (project.hasNature(IWebNatureConstants.J2EE_NATURE_ID)) {
				WARProjects.add(project);
				System.err.println("There are " + WARProjects.size() + " projects now."); //$NON-NLS-1$ //$NON-NLS-2$
			} else if (ApplicationClientNatureRuntime.hasRuntime(project)) {
				AppClientProjects.add(project);
			}
		} catch (Throwable t) {
		}
	}

	static public synchronized void removeProject(IProject project) {
		// we can't count on the nature any more, since it has been deleted
		try {
			EJBProjects.remove(project);
			WARProjects.remove(project);
			AppClientProjects.remove(project);
		} catch (Throwable t) {
		}
	}
}

Back to the top