Lines 10-25
Link Here
|
10 |
*****************************************************************************/ |
10 |
*****************************************************************************/ |
11 |
package org.eclipse.ecf.presence.ui; |
11 |
package org.eclipse.ecf.presence.ui; |
12 |
|
12 |
|
13 |
import java.text.SimpleDateFormat; |
13 |
//import java.text.SimpleDateFormat; |
14 |
import java.util.*; |
14 |
import java.util.*; |
15 |
import org.eclipse.core.runtime.*; |
15 |
import org.eclipse.core.runtime.*; |
16 |
import org.eclipse.ecf.core.identity.ID; |
16 |
import org.eclipse.ecf.core.identity.ID; |
|
|
17 |
//import org.eclipse.ecf.core.user.User; |
17 |
import org.eclipse.ecf.core.util.ECFException; |
18 |
import org.eclipse.ecf.core.util.ECFException; |
18 |
import org.eclipse.ecf.internal.presence.ui.Activator; |
19 |
import org.eclipse.ecf.internal.presence.ui.*; |
19 |
import org.eclipse.ecf.internal.presence.ui.Messages; |
|
|
20 |
import org.eclipse.ecf.presence.im.*; |
20 |
import org.eclipse.ecf.presence.im.*; |
|
|
21 |
import org.eclipse.ecf.presence.ui.chatroom.*; |
21 |
import org.eclipse.jface.action.*; |
22 |
import org.eclipse.jface.action.*; |
22 |
import org.eclipse.jface.dialogs.MessageDialog; |
23 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
|
24 |
import org.eclipse.jface.resource.JFaceResources; |
23 |
import org.eclipse.jface.text.Document; |
25 |
import org.eclipse.jface.text.Document; |
24 |
import org.eclipse.jface.text.source.SourceViewer; |
26 |
import org.eclipse.jface.text.source.SourceViewer; |
25 |
import org.eclipse.jface.util.IPropertyChangeListener; |
27 |
import org.eclipse.jface.util.IPropertyChangeListener; |
Lines 29-35
Link Here
|
29 |
import org.eclipse.swt.custom.*; |
31 |
import org.eclipse.swt.custom.*; |
30 |
import org.eclipse.swt.events.*; |
32 |
import org.eclipse.swt.events.*; |
31 |
import org.eclipse.swt.graphics.*; |
33 |
import org.eclipse.swt.graphics.*; |
32 |
import org.eclipse.swt.layout.FillLayout; |
34 |
import org.eclipse.swt.layout.*; |
33 |
import org.eclipse.swt.widgets.*; |
35 |
import org.eclipse.swt.widgets.*; |
34 |
import org.eclipse.ui.IWorkbenchPreferenceConstants; |
36 |
import org.eclipse.ui.IWorkbenchPreferenceConstants; |
35 |
import org.eclipse.ui.PlatformUI; |
37 |
import org.eclipse.ui.PlatformUI; |
Lines 40-50
Link Here
|
40 |
|
42 |
|
41 |
public class MessagesView extends ViewPart { |
43 |
public class MessagesView extends ViewPart { |
42 |
|
44 |
|
43 |
private static final SimpleDateFormat FORMATTER = new SimpleDateFormat("(hh:mm:ss a)"); //$NON-NLS-1$ |
45 |
//private static final SimpleDateFormat FORMATTER = new SimpleDateFormat("(hh:mm:ss a)"); //$NON-NLS-1$ |
|
|
46 |
// private static final SimpleDateFormat FORMATTER = new SimpleDateFormat("(HH:mm:ss)"); //$NON-NLS-1$ |
44 |
|
47 |
|
45 |
public static final String VIEW_ID = "org.eclipse.ecf.presence.ui.MessagesView"; //$NON-NLS-1$ |
48 |
public static final String VIEW_ID = "org.eclipse.ecf.presence.ui.MessagesView"; //$NON-NLS-1$ |
46 |
|
49 |
|
47 |
private static final int[] WEIGHTS = {75, 25}; |
50 |
//private static final int[] WEIGHTS = {75, 25}; |
48 |
|
51 |
|
49 |
private CTabFolder tabFolder; |
52 |
private CTabFolder tabFolder; |
50 |
|
53 |
|
Lines 57-62
Link Here
|
57 |
private boolean showTimestamps = true; |
60 |
private boolean showTimestamps = true; |
58 |
|
61 |
|
59 |
private static final String getUserName(ID id) { |
62 |
private static final String getUserName(ID id) { |
|
|
63 |
if (id == null) |
64 |
return Messages.MessagesView_broadcast; |
60 |
IChatID chatID = (IChatID) id.getAdapter(IChatID.class); |
65 |
IChatID chatID = (IChatID) id.getAdapter(IChatID.class); |
61 |
return chatID == null ? id.getName() : chatID.getUsername(); |
66 |
return chatID == null ? id.getName() : chatID.getUsername(); |
62 |
} |
67 |
} |
Lines 86-92
Link Here
|
86 |
while (it.hasNext()) { |
91 |
while (it.hasNext()) { |
87 |
ChatTab tab = (ChatTab) it.next(); |
92 |
ChatTab tab = (ChatTab) it.next(); |
88 |
if (tab.item == e.item) { |
93 |
if (tab.item == e.item) { |
89 |
tab.inputText.setFocus(); |
94 |
if (tab.inputText != null) |
|
|
95 |
tab.inputText.setFocus(); |
90 |
break; |
96 |
break; |
91 |
} |
97 |
} |
92 |
} |
98 |
} |
Lines 147-156
Link Here
|
147 |
} |
153 |
} |
148 |
|
154 |
|
149 |
private ChatTab getTab(IChatMessageSender messageSender, ITypingMessageSender typingSender, ID localID, ID userID) { |
155 |
private ChatTab getTab(IChatMessageSender messageSender, ITypingMessageSender typingSender, ID localID, ID userID) { |
150 |
ChatTab tab = (ChatTab) tabs.get(userID); |
156 |
ChatTab tab = (ChatTab) tabs.get((userID != null) ? userID : (Object) Messages.MessagesView_broadcast); |
151 |
if (tab == null) { |
157 |
if (tab == null) { |
152 |
tab = new ChatTab(messageSender, typingSender, localID, userID); |
158 |
tab = new ChatTab(messageSender, typingSender, localID, userID); |
153 |
tabs.put(userID, tab); |
159 |
tabs.put((userID != null) ? userID : (Object) Messages.MessagesView_broadcast, tab); |
154 |
} |
160 |
} |
155 |
return tab; |
161 |
return tab; |
156 |
} |
162 |
} |
Lines 190-196
Link Here
|
190 |
public synchronized void openTab(IChatMessageSender messageSender, ITypingMessageSender typingSender, ID localID, ID remoteID) { |
196 |
public synchronized void openTab(IChatMessageSender messageSender, ITypingMessageSender typingSender, ID localID, ID remoteID) { |
191 |
Assert.isNotNull(messageSender); |
197 |
Assert.isNotNull(messageSender); |
192 |
Assert.isNotNull(localID); |
198 |
Assert.isNotNull(localID); |
193 |
Assert.isNotNull(remoteID); |
199 |
//Assert.isNotNull(remoteID); |
194 |
ChatTab tab = getTab(messageSender, typingSender, localID, remoteID); |
200 |
ChatTab tab = getTab(messageSender, typingSender, localID, remoteID); |
195 |
// if there is only one tab, select this tab |
201 |
// if there is only one tab, select this tab |
196 |
if (tabs.size() == 1) { |
202 |
if (tabs.size() == 1) { |
Lines 213-219
Link Here
|
213 |
public synchronized void showMessage(IChatMessage message) { |
219 |
public synchronized void showMessage(IChatMessage message) { |
214 |
Assert.isNotNull(message); |
220 |
Assert.isNotNull(message); |
215 |
ID remoteID = message.getFromID(); |
221 |
ID remoteID = message.getFromID(); |
216 |
ChatTab tab = (ChatTab) tabs.get(remoteID); |
222 |
ChatTab tab = (ChatTab) tabs.get((remoteID != null) ? remoteID : (Object) Messages.MessagesView_broadcast); |
217 |
if (tab != null) { |
223 |
if (tab != null) { |
218 |
tab.append(remoteID, message.getBody()); |
224 |
tab.append(remoteID, message.getBody()); |
219 |
} |
225 |
} |
Lines 225-231
Link Here
|
225 |
for (Iterator it = tabs.values().iterator(); it.hasNext();) { |
231 |
for (Iterator it = tabs.values().iterator(); it.hasNext();) { |
226 |
ChatTab tab = (ChatTab) it.next(); |
232 |
ChatTab tab = (ChatTab) it.next(); |
227 |
if (tab.item == item) { |
233 |
if (tab.item == item) { |
228 |
tab.inputText.setFocus(); |
234 |
if (tab.inputText != null) |
|
|
235 |
tab.inputText.setFocus(); |
229 |
break; |
236 |
break; |
230 |
} |
237 |
} |
231 |
} |
238 |
} |
Lines 234-243
Link Here
|
234 |
|
241 |
|
235 |
private class ChatTab { |
242 |
private class ChatTab { |
236 |
|
243 |
|
237 |
private CTabItem item; |
244 |
/*private*/ CTabItem item; |
238 |
|
245 |
|
239 |
private StyledText chatText; |
246 |
private StyledText chatText; |
240 |
|
247 |
|
|
|
248 |
private MessageRenderer messageRenderer = null; |
249 |
|
241 |
private Text inputText; |
250 |
private Text inputText; |
242 |
|
251 |
|
243 |
private IChatMessageSender icms; |
252 |
private IChatMessageSender icms; |
Lines 261-303
Link Here
|
261 |
} |
270 |
} |
262 |
|
271 |
|
263 |
private void addListeners() { |
272 |
private void addListeners() { |
264 |
inputText.addKeyListener(new KeyAdapter() { |
273 |
if (remoteID != null) |
265 |
public void keyPressed(KeyEvent e) { |
274 |
inputText.addKeyListener(new KeyAdapter() { |
266 |
switch (e.keyCode) { |
275 |
public void keyPressed(KeyEvent e) { |
267 |
case SWT.CR : |
276 |
switch (e.keyCode) { |
268 |
case SWT.KEYPAD_CR : |
277 |
case SWT.CR : |
269 |
if (e.stateMask == 0) { |
278 |
case SWT.KEYPAD_CR : |
270 |
String text = inputText.getText(); |
279 |
if (e.stateMask == 0) { |
271 |
inputText.setText(""); //$NON-NLS-1$ |
280 |
String text = inputText.getText(); |
272 |
try { |
281 |
inputText.setText(""); //$NON-NLS-1$ |
273 |
if (!text.equals("")) { //$NON-NLS-1$ |
282 |
try { |
274 |
icms.sendChatMessage(remoteID, text); |
283 |
if (!text.equals("")) { //$NON-NLS-1$ |
|
|
284 |
icms.sendChatMessage(remoteID, text); |
285 |
} |
286 |
append(localID, text); |
287 |
} catch (ECFException ex) { |
288 |
setContentDescription(Messages.MessagesView_CouldNotSendMessage); |
275 |
} |
289 |
} |
276 |
append(localID, text); |
290 |
e.doit = false; |
277 |
} catch (ECFException ex) { |
291 |
sendTyping = false; |
278 |
setContentDescription(Messages.MessagesView_CouldNotSendMessage); |
|
|
279 |
} |
292 |
} |
280 |
e.doit = false; |
293 |
break; |
281 |
sendTyping = false; |
294 |
} |
282 |
} |
|
|
283 |
break; |
284 |
} |
295 |
} |
285 |
} |
296 |
}); |
286 |
}); |
|
|
287 |
|
297 |
|
288 |
inputText.addModifyListener(new ModifyListener() { |
298 |
if (remoteID != null) |
289 |
public void modifyText(ModifyEvent e) { |
299 |
inputText.addModifyListener(new ModifyListener() { |
290 |
if (!sendTyping && itms != null) { |
300 |
public void modifyText(ModifyEvent e) { |
291 |
sendTyping = true; |
301 |
if (!sendTyping && itms != null) { |
292 |
try { |
302 |
sendTyping = true; |
293 |
itms.sendTypingMessage(remoteID, true, null); |
303 |
try { |
294 |
} catch (ECFException ex) { |
304 |
itms.sendTypingMessage(remoteID, true, null); |
295 |
// ignored since this is not really that important |
305 |
} catch (ECFException ex) { |
296 |
return; |
306 |
// ignored since this is not really that important |
|
|
307 |
return; |
308 |
} |
297 |
} |
309 |
} |
298 |
} |
310 |
} |
299 |
} |
311 |
}); |
300 |
}); |
|
|
301 |
|
312 |
|
302 |
ScrollBar vscrollBar = chatText.getVerticalBar(); |
313 |
ScrollBar vscrollBar = chatText.getVerticalBar(); |
303 |
if (vscrollBar != null) { |
314 |
if (vscrollBar != null) { |
Lines 334-353
Link Here
|
334 |
private void append(ID fromID, String body) { |
345 |
private void append(ID fromID, String body) { |
335 |
boolean scrollToEnd = shouldScrollToEnd(chatText); |
346 |
boolean scrollToEnd = shouldScrollToEnd(chatText); |
336 |
|
347 |
|
337 |
if (!isFirstMessage) { |
348 |
//if (!isFirstMessage) { |
338 |
chatText.append(Text.DELIMITER); |
349 |
// chatText.append(Text.DELIMITER); |
339 |
} |
350 |
//} |
340 |
int length = chatText.getCharCount(); |
351 |
//int length = chatText.getCharCount(); |
341 |
String name = getUserName(fromID); |
352 |
String name = getUserName(fromID); |
342 |
if (fromID.equals(remoteID)) { |
353 |
String local = getUserName(localID); |
343 |
if (showTimestamps) { |
354 |
|
344 |
chatText.append(FORMATTER.format(new Date(System.currentTimeMillis())) + ' '); |
355 |
String output = messageRenderer.render(body, (fromID!=null)? name:null, local); |
345 |
chatText.setStyleRange(new StyleRange(length, 13, redColor, null)); |
356 |
StyleRange[] ranges = messageRenderer.getStyleRanges(); |
346 |
length = chatText.getCharCount(); |
357 |
|
347 |
} |
358 |
if (fromID == remoteID || fromID.equals(remoteID)) { |
348 |
chatText.append(name + ": " + body); //$NON-NLS-1$ |
359 |
// if (showTimestamps) { |
349 |
chatText.setStyleRange(new StyleRange(length, name.length() + 1, redColor, null, SWT.BOLD)); |
360 |
// //chatText.append(FORMATTER.format(new Date(System.currentTimeMillis())) + ' '); |
350 |
setContentDescription(""); //$NON-NLS-1$ |
361 |
// //chatText.setStyleRange(new StyleRange(length, 13, redColor, null)); |
|
|
362 |
// String text = FORMATTER.format(new Date(System.currentTimeMillis())) + ' '; |
363 |
// chatText.append(text); |
364 |
// chatText.setStyleRange(new StyleRange(length, text.length(), redColor, null)); |
365 |
// length = chatText.getCharCount(); |
366 |
// } |
367 |
// if (remoteID != null) { |
368 |
// chatText.append(name + ": "); //$NON-NLS-1$ |
369 |
// //chatText.append(body); |
370 |
// { |
371 |
// int posStyleRange = chatLink.scan(body); |
372 |
// chatText.append(body); |
373 |
// chatLink.setStyleRange(posStyleRange); |
374 |
// } |
375 |
// chatText.setStyleRange(new StyleRange(length, name.length() + 1, redColor, null, SWT.BOLD)); |
376 |
// } else { |
377 |
// //chatText.append(body); |
378 |
// { |
379 |
// int posStyleRange = chatLink.scan(body); |
380 |
// chatText.append(body); |
381 |
// chatLink.setStyleRange(posStyleRange); |
382 |
// } |
383 |
// chatText.setStyleRange(new StyleRange(length, 0, redColor, null, SWT.BOLD)); |
384 |
// } |
385 |
// setContentDescription(""); //$NON-NLS-1$ |
351 |
if (isFirstMessage) { |
386 |
if (isFirstMessage) { |
352 |
final MessageNotificationPopup popup = new MessageNotificationPopup(getSite().getWorkbenchWindow(), tabFolder.getShell(), remoteID); |
387 |
final MessageNotificationPopup popup = new MessageNotificationPopup(getSite().getWorkbenchWindow(), tabFolder.getShell(), remoteID); |
353 |
popup.setContent(name, body); |
388 |
popup.setContent(name, body); |
Lines 364-378
Link Here
|
364 |
}.schedule(5000); |
399 |
}.schedule(5000); |
365 |
} |
400 |
} |
366 |
} else { |
401 |
} else { |
367 |
if (showTimestamps) { |
402 |
// if (showTimestamps) { |
368 |
chatText.append(FORMATTER.format(new Date(System.currentTimeMillis())) + ' '); |
403 |
// //chatText.append(FORMATTER.format(new Date(System.currentTimeMillis())) + ' '); |
369 |
chatText.setStyleRange(new StyleRange(length, 13, blueColor, null)); |
404 |
// //chatText.setStyleRange(new StyleRange(length, 13, blueColor, null)); |
370 |
length = chatText.getCharCount(); |
405 |
// String text = FORMATTER.format(new Date(System.currentTimeMillis())) + ' '; |
371 |
} |
406 |
// chatText.append(text); |
372 |
chatText.append(name + ": " + body); //$NON-NLS-1$ |
407 |
// chatText.setStyleRange(new StyleRange(length, text.length(), blueColor, null)); |
373 |
chatText.setStyleRange(new StyleRange(length, name.length() + 1, blueColor, null, SWT.BOLD)); |
408 |
// length = chatText.getCharCount(); |
|
|
409 |
// } |
410 |
// chatText.append(name + ": "); //$NON-NLS-1$ |
411 |
// //chatText.append(body); |
412 |
// { |
413 |
// int posStyleRange = chatLink.scan(body); |
414 |
// chatText.append(body); |
415 |
// chatLink.setStyleRange(posStyleRange); |
416 |
// } |
417 |
// chatText.setStyleRange(new StyleRange(length, name.length() + 1, blueColor, null, SWT.BOLD)); |
374 |
} |
418 |
} |
375 |
isFirstMessage = false; |
419 |
isFirstMessage = false; |
|
|
420 |
|
421 |
if (output == null) { |
422 |
return; |
423 |
} |
424 |
|
425 |
int startRange = chatText.getText().length(); |
426 |
|
427 |
if (!body.endsWith("\n")) { |
428 |
output += "\n"; //$NON-NLS-1$ |
429 |
} |
430 |
|
431 |
chatText.append(output); |
432 |
|
433 |
if (ranges != null) { |
434 |
|
435 |
// set all ranges to start as message line starts |
436 |
for (int i = 0; i < ranges.length; i++) { |
437 |
ranges[i].start += startRange; |
438 |
} |
439 |
chatText.replaceStyleRanges(startRange, output.length(), ranges); |
440 |
} |
441 |
|
376 |
if (scrollToEnd) |
442 |
if (scrollToEnd) |
377 |
chatText.invokeAction(ST.TEXT_END); |
443 |
chatText.invokeAction(ST.TEXT_END); |
378 |
boldTabTitle(!scrollToEnd); |
444 |
boldTabTitle(!scrollToEnd); |
Lines 404-416
Link Here
|
404 |
Composite parent = new Composite(tabFolder, SWT.NONE); |
470 |
Composite parent = new Composite(tabFolder, SWT.NONE); |
405 |
parent.setLayout(new FillLayout()); |
471 |
parent.setLayout(new FillLayout()); |
406 |
|
472 |
|
407 |
SashForm sash = new SashForm(parent, SWT.VERTICAL); |
473 |
if (remoteID != null) { |
408 |
|
474 |
//SashForm sash = new SashForm(parent, SWT.VERTICAL); |
409 |
chatText = createStyledTextWidget(sash); |
475 |
Composite composite = new Composite(parent, SWT.NONE); |
|
|
476 |
GridLayout layout = new GridLayout(); |
477 |
layout.marginWidth = 0; |
478 |
layout.marginHeight = 0; |
479 |
layout.marginHeight = 0; |
480 |
layout.verticalSpacing = 3; |
481 |
layout.horizontalSpacing = 3; |
482 |
composite.setLayout(layout); |
483 |
|
484 |
chatText = createStyledTextWidget(/*sash*/composite); |
485 |
chatText.setLayoutData(new GridData(GridData.FILL_BOTH)); |
486 |
|
487 |
inputText = new Text(/*sash*/composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.WRAP); |
488 |
GridData gd = new GridData(GridData.FILL_HORIZONTAL); |
489 |
GC gc = new GC(inputText); |
490 |
gc.setFont(JFaceResources.getDialogFont()); |
491 |
FontMetrics fontMetrics = gc.getFontMetrics(); |
492 |
gc.dispose(); |
493 |
gd.heightHint = fontMetrics.getHeight() * 2; |
494 |
inputText.setLayoutData(gd); |
410 |
|
495 |
|
411 |
inputText = new Text(sash, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); |
496 |
//sash.setWeights(WEIGHTS); |
|
|
497 |
} else { |
498 |
chatText = createStyledTextWidget(parent); |
499 |
} |
412 |
|
500 |
|
413 |
sash.setWeights(WEIGHTS); |
501 |
messageRenderer = new MessageRenderer(); |
414 |
|
502 |
|
415 |
Menu menu = new Menu(chatText); |
503 |
Menu menu = new Menu(chatText); |
416 |
MenuItem mi = new MenuItem(menu, SWT.PUSH); |
504 |
MenuItem mi = new MenuItem(menu, SWT.PUSH); |