FileDocCategorySizeDatePackage
UISWTViewImpl.javaAPI DocAzureus 3.0.3.47526Wed Aug 30 21:45:40 BST 2006org.gudy.azureus2.ui.swt.pluginsimpl

UISWTViewImpl

public class UISWTViewImpl extends org.gudy.azureus2.ui.swt.views.AbstractIView implements org.gudy.azureus2.ui.swt.plugins.UISWTView
author
TuxPaper

Fields Summary
public static final String
CFG_PREFIX
private Object
dataSource
private final org.gudy.azureus2.ui.swt.plugins.UISWTViewEventListener
eventListener
private org.eclipse.swt.widgets.Composite
composite
private final String
sViewID
private int
iControlType
private boolean
bFirstGetCompositeCall
private final String
sParentID
private String
sTitle
Constructors Summary
public UISWTViewImpl(String sParentID, String sViewID, org.gudy.azureus2.ui.swt.plugins.UISWTViewEventListener eventListener)

param
sViewID
param
eventListener


	     	 
	      
			  
		this.sParentID = sParentID;
		this.sViewID = sViewID;
		this.eventListener = eventListener;

		if (!eventListener.eventOccurred(new UISWTViewEventImpl(this,
				UISWTViewEvent.TYPE_CREATE, this)))
			throw new Exception();
	
Methods Summary
public voidcloseView()

		try {
			
			UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
			if (uiFunctions != null) {
				uiFunctions.closePluginView(this);
			}
		} catch (Exception e) {
			Debug.out(e);
		}
	
public voiddataSourceChanged(java.lang.Object newDataSource)

		dataSource = newDataSource;

		triggerEvent(UISWTViewEvent.TYPE_DATASOURCE_CHANGED, newDataSource);
	
public voiddelete()

		triggerEvent(UISWTViewEvent.TYPE_DESTROY, null);
		super.delete();
	
public org.eclipse.swt.widgets.CompositegetComposite()

		if (bFirstGetCompositeCall) {
			bFirstGetCompositeCall = false;
		}
		return composite;
	
public java.lang.StringgetData()

		final String key = CFG_PREFIX + sViewID + ".title";
		if (MessageText.keyExists(key))
			return key;
		// For now, to get plugin developers to update their plugins
		// return key;
		// For release, change it to this, to make it at least shorter:
		return sViewID;
	
public java.lang.ObjectgetDataSource()

		return dataSource;
	
public java.lang.StringgetFullTitle()

		if (sTitle != null)
			return sTitle;

		return super.getFullTitle();
	
public java.lang.StringgetParentID()

		return sParentID;
	
public java.lang.StringgetViewID()

		return sViewID;
	
public voidinitialize(org.eclipse.swt.widgets.Composite parent)

		if (iControlType == UISWTView.CONTROLTYPE_SWT) {
			composite = new Composite(parent, SWT.NULL);
			GridLayout layout = new GridLayout(1, false);
			layout.marginHeight = 0;
			layout.marginWidth = 0;
			composite.setLayout(layout);
			GridData gridData = new GridData(GridData.FILL_BOTH);
			composite.setLayoutData(gridData);

			triggerEvent(UISWTViewEvent.TYPE_INITIALIZE, composite);
			
			if (composite.getLayout() instanceof GridLayout) {
				// Force children to have GridData layoutdata.
				Control[] children = composite.getChildren();
				for (int i = 0; i < children.length; i++) {
					Control control = children[i];
					Object layoutData = control.getLayoutData();
					if (layoutData == null || !(layoutData instanceof GridData)) {
						if (layoutData != null)
							Logger.log(new LogEvent(LogIDs.PLUGIN, LogEvent.LT_WARNING,
									"Plugin View '" + sViewID + "' tried to setLayouData of "
											+ control + " to a " + layoutData.getClass().getName()));
	
						if (children.length == 1)
							gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
						else
							gridData = new GridData();
						
						control.setLayoutData(gridData);
					}
				}
			}
		} else {
			composite = new Composite(parent, SWT.EMBEDDED);
			FillLayout layout = new FillLayout();
			layout.marginHeight = 0;
			layout.marginWidth = 0;
			composite.setLayout(layout);
			GridData gridData = new GridData(GridData.FILL_BOTH);
			composite.setLayoutData(gridData);

			Frame f = SWT_AWT.new_Frame(composite);

			Panel pan = new Panel();

			f.add(pan);

			triggerEvent(UISWTViewEvent.TYPE_INITIALIZE, pan);
		}
		
		if (composite != null) {
			composite.addListener(SWT.Activate, new Listener() {
				public void handleEvent(Event event) {
					triggerEvent(UISWTViewEvent.TYPE_FOCUSGAINED, null);
				}
			});
	
			composite.addListener(SWT.Deactivate, new Listener() {
				public void handleEvent(Event event) {
					triggerEvent(UISWTViewEvent.TYPE_FOCUSLOST, null);
				}
			});
		}
	
public voidrefresh()

		triggerEvent(UISWTViewEvent.TYPE_REFRESH, null);
	
public booleanrequestClose()

		return triggerEvent2(UISWTViewEvent.TYPE_CLOSE, null);
	
public voidsetControlType(int iControlType)

		if (iControlType == UISWTView.CONTROLTYPE_AWT
				|| iControlType == UISWTView.CONTROLTYPE_SWT)
			this.iControlType = iControlType;
	
public voidsetTitle(java.lang.String title)

		sTitle = title;
		
	
public voidtriggerEvent(int eventType, java.lang.Object data)

		try {
			eventListener.eventOccurred(new UISWTViewEventImpl(this, eventType, data));
		} catch (Throwable t) {
			throw (new UIRuntimeException("UISWTView.triggerEvent:: ViewID="
					+ sViewID + "; EventID=" + eventType + "; data=" + data, t));
		}
	
private booleantriggerEvent2(int eventType, java.lang.Object data)

		try {
			return eventListener.eventOccurred(new UISWTViewEventImpl(this, eventType, data));
		} catch (Throwable t) {
			throw (new UIRuntimeException("UISWTView.triggerEvent:: ViewID="
					+ sViewID + "; EventID=" + eventType + "; data=" + data, t));
		}
	
public voidupdateLanguage()

		super.updateLanguage();

		triggerEvent(UISWTViewEvent.TYPE_LANGUAGEUPDATE, null);