001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.templates;
011:
012: import java.net.MalformedURLException;
013: import java.net.URL;
014: import java.util.ArrayList;
015: import java.util.Locale;
016: import java.util.ResourceBundle;
017:
018: import org.eclipse.core.runtime.CoreException;
019: import org.eclipse.core.runtime.IProgressMonitor;
020: import org.eclipse.core.runtime.Platform;
021: import org.eclipse.pde.ui.templates.OptionTemplateSection;
022: import org.osgi.framework.Bundle;
023:
024: public abstract class PDETemplateSection extends OptionTemplateSection {
025:
026: public static final String KEY_PRODUCT_BRANDING = "productBranding"; //$NON-NLS-1$
027: public static final String KEY_PRODUCT_NAME = "productName"; //$NON-NLS-1$
028:
029: public static final String VALUE_PRODUCT_ID = "product"; //$NON-NLS-1$
030: public static final String VALUE_PRODUCT_NAME = "RCP Product"; //$NON-NLS-1$
031: public static final String VALUE_PERSPECTIVE_NAME = "RCP Perspective"; //$NON-NLS-1$
032: public static final String VALUE_APPLICATION_ID = "application"; //$NON-NLS-1$
033:
034: protected ResourceBundle getPluginResourceBundle() {
035: Bundle bundle = Platform.getBundle(Activator.getPluginId());
036: return Platform.getResourceBundle(bundle);
037: }
038:
039: protected URL getInstallURL() {
040: return Activator.getDefault().getInstallURL();
041: }
042:
043: public URL getTemplateLocation() {
044: try {
045: String[] candidates = getDirectoryCandidates();
046: for (int i = 0; i < candidates.length; i++) {
047: if (Activator.getDefault().getBundle().getEntry(
048: candidates[i]) != null) {
049: URL candidate = new URL(getInstallURL(),
050: candidates[i]);
051: return candidate;
052: }
053: }
054: } catch (MalformedURLException e) {
055: }
056: return null;
057: }
058:
059: private String[] getDirectoryCandidates() {
060: double version = getTargetVersion();
061: ArrayList result = new ArrayList();
062: if (version >= 3.3)
063: result.add("templates_3.3" + "/" + getSectionId() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
064: if (version >= 3.2)
065: result.add("templates_3.2" + "/" + getSectionId() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
066: if (version >= 3.1)
067: result.add("templates_3.1" + "/" + getSectionId() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
068: if (version >= 3.0)
069: result.add("templates_3.0" + "/" + getSectionId() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
070: return (String[]) result.toArray(new String[result.size()]);
071: }
072:
073: /* (non-Javadoc)
074: * @see org.eclipse.pde.ui.templates.ITemplateSection#getFoldersToInclude()
075: */
076: public String[] getNewFiles() {
077: return new String[0];
078: }
079:
080: protected String getFormattedPackageName(String id) {
081: StringBuffer buffer = new StringBuffer();
082: for (int i = 0; i < id.length(); i++) {
083: char ch = id.charAt(i);
084: if (buffer.length() == 0) {
085: if (Character.isJavaIdentifierStart(ch))
086: buffer.append(Character.toLowerCase(ch));
087: } else {
088: if (Character.isJavaIdentifierPart(ch) || ch == '.')
089: buffer.append(ch);
090: }
091: }
092: return buffer.toString().toLowerCase(Locale.ENGLISH);
093: }
094:
095: protected void generateFiles(IProgressMonitor monitor)
096: throws CoreException {
097: super .generateFiles(monitor);
098: // Copy the default splash screen if the branding option is selected
099: if (copyBrandingDirectory()) {
100: super .generateFiles(monitor, Activator.getDefault()
101: .getBundle().getEntry("branding/")); //$NON-NLS-1$
102: }
103: }
104:
105: protected boolean copyBrandingDirectory() {
106: return getBooleanOption(KEY_PRODUCT_BRANDING);
107: }
108:
109: protected void createBrandingOptions() {
110: addOption(KEY_PRODUCT_BRANDING,
111: PDETemplateMessages.HelloRCPTemplate_productBranding,
112: false, 0);
113: }
114:
115: }
|