1 20 21 package org.apache.directory.ldapstudio.valueeditors.integer; 22 23 24 import org.apache.directory.ldapstudio.valueeditors.ValueEditorsActivator; 25 import org.apache.directory.ldapstudio.valueeditors.ValueEditorsConstants; 26 import org.eclipse.jface.dialogs.Dialog; 27 import org.eclipse.jface.dialogs.IDialogConstants; 28 import org.eclipse.swt.SWT; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.layout.GridLayout; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.Control; 33 import org.eclipse.swt.widgets.Shell; 34 import org.eclipse.swt.widgets.Spinner; 35 36 37 43 public class IntegerDialog extends Dialog 44 { 45 46 47 public static final String DIALOG_TITLE = "Integer Editor"; 48 49 50 private int initialValue; 51 52 53 private int returnValue; 54 55 56 private Spinner spinner = null; 57 58 59 65 public IntegerDialog( Shell parentShell, int initialValue ) 66 { 67 super( parentShell ); 68 super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); 69 this.initialValue = initialValue; 70 this.returnValue = -1; 71 } 72 73 74 77 protected void configureShell( Shell shell ) 78 { 79 super.configureShell( shell ); 80 shell.setText( DIALOG_TITLE ); 81 shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_INTEGEREDITOR ) ); 82 } 83 84 85 88 protected void createButtonsForButtonBar( Composite parent ) 89 { 90 createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false ); 91 createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); 92 } 93 94 95 98 protected void okPressed() 99 { 100 returnValue = spinner.getSelection(); 101 super.okPressed(); 102 } 103 104 105 108 protected Control createDialogArea( Composite parent ) 109 { 110 Composite composite = ( Composite ) super.createDialogArea( parent ); 112 composite.setLayout( new GridLayout() ); 113 GridData gd = new GridData( GridData.FILL_BOTH ); 114 composite.setLayoutData( gd ); 115 116 spinner = new Spinner( composite, SWT.BORDER ); 117 spinner.setMinimum( 0 ); 118 spinner.setMaximum( Integer.MAX_VALUE ); 119 spinner.setDigits( 0 ); 120 spinner.setIncrement( 1 ); 121 spinner.setPageIncrement( 100 ); 122 spinner.setSelection( initialValue ); 123 spinner.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 124 125 applyDialogFont( composite ); 126 return composite; 127 } 128 129 130 135 public int getInteger() 136 { 137 return returnValue; 138 } 139 } 140 | Popular Tags |