jlahoda@385
|
1 |
/*
|
jlahoda@385
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
jlahoda@385
|
3 |
*
|
jlahoda@552
|
4 |
* Copyright 2010-2011 Sun Microsystems, Inc. All rights reserved.
|
jlahoda@385
|
5 |
*
|
jlahoda@385
|
6 |
* The contents of this file are subject to the terms of either the GNU
|
jlahoda@385
|
7 |
* General Public License Version 2 only ("GPL") or the Common
|
jlahoda@385
|
8 |
* Development and Distribution License("CDDL") (collectively, the
|
jlahoda@385
|
9 |
* "License"). You may not use this file except in compliance with the
|
jlahoda@385
|
10 |
* License. You can obtain a copy of the License at
|
jlahoda@385
|
11 |
* http://www.netbeans.org/cddl-gplv2.html
|
jlahoda@385
|
12 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
jlahoda@385
|
13 |
* specific language governing permissions and limitations under the
|
jlahoda@385
|
14 |
* License. When distributing the software, include this License Header
|
jlahoda@385
|
15 |
* Notice in each file and include the License file at
|
jlahoda@385
|
16 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
|
jlahoda@385
|
17 |
* particular file as subject to the "Classpath" exception as provided
|
jlahoda@385
|
18 |
* by Sun in the GPL Version 2 section of the License file that
|
jlahoda@385
|
19 |
* accompanied this code. If applicable, add the following below the
|
jlahoda@385
|
20 |
* License Header, with the fields enclosed by brackets [] replaced by
|
jlahoda@385
|
21 |
* your own identifying information:
|
jlahoda@385
|
22 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
jlahoda@385
|
23 |
*
|
jlahoda@385
|
24 |
* If you wish your version of this file to be governed by only the CDDL
|
jlahoda@385
|
25 |
* or only the GPL Version 2, indicate your decision by adding
|
jlahoda@385
|
26 |
* "[Contributor] elects to include this software in this distribution
|
jlahoda@385
|
27 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
jlahoda@385
|
28 |
* single choice of license, a recipient has the option to distribute
|
jlahoda@385
|
29 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
jlahoda@385
|
30 |
* to extend the choice of license to its licensees as provided above.
|
jlahoda@385
|
31 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
jlahoda@385
|
32 |
* Version 2 license, then the option applies only if the new code is
|
jlahoda@385
|
33 |
* made subject to such option by the copyright holder.
|
jlahoda@385
|
34 |
*
|
jlahoda@385
|
35 |
* Contributor(s):
|
jlahoda@385
|
36 |
*
|
jlahoda@552
|
37 |
* Portions Copyrighted 2010-2011 Sun Microsystems, Inc.
|
jlahoda@385
|
38 |
*/
|
jlahoda@552
|
39 |
package org.netbeans.modules.jackpot30.impl.indexing.options;
|
jlahoda@385
|
40 |
|
jlahoda@419
|
41 |
import java.awt.Component;
|
jlahoda@385
|
42 |
import java.io.File;
|
jlahoda@385
|
43 |
import java.net.MalformedURLException;
|
jlahoda@385
|
44 |
import java.net.URISyntaxException;
|
jlahoda@385
|
45 |
import java.net.URL;
|
jlahoda@387
|
46 |
import java.text.DateFormat;
|
jlahoda@385
|
47 |
import java.util.Collection;
|
jlahoda@387
|
48 |
import java.util.Date;
|
jlahoda@419
|
49 |
import java.util.HashMap;
|
jlahoda@419
|
50 |
import java.util.Map;
|
jlahoda@385
|
51 |
import java.util.concurrent.atomic.AtomicBoolean;
|
jlahoda@385
|
52 |
import java.util.concurrent.atomic.AtomicReference;
|
jlahoda@387
|
53 |
import java.util.logging.Level;
|
jlahoda@387
|
54 |
import java.util.logging.Logger;
|
jlahoda@385
|
55 |
import javax.swing.DefaultComboBoxModel;
|
jlahoda@419
|
56 |
import javax.swing.DefaultListCellRenderer;
|
jlahoda@385
|
57 |
import javax.swing.JButton;
|
jlahoda@385
|
58 |
import javax.swing.JFileChooser;
|
jlahoda@419
|
59 |
import javax.swing.JList;
|
jlahoda@385
|
60 |
import javax.swing.JTextField;
|
jlahoda@385
|
61 |
import javax.swing.SwingUtilities;
|
jlahoda@387
|
62 |
import javax.swing.UIManager;
|
jlahoda@385
|
63 |
import javax.swing.event.DocumentEvent;
|
jlahoda@385
|
64 |
import javax.swing.event.DocumentListener;
|
jlahoda@387
|
65 |
import org.codeviation.pojson.Pojson;
|
jlahoda@385
|
66 |
import org.netbeans.modules.jackpot30.impl.WebUtilities;
|
jlahoda@387
|
67 |
import org.netbeans.modules.jackpot30.impl.indexing.IndexInfo;
|
jlahoda@552
|
68 |
import org.netbeans.modules.jackpot30.impl.indexing.RemoteIndex;
|
jlahoda@385
|
69 |
import org.openide.NotificationLineSupport;
|
jlahoda@385
|
70 |
import org.openide.util.RequestProcessor;
|
jlahoda@385
|
71 |
|
jlahoda@385
|
72 |
/**
|
jlahoda@385
|
73 |
*
|
jlahoda@385
|
74 |
* @author lahvac
|
jlahoda@385
|
75 |
*/
|
jlahoda@552
|
76 |
public class CustomizeRemoteIndex extends javax.swing.JPanel {
|
jlahoda@385
|
77 |
|
jlahoda@385
|
78 |
private final JButton okButton;
|
jlahoda@385
|
79 |
|
jlahoda@552
|
80 |
public CustomizeRemoteIndex(JButton okButton) {
|
jlahoda@385
|
81 |
this.okButton = okButton;
|
jlahoda@385
|
82 |
initComponents();
|
jlahoda@385
|
83 |
DocumentListener updateErrorsListener = new DocumentListener() {
|
jlahoda@385
|
84 |
public void insertUpdate(DocumentEvent e) {
|
jlahoda@385
|
85 |
updateErrors();
|
jlahoda@385
|
86 |
}
|
jlahoda@385
|
87 |
public void removeUpdate(DocumentEvent e) {
|
jlahoda@385
|
88 |
updateErrors();
|
jlahoda@385
|
89 |
}
|
jlahoda@385
|
90 |
public void changedUpdate(DocumentEvent e) {}
|
jlahoda@385
|
91 |
};
|
jlahoda@385
|
92 |
folder.getDocument().addDocumentListener(updateErrorsListener);
|
jlahoda@385
|
93 |
indexURL.getDocument().addDocumentListener(new DocumentListener() {
|
jlahoda@385
|
94 |
public void insertUpdate(DocumentEvent e) {
|
jlahoda@385
|
95 |
indexURLUpdated();
|
jlahoda@385
|
96 |
}
|
jlahoda@385
|
97 |
public void removeUpdate(DocumentEvent e) {
|
jlahoda@385
|
98 |
indexURLUpdated();
|
jlahoda@385
|
99 |
}
|
jlahoda@385
|
100 |
public void changedUpdate(DocumentEvent e) {
|
jlahoda@385
|
101 |
}
|
jlahoda@385
|
102 |
});
|
jlahoda@387
|
103 |
indexInfo.setFont(UIManager.getFont("Label.font"));
|
jlahoda@387
|
104 |
indexInfo.setBackground(UIManager.getColor("Label.background"));
|
jlahoda@387
|
105 |
indexInfo.setDisabledTextColor(UIManager.getColor("Label.foreground"));
|
jlahoda@385
|
106 |
}
|
jlahoda@385
|
107 |
|
jlahoda@385
|
108 |
/** This method is called from within the constructor to
|
jlahoda@385
|
109 |
* initialize the form.
|
jlahoda@385
|
110 |
* WARNING: Do NOT modify this code. The content of this method is
|
jlahoda@385
|
111 |
* always regenerated by the Form Editor.
|
jlahoda@385
|
112 |
*/
|
jlahoda@385
|
113 |
@SuppressWarnings("unchecked")
|
jlahoda@385
|
114 |
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
jlahoda@385
|
115 |
private void initComponents() {
|
jlahoda@385
|
116 |
java.awt.GridBagConstraints gridBagConstraints;
|
jlahoda@385
|
117 |
|
jlahoda@385
|
118 |
buttonGroup1 = new javax.swing.ButtonGroup();
|
jlahoda@385
|
119 |
folderPanel = new javax.swing.JPanel();
|
jlahoda@385
|
120 |
folderLabel = new javax.swing.JLabel();
|
jlahoda@385
|
121 |
folderChooser = new javax.swing.JButton();
|
jlahoda@385
|
122 |
folder = new javax.swing.JTextField();
|
jlahoda@552
|
123 |
indexInfo = new javax.swing.JTextArea();
|
jlahoda@385
|
124 |
remoteIndexPanel = new javax.swing.JPanel();
|
jlahoda@385
|
125 |
indexURL = new javax.swing.JTextField();
|
jlahoda@385
|
126 |
indexURLLabel = new javax.swing.JLabel();
|
jlahoda@385
|
127 |
subIndex = new javax.swing.JComboBox();
|
jlahoda@385
|
128 |
jLabel1 = new javax.swing.JLabel();
|
jlahoda@385
|
129 |
|
jlahoda@385
|
130 |
setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 12, 12));
|
jlahoda@385
|
131 |
setLayout(new java.awt.GridBagLayout());
|
jlahoda@385
|
132 |
|
jlahoda@385
|
133 |
folderPanel.setLayout(new java.awt.GridBagLayout());
|
jlahoda@385
|
134 |
|
jlahoda@552
|
135 |
org.openide.awt.Mnemonics.setLocalizedText(folderLabel, org.openide.util.NbBundle.getMessage(CustomizeRemoteIndex.class, "CustomizeRemoteIndex.folderLabel.text")); // NOI18N
|
jlahoda@385
|
136 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
jlahoda@385
|
137 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
|
jlahoda@385
|
138 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
|
jlahoda@385
|
139 |
folderPanel.add(folderLabel, gridBagConstraints);
|
jlahoda@385
|
140 |
|
jlahoda@552
|
141 |
org.openide.awt.Mnemonics.setLocalizedText(folderChooser, org.openide.util.NbBundle.getMessage(CustomizeRemoteIndex.class, "CustomizeRemoteIndex.folderChooser.text")); // NOI18N
|
jlahoda@385
|
142 |
folderChooser.addActionListener(new java.awt.event.ActionListener() {
|
jlahoda@385
|
143 |
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
jlahoda@385
|
144 |
folderChooserActionPerformed(evt);
|
jlahoda@385
|
145 |
}
|
jlahoda@385
|
146 |
});
|
jlahoda@385
|
147 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
jlahoda@385
|
148 |
gridBagConstraints.gridx = 2;
|
jlahoda@385
|
149 |
gridBagConstraints.gridy = 0;
|
jlahoda@385
|
150 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
|
jlahoda@385
|
151 |
gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
|
jlahoda@385
|
152 |
folderPanel.add(folderChooser, gridBagConstraints);
|
jlahoda@385
|
153 |
|
jlahoda@552
|
154 |
folder.setText(org.openide.util.NbBundle.getMessage(CustomizeRemoteIndex.class, "CustomizeRemoteIndex.folder.text")); // NOI18N
|
jlahoda@385
|
155 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
jlahoda@385
|
156 |
gridBagConstraints.gridx = 1;
|
jlahoda@385
|
157 |
gridBagConstraints.gridy = 0;
|
jlahoda@385
|
158 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
|
jlahoda@385
|
159 |
gridBagConstraints.weightx = 1.0;
|
jlahoda@385
|
160 |
folderPanel.add(folder, gridBagConstraints);
|
jlahoda@385
|
161 |
|
jlahoda@385
|
162 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
jlahoda@385
|
163 |
gridBagConstraints.gridx = 0;
|
jlahoda@385
|
164 |
gridBagConstraints.gridy = 0;
|
jlahoda@385
|
165 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
|
jlahoda@385
|
166 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
|
jlahoda@385
|
167 |
gridBagConstraints.weightx = 1.0;
|
jlahoda@385
|
168 |
add(folderPanel, gridBagConstraints);
|
jlahoda@385
|
169 |
|
jlahoda@552
|
170 |
indexInfo.setColumns(20);
|
jlahoda@552
|
171 |
indexInfo.setEditable(false);
|
jlahoda@552
|
172 |
indexInfo.setRows(5);
|
jlahoda@552
|
173 |
indexInfo.setBorder(null);
|
jlahoda@385
|
174 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
jlahoda@385
|
175 |
gridBagConstraints.gridx = 0;
|
jlahoda@552
|
176 |
gridBagConstraints.gridy = 2;
|
jlahoda@552
|
177 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
|
jlahoda@552
|
178 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
|
jlahoda@385
|
179 |
gridBagConstraints.weightx = 1.0;
|
jlahoda@552
|
180 |
gridBagConstraints.weighty = 1.0;
|
jlahoda@385
|
181 |
gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
|
jlahoda@552
|
182 |
add(indexInfo, gridBagConstraints);
|
jlahoda@385
|
183 |
|
jlahoda@385
|
184 |
indexURL.setColumns(40);
|
jlahoda@552
|
185 |
indexURL.setText(org.openide.util.NbBundle.getMessage(CustomizeRemoteIndex.class, "CustomizeRemoteIndex.indexURL.text")); // NOI18N
|
jlahoda@385
|
186 |
|
jlahoda@552
|
187 |
org.openide.awt.Mnemonics.setLocalizedText(indexURLLabel, org.openide.util.NbBundle.getMessage(CustomizeRemoteIndex.class, "CustomizeRemoteIndex.indexURLLabel.text")); // NOI18N
|
jlahoda@385
|
188 |
|
jlahoda@387
|
189 |
subIndex.addActionListener(new java.awt.event.ActionListener() {
|
jlahoda@387
|
190 |
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
jlahoda@387
|
191 |
subIndexActionPerformed(evt);
|
jlahoda@387
|
192 |
}
|
jlahoda@387
|
193 |
});
|
jlahoda@387
|
194 |
|
jlahoda@552
|
195 |
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(CustomizeRemoteIndex.class, "CustomizeRemoteIndex.jLabel1.text")); // NOI18N
|
jlahoda@385
|
196 |
|
jlahoda@385
|
197 |
javax.swing.GroupLayout remoteIndexPanelLayout = new javax.swing.GroupLayout(remoteIndexPanel);
|
jlahoda@385
|
198 |
remoteIndexPanel.setLayout(remoteIndexPanelLayout);
|
jlahoda@385
|
199 |
remoteIndexPanelLayout.setHorizontalGroup(
|
jlahoda@385
|
200 |
remoteIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
jlahoda@385
|
201 |
.addGroup(remoteIndexPanelLayout.createSequentialGroup()
|
jlahoda@385
|
202 |
.addContainerGap()
|
jlahoda@385
|
203 |
.addGroup(remoteIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
jlahoda@385
|
204 |
.addGroup(remoteIndexPanelLayout.createSequentialGroup()
|
jlahoda@385
|
205 |
.addGap(12, 12, 12)
|
jlahoda@385
|
206 |
.addComponent(jLabel1)
|
jlahoda@385
|
207 |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
jlahoda@552
|
208 |
.addComponent(subIndex, 0, 589, Short.MAX_VALUE))
|
jlahoda@385
|
209 |
.addGroup(remoteIndexPanelLayout.createSequentialGroup()
|
jlahoda@385
|
210 |
.addComponent(indexURLLabel)
|
jlahoda@385
|
211 |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
jlahoda@385
|
212 |
.addComponent(indexURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
jlahoda@385
|
213 |
.addContainerGap())
|
jlahoda@385
|
214 |
);
|
jlahoda@385
|
215 |
remoteIndexPanelLayout.setVerticalGroup(
|
jlahoda@385
|
216 |
remoteIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
jlahoda@385
|
217 |
.addGroup(remoteIndexPanelLayout.createSequentialGroup()
|
jlahoda@385
|
218 |
.addContainerGap()
|
jlahoda@385
|
219 |
.addGroup(remoteIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
jlahoda@385
|
220 |
.addComponent(indexURLLabel)
|
jlahoda@385
|
221 |
.addComponent(indexURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
jlahoda@385
|
222 |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
jlahoda@385
|
223 |
.addGroup(remoteIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
jlahoda@385
|
224 |
.addComponent(jLabel1)
|
jlahoda@385
|
225 |
.addComponent(subIndex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
jlahoda@385
|
226 |
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
jlahoda@385
|
227 |
);
|
jlahoda@385
|
228 |
|
jlahoda@385
|
229 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
jlahoda@385
|
230 |
gridBagConstraints.gridx = 0;
|
jlahoda@552
|
231 |
gridBagConstraints.gridy = 1;
|
jlahoda@552
|
232 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
|
jlahoda@385
|
233 |
gridBagConstraints.weightx = 1.0;
|
jlahoda@552
|
234 |
add(remoteIndexPanel, gridBagConstraints);
|
jlahoda@385
|
235 |
}// </editor-fold>//GEN-END:initComponents
|
jlahoda@385
|
236 |
|
jlahoda@385
|
237 |
private void folderChooserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_folderChooserActionPerformed
|
jlahoda@385
|
238 |
showFileChooser(folder);
|
jlahoda@385
|
239 |
}//GEN-LAST:event_folderChooserActionPerformed
|
jlahoda@385
|
240 |
|
jlahoda@387
|
241 |
private void subIndexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subIndexActionPerformed
|
jlahoda@387
|
242 |
subindexSelectionUpdated();
|
jlahoda@387
|
243 |
}//GEN-LAST:event_subIndexActionPerformed
|
jlahoda@387
|
244 |
|
jlahoda@385
|
245 |
// Variables declaration - do not modify//GEN-BEGIN:variables
|
jlahoda@385
|
246 |
private javax.swing.ButtonGroup buttonGroup1;
|
jlahoda@385
|
247 |
private javax.swing.JTextField folder;
|
jlahoda@385
|
248 |
private javax.swing.JButton folderChooser;
|
jlahoda@385
|
249 |
private javax.swing.JLabel folderLabel;
|
jlahoda@385
|
250 |
private javax.swing.JPanel folderPanel;
|
jlahoda@387
|
251 |
private javax.swing.JTextArea indexInfo;
|
jlahoda@385
|
252 |
private javax.swing.JTextField indexURL;
|
jlahoda@385
|
253 |
private javax.swing.JLabel indexURLLabel;
|
jlahoda@385
|
254 |
private javax.swing.JLabel jLabel1;
|
jlahoda@385
|
255 |
private javax.swing.JPanel remoteIndexPanel;
|
jlahoda@385
|
256 |
private javax.swing.JComboBox subIndex;
|
jlahoda@385
|
257 |
// End of variables declaration//GEN-END:variables
|
jlahoda@385
|
258 |
|
jlahoda@385
|
259 |
private void showFileChooser(JTextField folder) {
|
jlahoda@385
|
260 |
JFileChooser c = new JFileChooser();
|
jlahoda@385
|
261 |
|
jlahoda@385
|
262 |
c.setSelectedFile(new File(folder.getText()));
|
jlahoda@385
|
263 |
c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
jlahoda@385
|
264 |
c.setMultiSelectionEnabled(false);
|
jlahoda@385
|
265 |
c.setApproveButtonText("Select");
|
jlahoda@385
|
266 |
|
jlahoda@385
|
267 |
if (c.showDialog(this, null) == JFileChooser.APPROVE_OPTION) {
|
jlahoda@385
|
268 |
folder.setText(c.getSelectedFile().getAbsolutePath());
|
jlahoda@385
|
269 |
}
|
jlahoda@385
|
270 |
}
|
jlahoda@385
|
271 |
|
jlahoda@552
|
272 |
public void setIndex(RemoteIndex index) {
|
jlahoda@552
|
273 |
folder.setText(index.folder);
|
jlahoda@552
|
274 |
indexURL.setText(index.remote.toExternalForm());
|
jlahoda@552
|
275 |
subIndex.setSelectedItem(index.remoteSegment);
|
jlahoda@385
|
276 |
}
|
jlahoda@385
|
277 |
|
jlahoda@552
|
278 |
public RemoteIndex getIndex() {
|
jlahoda@552
|
279 |
try {
|
jlahoda@552
|
280 |
return RemoteIndex.create(folder.getText(), new URL(indexURL.getText()), (String) subIndex.getSelectedItem());
|
jlahoda@552
|
281 |
} catch (MalformedURLException ex) {
|
jlahoda@552
|
282 |
throw new IllegalStateException(ex);
|
jlahoda@385
|
283 |
}
|
jlahoda@385
|
284 |
}
|
jlahoda@385
|
285 |
|
jlahoda@385
|
286 |
private NotificationLineSupport notificationSupport;
|
jlahoda@385
|
287 |
|
jlahoda@385
|
288 |
public void setNotificationSupport(NotificationLineSupport notificationSupport) {
|
jlahoda@385
|
289 |
this.notificationSupport = notificationSupport;
|
jlahoda@385
|
290 |
}
|
jlahoda@385
|
291 |
|
jlahoda@385
|
292 |
private void updateErrors() {
|
jlahoda@385
|
293 |
notificationSupport.clearMessages();
|
jlahoda@387
|
294 |
|
jlahoda@387
|
295 |
File folderFile = new File(folder.getText());
|
jlahoda@385
|
296 |
|
jlahoda@387
|
297 |
if (!folderFile.exists()) {
|
jlahoda@385
|
298 |
notificationSupport.setErrorMessage("Specified directory does not exist.");
|
jlahoda@385
|
299 |
okButton.setEnabled(false);
|
jlahoda@385
|
300 |
return;
|
jlahoda@385
|
301 |
}
|
jlahoda@385
|
302 |
|
jlahoda@387
|
303 |
if (!folderFile.isDirectory()) {
|
jlahoda@385
|
304 |
notificationSupport.setErrorMessage("Specified directory is not directory.");
|
jlahoda@385
|
305 |
okButton.setEnabled(false);
|
jlahoda@385
|
306 |
return ;
|
jlahoda@385
|
307 |
}
|
jlahoda@385
|
308 |
|
jlahoda@552
|
309 |
if (checkingIndexURL.get()) {
|
jlahoda@552
|
310 |
notificationSupport.setInformationMessage("Checking index URL");
|
jlahoda@552
|
311 |
okButton.setEnabled(false);
|
jlahoda@552
|
312 |
return;
|
jlahoda@385
|
313 |
}
|
jlahoda@385
|
314 |
|
jlahoda@552
|
315 |
String urlError = checkingIndexURLError.get();
|
jlahoda@385
|
316 |
|
jlahoda@552
|
317 |
if (urlError != null) {
|
jlahoda@552
|
318 |
notificationSupport.setErrorMessage(urlError);
|
jlahoda@552
|
319 |
okButton.setEnabled(false);
|
jlahoda@552
|
320 |
return;
|
jlahoda@385
|
321 |
}
|
jlahoda@385
|
322 |
|
jlahoda@385
|
323 |
okButton.setEnabled(true);
|
jlahoda@385
|
324 |
}
|
jlahoda@385
|
325 |
|
jlahoda@385
|
326 |
private final AtomicBoolean checkingIndexURL = new AtomicBoolean();
|
jlahoda@385
|
327 |
private final AtomicReference<String> checkingIndexURLContentCopy = new AtomicReference<String>();
|
jlahoda@385
|
328 |
private final AtomicReference<String> checkingIndexURLError = new AtomicReference<String>();
|
jlahoda@385
|
329 |
|
jlahoda@385
|
330 |
private void indexURLUpdated() {
|
jlahoda@385
|
331 |
checkingIndexURLContentCopy.set(indexURL.getText());
|
jlahoda@385
|
332 |
urlCheckerTask.cancel();
|
jlahoda@385
|
333 |
urlCheckerTask.schedule(50);
|
jlahoda@385
|
334 |
}
|
jlahoda@387
|
335 |
|
jlahoda@552
|
336 |
private static final RequestProcessor WORKER = new RequestProcessor(CustomizeRemoteIndex.class.getName(), 1, false, false);
|
jlahoda@385
|
337 |
private final RequestProcessor.Task urlCheckerTask = WORKER.create(new Runnable() {
|
jlahoda@385
|
338 |
|
jlahoda@385
|
339 |
public void run() {
|
jlahoda@385
|
340 |
checkingIndexURL.set(true);
|
jlahoda@385
|
341 |
checkingIndexURLError.set(null);
|
jlahoda@385
|
342 |
|
jlahoda@385
|
343 |
SwingUtilities.invokeLater(new Runnable() {
|
jlahoda@385
|
344 |
public void run() {
|
jlahoda@385
|
345 |
updateErrors();
|
jlahoda@385
|
346 |
}
|
jlahoda@385
|
347 |
});
|
jlahoda@385
|
348 |
|
jlahoda@385
|
349 |
String urlText = checkingIndexURLContentCopy.get();
|
jlahoda@385
|
350 |
Collection<? extends String> subindices = null;
|
jlahoda@385
|
351 |
|
jlahoda@385
|
352 |
try {
|
jlahoda@385
|
353 |
URL url = new URL(urlText);
|
jlahoda@385
|
354 |
|
jlahoda@385
|
355 |
if (!url.getPath().endsWith("/"))
|
jlahoda@385
|
356 |
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath() + "/" + (url.getQuery() != null ? "?" + url.getQuery() : ""));
|
jlahoda@385
|
357 |
|
jlahoda@385
|
358 |
subindices = WebUtilities.requestStringArrayResponse(url.toURI().resolve("list"));
|
jlahoda@385
|
359 |
|
jlahoda@385
|
360 |
if (subindices.isEmpty()) {
|
jlahoda@385
|
361 |
checkingIndexURLError.set("Not an index.");
|
jlahoda@385
|
362 |
}
|
jlahoda@385
|
363 |
} catch (URISyntaxException ex) {
|
jlahoda@385
|
364 |
checkingIndexURLError.set(ex.getLocalizedMessage());
|
jlahoda@385
|
365 |
} catch (MalformedURLException ex) {
|
jlahoda@385
|
366 |
checkingIndexURLError.set(ex.getLocalizedMessage());
|
jlahoda@572
|
367 |
} catch (ThreadDeath td) {
|
jlahoda@572
|
368 |
throw td;
|
jlahoda@572
|
369 |
} catch (Throwable t) {//#6541019
|
jlahoda@572
|
370 |
checkingIndexURLError.set("Invalid URL");
|
jlahoda@385
|
371 |
}
|
jlahoda@385
|
372 |
|
jlahoda@385
|
373 |
checkingIndexURL.set(false);
|
jlahoda@385
|
374 |
|
jlahoda@385
|
375 |
final Collection<? extends String> subindicesFinal = subindices;
|
jlahoda@385
|
376 |
|
jlahoda@385
|
377 |
SwingUtilities.invokeLater(new Runnable() {
|
jlahoda@385
|
378 |
public void run() {
|
jlahoda@385
|
379 |
updateErrors();
|
jlahoda@385
|
380 |
|
jlahoda@572
|
381 |
if (subindicesFinal == null || subindicesFinal.isEmpty()) return;
|
jlahoda@385
|
382 |
|
jlahoda@385
|
383 |
DefaultComboBoxModel model = (DefaultComboBoxModel) subIndex.getModel();
|
jlahoda@385
|
384 |
String selected = (String) model.getSelectedItem();
|
jlahoda@385
|
385 |
|
jlahoda@385
|
386 |
model.removeAllElements();
|
jlahoda@385
|
387 |
|
jlahoda@385
|
388 |
boolean containsSelection = false;
|
jlahoda@419
|
389 |
Map<String, String> displayNames = new HashMap<String, String>();
|
jlahoda@385
|
390 |
|
jlahoda@385
|
391 |
for (String subindex : subindicesFinal) {
|
jlahoda@419
|
392 |
String[] subindexSplit = subindex.split(":", 2);
|
jlahoda@419
|
393 |
if (subindexSplit[0].equals(selected)) containsSelection = true;
|
jlahoda@419
|
394 |
model.addElement(subindexSplit[0]);
|
jlahoda@419
|
395 |
displayNames.put(subindexSplit[0], subindexSplit[1]);
|
jlahoda@385
|
396 |
}
|
jlahoda@385
|
397 |
|
jlahoda@385
|
398 |
if (containsSelection) {
|
jlahoda@385
|
399 |
model.setSelectedItem(selected);
|
jlahoda@385
|
400 |
}
|
jlahoda@387
|
401 |
|
jlahoda@387
|
402 |
subindexSelectionUpdated();
|
jlahoda@419
|
403 |
subIndex.setRenderer(new RendererImpl(displayNames));
|
jlahoda@385
|
404 |
}
|
jlahoda@385
|
405 |
});
|
jlahoda@385
|
406 |
}
|
jlahoda@385
|
407 |
});
|
jlahoda@387
|
408 |
|
jlahoda@387
|
409 |
private final AtomicReference<String> indexInfoURLContentCopy = new AtomicReference<String>();
|
jlahoda@387
|
410 |
private final AtomicReference<String> indexInfoSubIndexCopy = new AtomicReference<String>();
|
jlahoda@387
|
411 |
private void subindexSelectionUpdated() {
|
jlahoda@387
|
412 |
indexInfoURLContentCopy.set(indexURL.getText());
|
jlahoda@387
|
413 |
indexInfoSubIndexCopy.set((String) subIndex.getSelectedItem());
|
jlahoda@387
|
414 |
indexInfoTask.cancel();
|
jlahoda@387
|
415 |
indexInfoTask.schedule(50);
|
jlahoda@387
|
416 |
}
|
jlahoda@387
|
417 |
|
jlahoda@387
|
418 |
private final RequestProcessor.Task indexInfoTask = WORKER.create(new Runnable() {
|
jlahoda@387
|
419 |
|
jlahoda@387
|
420 |
public void run() {
|
jlahoda@387
|
421 |
String urlText = indexInfoURLContentCopy.get();
|
jlahoda@387
|
422 |
String subIndex = indexInfoSubIndexCopy.get();
|
jlahoda@387
|
423 |
IndexInfo info = null;
|
jlahoda@387
|
424 |
|
jlahoda@387
|
425 |
try {
|
jlahoda@387
|
426 |
URL url = new URL(urlText);
|
jlahoda@387
|
427 |
|
jlahoda@387
|
428 |
if (!url.getPath().endsWith("/"))
|
jlahoda@387
|
429 |
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath() + "/" + (url.getQuery() != null ? "?" + url.getQuery() : ""));
|
jlahoda@387
|
430 |
|
jlahoda@387
|
431 |
String indexInfoText = WebUtilities.requestStringResponse(url.toURI().resolve("info?path=" + WebUtilities.escapeForQuery(subIndex)));
|
jlahoda@387
|
432 |
info = IndexInfo.empty();
|
jlahoda@387
|
433 |
|
jlahoda@572
|
434 |
if (indexInfoText != null)
|
jlahoda@572
|
435 |
Pojson.update(info, indexInfoText);
|
jlahoda@387
|
436 |
} catch (URISyntaxException ex) {
|
jlahoda@552
|
437 |
Logger.getLogger(CustomizeRemoteIndex.class.getName()).log(Level.FINE, null, ex);
|
jlahoda@387
|
438 |
} catch (MalformedURLException ex) {
|
jlahoda@552
|
439 |
Logger.getLogger(CustomizeRemoteIndex.class.getName()).log(Level.FINE, null, ex);
|
jlahoda@387
|
440 |
}
|
jlahoda@387
|
441 |
|
jlahoda@387
|
442 |
final IndexInfo infoFinal = info;
|
jlahoda@387
|
443 |
|
jlahoda@387
|
444 |
SwingUtilities.invokeLater(new Runnable() {
|
jlahoda@387
|
445 |
public void run() {
|
jlahoda@387
|
446 |
if (infoFinal != null) {
|
jlahoda@387
|
447 |
indexInfo.setText(toDisplayText(infoFinal));
|
jlahoda@387
|
448 |
} else {
|
jlahoda@387
|
449 |
indexInfo.setText("");
|
jlahoda@387
|
450 |
}
|
jlahoda@387
|
451 |
}
|
jlahoda@387
|
452 |
});
|
jlahoda@387
|
453 |
}
|
jlahoda@387
|
454 |
});
|
jlahoda@387
|
455 |
|
jlahoda@387
|
456 |
private static String toDisplayText(IndexInfo info) {
|
jlahoda@387
|
457 |
StringBuilder sb = new StringBuilder();
|
jlahoda@387
|
458 |
|
jlahoda@387
|
459 |
if (info.sourceLocation != null) {
|
jlahoda@387
|
460 |
sb.append("Source Location: ").append(info.sourceLocation).append("\n");
|
jlahoda@387
|
461 |
}
|
jlahoda@387
|
462 |
if (info.lastUpdate >= 0) {
|
jlahoda@387
|
463 |
sb.append("Last Update:\t").append(DateFormat.getDateTimeInstance().format(new Date(info.lastUpdate))).append("\n");
|
jlahoda@387
|
464 |
}
|
jlahoda@387
|
465 |
if (info.totalFiles >= 0) {
|
jlahoda@387
|
466 |
sb.append("Indexed Files:\t").append(info.totalFiles).append("\n");
|
jlahoda@387
|
467 |
}
|
jlahoda@387
|
468 |
|
jlahoda@387
|
469 |
return sb.toString();
|
jlahoda@387
|
470 |
}
|
jlahoda@419
|
471 |
|
jlahoda@419
|
472 |
private static final class RendererImpl extends DefaultListCellRenderer {
|
jlahoda@419
|
473 |
private final Map<String, String> displayNames;
|
jlahoda@419
|
474 |
public RendererImpl(Map<String, String> displayNames) {
|
jlahoda@419
|
475 |
this.displayNames = displayNames;
|
jlahoda@419
|
476 |
}
|
jlahoda@419
|
477 |
|
jlahoda@419
|
478 |
@Override
|
jlahoda@419
|
479 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
jlahoda@419
|
480 |
return super.getListCellRendererComponent(list, displayNames.get(value), index, isSelected, cellHasFocus);
|
jlahoda@419
|
481 |
}
|
jlahoda@419
|
482 |
|
jlahoda@419
|
483 |
}
|
jlahoda@385
|
484 |
}
|