Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ce2730aae3217401632ba81a9ead1db53136763a (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
package org.eclipse.ecf.presence.collab.ui;

import java.util.Hashtable;

import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.util.ECFException;
import org.eclipse.ecf.datashare.IChannelContainerAdapter;
import org.eclipse.ecf.internal.presence.collab.ui.Activator;
import org.eclipse.ecf.internal.presence.collab.ui.Messages;
import org.eclipse.ecf.presence.roster.IRoster;
import org.eclipse.ecf.presence.ui.roster.AbstractRosterContributionItem;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;

public class URLShareRosterContributionItem extends
		AbstractRosterContributionItem {

	private static Hashtable urlsharechannels = new Hashtable();

	public URLShareRosterContributionItem() {
	}

	public URLShareRosterContributionItem(String id) {
		super(id);
	}

	protected static URLShare getURLShare(ID containerID) {
		return (URLShare) urlsharechannels.get(containerID);
	}

	protected static URLShare addURLShare(ID containerID, URLShare urlshare) {
		return (URLShare) urlsharechannels.put(containerID, urlshare);
	}

	protected static URLShare removeURLShare(ID containerID) {
		return (URLShare) urlsharechannels.remove(containerID);
	}

	private IAction[] createActionAdd(final ID containerID,
			final IChannelContainerAdapter channelAdapter) {
		IAction action = new Action() {
			public void run() {
				try {
					addURLShare(containerID, new URLShare(containerID, channelAdapter));
				} catch (ECFException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
		action
				.setText(Messages.URLShareRosterContributionItem_ADD_URL_SHARE_MENU_TEXT);
		action.setImageDescriptor(Activator.imageDescriptorFromPlugin(
				Activator.PLUGIN_ID, Messages.URLShareRosterContributionItem_BROWSER_ICON));
		return new IAction[] { action };
	}

	private IAction[] createActionRemove(final ID containerID,
			final URLShare urlshare) {
		IAction action = new Action() {
			public void run() {
				urlshare.dispose();
				removeURLShare(containerID);
			}
		};
		action
				.setText(Messages.URLShareRosterContributionItem_REMOVE_URL_SHARE_MENU_TEXT);
		action.setImageDescriptor(Activator.imageDescriptorFromPlugin(
				Activator.PLUGIN_ID, Messages.URLShareRosterContributionItem_BROWSER_ICON));
		return new IAction[] { action };
	}

	protected IAction[] makeActions() {
		final IRoster roster = getSelectedRoster();
		if (roster != null) {
			// Roster is selected
			IContainer c = getContainerForRoster(roster);
			if (c != null) {
				// Get existing urlshare for this container (if it exists)
				URLShare urlshare = getURLShare(c.getID());
				// If it does exist already, then create action to remove
				if (urlshare != null)
					return createActionRemove(c.getID(), urlshare);
				else {
					IChannelContainerAdapter channelAdapter = (IChannelContainerAdapter) c
							.getAdapter(IChannelContainerAdapter.class);
					return (channelAdapter == null) ? null : createActionAdd(c
							.getID(), channelAdapter);
				}
			}
		}
		return null;
	}

}

Back to the top