1 6 package com.nightlabs.ipanema.person.search; 7 8 import org.eclipse.swt.SWT; 9 import org.eclipse.swt.layout.GridData; 10 import org.eclipse.swt.layout.GridLayout; 11 import org.eclipse.swt.widgets.Combo; 12 import org.eclipse.swt.widgets.Composite; 13 import org.eclipse.swt.widgets.Control; 14 import org.eclipse.swt.widgets.Text; 15 16 import com.nightlabs.ipanema.person.AbstractPersonStructField; 17 import com.nightlabs.ipanema.person.id.PersonStructFieldID; 18 import com.nightlabs.ipanema.person.util.TextPersonSearchFilterItem; 19 import com.nightlabs.jdo.JdoPlugin; 20 import com.nightlabs.jdo.search.SearchFilterItem; 21 22 25 public class TextStructFieldSearchItemEditorHelper 26 extends PersonStructFieldSearchItemEditorHelper { 27 28 private Composite helperComposite; 29 private Combo comboMatchType; 30 private Text textNeedle; 31 32 35 public TextStructFieldSearchItemEditorHelper() { 36 super(); 37 } 38 39 42 public TextStructFieldSearchItemEditorHelper( 43 AbstractPersonStructField personStructField) { 44 super(personStructField); 45 } 46 47 protected class MatchTypeOrderEntry { 48 int matchType; 49 String displayName; 50 public MatchTypeOrderEntry(int matchType, String displayName) { 51 this.matchType = matchType; 52 this.displayName = displayName; 53 } 54 } 55 private MatchTypeOrderEntry[] matchTypeOrder = new MatchTypeOrderEntry[6]; 56 private MatchTypeOrderEntry setMatchTypeOrderEntry(int idx, int matchType, String displayName) { 57 MatchTypeOrderEntry result = new MatchTypeOrderEntry(matchType,displayName); 58 matchTypeOrder[idx] = result; 59 return result; 60 } 61 62 65 public Control getControl(Composite parent) { 66 if (helperComposite == null) { 67 helperComposite = new Composite(parent,SWT.NONE); 68 GridLayout wrapperLayout = new GridLayout(); 69 wrapperLayout.numColumns = 2; 70 wrapperLayout.makeColumnsEqualWidth = true; 71 helperComposite.setLayout(wrapperLayout); 72 helperComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); 73 74 comboMatchType = new Combo(helperComposite,SWT.READ_ONLY); 75 comboMatchType.add(setMatchTypeOrderEntry(0,SearchFilterItem.MATCHTYPE_CONTAINS,JdoPlugin.getResourceString("search.matchType"+SearchFilterItem.MATCHTYPE_CONTAINS)).displayName); 76 comboMatchType.add(setMatchTypeOrderEntry(1,SearchFilterItem.MATCHTYPE_NOTCONTAINS,JdoPlugin.getResourceString("search.matchType"+SearchFilterItem.MATCHTYPE_NOTCONTAINS)).displayName); 77 comboMatchType.add(setMatchTypeOrderEntry(2,SearchFilterItem.MATCHTYPE_BEGINSWITH,JdoPlugin.getResourceString("search.matchType"+SearchFilterItem.MATCHTYPE_BEGINSWITH)).displayName); 78 comboMatchType.add(setMatchTypeOrderEntry(3,SearchFilterItem.MATCHTYPE_ENDSWITH,JdoPlugin.getResourceString("search.matchType"+SearchFilterItem.MATCHTYPE_ENDSWITH)).displayName); 79 comboMatchType.add(setMatchTypeOrderEntry(4,SearchFilterItem.MATCHTYPE_EQUALS,JdoPlugin.getResourceString("search.matchType"+SearchFilterItem.MATCHTYPE_EQUALS)).displayName); 80 comboMatchType.add(setMatchTypeOrderEntry(5,SearchFilterItem.MATCHTYPE_NOTEQUALS,JdoPlugin.getResourceString("search.matchType"+SearchFilterItem.MATCHTYPE_NOTEQUALS)).displayName); 81 82 GridData gdCombo = new GridData(); 83 gdCombo.grabExcessHorizontalSpace = true; 84 gdCombo.horizontalAlignment = GridData.FILL; 85 comboMatchType.setLayoutData(gdCombo); 86 comboMatchType.select(SearchFilterItem.MATCHTYPE_DEFAULT-1); 87 88 textNeedle = new Text(helperComposite,SWT.BORDER); 89 GridData gd = new GridData(); 90 gd.grabExcessHorizontalSpace = true; 91 gd.horizontalAlignment = GridData.FILL; 92 textNeedle.setLayoutData(gd); 93 } 94 95 return helperComposite; 96 } 97 98 101 public SearchFilterItem getSearchFilterItem() { 102 PersonStructFieldID id = PersonStructFieldID.create( 103 personStructField.getPersonStructBlockOrganisationID(), 104 personStructField.getPersonStructBlockID(), 105 personStructField.getPersonStructFieldOrganisationID(), 106 personStructField.getPersonStructFieldID() 107 ); 108 int matchType = matchTypeOrder[comboMatchType.getSelectionIndex()].matchType; 109 String needle = textNeedle.getText(); 110 TextPersonSearchFilterItem result = new TextPersonSearchFilterItem( 111 id, 112 matchType, 113 needle 114 ); 115 return result; 116 } 117 118 121 public void close() { 122 } 123 124 } 125 | Popular Tags |