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: 31861ac4c2728129fb0e2dcf39ec64d28755d221 (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
/*******************************************************************************
 * 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.server.ui.internal.editor;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.ServerCore;
import org.eclipse.wst.server.core.internal.Server;
import org.eclipse.wst.server.ui.internal.ImageResource;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPersistableElement;
/**
 * The editor input for server configurations and instances. The
 * input points to a resource that is either an instance or
 * configuration.
 *
 * <p>Editors supporting this editor input should use the ResourceManager
 * to load their own copy of the resource. Each editor is responsible
 * for managing this resource and making sure that only one copy is
 * loaded from disk when multiple editors are opened on the same
 * resource.</p>
 *
 * <p>When the editor saves back to the resource, the server tooling
 * will notice the change and reload the new configuration.</p>
 *
 * <p>Editors should call setEditing(resource, true) when the first
 * editor opens on a particular resource, and setEditing(resource,
 * false) when the last editor on a resource closes. This will
 * ensure that the server tooling does not try to edit the resource
 * and cause conflicting changes while an editor is open.</p>
 */
public class ServerEditorInput implements IServerEditorInput, IPersistableElement {
	private String serverId;

	/**
	 * ServerEditorInput constructor comment.
	 * 
	 * @param serverId a server id
	 */
	public ServerEditorInput(String serverId) {
		super();
		this.serverId = serverId;
	}
	
	/**
	 * Returns the server id.
	 * @return org.eclipse.core.resources.IResource
	 */
	public String getServerId() {
		return serverId;
	}

	/**
	 * @see Object#equals(Object)
	 */
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!(obj instanceof ServerEditorInput))
			return false;
		ServerEditorInput other = (ServerEditorInput) obj;
		if (serverId == null) {
			if (other.serverId != null)
				return false;	
		} else if (!serverId.equals(other.serverId))
			return false;
		return true;
	}

	/**
	 * Returns whether the editor input exists.  
	 * <p>
	 * This method is primarily used to determine if an editor input should 
	 * appear in the "File Most Recently Used" menu.  An editor input will appear 
	 * in the list until the return value of <code>exists</code> becomes 
	 * <code>false</code> or it drops off the bottom of the list.
	 *
	 * @return <code>true</code> if the editor input exists; <code>false</code>
	 *		otherwise
	 */
	public boolean exists() {
		if (serverId != null && ServerCore.findServer(serverId) == null)
			return false;
		
		return true;
	}

	/**
	 * Returns an object which is an instance of the given class
	 * associated with this object. Returns <code>null</code> if
	 * no such object can be found.
	 *
	 * @param adapter the adapter class to look up
	 * @return a object castable to the given class, 
	 *    or <code>null</code> if this object does not
	 *    have an adapter for the given class
	 */
	public Object getAdapter(Class adapter) {
		return Platform.getAdapterManager().getAdapter(this, adapter);
	}

	/**
	 * Returns the ID of an element factory which can be used to recreate 
	 * this object.  An element factory extension with this ID must exist
	 * within the workbench registry.
	 * 
	 * @return the element factory ID
	 */
	public String getFactoryId() {
		return ServerEditorInputFactory.FACTORY_ID;
	}

	public ImageDescriptor getImageDescriptor() {
		return ImageResource.getImageDescriptor(ImageResource.IMG_SERVER);
	}
	
	/**
	 * Returns the name of this editor input for display purposes.
	 * <p>
	 * For instance, if the fully qualified input name is
	 * <code>"a\b\MyFile.gif"</code>, the return value would be just
	 * <code>"MyFile.gif"</code>.
	 *
	 * @return the file name string
	 */
	public String getName() {
		if (serverId != null) {
			IServer server = ServerCore.findServer(serverId);
			if (server != null)
				return server.getName();
			return serverId;
		}
		return "";
	}

	/*
	 * Returns an object that can be used to save the state of this editor input.
	 *
	 * @return the persistable element, or <code>null</code> if this editor input
	 *   cannot be persisted
	 */
	public IPersistableElement getPersistable() {
		return this;
	}

	public String getToolTipText() {
		String s = null;
		if (serverId != null) {
			IServer server = ServerCore.findServer(serverId);
			if (server != null) {
				Server server2 = (Server) server;
				if (server2.getFile() != null) {
					s = server2.getFile().getFullPath().makeRelative().toString();
					if (s.startsWith("/"))
						s = s.substring(1);
				} else
					s = server.getName();
			}
		}
		if (s == null)
			s = "";
		return s;
	}

	/**
	 * Saves the state of an element within a memento.
	 *
	 * @param memento the storage area for element state
	 */
	public void saveState(IMemento memento) {
		ServerEditorInputFactory.saveState(memento, this);
	}
}

Back to the top