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.MatchingRuleDescription; 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 MatchingRuleDescriptionPage extends SchemaPage 46 { 47 48 53 public MatchingRuleDescriptionPage( SchemaBrowser schemaBrowser ) 54 { 55 super( schemaBrowser ); 56 } 57 58 59 62 protected String getTitle() 63 { 64 return "Matching Rules"; 65 } 66 67 68 71 protected String getFilterDescription() 72 { 73 return "Please select a matching rule. Enter a filter to restrict the list."; 74 } 75 76 77 80 protected IStructuredContentProvider getContentProvider() 81 { 82 return new MRDContentProvider(); 83 } 84 85 86 89 protected ITableLabelProvider getLabelProvider() 90 { 91 return new MRDLabelProvider(); 92 } 93 94 95 98 protected ViewerSorter getSorter() 99 { 100 return new MRDViewerSorter(); 101 } 102 103 104 107 protected ViewerFilter getFilter() 108 { 109 return new MRDViewerFilter(); 110 } 111 112 113 116 protected SchemaDetailsPage getDetailsPage() 117 { 118 return new MatchingRuleDescriptionDetailsPage( this, this.toolkit ); 119 } 120 121 127 private class MRDContentProvider 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.getMrdMapByName() != null ) 138 { 139 Set <Object > set = new HashSet <Object >( schema.getMrdMapByName().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 MRDLabelProvider 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 MRDViewerSorter 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 MRDViewerFilter extends ViewerFilter 213 { 214 217 public boolean select( Viewer viewer, Object parentElement, Object element ) 218 { 219 if ( element instanceof MatchingRuleDescription ) 220 { 221 MatchingRuleDescription mrd = ( MatchingRuleDescription ) element; 222 boolean matched = false; 223 224 if ( !matched ) 225 matched = mrd.toString().toLowerCase().indexOf( filterText.getText().toLowerCase() ) != -1; 226 if ( !matched ) 227 matched = mrd.getNumericOID().toLowerCase().indexOf( filterText.getText().toLowerCase() ) != -1; 228 229 return matched; 230 } 231 return false; 232 } 233 } 234 235 } 236 | Popular Tags |