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