mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Moving to root below branch label
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.web.app.context;
|
||||
|
||||
/**
|
||||
* Interface used to allow Beans to register themselves as interested in UI context events.
|
||||
* <p>
|
||||
* Beans supporting this interface should be register against the UIContextService. Then Beans
|
||||
* which wish to indicate that the UI should refresh itself i.e. dump all cached data and settings,
|
||||
* call the UIContextService.notifyBeans() to inform all registered instances of the change.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public interface IContextListener
|
||||
{
|
||||
/**
|
||||
* Method called by UIContextService.notifyBeans() to inform all registered beans that
|
||||
* all UI Beans should refresh dump all cached data and settings.
|
||||
*/
|
||||
public void contextUpdated();
|
||||
}
|
106
source/java/org/alfresco/web/app/context/UIContextService.java
Normal file
106
source/java/org/alfresco/web/app/context/UIContextService.java
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.web.app.context;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
/**
|
||||
* Beans supporting the IContextListener interface are registered against this class. Then Beans
|
||||
* which wish to indicate that the UI should refresh itself i.e. dump all cached data and settings,
|
||||
* call the UIContextService.notifyBeans() to inform all registered instances of the change.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class UIContextService
|
||||
{
|
||||
/**
|
||||
* Private constructor
|
||||
*/
|
||||
private UIContextService()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Session local instance of the UIContextService
|
||||
*
|
||||
* @return UIContextService for this Thread
|
||||
*/
|
||||
public static UIContextService getInstance(FacesContext fc)
|
||||
{
|
||||
Map session = fc.getExternalContext().getSessionMap();
|
||||
UIContextService service = (UIContextService)session.get(CONTEXT_KEY);
|
||||
if (service == null)
|
||||
{
|
||||
service = new UIContextService();
|
||||
session.put(CONTEXT_KEY, service);
|
||||
}
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a bean to be informed of context events
|
||||
*
|
||||
* @param bean Conforming to the IContextListener interface
|
||||
*/
|
||||
public void registerBean(IContextListener bean)
|
||||
{
|
||||
if (bean == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Bean reference specified cannot be null!");
|
||||
}
|
||||
|
||||
this.registeredBeans.put(bean.getClass(), bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a bean reference from those notified of changes
|
||||
*
|
||||
* @param bean Conforming to the IContextListener interface
|
||||
*/
|
||||
public void unregisterBean(IContextListener bean)
|
||||
{
|
||||
if (bean == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Bean reference specified cannot be null!");
|
||||
}
|
||||
|
||||
this.registeredBeans.remove(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to notify all register beans that the UI context has changed and they should
|
||||
* refresh themselves as appropriate.
|
||||
*/
|
||||
public void notifyBeans()
|
||||
{
|
||||
for (IContextListener listener: this.registeredBeans.values())
|
||||
{
|
||||
listener.contextUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** key for the UI context service in the session */
|
||||
private final static String CONTEXT_KEY = "__uiContextService";
|
||||
|
||||
/** Map of bean registered against the context service */
|
||||
private Map<Class, IContextListener> registeredBeans = new HashMap<Class, IContextListener>(7, 1.0f);
|
||||
}
|
Reference in New Issue
Block a user