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: 76b974464740544efe3bebf9420f4964d7fc60d7 (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
/*******************************************************************************
 * 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.earcreation;



import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jst.j2ee.application.Module;
import org.eclipse.jst.j2ee.internal.earcreation.modulemap.ModuleMapping;


/**
 * Insert the type's description here. Creation date: (03/29/01 4:48:46 PM)
 * 
 * @author: Administrator
 */
public class RemoveModuleFromEARProjectCommand extends ModuleInEARProjectCommand {
	public RemoveModuleFromEARProjectCommand(Module module, IProject anEarProject) {
		super();
		setEarProject(anEarProject);
		setModuleUri(module.getUri());
		setModuleAltDD(module.getAltDD());
		setModule(module);
	}

	public boolean canExecute() {
		return super.canExecute() && EARNatureRuntime.getRuntime(getEarProject()) != null;
	}

	protected void primExecute() {
		//Required for validate edit support
		refreshModule();
		// Set up nestedJ2EEProject before the map removed
		// It is needed for undo remove
		if (editModel != null) {
			ModuleMapping map = editModel.getModuleMapping(module);
			if (map != null)
				setNestedJ2EEProject(ResourcesPlugin.getWorkspace().getRoot().getProject(map.getProjectName()));
		}
		removeModuleMapping();
		if (mapSuccessful)
			removeModule();
	}

	/*
	 * If this was a deferred command, then the module object might be stale because a file was
	 * checked out
	 */
	protected void refreshModule() {
		if (module == null)
			return;
		Module m = (Module) EcoreUtil.resolve(module, getApplication());
		if (m != null)
			module = m;
	}

	protected void primUndo() {
		if (moduleSuccessful) {
			addModule();
			moduleSuccessful = false;
		}
		if (mapSuccessful) {
			addModuleMapping();
			mapSuccessful = false;
		}
	}

	protected void removeModule() {

		super.removeModule();
		moduleSuccessful = true;
	}

	protected void removeModuleMapping() {
		super.removeModuleMapping();
		mapSuccessful = true;
	}

	// override
	public String getLabel() {
		return label == null ? EARCreationResourceHandler.getString("Remove_Module_Command_Label_UI_") : label;//$NON-NLS-1$
	}
}

Back to the top