001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.support.components;
014:
015: import java.awt.BorderLayout;
016: import java.awt.Dimension;
017: import java.awt.event.ActionEvent;
018: import java.awt.event.ActionListener;
019: import java.io.File;
020:
021: import javax.swing.Box;
022: import javax.swing.BoxLayout;
023: import javax.swing.DefaultListModel;
024: import javax.swing.JButton;
025: import javax.swing.JList;
026: import javax.swing.JPanel;
027: import javax.swing.JScrollPane;
028: import javax.swing.event.ListSelectionEvent;
029: import javax.swing.event.ListSelectionListener;
030:
031: import com.eviware.soapui.support.UISupport;
032:
033: public class FileListFormComponent extends JPanel implements
034: JFormComponent, ActionListener {
035: private DefaultListModel listModel;
036: private JButton addButton;
037: private JButton removeButton;
038: private JList list;
039:
040: public FileListFormComponent(String tooltip) {
041: listModel = new DefaultListModel();
042: list = new JList(listModel);
043: list.setToolTipText(tooltip);
044: JScrollPane scrollPane = new JScrollPane(list);
045: scrollPane.setPreferredSize(new Dimension(300, 70));
046: add(scrollPane, BorderLayout.CENTER);
047: Box box = new Box(BoxLayout.Y_AXIS);
048: addButton = new JButton("Add..");
049: addButton.addActionListener(this );
050: box.add(addButton);
051: box.add(Box.createVerticalStrut(5));
052: removeButton = new JButton("Remove..");
053: removeButton.addActionListener(this );
054: box.add(removeButton);
055: box.add(Box.createVerticalGlue());
056:
057: add(box, BorderLayout.EAST);
058:
059: list.addListSelectionListener(new ListSelectionListener() {
060:
061: public void valueChanged(ListSelectionEvent e) {
062: removeButton.setEnabled(list.getSelectedIndex() != -1);
063: }
064: });
065:
066: removeButton.setEnabled(list.getSelectedIndex() != -1);
067: }
068:
069: public void setValue(String value) {
070: listModel.clear();
071: String[] files = value.split(";");
072: for (String file : files)
073: if (file.trim().length() > 0)
074: listModel.addElement(file);
075: }
076:
077: public String getValue() {
078: Object[] values = listModel.toArray();
079: StringBuffer buf = new StringBuffer();
080: for (int c = 0; c < values.length; c++) {
081: if (c > 0)
082: buf.append(';');
083:
084: buf.append(values[c]);
085: }
086:
087: return buf.toString();
088: }
089:
090: public void actionPerformed(ActionEvent arg0) {
091: if (arg0.getSource() == addButton) {
092: File file = UISupport.getFileDialogs().open(this ,
093: "Add file", null, null, null);
094: if (file != null) {
095: listModel.addElement(file.getAbsolutePath());
096: }
097: } else if (arg0.getSource() == removeButton
098: && list.getSelectedIndex() != -1) {
099: Object elm = listModel
100: .getElementAt(list.getSelectedIndex());
101: if (UISupport.confirm("Remove [" + elm.toString()
102: + "] from list", "Remove")) {
103: listModel.remove(list.getSelectedIndex());
104: }
105: }
106: }
107: }
|