KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > updatecenter > DataModel


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.ui.wizard.updatecenter;
21
22 import java.net.URL JavaDoc;
23 import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
24 import org.netbeans.modules.apisupport.project.ManifestManager;
25 import org.netbeans.modules.apisupport.project.Util;
26 import org.netbeans.modules.apisupport.project.layers.LayerUtils;
27 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
28 import org.openide.WizardDescriptor;
29 import org.openide.filesystems.FileObject;
30 import org.openide.filesystems.FileSystem;
31
32 /**
33  * Data model used across the <em>New Update Center Wizard</em>.
34  * @author Jiri Rechtacek
35  */

36 final class DataModel extends BasicWizardIterator.BasicDataModel {
37     
38     static private String JavaDoc AUTOUPDATE_TYPES = "Services/AutoupdateType"; //NOI18N
39
private String JavaDoc AUTOUPDATE_SERVICE_TYPE = "_update_center"; //NOI18N
40
static private String JavaDoc AUTOUPDATE_SERVICE_TYPE_EXT = "settings"; //NOI18N
41
static private String JavaDoc UC_LOCALIZING_BUNDLE = "SystemFileSystem.localizingBundle"; //NOI18N
42
static private String JavaDoc AUTOUPDATE_MODULE = "org.netbeans.modules.autoupdate"; // NOI18N
43

44     private CreatedModifiedFiles cmf;
45     
46     // third panel data (Name, and Location)
47
private String JavaDoc ucUrl;
48     private String JavaDoc ucDisplayName;
49
50     DataModel(WizardDescriptor wiz) {
51         super(wiz);
52     }
53     
54     private CreatedModifiedFiles regenerate () {
55         if (cmf == null) {
56             cmf = new CreatedModifiedFiles (getProject ());
57         }
58         URL JavaDoc url = DataModel.class.getResource ("update_center.xml"); //NOI18N
59
assert url != null : "File 'update_center.xml must exist in package of " + getClass().getName() + "!";
60         String JavaDoc serviceTypeName = getModuleInfo().getCodeNameBase ().replace ('.', '_') + AUTOUPDATE_SERVICE_TYPE; // NOI18N
61
FileSystem layer = LayerUtils.layerForProject (getProject ()).layer (false);
62         
63         String JavaDoc pathToAutoUpdateType = AUTOUPDATE_TYPES + '/' + serviceTypeName + '.' + AUTOUPDATE_SERVICE_TYPE_EXT;
64         int sequence = 0;
65         if (layer != null) {
66             FileObject f;
67             do {
68                 f = layer.findResource (pathToAutoUpdateType);
69                 if (f != null) {
70                     pathToAutoUpdateType = AUTOUPDATE_TYPES + '/' + serviceTypeName + '_' + ++sequence + '.' + AUTOUPDATE_SERVICE_TYPE_EXT;
71                 }
72             } while (f != null);
73         }
74         cmf.add (cmf.createLayerEntry (pathToAutoUpdateType, url, null, null, null));
75         
76         String JavaDoc url_key_base = getModuleInfo().getCodeNameBase ().replace ('.', '_') + AUTOUPDATE_SERVICE_TYPE; //NOI18N
77
String JavaDoc url_key = sequence == 0 ? url_key_base : url_key_base + '_' + sequence; // NOI18N
78
cmf.add (cmf.createLayerAttribute (pathToAutoUpdateType, "url_key", url_key)); //NOI18N
79
cmf.add (cmf.createLayerAttribute (pathToAutoUpdateType, "enabled", Boolean.TRUE)); //NOI18N
80

81         // write into bundle
82
ManifestManager mm = ManifestManager.getInstance(Util.getManifest(getModuleInfo().getManifestFile()), false);
83         String JavaDoc localizingBundle = mm.getLocalizingBundle ();
84         localizingBundle = localizingBundle.substring (0, localizingBundle.indexOf ('.'));
85         localizingBundle = localizingBundle.replace ('/', '.');
86         cmf.add (cmf.createLayerAttribute (pathToAutoUpdateType, UC_LOCALIZING_BUNDLE, localizingBundle));
87         
88         cmf.add (cmf.bundleKeyDefaultBundle (pathToAutoUpdateType, ucDisplayName));
89         cmf.add (cmf.bundleKeyDefaultBundle (url_key, ucUrl));
90         
91         // add dependency to autoupdate module
92
cmf.add (cmf.addModuleDependency (AUTOUPDATE_MODULE, null, null, false));
93         
94         return cmf;
95     }
96     
97     CreatedModifiedFiles refreshCreatedModifiedFiles() {
98         return regenerate ();
99     }
100     
101     void setUpdateCenterURL (String JavaDoc url) {
102         this.ucUrl = url;
103     }
104     
105     String JavaDoc getUpdateCenterURL () {
106         return ucUrl != null ? ucUrl : ""; //NOI18N
107
}
108     
109     void setUpdateCenterDisplayName (String JavaDoc name) {
110         this.ucDisplayName = name;
111     }
112     
113     String JavaDoc getUpdateCenterDisplayName () {
114         return ucDisplayName != null ? ucDisplayName : ""; //NOI18N
115
}
116     
117 }
118
119
Popular Tags