1 20 21 package org.apache.directory.ldapstudio.schemas.view.views; 22 23 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.regex.Matcher ; 29 import java.util.regex.Pattern ; 30 31 import org.apache.directory.ldapstudio.schemas.Messages; 32 import org.apache.directory.ldapstudio.schemas.model.AttributeType; 33 import org.apache.directory.ldapstudio.schemas.model.ObjectClass; 34 import org.apache.directory.ldapstudio.schemas.model.SchemaElement; 35 import org.apache.directory.ldapstudio.schemas.model.SchemaPool; 36 import org.eclipse.jface.viewers.IStructuredContentProvider; 37 import org.eclipse.jface.viewers.Viewer; 38 import org.eclipse.ui.PlatformUI; 39 40 41 47 public class SearchViewContentProvider implements IStructuredContentProvider 48 { 49 50 private Map <String , ObjectClass> objectClassTable; 51 52 53 private Map <String , AttributeType> attributeTypeTable; 54 55 56 59 public SearchViewContentProvider() 60 { 61 SchemaPool schemaPool = SchemaPool.getInstance(); 62 objectClassTable = schemaPool.getObjectClassesAsMap(); 63 attributeTypeTable = schemaPool.getAttributeTypesAsMap(); 64 } 65 66 67 70 public Object [] getElements( Object parent ) 71 { 72 if ( parent instanceof String ) 73 { 74 String searchText = ( String ) parent; 75 76 SearchView view = ( SearchView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() 78 .findView( SearchView.ID ); 79 view.setPartName( Messages.getString( "SearchContentProvider.Search" ) ); 81 if ( searchText.length() > 0 ) 82 { 83 String searchRegexp = searchText + ".*"; Pattern pattern = Pattern.compile( searchRegexp, Pattern.CASE_INSENSITIVE ); 85 List <SchemaElement> resultsList = new ArrayList <SchemaElement>(); 86 87 Collection <ObjectClass> OCs = objectClassTable.values(); 88 Collection <AttributeType> ATs = attributeTypeTable.values(); 89 90 List <SchemaElement> allList = new ArrayList <SchemaElement>(); 91 allList.addAll( OCs ); 92 allList.addAll( ATs ); 93 94 for ( SchemaElement element : allList ) 96 { 97 98 if ( SearchView.currentSearchScope.equals( SearchView.SEARCH_NAME ) 99 || SearchView.currentSearchScope.equals( SearchView.SEARCH_ALL ) ) 100 { 101 String [] names = element.getNames(); 102 for ( String name : names ) 103 { 104 Matcher m = pattern.matcher( name ); 105 if ( m.matches() ) 106 { 107 if ( !resultsList.contains( element ) ) 108 { 109 resultsList.add( element ); 110 } 111 break; 112 } 113 } 114 } 115 116 if ( SearchView.currentSearchScope.equals( SearchView.SEARCH_OID ) 117 || SearchView.currentSearchScope.equals( SearchView.SEARCH_ALL ) ) 118 { 119 String oid = element.getOid(); 120 Matcher m = pattern.matcher( oid ); 121 if ( m.matches() ) 122 { 123 if ( !resultsList.contains( element ) ) 124 { 125 resultsList.add( element ); 126 } 127 128 } 129 } 130 131 if ( SearchView.currentSearchScope.equals( SearchView.SEARCH_DESC ) 132 || SearchView.currentSearchScope.equals( SearchView.SEARCH_ALL ) ) 133 { 134 String desc = element.getDescription(); 135 if ( desc == null ) 136 continue; 137 Matcher m = pattern.matcher( desc ); 138 if ( m.matches() ) 139 { 140 if ( !resultsList.contains( element ) ) 141 { 142 resultsList.add( element ); 143 } 144 } 145 } 146 } 147 148 view 150 .setPartName( Messages.getString( "SearchContentProvider.Search_(" ) + resultsList.size() + Messages.getString( "SearchContentProvider.Results)" ) ); 152 return resultsList.toArray(); 154 } 155 } 156 157 return new Object [0]; 158 } 159 160 161 164 public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) 165 { 166 } 167 168 169 172 public void dispose() 173 { 174 } 175 } 176 | Popular Tags |