| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2007 IBM Corporation and others. |
| // 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: |
| // IBM Corporation - initial implementation |
| //------------------------------------------------------------------------------ |
| package org.eclipse.epf.diagram.wpdd.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.gmf.runtime.diagram.ui.resources.editor.ide.wizards.EditorCreationWizard; |
| 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 DiagramCreationWizard extends Wizard implements INewWizard { |
| |
| /** |
| * @generated |
| */ |
| private IWorkbench workbench; |
| /** |
| * @generated |
| */ |
| protected IStructuredSelection selection; |
| /** |
| * @generated |
| */ |
| protected DiagramCreationWizardPage 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 addPages() { |
| diagramModelFilePage = new DiagramCreationWizardPage( |
| "DiagramModelFile", getSelection(), "wpdd"); //$NON-NLS-1$ //$NON-NLS-2$ |
| diagramModelFilePage.setTitle("Create WPDD Diagram"); |
| diagramModelFilePage |
| .setDescription("Select file that will contain diagram and domain models."); |
| addPage(diagramModelFilePage); |
| } |
| |
| /** |
| * @generated |
| */ |
| public boolean performFinish() { |
| IRunnableWithProgress op = new WorkspaceModifyOperation(null) { |
| |
| protected void execute(IProgressMonitor monitor) |
| throws CoreException, InterruptedException { |
| diagram = DiagramDiagramEditorUtil.createDiagram( |
| diagramModelFilePage.getURI(), monitor); |
| if (isOpenNewlyCreatedDiagramEditor() && diagram != null) { |
| try { |
| DiagramDiagramEditorUtil.openDiagram(diagram); |
| } catch (PartInitException e) { |
| ErrorDialog.openError(getContainer().getShell(), |
| "Error opening diagram editor", 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(), |
| "Creation Problems", null, ((CoreException) e |
| .getTargetException()).getStatus()); |
| } else { |
| WPDDiagramEditorPlugin.getInstance().logError( |
| "Error creating diagram", e.getTargetException()); //$NON-NLS-1$ |
| } |
| return false; |
| } |
| return diagram != null; |
| } |
| |
| /** |
| * @generated |
| */ |
| public void init(IWorkbench workbench, IStructuredSelection selection) { |
| this.workbench = workbench; |
| this.selection = selection; |
| setWindowTitle("New WPDD Diagram"); |
| setDefaultPageImageDescriptor(WPDDiagramEditorPlugin |
| .getBundledImageDescriptor("icons/wizban/NewModelWizard.gif")); //$NON-NLS-1$ |
| setNeedsProgressMonitor(true); |
| } |
| } |