Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6f1b44ff1160a50561faa4167b09f2050582b877 (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
/****************************************************************************
 * Copyright (c) 2007 Remy Suen, Composent Inc., 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:
 *    Remy Suen <remy.suen@gmail.com> - initial API and implementation
 *    Scott Lewis <slewis@composent.com>
 *****************************************************************************/
package org.eclipse.ecf.internal.irc.ui.wizards;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.security.ConnectContextFactory;
import org.eclipse.ecf.core.security.IConnectContext;
import org.eclipse.ecf.core.util.IExceptionHandler;
import org.eclipse.ecf.internal.irc.ui.Activator;
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
import org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerUI;
import org.eclipse.ecf.ui.IConnectWizard;
import org.eclipse.ecf.ui.actions.AsynchContainerConnectAction;
import org.eclipse.ecf.ui.dialogs.ContainerConnectErrorDialog;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;

public final class IRCConnectWizard extends Wizard implements IConnectWizard {

	private Shell shell;

	private IRCConnectWizardPage page;

	private IContainer container;

	private ID targetID;

	private IConnectContext connectContext;

	private String uriString = null;
	
	private IExceptionHandler exceptionHandler = new IExceptionHandler() {
		public IStatus handleException(final Throwable exception) {
			if (exception != null) {
				Display.getDefault().asyncExec(new Runnable() {
					public void run() {
						new ContainerConnectErrorDialog(shell, IStatus.ERROR,
								"See Details", targetID.getName(), exception)
								.open();
					}
				});
			}
			return new Status(IStatus.OK, Activator.PLUGIN_ID, IStatus.OK,
					"Connected", null);
		}
	};

	public IRCConnectWizard() {
		super();
	}
	
	public IRCConnectWizard(String uri) {
		super();
		uriString = uri;
	}
	public void addPages() {
		page = new IRCConnectWizardPage(uriString);
		addPage(page);
	}

	public void init(IWorkbench workbench, IContainer container) {
		shell = workbench.getActiveWorkbenchWindow().getShell();
		this.container = container;
	}

	public boolean performFinish() {
		connectContext = ConnectContextFactory
				.createPasswordConnectContext(page.getPassword());

		try {
			targetID = IDFactory.getDefault().createID(
					container.getConnectNamespace(), page.getConnectID());
		} catch (IDCreateException e) {
			// TODO: This needs to be handled properly
			e.printStackTrace();
			return false;
		}

		IChatRoomManager manager = (IChatRoomManager) this.container
				.getAdapter(IChatRoomManager.class);

		if (manager == null) {
			// XXX
			// Serious error...log, show dialog, freak out, etc
			return false;
		} else {
			ChatRoomManagerUI ui = new ChatRoomManagerUI(this.container,
					manager, exceptionHandler);
			ui.showForTarget(targetID);
			// If it's not already connected, then we connect this new container
			if (!ui.isContainerConnected()) {
				new AsynchContainerConnectAction(this.container, this.targetID,
						this.connectContext, exceptionHandler).run(null);

			}
		}

		return true;
	}

}

Back to the top