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.MatchingRuleUseDescription; 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 MatchingRuleUseDescriptionPage extends SchemaPage 46 { 47 48 54 public MatchingRuleUseDescriptionPage( SchemaBrowser schemaBrowser ) 55 { 56 super( schemaBrowser ); 57 } 58 59 60 63 protected String getTitle() 64 { 65 return "Matching Rule Use"; 66 } 67 68 69 72 protected String getFilterDescription() 73 { 74 return "Please select a matching rule. Enter a filter to restrict the list."; 75 } 76 77 78 81 protected IStructuredContentProvider getContentProvider() 82 { 83 return new MRUDContentProvider(); 84 } 85 86 87 90 protected ITableLabelProvider getLabelProvider() 91 { 92 return new MRUDLabelProvider(); 93 } 94 95 96 99 protected ViewerSorter getSorter() 100 { 101 return new MRUDViewerSorter(); 102 } 103 104 105 108 protected ViewerFilter getFilter() 109 { 110 return new MRUDViewerFilter(); 111 } 112 113 114 117 protected SchemaDetailsPage getDetailsPage() 118 { 119 return new MatchingRuleUseDescriptionDetailsPage( this, this.toolkit ); 120 } 121 122 128 class MRUDContentProvider implements IStructuredContentProvider 129 { 130 133 public Object [] getElements( Object inputElement ) 134 { 135 if ( inputElement instanceof Schema ) 136 { 137 Schema schema = ( Schema ) inputElement; 138 if ( schema != null && schema.getMrudMapByName() != null ) 139 { 140 Set <Object > set = new HashSet <Object >( schema.getMrudMapByName().values() ); 141 return set.toArray(); 142 } 143 } 144 return new Object [0]; 145 } 146 147 148 151 public void dispose() 152 { 153 } 154 155 156 159 public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) 160 { 161 } 162 } 163 164 170 class MRUDLabelProvider extends LabelProvider implements ITableLabelProvider 171 { 172 175 public String getColumnText( Object obj, int index ) 176 { 177 return obj.toString(); 178 } 179 180 181 184 public Image getColumnImage( Object obj, int index ) 185 { 186 return null; 187 } 188 } 189 190 196 class MRUDViewerSorter extends ViewerSorter 197 { 198 201 public int compare( Viewer viewer, Object e1, Object e2 ) 202 { 203 return e1.toString().compareTo( e2.toString() ); 204 } 205 } 206 207 213 class MRUDViewerFilter extends ViewerFilter 214 { 215 218 public boolean select( Viewer viewer, Object parentElement, Object element ) 219 { 220 if ( element instanceof MatchingRuleUseDescription ) 221 { 222 MatchingRuleUseDescription mrud = ( MatchingRuleUseDescription ) element; 223 boolean matched = false; 224 225 if ( !matched ) 226 matched = mrud.toString().toLowerCase().indexOf( filterText.getText().toLowerCase() ) != -1; 227 if ( !matched ) 228 matched = mrud.getNumericOID().toLowerCase().indexOf( filterText.getText().toLowerCase() ) != -1; 229 230 return matched; 231 } 232 return false; 233 } 234 } 235 236 } 237 | Popular Tags |