| /******************************************************************************* |
| * Copyright (c) 2005, 2007 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.pde.internal.ui.templates.rcp; |
| |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.jface.wizard.Wizard; |
| import org.eclipse.jface.wizard.WizardPage; |
| import org.eclipse.pde.core.plugin.IPluginBase; |
| import org.eclipse.pde.core.plugin.IPluginElement; |
| import org.eclipse.pde.core.plugin.IPluginExtension; |
| import org.eclipse.pde.core.plugin.IPluginModelBase; |
| import org.eclipse.pde.core.plugin.IPluginReference; |
| import org.eclipse.pde.internal.ui.templates.IHelpContextIds; |
| import org.eclipse.pde.internal.ui.templates.PDETemplateMessages; |
| import org.eclipse.pde.internal.ui.templates.PDETemplateSection; |
| import org.eclipse.pde.ui.IFieldData; |
| import org.eclipse.pde.ui.templates.PluginReference; |
| |
| public class HelloRCPTemplate extends PDETemplateSection { |
| |
| public static final String KEY_APPLICATION_CLASS = "applicationClass"; //$NON-NLS-1$ |
| public static final String KEY_WINDOW_TITLE = "windowTitle"; //$NON-NLS-1$ |
| |
| public HelloRCPTemplate() { |
| setPageCount(1); |
| createOptions(); |
| } |
| |
| @Override |
| public void addPages(Wizard wizard) { |
| WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_RCP_MAIL); |
| page.setTitle(PDETemplateMessages.HelloRCPTemplate_title); |
| page.setDescription(PDETemplateMessages.HelloRCPTemplate_desc); |
| wizard.addPage(page); |
| markPagesAdded(); |
| } |
| |
| private void createOptions() { |
| addOption(KEY_WINDOW_TITLE, PDETemplateMessages.HelloRCPTemplate_windowTitle, "Hello RCP", 0); //$NON-NLS-1$ |
| |
| addOption(KEY_PACKAGE_NAME, PDETemplateMessages.MailTemplate_packageName, (String) null, 0); |
| |
| addOption(KEY_APPLICATION_CLASS, PDETemplateMessages.HelloRCPTemplate_appClass, "Application", 0); //$NON-NLS-1$ |
| |
| createBrandingOptions(); |
| } |
| |
| @Override |
| protected void initializeFields(IFieldData data) { |
| // In a new project wizard, we don't know this yet - the |
| // model has not been created |
| String packageName = getFormattedPackageName(data.getId()); |
| initializeOption(KEY_PACKAGE_NAME, packageName); |
| } |
| |
| @Override |
| public void initializeFields(IPluginModelBase model) { |
| String packageName = getFormattedPackageName(model.getPluginBase().getId()); |
| initializeOption(KEY_PACKAGE_NAME, packageName); |
| } |
| |
| @Override |
| public String getSectionId() { |
| return "helloRCP"; //$NON-NLS-1$ |
| } |
| |
| @Override |
| protected void updateModel(IProgressMonitor monitor) throws CoreException { |
| createApplicationExtension(); |
| createPerspectiveExtension(); |
| if (getBooleanOption(KEY_PRODUCT_BRANDING)) |
| createProductExtension(); |
| } |
| |
| private void createApplicationExtension() throws CoreException { |
| IPluginBase plugin = model.getPluginBase(); |
| |
| IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); //$NON-NLS-1$ |
| extension.setId(VALUE_APPLICATION_ID); |
| |
| IPluginElement element = model.getPluginFactory().createElement(extension); |
| element.setName("application"); //$NON-NLS-1$ |
| extension.add(element); |
| |
| IPluginElement run = model.getPluginFactory().createElement(element); |
| run.setName("run"); //$NON-NLS-1$ |
| run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); //$NON-NLS-1$ //$NON-NLS-2$ |
| element.add(run); |
| |
| if (!extension.isInTheModel()) |
| plugin.add(extension); |
| } |
| |
| private void createPerspectiveExtension() throws CoreException { |
| IPluginBase plugin = model.getPluginBase(); |
| |
| IPluginExtension extension = createExtension("org.eclipse.ui.perspectives", true); //$NON-NLS-1$ |
| IPluginElement element = model.getPluginFactory().createElement(extension); |
| element.setName("perspective"); //$NON-NLS-1$ |
| element.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); //$NON-NLS-1$ //$NON-NLS-2$ |
| element.setAttribute("name", VALUE_PERSPECTIVE_NAME); //$NON-NLS-1$ |
| element.setAttribute("id", plugin.getId() + ".perspective"); //$NON-NLS-1$ //$NON-NLS-2$ |
| extension.add(element); |
| |
| if (!extension.isInTheModel()) |
| plugin.add(extension); |
| } |
| |
| private void createProductExtension() throws CoreException { |
| IPluginBase plugin = model.getPluginBase(); |
| IPluginExtension extension = createExtension("org.eclipse.core.runtime.products", true); //$NON-NLS-1$ |
| extension.setId(VALUE_PRODUCT_ID); |
| |
| IPluginElement element = model.getFactory().createElement(extension); |
| element.setName("product"); //$NON-NLS-1$ |
| element.setAttribute("name", getStringOption(KEY_WINDOW_TITLE)); //$NON-NLS-1$ |
| element.setAttribute("application", plugin.getId() + "." + VALUE_APPLICATION_ID); //$NON-NLS-1$ //$NON-NLS-2$ |
| |
| IPluginElement property = model.getFactory().createElement(element); |
| |
| property = model.getFactory().createElement(element); |
| property.setName("property"); //$NON-NLS-1$ |
| property.setAttribute("name", "windowImages"); //$NON-NLS-1$ //$NON-NLS-2$ |
| property.setAttribute("value", "icons/alt_window_16.gif,icons/alt_window_32.gif"); //$NON-NLS-1$ //$NON-NLS-2$ |
| element.add(property); |
| |
| extension.add(element); |
| |
| if (!extension.isInTheModel()) |
| plugin.add(extension); |
| } |
| |
| @Override |
| public String getUsedExtensionPoint() { |
| return null; |
| } |
| |
| @Override |
| public boolean isDependentOnParentWizard() { |
| return true; |
| } |
| |
| @Override |
| public int getNumberOfWorkUnits() { |
| return super.getNumberOfWorkUnits() + 1; |
| } |
| |
| @Override |
| public IPluginReference[] getDependencies(String schemaVersion) { |
| IPluginReference[] dep = new IPluginReference[2]; |
| dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); //$NON-NLS-1$ |
| dep[1] = new PluginReference("org.eclipse.ui", null, 0); //$NON-NLS-1$ |
| return dep; |
| } |
| |
| @Override |
| public String[] getNewFiles() { |
| if (copyBrandingDirectory()) |
| return new String[] {"icons/", "splash.bmp"}; //$NON-NLS-1$ //$NON-NLS-2$ |
| return super.getNewFiles(); |
| } |
| } |