1 | /* |
2 | *Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.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(PalladioComponentModelComposedStructureDiagramEditorPlugin |
100 | .getBundledImageDescriptor("icons/wizban/NewEntityWizard.gif")); //$NON-NLS-1$ |
101 | setNeedsProgressMonitor(true); |
102 | } |
103 | |
104 | /** |
105 | * @generated not |
106 | */ |
107 | public void addPages() { |
108 | diagramModelFilePage = new PalladioComponentModelCreationWizardPage( |
109 | "DiagramModelFile", getSelection(), "system_diagram"); //$NON-NLS-1$ //$NON-NLS-2$ |
110 | diagramModelFilePage.setTitle("Create CompositeModel Diagram"); |
111 | diagramModelFilePage |
112 | .setDescription("Select file that will contain diagram model."); |
113 | addPage(diagramModelFilePage); |
114 | |
115 | domainModelFilePage = new PalladioComponentModelCreationWizardPage( |
116 | "DomainModelFile", getSelection(), "system"); //$NON-NLS-1$ //$NON-NLS-2$ |
117 | domainModelFilePage.setTitle("Create CompositeModel Diagram"); |
118 | domainModelFilePage |
119 | .setDescription("Select file that will contain domain model."); |
120 | addPage(domainModelFilePage); |
121 | } |
122 | |
123 | /** |
124 | * @generated |
125 | */ |
126 | public boolean performFinish() { |
127 | IRunnableWithProgress op = new WorkspaceModifyOperation(null) { |
128 | |
129 | protected void execute(IProgressMonitor monitor) |
130 | throws CoreException, InterruptedException { |
131 | diagram = PalladioComponentModelDiagramEditorUtil |
132 | .createDiagram(diagramModelFilePage.getURI(), |
133 | domainModelFilePage.getURI(), monitor); |
134 | if (isOpenNewlyCreatedDiagramEditor() && diagram != null) { |
135 | try { |
136 | PalladioComponentModelDiagramEditorUtil |
137 | .openDiagram(diagram); |
138 | } catch (PartInitException e) { |
139 | ErrorDialog |
140 | .openError( |
141 | getContainer().getShell(), |
142 | Messages.PalladioComponentModelCreationWizardOpenEditorError, |
143 | null, e.getStatus()); |
144 | } |
145 | } |
146 | } |
147 | }; |
148 | try { |
149 | getContainer().run(false, true, op); |
150 | } catch (InterruptedException e) { |
151 | return false; |
152 | } catch (InvocationTargetException e) { |
153 | if (e.getTargetException() instanceof CoreException) { |
154 | ErrorDialog |
155 | .openError( |
156 | getContainer().getShell(), |
157 | Messages.PalladioComponentModelCreationWizardCreationError, |
158 | null, ((CoreException) e.getTargetException()) |
159 | .getStatus()); |
160 | } else { |
161 | PalladioComponentModelComposedStructureDiagramEditorPlugin |
162 | .getInstance() |
163 | .logError( |
164 | "Error creating diagram", e.getTargetException()); //$NON-NLS-1$ |
165 | } |
166 | return false; |
167 | } |
168 | return diagram != null; |
169 | } |
170 | } |