com.extjs.gxt.ui.client.event.SelectionService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gxt Show documentation
Show all versions of gxt Show documentation
Rich Internet Application Framework for GWT
/*
* Sencha GXT 2.3.1a - Sencha for GWT
* Copyright(c) 2007-2013, Sencha, Inc.
* [email protected]
*
* http://www.sencha.com/products/gxt/license/
*/
package com.extjs.gxt.ui.client.event;
import java.util.ArrayList;
import java.util.List;
import com.extjs.gxt.ui.client.data.ModelData;
/**
* Provides a selection service where SelectionProviders
can
* register, allowing any listeners to be notified of selection events.
*/
public class SelectionService {
private static SelectionService instance = new SelectionService();
/**
* Returns the singleton instance.
*
* @return the service
*/
public static SelectionService get() {
return instance;
}
private SelectionChangedListener listener;
private List> providers;
private List> listeners;
private SelectionService() {
listener = new SelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
onSelectionChanged(event);
}
};
listeners = new ArrayList>();
providers = new ArrayList>();
}
/**
* Adds a listener to be notified of selection events from any registered
* selection providers.
*
* @param listener the listener to add
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public void addListener(SelectionChangedListener extends ModelData> listener) {
listeners.add((SelectionChangedListener)listener);
}
/**
* Returns a list of all current listeners.
*
* @return the listeners
*/
public List> getListeners() {
return new ArrayList>(listeners);
}
/**
* Returns the list of current providers.
*
* @return the providers
*/
public List> getProviders() {
return new ArrayList>(providers);
}
/**
* Registers a selection provider.
*
* @param provider the provider to add
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public void register(SelectionProvider extends ModelData> provider) {
provider.addSelectionChangedListener((SelectionChangedListener)listener);
providers.add((SelectionProvider)provider);
}
/**
* Removes a previously added listener.
*
* @param listener the listener to remove
*/
public void removeListener(SelectionChangedListener extends ModelData> listener) {
listeners.remove(listener);
}
/**
* Unregisters a selection provider.
*
* @param provider the provider to unregister
*/
public void unregister(SelectionProvider provider) {
provider.removeSelectionListener(listener);
providers.remove(provider);
}
/**
* Called when any selection changed event is received from any registered
* providers.
*
* @param event the selection changed event
*/
protected void onSelectionChanged(SelectionChangedEvent event) {
for (SelectionChangedListener l : listeners) {
l.selectionChanged(event);
}
}
}