001: /*******************************************************************************
002: * Copyright (c) 2006, 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.cheatsheet;
011:
012: import java.util.StringTokenizer;
013:
014: import org.eclipse.core.runtime.IPath;
015: import org.eclipse.jface.viewers.IStructuredSelection;
016: import org.eclipse.osgi.util.NLS;
017: import org.eclipse.pde.internal.core.util.PDETextHelper;
018: import org.eclipse.pde.internal.ui.PDEUIMessages;
019: import org.eclipse.swt.widgets.Composite;
020:
021: /**
022: * SimpleCheatSheetFileWizardPage
023: *
024: */
025: public class SimpleCSFileWizardPage extends CSFileWizardPage {
026:
027: public final static String F_PAGE_NAME = "simple-cheatsheet"; //$NON-NLS-1$
028:
029: private String fAbsoluteFileName;
030:
031: private String fProjectName;
032:
033: /**
034: * @param pageName
035: * @param selection
036: */
037: public SimpleCSFileWizardPage(IStructuredSelection selection) {
038: super (F_PAGE_NAME, selection);
039:
040: // Initialize called by parent
041: fAbsoluteFileName = null;
042: }
043:
044: /* (non-Javadoc)
045: * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.CheatSheetFileWizardPage#initialize()
046: */
047: protected void initialize() {
048: setTitle(PDEUIMessages.CheatSheetFileWizardPage_1);
049: setDescription(PDEUIMessages.SimpleCSFileWizardPage_simpleCSWizardDescription);
050: // Force the file extension to be 'xml'
051: setFileExtension(F_FILE_EXTENSION);
052: }
053:
054: /* (non-Javadoc)
055: * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.CheatSheetFileWizardPage#getCheatSheetType()
056: */
057: public int getCheatSheetType() {
058: return F_SIMPLE_CHEAT_SHEET;
059: }
060:
061: /* (non-Javadoc)
062: * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.CheatSheetFileWizardPage#createAdvancedControls(org.eclipse.swt.widgets.Composite)
063: */
064: protected void createAdvancedControls(Composite parent) {
065: // NO-OP
066: }
067:
068: /* (non-Javadoc)
069: * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.CheatSheetFileWizardPage#validatePage()
070: */
071: protected boolean validatePage() {
072: // Set the absolute file name
073: fAbsoluteFileName = getContainerFullPath().toPortableString()
074: + IPath.SEPARATOR + getFileName();
075: // Verify that the project name chosen by the user to store the simple
076: // cheat sheet is the same project name the composite cheat sheet is
077: // stored in
078: if (PDETextHelper.isDefined(fProjectName)) {
079: // Form: /<project-name>/<dir>/<dir>/<file>
080: String path = getContainerFullPath().toPortableString();
081: StringTokenizer tokenizer = new StringTokenizer(path,
082: new Character(IPath.SEPARATOR).toString());
083: String compareProject = tokenizer.nextToken();
084: if (compareProject.equals(fProjectName) == false) {
085: setErrorMessage(NLS
086: .bind(
087: PDEUIMessages.SimpleCSFileWizardPage_errorInvalidProjectSelected,
088: fProjectName));
089: return false;
090: }
091: }
092:
093: return super .validatePage();
094: }
095:
096: /**
097: * @return
098: */
099: public String getAbsoluteFileName() {
100: // This is needed because the resource and group widget is disposed
101: // before the file name can be retrieved
102: return fAbsoluteFileName;
103: }
104:
105: /**
106: * @param projectName
107: */
108: public void setProjectName(String projectName) {
109: fProjectName = projectName;
110: }
111:
112: }
|