1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
65
66
67
68
69
70
71
72
73 public class SFTPFilesUIPanel extends AbstractPreferencesUIPanel implements
74 ActionListener {
75
76
77
78
79 private static final long serialVersionUID = 4045426549505018717L;
80
81
82
83
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
99
100
101
102
103 private static final String DEFAULT_PORT = "22";
104
105
106
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
115
116 private int action = NONE;
117
118
119
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
141
142 private GridBagLayout gl;
143 private GridBagConstraints gc;
144
145
146
147
148
149
150 public SFTPFilesUIPanel() {
151
152 }
153
154
155
156
157
158
159
160
161
162
163
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
177
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
221
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
241
242
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
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
291 updateURLListToPreference(childPreference);
292 setDetailsWidgetsEnable(false);
293 this.action = NONE;
294 }
295 }
296
297
298
299
300
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
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
366 setDetailsWidgetsEnable(false);
367 }
368
369
370
371
372
373 protected void setPreferenceValues() {
374
375 updateFilesetListToPreference();
376 }
377
378
379
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
400
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
441
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
470
471
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
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
533
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
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
568
569
570
571
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
587
588 private class FilesetModel extends AbstractListModel {
589
590
591
592
593 private static final long serialVersionUID = -261681791719547352L;
594
595
596
597
598 private ArrayList configuredFilesets = new ArrayList();
599
600
601
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
613
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
622
623
624 public void listDataUpdated(int index) {
625 super.fireContentsChanged(this, index, index);
626 }
627
628
629
630
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
643
644
645 public int getSize() {
646 return configuredFilesets.size();
647 }
648
649
650
651
652
653
654 public Preference getPreference(int index) {
655 return (Preference)configuredFilesets.get(index);
656 }
657
658
659
660
661
662 public Object getElementAt(int index) {
663 return ((Preference)configuredFilesets.get(index)).getPreferenceInfo();
664 }
665 }
666
667
668
669
670 private class URLListModel extends AbstractListModel {
671
672
673
674
675 private static final long serialVersionUID = 5839919813014289538L;
676
677
678
679
680 private ArrayList configuredURLs = new ArrayList();
681
682
683
684
685 public URLListModel() {
686
687 }
688
689
690
691
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
700
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
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
723
724
725 public int getSize() {
726 return configuredURLs.size();
727 }
728
729
730
731
732
733 public Object getElementAt(int index) {
734 return configuredURLs.get(index);
735 }
736 }
737
738 }