01: package org.netbeans.modules.mashup.tables.wizard;
02:
03: import java.awt.Component;
04: import java.util.HashSet;
05: import java.util.Iterator;
06: import java.util.Set;
07: import javax.swing.event.ChangeEvent;
08: import javax.swing.event.ChangeListener;
09: import javax.swing.table.DefaultTableModel;
10:
11: import org.openide.WizardDescriptor;
12: import org.openide.util.HelpCtx;
13: import java.util.ArrayList;
14: import java.util.List;
15:
16: public class FileSelectionPanel implements WizardDescriptor.Panel {
17:
18: /**
19: * The visual component that displays this panel. If you need to access the
20: * component from this class, just use getComponent().
21: */
22: private Component component;
23: private WizardDescriptor wd;
24:
25: public Component getComponent() {
26: if (component == null) {
27: component = new FileSelectionVisualPanel(this );
28: }
29: return component;
30: }
31:
32: public HelpCtx getHelp() {
33: return HelpCtx.DEFAULT_HELP;
34: }
35:
36: public boolean isValid() {
37: return canAdvance();
38: }
39:
40: private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(
41: 1);
42:
43: public final void addChangeListener(ChangeListener l) {
44: synchronized (listeners) {
45: listeners.add(l);
46: }
47: }
48:
49: public final void removeChangeListener(ChangeListener l) {
50: synchronized (listeners) {
51: listeners.remove(l);
52: }
53: }
54:
55: protected final void fireChangeEvent() {
56: Iterator<ChangeListener> it;
57: synchronized (listeners) {
58: it = new HashSet<ChangeListener>(listeners).iterator();
59: }
60: ChangeEvent ev = new ChangeEvent(this );
61: while (it.hasNext()) {
62: it.next().stateChanged(ev);
63: }
64: }
65:
66: public void readSettings(Object settings) {
67: if (settings instanceof WizardDescriptor) {
68: wd = (WizardDescriptor) settings;
69: }
70: }
71:
72: public void storeSettings(Object settings) {
73: if (settings instanceof WizardDescriptor) {
74: WizardDescriptor wizDes = (WizardDescriptor) settings;
75: DefaultTableModel tables = ((FileSelectionVisualPanel) getComponent())
76: .getSelectedTables();
77: wizDes.putProperty(MashupTableWizardIterator.TABLE_LIST,
78: setTables(tables));
79: wizDes.putProperty(MashupTableWizardIterator.URL_LIST,
80: setTables(tables));
81: }
82: }
83:
84: private List<String> setTables(DefaultTableModel model) {
85: List<String> tables = new ArrayList<String>();
86: for (int i = 0; i < model.getRowCount(); i++) {
87: tables.add((String) model.getValueAt(i, 1));
88: }
89: return tables;
90: }
91:
92: private boolean canAdvance() {
93: return ((FileSelectionVisualPanel) getComponent()).canAdvance();
94: }
95: }
|