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