KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > commands > QueryByTag


1 /*******************************************************************************
2  * Copyright (c) 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 package org.eclipse.pde.internal.ui.commands;
12
13 import org.eclipse.core.commands.Command;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.events.DisposeEvent;
16 import org.eclipse.swt.events.DisposeListener;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.widgets.Combo;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Group;
21
22 public class QueryByTag extends QueryControl {
23
24     private TagManager fTagManager;
25     private Combo fTagsCombo;
26     private TagManager.Listener fTagManagerListener;
27     
28     public QueryByTag(CommandComposerPart csp, Composite comp) {
29         super(csp, comp);
30     }
31     
32     protected void createGroupContents(Group parent) {
33         fTagManager = fCSP.getTagManager();
34         
35         fTagsCombo = new Combo(parent, SWT.READ_ONLY | SWT.DROP_DOWN);
36         fTagsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
37         fToolkit.adapt(fTagsCombo, true, true);
38         
39         fTagManagerListener = new TagManagerListener();
40         fCSP.getTagManager().addListener(fTagManagerListener);
41         
42         parent.addDisposeListener(new DisposeListener() {
43             public void widgetDisposed(DisposeEvent e) {
44                 if (fTagManagerListener != null) {
45                     fTagManager.removeListener(fTagManagerListener);
46                 }
47             }
48         });
49     }
50
51     protected String JavaDoc getName() {
52         return "Query Commands by Tags"; //$NON-NLS-1$
53
}
54     
55     private void refreshTags() {
56         fTagsCombo.removeAll();
57         String JavaDoc[] tags = fTagManager.getTags();
58         for (int i = 0; i < tags.length; i++) {
59             fTagsCombo.add(tags[i]);
60         }
61     }
62     
63     private class TagManagerListener implements TagManager.Listener {
64         public void tagManagerChanged() {
65             refreshTags();
66         }
67     }
68
69     protected Command[] getCommands() {
70         String JavaDoc tagText = fTagsCombo.getText();
71         return fCSP.getTagManager().getCommands(tagText);
72     }
73     
74     protected void enable(boolean enable) {
75         fGroup.setEnabled(enable);
76         fTagsCombo.setEnabled(enable);
77     }
78 }
79
Popular Tags