a73147a449233ac65308f66afafcf2b79e5bacac
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpdt / ui / wizards / NewTypeWizardPage.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.ui.wizards;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import net.sourceforge.phpdt.core.Flags;
17 import net.sourceforge.phpdt.core.IBuffer;
18 import net.sourceforge.phpdt.core.ICompilationUnit;
19 import net.sourceforge.phpdt.core.IJavaElement;
20 import net.sourceforge.phpdt.core.IPackageFragment;
21 import net.sourceforge.phpdt.core.ISourceRange;
22 import net.sourceforge.phpdt.core.IType;
23 import net.sourceforge.phpdt.core.ToolFactory;
24 import net.sourceforge.phpdt.core.compiler.IScanner;
25 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
26 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
27 import net.sourceforge.phpdt.externaltools.internal.ui.StatusInfo;
28 import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility;
29 import net.sourceforge.phpdt.internal.corext.template.php.JavaContext;
30 import net.sourceforge.phpdt.internal.corext.template.php.Templates;
31 import net.sourceforge.phpdt.internal.corext.util.JavaModelUtil;
32 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
33 import net.sourceforge.phpdt.internal.ui.util.SWTUtil;
34 import net.sourceforge.phpdt.internal.ui.wizards.NewWizardMessages;
35 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.DialogField;
36 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
37 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.IListAdapter;
38 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
39 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.LayoutUtil;
40 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.ListDialogField;
41 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
42 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFieldGroup;
43 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.Separator;
44 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
45 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.StringButtonStatusDialogField;
46 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.StringDialogField;
47 import net.sourceforge.phpdt.ui.CodeGeneration;
48 import net.sourceforge.phpdt.ui.PreferenceConstants;
49 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
50
51 import org.eclipse.core.runtime.CoreException;
52 import org.eclipse.core.runtime.IProgressMonitor;
53 import org.eclipse.core.runtime.IStatus;
54 import org.eclipse.core.runtime.NullProgressMonitor;
55 import org.eclipse.core.runtime.SubProgressMonitor;
56 import org.eclipse.jface.preference.IPreferenceStore;
57 import org.eclipse.jface.text.BadLocationException;
58 import org.eclipse.jface.text.templates.Template;
59 import org.eclipse.jface.text.templates.TemplateException;
60 import org.eclipse.jface.viewers.LabelProvider;
61 import org.eclipse.swt.SWT;
62 import org.eclipse.swt.graphics.Image;
63 import org.eclipse.swt.layout.GridData;
64 import org.eclipse.swt.layout.GridLayout;
65 import org.eclipse.swt.widgets.Button;
66 import org.eclipse.swt.widgets.Composite;
67 import org.eclipse.swt.widgets.Control;
68
69 /**
70  * The class <code>NewTypeWizardPage</code> contains controls and validation
71  * routines for a 'New Type WizardPage'. Implementors decide which components to
72  * add and to enable. Implementors can also customize the validation code.
73  * <code>NewTypeWizardPage</code> is intended to serve as base class of all
74  * wizards that create types like applets, servlets, classes, interfaces, etc.
75  * <p>
76  * See <code>NewClassWizardPage</code> or <code>NewInterfaceWizardPage</code>
77  * for an example usage of <code>NewTypeWizardPage</code>.
78  * </p>
79  * 
80  * @see net.sourceforge.phpdt.ui.wizards.NewClassWizardPage
81  * @see net.sourceforge.phpdt.ui.wizards.NewInterfaceWizardPage
82  * 
83  * @since 2.0
84  */
85 public abstract class NewTypeWizardPage extends NewContainerWizardPage {
86
87         /**
88          * Class used in stub creation routines to add needed imports to a
89          * compilation unit.
90          */
91         // public static class ImportsManager {
92         //
93         // private IImportsStructure fImportsStructure;
94         //
95         // /* package */ ImportsManager(IImportsStructure structure) {
96         // fImportsStructure= structure;
97         // }
98         //
99         // /* package */ IImportsStructure getImportsStructure() {
100         // return fImportsStructure;
101         // }
102         //                              
103         // /**
104         // * Adds a new import declaration that is sorted in the existing imports.
105         // * If an import already exists or the import would conflict with another
106         // import
107         // * of an other type with the same simple name the import is not added.
108         // *
109         // * @param qualifiedTypeName The fully qualified name of the type to import
110         // * (dot separated)
111         // * @return Returns the simple type name that can be used in the code or
112         // the
113         // * fully qualified type name if an import conflict prevented the import
114         // */
115         // public String addImport(String qualifiedTypeName) {
116         // return fImportsStructure.addImport(qualifiedTypeName);
117         // }
118         // }
119         /**
120          * Public access flag. See The Java Virtual Machine Specification for more
121          * details.
122          */
123         public int F_PUBLIC = Flags.AccPublic;
124
125         /**
126          * Private access flag. See The Java Virtual Machine Specification for more
127          * details.
128          */
129         public int F_PRIVATE = Flags.AccPrivate;
130
131         /**
132          * Protected access flag. See The Java Virtual Machine Specification for
133          * more details.
134          */
135         public int F_PROTECTED = Flags.AccProtected;
136
137         /**
138          * Static access flag. See The Java Virtual Machine Specification for more
139          * details.
140          */
141         public int F_STATIC = Flags.AccStatic;
142
143         /**
144          * Final access flag. See The Java Virtual Machine Specification for more
145          * details.
146          */
147         public int F_FINAL = Flags.AccFinal;
148
149         /**
150          * Abstract property flag. See The Java Virtual Machine Specification for
151          * more details.
152          */
153         // public int F_ABSTRACT = Flags.AccAbstract;
154         private final static String PAGE_NAME = "NewTypeWizardPage"; //$NON-NLS-1$
155
156         /** Field ID of the package input field */
157         protected final static String PACKAGE = PAGE_NAME + ".package"; //$NON-NLS-1$
158
159         /** Field ID of the eclosing type input field */
160         protected final static String ENCLOSING = PAGE_NAME + ".enclosing"; //$NON-NLS-1$
161
162         /** Field ID of the enclosing type checkbox */
163         protected final static String ENCLOSINGSELECTION = ENCLOSING + ".selection"; //$NON-NLS-1$
164
165         /** Field ID of the type name input field */
166         protected final static String TYPENAME = PAGE_NAME + ".typename"; //$NON-NLS-1$
167
168         /** Field ID of the super type input field */
169         protected final static String SUPER = PAGE_NAME + ".superclass"; //$NON-NLS-1$
170
171         /** Field ID of the super interfaces input field */
172         protected final static String INTERFACES = PAGE_NAME + ".interfaces"; //$NON-NLS-1$
173
174         /** Field ID of the modifier checkboxes */
175         protected final static String MODIFIERS = PAGE_NAME + ".modifiers"; //$NON-NLS-1$
176
177         /** Field ID of the method stubs checkboxes */
178         protected final static String METHODS = PAGE_NAME + ".methods"; //$NON-NLS-1$
179
180         private class InterfacesListLabelProvider extends LabelProvider {
181
182                 private Image fInterfaceImage;
183
184                 public InterfacesListLabelProvider() {
185                         super();
186                         fInterfaceImage = PHPUiImages.get(PHPUiImages.IMG_OBJS_INTERFACE);
187                 }
188
189                 public Image getImage(Object element) {
190                         return fInterfaceImage;
191                 }
192         }
193
194         private StringButtonStatusDialogField fPackageDialogField;
195
196         private SelectionButtonDialogField fEnclosingTypeSelection;
197
198         private StringButtonDialogField fEnclosingTypeDialogField;
199
200         private boolean fCanModifyPackage;
201
202         private boolean fCanModifyEnclosingType;
203
204         private IPackageFragment fCurrPackage;
205
206         // private IType fCurrEnclosingType;
207         private StringDialogField fTypeNameDialogField;
208
209         private StringButtonDialogField fSuperClassDialogField;
210
211         private ListDialogField fSuperInterfacesDialogField;
212
213         // private IType fSuperClass;
214
215         private SelectionButtonDialogFieldGroup fAccMdfButtons;
216
217         private SelectionButtonDialogFieldGroup fOtherMdfButtons;
218
219         private IType fCreatedType;
220
221         protected IStatus fEnclosingTypeStatus;
222
223         protected IStatus fPackageStatus;
224
225         protected IStatus fTypeNameStatus;
226
227         // protected IStatus fSuperClassStatus;
228         protected IStatus fModifierStatus;
229
230         // protected IStatus fSuperInterfacesStatus;
231
232         private boolean fIsClass;
233
234         private int fStaticMdfIndex;
235
236         private final int PUBLIC_INDEX = 0, DEFAULT_INDEX = 1, PRIVATE_INDEX = 2,
237                         PROTECTED_INDEX = 3;
238
239         private final int ABSTRACT_INDEX = 0, FINAL_INDEX = 1;
240
241         /**
242          * Creates a new <code>NewTypeWizardPage</code>
243          * 
244          * @param isClass
245          *            <code>true</code> if a new class is to be created; otherwise
246          *            an interface is to be created
247          * @param pageName
248          *            the wizard page's name
249          */
250         public NewTypeWizardPage(boolean isClass, String pageName) {
251                 super(pageName);
252                 fCreatedType = null;
253
254                 fIsClass = isClass;
255
256                 TypeFieldsAdapter adapter = new TypeFieldsAdapter();
257
258                 fPackageDialogField = new StringButtonStatusDialogField(adapter);
259                 fPackageDialogField.setDialogFieldListener(adapter);
260                 fPackageDialogField.setLabelText(NewWizardMessages
261                                 .getString("NewTypeWizardPage.package.label")); //$NON-NLS-1$
262                 fPackageDialogField.setButtonLabel(NewWizardMessages
263                                 .getString("NewTypeWizardPage.package.button")); //$NON-NLS-1$
264                 fPackageDialogField.setStatusWidthHint(NewWizardMessages
265                                 .getString("NewTypeWizardPage.default")); //$NON-NLS-1$
266
267                 fEnclosingTypeSelection = new SelectionButtonDialogField(SWT.CHECK);
268                 fEnclosingTypeSelection.setDialogFieldListener(adapter);
269                 fEnclosingTypeSelection.setLabelText(NewWizardMessages
270                                 .getString("NewTypeWizardPage.enclosing.selection.label")); //$NON-NLS-1$
271
272                 fEnclosingTypeDialogField = new StringButtonDialogField(adapter);
273                 fEnclosingTypeDialogField.setDialogFieldListener(adapter);
274                 fEnclosingTypeDialogField.setButtonLabel(NewWizardMessages
275                                 .getString("NewTypeWizardPage.enclosing.button")); //$NON-NLS-1$
276
277                 fTypeNameDialogField = new StringDialogField();
278                 fTypeNameDialogField.setDialogFieldListener(adapter);
279                 fTypeNameDialogField.setLabelText(NewWizardMessages
280                                 .getString("NewTypeWizardPage.typename.label")); //$NON-NLS-1$
281
282                 fSuperClassDialogField = new StringButtonDialogField(adapter);
283                 fSuperClassDialogField.setDialogFieldListener(adapter);
284                 fSuperClassDialogField.setLabelText(NewWizardMessages
285                                 .getString("NewTypeWizardPage.superclass.label")); //$NON-NLS-1$
286                 fSuperClassDialogField.setButtonLabel(NewWizardMessages
287                                 .getString("NewTypeWizardPage.superclass.button")); //$NON-NLS-1$
288
289                 String[] addButtons = new String[] {
290                                 /* 0 */
291                                 NewWizardMessages.getString("NewTypeWizardPage.interfaces.add"), //$NON-NLS-1$
292                                 /* 1 */
293                                 null,
294                                 /* 2 */
295                                 NewWizardMessages
296                                                 .getString("NewTypeWizardPage.interfaces.remove") //$NON-NLS-1$
297                 };
298                 fSuperInterfacesDialogField = new ListDialogField(adapter, addButtons,
299                                 new InterfacesListLabelProvider());
300                 fSuperInterfacesDialogField.setDialogFieldListener(adapter);
301                 String interfaceLabel = fIsClass ? NewWizardMessages
302                                 .getString("NewTypeWizardPage.interfaces.class.label") : NewWizardMessages.getString("NewTypeWizardPage.interfaces.ifc.label"); //$NON-NLS-1$ //$NON-NLS-2$
303                 fSuperInterfacesDialogField.setLabelText(interfaceLabel);
304                 fSuperInterfacesDialogField.setRemoveButtonIndex(2);
305
306                 String[] buttonNames1 = new String[] {
307                                 /* 0 == PUBLIC_INDEX */
308                                 NewWizardMessages
309                                                 .getString("NewTypeWizardPage.modifiers.public"), //$NON-NLS-1$
310                                 /* 1 == DEFAULT_INDEX */
311                                 NewWizardMessages
312                                                 .getString("NewTypeWizardPage.modifiers.default"), //$NON-NLS-1$
313                                 /* 2 == PRIVATE_INDEX */
314                                 NewWizardMessages
315                                                 .getString("NewTypeWizardPage.modifiers.private"), //$NON-NLS-1$
316                                 /* 3 == PROTECTED_INDEX */
317                                 NewWizardMessages
318                                                 .getString("NewTypeWizardPage.modifiers.protected") //$NON-NLS-1$
319                 };
320                 fAccMdfButtons = new SelectionButtonDialogFieldGroup(SWT.RADIO,
321                                 buttonNames1, 4);
322                 fAccMdfButtons.setDialogFieldListener(adapter);
323                 fAccMdfButtons.setLabelText(NewWizardMessages
324                                 .getString("NewTypeWizardPage.modifiers.acc.label")); //$NON-NLS-1$
325                 fAccMdfButtons.setSelection(0, true);
326
327                 String[] buttonNames2;
328                 if (fIsClass) {
329                         buttonNames2 = new String[] {
330                                         /* 0 == ABSTRACT_INDEX */
331                                         NewWizardMessages
332                                                         .getString("NewTypeWizardPage.modifiers.abstract"), //$NON-NLS-1$
333                                         /* 1 == FINAL_INDEX */
334                                         NewWizardMessages
335                                                         .getString("NewTypeWizardPage.modifiers.final"), //$NON-NLS-1$
336                                         /* 2 */
337                                         NewWizardMessages
338                                                         .getString("NewTypeWizardPage.modifiers.static") //$NON-NLS-1$
339                         };
340                         fStaticMdfIndex = 2; // index of the static checkbox is 2
341                 } else {
342                         buttonNames2 = new String[] { NewWizardMessages
343                                         .getString("NewTypeWizardPage.modifiers.static") //$NON-NLS-1$
344                         };
345                         fStaticMdfIndex = 0; // index of the static checkbox is 0
346                 }
347
348                 fOtherMdfButtons = new SelectionButtonDialogFieldGroup(SWT.CHECK,
349                                 buttonNames2, 4);
350                 fOtherMdfButtons.setDialogFieldListener(adapter);
351
352                 fAccMdfButtons.enableSelectionButton(PRIVATE_INDEX, false);
353                 fAccMdfButtons.enableSelectionButton(PROTECTED_INDEX, false);
354                 fOtherMdfButtons.enableSelectionButton(fStaticMdfIndex, false);
355
356                 fPackageStatus = new StatusInfo();
357                 fEnclosingTypeStatus = new StatusInfo();
358
359                 fCanModifyPackage = true;
360                 fCanModifyEnclosingType = true;
361                 updateEnableState();
362
363                 fTypeNameStatus = new StatusInfo();
364                 // fSuperClassStatus= new StatusInfo();
365                 // fSuperInterfacesStatus= new StatusInfo();
366                 fModifierStatus = new StatusInfo();
367         }
368
369         /**
370          * Initializes all fields provided by the page with a given selection.
371          * 
372          * @param elem
373          *            the selection used to intialize this page or <code>
374          * null</code>
375          *            if no selection was available
376          */
377         protected void initTypePage(IJavaElement elem) {
378                 String initSuperclass = "java.lang.Object"; //$NON-NLS-1$
379                 ArrayList initSuperinterfaces = new ArrayList(5);
380
381                 IPackageFragment pack = null;
382                 IType enclosingType = null;
383
384                 if (elem != null) {
385                         // evaluate the enclosing type
386                         pack = (IPackageFragment) elem
387                                         .getAncestor(IJavaElement.PACKAGE_FRAGMENT);
388                         IType typeInCU = (IType) elem.getAncestor(IJavaElement.TYPE);
389                         if (typeInCU != null) {
390                                 if (typeInCU.getCompilationUnit() != null) {
391                                         enclosingType = typeInCU;
392                                 }
393                         } else {
394                                 ICompilationUnit cu = (ICompilationUnit) elem
395                                                 .getAncestor(IJavaElement.COMPILATION_UNIT);
396                                 if (cu != null) {
397                                         // enclosingType= cu.findPrimaryType();
398                                 }
399                         }
400
401                         // try {
402                         // IType type= null;
403                         // if (elem.getElementType() == IJavaElement.TYPE) {
404                         // type= (IType)elem;
405                         // if (type.exists()) {
406                         // String superName= JavaModelUtil.getFullyQualifiedName(type);
407                         // if (type.isInterface()) {
408                         // initSuperinterfaces.add(superName);
409                         // } else {
410                         // initSuperclass= superName;
411                         // }
412                         // }
413                         // }
414                         // } catch (JavaModelException e) {
415                         // PHPeclipsePlugin.log(e);
416                         // // ignore this exception now
417                         // }
418                 }
419
420                 setPackageFragment(pack, true);
421                 // setEnclosingType(enclosingType, true);
422                 setEnclosingTypeSelection(false, true);
423
424                 setTypeName("", true); //$NON-NLS-1$
425                 setSuperClass(initSuperclass, true);
426                 setSuperInterfaces(initSuperinterfaces, true);
427         }
428
429         // -------- UI Creation ---------
430
431         /**
432          * Creates a separator line. Expects a <code>GridLayout</code> with at
433          * least 1 column.
434          * 
435          * @param composite
436          *            the parent composite
437          * @param nColumns
438          *            number of columns to span
439          */
440         protected void createSeparator(Composite composite, int nColumns) {
441                 (new Separator(SWT.SEPARATOR | SWT.HORIZONTAL)).doFillIntoGrid(
442                                 composite, nColumns, convertHeightInCharsToPixels(1));
443         }
444
445         /**
446          * Creates the controls for the package name field. Expects a
447          * <code>GridLayout</code> with at least 4 columns.
448          * 
449          * @param composite
450          *            the parent composite
451          * @param nColumns
452          *            number of columns to span
453          */
454         protected void createPackageControls(Composite composite, int nColumns) {
455                 fPackageDialogField.doFillIntoGrid(composite, nColumns);
456                 LayoutUtil.setWidthHint(fPackageDialogField.getTextControl(null),
457                                 getMaxFieldWidth());
458                 LayoutUtil.setHorizontalGrabbing(fPackageDialogField
459                                 .getTextControl(null));
460         }
461
462         /**
463          * Creates the controls for the enclosing type name field. Expects a
464          * <code>GridLayout</code> with at least 4 columns.
465          * 
466          * @param composite
467          *            the parent composite
468          * @param nColumns
469          *            number of columns to span
470          */
471         protected void createEnclosingTypeControls(Composite composite, int nColumns) {
472                 // #6891
473                 Composite tabGroup = new Composite(composite, SWT.NONE);
474                 GridLayout layout = new GridLayout();
475                 layout.marginWidth = 0;
476                 layout.marginHeight = 0;
477                 tabGroup.setLayout(layout);
478
479                 fEnclosingTypeSelection.doFillIntoGrid(tabGroup, 1);
480
481                 Control c = fEnclosingTypeDialogField.getTextControl(composite);
482                 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
483                 gd.widthHint = getMaxFieldWidth();
484                 gd.horizontalSpan = 2;
485                 c.setLayoutData(gd);
486
487                 Button button = fEnclosingTypeDialogField.getChangeControl(composite);
488                 gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
489                 gd.heightHint = SWTUtil.getButtonHeightHint(button);
490                 gd.widthHint = SWTUtil.getButtonWidthHint(button);
491                 button.setLayoutData(gd);
492         }
493
494         /**
495          * Creates the controls for the type name field. Expects a
496          * <code>GridLayout</code> with at least 2 columns.
497          * 
498          * @param composite
499          *            the parent composite
500          * @param nColumns
501          *            number of columns to span
502          */
503         protected void createTypeNameControls(Composite composite, int nColumns) {
504                 fTypeNameDialogField.doFillIntoGrid(composite, nColumns - 1);
505                 DialogField.createEmptySpace(composite);
506
507                 LayoutUtil.setWidthHint(fTypeNameDialogField.getTextControl(null),
508                                 getMaxFieldWidth());
509         }
510
511         /**
512          * Creates the controls for the modifiers radio/ceckbox buttons. Expects a
513          * <code>GridLayout</code> with at least 3 columns.
514          * 
515          * @param composite
516          *            the parent composite
517          * @param nColumns
518          *            number of columns to span
519          */
520         protected void createModifierControls(Composite composite, int nColumns) {
521                 LayoutUtil.setHorizontalSpan(fAccMdfButtons.getLabelControl(composite),
522                                 1);
523
524                 Control control = fAccMdfButtons.getSelectionButtonsGroup(composite);
525                 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
526                 gd.horizontalSpan = nColumns - 2;
527                 control.setLayoutData(gd);
528
529                 DialogField.createEmptySpace(composite);
530
531                 DialogField.createEmptySpace(composite);
532
533                 control = fOtherMdfButtons.getSelectionButtonsGroup(composite);
534                 gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
535                 gd.horizontalSpan = nColumns - 2;
536                 control.setLayoutData(gd);
537
538                 DialogField.createEmptySpace(composite);
539         }
540
541         /**
542          * Creates the controls for the superclass name field. Expects a
543          * <code>GridLayout</code> with at least 3 columns.
544          * 
545          * @param composite
546          *            the parent composite
547          * @param nColumns
548          *            number of columns to span
549          */
550         protected void createSuperClassControls(Composite composite, int nColumns) {
551                 fSuperClassDialogField.doFillIntoGrid(composite, nColumns);
552                 LayoutUtil.setWidthHint(fSuperClassDialogField.getTextControl(null),
553                                 getMaxFieldWidth());
554         }
555
556         /**
557          * Creates the controls for the superclass name field. Expects a
558          * <code>GridLayout</code> with at least 3 columns.
559          * 
560          * @param composite
561          *            the parent composite
562          * @param nColumns
563          *            number of columns to span
564          */
565         protected void createSuperInterfacesControls(Composite composite,
566                         int nColumns) {
567                 fSuperInterfacesDialogField.doFillIntoGrid(composite, nColumns);
568                 GridData gd = (GridData) fSuperInterfacesDialogField.getListControl(
569                                 null).getLayoutData();
570                 if (fIsClass) {
571                         gd.heightHint = convertHeightInCharsToPixels(3);
572                 } else {
573                         gd.heightHint = convertHeightInCharsToPixels(6);
574                 }
575                 gd.grabExcessVerticalSpace = false;
576                 gd.widthHint = getMaxFieldWidth();
577         }
578
579         /**
580          * Sets the focus on the type name input field.
581          */
582         protected void setFocus() {
583                 fTypeNameDialogField.setFocus();
584         }
585
586         // -------- TypeFieldsAdapter --------
587
588         private class TypeFieldsAdapter implements IStringButtonAdapter,
589                         IDialogFieldListener, IListAdapter {
590
591                 // -------- IStringButtonAdapter
592                 public void changeControlPressed(DialogField field) {
593                         // typePageChangeControlPressed(field);
594                 }
595
596                 // -------- IListAdapter
597                 public void customButtonPressed(ListDialogField field, int index) {
598                         // typePageCustomButtonPressed(field, index);
599                 }
600
601                 public void selectionChanged(ListDialogField field) {
602                 }
603
604                 // -------- IDialogFieldListener
605                 public void dialogFieldChanged(DialogField field) {
606                         typePageDialogFieldChanged(field);
607                 }
608
609                 public void doubleClicked(ListDialogField field) {
610                 }
611         }
612
613         // private void typePageChangeControlPressed(DialogField field) {
614         // if (field == fPackageDialogField) {
615         // IPackageFragment pack= choosePackage();
616         // if (pack != null) {
617         // fPackageDialogField.setText(pack.getElementName());
618         // }
619         // } else if (field == fEnclosingTypeDialogField) {
620         // IType type= chooseEnclosingType();
621         // if (type != null) {
622         // fEnclosingTypeDialogField.setText(JavaModelUtil.getFullyQualifiedName(type));
623         // }
624         // } else if (field == fSuperClassDialogField) {
625         // IType type= chooseSuperType();
626         // if (type != null) {
627         // fSuperClassDialogField.setText(JavaModelUtil.getFullyQualifiedName(type));
628         // }
629         // }
630         // }
631
632         // private void typePageCustomButtonPressed(DialogField field, int index) {
633         // if (field == fSuperInterfacesDialogField) {
634         // chooseSuperInterfaces();
635         // }
636         // }
637
638         /*
639          * A field on the type has changed. The fields' status and all dependend
640          * status are updated.
641          */
642         private void typePageDialogFieldChanged(DialogField field) {
643                 String fieldName = null;
644                 if (field == fPackageDialogField) {
645                         fPackageStatus = packageChanged();
646                         updatePackageStatusLabel();
647                         fTypeNameStatus = typeNameChanged();
648                         // fSuperClassStatus= superClassChanged();
649                         fieldName = PACKAGE;
650                 } else if (field == fEnclosingTypeDialogField) {
651                         // fEnclosingTypeStatus= enclosingTypeChanged();
652                         fTypeNameStatus = typeNameChanged();
653                         // fSuperClassStatus= superClassChanged();
654                         fieldName = ENCLOSING;
655                 } else if (field == fEnclosingTypeSelection) {
656                         updateEnableState();
657                         boolean isEnclosedType = isEnclosingTypeSelected();
658                         if (!isEnclosedType) {
659                                 if (fAccMdfButtons.isSelected(PRIVATE_INDEX)
660                                                 || fAccMdfButtons.isSelected(PROTECTED_INDEX)) {
661                                         fAccMdfButtons.setSelection(PRIVATE_INDEX, false);
662                                         fAccMdfButtons.setSelection(PROTECTED_INDEX, false);
663                                         fAccMdfButtons.setSelection(PUBLIC_INDEX, true);
664                                 }
665                                 if (fOtherMdfButtons.isSelected(fStaticMdfIndex)) {
666                                         fOtherMdfButtons.setSelection(fStaticMdfIndex, false);
667                                 }
668                         }
669                         fAccMdfButtons.enableSelectionButton(PRIVATE_INDEX, isEnclosedType
670                                         && fIsClass);
671                         fAccMdfButtons.enableSelectionButton(PROTECTED_INDEX,
672                                         isEnclosedType && fIsClass);
673                         fOtherMdfButtons.enableSelectionButton(fStaticMdfIndex,
674                                         isEnclosedType);
675                         fTypeNameStatus = typeNameChanged();
676                         // fSuperClassStatus= superClassChanged();
677                         fieldName = ENCLOSINGSELECTION;
678                 } else if (field == fTypeNameDialogField) {
679                         fTypeNameStatus = typeNameChanged();
680                         fieldName = TYPENAME;
681                 } else if (field == fSuperClassDialogField) {
682                         // fSuperClassStatus= superClassChanged();
683                         fieldName = SUPER;
684                 } else if (field == fSuperInterfacesDialogField) {
685                         // fSuperInterfacesStatus= superInterfacesChanged();
686                         fieldName = INTERFACES;
687                 } else if (field == fOtherMdfButtons) {
688                         fModifierStatus = modifiersChanged();
689                         fieldName = MODIFIERS;
690                 } else {
691                         fieldName = METHODS;
692                 }
693                 // tell all others
694                 handleFieldChanged(fieldName);
695         }
696
697         // -------- update message ----------------
698
699         /*
700          * @see net.sourceforge.phpdt.ui.wizards.NewContainerWizardPage#handleFieldChanged(String)
701          */
702         protected void handleFieldChanged(String fieldName) {
703                 super.handleFieldChanged(fieldName);
704                 if (fieldName == CONTAINER) {
705                         fPackageStatus = packageChanged();
706                         // fEnclosingTypeStatus= enclosingTypeChanged();
707                         fTypeNameStatus = typeNameChanged();
708                         // fSuperClassStatus= superClassChanged();
709                         // fSuperInterfacesStatus= superInterfacesChanged();
710                 }
711         }
712
713         // ---- set / get ----------------
714
715         /**
716          * Returns the text of the package input field.
717          * 
718          * @return the text of the package input field
719          */
720         public String getPackageText() {
721                 return fPackageDialogField.getText();
722         }
723
724         /**
725          * Returns the text of the enclosing type input field.
726          * 
727          * @return the text of the enclosing type input field
728          */
729         public String getEnclosingTypeText() {
730                 return fEnclosingTypeDialogField.getText();
731         }
732
733         /**
734          * Returns the package fragment corresponding to the current input.
735          * 
736          * @return a package fragement or <code>null</code> if the input could not
737          *         be resolved.
738          */
739         public IPackageFragment getPackageFragment() {
740                 if (!isEnclosingTypeSelected()) {
741                         return fCurrPackage;
742                 } else {
743                         // if (fCurrEnclosingType != null) {
744                         // return fCurrEnclosingType.getPackageFragment();
745                         // }
746                 }
747                 return null;
748         }
749
750         /**
751          * Sets the package fragment to the given value. The method updates the
752          * model and the text of the control.
753          * 
754          * @param pack
755          *            the package fragement to be set
756          * @param canBeModified
757          *            if <code>true</code> the package fragment is editable;
758          *            otherwise it is read-only.
759          */
760         public void setPackageFragment(IPackageFragment pack, boolean canBeModified) {
761                 fCurrPackage = pack;
762                 fCanModifyPackage = canBeModified;
763                 String str = (pack == null) ? "" : pack.getElementName(); //$NON-NLS-1$
764                 fPackageDialogField.setText(str);
765                 updateEnableState();
766         }
767
768         /**
769          * Returns the enclosing type corresponding to the current input.
770          * 
771          * @return the enclosing type or <code>null</code> if the enclosing type
772          *         is not selected or the input could not be resolved
773          */
774         public IType getEnclosingType() {
775                 // if (isEnclosingTypeSelected()) {
776                 // return fCurrEnclosingType;
777                 // }
778                 return null;
779         }
780
781         /**
782          * Sets the enclosing type. The method updates the underlying model and the
783          * text of the control.
784          * 
785          * @param type
786          *            the enclosing type
787          * @param canBeModified
788          *            if <code>true</code> the enclosing type field is editable;
789          *            otherwise it is read-only.
790          */
791         // public void setEnclosingType(IType type, boolean canBeModified) {
792         // fCurrEnclosingType= type;
793         // fCanModifyEnclosingType= canBeModified;
794         // String str= (type == null) ? "" :
795         // JavaModelUtil.getFullyQualifiedName(type); //$NON-NLS-1$
796         // fEnclosingTypeDialogField.setText(str);
797         // updateEnableState();
798         // }
799         /**
800          * Returns the selection state of the enclosing type checkbox.
801          * 
802          * @return the seleciton state of the enclosing type checkbox
803          */
804         public boolean isEnclosingTypeSelected() {
805                 return fEnclosingTypeSelection.isSelected();
806         }
807
808         /**
809          * Sets the enclosing type checkbox's selection state.
810          * 
811          * @param isSelected
812          *            the checkbox's selection state
813          * @param canBeModified
814          *            if <code>true</code> the enclosing type checkbox is
815          *            modifiable; otherwise it is read-only.
816          */
817         public void setEnclosingTypeSelection(boolean isSelected,
818                         boolean canBeModified) {
819                 fEnclosingTypeSelection.setSelection(isSelected);
820                 fEnclosingTypeSelection.setEnabled(canBeModified);
821                 updateEnableState();
822         }
823
824         /**
825          * Returns the type name entered into the type input field.
826          * 
827          * @return the type name
828          */
829         public String getTypeName() {
830                 return fTypeNameDialogField.getText();
831         }
832
833         /**
834          * Sets the type name input field's text to the given value. Method doesn't
835          * update the model.
836          * 
837          * @param name
838          *            the new type name
839          * @param canBeModified
840          *            if <code>true</code> the enclosing type name field is
841          *            editable; otherwise it is read-only.
842          */
843         public void setTypeName(String name, boolean canBeModified) {
844                 fTypeNameDialogField.setText(name);
845                 fTypeNameDialogField.setEnabled(canBeModified);
846         }
847
848         /**
849          * Returns the selected modifiers.
850          * 
851          * @return the selected modifiers
852          * @see Flags
853          */
854         public int getModifiers() {
855                 int mdf = 0;
856                 if (fAccMdfButtons.isSelected(PUBLIC_INDEX)) {
857                         mdf += F_PUBLIC;
858                 } else if (fAccMdfButtons.isSelected(PRIVATE_INDEX)) {
859                         mdf += F_PRIVATE;
860                 } else if (fAccMdfButtons.isSelected(PROTECTED_INDEX)) {
861                         mdf += F_PROTECTED;
862                 }
863                 // if (fOtherMdfButtons.isSelected(ABSTRACT_INDEX) && (fStaticMdfIndex
864                 // != 0)) {
865                 // mdf+= F_ABSTRACT;
866                 // }
867                 if (fOtherMdfButtons.isSelected(FINAL_INDEX)) {
868                         mdf += F_FINAL;
869                 }
870                 if (fOtherMdfButtons.isSelected(fStaticMdfIndex)) {
871                         mdf += F_STATIC;
872                 }
873                 return mdf;
874         }
875
876         /**
877          * Sets the modifiers.
878          * 
879          * @param modifiers
880          *            <code>F_PUBLIC</code>, <code>F_PRIVATE</code>,
881          *            <code>F_PROTECTED</code>, <code>F_ABSTRACT, F_FINAL</code>
882          *            or <code>F_STATIC</code> or, a valid combination.
883          * @param canBeModified
884          *            if <code>true</code> the modifier fields are editable;
885          *            otherwise they are read-only
886          * @see Flags
887          */
888         public void setModifiers(int modifiers, boolean canBeModified) {
889                 if (Flags.isPublic(modifiers)) {
890                         fAccMdfButtons.setSelection(PUBLIC_INDEX, true);
891                 } else if (Flags.isPrivate(modifiers)) {
892                         fAccMdfButtons.setSelection(PRIVATE_INDEX, true);
893                 } else if (Flags.isProtected(modifiers)) {
894                         fAccMdfButtons.setSelection(PROTECTED_INDEX, true);
895                 } else {
896                         fAccMdfButtons.setSelection(DEFAULT_INDEX, true);
897                 }
898                 // if (Flags.isAbstract(modifiers)) {
899                 // fOtherMdfButtons.setSelection(ABSTRACT_INDEX, true);
900                 // }
901                 if (Flags.isFinal(modifiers)) {
902                         fOtherMdfButtons.setSelection(FINAL_INDEX, true);
903                 }
904                 if (Flags.isStatic(modifiers)) {
905                         fOtherMdfButtons.setSelection(fStaticMdfIndex, true);
906                 }
907
908                 fAccMdfButtons.setEnabled(canBeModified);
909                 fOtherMdfButtons.setEnabled(canBeModified);
910         }
911
912         /**
913          * Returns the content of the superclass input field.
914          * 
915          * @return the superclass name
916          */
917         public String getSuperClass() {
918                 return fSuperClassDialogField.getText();
919         }
920
921         /**
922          * Sets the super class name.
923          * 
924          * @param name
925          *            the new superclass name
926          * @param canBeModified
927          *            if <code>true</code> the superclass name field is editable;
928          *            otherwise it is read-only.
929          */
930         public void setSuperClass(String name, boolean canBeModified) {
931                 fSuperClassDialogField.setText(name);
932                 fSuperClassDialogField.setEnabled(canBeModified);
933         }
934
935         /**
936          * Returns the chosen super interfaces.
937          * 
938          * @return a list of chosen super interfaces. The list's elements are of
939          *         type <code>String</code>
940          */
941         public List getSuperInterfaces() {
942                 return fSuperInterfacesDialogField.getElements();
943         }
944
945         /**
946          * Sets the super interfaces.
947          * 
948          * @param interfacesNames
949          *            a list of super interface. The method requires that the list's
950          *            elements are of type <code>String</code>
951          * @param canBeModified
952          *            if <code>true</code> the super interface field is editable;
953          *            otherwise it is read-only.
954          */
955         public void setSuperInterfaces(List interfacesNames, boolean canBeModified) {
956                 fSuperInterfacesDialogField.setElements(interfacesNames);
957                 fSuperInterfacesDialogField.setEnabled(canBeModified);
958         }
959
960         // ----------- validation ----------
961
962         /**
963          * A hook method that gets called when the package field has changed. The
964          * method validates the package name and returns the status of the
965          * validation. The validation also updates the package fragment model.
966          * <p>
967          * Subclasses may extend this method to perform their own validation.
968          * </p>
969          * 
970          * @return the status of the validation
971          */
972         protected IStatus packageChanged() {
973                 StatusInfo status = new StatusInfo();
974                 fPackageDialogField.enableButton(getPackageFragmentRoot() != null);
975
976                 // String packName= getPackageText();
977                 // if (packName.length() > 0) {
978                 // IStatus val= JavaConventions.validatePackageName(packName);
979                 // if (val.getSeverity() == IStatus.ERROR) {
980                 // status.setError(NewWizardMessages.getFormattedString("NewTypeWizardPage.error.InvalidPackageName",
981                 // val.getMessage())); //$NON-NLS-1$
982                 // return status;
983                 // } else if (val.getSeverity() == IStatus.WARNING) {
984                 // status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.DiscouragedPackageName",
985                 // val.getMessage())); //$NON-NLS-1$
986                 // // continue
987                 // }
988                 // }
989
990                 // IPackageFragmentRoot root= getPackageFragmentRoot();
991                 // if (root != null) {
992                 // if (root.getJavaProject().exists() && packName.length() > 0) {
993                 // try {
994                 // IPath rootPath= root.getPath();
995                 // IPath outputPath= root.getJavaProject().getOutputLocation();
996                 // if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath))
997                 // {
998                 // // if the bin folder is inside of our root, dont allow to name a
999                 // package
1000                 // // like the bin folder
1001                 // IPath packagePath= rootPath.append(packName.replace('.', '/'));
1002                 // if (outputPath.isPrefixOf(packagePath)) {
1003                 // status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.ClashOutputLocation"));
1004                 // //$NON-NLS-1$
1005                 // return status;
1006                 // }
1007                 // }
1008                 // } catch (JavaModelException e) {
1009                 // PHPeclipsePlugin.log(e);
1010                 // // let pass
1011                 // }
1012                 // }
1013                 //                      
1014                 // fCurrPackage= root.getPackageFragment(packName);
1015                 // } else {
1016                 // status.setError(""); //$NON-NLS-1$
1017                 // }
1018                 return status;
1019         }
1020
1021         /*
1022          * Updates the 'default' label next to the package field.
1023          */
1024         private void updatePackageStatusLabel() {
1025                 String packName = getPackageText();
1026
1027                 if (packName.length() == 0) {
1028                         fPackageDialogField.setStatus(NewWizardMessages
1029                                         .getString("NewTypeWizardPage.default")); //$NON-NLS-1$
1030                 } else {
1031                         fPackageDialogField.setStatus(""); //$NON-NLS-1$
1032                 }
1033         }
1034
1035         /*
1036          * Updates the enable state of buttons related to the enclosing type
1037          * selection checkbox.
1038          */
1039         private void updateEnableState() {
1040                 boolean enclosing = isEnclosingTypeSelected();
1041                 fPackageDialogField.setEnabled(fCanModifyPackage && !enclosing);
1042                 fEnclosingTypeDialogField.setEnabled(fCanModifyEnclosingType
1043                                 && enclosing);
1044         }
1045
1046         /**
1047          * Hook method that gets called when the enclosing type name has changed.
1048          * The method validates the enclosing type and returns the status of the
1049          * validation. It also updates the enclosing type model.
1050          * <p>
1051          * Subclasses may extend this method to perform their own validation.
1052          * </p>
1053          * 
1054          * @return the status of the validation
1055          */
1056         // protected IStatus enclosingTypeChanged() {
1057         // StatusInfo status= new StatusInfo();
1058         // fCurrEnclosingType= null;
1059         //              
1060         // IPackageFragmentRoot root= getPackageFragmentRoot();
1061         //              
1062         // fEnclosingTypeDialogField.enableButton(root != null);
1063         // if (root == null) {
1064         // status.setError(""); //$NON-NLS-1$
1065         // return status;
1066         // }
1067         //              
1068         // String enclName= getEnclosingTypeText();
1069         // if (enclName.length() == 0) {
1070         // status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingTypeEnterName"));
1071         // //$NON-NLS-1$
1072         // return status;
1073         // }
1074         // try {
1075         // IType type= findType(root.getJavaProject(), enclName);
1076         // if (type == null) {
1077         // status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingTypeNotExists"));
1078         // //$NON-NLS-1$
1079         // return status;
1080         // }
1081         //
1082         // if (type.getCompilationUnit() == null) {
1083         // status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingNotInCU"));
1084         // //$NON-NLS-1$
1085         // return status;
1086         // }
1087         // if (!JavaModelUtil.isEditable(type.getCompilationUnit())) {
1088         // status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingNotEditable"));
1089         // //$NON-NLS-1$
1090         // return status;
1091         // }
1092         //                      
1093         // fCurrEnclosingType= type;
1094         // IPackageFragmentRoot enclosingRoot=
1095         // JavaModelUtil.getPackageFragmentRoot(type);
1096         // if (!enclosingRoot.equals(root)) {
1097         // status.setWarning(NewWizardMessages.getString("NewTypeWizardPage.warning.EnclosingNotInSourceFolder"));
1098         // //$NON-NLS-1$
1099         // }
1100         // return status;
1101         // } catch (JavaModelException e) {
1102         // status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingTypeNotExists"));
1103         // //$NON-NLS-1$
1104         // PHPeclipsePlugin.log(e);
1105         // return status;
1106         // }
1107         // }
1108         /**
1109          * Hook method that gets called when the type name has changed. The method
1110          * validates the type name and returns the status of the validation.
1111          * <p>
1112          * Subclasses may extend this method to perform their own validation.
1113          * </p>
1114          * 
1115          * @return the status of the validation
1116          */
1117         protected IStatus typeNameChanged() {
1118                 StatusInfo status = new StatusInfo();
1119                 String typeName = getTypeName();
1120                 // must not be empty
1121                 if (typeName.length() == 0) {
1122                         status.setError(NewWizardMessages
1123                                         .getString("NewTypeWizardPage.error.EnterTypeName")); //$NON-NLS-1$
1124                         return status;
1125                 }
1126                 if (typeName.indexOf('.') != -1) {
1127                         status.setError(NewWizardMessages
1128                                         .getString("NewTypeWizardPage.error.QualifiedName")); //$NON-NLS-1$
1129                         return status;
1130                 }
1131                 // IStatus val= JavaConventions.validateJavaTypeName(typeName);
1132                 // if (val.getSeverity() == IStatus.ERROR) {
1133                 // status.setError(NewWizardMessages.getFormattedString("NewTypeWizardPage.error.InvalidTypeName",
1134                 // val.getMessage())); //$NON-NLS-1$
1135                 // return status;
1136                 // } else if (val.getSeverity() == IStatus.WARNING) {
1137                 // status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.TypeNameDiscouraged",
1138                 // val.getMessage())); //$NON-NLS-1$
1139                 // // continue checking
1140                 // }
1141
1142                 // must not exist
1143                 if (!isEnclosingTypeSelected()) {
1144                         IPackageFragment pack = getPackageFragment();
1145                         if (pack != null) {
1146                                 ICompilationUnit cu = pack.getCompilationUnit(typeName
1147                                                 + ".java"); //$NON-NLS-1$
1148                                 if (cu.getResource().exists()) {
1149                                         status
1150                                                         .setError(NewWizardMessages
1151                                                                         .getString("NewTypeWizardPage.error.TypeNameExists")); //$NON-NLS-1$
1152                                         return status;
1153                                 }
1154                         }
1155                 } else {
1156                         IType type = getEnclosingType();
1157                         if (type != null) {
1158                                 IType member = type.getType(typeName);
1159                                 if (member.exists()) {
1160                                         status
1161                                                         .setError(NewWizardMessages
1162                                                                         .getString("NewTypeWizardPage.error.TypeNameExists")); //$NON-NLS-1$
1163                                         return status;
1164                                 }
1165                         }
1166                 }
1167                 return status;
1168         }
1169
1170         /**
1171          * Hook method that gets called when the superclass name has changed. The
1172          * method validates the superclass name and returns the status of the
1173          * validation.
1174          * <p>
1175          * Subclasses may extend this method to perform their own validation.
1176          * </p>
1177          * 
1178          * @return the status of the validation
1179          */
1180         // protected IStatus superClassChanged() {
1181         // StatusInfo status= new StatusInfo();
1182         // IPackageFragmentRoot root= getPackageFragmentRoot();
1183         // fSuperClassDialogField.enableButton(root != null);
1184         //              
1185         // fSuperClass= null;
1186         //              
1187         // String sclassName= getSuperClass();
1188         // if (sclassName.length() == 0) {
1189         // // accept the empty field (stands for java.lang.Object)
1190         // return status;
1191         // }
1192         // IStatus val= JavaConventions.validateJavaTypeName(sclassName);
1193         // if (val.getSeverity() == IStatus.ERROR) {
1194         // status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.InvalidSuperClassName"));
1195         // //$NON-NLS-1$
1196         // return status;
1197         // }
1198         // if (root != null) {
1199         // try {
1200         // IType type= resolveSuperTypeName(root.getJavaProject(), sclassName);
1201         // if (type == null) {
1202         // status.setWarning(NewWizardMessages.getString("NewTypeWizardPage.warning.SuperClassNotExists"));
1203         // //$NON-NLS-1$
1204         // return status;
1205         // } else {
1206         // if (type.isInterface()) {
1207         // status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.SuperClassIsNotClass",
1208         // sclassName)); //$NON-NLS-1$
1209         // return status;
1210         // }
1211         // int flags= type.getFlags();
1212         // if (Flags.isFinal(flags)) {
1213         // status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.SuperClassIsFinal",
1214         // sclassName)); //$NON-NLS-1$
1215         // return status;
1216         // } else if (!JavaModelUtil.isVisible(type, getPackageFragment())) {
1217         // status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.SuperClassIsNotVisible",
1218         // sclassName)); //$NON-NLS-1$
1219         // return status;
1220         // }
1221         // }
1222         // fSuperClass= type;
1223         // } catch (JavaModelException e) {
1224         // status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.InvalidSuperClassName"));
1225         // //$NON-NLS-1$
1226         // PHPeclipsePlugin.log(e);
1227         // }
1228         // } else {
1229         // status.setError(""); //$NON-NLS-1$
1230         // }
1231         // return status;
1232         //              
1233         // }
1234         // private IType resolveSuperTypeName(IJavaProject jproject, String
1235         // sclassName) throws JavaModelException {
1236         // if (!jproject.exists()) {
1237         // return null;
1238         // }
1239         // IType type= null;
1240         // if (isEnclosingTypeSelected()) {
1241         // // search in the context of the enclosing type
1242         // IType enclosingType= getEnclosingType();
1243         // if (enclosingType != null) {
1244         // String[][] res= enclosingType.resolveType(sclassName);
1245         // if (res != null && res.length > 0) {
1246         // type= jproject.findType(res[0][0], res[0][1]);
1247         // }
1248         // }
1249         // } else {
1250         // IPackageFragment currPack= getPackageFragment();
1251         // if (type == null && currPack != null) {
1252         // String packName= currPack.getElementName();
1253         // // search in own package
1254         // if (!currPack.isDefaultPackage()) {
1255         // type= jproject.findType(packName, sclassName);
1256         // }
1257         // // search in java.lang
1258         // if (type == null && !"java.lang".equals(packName)) { //$NON-NLS-1$
1259         // type= jproject.findType("java.lang", sclassName); //$NON-NLS-1$
1260         // }
1261         // }
1262         // // search fully qualified
1263         // if (type == null) {
1264         // type= jproject.findType(sclassName);
1265         // }
1266         // }
1267         // return type;
1268         // }
1269         // private IType findType(IJavaProject project, String typeName) throws
1270         // JavaModelException {
1271         // if (project.exists()) {
1272         // return project.findType(typeName);
1273         // }
1274         // return null;
1275         // }
1276         /**
1277          * Hook method that gets called when the list of super interface has
1278          * changed. The method validates the superinterfaces and returns the status
1279          * of the validation.
1280          * <p>
1281          * Subclasses may extend this method to perform their own validation.
1282          * </p>
1283          * 
1284          * @return the status of the validation
1285          */
1286         // protected IStatus superInterfacesChanged() {
1287         // StatusInfo status= new StatusInfo();
1288         //              
1289         // IPackageFragmentRoot root= getPackageFragmentRoot();
1290         // fSuperInterfacesDialogField.enableButton(0, root != null);
1291         //                                              
1292         // if (root != null) {
1293         // List elements= fSuperInterfacesDialogField.getElements();
1294         // int nElements= elements.size();
1295         // for (int i= 0; i < nElements; i++) {
1296         // String intfname= (String)elements.get(i);
1297         // try {
1298         // IType type= findType(root.getJavaProject(), intfname);
1299         // if (type == null) {
1300         // status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.InterfaceNotExists",
1301         // intfname)); //$NON-NLS-1$
1302         // return status;
1303         // } else {
1304         // if (type.isClass()) {
1305         // status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.InterfaceIsNotInterface",
1306         // intfname)); //$NON-NLS-1$
1307         // return status;
1308         // }
1309         // if (!JavaModelUtil.isVisible(type, getPackageFragment())) {
1310         // status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.InterfaceIsNotVisible",
1311         // intfname)); //$NON-NLS-1$
1312         // return status;
1313         // }
1314         // }
1315         // } catch (JavaModelException e) {
1316         // PHPeclipsePlugin.log(e);
1317         // // let pass, checking is an extra
1318         // }
1319         // }
1320         // }
1321         // return status;
1322         // }
1323         /**
1324          * Hook method that gets called when the modifiers have changed. The method
1325          * validates the modifiers and returns the status of the validation.
1326          * <p>
1327          * Subclasses may extend this method to perform their own validation.
1328          * </p>
1329          * 
1330          * @return the status of the validation
1331          */
1332         protected IStatus modifiersChanged() {
1333                 StatusInfo status = new StatusInfo();
1334                 int modifiers = getModifiers();
1335                 // if (Flags.isFinal(modifiers) && Flags.isAbstract(modifiers)) {
1336                 // status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.ModifiersFinalAndAbstract"));
1337                 // //$NON-NLS-1$
1338                 // }
1339                 return status;
1340         }
1341
1342         // selection dialogs
1343
1344         // private IPackageFragment choosePackage() {
1345         // IPackageFragmentRoot froot= getPackageFragmentRoot();
1346         // IJavaElement[] packages= null;
1347         // try {
1348         // if (froot != null && froot.exists()) {
1349         // packages= froot.getChildren();
1350         // }
1351         // } catch (JavaModelException e) {
1352         // PHPeclipsePlugin.log(e);
1353         // }
1354         // if (packages == null) {
1355         // packages= new IJavaElement[0];
1356         // }
1357         //              
1358         // ElementListSelectionDialog dialog= new
1359         // ElementListSelectionDialog(getShell(), new
1360         // JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT));
1361         // dialog.setIgnoreCase(false);
1362         // dialog.setTitle(NewWizardMessages.getString("NewTypeWizardPage.ChoosePackageDialog.title"));
1363         // //$NON-NLS-1$
1364         // dialog.setMessage(NewWizardMessages.getString("NewTypeWizardPage.ChoosePackageDialog.description"));
1365         // //$NON-NLS-1$
1366         // dialog.setEmptyListMessage(NewWizardMessages.getString("NewTypeWizardPage.ChoosePackageDialog.empty"));
1367         // //$NON-NLS-1$
1368         // dialog.setElements(packages);
1369         // IPackageFragment pack= getPackageFragment();
1370         // if (pack != null) {
1371         // dialog.setInitialSelections(new Object[] { pack });
1372         // }
1373         //
1374         // if (dialog.open() == ElementListSelectionDialog.OK) {
1375         // return (IPackageFragment) dialog.getFirstResult();
1376         // }
1377         // return null;
1378         // }
1379
1380         // private IType chooseEnclosingType() {
1381         // IPackageFragmentRoot root= getPackageFragmentRoot();
1382         // if (root == null) {
1383         // return null;
1384         // }
1385         //              
1386         // IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new
1387         // IJavaElement[] { root });
1388         //      
1389         // TypeSelectionDialog dialog= new TypeSelectionDialog(getShell(),
1390         // getWizard().getContainer(), IJavaSearchConstants.TYPE, scope);
1391         // dialog.setTitle(NewWizardMessages.getString("NewTypeWizardPage.ChooseEnclosingTypeDialog.title"));
1392         // //$NON-NLS-1$
1393         // dialog.setMessage(NewWizardMessages.getString("NewTypeWizardPage.ChooseEnclosingTypeDialog.description"));
1394         // //$NON-NLS-1$
1395         // dialog.setFilter(Signature.getSimpleName(getEnclosingTypeText()));
1396         //              
1397         // if (dialog.open() == TypeSelectionDialog.OK) {
1398         // return (IType) dialog.getFirstResult();
1399         // }
1400         // return null;
1401         // }
1402
1403         // private IType chooseSuperType() {
1404         // IPackageFragmentRoot root= getPackageFragmentRoot();
1405         // if (root == null) {
1406         // return null;
1407         // }
1408         //              
1409         // IJavaElement[] elements= new IJavaElement[] { root.getJavaProject() };
1410         // IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements);
1411         //
1412         // TypeSelectionDialog dialog= new TypeSelectionDialog(getShell(),
1413         // getWizard().getContainer(), IJavaSearchConstants.CLASS, scope);
1414         // dialog.setTitle(NewWizardMessages.getString("NewTypeWizardPage.SuperClassDialog.title"));
1415         // //$NON-NLS-1$
1416         // dialog.setMessage(NewWizardMessages.getString("NewTypeWizardPage.SuperClassDialog.message"));
1417         // //$NON-NLS-1$
1418         // dialog.setFilter(getSuperClass());
1419         //
1420         // if (dialog.open() == TypeSelectionDialog.OK) {
1421         // return (IType) dialog.getFirstResult();
1422         // }
1423         // return null;
1424         // }
1425
1426         // private void chooseSuperInterfaces() {
1427         // IPackageFragmentRoot root= getPackageFragmentRoot();
1428         // if (root == null) {
1429         // return;
1430         // }
1431         //
1432         // IJavaProject project= root.getJavaProject();
1433         // SuperInterfaceSelectionDialog dialog= new
1434         // SuperInterfaceSelectionDialog(getShell(), getWizard().getContainer(),
1435         // fSuperInterfacesDialogField, project);
1436         // dialog.setTitle(fIsClass ?
1437         // NewWizardMessages.getString("NewTypeWizardPage.InterfacesDialog.class.title")
1438         // :
1439         // NewWizardMessages.getString("NewTypeWizardPage.InterfacesDialog.interface.title"));
1440         // //$NON-NLS-1$ //$NON-NLS-2$
1441         // dialog.setMessage(NewWizardMessages.getString("NewTypeWizardPage.InterfacesDialog.message"));
1442         // //$NON-NLS-1$
1443         // dialog.open();
1444         // return;
1445         // }
1446
1447         // ---- creation ----------------
1448
1449         /**
1450          * Creates the new type using the entered field values.
1451          * 
1452          * @param monitor
1453          *            a progress monitor to report progress.
1454          */
1455         public void createType(IProgressMonitor monitor) throws CoreException,
1456                         InterruptedException {
1457                 if (monitor == null) {
1458                         monitor = new NullProgressMonitor();
1459                 }
1460
1461                 monitor.beginTask(NewWizardMessages
1462                                 .getString("NewTypeWizardPage.operationdesc"), 10); //$NON-NLS-1$
1463                 ICompilationUnit createdWorkingCopy = null;
1464                 try {
1465                         // IPackageFragmentRoot root = getPackageFragmentRoot();
1466                         // IPackageFragment pack = getPackageFragment();
1467                         // if (pack == null) {
1468                         // pack = root.getPackageFragment(""); //$NON-NLS-1$
1469                         // }
1470                         //
1471                         // if (!pack.exists()) {
1472                         // String packName = pack.getElementName();
1473                         // pack = root.createPackageFragment(packName, true, null);
1474                         // }
1475
1476                         monitor.worked(1);
1477
1478                         String clName = getTypeName();
1479
1480                         boolean isInnerClass = isEnclosingTypeSelected();
1481
1482                         IType createdType;
1483                         // ImportsStructure imports;
1484                         int indent = 0;
1485
1486                         IPreferenceStore store = PreferenceConstants.getPreferenceStore();
1487                         // String[] prefOrder =
1488                         // JavaPreferencesSettings.getImportOrderPreference(store);
1489                         // int threshold =
1490                         // JavaPreferencesSettings.getImportNumberThreshold(store);
1491                         //
1492                         String lineDelimiter = null;
1493                         // if (!isInnerClass) {
1494                         lineDelimiter = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
1495                         //
1496                         // ICompilationUnit parentCU = pack.createCompilationUnit(clName +
1497                         // ".php", "", false, new SubProgressMonitor(monitor, 2));
1498                         // //$NON-NLS-1$ //$NON-NLS-2$
1499                         // createdWorkingCopy = (ICompilationUnit)
1500                         // parentCU.getSharedWorkingCopy(null, JavaUI.getBufferFactory(),
1501                         // null);
1502                         //
1503                         // imports = new ImportsStructure(createdWorkingCopy, prefOrder,
1504                         // threshold, false);
1505                         // // add an import that will be removed again. Having this import
1506                         // solves 14661
1507                         // imports.addImport(pack.getElementName(), getTypeName());
1508                         //
1509                         String typeContent = constructTypeStub(lineDelimiter);// new
1510                                                                                                                                         // ImportsManager(imports),
1511                                                                                                                                         // lineDelimiter);
1512
1513                         // String cuContent = constructCUContent(parentCU, typeContent,
1514                         // lineDelimiter);
1515
1516                         // createdWorkingCopy.getBuffer().setContents(cuContent);
1517                         //
1518                         createdType = createdWorkingCopy.getType(clName);
1519                         // } else {
1520                         // IType enclosingType = getEnclosingType();
1521                         //
1522                         // // if we are working on a enclosed type that is open in an
1523                         // editor,
1524                         // // then replace the enclosing type with its working copy
1525                         // IType workingCopy = (IType)
1526                         // EditorUtility.getWorkingCopy(enclosingType);
1527                         // if (workingCopy != null) {
1528                         // enclosingType = workingCopy;
1529                         // }
1530                         //
1531                         // ICompilationUnit parentCU = enclosingType.getCompilationUnit();
1532                         // imports = new ImportsStructure(parentCU, prefOrder, threshold,
1533                         // true);
1534                         //
1535                         // // add imports that will be removed again. Having the imports
1536                         // solves 14661
1537                         // IType[] topLevelTypes = parentCU.getTypes();
1538                         // for (int i = 0; i < topLevelTypes.length; i++) {
1539                         // imports.addImport(topLevelTypes[i].getFullyQualifiedName('.'));
1540                         // }
1541                         //
1542                         // lineDelimiter = StubUtility.getLineDelimiterUsed(enclosingType);
1543                         // StringBuffer content = new StringBuffer();
1544                         // String comment = getTypeComment(parentCU);
1545                         // if (comment != null) {
1546                         // content.append(comment);
1547                         // content.append(lineDelimiter);
1548                         // }
1549                         // content.append(constructTypeStub(new ImportsManager(imports),
1550                         // lineDelimiter));
1551                         // IJavaElement[] elems = enclosingType.getChildren();
1552                         // IJavaElement sibling = elems.length > 0 ? elems[0] : null;
1553                         //
1554                         // createdType = enclosingType.createType(content.toString(),
1555                         // sibling, false, new SubProgressMonitor(monitor, 1));
1556                         //
1557                         // indent = StubUtility.getIndentUsed(enclosingType) + 1;
1558                         // }
1559                         //
1560                         // // add imports for superclass/interfaces, so types can be
1561                         // resolved correctly
1562                         // imports.create(false, new SubProgressMonitor(monitor, 1));
1563                         //
1564                         ICompilationUnit cu = createdType.getCompilationUnit();
1565                         synchronized (cu) {
1566                                 cu.reconcile();
1567                         }
1568                         // createTypeMembers(createdType, new ImportsManager(imports), new
1569                         // SubProgressMonitor(monitor, 1));
1570                         //
1571                         // // add imports
1572                         // imports.create(false, new SubProgressMonitor(monitor, 1));
1573
1574                         synchronized (cu) {
1575                                 cu.reconcile();
1576                         }
1577                         ISourceRange range = createdType.getSourceRange();
1578
1579                         IBuffer buf = cu.getBuffer();
1580                         String originalContent = buf.getText(range.getOffset(), range
1581                                         .getLength());
1582                         String formattedContent = StubUtility.codeFormat(originalContent,
1583                                         indent, lineDelimiter);
1584                         buf.replace(range.getOffset(), range.getLength(), formattedContent);
1585                         if (!isInnerClass) {
1586                                 String fileComment = getFileComment(cu);
1587                                 if (fileComment != null && fileComment.length() > 0) {
1588                                         buf.replace(0, 0, fileComment + lineDelimiter);
1589                                 }
1590                                 cu.commit(false, new SubProgressMonitor(monitor, 1));
1591                         } else {
1592                                 monitor.worked(1);
1593                         }
1594                         fCreatedType = createdType;
1595                 } finally {
1596                         if (createdWorkingCopy != null) {
1597                                 createdWorkingCopy.destroy();
1598                         }
1599                         monitor.done();
1600                 }
1601         }
1602
1603         /**
1604          * Uses the New Java file template from the code template page to generate a
1605          * compilation unit with the given type content.
1606          * 
1607          * @param cu
1608          *            The new created compilation unit
1609          * @param typeContent
1610          *            The content of the type, including signature and type body.
1611          * @param lineDelimiter
1612          *            The line delimiter to be used.
1613          * @return String Returns the result of evaluating the new file template
1614          *         with the given type content.
1615          * @throws CoreException
1616          * @since 2.1
1617          */
1618         // protected String constructCUContent(ICompilationUnit cu, String
1619         // typeContent, String lineDelimiter) throws CoreException {
1620         // StringBuffer typeQualifiedName= new StringBuffer();
1621         // if (isEnclosingTypeSelected()) {
1622         // typeQualifiedName.append(JavaModelUtil.getTypeQualifiedName(getEnclosingType())).append('.');
1623         // }
1624         // typeQualifiedName.append(getTypeName());
1625         // String typeComment= CodeGeneration.getTypeComment(cu,
1626         // typeQualifiedName.toString(), lineDelimiter);
1627         // IPackageFragment pack= (IPackageFragment) cu.getParent();
1628         // String content= CodeGeneration.getCompilationUnitContent(cu, typeComment,
1629         // typeContent, lineDelimiter);
1630         // if (content != null) {
1631         // CompilationUnit unit= AST.parseCompilationUnit(content.toCharArray());
1632         // if ((pack.isDefaultPackage() || unit.getPackage() != null) &&
1633         // !unit.types().isEmpty()) {
1634         // return content;
1635         // }
1636         // }
1637         // StringBuffer buf= new StringBuffer();
1638         // if (!pack.isDefaultPackage()) {
1639         // buf.append("package ").append(pack.getElementName()).append(';');
1640         // //$NON-NLS-1$
1641         // }
1642         // buf.append(lineDelimiter).append(lineDelimiter);
1643         // if (typeComment != null) {
1644         // buf.append(typeComment).append(lineDelimiter);
1645         // }
1646         // buf.append(typeContent);
1647         // return buf.toString();
1648         // }
1649         /**
1650          * Returns the created type. The method only returns a valid type after
1651          * <code>createType</code> has been called.
1652          * 
1653          * @return the created type
1654          * @see #createType(IProgressMonitor)
1655          */
1656         public IType getCreatedType() {
1657                 return fCreatedType;
1658         }
1659
1660         // ---- construct cu body----------------
1661
1662         // private void writeSuperClass(StringBuffer buf, ImportsManager imports) {
1663         // String typename= getSuperClass();
1664         // if (fIsClass && typename.length() > 0 &&
1665         // !"java.lang.Object".equals(typename)) { //$NON-NLS-1$
1666         // buf.append(" extends "); //$NON-NLS-1$
1667         //                      
1668         // String qualifiedName= fSuperClass != null ?
1669         // JavaModelUtil.getFullyQualifiedName(fSuperClass) : typename;
1670         // buf.append(imports.addImport(qualifiedName));
1671         // }
1672         // }
1673
1674         // private void writeSuperInterfaces(StringBuffer buf, ImportsManager
1675         // imports) {
1676         // List interfaces= getSuperInterfaces();
1677         // int last= interfaces.size() - 1;
1678         // if (last >= 0) {
1679         // if (fIsClass) {
1680         // buf.append(" implements "); //$NON-NLS-1$
1681         // } else {
1682         // buf.append(" extends "); //$NON-NLS-1$
1683         // }
1684         // for (int i= 0; i <= last; i++) {
1685         // String typename= (String) interfaces.get(i);
1686         // buf.append(imports.addImport(typename));
1687         // if (i < last) {
1688         // buf.append(',');
1689         // }
1690         // }
1691         // }
1692         // }
1693
1694         /*
1695          * Called from createType to construct the source for this type
1696          */
1697         private String constructTypeStub(String lineDelimiter) { // ImportsManager
1698                                                                                                                                 // imports,
1699                                                                                                                                 // String
1700                                                                                                                                 // lineDelimiter)
1701                                                                                                                                 // {
1702                 StringBuffer buf = new StringBuffer();
1703
1704                 int modifiers = getModifiers();
1705                 buf.append(Flags.toString(modifiers));
1706                 if (modifiers != 0) {
1707                         buf.append(' ');
1708                 }
1709                 buf.append(fIsClass ? "class " : "interface "); //$NON-NLS-2$ //$NON-NLS-1$
1710                 buf.append(getTypeName());
1711                 // writeSuperClass(buf, imports);
1712                 // writeSuperInterfaces(buf, imports);
1713                 buf.append('{');
1714                 buf.append(lineDelimiter);
1715                 buf.append(lineDelimiter);
1716                 buf.append('}');
1717                 buf.append(lineDelimiter);
1718                 return buf.toString();
1719         }
1720
1721         /**
1722          * @deprecated Overwrite createTypeMembers(IType, IImportsManager,
1723          *             IProgressMonitor) instead
1724          */
1725         // protected void createTypeMembers(IType newType, IImportsStructure
1726         // imports, IProgressMonitor monitor) throws CoreException {
1727         // //deprecated
1728         // }
1729         /**
1730          * Hook method that gets called from <code>createType</code> to support
1731          * adding of unanticipated methods, fields, and inner types to the created
1732          * type.
1733          * <p>
1734          * Implementers can use any methods defined on <code>IType</code> to
1735          * manipulate the new type.
1736          * </p>
1737          * <p>
1738          * The source code of the new type will be formtted using the platform's
1739          * formatter. Needed imports are added by the wizard at the end of the type
1740          * creation process using the given import manager.
1741          * </p>
1742          * 
1743          * @param newType
1744          *            the new type created via <code>createType</code>
1745          * @param imports
1746          *            an import manager which can be used to add new imports
1747          * @param monitor
1748          *            a progress monitor to report progress. Must not be
1749          *            <code>null</code>
1750          * 
1751          * @see #createType(IProgressMonitor)
1752          */
1753         // protected void createTypeMembers(IType newType, ImportsManager imports,
1754         // IProgressMonitor monitor) throws CoreException {
1755         // // call for compatibility
1756         // createTypeMembers(newType,
1757         // ((ImportsManager)imports).getImportsStructure(), monitor);
1758         //              
1759         // // default implementation does nothing
1760         // // example would be
1761         // // String mainMathod= "public void foo(Vector vec) {}"
1762         // // createdType.createMethod(main, null, false, null);
1763         // // imports.addImport("java.lang.Vector");
1764         // }
1765         /**
1766          * @deprecated Instead of file templates, the new type code template
1767          *             specifies the stub for a compilation unit.
1768          */
1769         protected String getFileComment(ICompilationUnit parentCU) {
1770                 return null;
1771         }
1772
1773         private boolean isValidComment(String template) {
1774                 IScanner scanner = ToolFactory.createScanner(true, false, false); // ,
1775                                                                                                                                                         // false);
1776                 scanner.setSource(template.toCharArray());
1777                 try {
1778                         int next = scanner.getNextToken();
1779                         while (next == ITerminalSymbols.TokenNameCOMMENT_LINE
1780                                         || next == ITerminalSymbols.TokenNameCOMMENT_PHPDOC
1781                                         || next == ITerminalSymbols.TokenNameCOMMENT_BLOCK) {
1782                                 next = scanner.getNextToken();
1783                         }
1784                         return next == ITerminalSymbols.TokenNameEOF;
1785                 } catch (InvalidInputException e) {
1786                 }
1787                 return false;
1788         }
1789
1790         /**
1791          * Hook method that gets called from <code>createType</code> to retrieve a
1792          * type comment. This default implementation returns the content of the
1793          * 'typecomment' template.
1794          * 
1795          * @return the type comment or <code>null</code> if a type comment is not
1796          *         desired
1797          */
1798         protected String getTypeComment(ICompilationUnit parentCU) {
1799                 if (PreferenceConstants.getPreferenceStore().getBoolean(
1800                                 PreferenceConstants.CODEGEN_ADD_COMMENTS)) {
1801                         try {
1802                                 StringBuffer typeName = new StringBuffer();
1803                                 if (isEnclosingTypeSelected()) {
1804                                         typeName.append(
1805                                                         JavaModelUtil
1806                                                                         .getTypeQualifiedName(getEnclosingType()))
1807                                                         .append('.');
1808                                 }
1809                                 typeName.append(getTypeName());
1810                                 String comment = CodeGeneration.getTypeComment(parentCU,
1811                                                 typeName.toString(), String.valueOf('\n'));
1812                                 if (comment != null && isValidComment(comment)) {
1813                                         return comment;
1814                                 }
1815                         } catch (CoreException e) {
1816                                 PHPeclipsePlugin.log(e);
1817                         }
1818                 }
1819                 return null;
1820         }
1821
1822         /**
1823          * @deprecated Use getTemplate(String,ICompilationUnit,int)
1824          */
1825         protected String getTemplate(String name, ICompilationUnit parentCU) {
1826                 return getTemplate(name, parentCU, 0);
1827         }
1828
1829         /**
1830          * Returns the string resulting from evaluation the given template in the
1831          * context of the given compilation unit. This accesses the normal template
1832          * page, not the code templates. To use code templates use
1833          * <code>constructCUContent</code> to construct a compilation unit stub or
1834          * getTypeComment for the comment of the type.
1835          * 
1836          * @param name
1837          *            the template to be evaluated
1838          * @param parentCU
1839          *            the templates evaluation context
1840          * @param pos
1841          *            a source offset into the parent compilation unit. The template
1842          *            is evalutated at the given source offset
1843          */
1844         protected String getTemplate(String name, ICompilationUnit parentCU, int pos) {
1845                 try {
1846                         Template[] templates = Templates.getInstance().getTemplates(name);
1847                         if (templates.length > 0) {
1848                                 return JavaContext
1849                                                 .evaluateTemplate(templates[0], parentCU, pos);
1850                         }
1851                 } catch (CoreException e) {
1852                         PHPeclipsePlugin.log(e);
1853                 } catch (BadLocationException e1) {
1854                         // TODO Auto-generated catch block
1855                         e1.printStackTrace();
1856                 } catch (TemplateException e1) {
1857                         // TODO Auto-generated catch block
1858                         e1.printStackTrace();
1859                 }
1860                 return null;
1861         }
1862
1863         /**
1864          * @deprecated Use
1865          *             createInheritedMethods(IType,boolean,boolean,IImportsManager,IProgressMonitor)
1866          */
1867         // protected IMethod[] createInheritedMethods(IType type, boolean
1868         // doConstructors, boolean doUnimplementedMethods, IImportsStructure
1869         // imports, IProgressMonitor monitor) throws CoreException {
1870         // return createInheritedMethods(type, doConstructors,
1871         // doUnimplementedMethods, new ImportsManager(imports), monitor);
1872         // }
1873         /**
1874          * Creates the bodies of all unimplemented methods and constructors and adds
1875          * them to the type. Method is typically called by implementers of
1876          * <code>NewTypeWizardPage</code> to add needed method and constructors.
1877          * 
1878          * @param type
1879          *            the type for which the new methods and constructor are to be
1880          *            created
1881          * @param doConstructors
1882          *            if <code>true</code> unimplemented constructors are created
1883          * @param doUnimplementedMethods
1884          *            if <code>true</code> unimplemented methods are created
1885          * @param imports
1886          *            an import manager to add all neded import statements
1887          * @param monitor
1888          *            a progress monitor to report progress
1889          */
1890         // protected IMethod[] createInheritedMethods(IType type, boolean
1891         // doConstructors, boolean doUnimplementedMethods, ImportsManager imports,
1892         // IProgressMonitor monitor) throws CoreException {
1893         // ArrayList newMethods= new ArrayList();
1894         // ITypeHierarchy hierarchy= null;
1895         // CodeGenerationSettings settings=
1896         // JavaPreferencesSettings.getCodeGenerationSettings();
1897         //
1898         // if (doConstructors) {
1899         // hierarchy= type.newSupertypeHierarchy(monitor);
1900         // IType superclass= hierarchy.getSuperclass(type);
1901         // if (superclass != null) {
1902         // String[] constructors= StubUtility.evalConstructors(type, superclass,
1903         // settings, imports.getImportsStructure());
1904         // if (constructors != null) {
1905         // for (int i= 0; i < constructors.length; i++) {
1906         // newMethods.add(constructors[i]);
1907         // }
1908         // }
1909         //                      
1910         // }
1911         // }
1912         // if (doUnimplementedMethods) {
1913         // if (hierarchy == null) {
1914         // hierarchy= type.newSupertypeHierarchy(monitor);
1915         // }
1916         // String[] unimplemented= StubUtility.evalUnimplementedMethods(type,
1917         // hierarchy, false, settings, null, imports.getImportsStructure());
1918         // if (unimplemented != null) {
1919         // for (int i= 0; i < unimplemented.length; i++) {
1920         // newMethods.add(unimplemented[i]);
1921         // }
1922         // }
1923         // }
1924         // IMethod[] createdMethods= new IMethod[newMethods.size()];
1925         // for (int i= 0; i < newMethods.size(); i++) {
1926         // String content= (String) newMethods.get(i) + '\n'; // content will be
1927         // formatted, ok to use \n
1928         // createdMethods[i]= type.createMethod(content, null, false, null);
1929         // }
1930         // return createdMethods;
1931         // }
1932         // ---- creation ----------------
1933         /**
1934          * Returns the runnable that creates the type using the current settings.
1935          * The returned runnable must be executed in the UI thread.
1936          * 
1937          * @return the runnable to create the new type
1938          */
1939         // public IRunnableWithProgress getRunnable() {
1940         // return new IRunnableWithProgress() {
1941         // public void run(IProgressMonitor monitor) throws
1942         // InvocationTargetException, InterruptedException {
1943         // try {
1944         // if (monitor == null) {
1945         // monitor= new NullProgressMonitor();
1946         // }
1947         // createType(monitor);
1948         // } catch (CoreException e) {
1949         // throw new InvocationTargetException(e);
1950         // }
1951         // }
1952         // };
1953         // }
1954 }