Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6590e49a974b78df9e229152af5cb98a0089bb0e (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*******************************************************************************
 * Copyright (c) Philipps University of Marburg. 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:
 *     Philipps University of Marburg - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.refactor.refactoring.core;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.emf.refactor.refactoring.interfaces.IController;
import org.eclipse.emf.refactor.refactoring.interfaces.IGuiHandler;

/**
 * Base class of a specific emf model refactoring.
 * @generated NOT
 * @author Florian Mantz
 */
public class Refactoring implements Comparable<Refactoring> {

	/**
	 * Id of the emf model refactoring.
	 */
	private final String id;
	
	/**
	 * Name of the emf model refactoring.
	 */
	private final String name;
	
	/**
	 * Namespace of the emf model refactoring.
	 */
	private final String namespaceUri;
	
	/**
	 * GuiHandler object of the emf model refactoring.
	 */
	private final IGuiHandler gui;
	
	/**
	 * Controller object of the emf model refactoring.
	 */
	private IController controller;
	
	/**
	 * ConfigurationElement object of the emf model refactoring used
	 * for lazy loading.
	 */
	private IConfigurationElement rawRefactoring;
	
	/**
	 * Contructs an emf model refactoring with GuiHandler object.
	 * @param id Id of the emf model refactoring.
	 * @param name Name of the emf model refactoring.
	 * @param namespaceUri Namespace of the emf model refactoring.
	 * @param gui GuiHandler object of the emf model refactoring.
	 */
	private Refactoring
		(String id, String name, String namespaceUri,IGuiHandler gui) {
		this.id = id;
		this.name = name;
		this.namespaceUri = namespaceUri;
		this.gui = gui;
		this.gui.setParent(this);
	}
	
	/**
	 * Contructs an emf model refactoring with GuiHandler and a controller
	 * object.
	 * @param id Id of the emf model refactoring.
	 * @param name Name of the emf model refactoring.
	 * @param namespaceUri Namespace of the emf model refactoring.
	 * @param gui GuiHandler object of the emf model refactoring.
	 * @param controller Controller object of the emf model refactoring.
	 */
	public Refactoring
		(String id, String name, String namespaceUri, 
				IGuiHandler gui, IController controller){
			this(id,name,namespaceUri,gui);
			this.controller = controller;
			this.controller.setParent(this);
	}
	
	/**
	 * Contructs an emf model refactoring with GuiHandler and a 
	 * ConfigurationElement object.
	 * @param id Id of the emf model refactoring.
	 * @param name Name of the emf model refactoring.
	 * @param namespaceUri Namespace of the emf model refactoring.
	 * @param gui GuiHandler object of the emf model refactoring.
	 * @param rawRefactoring ConfigurationElement object of the emf model 
	 * refactoring. 
	 */
	public Refactoring
		(String id, String name, String namespaceUri, 
				IGuiHandler gui, IConfigurationElement rawRefactoring){
			this(id,name,namespaceUri,gui);
			this.rawRefactoring = rawRefactoring;
	}
	
	/**
	 * Gets the namespace of the emf model refactoring.
	 * @return Namespace of the emf model refactoring.
	 */
	public String getNamespaceUri(){
		return namespaceUri;
	}
	
	/**
	 * Gets the id of the emf model refactoring.
	 * @return Id of the emf model refactoring.
	 */
	public String getId() {
		return id;
	}

	/**
	 * Gets the name of the emf model refactoring.
	 * @return Name of the emf model refactoring.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Gets the controller object of the emf model refactoring.
	 * @return Controller object of the emf model refactoring.
	 */
	public IController getController() {
		lazyLoadController();
		return controller;
	}
	
	private void lazyLoadController() {
		if(null == controller){
			try {
				this.controller = 
					(IController)rawRefactoring
							.createExecutableExtension("controller");
				this.controller.setParent(this);
			} catch (CoreException e) {
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * Gets the guiHandler object of the emf model refactoring.
	 * @return GuiHandler object of the emf model refactoring.
	 */
	public IGuiHandler getGui() {
		return gui;
	}
	
	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Refactoring other = (Refactoring) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	/**
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(Refactoring emfRefactoring) {
		if(this.equals(emfRefactoring))return 0;
		if(this.getName().equals(emfRefactoring.getName())){
			return emfRefactoring.id.hashCode() - this.id.hashCode();
		}else{
		    return emfRefactoring.getName().compareTo(this.getName());	
		}
	}

}

Back to the top