KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > templates > ide > PropertyPageTemplate


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 package org.eclipse.pde.internal.ui.templates.ide;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.jface.wizard.Wizard;
18 import org.eclipse.jface.wizard.WizardPage;
19 import org.eclipse.pde.core.plugin.IPluginBase;
20 import org.eclipse.pde.core.plugin.IPluginElement;
21 import org.eclipse.pde.core.plugin.IPluginExtension;
22 import org.eclipse.pde.core.plugin.IPluginModelBase;
23 import org.eclipse.pde.core.plugin.IPluginModelFactory;
24 import org.eclipse.pde.core.plugin.IPluginReference;
25 import org.eclipse.pde.internal.ui.templates.IHelpContextIds;
26 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
27 import org.eclipse.pde.internal.ui.templates.PDETemplateSection;
28 import org.eclipse.pde.internal.ui.templates.PluginReference;
29 import org.eclipse.pde.ui.IFieldData;
30
31 public class PropertyPageTemplate extends PDETemplateSection {
32     public static final String JavaDoc KEY_CLASSNAME = "className"; //$NON-NLS-1$
33
public static final String JavaDoc KEY_PAGE_NAME = "pageName"; //$NON-NLS-1$
34
public static final String JavaDoc KEY_TARGET_CLASS = "targetClass"; //$NON-NLS-1$
35
public static final String JavaDoc KEY_NAME_FILTER = "nameFilter"; //$NON-NLS-1$
36

37     /**
38      * Constructor for PropertyPageTemplate.
39      */

40     public PropertyPageTemplate() {
41         setPageCount(1);
42         createOptions();
43     }
44
45     public void addPages(Wizard wizard) {
46         WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_PROPERTY_PAGE);
47         page.setTitle(PDETemplateMessages.PropertyPageTemplate_title);
48         page.setDescription(PDETemplateMessages.PropertyPageTemplate_desc);
49         wizard.addPage(page);
50         markPagesAdded();
51     }
52
53     private void createOptions() {
54         addOption(
55             KEY_PACKAGE_NAME,
56             PDETemplateMessages.PropertyPageTemplate_packageName,
57             (String JavaDoc) null,
58             0);
59         addOption(
60             KEY_CLASSNAME,
61             PDETemplateMessages.PropertyPageTemplate_pageClass,
62             "SamplePropertyPage", //$NON-NLS-1$
63
0);
64         addOption(
65             KEY_PAGE_NAME,
66             PDETemplateMessages.PropertyPageTemplate_pageName,
67             PDETemplateMessages.PropertyPageTemplate_defaultPageName,
68             0);
69         addOption(
70             KEY_TARGET_CLASS,
71             PDETemplateMessages.PropertyPageTemplate_targetClass,
72             "org.eclipse.core.resources.IFile", //$NON-NLS-1$
73
0);
74         addOption(
75             KEY_NAME_FILTER,
76             PDETemplateMessages.PropertyPageTemplate_nameFilter,
77             "*.*", //$NON-NLS-1$
78
0);
79     }
80     /**
81      * @see PDETemplateSection#getSectionId()
82      */

83     public String JavaDoc getSectionId() {
84         return "propertyPages"; //$NON-NLS-1$
85
}
86
87     public boolean isDependentOnParentWizard() {
88         return true;
89     }
90     
91
92     protected void initializeFields(IFieldData data) {
93         // In a new project wizard, we don't know this yet - the
94
// model has not been created
95
String JavaDoc id = data.getId();
96         initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id));
97     }
98
99     public void initializeFields(IPluginModelBase model) {
100         // In the new extension wizard, the model exists so
101
// we can initialize directly from it
102
String JavaDoc pluginId = model.getPluginBase().getId();
103         initializeOption(KEY_PACKAGE_NAME,getFormattedPackageName(pluginId));
104     }
105
106     /**
107      * @see AbstractTemplateSection#updateModel(IProgressMonitor)
108      */

109     protected void updateModel(IProgressMonitor monitor) throws CoreException {
110         IPluginBase plugin = model.getPluginBase();
111         IPluginExtension extension = createExtension(getUsedExtensionPoint(), true);
112         IPluginModelFactory factory = model.getPluginFactory();
113
114         IPluginElement pageElement = factory.createElement(extension);
115         pageElement.setName("page"); //$NON-NLS-1$
116
pageElement.setAttribute(
117             "id", //$NON-NLS-1$
118
getStringOption(KEY_PACKAGE_NAME) + ".samplePropertyPage"); //$NON-NLS-1$
119
pageElement.setAttribute("name", getStringOption(KEY_PAGE_NAME)); //$NON-NLS-1$
120
pageElement.setAttribute("objectClass", getStringOption(KEY_TARGET_CLASS)); //$NON-NLS-1$
121
pageElement.setAttribute(
122             "class", //$NON-NLS-1$
123
getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_CLASSNAME)); //$NON-NLS-1$
124
pageElement.setAttribute("nameFilter", getStringOption(KEY_NAME_FILTER)); //$NON-NLS-1$
125

126         extension.add(pageElement);
127         if (!extension.isInTheModel())
128             plugin.add(extension);
129     }
130
131     /**
132      * @see ITemplateSection#getUsedExtensionPoint()
133      */

134     public String JavaDoc getUsedExtensionPoint() {
135         return "org.eclipse.ui.propertyPages"; //$NON-NLS-1$
136
}
137     
138     /* (non-Javadoc)
139      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
140      */

141     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
142         ArrayList JavaDoc result = new ArrayList JavaDoc();
143         result.add(new PluginReference("org.eclipse.core.resources", null, 0)); //$NON-NLS-1$
144
if (schemaVersion != null)
145             result.add(new PluginReference("org.eclipse.core.runtime", null, 0)); //$NON-NLS-1$
146
result.add(new PluginReference("org.eclipse.ui", null, 0)); //$NON-NLS-1$
147

148         return (IPluginReference[])result.toArray(new IPluginReference[result.size()]);
149     }
150     
151     /* (non-Javadoc)
152      * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#formatPackageName(java.lang.String)
153      */

154     protected String JavaDoc getFormattedPackageName(String JavaDoc id) {
155         String JavaDoc packageName = super.getFormattedPackageName(id);
156         if (packageName.length() != 0)
157             return packageName + ".properties"; //$NON-NLS-1$
158
return "properties"; //$NON-NLS-1$
159
}
160
161 }
162
Popular Tags