001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 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.IContainer;
015: import org.eclipse.core.resources.IResource;
016: import org.eclipse.core.resources.IWorkspaceRoot;
017: import org.eclipse.core.runtime.CoreException;
018: import org.eclipse.core.runtime.Path;
019: import org.eclipse.jface.operation.IRunnableWithProgress;
020: import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
021: import org.eclipse.pde.core.plugin.IPluginModelBase;
022: import org.eclipse.pde.core.plugin.PluginRegistry;
023: import org.eclipse.pde.internal.core.PDECore;
024: import org.eclipse.pde.internal.ui.PDEPlugin;
025: import org.eclipse.pde.internal.ui.PDEUIMessages;
026:
027: public class NewSchemaFileMainPage extends BaseExtensionPointMainPage {
028: private IPluginExtensionPoint fPoint;
029: private boolean isPluginIdFinal;
030:
031: public NewSchemaFileMainPage(IContainer container) {
032: this (container, null, false);
033: }
034:
035: public NewSchemaFileMainPage(IContainer container,
036: IPluginExtensionPoint point, boolean isPluginIdFinal) {
037: super (container);
038: setTitle(PDEUIMessages.NewSchemaFileWizard_title);
039: setDescription(PDEUIMessages.NewSchemaFileWizard_desc);
040: this .fPoint = point;
041: this .isPluginIdFinal = isPluginIdFinal;
042: }
043:
044: public boolean finish() {
045: IRunnableWithProgress operation = getOperation();
046: try {
047: getContainer().run(true, true, operation);
048: if (fPoint != null) {
049: fPoint.setId(fIdText.getText());
050: fPoint.setName(fNameText.getText());
051: fPoint.setSchema(fSchemaText.getText());
052: }
053:
054: } catch (InvocationTargetException e) {
055: PDEPlugin.logException(e);
056: return false;
057: } catch (InterruptedException e) {
058: return false;
059: } catch (CoreException e) {
060: return false;
061: }
062: return true;
063: }
064:
065: protected boolean isPluginIdNeeded() {
066: return true;
067: }
068:
069: protected boolean isPluginIdFinal() {
070: return isPluginIdFinal;
071: }
072:
073: protected boolean isSharedSchemaSwitchNeeded() {
074: return true;
075: }
076:
077: public void initializeValues() {
078: if (fContainer != null) {
079: fPluginIdText.setText(fContainer.getProject().getName());
080: if (!isPluginIdFinal())
081: fSchemaLocationText
082: .setText(fContainer.getProject().getName()
083: + "/" + fContainer.getProjectRelativePath().toString()); //$NON-NLS-1$
084: }
085: if (fPoint == null)
086: return;
087: if (fIdText != null && fPoint.getId() != null)
088: fIdText.setText(fPoint.getId());
089: if (fNameText != null && fPoint.getName() != null)
090: fNameText.setText(fPoint.getName());
091: if (fSchemaText != null && fPoint.getSchema() != null)
092: fSchemaText.setText(fPoint.getSchema());
093:
094: fPluginIdText.setEnabled(!isPluginIdFinal);
095: fPluginBrowseButton.setEnabled(!isPluginIdFinal);
096: }
097:
098: protected String validateFieldContents() {
099: String message = validatePluginID();
100: if (message != null)
101: return message;
102:
103: message = validateExtensionPointID();
104: if (message != null)
105: return message;
106:
107: message = validateExtensionPointName();
108: if (message != null)
109: return message;
110:
111: message = validateContainer();
112: if (message != null)
113: return message;
114:
115: message = validateExtensionPointSchema();
116: if (message != null)
117: return message;
118:
119: return null;
120: }
121:
122: protected String validatePluginID() {
123: // Verify not zero length
124: String pluginID = getPluginId();
125: if (pluginID.length() == 0)
126: return PDEUIMessages.NewSchemaFileMainPage_missingPluginID;
127:
128: // Verify plug-in ID exists
129: IPluginModelBase model = PluginRegistry.findModel(pluginID);
130: if (model == null)
131: return PDEUIMessages.NewSchemaFileMainPage_nonExistingPluginID;
132:
133: // Verify plug-in ID is not an external model
134: if (model.getUnderlyingResource() == null)
135: return PDEUIMessages.NewSchemaFileMainPage_externalPluginID;
136:
137: return null;
138: }
139:
140: protected String validateContainer() {
141: if (!isPluginIdFinal()) {
142: // Ensure not zero length
143: String newContainerName = fSchemaLocationText.getText()
144: .trim();
145: if (newContainerName.length() == 0)
146: return PDEUIMessages.NewSchemaFileMainPage_missingContainer;
147:
148: // Ensure valid target container
149: IWorkspaceRoot root = PDECore.getWorkspace().getRoot();
150: IResource resource = root.findMember(new Path(
151: newContainerName));
152: if (resource instanceof IContainer) {
153: fContainer = (IContainer) resource;
154: } else {
155: fContainer = null;
156: return PDEUIMessages.NewSchemaFileMainPage_invalidContainer;
157: }
158: }
159:
160: // Ensure target container exists
161: if (fContainer == null || !fContainer.exists())
162: return PDEUIMessages.NewSchemaFileMainPage_nonExistingContainer;
163:
164: return null;
165: }
166:
167: }
|