KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > bugs > EditQueryPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.bugs;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.FlowLayout JavaDoc;
24 import java.awt.Dialog JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.event.ActionListener JavaDoc;
27 import java.beans.PropertyVetoException JavaDoc;
28 import java.text.ParseException JavaDoc;
29 import java.text.SimpleDateFormat JavaDoc;
30 import java.util.Date JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Set JavaDoc;
33
34 import javax.swing.*;
35
36 import org.netbeans.modules.tasklist.bugs.BugQuery;
37 import org.netbeans.modules.tasklist.bugs.bugzilla.BugzillaQueryPanel;
38 import org.netbeans.modules.tasklist.bugs.bugzilla.SourcePanel;
39
40 import org.openide.DialogDescriptor;
41 import org.openide.ErrorManager;
42 import org.openide.NotifyDescriptor;
43 import org.openide.explorer.ExplorerManager;
44 import org.openide.explorer.view.BeanTreeView;
45 import org.openide.nodes.Node;
46 import org.openide.util.HelpCtx;
47 import org.openide.util.NbBundle;
48
49 /**
50  * This panel is the main panel show for a new query.
51  * The panel contains a dropdown box that contains the different bug engines
52  * available to the user to search aginst. It also contains another panel with
53  * the custom search parameters for each bug engine. This panel will be pulled in
54  * using reflection based on the name of the bugEngine picked.
55  *
56  * @todo have a default button they can click and set the query as a default query.
57  * this might end up being an "Add To Queries" button that will add the
58  * query to a list of saved queries
59  * @todo Finish all the getting of data from the other panel.
60  *
61  * @author serff
62  */

63 public final class EditQueryPanel extends JPanel {
64
65     private static final long serialVersionUID = 1;
66
67     /** A panel at the top to hold the combobox and label */
68     private JPanel mTopPanel;
69     /** a panel that holds the query part */
70     private JPanel mQueryPanel;
71     /** A label for the ComboBox */
72     private JLabel mEngineLabel;
73     /** a combox box for the bug engine choices */
74     private JComboBox mBugEngines;
75     /** A button panel */
76     private JPanel mButtonPanel;
77     /** A done button */
78     private JButton mDefaultButton;
79     
80     /** an instance of the query */
81     private BugQuery mQuery;
82     /** a flag to tell if we are editing this query or not */
83     private boolean mEditing;
84     
85     /** Creates a new instance of EditQueryPanel */
86     public EditQueryPanel(BugQuery query, boolean editing) {
87         mEditing = editing;
88         mQuery = query;
89         initComponents();
90     }
91     
92     private void initComponents() {
93         mTopPanel = new JPanel();
94         mEngineLabel = new JLabel();
95         mBugEngines = new JComboBox();
96         mButtonPanel = new JPanel();
97         mDefaultButton = new JButton();
98         
99         setLayout(new BorderLayout JavaDoc());
100
101         mEngineLabel.setText(NbBundle.getMessage(EditQueryPanel.class, "BugEngine_Label")); // NOI18N
102

103         //Now i have to get the list of bug engines
104
String JavaDoc[] engines = BugEngines.list();
105         for (int i= 0; i<engines.length; i++) {
106             mBugEngines.addItem(engines[i]);
107         }
108
109         mTopPanel.setLayout(new FlowLayout JavaDoc(FlowLayout.LEFT, 6, 6));
110         mTopPanel.add(mEngineLabel);
111         mTopPanel.add(mBugEngines);
112         
113         //now prepare the query panel
114
final JPanel hotSwap = new JPanel();
115         mQueryPanel = getQueryPanel((String JavaDoc)mBugEngines.getSelectedItem());
116         hotSwap.add(mQueryPanel);
117         mBugEngines.addActionListener(new ActionListener JavaDoc() {
118             public void actionPerformed(ActionEvent JavaDoc e) {
119                 hotSwap.removeAll();
120                 mQueryPanel = getQueryPanel((String JavaDoc)mBugEngines.getSelectedItem());
121                 hotSwap.add(mQueryPanel);
122                 hotSwap.revalidate();
123                 EditQueryPanel.this.repaint();
124             }
125         });
126
127         //Do the button panel
128
mDefaultButton.setText(NbBundle.getMessage(EditQueryPanel.class, "DefaultButton_Text"));
129         mDefaultButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
130             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
131                 defaultButtonActionPerformed(evt);
132             }
133         });
134         mDefaultButton.setEnabled(false);
135         mDefaultButton.setToolTipText("Not yet implemented");
136         mButtonPanel.setLayout(new FlowLayout JavaDoc(FlowLayout.RIGHT, 6, 6));
137         // mButtonPanel.add(mDefaultButton);
138

139         add(mTopPanel, BorderLayout.NORTH);
140         hotSwap.setBorder(BorderFactory.createEmptyBorder(0,6,0,6));
141         add(hotSwap, BorderLayout.CENTER);
142         add(mButtonPanel, BorderLayout.SOUTH);
143     }
144     
145     /**
146      * This method will use reflection to get the correct bug querypanel
147      * @param engineName the name of the bug engine they are going to use
148      */

149     public JPanel getQueryPanel(String JavaDoc engineName) {
150         // XXX force all to return JPanel
151
JPanel ret = null;
152         BugEngine engine = BugEngines.get(getBugEngine());
153         ret = (JPanel) engine.getQueryCustomizer(getQuery(), false);
154         assert ret instanceof QueryPanelIF : "Engine " + engine + " returned " + ret;
155         return ret;
156     }
157     
158     private void defaultButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
159         //get everything and populate the query object
160
mQuery.setBugEngine(((String JavaDoc)mBugEngines.getSelectedItem()));
161         mQuery = ((QueryPanelIF)mQueryPanel).getQueryOptions(mQuery);
162         
163         //set this somewhere...
164

165     }
166     
167     public BugQuery getQuery() {
168         mQuery.setBugEngine(((String JavaDoc)mBugEngines.getSelectedItem()));
169         if (mQueryPanel != null) {
170             mQuery = ((QueryPanelIF)mQueryPanel).getQueryOptions(mQuery);
171         }
172         return mQuery;
173     }
174     
175     public String JavaDoc getBugEngine() {
176         return (String JavaDoc)mBugEngines.getSelectedItem();
177     }
178     
179     public String JavaDoc getQueryString() {
180         return ((QueryPanelIF)mQueryPanel).getQueryOptions(mQuery).getQueryString();
181     }
182     
183     public String JavaDoc getBaseUrl() {
184         return ((QueryPanelIF)mQueryPanel).getQueryOptions(mQuery).getBaseUrl();
185     }
186 }
187
Popular Tags