KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > DialogBookmarkFilter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.views.markers.internal;
13
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.events.ModifyEvent;
16 import org.eclipse.swt.events.ModifyListener;
17 import org.eclipse.swt.events.SelectionAdapter;
18 import org.eclipse.swt.events.SelectionEvent;
19 import org.eclipse.swt.events.TraverseEvent;
20 import org.eclipse.swt.events.TraverseListener;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Combo;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.Shell;
27 import org.eclipse.swt.widgets.Text;
28
29 /**
30  * DialogBookmarkFilter is the filter dialog for bookmarks
31  *
32  */

33 public class DialogBookmarkFilter extends DialogMarkerFilter {
34
35     private DescriptionGroup descriptionGroup;
36
37     private class DescriptionGroup {
38         private Label descriptionLabel;
39
40         private Combo combo;
41
42         private Text description;
43
44         private String JavaDoc contains = MarkerMessages.filtersDialog_contains;
45
46         private String JavaDoc doesNotContain =
47             MarkerMessages.filtersDialog_doesNotContain;
48
49         /**
50          * Create a description group.
51          *
52          * @param parent
53          */

54         public DescriptionGroup(Composite parent) {
55             descriptionLabel = new Label(parent, SWT.NONE);
56             descriptionLabel.setFont(parent.getFont());
57             descriptionLabel.setText(
58                 MarkerMessages.filtersDialog_descriptionLabel);
59
60             combo = new Combo(parent, SWT.READ_ONLY);
61             combo.setFont(parent.getFont());
62             combo.add(contains);
63             combo.add(doesNotContain);
64             combo.addSelectionListener(new SelectionAdapter(){
65                 /* (non-Javadoc)
66                  * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
67                  */

68                 public void widgetSelected(SelectionEvent e) {
69                       updateForSelection();
70                 }
71               });
72             // Prevent Esc and Return from closing the dialog when the combo is
73
// active.
74
combo.addTraverseListener(new TraverseListener() {
75                 public void keyTraversed(TraverseEvent e) {
76                     if (e.detail == SWT.TRAVERSE_ESCAPE
77                             || e.detail == SWT.TRAVERSE_RETURN) {
78                         e.doit = false;
79                     }
80                 }
81             });
82
83             description = new Text(parent, SWT.SINGLE | SWT.BORDER);
84             description.setFont(parent.getFont());
85             GridData data = new GridData(GridData.FILL_HORIZONTAL);
86             data.horizontalSpan = 3;
87             description.setLayoutData(data);
88             description.addModifyListener(new ModifyListener() {
89                 public void modifyText(ModifyEvent e) {
90                     DialogBookmarkFilter.this.markDirty();
91                 }
92             });
93         }
94
95         public boolean getContains() {
96             return combo.getSelectionIndex() == combo.indexOf(contains);
97         }
98
99         public void setContains(boolean value) {
100             if (value) {
101                 combo.select(combo.indexOf(contains));
102             } else {
103                 combo.select(combo.indexOf(doesNotContain));
104             }
105         }
106
107         public void setDescription(String JavaDoc text) {
108             if (text == null) {
109                 description.setText(""); //$NON-NLS-1$
110
} else {
111                 description.setText(text);
112             }
113         }
114
115         public String JavaDoc getDescription() {
116             return description.getText();
117         }
118
119         /**
120          * Update the enablement based on enabled.
121          * @param enabled
122          */

123         public void updateEnablement(boolean enabled) {
124             descriptionLabel.setEnabled(enabled);
125             combo.setEnabled(enabled);
126             description.setEnabled(enabled);
127         }
128     }
129
130     /**
131      * @param parentShell
132      * @param filters
133      */

134     public DialogBookmarkFilter(Shell parentShell, BookmarkFilter[] filters) {
135         super(parentShell, filters);
136     }
137
138     /*
139      * (non-Javadoc)
140      *
141      * @see org.eclipse.ui.views.markers.internal.DialogMarkerFilter#createAttributesArea(org.eclipse.swt.widgets.Composite)
142      */

143     protected void createAttributesArea(Composite parent) {
144         Composite composite = new Composite(parent, SWT.NONE);
145         composite.setFont(parent.getFont());
146         composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
147         GridLayout layout = new GridLayout(5, false);
148         layout.verticalSpacing = 7;
149         composite.setLayout(layout);
150
151         descriptionGroup = new DescriptionGroup(composite);
152     }
153
154     /* (non-Javadoc)
155      * @see org.eclipse.ui.views.markers.internal.DialogMarkerFilter#updateFilterFromUI(org.eclipse.ui.views.markers.internal.MarkerFilter)
156      */

157     protected void updateFilterFromUI(MarkerFilter filter) {
158         super.updateFilterFromUI(filter);
159
160         BookmarkFilter bookmark = (BookmarkFilter) filter;
161         bookmark.setContains(descriptionGroup.getContains());
162         bookmark.setDescription(descriptionGroup.getDescription().trim());
163     
164     }
165     
166     /* (non-Javadoc)
167      * @see org.eclipse.ui.views.markers.internal.DialogMarkerFilter#updateUIWithFilter(org.eclipse.ui.views.markers.internal.MarkerFilter)
168      */

169     protected void updateUIWithFilter(MarkerFilter filter) {
170         super.updateUIWithFilter(filter);
171         BookmarkFilter bookmark = (BookmarkFilter) filter;
172         descriptionGroup.setContains(bookmark.getContains());
173         descriptionGroup.setDescription(bookmark.getDescription());
174     }
175
176     /* (non-Javadoc)
177      * @see org.eclipse.ui.views.markers.internal.DialogMarkerFilter#updateEnabledState(boolean)
178      */

179     protected void updateEnabledState(boolean enabled) {
180         super.updateEnabledState(enabled);
181         descriptionGroup.updateEnablement(enabled);
182     }
183     
184
185     /*
186      * (non-Javadoc)
187      *
188      * @see org.eclipse.ui.views.markerview.FiltersDialog#resetPressed()
189      */

190     protected void resetPressed() {
191         descriptionGroup.setContains(BookmarkFilter.DEFAULT_CONTAINS);
192         descriptionGroup.setDescription(BookmarkFilter.DEFAULT_DESCRIPTION);
193
194         super.resetPressed();
195     }
196
197     /*
198      * (non-Javadoc)
199      *
200      * @see org.eclipse.ui.views.markers.internal.DialogMarkerFilter#newFilter(java.lang.String)
201      */

202     protected MarkerFilter newFilter(String JavaDoc newName) {
203
204         return new BookmarkFilter(newName);
205     }
206
207 }
208
Popular Tags