/* * License (BSD Style License): * Copyright (c) 2011 * Software Engineering * Department of Computer Science * Technische Universität Darmstadt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of the Software Engineering Group or Technische * Universität Darmstadt nor the names of its contributors may be used to * endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ package de.tud.cs.st.vespucci.vespucci_model.diagram.part; import java.lang.reflect.InvocationTargetException; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PartInitException; import org.eclipse.ui.actions.WorkspaceModifyOperation; /** * @generated */ public class VespucciCreationWizard extends Wizard implements INewWizard { /** * @generated */ private IWorkbench workbench; /** * @generated */ protected IStructuredSelection selection; /** * @generated */ protected de.tud.cs.st.vespucci.vespucci_model.diagram.part.VespucciCreationWizardPage diagramModelFilePage; /** * @generated */ protected Resource diagram; /** * @generated */ private boolean openNewlyCreatedDiagramEditor = true; /** * @generated */ public IWorkbench getWorkbench() { return workbench; } /** * @generated */ public IStructuredSelection getSelection() { return selection; } /** * @generated */ public final Resource getDiagram() { return diagram; } /** * @generated */ public final boolean isOpenNewlyCreatedDiagramEditor() { return openNewlyCreatedDiagramEditor; } /** * @generated */ public void setOpenNewlyCreatedDiagramEditor(boolean openNewlyCreatedDiagramEditor) { this.openNewlyCreatedDiagramEditor = openNewlyCreatedDiagramEditor; } /** * @generated */ public void init(IWorkbench workbench, IStructuredSelection selection) { this.workbench = workbench; this.selection = selection; setWindowTitle(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.VespucciCreationWizardTitle); setDefaultPageImageDescriptor(de.tud.cs.st.vespucci.vespucci_model.diagram.part.VespucciDiagramEditorPlugin .getBundledImageDescriptor("icons/wizban/NewVespucci_modelWizard.gif")); //$NON-NLS-1$ setNeedsProgressMonitor(true); } /** * @generated */ public void addPages() { diagramModelFilePage = new de.tud.cs.st.vespucci.vespucci_model.diagram.part.VespucciCreationWizardPage( "DiagramModelFile", getSelection(), "sad"); //$NON-NLS-1$ //$NON-NLS-2$ diagramModelFilePage .setTitle(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.VespucciCreationWizard_DiagramModelFilePageTitle); diagramModelFilePage .setDescription(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.VespucciCreationWizard_DiagramModelFilePageDescription); addPage(diagramModelFilePage); } /** * @generated */ public boolean performFinish() { IRunnableWithProgress op = new WorkspaceModifyOperation(null) { protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException { diagram = de.tud.cs.st.vespucci.vespucci_model.diagram.part.VespucciDiagramEditorUtil.createDiagram( diagramModelFilePage.getURI(), monitor); if (isOpenNewlyCreatedDiagramEditor() && diagram != null) { try { de.tud.cs.st.vespucci.vespucci_model.diagram.part.VespucciDiagramEditorUtil.openDiagram(diagram); } catch (PartInitException e) { ErrorDialog.openError(getContainer().getShell(), de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.VespucciCreationWizardOpenEditorError, null, e.getStatus()); } } } }; try { getContainer().run(false, true, op); } catch (InterruptedException e) { return false; } catch (InvocationTargetException e) { if (e.getTargetException() instanceof CoreException) { ErrorDialog.openError(getContainer().getShell(), de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.VespucciCreationWizardCreationError, null, ((CoreException) e.getTargetException()).getStatus()); } else { de.tud.cs.st.vespucci.vespucci_model.diagram.part.VespucciDiagramEditorPlugin.getInstance().logError( "Error creating diagram", e.getTargetException()); //$NON-NLS-1$ } return false; } return diagram != null; } }