KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > retriever > RetrieveXMLResourceWizardPanel1


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.ui.retriever;
21
22 import java.awt.Component JavaDoc;
23 import java.io.File JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URI JavaDoc;
26 import java.net.URISyntaxException JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.Set JavaDoc;
31 import javax.swing.event.ChangeEvent JavaDoc;
32 import javax.swing.event.ChangeListener JavaDoc;
33 import org.openide.WizardDescriptor;
34 import org.openide.util.HelpCtx;
35 import org.netbeans.modules.xml.retriever.IConstants;
36 import org.openide.util.NbBundle;
37
38 public class RetrieveXMLResourceWizardPanel1 implements WizardDescriptor.Panel, ChangeListener JavaDoc{
39     
40     
41     /**
42      * The visual component that displays this panel. If you need to access the
43      * component from this class, just use getComponent().
44      */

45     private Component JavaDoc component;
46     private RetrieveXMLResourceVisualPanel1 retrieveXMLResourceVisualPanel1;
47     WizardDescriptor wizd = null;
48     // Get the visual component for the panel. In this template, the component
49
// is kept separate. This can be more efficient: if the wizard is created
50
// but never displayed, or not all panels are displayed, it is better to
51
// create only those which really need to be visible.
52
public Component JavaDoc getComponent() {
53         if (component == null) {
54             component = new RetrieveXMLResourceVisualPanel1(this);
55             retrieveXMLResourceVisualPanel1 = (RetrieveXMLResourceVisualPanel1)component;
56             retrieveXMLResourceVisualPanel1.addChangeListener(this);
57         }
58         return component;
59     }
60     
61     public WizardDescriptor getWizardDescriptor(){
62         return wizd;
63     }
64     
65     public HelpCtx getHelp() {
66         // Show no Help button for this panel:
67
//return HelpCtx.DEFAULT_HELP;
68
return new HelpCtx(RetrieveXMLResourceWizardPanel1.class);
69         // If you have context help:
70
// return new HelpCtx(SampleWizardPanel1.class);
71
}
72     
73     public boolean isValid() {
74         if(retrieveXMLResourceVisualPanel1.getSelectedSourceType() == RetrieveXMLResourceVisualPanel1.SourceType.LOCAL_FILE){
75             if(retrieveXMLResourceVisualPanel1.getSourceLocation() == null) {
76                 return false;
77             }
78             File JavaDoc sourceFile = null;
79             try {
80                 sourceFile = new File JavaDoc(new URI JavaDoc(retrieveXMLResourceVisualPanel1.getSourceLocation()));
81             } catch (URISyntaxException JavaDoc ex) {
82             }
83             if(!sourceFile.isDirectory()){
84                 return false;
85             }
86             
87             if(retrieveXMLResourceVisualPanel1.getSaveLocation() == null){
88                 return false;
89             }
90             return true;
91         }
92         if(retrieveXMLResourceVisualPanel1.getSelectedSourceType() == RetrieveXMLResourceVisualPanel1.SourceType.URL_ADDR){
93             String JavaDoc sourceLocation = retrieveXMLResourceVisualPanel1.getSourceLocation();
94             if((sourceLocation != null) && (sourceLocation.length() <= 0)){
95                 return false;
96             }
97             try {
98                 URL JavaDoc url = new URL JavaDoc(sourceLocation);
99                 if(url.getPath().trim().length() <= 0){
100                     return false;
101                 }
102                 if(url.getProtocol().equalsIgnoreCase("http") && //NOI18N
103
(url.getHost().length()<= 0)) {
104                     return false;
105                 }
106             } catch (MalformedURLException JavaDoc ex) {
107                 return false;
108             }
109             return true;
110         }
111         return false;
112     }
113     
114     private void setErrorMessage( String JavaDoc key ) {
115         if ( key == null ) {
116             wizd.putProperty("WizardPanel_errorMessage", ""); // NOI18N
117
} else {
118             String JavaDoc message = NbBundle.getMessage(
119                     RetrieveXMLResourceWizardPanel1.class, key); // NOI18N
120
wizd.putProperty("WizardPanel_errorMessage", message);
121         }
122     }
123         
124     private final Set JavaDoc<ChangeListener JavaDoc> listeners = new HashSet JavaDoc<ChangeListener JavaDoc>(1);
125     public final void addChangeListener(ChangeListener JavaDoc l) {
126         synchronized (listeners) {
127             listeners.add(l);
128         }
129     }
130     public final void removeChangeListener(ChangeListener JavaDoc l) {
131         synchronized (listeners) {
132             listeners.remove(l);
133         }
134     }
135     protected final void fireChangeEvent() {
136         Iterator JavaDoc<ChangeListener JavaDoc> it;
137         synchronized (listeners) {
138             it = new HashSet JavaDoc<ChangeListener JavaDoc>(listeners).iterator();
139         }
140         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
141         while (it.hasNext()) {
142             it.next().stateChanged(ev);
143         }
144     }
145     
146     
147     // You can use a settings object to keep track of state. Normally the
148
// settings object will be the WizardDescriptor, so you can use
149
// WizardDescriptor.getProperty & putProperty to store information entered
150
// by the user.
151
public void readSettings(Object JavaDoc settings) {
152         wizd = (WizardDescriptor) settings;
153         retrieveXMLResourceVisualPanel1.refreshSaveLocation();
154         //System.out.println("READDDD :"+settings);
155
}
156     public void storeSettings(Object JavaDoc settings) {
157         //System.out.println("Storeeeeeee");
158
wizd = (WizardDescriptor) settings;
159         wizd.putProperty(IConstants.RETRIVE_CLOSURE_KEY, Boolean.valueOf(retrieveXMLResourceVisualPanel1.retrieveClosure()));
160         wizd.putProperty(IConstants.SOURCE_LOCATION_KEY, retrieveXMLResourceVisualPanel1.getSourceLocation());
161         wizd.putProperty(IConstants.TARGET_FILE_KEY, retrieveXMLResourceVisualPanel1.getSaveLocation());
162         wizd.putProperty(IConstants.SOURCE_TYPE_KEY, retrieveXMLResourceVisualPanel1.getDocType());
163         wizd.putProperty(IConstants.SOURCE_LOCATION_TYPE_KEY, retrieveXMLResourceVisualPanel1.getSelectedSourceType());
164         wizd.putProperty(IConstants.USER_SELECTED_SAVE_ROOT, retrieveXMLResourceVisualPanel1.getSelectedSaveRootFolder());
165         wizd.putProperty(IConstants.OVERWRITE_FILES, retrieveXMLResourceVisualPanel1.shouldOverwrite());
166     }
167     
168     public void stateChanged(ChangeEvent JavaDoc e) {
169         fireChangeEvent();
170     }
171     
172 }
173
174
Popular Tags