You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by pr...@apache.org on 2002/07/31 22:33:11 UTC

cvs commit: jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/actions/listeners ActionActionListener.java

proyal      2002/07/31 13:33:11

  Added:       phyre/src/java/org/apache/avalon/phyre/actions Action.java
                        ActionFactory.java DefaultActionFactory.java
                        LoadSubContextAction.java
               phyre/src/java/org/apache/avalon/phyre/actions/listeners
                        ActionActionListener.java
  Log:
  an Action is a unit of work for the UI. Wrappers for an *Listener to perform
  an action are included
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/actions/Action.java
  
  Index: Action.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phyre.actions;
  
  import org.apache.avalon.framework.context.Context;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public interface Action
  {
      void perform( final Context ctx );
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/actions/ActionFactory.java
  
  Index: ActionFactory.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phyre.actions;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public interface ActionFactory
  {
      String ROLE = ActionFactory.class.getName();
  
      Action create( final String type, final Configuration configuration )
          throws ConfigurationException;
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/actions/DefaultActionFactory.java
  
  Index: DefaultActionFactory.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phyre.actions;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.ServiceSelector;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.phyre.container.ContentPanelHelper;
  import org.apache.avalon.phyre.container.PhyreContainer;
  import org.apache.avalon.phyre.container.SubContext;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public class DefaultActionFactory extends AbstractLogEnabled
      implements Serviceable, Contextualizable, ActionFactory
  {
      private static final String SWITCH_CONTENT_PANEL = "switch-content-panel";
      private static final String LOAD_SUB_CONTEXT = "load-subcontext";
  
      private ContentPanelHelper m_contentPanelHelper;
      private ServiceSelector m_panelSelector;
      private ServiceManager m_manager;
  
      public void contextualize( Context context )
          throws ContextException
      {
          m_contentPanelHelper = ( ContentPanelHelper ) context.get( ContentPanelHelper.CONTEXT );
      }
  
      public void service( ServiceManager manager )
          throws ServiceException
      {
          m_manager = manager;
          m_panelSelector = ( ServiceSelector ) manager.lookup( PhyreContainer.CONTENT_ROLE );
      }
  
      public Action create( final String type,
                            final Configuration configuration )
          throws ConfigurationException
      {
          if( SWITCH_CONTENT_PANEL.equals( type ) )
          {
              return new SwitchContentPanelAction( m_contentPanelHelper,
                                                   m_panelSelector,
                                                   configuration.getAttribute( "panel" ),
                                                   getLogger() );
          }
          else if( LOAD_SUB_CONTEXT.equals( type ) )
          {
              try
              {
                  final ServiceSelector selector =
                      ( ServiceSelector ) m_manager.lookup( SubContext.ROLE );
  
                  return new LoadSubContextAction(
                      configuration.getChild( "context-object-name" ).getValue(),
                      m_manager,
                      ( SubContext ) selector.select( configuration.getAttribute( "id" ) ),
                      getLogger() );
              }
              catch( ServiceException e )
              {
                  throw new ConfigurationException( "Unable to create action", e );
              }
          }
          else
          {
              throw new ConfigurationException( "Unknown action type: " + type );
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/actions/LoadSubContextAction.java
  
  Index: LoadSubContextAction.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phyre.actions;
  
  import org.apache.avalon.excalibur.property.PropertyUtil;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.phyre.container.SubContext;
  import org.apache.avalon.phyre.mbean.MBeanAccessor;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public class LoadSubContextAction implements Action
  {
      private final SubContext m_subContext;
      private final ServiceManager m_manager;
      private final String m_contextObjectName;
      private final Logger m_logger;
  
      public LoadSubContextAction( final String contextObjectName,
                                   final ServiceManager manager,
                                   final SubContext subContext,
                                   final Logger logger )
      {
          m_manager = manager;
          m_contextObjectName = contextObjectName;
          m_subContext = subContext;
          m_logger = logger;
      }
  
      public void perform( Context ctx )
      {
          try
          {
              final String objectName =
                  ( String ) PropertyUtil.resolveProperty( m_contextObjectName, ctx, false );
  
              m_subContext.load( ( MBeanAccessor ) m_manager.lookup( objectName ) );
          }
          catch( Exception e )
          {
              m_logger.error( "Unable to load subcontext", e );
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/actions/listeners/ActionActionListener.java
  
  Index: ActionActionListener.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phyre.actions.listeners;
  
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import org.apache.avalon.phyre.actions.Action;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public class ActionActionListener implements ActionListener
  {
      private final Action m_action;
  
      public ActionActionListener( Action action )
      {
          m_action = action;
      }
  
      public void actionPerformed( ActionEvent e )
      {
          if( ActionEvent.ACTION_PERFORMED == e.getID() )
          {
              m_action.perform( null );
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>