1 19 20 package org.openide.loaders; 21 22 23 import java.io.IOException ; 24 import javax.swing.event.ChangeListener ; 25 import org.openide.WizardDescriptor; 26 import org.openide.filesystems.FileObject; 27 import org.openide.util.*; 28 29 33 final class NewObjectWizardPanel implements WizardDescriptor.FinishablePanel<WizardDescriptor> { 34 private NewObjectPanel newObjectPanelUI; 35 36 private ChangeListener listener; 37 38 DataFolder targetFolder; 39 42 private String extension; 43 44 private TemplateWizard wizard; 45 46 private NewObjectPanel getPanelUI () { 47 if (newObjectPanelUI == null) { 48 newObjectPanelUI = new NewObjectPanel (); 49 newObjectPanelUI.addChangeListener (listener); 50 } 51 return newObjectPanelUI; 52 } 53 54 58 public void addChangeListener (ChangeListener l) { 59 if (listener != null) throw new IllegalStateException (); 60 if (newObjectPanelUI != null) 61 newObjectPanelUI.addChangeListener (l); 62 listener = l; 63 } 64 65 68 public void removeChangeListener (ChangeListener l) { 69 listener = null; 70 if (newObjectPanelUI != null) 71 newObjectPanelUI.removeChangeListener (l); 72 } 73 74 82 public java.awt.Component getComponent() { 83 return getPanelUI (); 84 } 85 86 89 public org.openide.util.HelpCtx getHelp () { 90 return new HelpCtx (NewObjectPanel.class); 91 } 92 93 100 public boolean isValid () { 101 String errorMsg = null; 102 boolean isOK = true; 103 if (!targetFolder.getPrimaryFile ().canWrite ()) { 105 errorMsg = NbBundle.getMessage(TemplateWizard2.class, "MSG_fs_is_readonly"); 106 isOK = false; 107 } 108 if (isOK) { 109 Object obj = targetFolder.getPrimaryFile().getAttribute( "isRemoteAndSlow" ); boolean makeFileExistsChecks = true; 111 if( obj instanceof Boolean ) 112 makeFileExistsChecks = ! ((Boolean ) obj).booleanValue(); 113 if( makeFileExistsChecks ) { 114 FileObject f = targetFolder.getPrimaryFile().getFileObject(getPanelUI ().getNewObjectName (), extension); 116 if (f != null) { 117 errorMsg = NbBundle.getMessage(TemplateWizard2.class, "MSG_file_already_exist", f.getNameExt()); isOK = false; 119 } 120 if ((Utilities.isWindows () || (Utilities.getOperatingSystem () == Utilities.OS_OS2))) { 121 if (TemplateWizard.checkCaseInsensitiveName (targetFolder.getPrimaryFile (), getPanelUI ().getNewObjectName (), extension)) { 122 errorMsg = NbBundle.getMessage(TemplateWizard2.class, "MSG_file_already_exist", getPanelUI ().getNewObjectName ()); isOK = false; 124 } 125 } 126 127 } 128 } 129 wizard.putProperty("WizardPanel_errorMessage", errorMsg); return isOK; 131 } 132 133 138 public void readSettings(WizardDescriptor settings) { 139 this.wizard = (TemplateWizard)settings; 140 DataObject template = wizard.getTemplate (); 141 if (template != null) { 142 extension = template.getPrimaryFile().getExt(); 143 } 144 145 try { 146 targetFolder = wizard.getTargetFolder(); 147 } catch (IOException x) { 148 Exceptions.printStackTrace(x); 149 } 150 151 } 152 153 162 public void storeSettings(WizardDescriptor settings) { 163 String name = getPanelUI ().getNewObjectName (); 164 if (name.equals (NewObjectPanel.defaultNewObjectName ())) { 165 name = null; 166 } 167 if (wizard != null) { 168 wizard.setTargetName (name); 169 wizard = null; 170 } 171 172 } 173 174 public boolean isFinishPanel () { 175 return true; 176 } 177 178 } 179 | Popular Tags |