KickJava   Java API By Example, From Geeks To Geeks.

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


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.wizards.extension;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.jface.operation.IRunnableWithProgress;
18 import org.eclipse.pde.core.plugin.IPluginBase;
19 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
20 import org.eclipse.pde.core.plugin.IPluginModelBase;
21 import org.eclipse.pde.internal.ui.PDEPlugin;
22 import org.eclipse.pde.internal.ui.PDEUIMessages;
23
24 public class NewExtensionPointMainPage extends BaseExtensionPointMainPage {
25     private IPluginModelBase fModel;
26     private IPluginExtensionPoint fPoint;
27     
28     public NewExtensionPointMainPage(
29             IProject project,
30             IPluginModelBase model) {
31         this(project, model, null);
32     }
33     
34     public NewExtensionPointMainPage(IProject project, IPluginModelBase model, IPluginExtensionPoint point){
35         super(project);
36         initialize();
37         this.fModel = model;
38         this.fPoint = point;
39     }
40     public void initialize(){
41         setTitle(PDEUIMessages.NewExtensionPointWizard_title);
42         setDescription(PDEUIMessages.NewExtensionPointWizard_desc);
43     }
44     
45     protected boolean isPluginIdFinal(){
46         return true;
47     }
48     public boolean finish() {
49         setPageComplete(false);
50         final String JavaDoc id = fIdText.getText();
51         final String JavaDoc name = fNameText.getText();
52         final String JavaDoc schema = fSchemaText.getText();
53         
54         IPluginBase plugin = fModel.getPluginBase();
55         
56         IPluginExtensionPoint point = fModel.getFactory().createExtensionPoint();
57         try {
58             point.setId(id);
59             if (name.length() > 0)
60                 point.setName(name);
61             if (schema.length() > 0)
62                 point.setSchema(schema);
63             
64             plugin.add(point);
65         } catch (CoreException e) {
66             PDEPlugin.logException(e);
67         }
68         
69         if (schema.length() > 0) {
70             IRunnableWithProgress operation = getOperation();
71             try {
72                 getContainer().run(true, true, operation);
73             } catch (InvocationTargetException JavaDoc e) {
74                 PDEPlugin.logException(e);
75                 return false;
76             } catch (InterruptedException JavaDoc e) {
77                 return false;
78             }
79         }
80         return true;
81     }
82     public String JavaDoc getPluginId() {
83         return fModel.getPluginBase().getId();
84     }
85     protected void initializeValues(){
86         if (fPoint == null)
87             return;
88         if (fIdText!=null && fPoint.getId()!=null)
89             fIdText.setText(fPoint.getId());
90         if (fNameText !=null && fPoint.getName() != null)
91             fNameText.setText(fPoint.getName());
92         if (fSchemaText!= null && fPoint.getSchema()!=null)
93             fSchemaText.setText(fPoint.getSchema());
94     }
95     
96     protected String JavaDoc validateFieldContents() {
97         String JavaDoc message = validateExtensionPointID();
98         if (message != null)
99             return message;
100         
101         message = validateExtensionPointName();
102         if (message != null)
103             return message;
104         
105         message = validateExtensionPointSchema();
106         if (message != null)
107             return message;
108         
109         return null;
110     }
111     
112     protected String JavaDoc validateExtensionPointSchema() {
113         // Do not validate "Extension Point Schema" Field
114
return null;
115     }
116     
117 }
118
Popular Tags