001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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.wizards.extension;
011:
012: import java.lang.reflect.InvocationTargetException;
013:
014: import org.eclipse.core.resources.IProject;
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.jface.operation.IRunnableWithProgress;
017: import org.eclipse.pde.core.plugin.IPluginBase;
018: import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
019: import org.eclipse.pde.core.plugin.IPluginModelBase;
020: import org.eclipse.pde.internal.ui.PDEPlugin;
021: import org.eclipse.pde.internal.ui.PDEUIMessages;
022:
023: public class NewExtensionPointMainPage extends
024: BaseExtensionPointMainPage {
025: private IPluginModelBase fModel;
026: private IPluginExtensionPoint fPoint;
027:
028: public NewExtensionPointMainPage(IProject project,
029: IPluginModelBase model) {
030: this (project, model, null);
031: }
032:
033: public NewExtensionPointMainPage(IProject project,
034: IPluginModelBase model, IPluginExtensionPoint point) {
035: super (project);
036: initialize();
037: this .fModel = model;
038: this .fPoint = point;
039: }
040:
041: public void initialize() {
042: setTitle(PDEUIMessages.NewExtensionPointWizard_title);
043: setDescription(PDEUIMessages.NewExtensionPointWizard_desc);
044: }
045:
046: protected boolean isPluginIdFinal() {
047: return true;
048: }
049:
050: public boolean finish() {
051: setPageComplete(false);
052: final String id = fIdText.getText();
053: final String name = fNameText.getText();
054: final String schema = fSchemaText.getText();
055:
056: IPluginBase plugin = fModel.getPluginBase();
057:
058: IPluginExtensionPoint point = fModel.getFactory()
059: .createExtensionPoint();
060: try {
061: point.setId(id);
062: if (name.length() > 0)
063: point.setName(name);
064: if (schema.length() > 0)
065: point.setSchema(schema);
066:
067: plugin.add(point);
068: } catch (CoreException e) {
069: PDEPlugin.logException(e);
070: }
071:
072: if (schema.length() > 0) {
073: IRunnableWithProgress operation = getOperation();
074: try {
075: getContainer().run(true, true, operation);
076: } catch (InvocationTargetException e) {
077: PDEPlugin.logException(e);
078: return false;
079: } catch (InterruptedException e) {
080: return false;
081: }
082: }
083: return true;
084: }
085:
086: public String getPluginId() {
087: return fModel.getPluginBase().getId();
088: }
089:
090: protected void initializeValues() {
091: if (fPoint == null)
092: return;
093: if (fIdText != null && fPoint.getId() != null)
094: fIdText.setText(fPoint.getId());
095: if (fNameText != null && fPoint.getName() != null)
096: fNameText.setText(fPoint.getName());
097: if (fSchemaText != null && fPoint.getSchema() != null)
098: fSchemaText.setText(fPoint.getSchema());
099: }
100:
101: protected String validateFieldContents() {
102: String message = validateExtensionPointID();
103: if (message != null)
104: return message;
105:
106: message = validateExtensionPointName();
107: if (message != null)
108: return message;
109:
110: message = validateExtensionPointSchema();
111: if (message != null)
112: return message;
113:
114: return null;
115: }
116:
117: protected String validateExtensionPointSchema() {
118: // Do not validate "Extension Point Schema" Field
119: return null;
120: }
121:
122: }
|