/** * */ package com.topsun.posclient.application; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.action.ControlContribution; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Widget; public class ContributionItemControl extends ControlContribution implements IAdaptable { private Control control; private IControlCreator creator; public ContributionItemControl(String id, IControlCreator creator) { super(id); this.creator = creator; } @Override protected Control createControl(Composite parent) { control = creator.createControl(parent); return control; } public Control getControl() { return control; } public void dispose() { if (control != null && !control.isDisposed()) { control.dispose(); } } @SuppressWarnings("rawtypes") public Object getAdapter(Class adapter) { if (adapter == null) { return null; } if (Widget.class.isAssignableFrom(adapter)) { return control; } if (IControlCreator.class.isAssignableFrom(adapter)) { return creator; } return null; } }