1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets.search; 22 23 24 import org.apache.directory.ldapstudio.browser.common.widgets.BrowserWidget; 25 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.events.SelectionAdapter; 28 import org.eclipse.swt.events.SelectionEvent; 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.Composite; 33 import org.eclipse.swt.widgets.Group; 34 35 36 43 public class ScopeWidget extends BrowserWidget 44 { 45 46 47 private int initialScope; 48 49 50 private Group scopeGroup; 51 52 53 private Button scopeObjectButton; 54 55 56 private Button scopeOnelevelButton; 57 58 59 private Button scopeSubtreeButton; 60 61 62 69 public ScopeWidget( int initialScope ) 70 { 71 this.initialScope = initialScope; 72 } 73 74 75 79 public ScopeWidget() 80 { 81 this.initialScope = 0; 82 } 83 84 85 90 public void createWidget( Composite parent ) 91 { 92 93 scopeGroup = new Group( parent, SWT.NONE ); 95 scopeGroup.setText( "Scope" ); 96 scopeGroup.setLayout( new GridLayout( 1, false ) ); 97 scopeGroup.setLayoutData( new GridData( GridData.FILL_BOTH ) ); 98 99 scopeObjectButton = new Button( scopeGroup, SWT.RADIO ); 101 scopeObjectButton.setText( "&Object" ); 102 scopeObjectButton.addSelectionListener( new SelectionAdapter() 103 { 104 public void widgetSelected( SelectionEvent e ) 105 { 106 notifyListeners(); 107 } 108 } ); 109 110 scopeOnelevelButton = new Button( scopeGroup, SWT.RADIO ); 112 scopeOnelevelButton.setText( "One &Level" ); 113 scopeOnelevelButton.addSelectionListener( new SelectionAdapter() 114 { 115 public void widgetSelected( SelectionEvent e ) 116 { 117 notifyListeners(); 118 } 119 } ); 120 121 scopeSubtreeButton = new Button( scopeGroup, SWT.RADIO ); 123 scopeSubtreeButton.setText( "&Subtree" ); 124 scopeSubtreeButton.addSelectionListener( new SelectionAdapter() 125 { 126 public void widgetSelected( SelectionEvent e ) 127 { 128 notifyListeners(); 129 } 130 } ); 131 132 setScope( initialScope ); 133 } 134 135 136 142 public void setScope( int scope ) 143 { 144 initialScope = scope; 145 scopeObjectButton.setSelection( initialScope == ISearch.SCOPE_OBJECT ); 146 scopeOnelevelButton.setSelection( initialScope == ISearch.SCOPE_ONELEVEL ); 147 scopeSubtreeButton.setSelection( initialScope == ISearch.SCOPE_SUBTREE ); 148 } 149 150 151 157 public int getScope() 158 { 159 int scope; 160 161 if ( scopeSubtreeButton.getSelection() ) 162 { 163 scope = ISearch.SCOPE_SUBTREE; 164 } 165 else if ( scopeOnelevelButton.getSelection() ) 166 { 167 scope = ISearch.SCOPE_ONELEVEL; 168 } 169 else if ( scopeObjectButton.getSelection() ) 170 { 171 scope = ISearch.SCOPE_OBJECT; 172 } 173 else 174 { 175 scope = ISearch.SCOPE_ONELEVEL; 176 } 177 178 return scope; 179 } 180 181 182 187 public void setEnabled( boolean b ) 188 { 189 scopeGroup.setEnabled( b ); 190 scopeObjectButton.setEnabled( b ); 191 scopeOnelevelButton.setEnabled( b ); 192 scopeSubtreeButton.setEnabled( b ); 193 } 194 195 } 196 | Popular Tags |