]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * IBM Corporation - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.internal.ui.wizards.buildpaths; | |
12 | ||
13 | import org.eclipse.swt.widgets.Shell; | |
14 | ||
15 | import org.eclipse.core.runtime.CoreException; | |
16 | ||
17 | import org.eclipse.jface.layout.PixelConverter; | |
18 | import org.eclipse.jface.resource.JFaceResources; | |
19 | import org.eclipse.jface.wizard.IWizardPage; | |
20 | import org.eclipse.jface.wizard.Wizard; | |
21 | import org.eclipse.jface.wizard.WizardDialog; | |
22 | ||
23 | import org.eclipse.jdt.core.IClasspathEntry; | |
24 | import org.eclipse.jdt.core.IJavaProject; | |
25 | ||
26 | import org.eclipse.jdt.ui.wizards.IClasspathContainerPage; | |
27 | import org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension; | |
28 | import org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension2; | |
29 | ||
30 | import org.eclipse.jdt.internal.ui.util.ExceptionHandler; | |
31 | import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; | |
32 | ||
33 | ||
34 | /** | |
35 | */ | |
36 | public class ClasspathContainerWizard extends Wizard { | |
37 | ||
38 | private final ClasspathContainerDescriptor fPageDesc; | |
39 | private final IClasspathEntry fEntryToEdit; | |
40 | ||
41 | private IClasspathEntry[] fNewEntries; | |
42 | private IClasspathContainerPage fContainerPage; | |
43 | private final IJavaProject fCurrProject; | |
44 | private final IClasspathEntry[] fCurrClasspath; | |
45 | ||
46 | private ClasspathContainerSelectionPage fSelectionWizardPage; | |
47 | ||
48 | /** | |
49 | * Constructor for ClasspathContainerWizard. | |
50 | * @param entryToEdit entry to edit | |
51 | * @param currProject current project | |
52 | * @param currEntries entries currently in classpath | |
53 | */ | |
54 | public ClasspathContainerWizard(IClasspathEntry entryToEdit, IJavaProject currProject, IClasspathEntry[] currEntries) { | |
55 | this(entryToEdit, null, currProject, currEntries); | |
56 | } | |
57 | ||
58 | /** | |
59 | * Constructor for ClasspathContainerWizard. | |
60 | * @param pageDesc page description | |
61 | * @param currProject current project | |
62 | * @param currEntries entries currently in classpath | |
63 | */ | |
64 | public ClasspathContainerWizard(ClasspathContainerDescriptor pageDesc, IJavaProject currProject, IClasspathEntry[] currEntries) { | |
65 | this(null, pageDesc, currProject, currEntries); | |
66 | } | |
67 | ||
68 | private ClasspathContainerWizard(IClasspathEntry entryToEdit, ClasspathContainerDescriptor pageDesc, IJavaProject currProject, IClasspathEntry[] currEntries) { | |
69 | fEntryToEdit= entryToEdit; | |
70 | fPageDesc= pageDesc; | |
71 | fNewEntries= null; | |
72 | ||
73 | fCurrProject= currProject; | |
74 | fCurrClasspath= currEntries; | |
75 | ||
76 | String title; | |
77 | if (entryToEdit == null) { | |
78 | title= NewWizardMessages.ClasspathContainerWizard_new_title; | |
79 | } else { | |
80 | title= NewWizardMessages.ClasspathContainerWizard_edit_title; | |
81 | } | |
82 | setWindowTitle(title); | |
83 | } | |
84 | ||
85 | public IClasspathEntry[] getNewEntries() { | |
86 | return fNewEntries; | |
87 | } | |
88 | ||
89 | /* (non-Javadoc) | |
90 | * @see IWizard#performFinish() | |
91 | */ | |
92 | @Override | |
93 | public boolean performFinish() { | |
94 | if (fContainerPage != null) { | |
95 | if (fContainerPage.finish()) { | |
96 | if (fEntryToEdit == null && fContainerPage instanceof IClasspathContainerPageExtension2) { | |
97 | fNewEntries= ((IClasspathContainerPageExtension2) fContainerPage).getNewContainers(); | |
98 | } else { | |
99 | IClasspathEntry entry= fContainerPage.getSelection(); | |
100 | fNewEntries= (entry != null) ? new IClasspathEntry[] { entry } : null; | |
101 | } | |
102 | return true; | |
103 | } | |
104 | } | |
105 | return false; | |
106 | } | |
107 | ||
108 | /* (non-Javadoc) | |
109 | * @see IWizard#addPages() | |
110 | */ | |
111 | @Override | |
112 | public void addPages() { | |
113 | if (fPageDesc != null) { | |
114 | fContainerPage= getContainerPage(fPageDesc); | |
115 | addPage(fContainerPage); | |
116 | } else if (fEntryToEdit == null) { // new entry: show selection page as first page | |
117 | ClasspathContainerDescriptor[] containers= ClasspathContainerDescriptor.getDescriptors(); | |
118 | ||
119 | fSelectionWizardPage= new ClasspathContainerSelectionPage(containers); | |
120 | addPage(fSelectionWizardPage); | |
121 | ||
122 | // add as dummy, will not be shown | |
123 | fContainerPage= new ClasspathContainerDefaultPage(); | |
124 | addPage(fContainerPage); | |
125 | } else { // fPageDesc == null && fEntryToEdit != null | |
126 | ClasspathContainerDescriptor[] containers= ClasspathContainerDescriptor.getDescriptors(); | |
127 | ClasspathContainerDescriptor descriptor= findDescriptorPage(containers, fEntryToEdit); | |
128 | fContainerPage= getContainerPage(descriptor); | |
129 | addPage(fContainerPage); | |
130 | } | |
131 | super.addPages(); | |
132 | } | |
133 | ||
134 | private IClasspathContainerPage getContainerPage(ClasspathContainerDescriptor pageDesc) { | |
135 | IClasspathContainerPage containerPage= null; | |
136 | if (pageDesc != null) { | |
137 | IClasspathContainerPage page= pageDesc.getPage(); | |
138 | if (page != null) { | |
139 | return page; // if page is already created, avoid double initialization | |
140 | } | |
141 | try { | |
142 | containerPage= pageDesc.createPage(); | |
143 | } catch (CoreException e) { | |
144 | handlePageCreationFailed(e); | |
145 | } | |
146 | } | |
147 | ||
148 | if (containerPage == null) { | |
149 | containerPage= new ClasspathContainerDefaultPage(); | |
150 | if (pageDesc != null) { | |
151 | pageDesc.setPage(containerPage); // avoid creation next time | |
152 | } | |
153 | } | |
154 | ||
155 | if (containerPage instanceof IClasspathContainerPageExtension) { | |
156 | ((IClasspathContainerPageExtension) containerPage).initialize(fCurrProject, fCurrClasspath); | |
157 | } | |
158 | ||
159 | containerPage.setSelection(fEntryToEdit); | |
160 | containerPage.setWizard(this); | |
161 | return containerPage; | |
162 | } | |
163 | ||
164 | /* (non-Javadoc) | |
165 | * @see IWizard#getNextPage(IWizardPage) | |
166 | */ | |
167 | @Override | |
168 | public IWizardPage getNextPage(IWizardPage page) { | |
169 | if (page == fSelectionWizardPage) { | |
170 | ||
171 | ClasspathContainerDescriptor selected= fSelectionWizardPage.getSelected(); | |
172 | fContainerPage= getContainerPage(selected); | |
173 | ||
174 | return fContainerPage; | |
175 | } | |
176 | return super.getNextPage(page); | |
177 | } | |
178 | ||
179 | private void handlePageCreationFailed(CoreException e) { | |
180 | String title= NewWizardMessages.ClasspathContainerWizard_pagecreationerror_title; | |
181 | String message= NewWizardMessages.ClasspathContainerWizard_pagecreationerror_message; | |
182 | ExceptionHandler.handle(e, getShell(), title, message); | |
183 | } | |
184 | ||
185 | ||
186 | private ClasspathContainerDescriptor findDescriptorPage(ClasspathContainerDescriptor[] containers, IClasspathEntry entry) { | |
187 | for (int i = 0; i < containers.length; i++) { | |
188 | if (containers[i].canEdit(entry)) { | |
189 | return containers[i]; | |
190 | } | |
191 | } | |
192 | return null; | |
193 | } | |
194 | ||
195 | /* (non-Javadoc) | |
196 | * @see org.eclipse.jface.wizard.Wizard#dispose() | |
197 | */ | |
198 | @Override | |
199 | public void dispose() { | |
200 | if (fSelectionWizardPage != null) { | |
201 | ClasspathContainerDescriptor[] descriptors= fSelectionWizardPage.getContainers(); | |
202 | for (int i= 0; i < descriptors.length; i++) { | |
203 | descriptors[i].dispose(); | |
204 | } | |
205 | } | |
206 | super.dispose(); | |
207 | } | |
208 | ||
209 | /* (non-Javadoc) | |
210 | * @see IWizard#canFinish() | |
211 | */ | |
212 | @Override | |
213 | public boolean canFinish() { | |
214 | if (fSelectionWizardPage != null) { | |
215 | if (!fContainerPage.isPageComplete()) { | |
216 | return false; | |
217 | } | |
218 | } | |
219 | if (fContainerPage != null) { | |
220 | return fContainerPage.isPageComplete(); | |
221 | } | |
222 | return false; | |
223 | } | |
224 | ||
225 | public void generated_2793864386879554382(Shell shell) { | |
226 | setNeedsProgressMonitor(true); | |
227 | ||
228 | WizardDialog dialog= new WizardDialog(shell, this); | |
229 | PixelConverter converter= new PixelConverter(shell); | |
230 | dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70), converter.convertHeightInCharsToPixels(20)); | |
231 | dialog.create(); | |
232 | dialog.open(); | |
233 | } | |
234 | ||
235 | public static int openWizard(Shell shell, ClasspathContainerWizard wizard) { | |
236 | WizardDialog dialog= new WizardDialog(shell, wizard); | |
237 | PixelConverter converter= new PixelConverter(JFaceResources.getDialogFont()); | |
238 | dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70), converter.convertHeightInCharsToPixels(20)); | |
239 | dialog.create(); | |
240 | return dialog.open(); | |
241 | } | |
242 | ||
243 | } |