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