KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > extension > NewSchemaFileMainPage


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 package org.eclipse.pde.internal.ui.wizards.extension;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.resources.IContainer;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.resources.IWorkspaceRoot;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.Path;
20 import org.eclipse.jface.operation.IRunnableWithProgress;
21 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
22 import org.eclipse.pde.core.plugin.IPluginModelBase;
23 import org.eclipse.pde.core.plugin.PluginRegistry;
24 import org.eclipse.pde.internal.core.PDECore;
25 import org.eclipse.pde.internal.ui.PDEPlugin;
26 import org.eclipse.pde.internal.ui.PDEUIMessages;
27
28 public class NewSchemaFileMainPage extends BaseExtensionPointMainPage {
29     private IPluginExtensionPoint fPoint;
30     private boolean isPluginIdFinal;
31     
32     public NewSchemaFileMainPage(IContainer container) {
33         this(container, null, false);
34     }
35     
36     public NewSchemaFileMainPage(IContainer container, IPluginExtensionPoint point, boolean isPluginIdFinal){
37         super(container);
38         setTitle(PDEUIMessages.NewSchemaFileWizard_title);
39         setDescription(PDEUIMessages.NewSchemaFileWizard_desc);
40         this.fPoint = point;
41         this.isPluginIdFinal = isPluginIdFinal;
42     }
43
44     public boolean finish() {
45         IRunnableWithProgress operation = getOperation();
46         try {
47             getContainer().run(true, true, operation);
48             if (fPoint != null){
49                 fPoint.setId(fIdText.getText());
50                 fPoint.setName(fNameText.getText());
51                 fPoint.setSchema(fSchemaText.getText());
52             }
53                 
54         } catch (InvocationTargetException JavaDoc e) {
55             PDEPlugin.logException(e);
56             return false;
57         } catch (InterruptedException JavaDoc e) {
58             return false;
59         } catch (CoreException e){
60             return false;
61         }
62         return true;
63     }
64     protected boolean isPluginIdNeeded() {
65         return true;
66     }
67     protected boolean isPluginIdFinal(){
68         return isPluginIdFinal;
69     }
70     protected boolean isSharedSchemaSwitchNeeded() {
71         return true;
72     }
73     public void initializeValues(){
74         if (fContainer!=null){
75             fPluginIdText.setText(fContainer.getProject().getName());
76             if (!isPluginIdFinal())
77                 fSchemaLocationText.setText(fContainer.getProject().getName() + "/" + fContainer.getProjectRelativePath().toString()); //$NON-NLS-1$
78
}
79         if (fPoint == null)
80             return;
81         if (fIdText!=null && fPoint.getId()!=null)
82             fIdText.setText(fPoint.getId());
83         if (fNameText !=null && fPoint.getName() != null)
84             fNameText.setText(fPoint.getName());
85         if (fSchemaText!= null && fPoint.getSchema()!=null)
86             fSchemaText.setText(fPoint.getSchema());
87         
88         fPluginIdText.setEnabled(!isPluginIdFinal);
89         fPluginBrowseButton.setEnabled(!isPluginIdFinal);
90     }
91     
92     protected String JavaDoc validateFieldContents() {
93         String JavaDoc message = validatePluginID();
94         if (message != null)
95             return message;
96         
97         message = validateExtensionPointID();
98         if (message != null)
99             return message;
100         
101         message = validateExtensionPointName();
102         if (message != null)
103             return message;
104         
105         message = validateContainer();
106         if (message != null)
107             return message;
108         
109         message = validateExtensionPointSchema();
110         if (message != null)
111             return message;
112         
113         return null;
114     }
115     
116     protected String JavaDoc validatePluginID() {
117         // Verify not zero length
118
String JavaDoc pluginID = getPluginId();
119         if (pluginID.length() == 0)
120             return PDEUIMessages.NewSchemaFileMainPage_missingPluginID;
121
122         // Verify plug-in ID exists
123
IPluginModelBase model = PluginRegistry.findModel(pluginID);
124         if (model == null)
125             return PDEUIMessages.NewSchemaFileMainPage_nonExistingPluginID;
126
127         // Verify plug-in ID is not an external model
128
if (model.getUnderlyingResource() == null)
129             return PDEUIMessages.NewSchemaFileMainPage_externalPluginID;
130
131         return null;
132     }
133
134     protected String JavaDoc validateContainer() {
135         if (!isPluginIdFinal()) {
136             // Ensure not zero length
137
String JavaDoc newContainerName = fSchemaLocationText.getText().trim();
138             if (newContainerName.length() == 0)
139                 return PDEUIMessages.NewSchemaFileMainPage_missingContainer;
140
141             // Ensure valid target container
142
IWorkspaceRoot root = PDECore.getWorkspace().getRoot();
143             IResource resource = root.findMember(new Path(newContainerName));
144             if (resource instanceof IContainer) {
145                 fContainer = (IContainer) resource;
146             } else {
147                 fContainer = null;
148                 return PDEUIMessages.NewSchemaFileMainPage_invalidContainer;
149             }
150         }
151
152         // Ensure target container exists
153
if (fContainer == null || !fContainer.exists())
154             return PDEUIMessages.NewSchemaFileMainPage_nonExistingContainer;
155
156         return null;
157     }
158     
159 }
160
Popular Tags