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