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