001: /*
002: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004, Refractions Research Inc. This
003: * library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
004: * License as published by the Free Software Foundation; version 2.1 of the License. This library is distributed in the
005: * hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
006: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
007: */
008: package net.refractions.udig.project.ui.internal.wizard;
009:
010: import java.io.IOException;
011: import java.util.Collections;
012:
013: import net.refractions.udig.project.internal.Project;
014: import net.refractions.udig.project.internal.ProjectPlugin;
015: import net.refractions.udig.project.ui.internal.ProjectUIPlugin;
016:
017: import org.eclipse.emf.ecore.resource.Resource;
018: import org.eclipse.jface.viewers.IStructuredSelection;
019: import org.eclipse.jface.wizard.Wizard;
020: import org.eclipse.ui.INewWizard;
021: import org.eclipse.ui.IWorkbench;
022:
023: /**
024: * Wizard to create a new project.
025: *
026: * @author jgarnett
027: * @author vitalus
028: *
029: * @since 0.3
030: *
031: * @version 1.1.0
032: */
033: public class NewProjectWizard extends Wizard implements INewWizard {
034:
035: /**
036: * Wizard page used to fill parameters of new project
037: */
038: protected NewProjectWizardPage page;
039:
040: /**
041: * Override to make title reflect current page.
042: *
043: * @param page The page to set.
044: */
045: public void setPage(NewProjectWizardPage page) {
046: this .page = page;
047: setWindowTitle(page.getTitle());
048: }
049:
050: /**
051: * The <code>Wizard</code> implementation of this <code>IWizard</code> method does nothing.
052: * Subclasses should extend if extra pages need to be added before the wizard opens. New pages
053: * should be added by calling <code>addPage</code>.
054: */
055: public void addPages() {
056: page = new NewProjectWizardPage();
057: addPage(page);
058: setWindowTitle(page.getTitle());
059: setHelpAvailable(true);
060: }
061:
062: /**
063: * Completes the wizard if new project parameters are valid.
064: * <p>
065: *
066: * @see org.eclipse.jface.wizard.IWizard#performFinish()
067: * @return <code>true</code> when project successfully created
068: */
069: public boolean performFinish() {
070: if (!page.validate())
071: return false;
072:
073: final String projectPath = page.getProjectPath();
074: final String projectName = page.getProjectName();
075:
076: Project project = ProjectPlugin.getPlugin()
077: .getProjectRegistry().getProject(projectPath);
078: project.setName(projectName);
079: Resource projectResource = project.eResource();
080: try {
081: projectResource.save(Collections.EMPTY_MAP);
082: } catch (IOException e) {
083: ProjectUIPlugin
084: .log(
085: "Error during saving the project file of an anew created project", e); //$NON-NLS-1$
086: }
087:
088: return true;
089: }
090:
091: /**
092: * We can finish if the user has entered a file.
093: *
094: * @return true if we can finish
095: */
096: public boolean canFinish() {
097: return page.isPageComplete();
098: }
099:
100: /**
101: * Hook us up to the world .. I mean workbench.
102: * <p>
103: * This is where all the magic is supposed to happen to remember the previous directory and so
104: * on.
105: * </p>
106: * <p>
107: * </p>
108: *
109: * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
110: * org.eclipse.jface.viewers.IStructuredSelection)
111: * @param workbench
112: * @param selection
113: */
114: public void init(IWorkbench workbench,
115: IStructuredSelection selection) {
116: // TODO: Magic to remember previous directory
117: }
118:
119: }
|