1 20 package org.apache.directory.ldapstudio.proxy.view; 21 22 23 import org.eclipse.jface.dialogs.Dialog; 24 import org.eclipse.jface.dialogs.IDialogConstants; 25 import org.eclipse.jface.resource.JFaceResources; 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.graphics.FontMetrics; 28 import org.eclipse.swt.graphics.GC; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.layout.GridLayout; 31 import org.eclipse.swt.widgets.Button; 32 import org.eclipse.swt.widgets.Combo; 33 import org.eclipse.swt.widgets.Composite; 34 import org.eclipse.swt.widgets.Group; 35 import org.eclipse.swt.widgets.Label; 36 import org.eclipse.swt.widgets.Link; 37 import org.eclipse.swt.widgets.Text; 38 39 40 46 public class BaseWidgetUtils 47 { 48 public static Group createGroup( Composite parent, String label, int span ) 49 { 50 Group group = new Group( parent, SWT.NONE ); 51 GridData gd = new GridData( GridData.FILL_BOTH ); 52 gd.horizontalSpan = span; 53 group.setLayoutData( gd ); 54 group.setText( label ); 55 group.setLayout( new GridLayout() ); 56 return group; 57 } 58 59 60 public static Composite createColumnContainer( Composite parent, int columnCount, int span ) 61 { 62 Composite container = new Composite( parent, SWT.NONE ); 63 GridLayout gl = new GridLayout( columnCount, false ); 64 gl.marginHeight = gl.marginWidth = 0; 65 container.setLayout( gl ); 66 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 67 gd.horizontalSpan = span; 68 container.setLayoutData( gd ); 69 return container; 70 } 71 72 73 public static Label createLabel( Composite parent, String text, int span ) 74 { 75 Label l = new Label( parent, SWT.NONE ); 76 GridData gd = new GridData(); 77 gd.horizontalSpan = span; 78 l.setLayoutData( gd ); 80 l.setText( text ); 81 return l; 82 } 83 84 85 public static Label createWrappedLabel( Composite parent, String text, int span ) 86 { 87 Label l = new Label( parent, SWT.WRAP ); 88 GridData gd = new GridData(); 89 gd.horizontalSpan = span; 90 l.setLayoutData( gd ); 92 l.setText( text ); 93 return l; 94 } 95 96 97 public static Text createText( Composite parent, String text, int span ) 98 { 99 Text t = new Text( parent, SWT.NONE | SWT.BORDER ); 100 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 101 gd.horizontalSpan = span; 102 t.setLayoutData( gd ); 103 t.setText( text ); 104 return t; 105 } 106 107 108 public static Text createText( Composite parent, String text, int textWidth, int span ) 109 { 110 Text t = new Text( parent, SWT.NONE | SWT.BORDER ); 111 GridData gd = new GridData(); 112 gd.horizontalSpan = span; 113 gd.widthHint = 9 * textWidth; 114 t.setLayoutData( gd ); 115 t.setText( text ); 116 t.setTextLimit( textWidth ); 117 return t; 118 } 119 120 121 public static Text createPasswordText( Composite parent, String text, int span ) 122 { 123 Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.PASSWORD ); 124 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 125 gd.horizontalSpan = span; 126 t.setLayoutData( gd ); 127 t.setText( text ); 128 return t; 129 } 130 131 132 public static Text createReadonlyPasswordText( Composite parent, String text, int span ) 133 { 134 Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.PASSWORD | SWT.READ_ONLY ); 135 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 136 gd.horizontalSpan = span; 137 t.setLayoutData( gd ); 138 t.setEditable( false ); 139 t.setBackground( parent.getBackground() ); 140 t.setText( text ); 141 return t; 142 } 143 144 145 public static Text createLabeledText( Composite parent, String text, int span ) 146 { 147 Text t = new Text( parent, SWT.NONE ); 148 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 149 gd.horizontalSpan = span; 150 t.setLayoutData( gd ); 151 t.setEditable( false ); 152 t.setBackground( parent.getBackground() ); 153 t.setText( text ); 154 return t; 155 } 156 157 158 public static Text createWrappedLabeledText( Composite parent, String text, int span ) 159 { 160 Text t = new Text( parent, SWT.WRAP ); 161 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 162 gd.horizontalSpan = span; 163 gd.widthHint = 10; 164 gd.grabExcessHorizontalSpace = true; 165 gd.horizontalAlignment = GridData.FILL; 166 t.setLayoutData( gd ); 167 t.setEditable( false ); 168 t.setBackground( parent.getBackground() ); 169 t.setText( text ); 170 return t; 171 } 172 173 174 public static Text createReadonlyText( Composite parent, String text, int span ) 175 { 176 Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.READ_ONLY ); 177 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 178 gd.horizontalSpan = span; 179 t.setLayoutData( gd ); 180 t.setEditable( false ); 181 t.setBackground( parent.getBackground() ); 182 t.setText( text ); 183 return t; 184 } 185 186 187 public static String getNonNullString( String s ) 188 { 189 return s == null ? "-" : s; 190 } 191 192 193 public static Combo createCombo( Composite parent, String [] items, int selectedIndex, int span ) 194 { 195 Combo c = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER ); 196 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 197 gd.horizontalSpan = span; 198 c.setLayoutData( gd ); 199 c.setItems( items ); 200 c.select( selectedIndex ); 201 c.setVisibleItemCount( 20 ); 202 return c; 203 } 204 205 206 public static Combo createReadonlyCombo( Composite parent, String [] items, int selectedIndex, int span ) 207 { 208 Combo c = new Combo( parent, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); 209 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 210 gd.horizontalSpan = span; 211 c.setLayoutData( gd ); 212 c.setItems( items ); 214 c.select( selectedIndex ); 215 c.setVisibleItemCount( 20 ); 216 return c; 217 } 218 219 220 public static Combo createReadonlyReadonlyCombo( Composite parent, String [] items, int selectedIndex, int span ) 221 { 222 Combo c = new Combo( parent, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); 223 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 224 gd.horizontalSpan = span; 225 c.setLayoutData( gd ); 226 c.setBackground( parent.getBackground() ); 227 c.setItems( items ); 228 c.select( selectedIndex ); 229 c.setVisibleItemCount( 20 ); 230 return c; 231 } 232 233 234 public static Button createCheckbox( Composite composite, String text, int span ) 235 { 236 Button checkbox = new Button( composite, SWT.CHECK ); 237 checkbox.setText( text ); 238 GridData gd = new GridData(); 239 gd.horizontalSpan = span; 240 checkbox.setLayoutData( gd ); 241 return checkbox; 242 } 243 244 245 public static Button createRadiobutton( Composite composite, String text, int span ) 246 { 247 Button radio = new Button( composite, SWT.RADIO ); 248 radio.setText( text ); 249 GridData gd = new GridData(); 250 gd.horizontalSpan = span; 251 radio.setLayoutData( gd ); 252 return radio; 253 } 254 255 256 public static Button createButton( Composite composite, String text, int span ) 257 { 258 GC gc = new GC( composite ); 259 gc.setFont( JFaceResources.getDialogFont() ); 260 FontMetrics fontMetrics = gc.getFontMetrics(); 261 gc.dispose(); 262 263 Button button = new Button( composite, SWT.PUSH ); 264 GridData gd = new GridData(); 265 gd.widthHint = Dialog.convertHorizontalDLUsToPixels( fontMetrics, IDialogConstants.BUTTON_WIDTH ); 266 button.setLayoutData( gd ); 267 button.setText( text ); 268 return button; 269 } 270 271 272 public static void createRadioIndent( Composite composite, int span ) 273 { 274 Label l = new Label( composite, SWT.NONE ); 275 GridData gd = new GridData(); 276 gd.horizontalSpan = span; 277 gd.horizontalIndent = 22; 278 l.setLayoutData( gd ); 279 } 280 281 282 public static void createSpacer( Composite composite, int span ) 283 { 284 Label l = new Label( composite, SWT.NONE ); 285 GridData gd = new GridData(); 287 gd.horizontalSpan = span; 288 gd.heightHint = 1; 289 l.setLayoutData( gd ); 290 } 291 292 293 public static void createSeparator( Composite composite, int span ) 294 { 295 Label l = new Label( composite, SWT.SEPARATOR | SWT.HORIZONTAL ); 296 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 297 gd.horizontalSpan = span; 298 l.setLayoutData( gd ); 300 } 301 302 303 public static Link createLink( Composite parent, String text, int span ) 304 { 305 Link link = new Link( parent, SWT.NONE ); 306 link.setText( text ); 307 GridData gd = new GridData( SWT.FILL, SWT.BEGINNING, true, false ); 308 gd.horizontalSpan = span; 309 gd.widthHint = 150; 310 link.setLayoutData( gd ); 311 return link; 312 } 313 } 314 | Popular Tags |