View Javadoc

1   /*
2    * $HeadURL: $
3    * $Date: $
4    * $Revision: $
5    * $Author: $
6    * 
7    * Copyright (c) 2005 MindTree Consulting Ltd. 
8    * 
9    * This file is part of Insight.
10   * 
11   * Insight is free software: you can redistribute it and/or modify it under the 
12   * terms of the GNU General Public License as published by the Free Software 
13   * Foundation, either version 3 of the License, or (at your option) any later 
14   * version.
15   * 
16   * Insight is distributed in the hope that it will be useful, but 
17   * WITHOUT ANY WARRANTY; without even the implied warranty of 
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
19   * Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public License along with 
22   * Insight.  If not, see <http://www.gnu.org/licenses/>.
23   */
24  package com.mindtree.techworks.insight.gui.preferences;
25  
26  import java.awt.Component;
27  import java.awt.GridBagConstraints;
28  import java.awt.GridBagLayout;
29  import java.awt.Insets;
30  import java.awt.event.ActionEvent;
31  import java.awt.event.ActionListener;
32  import java.io.File;
33  import java.net.PasswordAuthentication;
34  import java.net.URL;
35  import java.util.ArrayList;
36  import java.util.Iterator;
37  
38  import javax.swing.AbstractListModel;
39  import javax.swing.BorderFactory;
40  import javax.swing.JButton;
41  import javax.swing.JCheckBox;
42  import javax.swing.JFileChooser;
43  import javax.swing.JLabel;
44  import javax.swing.JList;
45  import javax.swing.JPanel;
46  import javax.swing.JPasswordField;
47  import javax.swing.JScrollPane;
48  import javax.swing.JTextField;
49  import javax.swing.ListSelectionModel;
50  
51  import com.mindtree.techworks.insight.InsightConstants;
52  import com.mindtree.techworks.insight.download.ftpbrowse.FTPFileFile;
53  import com.mindtree.techworks.insight.download.ftpbrowse.FTPRemoteFileSystemView;
54  import com.mindtree.techworks.insight.gui.widgets.InsightRemoteFileChooser;
55  import com.mindtree.techworks.insight.gui.widgets.StatusBar;
56  import com.mindtree.techworks.insight.preferences.PreferenceManager;
57  import com.mindtree.techworks.insight.preferences.model.Preference;
58  import com.mindtree.techworks.insight.preferences.model.PreferenceAttribute;
59  import com.mindtree.techworks.insight.preferences.model.PreferenceAttributeType;
60  import com.mindtree.techworks.insight.preferences.model.PreferenceInfo;
61  
62  
63  /**
64  *
65  * The <code>FTPFilesUIPanel</code> displays the UI for editing 
66  * FTP file set preferences.
67  *
68  * @see com.mindtree.techworks.insight.preferences.model.Preference
69  * @see com.mindtree.techworks.insight.gui.preferences.AbstractPreferencesUIPanel
70  *
71  * @author  Regunath B
72  * @version $Revision: 27 $ $Date: 2007-12-16 04:58:03 -0700 (Sun, 16 Dec 2007) $
73  */
74  public class FTPFilesUIPanel extends AbstractPreferencesUIPanel implements
75  		ActionListener {
76  	
77  	/**
78  	 * Serial version UID
79  	 */
80  	private static final long serialVersionUID = 917645181047346050L;
81  	
82  	/**
83  	 * Constants for attribute Ids and prefixes of the remote file 
84  	 * set preference 
85  	 */
86  	private static final String REQUIRES_AUTHENTICATION = "authentication";
87  	private static final String REQUIRES_AUTHENTICATION_NAME = "Requires Authentication";
88  	private static final String HOST = "hostname";
89  	private static final String HOST_NAME = "Host Name";
90  	private static final String PORT = "portno";
91  	private static final String PORT_NAME = "Port Number";
92  	private static final String HOME_DIR = "homedir";
93  	private static final String HOME_DIR_NAME = "Home Dir";
94  	private static final String USER = "username";
95  	private static final String USER_NAME = "User Name";
96  	private static final String PASSWORD = "password";
97  	private static final String PASSWORD_NAME = "Password";
98  	private static final String URL_PREFIX = "urlId";
99  //	private static final String URL_ATTRIB_NAME_PREFIX = "urlName";
100 	
101 	/**
102 	 * Default port for FTP
103 	 */
104 	private static final String DEFAULT_PORT = "21";
105 
106 	/**
107 	 * Constants to identify the file set edit action
108 	 */
109 	private static final int NONE = 0;
110 	private static final int ADD = 1;
111 	private static final int EDIT = 2;
112 	private static final int REMOVE = 3;
113 	
114 	/**
115 	 * State that holds the action type
116 	 */
117 	private int action = NONE;
118 	
119 	/**
120 	 * The display widgets
121 	 */
122 	private JList configuredFilesetsList;
123 	private JButton addButton;
124 	private JButton editButton;
125 	private JButton removeButton;
126 	private JTextField nameField;
127 	private JTextField hostField;
128 	private JTextField portField;
129 	private JTextField homeDirField;
130 	private JList urlList;
131 	private JTextField newURLField;
132 	private JButton addURLButton;
133 	private JButton browseButton;
134 	private JButton removeURLButton;
135 	private JCheckBox requiresAuthentication;
136 	private JTextField userField;
137 	private JPasswordField passwordField;
138 	private JButton applyChangesButton;
139 	
140 	/**
141 	 * Layout definition for the fileset details
142 	 */
143 	private GridBagLayout gl;
144 	private GridBagConstraints gc;		
145 	
146 //	private FilesetModel filesetModel;
147 	
148 	/**
149 	 * No args constructor
150 	 */
151 	public FTPFilesUIPanel() {
152 	}
153 
154 	/**
155 	 * Tells whether the file given by the absolute path already exists in the File Set.
156 	 */
157 	private boolean isFileAlreadyExistsInFileSet(URLListModel urlListModel, String filePath){
158     	for(int j = 0; j < urlListModel.getSize(); j++){
159     		if(((String)(urlListModel.getElementAt(j))).equals(filePath)){
160     			StatusBar.getInstance().setDisplayText(0,InsightConstants.getLiteral("FILE_ALREADY_LOADED"), false);
161     			return true;
162     		}
163     	}
164     	return false;
165 	}
166 	
167 	/** 
168 	 * ActionListener interface method implementation
169 	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
170 	 */
171 	public void actionPerformed(ActionEvent event) {
172 		Object source = event.getSource();
173 		if (source == this.addButton) {
174 			this.action = ADD;
175 			this.configuredFilesetsList.removeSelectionInterval(0,this.configuredFilesetsList.getModel().getSize() - 1);
176 			setDetailsWidgetsEnable(true);
177 		} else if (source == this.editButton) {
178 			if (this.configuredFilesetsList.getSelectedIndex() > -1) {
179 				this.action = EDIT;
180 				PreferenceInfo prefInfo = (PreferenceInfo)this.configuredFilesetsList
181 					.getModel().getElementAt(this.configuredFilesetsList
182 							.getSelectedIndex());
183 				displayFilesetInfoForEdit(PreferenceManager.getInstance().getPreference(prefInfo.getCompleteId()));
184 			}
185 		} else if (source == this.removeButton) {
186 			if (this.configuredFilesetsList.getSelectedIndex() > -1) {
187 				this.action = REMOVE;
188 				((FilesetModel)this.configuredFilesetsList.getModel())
189 					.removeFileset(this.configuredFilesetsList.getSelectedIndex());
190 				setDetailsWidgetsEnable(false);
191 			}
192 		} else if (source == this.removeURLButton) {
193 			if (this.urlList.getSelectedIndex() > -1) {
194 				((URLListModel)this.urlList.getModel())
195 				.removeURL(this.urlList.getSelectedIndex());
196 			}
197 		} else if (source == this.addURLButton) {
198 			if (newURLField.getText().trim().length() > 0) {
199 				URLListModel urlListModel = (URLListModel)this.urlList.getModel();
200 				if(!isFileAlreadyExistsInFileSet(urlListModel,newURLField.getText()))
201 					urlListModel.addURL(newURLField.getText());
202 				else
203 					StatusBar.getInstance().setDisplayText(0, InsightConstants.getLiteral("FILE_ALREADY_LOADED"), false);
204 				newURLField.setText("");
205 			}
206 		} else if (source == browseButton) {
207 			if (this.hostField.getText().trim().length() <= 0) {
208 				StatusBar.getInstance().setDisplayText(0,InsightConstants.getLiteral("ERROR_HOST_NAME"), false);
209 				return;
210 			}
211 			JFileChooser fileChooser = getRemoteFileChooser();
212 	        if (fileChooser.showOpenDialog(this.parent) == JFileChooser.APPROVE_OPTION) {
213 	            File[] chosenFiles = fileChooser.getSelectedFiles();
214 	            for (int i = 0; i < chosenFiles.length; i++) {
215 					FTPFileFile ftpFile = (FTPFileFile) chosenFiles[i];
216 	            	((URLListModel)this.urlList.getModel()).addURL(ftpFile.getAbsolutePath());
217 	            	URLListModel urlListModel = ((URLListModel)this.urlList.getModel());
218 	            	String filePath = ftpFile.getAbsolutePath();
219 	            	if(!isFileAlreadyExistsInFileSet(urlListModel, filePath))
220 	            		urlListModel.addURL(filePath);
221 	            	else
222 	            		StatusBar.getInstance().setDisplayText(0, InsightConstants.getLiteral("FILE_ALREADY_LOADED"), false);
223 	            }
224 	        }			
225 		} else if (source == this.requiresAuthentication) {
226 			if (this.configuredFilesetsList.getSelectedIndex() > -1) {
227 				PreferenceInfo prefInfo = (PreferenceInfo)this.configuredFilesetsList.getModel().
228 				getElementAt(this.configuredFilesetsList.getSelectedIndex());
229 				checkAuthenticationEnable(PreferenceManager.getInstance().getPreference(prefInfo.getCompleteId()));
230 			} else {
231 				checkAuthenticationEnable(null);
232 			}
233 		} else if (source == applyChangesButton) {
234 			if (this.nameField.getText().trim().length() < InsightConstants.PREFERENCE_NAME_MIN_SIZE) {
235 				StatusBar.getInstance().setDisplayText(0,InsightConstants.getLiteral("ERROR_FILESET_NAME") + 
236 						InsightConstants.PREFERENCE_NAME_MIN_SIZE, false);
237 				return;
238 			}
239 			Preference childPreference = null;
240 			switch(this.action) {
241 				case ADD:
242 					childPreference = new Preference(String.valueOf(new Object().hashCode()), true, true, this.nameField.getText());
243 					createAndAddBooleanAttribute(childPreference, REQUIRES_AUTHENTICATION, 
244 							REQUIRES_AUTHENTICATION_NAME, this.requiresAuthentication);
245 					createAndAddTextAttribute(childPreference, HOST, HOST_NAME, this.hostField);
246 					createAndAddTextAttribute(childPreference, PORT, PORT_NAME, this.portField);
247 					createAndAddTextAttribute(childPreference, HOME_DIR, HOME_DIR_NAME, this.homeDirField);
248 					createAndAddTextAttribute(childPreference, USER, USER_NAME, this.userField);
249 					createAndAddPasswordAttribute(childPreference, PASSWORD, PASSWORD_NAME, this.passwordField);
250 					
251 					this.preference.addChildPreference(childPreference);
252 					
253 					// update the GUI
254 					((FilesetModel)this.configuredFilesetsList.getModel()).addFileset(childPreference);
255 					
256 					break;
257 				case EDIT:
258 					childPreference = ((FilesetModel)this.configuredFilesetsList.
259 						getModel()).getPreference(this.configuredFilesetsList.getSelectedIndex());
260 					childPreference.setName(this.nameField.getText());
261 					childPreference.getPreferenceAttributeById(REQUIRES_AUTHENTICATION).setValue(this.requiresAuthentication.isSelected() ? TRUE : FALSE);
262 					childPreference.getPreferenceAttributeById(USER).setValue(this.userField.getText());
263 					childPreference.getPreferenceAttributeById(HOST).setValue(this.hostField.getText());
264 					childPreference.getPreferenceAttributeById(PORT).setValue(this.portField.getText());
265 					childPreference.getPreferenceAttributeById(HOME_DIR).setValue(this.homeDirField.getText());
266 					childPreference.getPreferenceAttributeById(PASSWORD).setValue(new String(this.passwordField.getPassword()));
267 					((FilesetModel)this.configuredFilesetsList.getModel()).listDataUpdated(this.configuredFilesetsList.getSelectedIndex());
268 					break;
269 			}
270 			// Remove all old URLs and add the new ones
271 			updateURLListToPreference(childPreference);
272 			setDetailsWidgetsEnable(false);
273 			this.action = NONE;
274 		}
275 	}
276 		
277 	
278 	/**
279 	 *  Overriden super class method
280 	 * @see com.mindtree.techworks.insight.gui.preferences.AbstractPreferencesUIPanel#initializeDisplay()
281 	 */
282 	protected void initializeDisplay() {
283 		this.configuredFilesetsList = new JList(new FilesetModel());
284 		this.configuredFilesetsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
285 		addComponent(new JLabel(InsightConstants.getLiteral("CONFIGURED_FILESETS")),0,0,0,0,1,1);		
286 		addComponent(new JScrollPane(configuredFilesetsList),1,0,1,1,1,4);	
287 		this.addButton = new JButton(InsightConstants.getLiteral("ADD"));
288 		this.editButton = new JButton(InsightConstants.getLiteral("EDIT"));
289 		this.removeButton = new JButton(InsightConstants.getLiteral("REMOVE"));
290 		this.addButton.addActionListener(this);
291 		this.editButton.addActionListener(this);
292 		this.removeButton.addActionListener(this);
293 		addComponent(addButton,2,0,0,0,1,1);	
294 		addComponent(editButton,2,1,0,0,1,1);	
295 		addComponent(removeButton,2,2,0,0,1,1);	
296 		
297 		// add the widgets for the fileset details
298 		JPanel filesetDetailsPanel = new JPanel();
299 		this.gl = new GridBagLayout();
300 		this.gc = new GridBagConstraints();
301 		filesetDetailsPanel.setLayout(gl);
302 		filesetDetailsPanel.setBorder(BorderFactory.createTitledBorder(InsightConstants.getLiteral("FILESET_DETAILS")));
303 		addComponent(filesetDetailsPanel,0,4,1,1,3,1);	
304 		
305 		addComponent(filesetDetailsPanel,new JLabel(InsightConstants.getLiteral("NAME")),0,0,0,0,1,1);
306 		this.nameField = new JTextField();
307 		addComponent(filesetDetailsPanel,nameField,1,0,1,0,4,1);
308 		addComponent(filesetDetailsPanel,new JLabel(InsightConstants.getLiteral("HOST")),0,1,0,0,1,1);
309 		this.hostField = new JTextField();
310 		addComponent(filesetDetailsPanel,hostField,1,1,1,0,2,1);
311 		addComponent(filesetDetailsPanel,new JLabel(InsightConstants.getLiteral("PORT")),3,1,0,0,1,1);
312 		this.portField = new JTextField();
313 		addComponent(filesetDetailsPanel,portField,4,1,1,0,1,1);
314 		addComponent(filesetDetailsPanel,new JLabel(InsightConstants.getLiteral("HOME_DIR")),5,1,0,0,1,1);
315 		this.homeDirField = new JTextField();
316 		addComponent(filesetDetailsPanel,homeDirField,6,1,1,0,1,1);
317 		this.requiresAuthentication = new JCheckBox(InsightConstants.getLiteral("REQUIRES_AUTHENTICATION"));
318 		this.requiresAuthentication.addActionListener(this);
319 		addComponent(filesetDetailsPanel,requiresAuthentication,0,2,1,0,6,1);
320 		addComponent(filesetDetailsPanel,new JLabel(InsightConstants.getLiteral("USER")),0,3,0,0,1,1);
321 		this.userField = new JTextField();
322 		addComponent(filesetDetailsPanel,userField,1,3,1,0,4,1);
323 		addComponent(filesetDetailsPanel,new JLabel(InsightConstants.getLiteral("PASSWORD")),5,3,0,0,1,1);
324 		this.passwordField = new JPasswordField();
325 		addComponent(filesetDetailsPanel,passwordField,6,3,1,0,1,1);
326 		this.urlList = new JList(new URLListModel());
327 		this.urlList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
328 		addComponent(filesetDetailsPanel,new JLabel(InsightConstants.getLiteral("URLS")),0,4,0,0,1,1);		
329 		addComponent(filesetDetailsPanel,new JScrollPane(urlList),1,4,1,1,4,2);			
330 		this.removeURLButton = new JButton(InsightConstants.getLiteral("REMOVE"));
331 		this.removeURLButton.addActionListener(this);
332 		addComponent(filesetDetailsPanel,removeURLButton,5,4,0,0,1,1);	
333 		addComponent(filesetDetailsPanel,new JLabel(InsightConstants.getLiteral("NEW_URL")),0,6,0,0,1,1);
334 		this.newURLField = new JTextField();
335 		addComponent(filesetDetailsPanel,newURLField,1,6,1,0,4,1);
336 		this.addURLButton = new JButton(InsightConstants.getLiteral("ADD"));
337 		this.addURLButton.addActionListener(this);
338 		addComponent(filesetDetailsPanel,addURLButton,5,6,0,0,1,1);	
339 		this.browseButton = new JButton(InsightConstants.getLiteral("BROWSE"));
340 		this.browseButton.addActionListener(this);
341 		addComponent(filesetDetailsPanel,browseButton,6,6,0,0,1,1);	
342 		this.applyChangesButton = new JButton(InsightConstants.getLiteral("APPLY_FILESET_CHANGES"));
343 		this.applyChangesButton.addActionListener(this);
344 		addComponent(filesetDetailsPanel,applyChangesButton,5,7,0,0,2,1);
345 		// disable the details widgets
346 		setDetailsWidgetsEnable(false);		
347 	}
348 
349 	/**
350 	 *  Overriden super class method
351 	 * @see com.mindtree.techworks.insight.gui.preferences.AbstractPreferencesUIPanel#setPreferenceValues()
352 	 */
353 	protected  void setPreferenceValues() {
354 		// update the fileset list change
355 		updateFilesetListToPreference();
356 	}
357 	
358 	/**
359 	 * Helper method to update the list of filesets in the Preference for this panel
360 	 */
361 	private final void updateFilesetListToPreference() {
362 		ArrayList oldValues = new ArrayList();
363 		Iterator iterator = this.preference.iterateChildPreferenceIds();
364 		while(iterator.hasNext()) {
365 			oldValues.add(iterator.next());
366 		}
367 		iterator = oldValues.iterator();
368 		while(iterator.hasNext()) {
369 			this.preference.removePreference(
370 					this.preference.getPreferenceById(
371 							(String)iterator.next()));
372 		}
373 		for (int i = 0; i < this.configuredFilesetsList.getModel().getSize(); i++) {
374 			this.preference.addChildPreference(((FilesetModel)this.configuredFilesetsList.getModel()).getPreference(i));
375 		}				
376 	}
377 	
378 	/**
379 	 * Helper method to return the remote file chooser
380 	 * @return JFileChooser for the remote system
381 	 */
382 	private JFileChooser getRemoteFileChooser() {
383 		PasswordAuthentication passwordAuthentication = null;
384 		JFileChooser fileChooser = null;
385 		if (this.requiresAuthentication.isSelected()) {
386 			passwordAuthentication = new PasswordAuthentication(this.userField.getText(), this.passwordField.getPassword());
387 		}
388 		FTPRemoteFileSystemView remoteFileSystemView = null;
389 		String port = this.portField.getText().trim();		
390 		try {
391 			if (port.length() > 0) {
392 				int portNo = Integer.parseInt(port);
393 				remoteFileSystemView = new FTPRemoteFileSystemView(
394 						new URL("ftp", this.hostField.getText(), portNo, this.homeDirField.getText()), passwordAuthentication);
395 			} else {
396 				remoteFileSystemView = new FTPRemoteFileSystemView(
397 						new URL("ftp", this.hostField.getText(),""), passwordAuthentication);
398 			}
399 			fileChooser = new InsightRemoteFileChooser(remoteFileSystemView);
400 		} catch (NumberFormatException nfe) {
401 			nfe.printStackTrace();
402 			StatusBar.getInstance().setDisplayText(0,InsightConstants.getLiteral("ERROR_PORT_NO"), false);
403 			return fileChooser;				
404 		} catch (Exception e) {
405 			e.printStackTrace();
406 			StatusBar.getInstance().setDisplayText(0,InsightConstants.getLiteral("ERROR_BROWSE_REMOTE") + e.getMessage(), false);
407 			return fileChooser;				
408 		}
409     	fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
410     	fileChooser.setMultiSelectionEnabled(true);
411     	fileChooser.setDialogTitle(InsightConstants.getLiteral("SELECT_FILES"));    	
412     	fileChooser.setApproveButtonText(InsightConstants.getLiteral("SELECT_FILES"));
413     	return fileChooser;
414 	}
415 	
416 	/**
417 	 * Helper method to update the list of URLs in the specified file set Preference
418 	 * @param childPreference the Preference to be updated with URL list
419 	 */
420 	private final void updateURLListToPreference(Preference childPreference) {
421 		ArrayList oldValues = new ArrayList();
422 		Iterator iterator = childPreference.iteratePreferenceAttributeIds();
423 		while(iterator.hasNext()) {
424 			String id = (String)iterator.next();
425 			if (id.startsWith(URL_PREFIX)) {
426 				oldValues.add(id);
427 			}
428 		}
429 		iterator = oldValues.iterator();
430 		while(iterator.hasNext()) {
431 			childPreference.removePreferenceAttribute(
432 					childPreference.getPreferenceAttributeById(
433 							(String)iterator.next()));
434 		}
435 		for (int i = 0; i < this.urlList.getModel().getSize(); i++) {
436 			String identifier = (String)this.urlList.getModel().getElementAt(i);
437 			PreferenceAttribute newAttribute = new PreferenceAttribute(PreferenceAttributeType.TEXT,
438 					URL_PREFIX + i, identifier, false,
439 					true, true, childPreference);
440 			newAttribute.setName(URL_PREFIX + i);
441 			childPreference.addPreferenceAttribute(newAttribute);
442 		}		
443 	}
444 	
445 	/**
446 	 * Helper method that displays the specified file set information for
447 	 * editing
448 	 * @param filesetInfo Presefernce containing the file set information
449 	 */
450 	private final void displayFilesetInfoForEdit(Preference filesetInfo) {
451 		setDetailsWidgetsEnable(true);
452 		this.nameField.setText(filesetInfo.getName());
453 		Iterator iterator = filesetInfo.iteratePreferenceAttributeIds();
454 		while(iterator.hasNext()) {			
455 			String id = (String)iterator.next();
456 			PreferenceAttribute prefAttribute = filesetInfo.getPreferenceAttributeById(id);
457 			if (id.startsWith(URL_PREFIX)) {
458 				((URLListModel)this.urlList.getModel()).addURL(prefAttribute.getValue());
459 			} else if (id.equals(REQUIRES_AUTHENTICATION)) {
460 				this.requiresAuthentication.setSelected(prefAttribute.getValue().equals(TRUE));
461 			} else if (id.equals(HOST)) {
462 				this.hostField.setText(prefAttribute.getValue());
463 			} else if (id.equals(PORT)) {
464 				this.portField.setText(prefAttribute.getValue());				
465 			} else if (id.equals(HOME_DIR)) {
466 				this.homeDirField.setText(prefAttribute.getValue());			
467 			}
468 		}
469 		checkAuthenticationEnable(filesetInfo);
470 	}
471 	
472 	/**
473 	 * Adds the specified component to this panel using the specified
474 	 * constraints.
475 	 * 
476 	 * @param panel
477 	 *            The panel to add the component to.
478 	 * @param c
479 	 *            The component to layout
480 	 * @param gridx
481 	 *            X location in the Grid
482 	 * @param gridy
483 	 *            Y location in the Grid
484 	 * @param weightx
485 	 *            Weight in X direction
486 	 * @param weighty
487 	 *            Weight in Y direction
488 	 * @param width
489 	 *            Width
490 	 * @param height
491 	 *            Height
492 	 */
493 	private final void addComponent (JPanel panel, Component c, int gridx,
494 			int gridy, int weightx, int weighty, int width, int height) {
495 		gc.fill = GridBagConstraints.BOTH;
496 		gc.anchor = GridBagConstraints.NORTHWEST;
497 		gc.insets = new Insets(5,5,5,5);		
498 		gc.gridx = gridx;
499 		gc.gridy = gridy;
500 		gc.weightx = weightx;
501 		gc.weighty = weighty;
502 		gc.gridwidth = width;
503 		gc.gridheight = height;		
504 		gl.setConstraints( c, gc);
505 		panel.add(c);
506 	}	
507 
508 	/**
509 	 * Helper method to set the enable status of file set details widgest
510 	 * @param enable true to enable, false to disable
511 	 */
512 	private void setDetailsWidgetsEnable(boolean enable) {
513 		this.nameField.setText("");
514 		this.nameField.setEditable(enable);
515 		this.nameField.setEnabled(enable);		
516 		this.hostField.setText("");
517 		this.hostField.setEditable(enable);
518 		this.hostField.setEnabled(enable);		
519 		this.portField.setText(DEFAULT_PORT);
520 		this.portField.setEditable(enable);
521 		this.portField.setEnabled(enable);		
522 		this.homeDirField.setText("");
523 		this.homeDirField.setEditable(enable);
524 		this.homeDirField.setEnabled(enable);		
525 		((URLListModel)this.urlList.getModel()).clearAll();
526 		this.urlList.setEnabled(enable);
527 		this.newURLField.setText("");
528 		this.newURLField.setEditable(enable);
529 		this.newURLField.setEnabled(enable);		
530 		this.requiresAuthentication.setEnabled(enable);
531 		this.requiresAuthentication.setSelected(false);
532 		// pass null so that only enabling/disabling is done
533 		checkAuthenticationEnable(null);
534 		this.removeURLButton.setEnabled(enable);
535 		this.addURLButton.setEnabled(enable);
536 		this.browseButton.setEnabled(enable);
537 		this.applyChangesButton.setEnabled(enable);
538 		if (enable) {
539 			this.nameField.requestFocus();
540 		}
541 	}
542 	
543 	/**
544 	 * Helper method that checks enabling and disabling of the user credential
545 	 * widgets
546 	 * 
547 	 * @param filesetInfo
548 	 *            The fileset preference.
549 	 */
550 	private void checkAuthenticationEnable(Preference filesetInfo) {
551 		boolean authenticationEnabled = this.requiresAuthentication.isSelected();
552 		this.userField.setEditable(authenticationEnabled);
553 		this.passwordField.setEditable(authenticationEnabled);
554 		this.userField.setEnabled(authenticationEnabled);
555 		this.passwordField.setEnabled(authenticationEnabled);
556 		this.userField.setText((authenticationEnabled && filesetInfo != null) ? 
557 				filesetInfo.getPreferenceAttributeById(USER).getValue() : "");
558 		this.passwordField.setText((authenticationEnabled && filesetInfo != null) ? 
559 				filesetInfo.getPreferenceAttributeById(PASSWORD).getValue() : "");
560 	}	
561 
562 	/**
563 	 * Helper class to that acts as the model for the fileset JList 
564 	 */
565 	private class FilesetModel extends AbstractListModel {
566 		
567 		/**
568 		 * Serial Version UID
569 		 */
570 		private static final long serialVersionUID = 3895409787401891091L;
571 		
572 		/**
573 		 * Collection that holds the configured fileset data
574 		 */
575 		private ArrayList configuredFilesets = new ArrayList();
576 
577 		/**
578 		 * No args constructor
579 		 */
580 		public FilesetModel() {
581 			Iterator iterator = preference.iterateChildPreferences();
582 			while(iterator.hasNext()) {
583 				Preference filesetPreference = (Preference)iterator.next();
584 				configuredFilesets.add(filesetPreference);
585 			}			
586 		}
587 
588 		/**
589 		 * Adds the specified fileset information to this model
590 		 * @param filesetInfo Preference containing the file set information to be added
591 		 */
592 		public void addFileset(Preference filesetInfo) {
593 			configuredFilesets.add(filesetInfo);
594 			super.fireIntervalAdded(this, configuredFilesets.size() - 1, configuredFilesets.size() - 1);
595 		}
596 		
597 		/**
598 		 * Informs this model that the data at the specified index has changed
599 		 * @param index index at which the data has changed
600 		 */
601 		public void listDataUpdated(int index) {
602 			super.fireContentsChanged(this, index, index);
603 		}		
604 		
605 		/**
606 		 * Removes the specified fileset information to this model
607 		 * @param index from where to remove the file set information
608 		 */
609 		public void removeFileset(int index) {
610 			if (index < 0 || index >= configuredFilesets.size()) {
611 				return;
612 			}
613 			configuredFilesets.remove(index);
614 			super.fireIntervalRemoved(this, index, index);
615 		}
616 		
617 		
618 		/** 
619 		 * Superclass abstract method implementation
620 		 * @see javax.swing.ListModel#getSize()
621 		 */
622 		public int getSize() {
623 			return configuredFilesets.size();
624 		}
625 		
626 		/**
627 		 * Returns the Preference at the sepcified index
628 		 * @param index index of the required Preference
629 		 * @return Preference at the specified index
630 		 */
631 		public Preference getPreference(int index) {
632 			return (Preference)configuredFilesets.get(index);
633 		}
634 
635 		/** 
636 		 * Superclass abstract method implementation
637 		 * @see javax.swing.ListModel#getElementAt(int)
638 		 */
639 		public Object getElementAt(int index) {
640 			return ((Preference)configuredFilesets.get(index)).getPreferenceInfo();
641 		}
642 	}
643 	
644 	/**
645 	 * Helper class to that acts as the model for the URL JList 
646 	 */
647 	private class URLListModel extends AbstractListModel {
648 		
649 		/**
650 		 * Serial Version UID
651 		 */
652 		private static final long serialVersionUID = 3079808278133329149L;
653 		
654 		/**
655 		 * Collection that holds the configured URL data
656 		 */
657 		private ArrayList configuredURLs = new ArrayList();
658 
659 		/**
660 		 * No args constructor
661 		 */
662 		public URLListModel() {
663 			// No args constructor
664 		}
665 
666 		/**
667 		 * Adds the specified URL information to this model
668 		 * @param url the URL string
669 		 */
670 		public void addURL(String url) {
671 			configuredURLs.add(url);
672 			super.fireIntervalAdded(this, configuredURLs.size() - 1, configuredURLs.size() - 1);
673 		}
674 		
675 		/**
676 		 * Removes the specified URL information to this model
677 		 * @param index from where to remove the URL information
678 		 */
679 		public void removeURL(int index) {
680 			if (index < 0 || index >= configuredURLs.size()) {
681 				return;
682 			}			
683 			configuredURLs.remove(index);
684 			super.fireIntervalRemoved(this, index, index);
685 		}
686 		
687 		/**
688 		 * Clears the entire list contents
689 		 */
690 		public void clearAll() {
691 			if (configuredURLs.size() > 0) {
692 				int lastIndex = configuredURLs.size() - 1;
693 				configuredURLs.clear();
694 				super.fireIntervalRemoved(this, 0, lastIndex);
695 			}
696 		}
697 		
698 		/** 
699 		 * Superclass abstract method implementation
700 		 * @see javax.swing.ListModel#getSize()
701 		 */
702 		public int getSize() {
703 			return configuredURLs.size();
704 		}
705 
706 		/** 
707 		 * Superclass abstract method implementation
708 		 * @see javax.swing.ListModel#getElementAt(int)
709 		 */
710 		public Object getElementAt(int index) {
711 			return configuredURLs.get(index);
712 		}
713 	}
714 
715 }