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
|
/****************************************************************************
* 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.internal.irc.ui.IRCUI;
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
import org.eclipse.ecf.ui.IConnectWizard;
import org.eclipse.ecf.ui.actions.AsynchContainerConnectAction;
import org.eclipse.ecf.ui.dialogs.ContainerConnectErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.osgi.util.NLS;
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 {
public static final String DEFAULT_GUEST_USER = "guest";
private Shell shell;
private IRCConnectWizardPage page;
private IContainer container;
private ID targetID;
private IConnectContext connectContext;
private String authorityAndPath = 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 authorityAndPart) {
super();
this.authorityAndPath = authorityAndPart;
}
public void addPages() {
page = new IRCConnectWizardPage(authorityAndPath);
addPage(page);
}
public void init(IWorkbench workbench, IContainer container) {
shell = workbench.getActiveWorkbenchWindow().getShell();
this.container = container;
}
public boolean performFinish() {
connectContext = ConnectContextFactory
.createPasswordConnectContext(page.getPassword());
String connectID = "irc://"+page.getConnectID();
try {
targetID = IDFactory.getDefault().createID(
container.getConnectNamespace(), connectID);
} catch (IDCreateException e) {
MessageDialog.openError(shell, "Connect Error", NLS.bind(
"Invalid connect ID: {0}", connectID));
return false;
}
IChatRoomManager manager = (IChatRoomManager) this.container
.getAdapter(IChatRoomManager.class);
IRCUI ui = new IRCUI(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;
}
}
|