at.spardat.xma.gui.projectw.XMAProjectCreationWizzard.java Source code

Java tutorial

Introduction

Here is the source code for at.spardat.xma.gui.projectw.XMAProjectCreationWizzard.java

Source

/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

package at.spardat.xma.gui.projectw;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.internal.debug.ui.ExceptionHandler;
import org.eclipse.jdt.internal.ui.wizards.NewElementWizard;
import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;

/**
 * TODO Prio 2: Provide description for "XMAProjectCreationWizzard".
 * TODO Prio 2: eliminate deprecated or discouraged warnings
 * @see Wizard
 */
public class XMAProjectCreationWizzard extends NewElementWizard implements IExecutableExtension {

    // public static final String NEW_PROJECT_WIZARD_ID= "org.eclipse.jdt.ui.wizards.NewProjectCreationWizard"; //$NON-NLS-1$

    private WizardNewProjectCreationPage fMainPage;
    private XMAProjectWizzardPage fXMAPage;

    //    private JavaCapabilityConfigurationPage fJavaPage;
    //    private NewJavaProjectWizardPage fJavaPage;
    private NewXMAJavaProjectCreationWizardPage fJavaPage;

    private IConfigurationElement fConfigElement;

    private boolean srcBinFolderInNewProject;
    private String srcBinSrcName;
    private String srcBinBinName;

    /**
    *
    */
    public XMAProjectCreationWizzard() {
    }

    /**
     *
     * @see Wizard#init
     */
    public void init(IWorkbench workbench, IStructuredSelection selection) {
        super.init(workbench, selection);
        adjustSrcBinDirSettings();
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.wizard.IWizard#addPages()
     */
    public void addPages() {
        super.addPages();

        fMainPage = new WizardNewProjectCreationPage("XMA Page 1");
        fMainPage.setInitialProjectName("yourProjectName");
        fMainPage.setTitle(XMAProjectCreationWizzardPlugin.getResourceString("mainpage.title"));
        fMainPage.setDescription(XMAProjectCreationWizzardPlugin.getResourceString("mainpage.description"));
        fMainPage.setPageComplete(false);
        addPage(fMainPage);

        //        IWorkspaceRoot root= JavaPlugin.getWorkspace().getRoot();
        //        fJavaPage= new JavaCapabilityConfigurationPage();
        //        fJavaPage = new NewJavaProjectWizardPage(root, fMainPage);

        fJavaPage = new NewXMAJavaProjectCreationWizardPage(fMainPage);
        addPage(fJavaPage);

        fXMAPage = new XMAProjectWizzardPage(this, "XMA Project Wizzard Page ");
        fXMAPage.setTitle("XMA Project");
        fXMAPage.setDescription("xma specific input parameters");
        addPage(fXMAPage);

    }

    /* (non-Javadoc)
     * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
     */
    public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
            throws CoreException {
        this.fConfigElement = config;

    }

    /* (non-Javadoc)
     * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
     */
    public void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {

        fJavaPage.performFinish(monitor);
        fXMAPage.performFinish(new SubProgressMonitor(monitor, 2));

        BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
        // selectAndReveal(fJavaPage.getJavaProject().getProject());
    }

    protected void handleFinishException(Shell shell, InvocationTargetException e) {
        String title = NewWizardMessages.NewElementWizard_op_error_title;
        String message = NewWizardMessages.NewElementWizard_op_error_message;
        ExceptionHandler.handle(e, getShell(), title, message);
    }

    /**
     * @return
     */
    public NewXMAJavaProjectCreationWizardPage getFJavaPage() {
        return fJavaPage;
    }

    /**
     * @return
     */
    public WizardNewProjectCreationPage getFMainPage() {
        return fMainPage;
    }

    /**
     * @return
     */
    public XMAProjectWizzardPage getFXMAPage() {
        return fXMAPage;
    }

    /**
     * @param page
     */
    public void setFJavaPage(NewXMAJavaProjectCreationWizardPage page) {
        fJavaPage = page;
    }

    /**
     * @param page
     */
    public void setFMainPage(WizardNewProjectCreationPage page) {
        fMainPage = page;
    }

    /**
     * @param page
     */
    public void setFXMAPage(XMAProjectWizzardPage page) {
        fXMAPage = page;
    }

    /* (non-Javadoc)
     * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#canRunForked()
     * has to be overriden to avoid runnning multithreaded because the runnable
     * operation get info from widgets, which only haveto processed in the UI thread.
     */
    protected boolean canRunForked() {
        return false;
    }

    public IJavaElement getCreatedElement() {
        return null;
    }

    /* (non-Javadoc)
     * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#performFinish()
     */
    public boolean performFinish() {
        boolean res = super.performFinish();
        restoreOriginalSrcBinDirSettings();
        return res;
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.wizard.Wizard#performCancel()
     */
    public boolean performCancel() {
        boolean res = super.performCancel();
        restoreOriginalSrcBinDirSettings();
        return res;
    }

    /*
     * Overrides the settings for src and bin path and stores the original
     * values - will be restored by restoreOriginalSrcBinDirSettings()
     * @author s4709
     */
    private void adjustSrcBinDirSettings() {
        if (srcBinSrcName != null)
            return;
        IPreferenceStore store = PreferenceConstants.getPreferenceStore();
        srcBinFolderInNewProject = store.getBoolean(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ);
        srcBinSrcName = store.getString(PreferenceConstants.SRCBIN_SRCNAME);
        srcBinBinName = store.getString(PreferenceConstants.SRCBIN_BINNAME);
        store.setValue(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ, true);
        store.setValue(PreferenceConstants.SRCBIN_SRCNAME, "src");
        store.setValue(PreferenceConstants.SRCBIN_BINNAME, "classes");
    }

    /*
     * Restores the values for src and bin path stored by
     * adjustSrcBinDirSettings()
     */
    private void restoreOriginalSrcBinDirSettings() {
        if (srcBinSrcName == null)
            return;
        IPreferenceStore store = PreferenceConstants.getPreferenceStore();
        store.setValue(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ, srcBinFolderInNewProject);
        store.setValue(PreferenceConstants.SRCBIN_SRCNAME, srcBinSrcName);
        store.setValue(PreferenceConstants.SRCBIN_BINNAME, srcBinBinName);
        srcBinSrcName = srcBinBinName = null;
    }

}