| 1 | /* |
| 2 | *Copyright 2007, IPD, SDQ, University of Karlsruhe |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.repository.part; |
| 5 | |
| 6 | import java.lang.reflect.InvocationTargetException; |
| 7 | |
| 8 | import org.eclipse.core.runtime.CoreException; |
| 9 | import org.eclipse.core.runtime.IProgressMonitor; |
| 10 | import org.eclipse.emf.ecore.resource.Resource; |
| 11 | import org.eclipse.jface.dialogs.ErrorDialog; |
| 12 | import org.eclipse.jface.operation.IRunnableWithProgress; |
| 13 | import org.eclipse.jface.viewers.IStructuredSelection; |
| 14 | import org.eclipse.jface.wizard.Wizard; |
| 15 | import org.eclipse.ui.INewWizard; |
| 16 | import org.eclipse.ui.IWorkbench; |
| 17 | import org.eclipse.ui.PartInitException; |
| 18 | import org.eclipse.ui.actions.WorkspaceModifyOperation; |
| 19 | |
| 20 | /** |
| 21 | * @generated |
| 22 | */ |
| 23 | public class PalladioComponentModelCreationWizard extends Wizard implements |
| 24 | INewWizard { |
| 25 | |
| 26 | /** |
| 27 | * @generated |
| 28 | */ |
| 29 | private IWorkbench workbench; |
| 30 | |
| 31 | /** |
| 32 | * @generated |
| 33 | */ |
| 34 | protected IStructuredSelection selection; |
| 35 | |
| 36 | /** |
| 37 | * @generated |
| 38 | */ |
| 39 | protected PalladioComponentModelCreationWizardPage diagramModelFilePage; |
| 40 | |
| 41 | /** |
| 42 | * @generated |
| 43 | */ |
| 44 | protected PalladioComponentModelCreationWizardPage domainModelFilePage; |
| 45 | |
| 46 | /** |
| 47 | * @generated |
| 48 | */ |
| 49 | protected Resource diagram; |
| 50 | |
| 51 | /** |
| 52 | * @generated |
| 53 | */ |
| 54 | private boolean openNewlyCreatedDiagramEditor = true; |
| 55 | |
| 56 | /** |
| 57 | * @generated |
| 58 | */ |
| 59 | public IWorkbench getWorkbench() { |
| 60 | return workbench; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @generated |
| 65 | */ |
| 66 | public IStructuredSelection getSelection() { |
| 67 | return selection; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @generated |
| 72 | */ |
| 73 | public final Resource getDiagram() { |
| 74 | return diagram; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @generated |
| 79 | */ |
| 80 | public final boolean isOpenNewlyCreatedDiagramEditor() { |
| 81 | return openNewlyCreatedDiagramEditor; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @generated |
| 86 | */ |
| 87 | public void setOpenNewlyCreatedDiagramEditor( |
| 88 | boolean openNewlyCreatedDiagramEditor) { |
| 89 | this.openNewlyCreatedDiagramEditor = openNewlyCreatedDiagramEditor; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @generated |
| 94 | */ |
| 95 | public void init(IWorkbench workbench, IStructuredSelection selection) { |
| 96 | this.workbench = workbench; |
| 97 | this.selection = selection; |
| 98 | setWindowTitle(Messages.PalladioComponentModelCreationWizardTitle); |
| 99 | setDefaultPageImageDescriptor(PalladioComponentModelRepositoryDiagramEditorPlugin |
| 100 | .getBundledImageDescriptor("icons/wizban/NewRepositoryWizard.gif")); //$NON-NLS-1$ |
| 101 | setNeedsProgressMonitor(true); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * @generated |
| 106 | */ |
| 107 | public void addPages() { |
| 108 | diagramModelFilePage = new PalladioComponentModelCreationWizardPage( |
| 109 | "DiagramModelFile", getSelection(), "repository_diagram"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 110 | diagramModelFilePage |
| 111 | .setTitle(Messages.PalladioComponentModelCreationWizard_DiagramModelFilePageTitle); |
| 112 | diagramModelFilePage |
| 113 | .setDescription(Messages.PalladioComponentModelCreationWizard_DiagramModelFilePageDescription); |
| 114 | addPage(diagramModelFilePage); |
| 115 | |
| 116 | domainModelFilePage = new PalladioComponentModelCreationWizardPage( |
| 117 | "DomainModelFile", getSelection(), "repository") { //$NON-NLS-1$ //$NON-NLS-2$ |
| 118 | |
| 119 | public void setVisible(boolean visible) { |
| 120 | if (visible) { |
| 121 | String fileName = diagramModelFilePage.getFileName(); |
| 122 | fileName = fileName.substring(0, fileName.length() |
| 123 | - ".repository_diagram".length()); //$NON-NLS-1$ |
| 124 | setFileName(PalladioComponentModelDiagramEditorUtil |
| 125 | .getUniqueFileName(getContainerFullPath(), |
| 126 | fileName, "repository")); //$NON-NLS-1$ |
| 127 | } |
| 128 | super.setVisible(visible); |
| 129 | } |
| 130 | }; |
| 131 | domainModelFilePage |
| 132 | .setTitle(Messages.PalladioComponentModelCreationWizard_DomainModelFilePageTitle); |
| 133 | domainModelFilePage |
| 134 | .setDescription(Messages.PalladioComponentModelCreationWizard_DomainModelFilePageDescription); |
| 135 | addPage(domainModelFilePage); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * @generated |
| 140 | */ |
| 141 | public boolean performFinish() { |
| 142 | IRunnableWithProgress op = new WorkspaceModifyOperation(null) { |
| 143 | |
| 144 | protected void execute(IProgressMonitor monitor) |
| 145 | throws CoreException, InterruptedException { |
| 146 | diagram = PalladioComponentModelDiagramEditorUtil |
| 147 | .createDiagram(diagramModelFilePage.getURI(), |
| 148 | domainModelFilePage.getURI(), monitor); |
| 149 | if (isOpenNewlyCreatedDiagramEditor() && diagram != null) { |
| 150 | try { |
| 151 | PalladioComponentModelDiagramEditorUtil |
| 152 | .openDiagram(diagram); |
| 153 | } catch (PartInitException e) { |
| 154 | ErrorDialog |
| 155 | .openError( |
| 156 | getContainer().getShell(), |
| 157 | Messages.PalladioComponentModelCreationWizardOpenEditorError, |
| 158 | null, e.getStatus()); |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | }; |
| 163 | try { |
| 164 | getContainer().run(false, true, op); |
| 165 | } catch (InterruptedException e) { |
| 166 | return false; |
| 167 | } catch (InvocationTargetException e) { |
| 168 | if (e.getTargetException() instanceof CoreException) { |
| 169 | ErrorDialog |
| 170 | .openError( |
| 171 | getContainer().getShell(), |
| 172 | Messages.PalladioComponentModelCreationWizardCreationError, |
| 173 | null, ((CoreException) e.getTargetException()) |
| 174 | .getStatus()); |
| 175 | } else { |
| 176 | PalladioComponentModelRepositoryDiagramEditorPlugin |
| 177 | .getInstance() |
| 178 | .logError( |
| 179 | "Error creating diagram", e.getTargetException()); //$NON-NLS-1$ |
| 180 | } |
| 181 | return false; |
| 182 | } |
| 183 | return diagram != null; |
| 184 | } |
| 185 | } |