KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > templates > PDETemplateSection


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.ui.templates;
13
14 import java.net.MalformedURLException JavaDoc;
15 import java.net.URL JavaDoc;
16 import java.util.ArrayList JavaDoc;
17 import java.util.Locale JavaDoc;
18 import java.util.ResourceBundle JavaDoc;
19
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.core.runtime.Platform;
23 import org.eclipse.pde.ui.templates.OptionTemplateSection;
24 import org.osgi.framework.Bundle;
25
26 public abstract class PDETemplateSection extends OptionTemplateSection {
27
28     public static final String JavaDoc KEY_PRODUCT_BRANDING = "productBranding"; //$NON-NLS-1$
29
public static final String JavaDoc KEY_PRODUCT_NAME = "productName"; //$NON-NLS-1$
30

31     public static final String JavaDoc VALUE_PRODUCT_ID = "product"; //$NON-NLS-1$
32
public static final String JavaDoc VALUE_PRODUCT_NAME = "RCP Product"; //$NON-NLS-1$
33
public static final String JavaDoc VALUE_PERSPECTIVE_NAME = "RCP Perspective"; //$NON-NLS-1$
34
public static final String JavaDoc VALUE_APPLICATION_ID = "application"; //$NON-NLS-1$
35

36     protected ResourceBundle JavaDoc getPluginResourceBundle() {
37         Bundle JavaDoc bundle = Platform.getBundle(Activator.getPluginId());
38         return Platform.getResourceBundle(bundle);
39     }
40     
41     protected URL JavaDoc getInstallURL() {
42         return Activator.getDefault().getInstallURL();
43     }
44     
45     public URL JavaDoc getTemplateLocation() {
46         try {
47             String JavaDoc[] candidates = getDirectoryCandidates();
48             for (int i = 0; i < candidates.length; i++) {
49                 if (Activator.getDefault().getBundle().getEntry(candidates[i]) != null) {
50                     URL JavaDoc candidate = new URL JavaDoc(getInstallURL(), candidates[i]);
51                     return candidate;
52                 }
53             }
54         } catch (MalformedURLException JavaDoc e) {
55         }
56         return null;
57     }
58
59     private String JavaDoc[] getDirectoryCandidates() {
60         double version = getTargetVersion();
61         ArrayList JavaDoc result = new ArrayList JavaDoc();
62         if (version >= 3.3)
63             result.add("templates_3.3" + "/" + getSectionId() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
64
if (version >= 3.2)
65             result.add("templates_3.2" + "/" + getSectionId() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
66
if (version >= 3.1)
67             result.add("templates_3.1" + "/" + getSectionId() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
68
if (version >= 3.0)
69             result.add("templates_3.0" + "/" + getSectionId() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
70
return (String JavaDoc[])result.toArray(new String JavaDoc[result.size()]);
71     }
72     
73     /* (non-Javadoc)
74      * @see org.eclipse.pde.ui.templates.ITemplateSection#getFoldersToInclude()
75      */

76     public String JavaDoc[] getNewFiles() {
77         return new String JavaDoc[0];
78     }
79     
80     protected String JavaDoc getFormattedPackageName(String JavaDoc id){
81         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
82         for (int i = 0; i < id.length(); i++) {
83             char ch = id.charAt(i);
84             if (buffer.length() == 0) {
85                 if (Character.isJavaIdentifierStart(ch))
86                     buffer.append(Character.toLowerCase(ch));
87             } else {
88                 if (Character.isJavaIdentifierPart(ch) || ch == '.')
89                     buffer.append(ch);
90             }
91         }
92         return buffer.toString().toLowerCase(Locale.ENGLISH);
93     }
94     
95     protected void generateFiles(IProgressMonitor monitor) throws CoreException {
96         super.generateFiles(monitor);
97         // Copy the default splash screen if the branding option is selected
98
if (copyBrandingDirectory()) {
99             super.generateFiles(monitor, Activator.getDefault().getBundle().getEntry("branding/")); //$NON-NLS-1$
100
}
101     }
102     
103     protected boolean copyBrandingDirectory() {
104         return getBooleanOption(KEY_PRODUCT_BRANDING);
105     }
106     
107     protected void createBrandingOptions() {
108         addOption(KEY_PRODUCT_BRANDING, PDETemplateMessages.HelloRCPTemplate_productBranding, false, 0);
109     }
110     
111
112 }
113
Popular Tags