| 1 | /* |
| 2 | *Copyright 2007, SDQ, IPD, U KA |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.allocation.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 | private ResourceEnvironmentSelectorPage myResourceEnvironmentSelectorPage; |
| 27 | private SystemSelectorPage mySystemSelectorPage; |
| 28 | |
| 29 | public PalladioComponentModelCreationWizard() { |
| 30 | myResourceEnvironmentSelectorPage = new ResourceEnvironmentSelectorPage( |
| 31 | null); |
| 32 | mySystemSelectorPage = new SystemSelectorPage(null); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @generated |
| 37 | */ |
| 38 | private IWorkbench workbench; |
| 39 | |
| 40 | /** |
| 41 | * @generated |
| 42 | */ |
| 43 | protected IStructuredSelection selection; |
| 44 | |
| 45 | /** |
| 46 | * @generated |
| 47 | */ |
| 48 | protected PalladioComponentModelCreationWizardPage diagramModelFilePage; |
| 49 | |
| 50 | /** |
| 51 | * @generated |
| 52 | */ |
| 53 | protected PalladioComponentModelCreationWizardPage domainModelFilePage; |
| 54 | |
| 55 | /** |
| 56 | * @generated |
| 57 | */ |
| 58 | protected Resource diagram; |
| 59 | |
| 60 | /** |
| 61 | * @generated |
| 62 | */ |
| 63 | private boolean openNewlyCreatedDiagramEditor = true; |
| 64 | |
| 65 | /** |
| 66 | * @generated |
| 67 | */ |
| 68 | public IWorkbench getWorkbench() { |
| 69 | return workbench; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @generated |
| 74 | */ |
| 75 | public IStructuredSelection getSelection() { |
| 76 | return selection; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @generated |
| 81 | */ |
| 82 | public final Resource getDiagram() { |
| 83 | return diagram; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @generated |
| 88 | */ |
| 89 | public final boolean isOpenNewlyCreatedDiagramEditor() { |
| 90 | return openNewlyCreatedDiagramEditor; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @generated |
| 95 | */ |
| 96 | public void setOpenNewlyCreatedDiagramEditor( |
| 97 | boolean openNewlyCreatedDiagramEditor) { |
| 98 | this.openNewlyCreatedDiagramEditor = openNewlyCreatedDiagramEditor; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @generated |
| 103 | */ |
| 104 | public void init(IWorkbench workbench, IStructuredSelection selection) { |
| 105 | this.workbench = workbench; |
| 106 | this.selection = selection; |
| 107 | setWindowTitle(Messages.PalladioComponentModelCreationWizardTitle); |
| 108 | setDefaultPageImageDescriptor(PalladioComponentModelAllocationDiagramEditorPlugin |
| 109 | .getBundledImageDescriptor("icons/wizban/NewAllocationWizard.gif")); //$NON-NLS-1$ |
| 110 | setNeedsProgressMonitor(true); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @generated not |
| 115 | */ |
| 116 | public void addPages() { |
| 117 | diagramModelFilePage = new PalladioComponentModelCreationWizardPage( |
| 118 | "DiagramModelFile", getSelection(), "allocation_diagram"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 119 | diagramModelFilePage.setTitle("Create allocation Diagram"); |
| 120 | diagramModelFilePage |
| 121 | .setDescription("Select file that will contain diagram model."); |
| 122 | addPage(diagramModelFilePage); |
| 123 | |
| 124 | domainModelFilePage = new PalladioComponentModelCreationWizardPage( |
| 125 | "DomainModelFile", getSelection(), "allocation"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 126 | domainModelFilePage.setTitle("Create allocation Diagram"); |
| 127 | domainModelFilePage |
| 128 | .setDescription("Select file that will contain domain model."); |
| 129 | addPage(domainModelFilePage); |
| 130 | |
| 131 | addPage(myResourceEnvironmentSelectorPage); |
| 132 | addPage(mySystemSelectorPage); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * @generated not |
| 137 | */ |
| 138 | public boolean performFinish() { |
| 139 | IRunnableWithProgress op = new WorkspaceModifyOperation(null) { |
| 140 | |
| 141 | protected void execute(IProgressMonitor monitor) |
| 142 | throws CoreException, InterruptedException { |
| 143 | diagram = PalladioComponentModelDiagramEditorUtil |
| 144 | .createDiagram(diagramModelFilePage.getURI(), |
| 145 | domainModelFilePage.getURI(), |
| 146 | mySystemSelectorPage.getSelectedSystem(), |
| 147 | myResourceEnvironmentSelectorPage |
| 148 | .getSelectedResourceEnvironment(), |
| 149 | monitor); |
| 150 | if (isOpenNewlyCreatedDiagramEditor() && diagram != null) { |
| 151 | try { |
| 152 | PalladioComponentModelDiagramEditorUtil |
| 153 | .openDiagram(diagram); |
| 154 | } catch (PartInitException e) { |
| 155 | ErrorDialog.openError(getContainer().getShell(), |
| 156 | "Error opening diagram editor", null, e |
| 157 | .getStatus()); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | }; |
| 162 | try { |
| 163 | getContainer().run(false, true, op); |
| 164 | } catch (InterruptedException e) { |
| 165 | return false; |
| 166 | } catch (InvocationTargetException e) { |
| 167 | if (e.getTargetException() instanceof CoreException) { |
| 168 | ErrorDialog.openError(getContainer().getShell(), |
| 169 | "Creation Problems", null, ((CoreException) e |
| 170 | .getTargetException()).getStatus()); |
| 171 | } else { |
| 172 | PalladioComponentModelAllocationDiagramEditorPlugin |
| 173 | .getInstance() |
| 174 | .logError( |
| 175 | "Error creating diagram", e.getTargetException()); //$NON-NLS-1$ |
| 176 | } |
| 177 | return false; |
| 178 | } |
| 179 | return diagram != null; |
| 180 | } |
| 181 | } |