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