Skip to main content
summaryrefslogtreecommitdiffstats
blob: 16fa29dd3abd9214c88647fea1034f6a29ad975b (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
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ui.target;

import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.core.target.IRemoteTargetResource;
import org.eclipse.team.internal.core.target.Site;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.ISharedImages;

/**
 * Used to show Site instances in the UI. Sites are really just remote
 * resources but are shown with a different icon and label.
 * 
 * @see RemoteResourceElement
 */
public class SiteElement extends RemoteResourceElement {
	private Site site;
	
	public SiteElement(Site site) {
		super(null);
		this.site = site;
	}
	
	public SiteElement(Site site, IRunnableContext runContext) {
		super(null, runContext);
		this.site = site;
	}
	
	public Site getSite() {
		return site;
	}

	public int hashCode() {
		return site.hashCode();
	}
	
	public ImageDescriptor getImageDescriptor(Object object) {
		return TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_SITE_ELEMENT);
	}
	
	public String getLabel(Object o) {
		return getSite().getDisplayName();
	}
	
	public Object getParent(Object o) {
		return null;
	}
	
	public boolean equals(Object obj) {
		if(this == obj)
			return true;
		if(!(obj instanceof SiteElement))
			return false;
		Site otherSite = ((SiteElement)obj).getSite();
		return getSite().equals(otherSite);
	}
	/**
	 * @see IWorkbenchAdapter#getChildren(Object)
	 */
	public Object[] getChildren(Object o) {
		try {
			setRemoteResource(site.getRemoteResource());
		} catch (TeamException e) {
			Utils.handle(e);
			return new Object[0];
		}
		return super.getChildren(this);
	}
	/**
	 * @see RemoteResourceElement#getRemoteResource()
	 */
	public IRemoteTargetResource getRemoteResource() {
		try {
			return site.getRemoteResource();
		} catch (TeamException e) {
			Utils.handle(e);
			return null;
		}
	}
}

Back to the top