1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets.search; 22 23 24 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 25 import org.apache.directory.ldapstudio.browser.common.widgets.BrowserWidget; 26 import org.eclipse.swt.events.ModifyEvent; 27 import org.eclipse.swt.events.ModifyListener; 28 import org.eclipse.swt.events.VerifyEvent; 29 import org.eclipse.swt.events.VerifyListener; 30 import org.eclipse.swt.layout.GridLayout; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.Group; 33 import org.eclipse.swt.widgets.Label; 34 import org.eclipse.swt.widgets.Text; 35 36 37 44 public class LimitWidget extends BrowserWidget 45 { 46 47 48 private int initialCountLimit; 49 50 51 private int initialTimeLimit; 52 53 54 private Group limitGroup; 55 56 57 private Label countLimitLabel; 58 59 60 private Text countLimitText; 61 62 63 private Label timeLimitLabel; 64 65 66 private Text timeLimitText; 67 68 69 75 public LimitWidget( int initialCountLimit, int initialTimeLimit ) 76 { 77 this.initialCountLimit = initialCountLimit; 78 this.initialTimeLimit = initialTimeLimit; 79 } 80 81 82 85 public LimitWidget() 86 { 87 this.initialCountLimit = 0; 88 this.initialTimeLimit = 0; 89 } 90 91 92 97 public void createWidget( Composite parent ) 98 { 99 100 limitGroup = BaseWidgetUtils.createGroup( parent, "Limits", 1 ); 101 GridLayout gl = new GridLayout( 2, false ); 102 limitGroup.setLayout( gl ); 103 104 countLimitLabel = BaseWidgetUtils.createLabel( limitGroup, "&Count Limit:", 1 ); 106 countLimitText = BaseWidgetUtils.createText( limitGroup, "", 1 ); 107 countLimitText.addVerifyListener( new VerifyListener() 108 { 109 public void verifyText( VerifyEvent e ) 110 { 111 if ( !e.text.matches( "[0-9]*" ) ) 112 { 113 e.doit = false; 114 } 115 } 116 } ); 117 countLimitText.addModifyListener( new ModifyListener() 118 { 119 public void modifyText( ModifyEvent e ) 120 { 121 notifyListeners(); 122 } 123 } ); 124 125 timeLimitLabel = BaseWidgetUtils.createLabel( limitGroup, "&Time Limit:", 1 ); 127 timeLimitText = BaseWidgetUtils.createText( limitGroup, "", 1 ); 128 timeLimitText.addVerifyListener( new VerifyListener() 129 { 130 public void verifyText( VerifyEvent e ) 131 { 132 if ( !e.text.matches( "[0-9]*" ) ) 133 { 134 e.doit = false; 135 } 136 } 137 } ); 138 timeLimitText.addModifyListener( new ModifyListener() 139 { 140 public void modifyText( ModifyEvent e ) 141 { 142 notifyListeners(); 143 } 144 } ); 145 146 setCountLimit( initialCountLimit ); 147 setTimeLimit( initialTimeLimit ); 148 } 149 150 151 156 public void setCountLimit( int countLimit ) 157 { 158 initialCountLimit = countLimit; 159 countLimitText.setText( Integer.toString( initialCountLimit ) ); 160 } 161 162 163 168 public void setTimeLimit( int timeLimit ) 169 { 170 initialTimeLimit = timeLimit; 171 timeLimitText.setText( Integer.toString( initialTimeLimit ) ); 172 } 173 174 175 180 public int getCountLimit() 181 { 182 int countLimit; 183 try 184 { 185 countLimit = new Integer ( countLimitText.getText() ).intValue(); 186 } 187 catch ( NumberFormatException e ) 188 { 189 countLimit = 0; 190 } 191 return countLimit; 192 } 193 194 195 200 public int getTimeLimit() 201 { 202 int timeLimit; 203 try 204 { 205 timeLimit = new Integer ( timeLimitText.getText() ).intValue(); 206 } 207 catch ( NumberFormatException e ) 208 { 209 timeLimit = 0; 210 } 211 return timeLimit; 212 } 213 214 215 220 public void setEnabled( boolean b ) 221 { 222 limitGroup.setEnabled( b ); 223 countLimitLabel.setEnabled( b ); 224 countLimitText.setEnabled( b ); 225 timeLimitLabel.setEnabled( b ); 226 timeLimitText.setEnabled( b ); 227 } 228 229 } 230 | Popular Tags |