org.melanee.textdsl.grammarimport.importWizards.ImportGrammar.java Source code

Java tutorial

Introduction

Here is the source code for org.melanee.textdsl.grammarimport.importWizards.ImportGrammar.java

Source

/*******************************************************************************
 * Copyright (c) 2011, 2013 University of Mannheim: Chair for Software Engineering
 * 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:
 *    Nikolai Hellwig - initial API and implementation and initial documentation
 *******************************************************************************/
package org.melanee.textdsl.grammarimport.importWizards;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.InvalidRegistryObjectException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;
import org.melanee.textdsl.grammarimport.GrammarTransformer;

public class ImportGrammar extends Wizard implements IImportWizard {

    GrammarImportSelectionPage selectionPage;
    ImportGrammarPage mainPage;

    public ImportGrammar() {
        super();
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
     */
    public boolean performFinish() {
        try {
            IFile file = mainPage.createNewFile();
            if (file == null)
                return false;

            GrammarTransformer.transform(selectionPage.getFileName(), file.getFullPath().toString(),
                    selectionPage.getGrammarImporter(), selectionPage.getGrammarTransformer(),
                    selectionPage.isOptimizationDisabled());

            return true;
        } catch (InvalidRegistryObjectException e) {
            e.printStackTrace();
            MessageDialog dialog = new MessageDialog(getShell(), "Error", null, e.getMessage(), MessageDialog.ERROR,
                    new String[] { "OK" }, 0);
            dialog.open();
        } catch (CoreException e) {
            e.printStackTrace();
            MessageDialog dialog = new MessageDialog(getShell(), "Error", null, e.getMessage(), MessageDialog.ERROR,
                    new String[] { "OK" }, 0);
            dialog.open();
        } catch (Exception e) {
            e.printStackTrace();
            MessageDialog dialog = new MessageDialog(getShell(), "Error", null, e.getMessage(), MessageDialog.ERROR,
                    new String[] { "OK" }, 0);
            dialog.open();
        }

        return false;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
     * org.eclipse.jface.viewers.IStructuredSelection)
     */
    public void init(IWorkbench workbench, IStructuredSelection selection) {
        setWindowTitle("File Import Wizard"); // NON-NLS-1
        setNeedsProgressMonitor(true);
        mainPage = new ImportGrammarPage("Destination Model File", selection); // NON-NLS-1
        selectionPage = new GrammarImportSelectionPage("Select Grammar Importer");
    }

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

}