79 lines
1.8 KiB
Java
79 lines
1.8 KiB
Java
package org.gcube.portets.user.message_conversations.client.ui;
|
|
|
|
import java.util.List;
|
|
|
|
import org.gcube.portets.user.message_conversations.shared.ConvMessage;
|
|
|
|
import com.google.gwt.view.client.HasData;
|
|
import com.google.gwt.view.client.ListDataProvider;
|
|
|
|
/**
|
|
* The data source for contact information used in the sample.
|
|
*/
|
|
public class MessageProvider {
|
|
|
|
/**
|
|
* The singleton instance of the database.
|
|
|
|
private static MessageProvider instance;
|
|
|
|
|
|
* Get the singleton instance of the contact database.
|
|
*
|
|
* @return the singleton instance
|
|
|
|
public static MessageProvider get() {
|
|
if (instance == null) {
|
|
instance = new MessageProvider();
|
|
}
|
|
return instance;
|
|
} */
|
|
|
|
/**
|
|
* The provider that holds the list of contacts in the database.
|
|
*/
|
|
private ListDataProvider<ConvMessage> dataProvider = new ListDataProvider<ConvMessage>();
|
|
|
|
|
|
public MessageProvider(List<ConvMessage> messages) {
|
|
List<ConvMessage> contacts = dataProvider.getList();
|
|
contacts.addAll(messages);
|
|
}
|
|
|
|
/**
|
|
* Add a new contact.
|
|
*
|
|
* @param contact the contact to add.
|
|
*/
|
|
public void addMessage(ConvMessage message) {
|
|
List<ConvMessage> contacts = dataProvider.getList();
|
|
// Remove the contact first so we don't add a duplicate.
|
|
contacts.remove(message);
|
|
contacts.add(message);
|
|
}
|
|
|
|
/**
|
|
* Add a display to the database. The current range of interest of the display
|
|
* will be populated with data.
|
|
*
|
|
* @param display a {@Link HasData}.
|
|
*/
|
|
public void addDataDisplay(HasData<ConvMessage> display) {
|
|
dataProvider.addDataDisplay(display);
|
|
}
|
|
|
|
|
|
public ListDataProvider<ConvMessage> getDataProvider() {
|
|
return dataProvider;
|
|
}
|
|
|
|
|
|
/**
|
|
* Refresh all displays.
|
|
*/
|
|
public void refreshDisplays() {
|
|
dataProvider.refresh();
|
|
}
|
|
|
|
|
|
} |