1 19 20 package org.netbeans.modules.group; 21 22 import java.awt.event.ActionEvent ; 23 import java.io.IOException ; 24 import java.util.Collections ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.NoSuchElementException ; 29 import java.util.Set ; 30 import javax.swing.event.ChangeListener ; 31 import org.openide.WizardDescriptor; 32 import org.openide.WizardDescriptor.Panel; 33 import org.openide.actions.ActionManager; 34 import org.openide.loaders.DataFolder; 35 import org.openide.loaders.DataLoader; 36 import org.openide.loaders.DataObject; 37 import org.openide.loaders.TemplateWizard; 38 import org.openide.nodes.Node; 39 import org.openide.util.Lookup; 40 import org.openide.util.actions.SystemAction; 41 42 47 class GroupTemplateIterator implements TemplateWizard.Iterator { 48 49 50 private Panel targetPanel = null; 51 52 53 GroupTemplateIterator() { 54 } 55 56 64 public Set instantiate(TemplateWizard wiz) throws IOException { 65 String nam = wiz.getTargetName(); 66 DataFolder folder = wiz.getTargetFolder(); 67 DataObject template = wiz.getTemplate(); 68 69 if (template instanceof GroupShadow) { 72 GroupShadow group = (GroupShadow) template; 73 List createdObjs = group.createGroupFromTemplate(folder, nam, true); 74 HashSet templObjs = new HashSet (createdObjs.size()); 75 76 if (createdObjs != null) { 77 Iterator it = createdObjs.iterator(); 78 while (it.hasNext()) { 79 DataObject obj = (DataObject) it.next(); 80 if (!(obj instanceof DataFolder) 81 && !(obj instanceof GroupShadow)) { 82 templObjs.add(obj); 83 Node node = obj.getNodeDelegate(); 84 SystemAction sa = node.getDefaultAction(); 85 if (sa != null) { 86 ActionManager actionManager 87 = (ActionManager) Lookup.getDefault().lookup(ActionManager.class); 88 actionManager.invokeAction(sa, new ActionEvent (node, ActionEvent.ACTION_PERFORMED, "")); } 90 } 91 } 92 } 93 return templObjs; 94 } else { 95 DataObject obj = nam == null ? 96 template.createFromTemplate(folder) : 97 template.createFromTemplate(folder, nam); 98 99 return Collections.singleton(obj); 100 } 101 } 102 103 104 public void initialize(TemplateWizard wiz) { 105 targetPanel = wiz.targetChooser(); 106 } 107 108 109 public void uninitialize(TemplateWizard wiz) { 110 targetPanel = null; 111 } 112 113 115 public Panel current() { 116 return targetPanel; 117 } 118 119 120 public String name() { 121 return ""; } 123 124 127 public boolean hasNext() { 128 return false; 129 } 130 131 134 public boolean hasPrevious() { 135 return false; 136 } 137 138 144 public void nextPanel() { 145 throw new NoSuchElementException (); 146 } 147 148 154 public void previousPanel() { 155 throw new NoSuchElementException (); 156 } 157 158 159 public void addChangeListener(ChangeListener l) {} 160 161 162 public void removeChangeListener(ChangeListener l) {} 163 164 } | Popular Tags |