FileDocCategorySizeDatePackage
UIManagerImpl.javaAPI DocAzureus 3.0.3.412280Wed Sep 19 11:16:34 BST 2007org.gudy.azureus2.pluginsimpl.local.ui

UIManagerImpl

public class UIManagerImpl extends Object implements UIManager
author
parg

Fields Summary
protected static org.gudy.azureus2.core3.util.AEMonitor
class_mon
protected static boolean
initialisation_complete
protected static com.aelitis.azureus.core.util.CopyOnWriteList
ui_listeners
protected static com.aelitis.azureus.core.util.CopyOnWriteList
ui_event_listeners
protected static List
ui_factories
protected static List
ui_event_history
protected static List
configModels
protected org.gudy.azureus2.plugins.PluginInterface
pi
protected org.gudy.azureus2.plugins.PluginConfig
plugin_config
protected String
key_prefix
protected org.gudy.azureus2.plugins.ui.tables.TableManager
table_manager
protected org.gudy.azureus2.plugins.ui.menus.MenuManager
menu_manager
Constructors Summary
public UIManagerImpl(org.gudy.azureus2.plugins.PluginInterface _pi)

	
	
	
				 
	
		pi		=_pi;
		
		plugin_config	= pi.getPluginconfig();
		
		key_prefix		= plugin_config.getPluginConfigKeyPrefix();
		
		table_manager	= new TableManagerImpl( this );
		menu_manager	= new MenuManagerImpl( this );
	
Methods Summary
public voidaddUIEventListener(UIManagerEventListener listener)

		try{
  			class_mon.enter();
  			
  			ui_event_listeners.add( listener );
  			
  		}finally{
  			
  			class_mon.exit();
  		} 
  		
  		for (int i=0;i<ui_event_history.size();i++){
  			
  			try{
  				listener.eventOccurred((UIManagerEvent)ui_event_history.get(i));
  				
  			}catch( Throwable e ){
  				
  				Debug.printStackTrace(e);
  			}
  		}
  	
public voidaddUIListener(UIManagerListener listener)

		try{
  			class_mon.enter();
  			
  			ui_listeners.add( new Object[]{ listener, pi });
  			
 			if ( initialisation_complete ){
  				
  				for (int i=0;i<ui_factories.size();i++){
  					
  					UIInstanceFactory	instance = (UIInstanceFactory)ui_factories.get(i);

  					try{  						
  						listener.UIAttached( instance.getInstance( pi ));
  						
  					}catch( Throwable e ){
  						
  						Debug.printStackTrace(e);
  					}
  				}
  			}
  		}finally{
  			
  			class_mon.exit();
  		} 		
  	
public voidattachUI(UIInstanceFactory factory)

		try{
  			class_mon.enter();
  			
  			ui_factories.add( factory );
  			
  			if ( initialisation_complete ){
  							
  				Iterator it = ui_listeners.iterator();

  				while( it.hasNext()){
  					  					
  					Object[]	entry = (Object[])it.next();
  					
  					try{
  						((UIManagerListener)entry[0]).UIAttached( 
  								factory.getInstance((PluginInterface)entry[1]));
  						
  					}catch( Throwable e ){
  						
  						Debug.printStackTrace(e);
  					}
  				}
  			}
  		}finally{
  			
  			class_mon.exit();
  		}		
	
public voidcopyToClipBoard(java.lang.String data)

		boolean ok = fireEvent( UIManagerEvent.ET_COPY_TO_CLIPBOARD, data );
		
		if ( !ok ){
			
			throw( new UIException("Failed to deliver request to UI" ));
		}
	
public org.gudy.azureus2.plugins.ui.model.BasicPluginConfigModelcreateBasicPluginConfigModel(java.lang.String section_name)

		return( createBasicPluginConfigModel( ConfigSection.SECTION_PLUGINS, section_name ));
	
public org.gudy.azureus2.plugins.ui.model.BasicPluginConfigModelcreateBasicPluginConfigModel(java.lang.String parent_section, java.lang.String section_name)

		final BasicPluginConfigModel	model = new BasicPluginConfigModelImpl( this, parent_section, section_name );
		configModels.add(model);
		
		fireEvent( UIManagerEvent.ET_PLUGIN_CONFIG_MODEL_CREATED, model );
		
		return( model );
	
public org.gudy.azureus2.plugins.ui.model.BasicPluginViewModelcreateBasicPluginViewModel(java.lang.String name)

		final BasicPluginViewModel	model = new BasicPluginViewModelImpl( this, name );
				
		fireEvent( UIManagerEvent.ET_PLUGIN_VIEW_MODEL_CREATED, model );
		
		return( model );
	
public org.gudy.azureus2.plugins.PluginViewcreatePluginView(org.gudy.azureus2.plugins.ui.model.PluginViewModel model)

		try{
			return( SWTManagerImpl.getSingleton().createPluginView( model ));
	
		}catch( Throwable e ){
			
			return( null );
		}
	
public voiddestroy(org.gudy.azureus2.plugins.ui.model.BasicPluginViewModel model)

		fireEvent( UIManagerEvent.ET_PLUGIN_VIEW_MODEL_DESTROYED, model );
	
public voiddestroy(org.gudy.azureus2.plugins.ui.model.BasicPluginConfigModel model)

		configModels.remove(model);
		fireEvent( UIManagerEvent.ET_PLUGIN_CONFIG_MODEL_DESTROYED, model );
	
public voiddetachUI(UIInstanceFactory instance)

		try{
  			class_mon.enter();
  			
  			instance.detach();
  			
  			ui_factories.remove( instance );
  			
  			if ( initialisation_complete ){
  				
  				Iterator it = ui_listeners.iterator();

  				while( it.hasNext()){
  					
 					Object[]	entry = (Object[])it.next();
  					
  					try{
   						((UIManagerListener)entry[0]).UIDetached( 
   								instance.getInstance((PluginInterface)entry[1]));
  						
  					}catch( Throwable e ){
  						
  						Debug.printStackTrace(e);
  					}
  				}
  			}
  		}finally{
  			
  			class_mon.exit();
  		}		
	
public static booleanfireEvent(int type, java.lang.Object data)

		return( fireEvent( new UIManagerEventAdapter( type, data )));
 	
public static booleanfireEvent(UIManagerEvent event)

 		boolean	delivered	= false;
 		
		Iterator event_it = ui_event_listeners.iterator();

		while( event_it.hasNext()){
 			
 			try{
 				if (((UIManagerEventListener)event_it.next()).eventOccurred( event )){
 					
 					delivered = true;
 					
 					break;
 				}
 				
 			}catch( Throwable e ){
 				
 				e.printStackTrace();
 			}
 		}
 		
 		int	type = event.getType();
 		
 			// some events need to be replayed when new UIs attach
 		
 		if ( 	type == UIManagerEvent.ET_PLUGIN_VIEW_MODEL_CREATED ||
 				type == UIManagerEvent.ET_PLUGIN_CONFIG_MODEL_CREATED || 
 				type == UIManagerEvent.ET_ADD_TABLE_CONTEXT_MENU_ITEM ||
 				type == UIManagerEvent.ET_ADD_MENU_ITEM ||
 				type == UIManagerEvent.ET_REMOVE_TABLE_CONTEXT_MENU_ITEM ||
 				type == UIManagerEvent.ET_REMOVE_MENU_ITEM) {
 			
 			delivered = true;
 			
 			ui_event_history.add( event );
 			
 		}else if ( 	type == UIManagerEvent.ET_PLUGIN_VIEW_MODEL_DESTROYED ||
 					type == UIManagerEvent.ET_PLUGIN_CONFIG_MODEL_DESTROYED ){
 			
 				// remove any corresponding history events for creation of these entities
 			
 			delivered = true;
 			
 			Iterator 	history_it = ui_event_history.iterator();
 			
 			while( history_it.hasNext()){
 				
 				UIManagerEvent	e = (UIManagerEvent)history_it.next();
 			
 				int	e_type = e.getType();
 				
 				if ( 	e_type == UIManagerEvent.ET_PLUGIN_VIEW_MODEL_CREATED ||
 		 				e_type == UIManagerEvent.ET_PLUGIN_CONFIG_MODEL_CREATED ){
 		 
 					if ( e.getData() == event.getData()){
 						
 						history_it.remove();
 						
 						break;
 					}
 				}
 			}
 		}
 		
 		return( delivered );
 	
public org.gudy.azureus2.plugins.ui.model.BasicPluginViewModelgetBasicPluginViewModel(java.lang.String name)

		// grrr, RSSImport plugin directly uses this method
		
		return( createBasicPluginViewModel( name ));
		// throw( new RuntimeException( "Deprecated method - use createBasicPluginViewModel"));
	
public org.gudy.azureus2.plugins.ui.menus.MenuManagergetMenuManager()

	  return menu_manager;
  
public org.gudy.azureus2.plugins.ui.model.PluginConfigModel[]getPluginConfigModels()

		return (PluginConfigModel[]) configModels.toArray(new PluginConfigModel[0]);
	
public org.gudy.azureus2.plugins.PluginInterfacegetPluginInterface()

		return( pi );
	
public org.gudy.azureus2.plugins.ui.SWT.SWTManagergetSWTManager()

    return SWTManagerImpl.getSingleton();
  
public org.gudy.azureus2.plugins.ui.tables.TableManagergetTableManager()

    return( table_manager );
  
public UIInstance[]getUIInstances()

 		try {
  			class_mon.enter();
  			ArrayList result = new ArrayList(ui_factories.size());
  			for (int i=0;i<ui_factories.size();i++){
  				UIInstanceFactory instance = (UIInstanceFactory)ui_factories.get(i);
  				result.add(instance.getInstance(pi));
  			}
  			return (UIInstance[])result.toArray(new UIInstance[result.size()]);
 		}
 		finally {
 			class_mon.exit();
 		}
 	
public booleanhasUIInstances()

return !ui_factories.isEmpty();
public static voidinitialisationComplete()

  		try{
  			class_mon.enter();
  			
  			initialisation_complete	= true;
  			
			for (int j=0;j<ui_factories.size();j++){

				UIInstanceFactory	instance = (UIInstanceFactory)ui_factories.get(j);
				
  				Iterator it = ui_listeners.iterator();

  				while( it.hasNext()){
  					
 					Object[]	entry = (Object[])it.next();
  					
  					try{
  						((UIManagerListener)entry[0]).UIAttached( 
  								instance.getInstance((PluginInterface)entry[1]) );
						
					}catch( Throwable e ){
						
						Debug.printStackTrace(e);
					}
				}  				
			}
  		}finally{
  			
  			class_mon.exit();
  		}
  	
public voidopenURL(java.net.URL url)

		boolean ok = fireEvent( UIManagerEvent.ET_OPEN_URL, url );
		
		if ( !ok ){
			
			throw( new UIException("Failed to deliver request to UI" ));
		}		
	
public voidremoveUIEventListener(UIManagerEventListener listener)

		try{
  			class_mon.enter();
  			
  			ui_event_listeners.remove( listener );
 			 
  		}finally{
  			
  			class_mon.exit();
  		}		
 	
public voidremoveUIListener(UIManagerListener listener)

		try{
  			class_mon.enter();

  			Iterator	it = ui_listeners.iterator();
  			
  			while( it.hasNext()){
  				
				Object[]	entry = (Object[])it.next();
					
				if ( entry[0] == listener ){
					
					it.remove();
				}
  			}
 			 
  		}finally{
  			
  			class_mon.exit();
  		}		
 	
public booleanshowConfigSection(java.lang.String sectionID)

		UIManagerEventAdapter event = new UIManagerEventAdapter(
				UIManagerEvent.ET_SHOW_CONFIG_SECTION, sectionID);
		if (!fireEvent(event))
			return false;

		if (event.getResult() instanceof Boolean)
			return false;

		return ((Boolean)event.getResult()).booleanValue();
	
public voidshowTextMessage(java.lang.String title_resource, java.lang.String message_resource, java.lang.String contents)

		fireEvent( UIManagerEvent.ET_SHOW_TEXT_MESSAGE, new String[]{ title_resource, message_resource, contents });