View | Details | Raw Unified | Return to bug 256696 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ecf/provider/xmpp/XMPPContainer.java (+11 lines)
Lines 41-46 Link Here
41
import org.eclipse.ecf.internal.provider.xmpp.events.MessageEvent;
41
import org.eclipse.ecf.internal.provider.xmpp.events.MessageEvent;
42
import org.eclipse.ecf.internal.provider.xmpp.events.PresenceEvent;
42
import org.eclipse.ecf.internal.provider.xmpp.events.PresenceEvent;
43
import org.eclipse.ecf.internal.provider.xmpp.filetransfer.XMPPOutgoingFileTransferHelper;
43
import org.eclipse.ecf.internal.provider.xmpp.filetransfer.XMPPOutgoingFileTransferHelper;
44
import org.eclipse.ecf.internal.provider.xmpp.search.XMPPSearchManager;
44
import org.eclipse.ecf.internal.provider.xmpp.smack.ECFConnection;
45
import org.eclipse.ecf.internal.provider.xmpp.smack.ECFConnection;
45
import org.eclipse.ecf.internal.provider.xmpp.smack.ECFConnectionObjectPacketEvent;
46
import org.eclipse.ecf.internal.provider.xmpp.smack.ECFConnectionObjectPacketEvent;
46
import org.eclipse.ecf.internal.provider.xmpp.smack.ECFConnectionPacketEvent;
47
import org.eclipse.ecf.internal.provider.xmpp.smack.ECFConnectionPacketEvent;
Lines 50-55 Link Here
50
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
51
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
51
import org.eclipse.ecf.presence.im.IChatManager;
52
import org.eclipse.ecf.presence.im.IChatManager;
52
import org.eclipse.ecf.presence.roster.IRosterManager;
53
import org.eclipse.ecf.presence.roster.IRosterManager;
54
import org.eclipse.ecf.presence.search.IUserSearchManager;
53
import org.eclipse.ecf.presence.service.IPresenceService;
55
import org.eclipse.ecf.presence.service.IPresenceService;
54
import org.eclipse.ecf.provider.comm.AsynchEvent;
56
import org.eclipse.ecf.provider.comm.AsynchEvent;
55
import org.eclipse.ecf.provider.comm.ConnectionCreateException;
57
import org.eclipse.ecf.provider.comm.ConnectionCreateException;
Lines 104-109 Link Here
104
	protected XMPPOutgoingFileTransferHelper outgoingFileTransferContainerAdapter = null;
106
	protected XMPPOutgoingFileTransferHelper outgoingFileTransferContainerAdapter = null;
105
107
106
	protected XMPPContainerPresenceHelper presenceHelper = null;
108
	protected XMPPContainerPresenceHelper presenceHelper = null;
109
	
110
	protected XMPPSearchManager searchManager = null;
107
111
108
	protected ID presenceHelperID = null;
112
	protected ID presenceHelperID = null;
109
113
Lines 112-117 Link Here
112
		this.keepAlive = keepAlive;
116
		this.keepAlive = keepAlive;
113
		accountManager = new XMPPContainerAccountManager();
117
		accountManager = new XMPPContainerAccountManager();
114
		chatRoomManager = new XMPPChatRoomManager(getID());
118
		chatRoomManager = new XMPPChatRoomManager(getID());
119
		searchManager = new XMPPSearchManager();
115
		this.presenceHelperID = IDFactory.getDefault().createStringID(CONTAINER_HELPER_ID);
120
		this.presenceHelperID = IDFactory.getDefault().createStringID(CONTAINER_HELPER_ID);
116
		presenceHelper = new XMPPContainerPresenceHelper(this);
121
		presenceHelper = new XMPPContainerPresenceHelper(this);
117
		outgoingFileTransferContainerAdapter = new XMPPOutgoingFileTransferHelper(this);
122
		outgoingFileTransferContainerAdapter = new XMPPOutgoingFileTransferHelper(this);
Lines 132-137 Link Here
132
	public IRosterManager getRosterManager() {
137
	public IRosterManager getRosterManager() {
133
		return presenceHelper.getRosterManager();
138
		return presenceHelper.getRosterManager();
134
	}
139
	}
140
	
141
	public IUserSearchManager getUserSearchManager() {
142
		return searchManager;
143
	}
135
144
136
	public IAccountManager getAccountManager() {
145
	public IAccountManager getAccountManager() {
137
		return accountManager;
146
		return accountManager;
Lines 238-243 Link Here
238
			final ECFConnection conn = getECFConnection();
247
			final ECFConnection conn = getECFConnection();
239
			accountManager.setConnection(conn.getXMPPConnection());
248
			accountManager.setConnection(conn.getXMPPConnection());
240
			chatRoomManager.setConnection(getConnectNamespace(), originalTarget, conn);
249
			chatRoomManager.setConnection(getConnectNamespace(), originalTarget, conn);
250
			searchManager.setConnection(getConnectNamespace(), originalTarget,conn);
251
			searchManager.setEnabled(!isGoogle(originalTarget));
241
			presenceHelper.setUser(new User(originalTarget));
252
			presenceHelper.setUser(new User(originalTarget));
242
			outgoingFileTransferContainerAdapter.setConnection(conn.getXMPPConnection());
253
			outgoingFileTransferContainerAdapter.setConnection(conn.getXMPPConnection());
243
			return originalTarget;
254
			return originalTarget;
(-)src/org/eclipse/ecf/internal/provider/xmpp/Messages.java (+1 lines)
Lines 35-40 Link Here
35
	public static String XMPPContainer_UNEXPECTED_EVENT;
35
	public static String XMPPContainer_UNEXPECTED_EVENT;
36
	public static String XMPPContainer_UNEXPECTED_XMPP_MESSAGE;
36
	public static String XMPPContainer_UNEXPECTED_XMPP_MESSAGE;
37
	public static String XMPPContainer_UNRECOGONIZED_CONTAINER_MESSAGE;
37
	public static String XMPPContainer_UNRECOGONIZED_CONTAINER_MESSAGE;
38
	public static String XMPPContainer_UNRECOGONIZED_SEARCH_SERVICE;
38
	public static String XMPPFileID_EXCEPTION_FILE_IDS_NOT_URLS;
39
	public static String XMPPFileID_EXCEPTION_FILE_IDS_NOT_URLS;
39
	public static String XMPPFileNamespace_EXCEPTION_FILEID_FILENAME_NOT_NULL;
40
	public static String XMPPFileNamespace_EXCEPTION_FILEID_FILENAME_NOT_NULL;
40
	public static String XMPPFileNamespace_EXCEPTION_FILEID_TARGETID_NOT_NULL;
41
	public static String XMPPFileNamespace_EXCEPTION_FILEID_TARGETID_NOT_NULL;
(-)src/org/eclipse/ecf/internal/provider/xmpp/XMPPContainerPresenceHelper.java (-160 / +50 lines)
Lines 437-443 Link Here
437
					final IRosterEntry entry = createRosterEntry(newID, item);
437
					final IRosterEntry entry = createRosterEntry(newID, item);
438
					if (itemType == RosterPacket.ItemType.NONE
438
					if (itemType == RosterPacket.ItemType.NONE
439
							|| itemType == RosterPacket.ItemType.REMOVE) {
439
							|| itemType == RosterPacket.ItemType.REMOVE) {
440
						removeFromRoster(createIDFromName(item.getUser()));
440
						removeItemFromRoster(roster.getItems(),
441
								createIDFromName(item.getUser()));
441
						remove = true;
442
						remove = true;
442
					} else {
443
					} else {
443
						remove = false;
444
						remove = false;
Lines 459-482 Link Here
459
			rosterManager.notifyRosterAdd(entry);
460
			rosterManager.notifyRosterAdd(entry);
460
	}
461
	}
461
462
462
	private void removeFromRoster(XMPPID itemIDToRemove) {
463
	private void removeItemFromRoster(Collection rosterItems,
464
			XMPPID itemIDToRemove) {
463
		boolean removed = false;
465
		boolean removed = false;
464
		Collection rosterItems = roster.getItems();
465
		synchronized (rosterItems) {
466
		synchronized (rosterItems) {
466
			for (final Iterator i = rosterItems.iterator(); i.hasNext();) {
467
			for (final Iterator i = rosterItems.iterator(); i.hasNext();) {
467
				final IRosterItem item = (IRosterItem) i.next();
468
				final IRosterItem item = (IRosterItem) i.next();
468
				if (item instanceof org.eclipse.ecf.presence.roster.RosterGroup) {
469
				if (item instanceof org.eclipse.ecf.presence.roster.RosterGroup) {
469
					final org.eclipse.ecf.presence.roster.RosterGroup group = (org.eclipse.ecf.presence.roster.RosterGroup) item;
470
					final org.eclipse.ecf.presence.roster.RosterGroup group = (org.eclipse.ecf.presence.roster.RosterGroup) item;
470
					boolean r = removeItemFromRosterGroup(group, itemIDToRemove);
471
					removed = removeItemFromRosterGroup(group, itemIDToRemove);
471
					if (r)
472
						removed = true;
473
					// If group is empty, remove it too
472
					// If group is empty, remove it too
474
					if (group.getEntries().size() == 0)
473
					if (group.getEntries().size() == 0)
475
						i.remove();
474
						i.remove();
476
				} else if (item instanceof org.eclipse.ecf.presence.roster.RosterEntry) {
475
				} else if (item instanceof org.eclipse.ecf.presence.roster.RosterEntry) {
477
					org.eclipse.ecf.presence.roster.RosterEntry entry = (org.eclipse.ecf.presence.roster.RosterEntry) item;
476
					if (((org.eclipse.ecf.presence.roster.RosterEntry) item)
478
					XMPPID entryID = (XMPPID) entry.getUser().getID();
477
							.getUser().getID().equals(itemIDToRemove)) {
479
					if (entryID.equals(itemIDToRemove)) {
480
						i.remove();
478
						i.remove();
481
						removed = true;
479
						removed = true;
482
					}
480
					}
Lines 496-503 Link Here
496
			for (final Iterator i = group.getEntries().iterator(); i.hasNext();) {
494
			for (final Iterator i = group.getEntries().iterator(); i.hasNext();) {
497
				final org.eclipse.ecf.presence.roster.RosterEntry entry = (org.eclipse.ecf.presence.roster.RosterEntry) i
495
				final org.eclipse.ecf.presence.roster.RosterEntry entry = (org.eclipse.ecf.presence.roster.RosterEntry) i
498
						.next();
496
						.next();
499
				XMPPID entryID = (XMPPID) entry.getUser().getID();
497
				if (entry.getUser().getID().equals(itemIDToRemove)) {
500
				if (entryID.equals(itemIDToRemove)) {
501
					i.remove();
498
					i.remove();
502
					return true;
499
					return true;
503
				}
500
				}
Lines 570-769 Link Here
570
567
571
	private void updatePresence(XMPPID fromID, IPresence newPresence) {
568
	private void updatePresence(XMPPID fromID, IPresence newPresence) {
572
		final Collection rosterItems = roster.getItems();
569
		final Collection rosterItems = roster.getItems();
573
		AdditionalClient newEntry = null;
570
		List newEntrys = new ArrayList();
574
		synchronized (rosterItems) {
571
		synchronized (rosterItems) {
575
			for (final Iterator i = roster.getItems().iterator(); i.hasNext();) {
572
			for (final Iterator i = roster.getItems().iterator(); i.hasNext();) {
576
				final IRosterItem item = (IRosterItem) i.next();
573
				final IRosterItem item = (IRosterItem) i.next();
577
				if (item instanceof IRosterGroup) {
574
				if (item instanceof IRosterGroup) {
578
					AdditionalClient newClient = updatePresenceInGroup(
575
					AdditionalClientRosterEntry[] es = updatePresenceInGroup(
579
							(IRosterGroup) item, fromID, newPresence);
576
							(IRosterGroup) item, fromID, newPresence);
580
					if (newClient != null)
577
					for (int j = 0; j < es.length; j++) {
581
						newEntry = newClient;
578
						newEntrys.add(es[j]);
579
					}
582
				} else if (item instanceof org.eclipse.ecf.presence.roster.RosterEntry) {
580
				} else if (item instanceof org.eclipse.ecf.presence.roster.RosterEntry) {
583
					AdditionalClient newClient = updatePresenceForMatchingEntry(
581
					AdditionalClientRosterEntry entry = updatePresenceForMatchingEntry(
584
							(org.eclipse.ecf.presence.roster.RosterEntry) item,
582
							(org.eclipse.ecf.presence.roster.RosterEntry) item,
585
							fromID, newPresence);
583
							fromID, newPresence);
586
					if (newClient != null)
584
					if (entry != null)
587
						newEntry = newClient;
585
						newEntrys.add(entry);
588
				}
586
				}
589
			}
587
			}
590
		}
588
		}
591
589
592
		if (newEntry != null) {
590
		AdditionalClientRosterEntry[] entrys = (AdditionalClientRosterEntry[]) newEntrys
593
			if (newEntry.add) {
591
				.toArray(new AdditionalClientRosterEntry[] {});
594
				if (!rosterContainsEntry(fromID)) {
592
		IRosterEntry entry = null;
595
					IRosterEntry entry = new org.eclipse.ecf.presence.roster.RosterEntry(
593
		if (entrys.length > 0) {
596
							newEntry.parent, newEntry.user, newEntry.presence);
594
			for (int i = 0; i < entrys.length; i++) {
597
					rosterManager.notifyRosterUpdate(roster);
595
				entry = new org.eclipse.ecf.presence.roster.RosterEntry(entrys[i].parent,entrys[i].user,entrys[i].presence);
598
					fireSetRosterEntry(false, entry);
596
				//roster.addItem(entry);
599
				}
600
			} else {
601
				// remove from roster as it's another client
602
				removeFromRoster(fromID);
603
			}
597
			}
598
			rosterManager.notifyRosterUpdate(roster);
599
			fireSetRosterEntry(false, entry);
604
		}
600
		}
605
	}
601
	}
606
602
607
	class AdditionalClient {
603
	class AdditionalClientRosterEntry {
608
604
		
609
		IRosterItem parent;
605
		IRosterItem parent;
610
		IUser user;
606
		IUser user;
611
		IPresence presence;
607
		IPresence presence;
612
		boolean add;
608
		
613
609
		public AdditionalClientRosterEntry(IRosterItem parent, IUser user, IPresence presence) {
614
		public AdditionalClient(IRosterItem parent, IUser user,
615
				IPresence presence, boolean add) {
616
			this.parent = parent;
610
			this.parent = parent;
617
			this.user = user;
611
			this.user = user;
618
			this.presence = presence;
612
			this.presence = presence;
619
			this.add = add;
620
		}
621
622
		public AdditionalClient(IUser user) {
623
			this.user = user;
624
			this.add = false;
625
		}
626
	}
627
628
	private int countClientsInRosterGroup(
629
			org.eclipse.ecf.presence.roster.RosterGroup group, XMPPID oldID) {
630
		Collection groupItems = group.getEntries();
631
		int count = 0;
632
		for (final Iterator i = groupItems.iterator(); i.hasNext();) {
633
			final IRosterItem item = (IRosterItem) i.next();
634
			if (item instanceof org.eclipse.ecf.presence.roster.RosterEntry) {
635
				org.eclipse.ecf.presence.roster.RosterEntry entry = (org.eclipse.ecf.presence.roster.RosterEntry) item;
636
				XMPPID entryID = (XMPPID) entry.getUser().getID();
637
				if (entryID.getUsernameAtHost().equals(
638
						oldID.getUsernameAtHost()))
639
					count++;
640
			}
641
		}
613
		}
642
		return count;
643
	}
614
	}
644
615
	
645
	private int countClientsInRoster(XMPPID oldID) {
616
	
646
		Collection rosterItems = roster.getItems();
617
	private AdditionalClientRosterEntry updatePresenceForMatchingEntry(
647
		int count = 0;
648
		synchronized (rosterItems) {
649
			for (final Iterator i = rosterItems.iterator(); i.hasNext();) {
650
				final IRosterItem item = (IRosterItem) i.next();
651
				if (item instanceof org.eclipse.ecf.presence.roster.RosterGroup) {
652
					final org.eclipse.ecf.presence.roster.RosterGroup group = (org.eclipse.ecf.presence.roster.RosterGroup) item;
653
					count += countClientsInRosterGroup(group, oldID);
654
				} else if (item instanceof org.eclipse.ecf.presence.roster.RosterEntry) {
655
					org.eclipse.ecf.presence.roster.RosterEntry entry = (org.eclipse.ecf.presence.roster.RosterEntry) item;
656
					XMPPID entryID = (XMPPID) entry.getUser().getID();
657
					if (entryID.getUsernameAtHost().equals(
658
							oldID.getUsernameAtHost())) {
659
						count++;
660
					}
661
				}
662
			}
663
		}
664
		return count;
665
	}
666
667
	private boolean rosterGroupContainsEntry(
668
			org.eclipse.ecf.presence.roster.RosterGroup group, XMPPID oldID) {
669
		Collection groupItems = group.getEntries();
670
		for (final Iterator i = groupItems.iterator(); i.hasNext();) {
671
			final IRosterItem item = (IRosterItem) i.next();
672
			if (item instanceof org.eclipse.ecf.presence.roster.RosterEntry) {
673
				org.eclipse.ecf.presence.roster.RosterEntry entry = (org.eclipse.ecf.presence.roster.RosterEntry) item;
674
				XMPPID entryID = (XMPPID) entry.getUser().getID();
675
				if (entryID.equals(oldID))
676
					return true;
677
			}
678
		}
679
		return false;
680
	}
681
682
	private boolean rosterContainsEntry(XMPPID oldID) {
683
		Collection rosterItems = roster.getItems();
684
		synchronized (rosterItems) {
685
			for (final Iterator i = rosterItems.iterator(); i.hasNext();) {
686
				final IRosterItem item = (IRosterItem) i.next();
687
				if (item instanceof org.eclipse.ecf.presence.roster.RosterGroup) {
688
					final org.eclipse.ecf.presence.roster.RosterGroup group = (org.eclipse.ecf.presence.roster.RosterGroup) item;
689
					if (rosterGroupContainsEntry(group, oldID))
690
						return true;
691
				} else if (item instanceof org.eclipse.ecf.presence.roster.RosterEntry) {
692
					org.eclipse.ecf.presence.roster.RosterEntry entry = (org.eclipse.ecf.presence.roster.RosterEntry) item;
693
					XMPPID entryID = (XMPPID) entry.getUser().getID();
694
					if (entryID.equals(oldID))
695
						return true;
696
				}
697
			}
698
		}
699
		return false;
700
	}
701
702
	private AdditionalClient removeEntryFromRoster(XMPPID oldID,
703
			org.eclipse.ecf.presence.roster.RosterEntry entry,
704
			IPresence newPresence, IUser user) {
705
		if (countClientsInRoster(oldID) > 1) {
706
			// remove this client from roster
707
			return new AdditionalClient(user);
708
		} else {
709
			// Last one, so we set resource to null and set presence to
710
			// unavailable
711
			oldID.setResourceName(null);
712
			entry.setPresence(newPresence);
713
			rosterManager.notifyRosterUpdate(entry);
714
			return null;
715
		}
716
	}
717
718
	private AdditionalClient updatePresenceForMatchingEntry(
719
			org.eclipse.ecf.presence.roster.RosterEntry entry, XMPPID fromID,
618
			org.eclipse.ecf.presence.roster.RosterEntry entry, XMPPID fromID,
720
			IPresence newPresence) {
619
			IPresence newPresence) {
721
		final IUser user = entry.getUser();
620
		final IUser user = entry.getUser();
722
		XMPPID oldID = (XMPPID) user.getID();
621
		XMPPID oldID = (XMPPID) user.getID();
723
		if (newPresence.getType().equals(IPresence.Type.UNAVAILABLE)) {
622
		// If the username/host part matches that means we either have to update
724
			// This is an unavailable presence change
623
		// the resource, or create a new client
725
			if (oldID.equals(fromID))
624
		if (oldID.equals(fromID)) {
726
				return removeEntryFromRoster(oldID, entry, newPresence, user);
625
			// set the new presence state
727
		} else {
626
			entry.setPresence(newPresence);
728
			// This is some other presence change
627
			// and notify with roster update
729
			// If the username/host part matches that means we either have to
628
			rosterManager.notifyRosterUpdate(entry);
730
			// update
629
		} else if (oldID.getUsernameAtHost().equals(fromID.getUsernameAtHost())) {
731
			// the resource, or create a new client
630
			if (oldID.getResourceName() == null) {
732
			if (oldID.equals(fromID)) {
631
				oldID.setResourceName(fromID.getResourceName());
733
				// set the new presence state
632
				// set the new presence state
734
				entry.setPresence(newPresence);
633
				entry.setPresence(newPresence);
735
				// and notify with roster update
634
				// and notify with roster update
736
				rosterManager.notifyRosterUpdate(entry);
635
				rosterManager.notifyRosterUpdate(entry);
737
			} else if (oldID.getUsernameAtHost().equals(
636
			} else if (fromID.getResourceName() != null && !newPresence.getType().equals(IPresence.Type.UNAVAILABLE)) {
738
					fromID.getUsernameAtHost())) {
637
				return new AdditionalClientRosterEntry(entry.getParent(), new User(fromID, user.getName()), newPresence);
739
				if (oldID.getResourceName() == null) {
740
					oldID.setResourceName(fromID.getResourceName());
741
					// set the new presence state
742
					entry.setPresence(newPresence);
743
					// and notify with roster update
744
					rosterManager.notifyRosterUpdate(entry);
745
				} else
746
					return new AdditionalClient(entry.getParent(), new User(
747
							fromID, user.getName()), newPresence, true);
748
			}
638
			}
749
		}
639
		}
750
		return null;
640
		return null;
751
	}
641
	}
752
642
753
	private AdditionalClient updatePresenceInGroup(IRosterGroup group,
643
	private AdditionalClientRosterEntry[] updatePresenceInGroup(IRosterGroup group,
754
			XMPPID fromID, IPresence newPresence) {
644
			XMPPID fromID, IPresence newPresence) {
645
		List results = new ArrayList();
755
		final Collection groupEntries = group.getEntries();
646
		final Collection groupEntries = group.getEntries();
756
		AdditionalClient newEntry = null;
757
		synchronized (groupEntries) {
647
		synchronized (groupEntries) {
758
			for (final Iterator i = group.getEntries().iterator(); i.hasNext();) {
648
			for (final Iterator i = group.getEntries().iterator(); i.hasNext();) {
759
				AdditionalClient newClient = updatePresenceForMatchingEntry(
649
				AdditionalClientRosterEntry newEntry = updatePresenceForMatchingEntry(
760
						(org.eclipse.ecf.presence.roster.RosterEntry) i.next(),
650
						(org.eclipse.ecf.presence.roster.RosterEntry) i.next(),
761
						fromID, newPresence);
651
						fromID, newPresence);
762
				if (newClient != null)
652
				if (newEntry != null)
763
					newEntry = newClient;
653
					results.add(newEntry);
764
			}
654
			}
765
		}
655
		}
766
		return newEntry;
656
		return (AdditionalClientRosterEntry[]) results.toArray(new AdditionalClientRosterEntry[] {});
767
	}
657
	}
768
658
769
	protected void handleRoster(Roster roster) {
659
	protected void handleRoster(Roster roster) {
(-)src/org/eclipse/ecf/internal/provider/xmpp/messages.properties (-1 / +2 lines)
Lines 22-28 Link Here
22
XMPPContainer_EXCEPTION_INVALID_RESPONSE_FROM_SERVER=invalid connect response from server
22
XMPPContainer_EXCEPTION_INVALID_RESPONSE_FROM_SERVER=invalid connect response from server
23
XMPPIncomingFileTransfer_Status_Transfer_Exception=Transfer Exception
23
XMPPIncomingFileTransfer_Status_Transfer_Exception=Transfer Exception
24
XMPPContainer_EXCEPTION_ADDING_SHARED_OBJECT=Exception adding shared object %1
24
XMPPContainer_EXCEPTION_ADDING_SHARED_OBJECT=Exception adding shared object %1
25
XMPPContainer_UNRECOGONIZED_CONTAINER_MESSAGE=got unrecognized container message...ignoring message 
25
XMPPContainer_UNRECOGONIZED_CONTAINER_MESSAGE=got unrecognized container message...ignoring message
26
XMPPContainer_UNRECOGONIZED_SEARCH_SERVICE=Search Service not available on the server 
26
XMPPContainer_UNEXPECTED_EVENT=processAsynch got unexpected event %1
27
XMPPContainer_UNEXPECTED_EVENT=processAsynch got unexpected event %1
27
XMPPContainer_EXCEPTION_HANDLING_ASYCH_EVENT=processAsynch exception processing event %1
28
XMPPContainer_EXCEPTION_HANDLING_ASYCH_EVENT=processAsynch exception processing event %1
28
XMPPFileID_EXCEPTION_FILE_IDS_NOT_URLS=XMPPFileIDs cannot be represented as URLs.
29
XMPPFileID_EXCEPTION_FILE_IDS_NOT_URLS=XMPPFileIDs cannot be represented as URLs.
(-)src/org/eclipse/ecf/internal/provider/xmpp/search/XMPPResultItem.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.internal.provider.xmpp.search;
11
12
import org.eclipse.ecf.core.user.IUser;
13
import org.eclipse.ecf.presence.search.IResult;
14
15
/**
16
 * Implement a specific result for XMPP
17
 *@since 3.0
18
 */
19
public class XMPPResultItem implements IResult {
20
21
	/** contain a IUser */
22
	protected IUser user;
23
24
	/**
25
	 * Create a XMPP result with a IUser
26
	 * @param user IUser
27
	 */
28
	public XMPPResultItem(IUser user) {
29
		this.user = user;
30
	}
31
32
	/*
33
	 * (non-Javadoc)
34
	 * @see org.eclipse.ecf.presence.search.IResult#getUser()
35
	 */
36
	public IUser getUser() {
37
		return user;
38
	}
39
40
	/**
41
	 * Verify if there is the same IUser. Compare using ID
42
	 */
43
	public boolean equals(Object o) {
44
		if(o instanceof XMPPResultItem)
45
			return ((XMPPResultItem) o).getUser().getID().toString().equals(user.getID().toString());
46
		else
47
			return false;
48
	}
49
50
	public int hashCode() {
51
		return (user.getID().toString() != null ? user.getID().toString()
52
				.hashCode() : 0);
53
	}
54
55
	public Object getAdapter(Class adapter) {
56
		// TODO Auto-generated method stub
57
		return null;
58
	}
59
60
}
(-)src/org/eclipse/ecf/internal/provider/xmpp/search/XMPPCriteria.java (+73 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.internal.provider.xmpp.search;
11
12
import java.util.ArrayList;
13
import java.util.Collections;
14
import java.util.Iterator;
15
import java.util.List;
16
17
import org.eclipse.ecf.presence.search.ICriteria;
18
import org.eclipse.ecf.presence.search.ICriterion;
19
20
/**
21
 * Implement a specific criteria control for XMPP
22
 *@since 3.0
23
 */
24
public class XMPPCriteria implements ICriteria {
25
26
	/** criteria list */
27
	protected List criteria;
28
	
29
	/**
30
	 * Create a criteria with a sync list
31
	 */
32
	public XMPPCriteria(){
33
		criteria = Collections.synchronizedList(new ArrayList());
34
	}
35
	
36
	/*
37
	 * (non-Javadoc)
38
	 * @see org.eclipse.ecf.presence.search.ICriteria#add(org.eclipse.ecf.presence.search.ICriterion)
39
	 */
40
	public void add(ICriterion criterion) {
41
		criteria.add(criterion);
42
	}
43
44
	/*
45
	 * (non-Javadoc)
46
	 * @see org.eclipse.ecf.presence.search.ICriteria#getCriterions()
47
	 */
48
	public List getCriterions() {
49
		return criteria;
50
	}
51
52
	/*
53
	 * (non-Javadoc)
54
	 * @see org.eclipse.ecf.presence.search.ICriteria#isEmpty()
55
	 */
56
	public boolean isEmpty() {
57
		return criteria.isEmpty();
58
	}
59
	
60
	public String toString() {
61
		StringBuffer sb = new StringBuffer("XMPPCriteria["); //$NON-NLS-1$
62
		Iterator it = criteria.iterator();
63
		while (it.hasNext()) {
64
			sb.append("[");//$NON-NLS-1$
65
			ICriterion criterion = (ICriterion) it.next();
66
			sb.append(criterion.toString());
67
			sb.append("];");//$NON-NLS-1$
68
		}
69
		sb.append("];");//$NON-NLS-1$
70
		return sb.toString();
71
	}
72
73
}
(-)src/org/eclipse/ecf/internal/provider/xmpp/search/XMPPSearch.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.internal.provider.xmpp.search;
11
12
import org.eclipse.ecf.presence.search.ICriteria;
13
import org.eclipse.ecf.presence.search.IResultList;
14
import org.eclipse.ecf.presence.search.ISearch;
15
import org.eclipse.ecf.presence.search.ResultList;
16
17
/**
18
 * Implement ISearch for XMPP
19
 *@since 3.0
20
 */
21
public class XMPPSearch implements ISearch {
22
23
	protected IResultList resultList;
24
	private ICriteria criteria;
25
26
	/*
27
	 * (non-Javadoc)
28
	 * @see org.eclipse.ecf.presence.search.ISearch#getResultList()
29
	 */
30
	public IResultList getResultList() {
31
		return resultList;
32
	}
33
34
	protected XMPPSearch(ICriteria criteria) {
35
		this.criteria = criteria;
36
	}
37
38
	public XMPPSearch(ResultList resultList) {
39
		this.resultList = resultList;
40
	}
41
42
	public ICriteria getCriteria() {
43
		return this.criteria;
44
	}
45
46
	public void setResultList(IResultList resultList) {
47
		this.resultList = resultList;
48
		
49
	}
50
	
51
52
}
(-)src/org/eclipse/ecf/internal/provider/xmpp/search/XMPPSelection.java (+39 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.internal.provider.xmpp.search;
11
12
import org.eclipse.ecf.presence.search.ICriterion;
13
import org.eclipse.ecf.presence.search.Restriction;
14
15
/**
16
 * Implement a specific Selection for XMPP
17
 * @since 3.0
18
 */
19
public class XMPPSelection extends Restriction {
20
21
	/*
22
	 * (non-Javadoc)
23
	 * @see org.eclipse.ecf.presence.search.ISelection#eq(java.lang.String, java.lang.String)
24
	 */
25
	public ICriterion eq(String field, String value) {
26
		//the operator is ignored for XMPP
27
		return new XMPPSimpleCriterion(field, value, "");
28
	}
29
	
30
	/*
31
	 * (non-Javadoc)
32
	 * @see org.eclipse.ecf.presence.search.ISelection#eq(java.lang.String, java.lang.String)
33
	 */
34
	public ICriterion eq(String field, String value, boolean ignoreCase) {
35
		//the operator is ignored for XMPP
36
		return new XMPPSimpleCriterion(field, value, "");
37
	}
38
	
39
}
(-)src/org/eclipse/ecf/internal/provider/xmpp/search/XMPPSearchManager.java (+270 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.internal.provider.xmpp.search;
11
12
import java.net.URISyntaxException;
13
import java.util.HashSet;
14
import java.util.Iterator;
15
import java.util.List;
16
import java.util.Set;
17
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.ecf.core.ContainerConnectException;
20
import org.eclipse.ecf.core.identity.ID;
21
import org.eclipse.ecf.core.identity.Namespace;
22
import org.eclipse.ecf.core.user.IUser;
23
import org.eclipse.ecf.core.user.User;
24
import org.eclipse.ecf.internal.provider.xmpp.Messages;
25
import org.eclipse.ecf.internal.provider.xmpp.smack.ECFConnection;
26
import org.eclipse.ecf.presence.search.AbstractUserSearchManager;
27
import org.eclipse.ecf.presence.search.ICriteria;
28
import org.eclipse.ecf.presence.search.ICriterion;
29
import org.eclipse.ecf.presence.search.IResultList;
30
import org.eclipse.ecf.presence.search.ISearch;
31
import org.eclipse.ecf.presence.search.IRestriction;
32
import org.eclipse.ecf.presence.search.IUserSearchListener;
33
import org.eclipse.ecf.presence.search.IUserSearchManager;
34
import org.eclipse.ecf.presence.search.ResultList;
35
import org.eclipse.ecf.presence.search.UserSearchException;
36
import org.eclipse.ecf.provider.xmpp.identity.XMPPID;
37
import org.jivesoftware.smack.XMPPException;
38
import org.jivesoftware.smackx.Form;
39
import org.jivesoftware.smackx.FormField;
40
import org.jivesoftware.smackx.ReportedData;
41
import org.jivesoftware.smackx.ReportedData.Row;
42
import org.jivesoftware.smackx.search.UserSearch;
43
44
/**
45
 * A specific implementation for XMPP provider. XEP-0055:
46
 * http://www.xmpp.org/extensions/xep-0055.html
47
 * 
48
 * @see IUserSearchManager
49
 * @since 3.0
50
 */
51
public class XMPPSearchManager extends AbstractUserSearchManager {
52
53
	/** Search service name on XMPP server */
54
	protected static final String SERVICE_SEARCH = "search.";
55
56
	/** Wrapper for XMPP connection */
57
	protected ECFConnection ecfConnection;
58
59
	protected Namespace connectNamespace;
60
61
	protected ID connectedID;
62
63
	protected Form form;
64
65
	protected UserSearch manager;
66
67
	protected boolean enabled;
68
69
	protected static final String FORM_TYPE = "FORM_TYPE";
70
71
	protected static final String NAME = "name";
72
73
	protected static final String JID = "jid";
74
75
	protected static final String SEARCH_ACTION = "search";
76
77
	public XMPPSearchManager() {
78
		manager = new UserSearch();
79
	}
80
	
81
	/**
82
	 * Create a specific {@link ICriteria} for XMPP
83
	 */
84
	public ICriteria createCriteria() {
85
		return new XMPPCriteria();
86
	}
87
88
	/**
89
	 * Create a specific {@link IRestriction} for XMPP
90
	 */
91
	public IRestriction createSelection() {
92
		return new XMPPSelection();
93
	}
94
95
	/**
96
	 * Specific implementation for XMPP
97
	 * 
98
	 * @see IUserSearchManager#search(ICriteria).
99
	 */
100
	public ISearch search(ICriteria criteria) throws UserSearchException {
101
102
		ResultList resultList = new ResultList();
103
		try {
104
			//initialize the form by chance it is null
105
			if (form == null)
106
				form = manager.getSearchForm(ecfConnection.getXMPPConnection(),
107
						SERVICE_SEARCH
108
								+ ecfConnection.getXMPPConnection()
109
										.getServiceName());
110
111
			/*
112
			 * For XMPP criterion is considered. The XMPP server will deal with
113
			 * the search.
114
			 */
115
			List criterions = criteria.getCriterions();
116
			// add the fields for the search dynamically
117
			// consider just the fields used on the search
118
			// fields checked by user
119
			
120
			String fields[] = getUserPropertiesFields();
121
			for (int i = 0; i < fields.length; i++) {
122
				Iterator criterionsIterator = criterions.iterator();
123
				//for each user properties field check if it
124
				//was added by user for the criteria
125
				//for each field, a search is performed, and 
126
				//the partial result is added to the result list
127
				while (criterionsIterator.hasNext()) {
128
					ICriterion criterion = (ICriterion) criterionsIterator.next();
129
					if(criterion.equals(fields[i])){
130
						Form answerForm = form.createAnswerForm();
131
						answerForm.setAnswer(fields[i], true);
132
						answerForm.setAnswer(SEARCH_ACTION, criterion.toExpression());
133
						ReportedData data = manager.sendSearchForm(ecfConnection
134
								.getXMPPConnection(), answerForm, SERVICE_SEARCH + ecfConnection.getXMPPConnection().getServiceName());
135
						// create a result list from ReportedData
136
						IResultList partialResultList = createResultList(data);
137
						resultList.addAll(partialResultList.geResults());
138
					}
139
				}
140
			}			
141
142
			return new XMPPSearch(resultList);
143
			
144
		} catch (final XMPPException e) {
145
			String message = null;
146
			if (e.getXMPPError() != null && e.getXMPPError().getCode() == 404) {
147
				message = Messages.XMPPContainer_UNRECOGONIZED_SEARCH_SERVICE;
148
			} else{
149
				message = e.getLocalizedMessage();
150
			}
151
			throw new UserSearchException(message, e, criteria);
152
		} catch (ContainerConnectException e) {
153
			throw new UserSearchException(e, criteria);
154
		}
155
156
	}
157
158
	/**
159
	 * Create a result list from ReportedData. Identify dynamically columns and
160
	 * rows and create users adding it to a {@link IResultList}
161
	 * 
162
	 * @param data ReportedData
163
	 * @return {@link IResultList} a list of users
164
	 * @throws  
165
	 */
166
	protected IResultList createResultList(ReportedData data) {
167
		ResultList result = new ResultList();
168
		Iterator rows = data.getRows();
169
		while (rows.hasNext()) {
170
			Row row = (Row) rows.next();
171
			Iterator jids = row.getValues(JID);
172
			Iterator names = row.getValues(NAME);
173
			String jid = null;
174
			String name = null;
175
			// XMPP server returns the same length for both
176
			while (jids.hasNext() && names.hasNext()) {
177
				try {
178
					jid = (String) jids.next();
179
					name = (String) names.next();					
180
					IUser user = new User(new XMPPID(connectNamespace, jid), name);
181
					result.add(new XMPPResultItem(user));
182
				} catch(URISyntaxException e){
183
					throw new RuntimeException(
184
							"cannot create connect id for client " + jid
185
									+ " , name = " + name, e);
186
				}
187
			}
188
		}
189
		return result;
190
	}
191
192
	/**
193
	 * Specific implementation for XMPP
194
	 * 
195
	 * @see IUserSearchManager#search(ICriteria).
196
	 */
197
	public void search(ICriteria criteria, IUserSearchListener listener) {
198
		this.criteria = criteria;
199
		addListener(listener);
200
	}
201
202
	/**
203
	 * These parameters must be not null
204
	 * 
205
	 * @param connectNamespace
206
	 * @param connectedID
207
	 * @param connection
208
	 */
209
	public void setConnection(Namespace connectNamespace, ID connectedID,
210
			ECFConnection connection) {
211
		Assert.isNotNull(connectNamespace);
212
		Assert.isNotNull(connectedID);
213
		Assert.isNotNull(connection);
214
		this.connectNamespace = connectNamespace;
215
		this.connectedID = connectedID;
216
		this.ecfConnection = connection;
217
	}
218
219
	/**
220
	 * Returns the user properties fields available on the XMPP server
221
	 * 
222
	 * @param form
223
	 * @return String[] fields for form
224
	 * @throws ContainerConnectException 
225
	 */
226
	public String[] getUserPropertiesFields() throws ContainerConnectException {
227
		try{
228
			if (form == null)
229
				form = manager.getSearchForm(ecfConnection.getXMPPConnection(),
230
						SERVICE_SEARCH + ecfConnection.getXMPPConnection().getServiceName());
231
	
232
			Set fields = new HashSet();
233
			Iterator userProperties = form.getFields();
234
			while (userProperties.hasNext()) {
235
				FormField field = (FormField) userProperties.next();
236
				String variable = field.getVariable();
237
				// ignore these fields
238
				if (!variable.equalsIgnoreCase(FORM_TYPE)
239
						&& !variable.equalsIgnoreCase(SEARCH_ACTION))
240
					fields.add(variable);
241
			}
242
			return (String[]) fields.toArray(new String[0]);
243
		} catch (final XMPPException e) {
244
			String message = null;
245
			if (e.getXMPPError() != null && e.getXMPPError().getCode() == 404) {
246
				message = Messages.XMPPContainer_UNRECOGONIZED_SEARCH_SERVICE;
247
			} else{
248
				message = e.getLocalizedMessage();
249
			}
250
			throw new ContainerConnectException(message, e);
251
		}
252
253
	}
254
	
255
	/**
256
	 * Notify that user search for XMPP is enabled
257
	 */
258
	public boolean isEnabled() {
259
		return this.enabled;
260
	}
261
	
262
	/**
263
	 * For gtalk it should be not enabled
264
	 * @param enabled
265
	 */
266
	public void setEnabled(boolean enabled) {
267
		this.enabled = enabled;
268
	}
269
270
}
(-)src/org/eclipse/ecf/internal/provider/xmpp/search/XMPPSimpleCriterion.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.internal.provider.xmpp.search;
11
12
import org.eclipse.ecf.presence.search.SimpleCriterion;
13
14
/**
15
 * Implement specific for ICriterion
16
 * @since 3.0
17
 */
18
public class XMPPSimpleCriterion extends SimpleCriterion {
19
20
	public XMPPSimpleCriterion(String field, String value, String operator,
21
			boolean ignoreCase) {
22
		super(field, value, operator, ignoreCase);
23
24
	}
25
26
	public XMPPSimpleCriterion(String field, String value, String operator) {
27
		super(field, value, operator);
28
	}
29
	
30
	/**
31
	 * Provide the expression compose just for the value
32
	 */
33
	public String toExpression() {
34
		return value;
35
	}
36
}
(-).project (-6 lines)
Lines 20-34 Link Here
20
			<arguments>
20
			<arguments>
21
			</arguments>
21
			</arguments>
22
		</buildCommand>
22
		</buildCommand>
23
		<buildCommand>
24
			<name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
25
			<arguments>
26
			</arguments>
27
		</buildCommand>
28
	</buildSpec>
23
	</buildSpec>
29
	<natures>
24
	<natures>
30
		<nature>org.eclipse.pde.PluginNature</nature>
25
		<nature>org.eclipse.pde.PluginNature</nature>
31
		<nature>org.eclipse.jdt.core.javanature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
32
		<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
33
	</natures>
27
	</natures>
34
</projectDescription>
28
</projectDescription>
(-)src/org/ecllpse/ecf/tests/provider/xmpp/search/XMPPSearchTest.java (+248 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.ecllpse.ecf.tests.provider.xmpp.search;
11
12
import java.util.Iterator;
13
14
import org.eclipse.ecf.core.ContainerConnectException;
15
import org.eclipse.ecf.core.IContainer;
16
import org.eclipse.ecf.core.identity.ID;
17
import org.eclipse.ecf.presence.search.AbstractUserSearchManager;
18
import org.eclipse.ecf.presence.search.ICriteria;
19
import org.eclipse.ecf.presence.search.ICriterion;
20
import org.eclipse.ecf.presence.search.IResult;
21
import org.eclipse.ecf.presence.search.IResultList;
22
import org.eclipse.ecf.presence.search.ISearch;
23
import org.eclipse.ecf.presence.search.IRestriction;
24
import org.eclipse.ecf.presence.search.IUserSearchCompleteEvent;
25
import org.eclipse.ecf.presence.search.IUserSearchEvent;
26
import org.eclipse.ecf.presence.search.IUserSearchListener;
27
import org.eclipse.ecf.presence.search.IUserSearchManager;
28
import org.eclipse.ecf.tests.presence.AbstractSearchTest;
29
import org.ecllpse.ecf.tests.provider.xmpp.XMPP;
30
31
/**
32
 * 
33
 * @since 3.0
34
 */
35
public class XMPPSearchTest extends AbstractSearchTest {
36
37
	private static final String USERNAME = "Username";
38
	private static final String EMAIL = "Email";
39
	private static final String NAME = "Name";
40
	IContainer client;
41
	IUserSearchManager searchManager;
42
	ISearch searchResult;
43
	
44
	protected String getClientContainerName() {
45
		return XMPP.CONTAINER_NAME;
46
	}
47
48
	public void testRetrieveBuddiesAsync() throws Exception {
49
		assertNotNull(searchManager);
50
51
		IRestriction selection = searchManager.createSelection();
52
		
53
		assertNotNull(selection);
54
55
		// fields to consider on XMPP server side search
56
		// search field for XMPP, criterion to match the search
57
		ICriterion name = selection.eq(NAME, "Marcelo*");
58
		ICriterion email = selection.eq(EMAIL, "zx*");
59
		ICriterion username = selection.eq(USERNAME, "sl*");
60
61
		// create a specific criteria
62
		ICriteria criteria = searchManager.createCriteria();
63
		assertNotNull(criteria);
64
		criteria.add(name);
65
		criteria.add(email);
66
		criteria.add(username);
67
		
68
		final IUserSearchEvent event = new IUserSearchEvent(){};
69
		
70
		IUserSearchListener listenerCompleted = new IUserSearchListener(){
71
			public void handleUserSearchEvent(IUserSearchEvent event) {
72
				if(event instanceof IUserSearchCompleteEvent){
73
					searchResult = ((IUserSearchCompleteEvent)event).getSearch();
74
				}
75
			}
76
		};
77
78
		((AbstractUserSearchManager) searchManager).addListener(listenerCompleted);
79
		
80
		// call the non-block search
81
		searchManager.search(criteria, ((AbstractUserSearchManager) searchManager).getUserSearchListner());
82
83
		//async operation that fire an event to start a user search
84
		Thread localThread = new Thread(new Runnable() {
85
			public void run() {
86
				((AbstractUserSearchManager) searchManager).fireUserSearchEvent(event);
87
			}
88
		});
89
		assertNull(searchResult);
90
		localThread.setDaemon(true);
91
		localThread.start();	
92
		
93
		Thread.sleep(5000);
94
		
95
		//put the completion result on the search handle
96
		assertNotNull(searchResult);
97
98
		// check if there is at least one result
99
		assertTrue(0 != searchResult.getResultList().geResults().size());
100
	}
101
102
	/**
103
	 * Try to locate buddies on the XMPP server in a call block way
104
	 * 
105
	 * @throws ContainerConnectException
106
	 */
107
	public void testRetrieveBuddiesAllFieldsSync()
108
			throws ContainerConnectException {
109
110
		try {
111
			assertNotNull(searchManager);
112
113
			IRestriction selection = searchManager.createSelection();
114
			assertNotNull(selection);
115
116
			// fields to consider on XMPP server side search
117
			// search field for XMPP, criterion to match the search
118
			ICriterion name = selection.eq(NAME, "Marcelo*");
119
			ICriterion email = selection.eq(EMAIL, "zx*");
120
			ICriterion username = selection.eq(USERNAME, "sl*");
121
122
			// create a specific criteria
123
			ICriteria criteria = searchManager.createCriteria();
124
			assertNotNull(criteria);
125
			criteria.add(name);
126
			criteria.add(email);
127
			criteria.add(username);
128
129
			// call the block search
130
			ISearch search = searchManager.search(criteria);
131
132
			// the collection of IResult
133
			IResultList resultList = search.getResultList();
134
135
			// check if there is at least one result
136
			assertTrue(0 != resultList.geResults().size());
137
138
			Iterator it = resultList.geResults().iterator();
139
			while (it.hasNext()) {
140
				IResult type = (IResult) it.next();
141
				System.out.println(type.getUser().getName() + " : "
142
						+ type.getUser().getID());
143
144
			}
145
		} catch (Exception e) {
146
			e.printStackTrace();
147
		}
148
149
	}
150
151
	/**
152
	 * Try to locate buddies on the XMPP server in a call block way
153
	 * 
154
	 * @throws ContainerConnectException
155
	 */
156
	public void testRetrieveBuddiesEmailFieldSync()
157
			throws Exception {
158
159
		assertNotNull(searchManager);
160
161
		IRestriction selection = searchManager.createSelection();
162
		assertNotNull(selection);
163
164
		// search field for XMPP, criterion to match the search
165
		// fields to consider on XMPP server side search
166
		ICriterion email = selection.eq(EMAIL, "mayworm*");
167
168
		// create a specific criteria
169
		ICriteria criteria = searchManager.createCriteria();
170
		assertNotNull(criteria);
171
		criteria.add(email);
172
173
		// call the block search
174
		ISearch search = searchManager.search(criteria);
175
176
		// the collection of IResult
177
		IResultList resultList = search.getResultList();
178
179
		// check if there is at least one result
180
		assertTrue(1 == resultList.geResults().size());
181
182
	}
183
184
	/**
185
	 * Try to locate buddies on the XMPP server in a call block way
186
	 * 
187
	 * @throws ContainerConnectException
188
	 */
189
	public void testRetrieveBuddiesNameFieldSync()
190
			throws Exception {
191
192
		assertNotNull(searchManager);
193
194
		IRestriction selection = searchManager.createSelection();
195
		assertNotNull(selection);
196
197
		// fields to consider on XMPP server side search
198
		// search field for XMPP, criterion to match the search
199
		ICriterion name = selection.eq(NAME, "marcelo*");
200
201
		// create a specific criteria
202
		ICriteria criteria = searchManager.createCriteria();
203
		assertNotNull(criteria);
204
		// criteria.add(searchCriterion);
205
		criteria.add(name);
206
207
		// call the block search
208
		ISearch search = searchManager.search(criteria);
209
210
		// the collection of IResult
211
		IResultList resultList = search.getResultList();
212
213
		// check if there is at least one result
214
		assertTrue(1 == resultList.geResults().size());
215
216
	}
217
218
	protected void setUp() throws Exception {
219
		super.setUp();
220
		final int clientIndex = 0;
221
		client = getClient(clientIndex);
222
		assertNull(client.getConnectedID());
223
		final ID serverConnectID = getServerConnectID(clientIndex);
224
		assertNotNull(serverConnectID);
225
226
		connectClient(client, serverConnectID, getConnectContext(clientIndex));
227
		assertEquals(serverConnectID, client.getConnectedID());
228
229
		searchManager = getPresenceAdapter(clientIndex).getUserSearchManager();
230
231
	}
232
233
	protected void tearDown() throws Exception {
234
		super.tearDown();
235
		client.disconnect();
236
	}
237
238
	public void testUserProperties() throws ContainerConnectException {
239
		assertNotNull(searchManager);
240
		String userProperties[] = searchManager.getUserPropertiesFields();
241
242
		// check if there is at least one result
243
		assertTrue(0 != userProperties.length);
244
245
	}
246
247
248
}
(-)plugin.properties (+1 lines)
Lines 15-20 Link Here
15
15
16
views.messages = Messages
16
views.messages = Messages
17
views.multiRosterView = Contacts
17
views.multiRosterView = Contacts
18
views.userSearchView = Search Contacts
18
19
19
browse.command.label = Open Contact...
20
browse.command.label = Open Contact...
20
browse.command.tooltip = Open Contact
21
browse.command.tooltip = Open Contact
(-)plugin.xml (+7 lines)
Lines 78-83 Link Here
78
            name="%views.multiRosterView">
78
            name="%views.multiRosterView">
79
      </view>
79
      </view>
80
      <view
80
      <view
81
            category="org.eclipse.ecf.ui.viewcategory"
82
            class="org.eclipse.ecf.presence.ui.UserSearchView"
83
            icon="icons/contacts.gif"
84
            id="org.eclipse.ecf.presence.ui.UserSearchView"
85
            name="%views.userSearchView">
86
      </view>
87
      <view
81
            allowMultiple="true"
88
            allowMultiple="true"
82
            category="org.eclipse.ecf.ui.viewcategory"
89
            category="org.eclipse.ecf.ui.viewcategory"
83
            class="org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerView"
90
            class="org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerView"
(-)src/org/eclipse/ecf/internal/presence/ui/messages.properties (+21 lines)
Lines 40-45 Link Here
40
MultiRosterView_CHANGE_PASSWORD_EXCEPTION=changePassword
40
MultiRosterView_CHANGE_PASSWORD_EXCEPTION=changePassword
41
MultiRosterView_ENTER_CHATROOM_TOOLTIP_TEXT=Show chat rooms for all accounts
41
MultiRosterView_ENTER_CHATROOM_TOOLTIP_TEXT=Show chat rooms for all accounts
42
MultiRosterView_AddContact = &Add Contact
42
MultiRosterView_AddContact = &Add Contact
43
MultiRosterView_SearchContact = &Search Contact
43
44
44
MessagesView_ClearChatLog = &Clear Chat Log
45
MessagesView_ClearChatLog = &Clear Chat Log
45
MessagesView_ClearChatLogDialogTitle = Clear Chat Log
46
MessagesView_ClearChatLogDialogTitle = Clear Chat Log
Lines 56-61 Link Here
56
AddContactDialog_Alias = Alias:
57
AddContactDialog_Alias = Alias:
57
AddContactDialog_Account = Account:
58
AddContactDialog_Account = Account:
58
59
60
SearchContactDialog_DialogTitle = Search Contact
61
SearchContactDialog = Search
62
SearchContactDialog_InfoSearching = The following fields are available\nfor searching. Wildcard(*)\ncharacters are allowed as part the\nof query.
63
SearchContactDialog_InfoSearchFields= Search Fields
64
SearchContactDialog_InfoContactFields = Search Results
65
SearchContactDialog_ButtonSearch = Search
66
SearchContactDialog_ButtonStop = Stop
67
SearchContactDialog_ButtonAddContact = Add Contact
68
SearchContactDialog_ContactInfo=Contact Info
69
SearchContactDialog_RunInBackground=Run in background
70
SearchContactDialog_RunInBackGroundToolTip=Run long operations in the background where possible
71
SearchContactDialog_TableResultColumnName=Name
72
SearchContactDialog_TableResultColumnUsername=ID
73
SearchContactDialog_TableSearchColumnField=Field
74
SearchContactDialog_TableSearchColumnValue=Value For Search
75
SearchContactDialog_AddContactMessage=Do you want to add the contact {0}?
76
SearchContactDialog_SearchingMessage=Searching...
77
SearchContactDialog_UserSearchJobName=Searching User...
78
59
RosterWorkbenchAdapterFactory_Mode = Mode: {0} 
79
RosterWorkbenchAdapterFactory_Mode = Mode: {0} 
60
RosterWorkbenchAdapterFactory_Type = Type: {0} 
80
RosterWorkbenchAdapterFactory_Type = Type: {0} 
61
RosterWorkbenchAdapterFactory_Account = Account: {0}
81
RosterWorkbenchAdapterFactory_Account = Account: {0}
Lines 149-151 Link Here
149
ChatRoomPreferencePage_CHATROOM_SHOW_USER_PRESENCE_TEXT=&Show user entry and exit messages
169
ChatRoomPreferencePage_CHATROOM_SHOW_USER_PRESENCE_TEXT=&Show user entry and exit messages
150
 
170
 
151
ChatRoomPreferencePage_SCROLL_OUTPUT_ON_INPUT=Scroll &output to bottom on user input
171
ChatRoomPreferencePage_SCROLL_OUTPUT_ON_INPUT=Scroll &output to bottom on user input
172
UserSearchLabelProvider_ContactsFound=\ contacts found
(-)src/org/eclipse/ecf/internal/presence/ui/Messages.java (+32 lines)
Lines 194-199 Link Here
194
	public static String MultiRosterView_ShowOffline;
194
	public static String MultiRosterView_ShowOffline;
195
	public static String MultiRosterView_ShowEmptyGroups;
195
	public static String MultiRosterView_ShowEmptyGroups;
196
	public static String MultiRosterView_AddContact;
196
	public static String MultiRosterView_AddContact;
197
	public static String MultiRosterView_SearchContact;
197
198
198
	public static String MessagesView_ClearChatLog;
199
	public static String MessagesView_ClearChatLog;
199
	public static String MessagesView_ClearChatLogDialogTitle;
200
	public static String MessagesView_ClearChatLogDialogTitle;
Lines 209-214 Link Here
209
	public static String AddContactDialog_Alias;
210
	public static String AddContactDialog_Alias;
210
	public static String AddContactDialog_Account;
211
	public static String AddContactDialog_Account;
211
212
213
	public static String SearchContactDialog_DialogTitle;
214
	public static String SearchContactDialog;
215
	public static String SearchContactDialog_InfoSearching;
216
	public static String SearchContactDialog_InfoSearchFields;
217
	public static String SearchContactDialog_InfoContactFields;
218
	public static String SearchContactDialog_ButtonSearch;
219
	public static String SearchContactDialog_ButtonStop;
220
	public static String SearchContactDialog_ButtonAddContact;
221
222
	public static String SearchContactDialog_ContactInfo;
223
224
	public static String SearchContactDialog_AddContactMessage;
225
226
	public static String SearchContactDialog_RunInBackground;
227
228
	public static String SearchContactDialog_RunInBackGroundToolTip;
229
230
	public static String SearchContactDialog_SearchingMessage;
231
232
	public static String SearchContactDialog_TableResultColumnName;
233
234
	public static String SearchContactDialog_TableResultColumnUsername;
235
236
	public static String SearchContactDialog_TableSearchColumnField;
237
238
	public static String SearchContactDialog_TableSearchColumnValue;
239
240
	public static String SearchContactDialog_UserSearchJobName;
241
212
	public static String ReceiveAuthorizeRequestDialog_AUTH_REQUEST_FROM;
242
	public static String ReceiveAuthorizeRequestDialog_AUTH_REQUEST_FROM;
213
243
214
	public static String ReceiveAuthorizeRequestDialog_BUTTON_AUTHORIZE_AND_ADD;
244
	public static String ReceiveAuthorizeRequestDialog_BUTTON_AUTHORIZE_AND_ADD;
Lines 244-249 Link Here
244
274
245
	public static String ChatRoomPreferencePage_SCROLL_OUTPUT_ON_INPUT;
275
	public static String ChatRoomPreferencePage_SCROLL_OUTPUT_ON_INPUT;
246
276
277
	public static String UserSearchLabelProvider_ContactsFound;
278
247
	static {
279
	static {
248
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
280
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
249
	}
281
	}
(-)src/org/eclipse/ecf/presence/ui/MultiRosterView.java (+24 lines)
Lines 97-102 Link Here
97
97
98
	private IAction addContactAction;
98
	private IAction addContactAction;
99
99
100
	private IAction searchContactAction;
101
100
	private IAction openChatRoomAction;
102
	private IAction openChatRoomAction;
101
103
102
	private IAction openAccountChatRoomAction;
104
	private IAction openAccountChatRoomAction;
Lines 480-485 Link Here
480
			}
482
			}
481
		};
483
		};
482
484
485
		searchContactAction = new Action() {
486
			public void run() {
487
				IStructuredSelection iss = (IStructuredSelection) treeViewer.getSelection();
488
				IRoster roster = (IRoster) iss.getFirstElement();
489
				MultiRosterAccount account = findAccountForUser(roster.getUser().getID());
490
				if (account != null) {
491
					SearchContactDialog dialog = new SearchContactDialog(treeViewer.getControl().getShell(), account);
492
					dialog.open();
493
				}
494
			}
495
		};
496
497
		searchContactAction.setText(Messages.MultiRosterView_SearchContact);
498
483
		openChatRoomAction = new Action() {
499
		openChatRoomAction = new Action() {
484
			public void run() {
500
			public void run() {
485
				selectAndJoinChatRoomForAccounts((MultiRosterAccount[]) rosterAccounts.toArray(new MultiRosterAccount[] {}));
501
				selectAndJoinChatRoomForAccounts((MultiRosterAccount[]) rosterAccounts.toArray(new MultiRosterAccount[] {}));
Lines 618-623 Link Here
618
			}
634
			}
619
			manager.add(addContactAction);
635
			manager.add(addContactAction);
620
			manager.add(new Separator());
636
			manager.add(new Separator());
637
			//add if the provider supports user search
638
			if (((IRoster) element).getPresenceContainerAdapter().getUserSearchManager().isEnabled()) {
639
				manager.add(searchContactAction);
640
				manager.add(new Separator());
641
			}
621
			manager.add(openAccountChatRoomAction);
642
			manager.add(openAccountChatRoomAction);
622
			manager.add(new Separator());
643
			manager.add(new Separator());
623
			manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
644
			manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
Lines 701-706 Link Here
701
		showOfflineAction.setEnabled(enabled);
722
		showOfflineAction.setEnabled(enabled);
702
		showEmptyGroupsAction.setEnabled(enabled);
723
		showEmptyGroupsAction.setEnabled(enabled);
703
		addContactAction.setEnabled(enabled);
724
		addContactAction.setEnabled(enabled);
725
		searchContactAction.setEnabled(enabled);
704
		openChatRoomAction.setEnabled(enabled);
726
		openChatRoomAction.setEnabled(enabled);
705
		disconnectAllAccountsAction.setEnabled(enabled);
727
		disconnectAllAccountsAction.setEnabled(enabled);
706
	}
728
	}
Lines 722-727 Link Here
722
		manager.add(new Separator());
744
		manager.add(new Separator());
723
		manager.add(addContactAction);
745
		manager.add(addContactAction);
724
		manager.add(new Separator());
746
		manager.add(new Separator());
747
		manager.add(searchContactAction);
748
		manager.add(new Separator());
725
		manager.add(openChatRoomAction);
749
		manager.add(openChatRoomAction);
726
		manager.add(new Separator());
750
		manager.add(new Separator());
727
		manager.add(disconnectAllAccountsAction);
751
		manager.add(disconnectAllAccountsAction);
(-)src/org/eclipse/ecf/presence/ui/UserSearchView.java (+183 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.ui;
11
12
import java.util.ArrayList;
13
import java.util.List;
14
import org.eclipse.core.runtime.Assert;
15
import org.eclipse.ecf.core.util.ECFException;
16
import org.eclipse.ecf.internal.presence.ui.Activator;
17
import org.eclipse.ecf.internal.presence.ui.Messages;
18
import org.eclipse.ecf.presence.IPresenceContainerAdapter;
19
import org.eclipse.ecf.presence.roster.IRosterSubscriptionSender;
20
import org.eclipse.ecf.presence.search.IResult;
21
import org.eclipse.ecf.presence.search.IResultList;
22
import org.eclipse.ecf.ui.SharedImages;
23
import org.eclipse.jface.action.*;
24
import org.eclipse.jface.dialogs.MessageDialog;
25
import org.eclipse.jface.viewers.*;
26
import org.eclipse.osgi.util.NLS;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.widgets.*;
29
import org.eclipse.ui.part.PageBook;
30
import org.eclipse.ui.part.ViewPart;
31
32
/**
33
 * View class for displaying multiple users that match a search in a tree viewer. This view part
34
 * provides the ability to display multiple users in a single tree viewer. This class may be subclassed as
35
 * desired to add or customize behavior.
36
 */
37
public class UserSearchView extends ViewPart {
38
39
	public static final String VIEW_ID = "org.eclipse.ecf.presence.ui.UserSearchView"; //$NON-NLS-1$
40
41
	protected static final int DEFAULT_EXPAND_LEVEL = 3;
42
43
	protected TreeViewer treeViewer;
44
45
	protected List users = new ArrayList();
46
47
	private IAction addContactAction;
48
49
	private MultiRosterAccount account;
50
51
	private PageBook pageBook;
52
53
	private Label helpMessageLabel;
54
55
	/*
56
	 * (non-Javadoc)
57
	 * 
58
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
59
	 */
60
	public void createPartControl(Composite parent) {
61
		pageBook = new PageBook(parent, SWT.NONE);
62
63
		createHelpMessage(pageBook);
64
		setupTreeViewer(pageBook);
65
66
		if (users.size() == 0)
67
			pageBook.showPage(helpMessageLabel);
68
	}
69
70
	private void createHelpMessage(Composite parent) {
71
		if (!parent.isDisposed()) {
72
			helpMessageLabel = new Label(parent, SWT.TOP + SWT.LEFT + SWT.WRAP);
73
		}
74
	}
75
76
	protected void setupTreeViewer(Composite parent) {
77
		treeViewer = new TreeViewer(parent, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL);
78
		getSite().setSelectionProvider(treeViewer);
79
		treeViewer.setContentProvider(new UserSearchContentProvider());
80
		treeViewer.setLabelProvider(new UserSearchLabelProvider());
81
		makeActions();
82
		hookContextMenu();
83
84
	}
85
86
	private void makeActions() {
87
88
		addContactAction = new Action(Messages.MultiRosterView_AddContact, SharedImages.getImageDescriptor(SharedImages.IMG_ADD_BUDDY)) {
89
			public void run() {
90
				ITreeSelection selection = (ITreeSelection) treeViewer.getSelection();
91
				IResult contact = (IResult) selection.getFirstElement();
92
				if (MessageDialog.openConfirm(null, Messages.AddContactDialog_DialogTitle, NLS.bind(Messages.SearchContactDialog_AddContactMessage, contact.getUser().getName()))) {
93
					IPresenceContainerAdapter ipca = account.getPresenceContainerAdapter();
94
					IRosterSubscriptionSender sender = ipca.getRosterManager().getRosterSubscriptionSender();
95
					try {
96
						sender.sendRosterAdd(contact.getUser().getID().getName(), contact.getUser().getName(), null);
97
					} catch (ECFException e) {
98
						Activator.getDefault().getLog().log(e.getStatus());
99
					}
100
				}
101
102
			}
103
		};
104
105
	}
106
107
	private void hookContextMenu() {
108
		MenuManager menuMgr = new MenuManager();
109
		menuMgr.setRemoveAllWhenShown(true);
110
		menuMgr.addMenuListener(new IMenuListener() {
111
			public void menuAboutToShow(IMenuManager manager) {
112
				fillContextMenu(manager);
113
			}
114
		});
115
		Menu menu = menuMgr.createContextMenu(treeViewer.getControl());
116
		treeViewer.getControl().setMenu(menu);
117
		getSite().registerContextMenu(menuMgr, treeViewer);
118
	}
119
120
	private void fillContextMenu(IMenuManager manager) {
121
		IStructuredSelection iss = (IStructuredSelection) treeViewer.getSelection();
122
		Object element = iss.getFirstElement();
123
		if (element instanceof IResult) {
124
			manager.add(addContactAction);
125
		}
126
	}
127
128
	/*
129
	 * (non-Javadoc)
130
	 * 
131
	 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
132
	 */
133
	public void dispose() {
134
		treeViewer = null;
135
		users.clear();
136
		super.dispose();
137
	}
138
139
	/*
140
	 * (non-Javadoc)
141
	 * 
142
	 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
143
	 */
144
	public void setFocus() {
145
		treeViewer.getControl().setFocus();
146
	}
147
148
	/**
149
	 * Add the list of {@link IResult} that will be display on a tree
150
	 * @param list
151
	 * @return boolean
152
	 */
153
	public boolean addResult(IResultList list) {
154
		users.clear();
155
		users.add(list);
156
		treeViewer.setInput(users);
157
		pageBook.showPage(treeViewer.getControl());
158
		treeViewer.expandToLevel(DEFAULT_EXPAND_LEVEL);
159
		helpMessageLabel.setText("");
160
		return true;
161
	}
162
163
	/**
164
	 * Add the MultiRosterAccount for add user contact
165
	 * @param account
166
	 * @return boolean
167
	 */
168
	public boolean addMultiRosterAccount(MultiRosterAccount multiRosterAccount) {
169
		Assert.isNotNull(multiRosterAccount);
170
		this.account = multiRosterAccount;
171
		return true;
172
	}
173
174
	/**
175
	 * Show a message into the view before show the result in a tree view
176
	 * @param string
177
	 */
178
	public void showMessage(String message) {
179
		helpMessageLabel.setText(message);
180
		pageBook.showPage(helpMessageLabel);
181
	}
182
183
}
(-)src/org/eclipse/ecf/internal/presence/ui/dialogs/SearchContactDialog.java (+264 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.internal.presence.ui.dialogs;
11
12
import java.util.Iterator;
13
import org.eclipse.core.runtime.*;
14
import org.eclipse.ecf.core.ContainerConnectException;
15
import org.eclipse.ecf.core.util.ECFException;
16
import org.eclipse.ecf.internal.presence.ui.Activator;
17
import org.eclipse.ecf.internal.presence.ui.Messages;
18
import org.eclipse.ecf.presence.IPresenceContainerAdapter;
19
import org.eclipse.ecf.presence.roster.IRosterSubscriptionSender;
20
import org.eclipse.ecf.presence.search.*;
21
import org.eclipse.ecf.presence.ui.MultiRosterAccount;
22
import org.eclipse.ecf.presence.ui.UserSearchView;
23
import org.eclipse.jface.dialogs.*;
24
import org.eclipse.jface.dialogs.Dialog;
25
import org.eclipse.osgi.util.NLS;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.custom.TableEditor;
28
import org.eclipse.swt.events.*;
29
import org.eclipse.swt.layout.GridData;
30
import org.eclipse.swt.layout.GridLayout;
31
import org.eclipse.swt.widgets.*;
32
import org.eclipse.ui.PartInitException;
33
import org.eclipse.ui.PlatformUI;
34
import org.eclipse.ui.progress.UIJob;
35
36
/**
37
 * 
38
 * @since 3.0
39
 *
40
 */
41
public class SearchContactDialog extends Dialog {
42
43
	Button closeButton;
44
45
	Button searchButton;
46
47
	MultiRosterAccount account;
48
49
	Button addContactButton;
50
51
	Button runInBackgroundButton;
52
53
	Table tableResult;
54
55
	Table tableFields;
56
57
	public SearchContactDialog(Shell parentShell, MultiRosterAccount account) {
58
		super(parentShell);
59
		this.account = account;
60
61
	}
62
63
	protected void addListeners() {
64
65
		searchButton.addMouseListener(new MouseAdapter() {
66
			public void mouseUp(MouseEvent e) {
67
				IUserSearchManager userManager = account.getPresenceContainerAdapter().getUserSearchManager();
68
				try {
69
					//selection to build the criteria
70
					IRestriction selection = userManager.createSelection();
71
					//create a specific criteria 
72
					final ICriteria criteria = userManager.createCriteria();
73
					//fields to consider on XMPP server side search
74
					TableItem items[] = tableFields.getItems();
75
					for (int i = 0; i < items.length; i++) {
76
						TableItem item = items[i];
77
						if (item.getChecked()) {
78
							//build criterion field=value
79
							ICriterion criterion = selection.eq(item.getText(0), item.getText(1));
80
							criteria.add(criterion);
81
						}
82
					}
83
					//Run in a block or non-block way using the criteria built previously
84
					if (runInBackgroundButton.getSelection()) {
85
						callAsynchronous(userManager, criteria);
86
						//close the UI
87
						close();
88
					} else {
89
						//call the block search
90
						ISearch search = userManager.search(criteria);
91
						//the collection of IResult
92
						IResultList resultList = search.getResultList();
93
						//clean the table for a new result list
94
						tableResult.removeAll();
95
						for (Iterator iterator = resultList.geResults().iterator(); iterator.hasNext();) {
96
							IResult result = (IResult) iterator.next();
97
							TableItem item = new TableItem(tableResult, SWT.NONE);
98
							item.setText(0, result.getUser().getName());
99
							item.setText(1, result.getUser().getID().getName());
100
						}
101
					}
102
103
				} catch (UserSearchException e1) {
104
					Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e1.getLocalizedMessage(), e1));
105
				}
106
			}
107
		});
108
109
		addContactButton.addMouseListener(new MouseAdapter() {
110
			public void mouseUp(MouseEvent e) {
111
				TableItem contact = tableResult.getSelection()[0];
112
				if (MessageDialog.openConfirm(null, Messages.AddContactDialog_DialogTitle, NLS.bind(Messages.SearchContactDialog_AddContactMessage, contact.getText(0)))) {
113
114
					IPresenceContainerAdapter ipca = account.getPresenceContainerAdapter();
115
					IRosterSubscriptionSender sender = ipca.getRosterManager().getRosterSubscriptionSender();
116
					try {
117
						sender.sendRosterAdd(contact.getText(1), contact.getText(0), null);
118
					} catch (ECFException e1) {
119
						Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e1.getLocalizedMessage(), e1));
120
					}
121
					close();
122
				}
123
			}
124
		});
125
126
	}
127
128
	protected void configureShell(Shell newShell) {
129
		super.configureShell(newShell);
130
		newShell.setText(Messages.SearchContactDialog_DialogTitle);
131
	}
132
133
	/*
134
	 * Create just a close button for the Dialog
135
	 * (non-Javadoc)
136
	 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
137
	 */
138
	protected void createButtonsForButtonBar(Composite parent) {
139
		createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, true);
140
		closeButton = getButton(IDialogConstants.OK_ID);
141
		closeButton.setEnabled(true);
142
	}
143
144
	protected Control createDialogArea(Composite parent) {
145
		final int editableColumn = 1;
146
		try {
147
			parent = (Composite) super.createDialogArea(parent);
148
			parent.setLayout(new GridLayout(2, false));
149
			String fields[] = null;
150
			IUserSearchManager userManager = account.getPresenceContainerAdapter().getUserSearchManager();
151
			fields = userManager.getUserPropertiesFields();
152
153
			GridData searchButtonData = new GridData(SWT.RIGHT, GridData.FILL_HORIZONTAL, false, false, 1, 1);
154
			GridData addContactData = new GridData(SWT.RIGHT, GridData.FILL_HORIZONTAL, true, false, 1, 1);
155
156
			Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
157
			group.setLayout(new GridLayout(2, false));
158
			group.setText(Messages.SearchContactDialog_InfoSearchFields);
159
160
			Group groupContact = new Group(parent, SWT.SHADOW_ETCHED_IN);
161
			groupContact.setLayout(new GridLayout(2, false));
162
			groupContact.setText(Messages.SearchContactDialog_InfoContactFields);
163
164
			tableResult = new Table(groupContact, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
165
			tableResult.setLinesVisible(true);
166
			tableResult.setHeaderVisible(true);
167
			GridData dataTable = new GridData(GridData.FILL_HORIZONTAL, GridData.FILL_VERTICAL, true, true, 2, 1);
168
			dataTable.heightHint = 200;
169
			tableResult.setLayoutData(dataTable);
170
171
			new TableColumn(tableResult, SWT.NONE).setText(Messages.SearchContactDialog_TableResultColumnName);
172
			new TableColumn(tableResult, SWT.NONE).setText(Messages.SearchContactDialog_TableResultColumnUsername);
173
			new TableItem(tableResult, SWT.NONE);
174
175
			for (int i = 0; i < 2; i++) {
176
				tableResult.getColumn(i).setWidth(130);
177
			}
178
179
			addContactButton = new Button(groupContact, SWT.PUSH | SWT.RIGHT);
180
			addContactButton.setText(Messages.SearchContactDialog_ButtonAddContact);
181
			addContactButton.setLayoutData(addContactData);
182
183
			tableFields = new Table(group, SWT.BORDER | SWT.MULTI | SWT.CHECK);
184
			tableFields.setLinesVisible(true);
185
			tableFields.setHeaderVisible(true);
186
			dataTable = new GridData(GridData.FILL_HORIZONTAL, GridData.FILL_VERTICAL, true, true, 2, 1);
187
			dataTable.heightHint = 200;
188
			tableFields.setLayoutData(dataTable);
189
190
			TableColumn colField = new TableColumn(tableFields, SWT.NONE);
191
			colField.setText(Messages.SearchContactDialog_TableSearchColumnField);
192
			TableColumn colValue = new TableColumn(tableFields, SWT.NONE);
193
			colValue.setText(Messages.SearchContactDialog_TableSearchColumnValue);
194
			colValue.setWidth(130);
195
196
			for (int i = 0; i < fields.length; i++) {
197
				TableItem item = new TableItem(tableFields, SWT.NONE);
198
				item.setText(new String[] {fields[i], ""}); //$NON-NLS-1$
199
				item.setChecked(true);
200
			}
201
202
			TableItem[] items = tableFields.getItems();
203
			for (int i = 0; i < items.length; i++) {
204
				final TableEditor editor = new TableEditor(tableFields);
205
				Text text = new Text(tableFields, SWT.NONE);
206
				text.setText(items[i].getText(editableColumn));
207
				text.addModifyListener(new ModifyListener() {
208
					public void modifyText(ModifyEvent e) {
209
						editor.getItem().setText(editableColumn, ((Text) editor.getEditor()).getText());
210
					}
211
				});
212
				text.selectAll();
213
				text.setFocus();
214
				editor.grabHorizontal = true;
215
				editor.setEditor(text, items[i], editableColumn);
216
217
			}
218
			colField.pack();
219
220
			runInBackgroundButton = new Button(group, SWT.CHECK);
221
			runInBackgroundButton.setText(Messages.SearchContactDialog_RunInBackground);
222
			runInBackgroundButton.setToolTipText(Messages.SearchContactDialog_RunInBackGroundToolTip);
223
224
			searchButton = new Button(group, SWT.PUSH | SWT.RIGHT);
225
			searchButton.setText(Messages.SearchContactDialog_ButtonSearch);
226
			searchButton.setLayoutData(searchButtonData);
227
228
		} catch (ContainerConnectException e) {
229
			Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getLocalizedMessage(), e));
230
			new Label(parent, SWT.LEFT).setText(e.getLocalizedMessage());
231
		}
232
		addListeners();
233
		applyDialogFont(parent);
234
		return parent;
235
	}
236
237
	/**
238
	 * Call the user search and open the view 
239
	 * asynchronous
240
	 * @param userManager
241
	 * @param criteria
242
	 */
243
	protected void callAsynchronous(final IUserSearchManager userManager, final ICriteria criteria) {
244
		new UIJob(Messages.SearchContactDialog_UserSearchJobName) {
245
			public IStatus runInUIThread(IProgressMonitor monitor) {
246
				try {
247
					final UserSearchView view = (UserSearchView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(UserSearchView.VIEW_ID);
248
					view.showMessage(Messages.SearchContactDialog_SearchingMessage);
249
					view.addMultiRosterAccount(account);
250
					IResultList resultList = userManager.search(criteria).getResultList();
251
					view.addResult(resultList);
252
				} catch (PartInitException e) {
253
					Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getLocalizedMessage(), e));
254
					return Status.CANCEL_STATUS;
255
				} catch (UserSearchException e) {
256
					Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getLocalizedMessage(), e));
257
					return Status.CANCEL_STATUS;
258
				}
259
				return Status.OK_STATUS;
260
			}
261
		}.schedule(3000);
262
	}
263
264
}
(-)src/org/eclipse/ecf/presence/ui/UserSearchLabelProvider.java (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.ui;
11
12
import org.eclipse.ecf.internal.presence.ui.Messages;
13
import org.eclipse.ecf.presence.search.IResult;
14
import org.eclipse.ecf.presence.search.IResultList;
15
import org.eclipse.ecf.ui.SharedImages;
16
import org.eclipse.jface.viewers.LabelProvider;
17
import org.eclipse.swt.graphics.Image;
18
19
/**
20
 * Label provider for multiple users viewer. This label provider implements an
21
 * LabelProvider suitable for use by viewers that accepts LabelProvider as
22
 * input. This class may be subclassed in order to customize the
23
 * behavior/display of other label providers.
24
 * 
25
 */
26
public class UserSearchLabelProvider extends LabelProvider {
27
28
	/*
29
	 * (non-Javadoc)
30
	 * 
31
	 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
32
	 */
33
	public Image getImage(Object element) {
34
		if (element instanceof IResultList)
35
			return SharedImages.getImage(SharedImages.IMG_GROUP);
36
		if (element instanceof IResult)
37
			return SharedImages.getImage(SharedImages.IMG_USER_AVAILABLE);
38
39
		return null;
40
	}
41
42
	/*
43
	 * (non-Javadoc)
44
	 * 
45
	 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
46
	 */
47
	public String getText(Object element) {
48
		if (element instanceof IResult) {
49
			return ((IResult) element).getUser().getName();
50
		} else if (element instanceof IResultList) {
51
			return ((IResultList) element).geResults().size() + Messages.UserSearchLabelProvider_ContactsFound;
52
		}
53
		return element.toString();
54
	}
55
56
}
(-)src/org/eclipse/ecf/presence/ui/UserSearchContentProvider.java (+98 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.ui;
11
12
import java.util.List;
13
import org.eclipse.ecf.presence.search.IResultList;
14
import org.eclipse.jface.viewers.ITreeContentProvider;
15
import org.eclipse.jface.viewers.Viewer;
16
17
/**
18
 * Content provider for multiple users viewer. This content provider implements
19
 * an ITreeContentProvider suitable for use by tree viewers that accepts
20
 * ITreeContentProviders as input. This class may be subclassed in order to
21
 * customize the behavior/display of other content providers.
22
 * 
23
 */
24
public class UserSearchContentProvider implements ITreeContentProvider {
25
26
	protected static Object[] EMPTY_ARRAY = new Object[0];
27
28
	/*
29
	 * (non-Javadoc)
30
	 * 
31
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
32
	 */
33
	public Object[] getChildren(Object parentElement) {
34
		if (parentElement instanceof IResultList) {
35
			return ((IResultList) parentElement).geResults().toArray();
36
		}
37
		return EMPTY_ARRAY;
38
	}
39
40
	/*
41
	 * (non-Javadoc)
42
	 * 
43
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
44
	 */
45
	public Object getParent(Object element) {
46
		if (element == null) {
47
			return null;
48
		}
49
		return element;
50
	}
51
52
	/*
53
	 * (non-Javadoc)
54
	 * 
55
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
56
	 */
57
	public boolean hasChildren(Object element) {
58
		if (element instanceof IResultList) {
59
			IResultList list = (IResultList) element;
60
			if (list.geResults().size() > 0)
61
				return true;
62
		}
63
		return false;
64
	}
65
66
	/*
67
	 * (non-Javadoc)
68
	 * 
69
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
70
	 */
71
	public Object[] getElements(Object inputElement) {
72
		if (inputElement instanceof List)
73
			return ((List) inputElement).toArray();
74
75
		return null;
76
77
	}
78
79
	/*
80
	 * (non-Javadoc)
81
	 * 
82
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
83
	 */
84
	public void dispose() {
85
		// do nothing
86
	}
87
88
	/*
89
	 * (non-Javadoc)
90
	 * 
91
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
92
	 *      java.lang.Object, java.lang.Object)
93
	 */
94
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
95
		// do nothing
96
	}
97
98
}
(-)src/org/eclipse/ecf/presence/IPresenceContainerAdapter.java (+11 lines)
Lines 14-19 Link Here
14
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
14
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
15
import org.eclipse.ecf.presence.im.IChatManager;
15
import org.eclipse.ecf.presence.im.IChatManager;
16
import org.eclipse.ecf.presence.roster.IRosterManager;
16
import org.eclipse.ecf.presence.roster.IRosterManager;
17
import org.eclipse.ecf.presence.search.IUserSearchManager;
17
18
18
/**
19
/**
19
 * Entry point presence container adapter. For setting up listeners for presence
20
 * Entry point presence container adapter. For setting up listeners for presence
Lines 71-74 Link Here
71
	 *         available, returns <code>null</code>.
72
	 *         available, returns <code>null</code>.
72
	 */
73
	 */
73
	public IChatRoomManager getChatRoomManager();
74
	public IChatRoomManager getChatRoomManager();
75
76
	/**
77
	 * Retrieve interface for search on the provide. The returned
78
	 * IUserSearchManager (if not <code>null</code>) can be used to search users
79
	 * related to the same provider.
80
	 * 
81
	 * @return IUserSearchManager. <code>null</code> if no search 
82
	 *         available for this provider.
83
	 */
84
	public IUserSearchManager getUserSearchManager();
74
}
85
}
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 12-17 Link Here
12
 org.eclipse.ecf.presence.history,
12
 org.eclipse.ecf.presence.history,
13
 org.eclipse.ecf.presence.im,
13
 org.eclipse.ecf.presence.im,
14
 org.eclipse.ecf.presence.roster,
14
 org.eclipse.ecf.presence.roster,
15
 org.eclipse.ecf.presence.search,
15
 org.eclipse.ecf.presence.service
16
 org.eclipse.ecf.presence.service
16
Bundle-ManifestVersion: 2
17
Bundle-ManifestVersion: 2
17
Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0,
18
Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0,
(-)src/org/eclipse/ecf/presence/search/IUserSearchCompleteEvent.java (+23 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.search;
11
12
/**
13
 * This event indicate that a user search was completed
14
 *@since 3.0
15
 */
16
public interface IUserSearchCompleteEvent extends IUserSearchEvent {
17
18
	/**
19
	 * Provide the result for a non-blocking search
20
	 * @return ISearch
21
	 */
22
	public ISearch getSearch();
23
}
(-)src/org/eclipse/ecf/presence/search/ResultList.java (+103 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.search;
11
12
import java.util.*;
13
import org.eclipse.core.runtime.IAdapterManager;
14
import org.eclipse.ecf.internal.presence.PresencePlugin;
15
16
/**
17
 * This Class implements {@link IResultList}. Subclasses may be created as
18
 * appropriate.
19
 * @since 3.0
20
 */
21
public class ResultList implements IResultList {
22
23
	protected Set results;
24
25
	/**
26
	 * Create a new synchronized result list from a existing one
27
	 * @param existingResults
28
	 */
29
	public ResultList(Collection /* <IResult> */existingResults) {
30
		results = Collections.synchronizedSet(new HashSet());
31
		if (existingResults != null)
32
			addAll(existingResults);
33
	}
34
35
	/**
36
	 * Create a new synchronized result list from a existing one
37
	 *
38
	 */
39
	public ResultList() {
40
		results = Collections.synchronizedSet(new HashSet());
41
	}
42
43
	/**
44
	 * Add an item for the result list
45
	 * @param item
46
	 * @return boolean
47
	 */
48
	public boolean add(IResult item) {
49
		if (item == null)
50
			return false;
51
		if (results.add(item))
52
			return true;
53
		return false;
54
	}
55
56
	/**
57
	 * Add the list for the current result list
58
	 * @param existingResults
59
	 */
60
	public void addAll(Collection /* <IResult> */existingResults) {
61
		if (existingResults == null)
62
			return;
63
		synchronized (results) {
64
			for (Iterator i = existingResults.iterator(); i.hasNext();) {
65
				add((IResult) i.next());
66
			}
67
		}
68
	}
69
70
	/*
71
	 * (non-Javadoc)
72
	 * 
73
	 * @see org.eclipse.ecf.ui.presence.search.IResultList#getEntries()
74
	 */
75
	public Collection geResults() {
76
		return results;
77
	}
78
79
	public boolean remove(IResult item) {
80
		return results.remove(item);
81
	}
82
83
	/*
84
	 * (non-Javadoc)
85
	 * 
86
	 * @see org.eclipse.ecf.ui.presence.search.IResultList#getResult
87
	 */
88
	public IResult getResult(String field, String value) {
89
		// TODO 
90
		return null;
91
	}
92
93
	public Object getAdapter(Class adapter) {
94
		if (adapter.isInstance(this)) {
95
			return this;
96
		}
97
		IAdapterManager adapterManager = PresencePlugin.getDefault().getAdapterManager();
98
		if (adapterManager == null)
99
			return null;
100
		return adapterManager.loadAdapter(this, adapter.getName());
101
	}
102
103
}
(-)src/org/eclipse/ecf/presence/search/ICriteria.java (+54 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
11
package org.eclipse.ecf.presence.search;
12
13
import java.util.List;
14
15
/**
16
 * Criteria helps for retrieving results from the provider search by composing Criterion objects. 
17
 * The {@link IUserSearchManager} is a factory for Criteria. Criterion instances are obtained via ISelection methods.
18
 * Criteria can deal with different kind of criterion, as logical or just simple expression.
19
 * 
20
 *  The typical usage of the Criteria is as
21
 * follows:
22
 * 
23
 * <pre>
24
 *      ISelection selection = ...
25
 *		ICriterion name = selection.eq("name", "value");
26
 *		ICriterion host = selection.eq("host", "value");
27
 *		ICriterion and = selection.and(name, host);
28
 *		ICriteria criteria = ...
29
 *		criteria.add(and);
30
 * </pre>
31
 * 
32
 * @since 3.0
33
 */
34
public interface ICriteria {
35
36
	/**
37
	 * Add a criterion that composes the criteria
38
	 * @param criterion
39
	 */
40
	public void add(ICriterion criterion);
41
42
	/**
43
	 * A list of all criterion added to the criteria
44
	 * @return List of {@link ICriterion}
45
	 */
46
	public List getCriterions();
47
48
	/**
49
	 * Notify if there is or not criterion added for this criteria
50
	 * @return indicate if there are or not criterion
51
	 */
52
	public boolean isEmpty();
53
54
}
(-)src/org/eclipse/ecf/presence/search/LogicalCriterion.java (+49 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.search;
11
12
/**
13
 * Base class implementation of {@link ICriterion} for logical criterion. 
14
 * Subclasses may be created as appropriate. It is just a simple 
15
 * implementation that can be considered for some provider or even used 
16
 * as base for some implementation.
17
 * @since 3.0
18
 */
19
public class LogicalCriterion implements ICriterion {
20
21
	final ICriterion left;
22
	final ICriterion right;
23
	final String operator;
24
25
	/**
26
	 * Creates a logic operation for compose a {@link ICrteria}
27
	 * @param left Criterion on the left side of the expression
28
	 * @param right Criterion on the right side of the expression
29
	 * @param operator Operator considered on the logical. Ex: And
30
	 */
31
	public LogicalCriterion(ICriterion left, ICriterion right, String operator) {
32
		this.left = left;
33
		this.right = right;
34
		this.operator = operator;
35
	}
36
37
	public String toExpression() {
38
		return left.toExpression() + ' ' + operator + ' ' + right.toExpression();
39
	}
40
41
	public String toString() {
42
		StringBuffer sb = new StringBuffer("LogicalCriterion["); //$NON-NLS-1$
43
		sb.append("left=").append(left).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
44
		sb.append("right=").append(right).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
45
		sb.append("operator=").append(operator).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
46
		return sb.toString();
47
	}
48
49
}
(-)src/org/eclipse/ecf/presence/search/IUserSearchManager.java (+73 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
11
package org.eclipse.ecf.presence.search;
12
13
import org.eclipse.ecf.core.ContainerConnectException;
14
15
/**
16
 * Get a search mechanism for an account.
17
 * @since 3.0
18
 */
19
public interface IUserSearchManager {
20
21
	/**
22
	 * Execute the search for a specific criteria, blocking until the search returns.
23
	 * This method can apply search to math the specific criteria in case if the 
24
	 * provider is not able to do it completely
25
	 * @param criteria 
26
	 * @return ISearch Contain the search results
27
	 * @throws UserSearchException 
28
	 */
29
	public ISearch search(ICriteria criteria) throws UserSearchException;
30
31
	/**
32
	 * Execute the search for a specific criteria, not blocking until the search returns.
33
	 * This method can apply search to math the specific criteria in case if the 
34
	 * provider is not able to do it completely
35
	 * @param criteria 
36
	 * @param listener the listener {@link IUserSearchListener} to search. Must not be <code>null</code>. 
37
	 */
38
	public void search(ICriteria criteria, IUserSearchListener listener);
39
40
	/**
41
	 * Create a specific criteria for the provider. Each provider must 
42
	 * implement a specific Criteria in a convenient approach for keep, 
43
	 * organize and deal with the {@link ICriterion}.
44
	 * @return {@link ICriteria}
45
	 */
46
	public ICriteria createCriteria();
47
48
	/**
49
	 * Create a specific {@link IRestriction} implementation for the provider. 
50
	 * This implementation will provide the methods to created and organize 
51
	 * the {@link ICriterion} that composes the search. The {@link Restriction} 
52
	 * is a simple implementation of this, but subclasses or new implementation 
53
	 * may be created as appropriate.
54
	 * 
55
	 * @return {@link IRestriction}
56
	 */
57
	public IRestriction createSelection();
58
59
	/**
60
	 * Each provider can inform the user properties fields
61
	 * to be considered on the user search, allowing the 
62
	 * dynamically user interface for the search.
63
	 * @return String[] user properties provides by server
64
	 * @throws ContainerConnectException 
65
	 */
66
	public String[] getUserPropertiesFields() throws ContainerConnectException;
67
68
	/**
69
	 * Whether this handler is capable of executing at this time.
70
	 * @return boolean
71
	 */
72
	public boolean isEnabled();
73
}
(-)src/org/eclipse/ecf/presence/search/ICriterion.java (+30 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
11
package org.eclipse.ecf.presence.search;
12
13
/**
14
 * A representation of a query criterion for a restriction in a Criteria.
15
 * A Criteria is formed by one or several criterion, 
16
 * that together are able to compose an entire expression to project 
17
 * a result that match the criteria. The instances of this should be 
18
 * created for {@link IRestriction} implementations.
19
 * @since 3.0
20
 */
21
public interface ICriterion {
22
23
	/**
24
	 * Returns a expression composed for the search.
25
	 * The String can be something like 'field' + 'operator' + value, 
26
	 * that it will be interpreted for each specific provider.
27
	 * @return String
28
	 */
29
	public String toExpression();
30
}
(-)src/org/eclipse/ecf/presence/search/IUserSearchEvent.java (+20 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.search;
11
12
/**
13
 * An event received by a user search. This interface address the events 
14
 * that happens on user search API. There be different sub-interfaces of IUserSearchEvent to
15
 * represent different types of events.
16
 * @since 3.0
17
 */
18
public interface IUserSearchEvent {
19
	//
20
}
(-)src/org/eclipse/ecf/presence/search/UserSearchCompleteEvent.java (+28 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.search;
11
12
/**
13
 * 
14
 * @since 3.0
15
 */
16
public class UserSearchCompleteEvent implements IUserSearchCompleteEvent {
17
18
	private ISearch search;
19
20
	public UserSearchCompleteEvent(ISearch search) {
21
		this.search = search;
22
	}
23
24
	public ISearch getSearch() {
25
		return search;
26
	}
27
28
}
(-)src/org/eclipse/ecf/presence/search/Restriction.java (+71 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.search;
11
12
/**
13
 * This Class implements {@link IRestriction}. Subclasses may be created as
14
 * appropriate. It is just a simple implementation that can be considered 
15
 * for some provider or even used as base for some implementation.
16
 * @since 3.0
17
 */
18
public class Restriction implements IRestriction {
19
20
	/** Operator Equal */
21
	public static final String OPERATOR_EQ = "="; //$NON-NLS-1$
22
23
	/** Operator Not Equal */
24
	public static final String OPERATOR_NE = "!="; //$NON-NLS-1$
25
26
	/** Operator AND */
27
	public static final String OPERATOR_AND = "&&"; //$NON-NLS-1$
28
29
	/*
30
	 * (non-Javadoc)
31
	 * @see org.eclipse.ecf.presence.search.ISelection#and(org.eclipse.ecf.presence.search.ICriterion, org.eclipse.ecf.presence.search.ICriterion)
32
	 */
33
	public ICriterion and(ICriterion left, ICriterion right) {
34
		return new LogicalCriterion(left, right, OPERATOR_AND);
35
	}
36
37
	/*
38
	 * (non-Javadoc)
39
	 * @see org.eclipse.ecf.presence.search.ISelection#eq(java.lang.String, java.lang.String)
40
	 */
41
	public ICriterion eq(String field, String value) {
42
		return new SimpleCriterion(field, value, OPERATOR_EQ);
43
	}
44
45
	/*
46
	 * (non-Javadoc)
47
	 * @see org.eclipse.ecf.presence.search.ISelection#ne(java.lang.String, java.lang.String)
48
	 */
49
	public ICriterion ne(String field, String value) {
50
		return new SimpleCriterion(field, value, OPERATOR_NE);
51
	}
52
53
	/*
54
	 * (non-Javadoc)
55
	 * @see org.eclipse.ecf.presence.search.ISelection#eq(java.lang.String, java.lang.String, boolean)
56
	 */
57
	public ICriterion eq(String field, String value, boolean ignoreCase) {
58
		//TODO implement a criterion that supports ignore case approach
59
		return new SimpleCriterion(field, value, OPERATOR_EQ);
60
	}
61
62
	/*
63
	 * (non-Javadoc)
64
	 * @see org.eclipse.ecf.presence.search.ISelection#ne(java.lang.String, java.lang.String, boolean)
65
	 */
66
	public ICriterion ne(String field, String value, boolean ignoreCase) {
67
		//TODO implement a criterion that supports ignore case approach
68
		return new SimpleCriterion(field, value, OPERATOR_NE);
69
	}
70
71
}
(-)src/org/eclipse/ecf/presence/search/UserSearchException.java (+72 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.search;
11
12
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.ecf.core.util.ECFException;
14
15
/**
16
 * 
17
 * @since 3.0
18
 */
19
public class UserSearchException extends ECFException {
20
21
	/**
22
	 * 
23
	 */
24
	private static final long serialVersionUID = -896845055593390010L;
25
26
	private ICriteria criteria = null;
27
28
	/**
29
	 * 
30
	 */
31
	public UserSearchException(ICriteria criteria) {
32
		super();
33
		this.criteria = criteria;
34
	}
35
36
	/**
37
	 * @param status
38
	 */
39
	public UserSearchException(IStatus status, ICriteria criteria) {
40
		super(status);
41
		this.criteria = criteria;
42
	}
43
44
	/**
45
	 * @param message
46
	 * @param cause
47
	 */
48
	public UserSearchException(String message, Throwable cause, ICriteria criteria) {
49
		super(message, cause);
50
		this.criteria = criteria;
51
	}
52
53
	/**
54
	 * @param message
55
	 */
56
	public UserSearchException(String message, ICriteria criteria) {
57
		super(message);
58
		this.criteria = criteria;
59
	}
60
61
	/**
62
	 * @param cause
63
	 */
64
	public UserSearchException(Throwable cause, ICriteria criteria) {
65
		super(cause);
66
		this.criteria = criteria;
67
	}
68
69
	public ICriteria getSearchCriteria() {
70
		return this.criteria;
71
	}
72
}
(-)src/org/eclipse/ecf/presence/search/ISearch.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
11
package org.eclipse.ecf.presence.search;
12
13
/**
14
 * Provide access for the list of matched query results. This interface can be
15
 * extended to supply more features around the result list.
16
 * @since 3.0
17
 */
18
public interface ISearch {
19
20
	/**
21
	 * Gets a result list.
22
	 * Will not return <code>null</code>.
23
	 * @return IResultList list of {@link IResult} 
24
	 */
25
	IResultList getResultList();
26
27
	/**
28
	 * 
29
	 * @param IResultList
30
	 */
31
	public void setResultList(IResultList resultList);
32
33
}
(-)src/org/eclipse/ecf/presence/search/IRestriction.java (+61 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.search;
11
12
/**
13
 * Instances implementing this interface provide methods to compose the corrects operations for each
14
 * provide
15
 * @since 3.0
16
 */
17
public interface IRestriction {
18
19
	/**
20
	 * Apply an "add" constraint to the two criterion
21
	 * @param left
22
	 * @param right
23
	 * @return ICriterion
24
	 */
25
	public ICriterion and(ICriterion left, ICriterion right);
26
27
	/**
28
	 * Apply an "equal" constraint to the field, ignoring case
29
	 * @param field
30
	 * @param value
31
	 * @return ICriterion
32
	 */
33
	public ICriterion eq(String field, String value);
34
35
	/**
36
	 * Apply an "not equal" constraint to the field ignoring case
37
	 * @param field
38
	 * @param value
39
	 * @return ICriterion
40
	 */
41
	public ICriterion ne(String field, String value);
42
43
	/**
44
	 * Apply an "equal" constraint to the field, taking into consideration ignore case
45
	 * @param field
46
	 * @param value
47
	 * @param ignoreCase
48
	 * @return ICriterion
49
	 */
50
	public ICriterion eq(String field, String value, boolean ignoreCase);
51
52
	/**
53
	 * Apply an "not equal" constraint to the field, taking into consideration ignore case
54
	 * @param field
55
	 * @param value
56
	 * @param ignoreCase
57
	 * @return ICriterion
58
	 */
59
	public ICriterion ne(String field, String value, boolean ignoreCase);
60
61
}
(-)src/org/eclipse/ecf/presence/search/IResult.java (+28 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.search;
11
12
import org.eclipse.core.runtime.IAdaptable;
13
import org.eclipse.ecf.core.user.IUser;
14
15
/**
16
 * Each result returned for the search will be reach through this interface.
17
 * The result contain the user that match the search.
18
 * @since 3.0
19
 */
20
public interface IResult extends IAdaptable {
21
22
	/**
23
	 * Get user for the search. This is the user that comes from the search.
24
	 * 
25
	 * @return IUser user associated with the search.
26
	 */
27
	public IUser getUser();
28
}
(-)src/org/eclipse/ecf/presence/search/IUserSearchListener.java (+31 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.search;
11
12
/** 
13
 * This Interface allows for implementing classes to execute the search
14
 * for users in a non block way.
15
 * Note these methods will be called asynchronously not blocking a search action.
16
 * The provider is free to call the methods below with an arbitrary thread, so the
17
 * implementation of these methods must be appropriately prepared.
18
 * @since 3.0
19
 */
20
public interface IUserSearchListener {
21
22
	/**
23
	 * Catch the event fired and proceed to complete the search.
24
	 * Handle the search asynchronously. Notify that the search was completed 
25
	 * for the specific criteria.
26
	 * @param event the object that contains the composition of {@link ICriteria}
27
	 * and deal with the results in a non-blocking way
28
	 */
29
	public void handleUserSearchEvent(IUserSearchEvent event);
30
31
}
(-)src/org/eclipse/ecf/presence/search/SimpleCriterion.java (+83 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.search;
11
12
/**
13
 * 
14
 * Base class implementation of {@link ICriterion} for simple comparisons. Subclasses may be created as
15
 * appropriate.
16
 * @since 3.0
17
 */
18
public class SimpleCriterion implements ICriterion {
19
20
	protected final String field;
21
	protected final String value;
22
	protected final String operator;
23
	protected final boolean ignoreCase;
24
25
	/**
26
	 * Constructor for a instance of {@link ICriterion}
27
	 * @param field Name of the field
28
	 * @param value Value that match the search
29
	 * @param operator Operator opportune for the search 
30
	 * @param ignoreCase Consider case or not
31
	 */
32
	public SimpleCriterion(String field, String value, String operator, boolean ignoreCase) {
33
		this.field = field;
34
		this.value = value;
35
		this.operator = operator;
36
		this.ignoreCase = ignoreCase;
37
	}
38
39
	/**
40
	 * Constructor for a instance of {@link ICriterion}. This is 
41
	 * ignore case
42
	 * @param field Name of the field
43
	 * @param value Value that match the search
44
	 * @param operator Operator opportune for the search 
45
	 */
46
	public SimpleCriterion(String field, String value, String operator) {
47
		this.field = field;
48
		this.value = value;
49
		this.operator = operator;
50
		this.ignoreCase = false;
51
	}
52
53
	/*
54
	 * (non-Javadoc)
55
	 * @see org.eclipse.ecf.presence.search.ICriterion#toExpression()
56
	 */
57
	public String toExpression() {
58
		return field + ' ' + operator + ' ' + value;
59
	}
60
61
	public String toString() {
62
		StringBuffer sb = new StringBuffer("SimpleCriterion["); //$NON-NLS-1$
63
		sb.append("field=").append(field).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
64
		sb.append("value=").append(value).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
65
		sb.append("operator=").append(operator).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
66
		sb.append("ignoreCase=").append(ignoreCase).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
67
		return sb.toString();
68
	}
69
70
	public boolean equals(Object o) {
71
		if (this == o) {
72
			return true;
73
		}
74
		if (o instanceof String) {
75
			return o.equals(field);
76
		}
77
		return false;
78
	}
79
80
	public int hashCode() {
81
		return (field != null ? field.hashCode() : 0);
82
	}
83
}
(-)src/org/eclipse/ecf/presence/search/AbstractUserSearchManager.java (+86 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.presence.search;
11
12
import java.util.*;
13
14
/**
15
 * Abstract implementation of IUserSearchManager. Provides implementations of listener
16
 * methods that subsclasses may use to avoid having to implement them
17
 * themselves. This class may be subclassed as needed.
18
 * @since 3.0
19
 */
20
public abstract class AbstractUserSearchManager implements IUserSearchManager {
21
22
	private final List userSearchListeners = new ArrayList(5);
23
	protected ICriteria criteria;
24
25
	/**
26
	 * Add the listener to be notify by events
27
	 * @param listener
28
	 */
29
	public void addListener(IUserSearchListener l) {
30
		synchronized (userSearchListeners) {
31
			userSearchListeners.add(l);
32
		}
33
	}
34
35
	public void removeListener(IUserSearchListener l) {
36
		synchronized (userSearchListeners) {
37
			userSearchListeners.remove(l);
38
		}
39
	}
40
41
	/**
42
	 * Fires a user search event
43
	 * 
44
	 * @param event
45
	 */
46
	public void fireUserSearchEvent(IUserSearchEvent event) {
47
		List toNotify = null;
48
		// Copy array
49
		synchronized (userSearchListeners) {
50
			toNotify = new ArrayList(userSearchListeners);
51
		}
52
		// Notify all in toNotify
53
		for (Iterator i = toNotify.iterator(); i.hasNext();) {
54
			IUserSearchListener l = (IUserSearchListener) i.next();
55
			l.handleUserSearchEvent(event);
56
		}
57
	}
58
59
	/**
60
	 * Returns a default implementation for IUserSearchListner
61
	 * @return IUserSearchListener
62
	 */
63
	public IUserSearchListener getUserSearchListner() {
64
		return new UserListener();
65
	}
66
67
	public class UserListener implements IUserSearchListener {
68
69
		public void handleUserSearchEvent(IUserSearchEvent event) {
70
			try {
71
				if (event instanceof IUserSearchCompleteEvent) {
72
					//ISearch searchResult = ((IUserSearchCompleteEvent) event).getSearch();
73
				} else if (event instanceof IUserSearchEvent) {
74
					ISearch searchResult = search(criteria);
75
					fireUserSearchEvent(new UserSearchCompleteEvent(searchResult));
76
				}
77
78
			} catch (UserSearchException e) {
79
				e.printStackTrace();
80
			}
81
82
		}
83
84
	}
85
86
}
(-)src/org/eclipse/ecf/presence/search/IResultList.java (+38 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
11
package org.eclipse.ecf.presence.search;
12
13
import java.util.Collection;
14
import org.eclipse.core.runtime.IAdaptable;
15
16
/**
17
 * This interface provides methods to handle the result list that match the search.
18
 * @since 3.0
19
 */
20
public interface IResultList extends IAdaptable {
21
22
	/**
23
	 * Get results that match the search. Instances of list are of type
24
	 * {@link IResult}
25
	 * 
26
	 * @return Collection of IResult. Will not return <code>null</code>.
27
	 *         May return an empty Collection.
28
	 */
29
	public Collection geResults();
30
31
	/**
32
	 * Get the result that math the specific field and value
33
	 * @param field field's name used as argument to try to match the search
34
	 * @param value value for the respective field used as argument to try to match the search
35
	 * @return IResult will be null case it doesn't exist
36
	 */
37
	public IResult getResult(String field, String value);
38
}
(-)src/org/eclipse/ecf/internal/provider/msn/MSNContainer.java (+50 lines)
Lines 63-68 Link Here
63
import org.eclipse.ecf.presence.roster.IRosterManager;
63
import org.eclipse.ecf.presence.roster.IRosterManager;
64
import org.eclipse.ecf.presence.roster.IRosterSubscriptionListener;
64
import org.eclipse.ecf.presence.roster.IRosterSubscriptionListener;
65
import org.eclipse.ecf.presence.roster.IRosterSubscriptionSender;
65
import org.eclipse.ecf.presence.roster.IRosterSubscriptionSender;
66
import org.eclipse.ecf.presence.search.ICriteria;
67
import org.eclipse.ecf.presence.search.ISearch;
68
import org.eclipse.ecf.presence.search.IRestriction;
69
import org.eclipse.ecf.presence.search.IUserSearchListener;
70
import org.eclipse.ecf.presence.search.IUserSearchManager;
71
import org.eclipse.ecf.presence.search.UserSearchException;
66
import org.eclipse.ecf.presence.service.IPresenceService;
72
import org.eclipse.ecf.presence.service.IPresenceService;
67
import org.eclipse.ecf.protocol.msn.ChatSession;
73
import org.eclipse.ecf.protocol.msn.ChatSession;
68
import org.eclipse.ecf.protocol.msn.Contact;
74
import org.eclipse.ecf.protocol.msn.Contact;
Lines 758-761 Link Here
758
		return null;
764
		return null;
759
	}
765
	}
760
766
767
	/**
768
	 * TODO Implement a User Search Manager for MSN
769
	 * for while it just returns a manger
770
	 * to inform that user search is not allow
771
	 * for this provider see {@link IUserSearchManager#isEnabled()}
772
	 */
773
	public IUserSearchManager getUserSearchManager() {
774
		return new IUserSearchManager(){
775
776
			public ICriteria createCriteria() {
777
				// TODO Auto-generated method stub
778
				return null;
779
			}
780
781
			public IRestriction createSelection() {
782
				// TODO Auto-generated method stub
783
				return null;
784
			}
785
786
			public String[] getUserPropertiesFields()
787
					throws ContainerConnectException {
788
				// TODO Auto-generated method stub
789
				return null;
790
			}
791
792
			public boolean isEnabled() {
793
				// TODO Auto-generated method stub
794
				return false;
795
			}
796
797
			public ISearch search(ICriteria criteria)
798
					throws UserSearchException {
799
				// TODO Auto-generated method stub
800
				return null;
801
			}
802
803
			public void search(ICriteria criteria, IUserSearchListener listener) {
804
				// TODO Auto-generated method stub
805
				
806
			}
807
			
808
		};
809
	}
810
761
}
811
}
(-)src/org/eclipse/ecf/tests/presence/AbstractSearchTest.java (+23 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 	Marcelo Mayworm - initial API and implementation
8
 *
9
 ******************************************************************************/
10
package org.eclipse.ecf.tests.presence;
11
12
13
public abstract class AbstractSearchTest extends AbstractPresenceTestCase {
14
15
	public static final int CLIENT_COUNT = 1;
16
	public static final int WAITTIME = 3000;
17
18
	protected void setUp() throws Exception {
19
		setClientCount(CLIENT_COUNT);
20
		clients = createClients();
21
	}
22
23
}

Return to bug 256696