FileDocCategorySizeDatePackage
BasicPluginViewImpl.javaAPI DocAzureus 3.0.3.47965Wed Mar 28 17:58:52 BST 2007org.gudy.azureus2.ui.swt.pluginsimpl

BasicPluginViewImpl

public class BasicPluginViewImpl extends Object implements org.gudy.azureus2.ui.swt.plugins.UISWTViewEventListener, org.gudy.azureus2.plugins.ui.components.UIPropertyChangeListener

Fields Summary
org.gudy.azureus2.plugins.ui.model.BasicPluginViewModel
model
Display
display
Composite
panel
ProgressBar
progress
org.gudy.azureus2.ui.swt.components.BufferedLabel
status
org.gudy.azureus2.ui.swt.components.BufferedLabel
task
org.eclipse.swt.custom.StyledText
log
boolean
isCreated
Constructors Summary
public BasicPluginViewImpl(org.gudy.azureus2.plugins.ui.model.BasicPluginViewModel model)

    this.model = model;
    isCreated = false;
  
Methods Summary
private voiddelete()

    model.getLogArea().removePropertyChangeListener( this );
  
public booleaneventOccurred(org.gudy.azureus2.ui.swt.plugins.UISWTViewEvent event)

		switch (event.getType()) {
			case UISWTViewEvent.TYPE_CREATE:
				if (isCreated)
					return false;
				isCreated = true;
				break;
				
			case UISWTViewEvent.TYPE_INITIALIZE:
				initialize((Composite)event.getData());
				break;
			
			case UISWTViewEvent.TYPE_REFRESH:
				refresh();
				break;
			
			case UISWTViewEvent.TYPE_DESTROY:
				delete();
				isCreated = false;
				break;
		}
		return true;
	
private voidinitialize(Composite composite)

    GridData gridData;
    GridLayout gridLayout;
    String sConfigSectionID = model.getConfigSectionID();

    this.display = composite.getDisplay();
    panel = new Composite(composite,SWT.NULL);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    panel.setLayout(gridLayout);
		gridData = new GridData(GridData.FILL_BOTH);
		panel.setLayoutData(gridData);
    
    /*
     * Status       : [Status Text]
     * Current Task : [Task Text]
     * Progress     : [||||||||||----------]
     * Log :
     * [
     * 
     * 
     * ]
     */
		
	Composite topSection = new Composite(panel, SWT.NONE);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    topSection.setLayout(gridLayout);
	gridData = new GridData(GridData.FILL_HORIZONTAL);
	if (sConfigSectionID == null){
		gridData.horizontalSpan = 2;
	}
	topSection.setLayoutData(gridData);
    
    if(model.getStatus().getVisible()) {
      Label statusTitle = new Label(topSection,SWT.NULL);
      Messages.setLanguageText(statusTitle,"plugins.basicview.status");
    
      status = new BufferedLabel(topSection,SWT.NULL);
      gridData = new GridData(GridData.FILL_HORIZONTAL);
      status.setLayoutData(gridData);
    }
    
    if(model.getActivity().getVisible()) {
      Label activityTitle = new Label(topSection,SWT.NULL);
      Messages.setLanguageText(activityTitle,"plugins.basicview.activity");
    
      task = new BufferedLabel(topSection,SWT.NULL);
      gridData = new GridData(GridData.FILL_HORIZONTAL);
      task.setLayoutData(gridData);
    }
    
    if(model.getProgress().getVisible()) {
      Label progressTitle = new Label(topSection,SWT.NULL);
      Messages.setLanguageText(progressTitle,"plugins.basicview.progress");
    
      progress = new ProgressBar(topSection,SWT.NULL);
      progress.setMaximum(100);
      progress.setMinimum(0);
      gridData = new GridData(GridData.FILL_HORIZONTAL);
      progress.setLayoutData(gridData);
    }
    
    if (sConfigSectionID != null) {
    	Composite configSection = new Composite(panel, SWT.NONE);
        gridLayout = new GridLayout();
        gridLayout.numColumns = 1;
        gridLayout.marginHeight = 0;
        gridLayout.marginWidth = 2;
        configSection.setLayout(gridLayout);
        gridData = new GridData(GridData.END | GridData.VERTICAL_ALIGN_END );
        configSection.setLayoutData(gridData);
        //Label padding = new Label(configSection,SWT.NULL);
        //gridData = new GridData(GridData.FILL_HORIZONTAL);
        //padding.setLayoutData(gridData);
    	Button btnConfig = new Button(configSection, SWT.PUSH);
    	Messages.setLanguageText(btnConfig, "plugins.basicview.config");
    	btnConfig.addSelectionListener(new SelectionAdapter() {
    		public void widgetSelected(SelectionEvent e) {
       	 UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
      	 if (uiFunctions != null) {
      		 uiFunctions.showConfig(model.getConfigSectionID());
      	 }
    		}
    	});
    	btnConfig.setLayoutData(new GridData());
    }
    
    if(model.getLogArea().getVisible()) {
      Label logTitle = new Label(topSection,SWT.NULL);
      Messages.setLanguageText(logTitle,"plugins.basicview.log");
    //  gridData = new GridData(GridData.FILL_HORIZONTAL);
    //  gridData.horizontalSpan = 1;
    //  logTitle.setLayoutData(gridData);
      
      Button button = new Button( topSection, SWT.PUSH );
      Messages.setLanguageText(button,"plugins.basicview.clear");
      
      button.addListener(SWT.Selection, new Listener() {
  	      public void handleEvent(Event event) 
  	      {
  	      	model.getLogArea().setText("");
  	      }});

      log = new StyledText(panel,SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      log.setLayoutData(gridData);
      log.setText( model.getLogArea().getText());
      model.getLogArea().addPropertyChangeListener(this);
    }
  
public voidpropertyChanged(org.gudy.azureus2.plugins.ui.components.UIPropertyChangeEvent ev)

    if(ev.getSource() != model.getLogArea())
      return;
    if(display == null || display.isDisposed())
      return;
    if(log == null)
      return;
    display.asyncExec(new AERunnable(){
      public void runSupport() {
        if(log.isDisposed())
          return;
        String old_value = (String)ev.getOldPropertyValue();
        String new_value = (String) ev.getNewPropertyValue();
     
        if ( new_value.startsWith( old_value )){
               		
        	log.append( new_value.substring(old_value.length()));
       
        }else{
        	log.setText(new_value);
        }
      }
    });
  
private voidrefresh()

    if(status != null) {
      status.setText(model.getStatus().getText());
    }
    if(task != null) {
      task.setText(model.getActivity().getText());
    }
    if(progress != null) {
      progress.setSelection(model.getProgress().getPercentageComplete());
    }