001: package org.netbeans.modules.mashup.tables.wizard;
002:
003: import java.awt.Component;
004: import java.util.HashSet;
005: import java.util.Iterator;
006: import java.util.List;
007: import java.util.Set;
008: import javax.swing.event.ChangeEvent;
009: import javax.swing.event.ChangeListener;
010:
011: import org.netbeans.modules.mashup.db.model.FlatfileDBTable;
012: import org.netbeans.modules.mashup.db.model.impl.FlatfileDBTableImpl;
013: import org.openide.WizardDescriptor;
014: import org.openide.util.HelpCtx;
015:
016: public class ChooseTablePanel implements WizardDescriptor.Panel {
017:
018: /**
019: * The visual component that displays this panel. If you need to access the
020: * component from this class, just use getComponent().
021: */
022: private Component component;
023:
024: public Component getComponent() {
025: if (component == null) {
026: component = new ChooseTableVisualPanel(this );
027: }
028: return component;
029: }
030:
031: public HelpCtx getHelp() {
032: return HelpCtx.DEFAULT_HELP;
033: }
034:
035: public boolean isValid() {
036: return canAdvance();
037: }
038:
039: private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(
040: 1);
041:
042: public final void addChangeListener(ChangeListener l) {
043: synchronized (listeners) {
044: listeners.add(l);
045: }
046: }
047:
048: public final void removeChangeListener(ChangeListener l) {
049: synchronized (listeners) {
050: listeners.remove(l);
051: }
052: }
053:
054: protected final void fireChangeEvent() {
055: Iterator<ChangeListener> it;
056: synchronized (listeners) {
057: it = new HashSet<ChangeListener>(listeners).iterator();
058: }
059: ChangeEvent ev = new ChangeEvent(this );
060: while (it.hasNext()) {
061: it.next().stateChanged(ev);
062: }
063: }
064:
065: public void readSettings(Object settings) {
066: if (settings instanceof WizardDescriptor) {
067: WizardDescriptor wd = (WizardDescriptor) settings;
068: FlatfileDBTable table = (FlatfileDBTable) wd
069: .getProperty(MashupTableWizardIterator.PROP_CURRENTTABLE);
070: List<String> urls = (List<String>) wd
071: .getProperty(MashupTableWizardIterator.URL_LIST);
072: int index = Integer
073: .parseInt((String) wd
074: .getProperty(MashupTableWizardIterator.TABLE_INDEX));
075: ((FlatfileDBTableImpl) table).setOrPutProperty("URL", urls
076: .get(index));
077: if (table != null) {
078: ((ChooseTableVisualPanel) getComponent())
079: .populateTablesList(urls.get(index));
080: }
081: }
082: }
083:
084: public void storeSettings(Object settings) {
085: if (settings instanceof WizardDescriptor) {
086: WizardDescriptor wd = (WizardDescriptor) settings;
087: FlatfileDBTable table = (FlatfileDBTable) wd
088: .getProperty(MashupTableWizardIterator.PROP_CURRENTTABLE);
089: ((FlatfileDBTableImpl) table)
090: .setOrPutProperty(
091: "TABLENUMBER",
092: String
093: .valueOf(((ChooseTableVisualPanel) getComponent())
094: .getTableDepth()));
095: }
096: }
097:
098: private boolean canAdvance() {
099: return ((ChooseTableVisualPanel) getComponent()).canAdvance();
100: }
101: }
|