1 20 21 package org.apache.directory.ldapstudio.schemas.view.search; 22 23 24 import org.apache.directory.ldapstudio.schemas.Messages; 25 import org.apache.directory.ldapstudio.schemas.PluginConstants; 26 import org.apache.directory.ldapstudio.schemas.view.views.SearchView; 27 import org.eclipse.jface.dialogs.DialogPage; 28 import org.eclipse.search.ui.ISearchPage; 29 import org.eclipse.search.ui.ISearchPageContainer; 30 import org.eclipse.swt.SWT; 31 import org.eclipse.swt.events.ModifyEvent; 32 import org.eclipse.swt.events.ModifyListener; 33 import org.eclipse.swt.layout.GridData; 34 import org.eclipse.swt.layout.GridLayout; 35 import org.eclipse.swt.widgets.Button; 36 import org.eclipse.swt.widgets.Combo; 37 import org.eclipse.swt.widgets.Composite; 38 import org.eclipse.swt.widgets.Group; 39 import org.eclipse.swt.widgets.Label; 40 import org.eclipse.ui.PlatformUI; 41 42 43 49 public class SearchPage extends DialogPage implements ISearchPage 50 { 51 private ISearchPageContainer container; 52 53 private Combo searchCombo; 55 private Button allMetadataButton; 56 private Button nameButton; 57 private Button oidButton; 58 private Button descriptionButon; 59 60 61 64 public void createControl( Composite parent ) 65 { 66 parent.setLayout( new GridLayout() ); 67 68 Label label = new Label( parent, SWT.NONE ); 69 label.setText( Messages.getString( "SearchPage.Search_string" ) ); label.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) ); 71 72 searchCombo = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER ); 73 searchCombo.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) ); 74 searchCombo.addModifyListener( new ModifyListener() 75 { 76 public void modifyText( ModifyEvent arg0 ) 77 { 78 validate(); 79 } 80 } ); 81 82 Group scopeGroup = new Group( parent, SWT.NONE ); 83 scopeGroup.setLayout( new GridLayout( 4, false ) ); 84 scopeGroup.setText( Messages.getString( "SearchPage.Scope" ) ); scopeGroup.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) ); 86 87 allMetadataButton = new Button( scopeGroup, SWT.RADIO ); 88 allMetadataButton.setText( Messages.getString( "SearchPage.All_metada" ) ); allMetadataButton.setSelection( true ); 90 91 nameButton = new Button( scopeGroup, SWT.RADIO ); 92 nameButton.setText( Messages.getString( "SearchPage.Name" ) ); 94 oidButton = new Button( scopeGroup, SWT.RADIO ); 95 oidButton.setText( Messages.getString( "SearchPage.OID" ) ); 97 descriptionButon = new Button( scopeGroup, SWT.RADIO ); 98 descriptionButon.setText( Messages.getString( "SearchPage.Description" ) ); 100 initSearchHistory(); 101 102 super.setControl( parent ); 103 } 104 105 106 109 private void initSearchHistory() 110 { 111 searchCombo.setItems( SearchView.loadHistory( PluginConstants.PREFS_SEARCH_VIEW_SEARCH_HISTORY ) ); 112 } 113 114 115 118 public boolean performAction() 119 { 120 SearchView searchView = ( SearchView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() 121 .findView( SearchView.ID ); 122 123 String scope = null; 124 125 if ( allMetadataButton.getSelection() ) 126 { 127 scope = SearchView.SEARCH_ALL; 128 } 129 else if ( nameButton.getSelection() ) 130 { 131 scope = SearchView.SEARCH_NAME; 132 } 133 else if ( oidButton.getSelection() ) 134 { 135 scope = SearchView.SEARCH_OID; 136 } 137 else if ( descriptionButon.getSelection() ) 138 { 139 scope = SearchView.SEARCH_DESC; 140 } 141 142 searchView.setSearch( searchCombo.getText(), scope ); 143 144 return true; 145 } 146 147 148 151 public void setContainer( ISearchPageContainer container ) 152 { 153 this.container = container; 154 } 155 156 157 160 public void setVisible( boolean visible ) 161 { 162 validate(); 163 super.setVisible( visible ); 164 } 165 166 167 173 private boolean isValid() 174 { 175 return ( ( searchCombo.getText() != null ) && ( !"".equals( searchCombo.getText() ) ) ); } 177 178 179 182 private void validate() 183 { 184 container.setPerformActionEnabled( isValid() ); 185 } 186 187 } 188 | Popular Tags |