1 11 package org.eclipse.jface.action; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.widgets.Composite; 16 import org.eclipse.swt.widgets.Control; 17 import org.eclipse.swt.widgets.Menu; 18 import org.eclipse.swt.widgets.ToolBar; 19 import org.eclipse.swt.widgets.ToolItem; 20 21 30 public abstract class ControlContribution extends ContributionItem { 31 36 protected ControlContribution(String id) { 37 super(id); 38 } 39 40 53 protected int computeWidth(Control control) { 54 return control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x; 55 } 56 57 68 protected abstract Control createControl(Composite parent); 69 70 76 public final void fill(Composite parent) { 77 createControl(parent); 78 } 79 80 84 public final void fill(Menu parent, int index) { 85 Assert.isTrue(false, "Can't add a control to a menu"); } 87 88 96 public final void fill(ToolBar parent, int index) { 97 Control control = createControl(parent); 98 ToolItem ti = new ToolItem(parent, SWT.SEPARATOR, index); 99 ti.setControl(control); 100 ti.setWidth(computeWidth(control)); 101 } 102 } 103 | Popular Tags |