KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > person > search > TextStructFieldSearchItemEditorHelper


1 /*
2  * Created on Dec 19, 2004
3  * by alex
4  *
5  */

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 /**
23  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
24  */

25 public class TextStructFieldSearchItemEditorHelper
26         extends PersonStructFieldSearchItemEditorHelper {
27
28     private Composite helperComposite;
29     private Combo comboMatchType;
30     private Text textNeedle;
31
32     /**
33      *
34      */

35     public TextStructFieldSearchItemEditorHelper() {
36         super();
37     }
38
39     /**
40      * @param personStructField
41      */

42     public TextStructFieldSearchItemEditorHelper(
43             AbstractPersonStructField personStructField) {
44         super(personStructField);
45     }
46
47     protected class MatchTypeOrderEntry {
48         int matchType;
49         String JavaDoc displayName;
50         public MatchTypeOrderEntry(int matchType, String JavaDoc 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 JavaDoc displayName) {
57         MatchTypeOrderEntry result = new MatchTypeOrderEntry(matchType,displayName);
58         matchTypeOrder[idx] = result;
59         return result;
60     }
61     
62     /**
63      * @see com.nightlabs.ipanema.person.search.PersonSearchFilterItemEditorHelper#getControl(org.eclipse.swt.widgets.Composite)
64      */

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     /**
99      * @see com.nightlabs.ipanema.person.search.PersonSearchFilterItemEditorHelper#getSearchFilterItem()
100      */

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 JavaDoc needle = textNeedle.getText();
110         TextPersonSearchFilterItem result = new TextPersonSearchFilterItem(
111             id,
112             matchType,
113             needle
114         );
115         return result;
116     }
117
118     /**
119      * @see com.nightlabs.ipanema.person.search.PersonSearchFilterItemEditorHelper#close()
120      */

121     public void close() {
122     }
123
124 }
125
Popular Tags