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.Set;
007: import javax.swing.event.ChangeEvent;
008: import javax.swing.event.ChangeListener;
009:
010: import org.netbeans.modules.mashup.db.model.FlatfileDBTable;
011: import org.netbeans.modules.mashup.db.model.impl.FlatfileDBTableImpl;
012: import org.openide.WizardDescriptor;
013: import org.openide.util.HelpCtx;
014:
015: import java.util.List;
016:
017: public class SpreadsheetChooserPanel implements WizardDescriptor.Panel {
018:
019: /**
020: * The visual component that displays this panel. If you need to access the
021: * component from this class, just use getComponent().
022: */
023: private Component component;
024:
025: // Get the visual component for the panel. In this template, the component
026: // is kept separate. This can be more efficient: if the wizard is created
027: // but never displayed, or not all panels are displayed, it is better to
028: // create only those which really need to be visible.
029: public Component getComponent() {
030: if (component == null) {
031: component = new SpreadsheetChooserVisualPanel(this );
032: }
033: return component;
034: }
035:
036: public HelpCtx getHelp() {
037: return HelpCtx.DEFAULT_HELP;
038: }
039:
040: public boolean isValid() {
041: return canAdvance();
042: }
043:
044: private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(
045: 1);
046:
047: public final void addChangeListener(ChangeListener l) {
048: synchronized (listeners) {
049: listeners.add(l);
050: }
051: }
052:
053: public final void removeChangeListener(ChangeListener l) {
054: synchronized (listeners) {
055: listeners.remove(l);
056: }
057: }
058:
059: protected final void fireChangeEvent() {
060: Iterator<ChangeListener> it;
061: synchronized (listeners) {
062: it = new HashSet<ChangeListener>(listeners).iterator();
063: }
064: ChangeEvent ev = new ChangeEvent(this );
065: while (it.hasNext()) {
066: it.next().stateChanged(ev);
067: }
068: }
069:
070: public void readSettings(Object settings) {
071: if (settings instanceof WizardDescriptor) {
072: WizardDescriptor wd = (WizardDescriptor) settings;
073: List<String> tables = (List<String>) wd
074: .getProperty(MashupTableWizardIterator.URL_LIST);
075: int index = Integer
076: .parseInt((String) wd
077: .getProperty(MashupTableWizardIterator.TABLE_INDEX));
078: ((SpreadsheetChooserVisualPanel) getComponent())
079: .populateSheets(tables.get(index));
080: }
081: }
082:
083: public void storeSettings(Object settings) {
084: if (settings instanceof WizardDescriptor) {
085: WizardDescriptor wd = (WizardDescriptor) settings;
086: FlatfileDBTable table = (FlatfileDBTable) wd
087: .getProperty(MashupTableWizardIterator.PROP_CURRENTTABLE);
088: if (!((SpreadsheetChooserVisualPanel) getComponent())
089: .getSelectedSheetName().equals("")) {
090: ((FlatfileDBTableImpl) table)
091: .setOrPutProperty(
092: "SHEET",
093: ((SpreadsheetChooserVisualPanel) getComponent())
094: .getSelectedSheetName());
095: }
096: }
097: }
098:
099: private boolean canAdvance() {
100: return ((SpreadsheetChooserVisualPanel) getComponent())
101: .canAdvance();
102: }
103: }
|