1 19 package org.openide; 20 21 22 import org.netbeans.api.progress.ProgressHandle; 23 import org.netbeans.junit.NbTestSuite; 24 25 import java.awt.Component ; 26 import java.io.IOException ; 27 import java.util.*; 28 import javax.swing.*; 29 import javax.swing.JLabel ; 30 import javax.swing.event.ChangeListener ; 31 import org.openide.InstantiatingIteratorTest.Listener; 32 import org.openide.util.HelpCtx; 33 34 38 public class ProgressInstantiatingIteratorTest extends AsynchronousInstantiatingIteratorTest { 39 40 41 public ProgressInstantiatingIteratorTest (String name) { 42 super(name); 43 } 44 45 46 private Iterator iterator; 47 48 protected void setUp () { 49 iterator = new Iterator (); 50 wd = new WizardDescriptor (iterator); 51 wd.addPropertyChangeListener(new Listener ()); 52 java.awt.Dialog d = DialogDisplayer.getDefault ().createDialog (wd); 53 checkOrder = false; 54 shouldThrowException = false; 55 } 57 58 59 protected boolean runInEQ() { 60 return true; 61 } 62 63 public class Panel implements WizardDescriptor.FinishablePanel { 64 private JLabel component; 65 private String text; 66 public Panel(String text) { 67 this.text = text; 68 } 69 70 public Component getComponent() { 71 if (component == null) { 72 component = new JLabel (text); 73 } 74 return component; 75 } 76 77 public void addChangeListener(ChangeListener l) { 78 changeListenersInPanel.add (l); 79 } 80 81 public HelpCtx getHelp() { 82 return null; 83 } 84 85 public boolean isValid() { 86 return true; 87 } 88 89 public void readSettings(Object settings) { 90 log ("readSettings of panel: " + text + " [time: " + System.currentTimeMillis () + 91 "] with PROP_VALUE: " + handleValue (wd.getValue ())); 92 } 93 94 public void removeChangeListener(ChangeListener l) { 95 changeListenersInPanel.remove (l); 96 } 97 98 public void storeSettings(Object settings) { 99 if (checkOrder) { 100 assertNull ("WD.P.storeSettings() called before WD.I.instantiate()", iterator.result); 101 checkOrder = false; 104 } 105 log ("storeSettings of panel: " + text + " [time: " + System.currentTimeMillis () + 106 "] with PROP_VALUE: " + handleValue (wd.getValue ())); 107 if (exceptedValue != null) { 108 assertEquals ("WD.getValue() returns excepted value.", exceptedValue, handleValue (wd.getValue ())); 109 } 110 } 111 112 public boolean isFinishPanel () { 113 return true; 114 } 115 116 } 117 118 protected Boolean getInitialized () { 119 return iterator.initialized; 120 } 121 122 protected Set getResult () { 123 return iterator.result; 124 } 125 126 public class Iterator implements WizardDescriptor.ProgressInstantiatingIterator { 127 int index = 0; 128 WizardDescriptor.Panel panels[] = new WizardDescriptor.Panel[2]; 129 java.util.Set helpSet; 130 131 private Boolean initialized = null; 132 private Set result = null; 133 134 public WizardDescriptor.Panel current () { 135 assertTrue ("WD.current() called on initialized iterator.", initialized != null && initialized.booleanValue ()); 136 return panels[index]; 137 } 138 public String name () { 139 return "Test iterator"; 140 } 141 public boolean hasNext () { 142 return index < 1; 143 } 144 public boolean hasPrevious () { 145 return index > 0; 146 } 147 public void nextPanel () { 148 if (!hasNext ()) throw new NoSuchElementException (); 149 index ++; 150 } 151 public void previousPanel () { 152 if (!hasPrevious ()) throw new NoSuchElementException (); 153 index --; 154 } 155 public void addChangeListener (ChangeListener l) { 156 changeListenersInIterator.add (l); 157 } 158 public void removeChangeListener (ChangeListener l) { 159 changeListenersInIterator.remove (l); 160 } 161 public void initialize (WizardDescriptor wizard) { 162 helpSet = new HashSet (); 163 panels[0] = new Panel("first panel"); 164 panels[1] = new Panel("second panel"); 165 initialized = Boolean.TRUE; 166 } 167 public void uninitialize (WizardDescriptor wizard) { 168 helpSet.clear (); 169 initialized = Boolean.FALSE; 170 panels = null; 171 } 172 173 public Set instantiate (ProgressHandle handle) throws IOException { 174 assertNotNull ("ProgressHandle cannot be null", handle); 175 if (checkIfInAWT) { 176 if (SwingUtilities.isEventDispatchThread ()) { 177 throw new IOException ("Cannot run in AWT queue."); 178 } 179 } 180 if (shouldThrowException) { 181 throw new IOException ("Test throw IOException during instantiate()."); 182 } 183 if (initialized.booleanValue ()) { 184 helpSet.add ("member"); 185 result = helpSet; 186 } else { 187 result = null; 188 } 189 return result; 190 } 191 192 public Set instantiate () throws IOException { 193 fail ("Cannot call this method iff implement ProgressInstantiatingIterator!"); 194 return null; 195 } 196 } 197 198 } 199 | Popular Tags |