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