1 20 21 package org.apache.directory.ldapstudio.browser.ui.editors.schemabrowser; 22 23 24 import java.util.HashSet ; 25 import java.util.Set ; 26 27 import org.apache.directory.ldapstudio.browser.core.model.schema.LdapSyntaxDescription; 28 import org.apache.directory.ldapstudio.browser.core.model.schema.Schema; 29 import org.eclipse.jface.viewers.IStructuredContentProvider; 30 import org.eclipse.jface.viewers.ITableLabelProvider; 31 import org.eclipse.jface.viewers.LabelProvider; 32 import org.eclipse.jface.viewers.Viewer; 33 import org.eclipse.jface.viewers.ViewerFilter; 34 import org.eclipse.jface.viewers.ViewerSorter; 35 import org.eclipse.swt.graphics.Image; 36 37 38 45 public class LdapSyntaxDescriptionPage extends SchemaPage 46 { 47 48 53 public LdapSyntaxDescriptionPage( SchemaBrowser schemaBrowser ) 54 { 55 super( schemaBrowser ); 56 } 57 58 59 62 protected String getTitle() 63 { 64 return "Syntaxes"; 65 } 66 67 68 71 protected String getFilterDescription() 72 { 73 return "Please select a syntax. Enter a filter to restrict the list."; 74 } 75 76 77 80 protected IStructuredContentProvider getContentProvider() 81 { 82 return new LSDContentProvider(); 83 } 84 85 86 89 protected ITableLabelProvider getLabelProvider() 90 { 91 return new LSDLabelProvider(); 92 } 93 94 95 98 protected ViewerSorter getSorter() 99 { 100 return new LSDViewerSorter(); 101 } 102 103 104 107 protected ViewerFilter getFilter() 108 { 109 return new LSDViewerFilter(); 110 } 111 112 113 116 protected SchemaDetailsPage getDetailsPage() 117 { 118 return new LdapSyntaxDescriptionDetailsPage( this, this.toolkit ); 119 } 120 121 127 private class LSDContentProvider implements IStructuredContentProvider 128 { 129 132 public Object [] getElements( Object inputElement ) 133 { 134 if ( inputElement instanceof Schema ) 135 { 136 Schema schema = ( Schema ) inputElement; 137 if ( schema != null && schema.getLsdMapByNumericOID() != null ) 138 { 139 Set <Object > set = new HashSet <Object >( schema.getLsdMapByNumericOID().values() ); 140 return set.toArray(); 141 } 142 } 143 return new Object [0]; 144 } 145 146 147 150 public void dispose() 151 { 152 } 153 154 155 158 public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) 159 { 160 } 161 } 162 163 169 private class LSDLabelProvider extends LabelProvider implements ITableLabelProvider 170 { 171 174 public String getColumnText( Object obj, int index ) 175 { 176 return obj.toString(); 177 } 178 179 180 183 public Image getColumnImage( Object obj, int index ) 184 { 185 return null; 186 } 187 } 188 189 195 private class LSDViewerSorter extends ViewerSorter 196 { 197 200 public int compare( Viewer viewer, Object e1, Object e2 ) 201 { 202 return e1.toString().compareTo( e2.toString() ); 203 } 204 } 205 206 212 private class LSDViewerFilter extends ViewerFilter 213 { 214 217 public boolean select( Viewer viewer, Object parentElement, Object element ) 218 { 219 if ( element instanceof LdapSyntaxDescription ) 220 { 221 LdapSyntaxDescription lsd = ( LdapSyntaxDescription ) element; 222 boolean matched = false; 223 224 if ( !matched ) 225 matched = lsd.toString().toLowerCase().indexOf( filterText.getText().toLowerCase() ) != -1; 226 if ( !matched ) 227 matched = lsd.getNumericOID().toLowerCase().indexOf( filterText.getText().toLowerCase() ) != -1; 228 229 return matched; 230 } 231 return false; 232 } 233 } 234 235 } 236 | Popular Tags |