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