|
Lines 17-24
Link Here
|
| 17 |
import org.eclipse.core.runtime.CoreException; |
17 |
import org.eclipse.core.runtime.CoreException; |
| 18 |
import org.eclipse.core.runtime.IStatus; |
18 |
import org.eclipse.core.runtime.IStatus; |
| 19 |
|
19 |
|
|
|
20 |
import org.eclipse.swt.SWT; |
| 21 |
import org.eclipse.swt.events.SelectionAdapter; |
| 22 |
import org.eclipse.swt.events.SelectionEvent; |
| 23 |
import org.eclipse.swt.layout.GridData; |
| 20 |
import org.eclipse.swt.layout.GridLayout; |
24 |
import org.eclipse.swt.layout.GridLayout; |
|
|
25 |
import org.eclipse.swt.widgets.Combo; |
| 21 |
import org.eclipse.swt.widgets.Composite; |
26 |
import org.eclipse.swt.widgets.Composite; |
|
|
27 |
import org.eclipse.swt.widgets.Label; |
| 22 |
import org.eclipse.swt.widgets.Shell; |
28 |
import org.eclipse.swt.widgets.Shell; |
| 23 |
|
29 |
|
| 24 |
import org.eclipse.jface.dialogs.IDialogConstants; |
30 |
import org.eclipse.jface.dialogs.IDialogConstants; |
|
Lines 49-54
Link Here
|
| 49 |
|
55 |
|
| 50 |
import org.eclipse.jdt.internal.corext.codemanipulation.AddCustomConstructorOperation; |
56 |
import org.eclipse.jdt.internal.corext.codemanipulation.AddCustomConstructorOperation; |
| 51 |
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings; |
57 |
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings; |
|
|
58 |
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility; |
| 52 |
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; |
59 |
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; |
| 53 |
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; |
60 |
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; |
| 54 |
import org.eclipse.jdt.internal.ui.JavaPlugin; |
61 |
import org.eclipse.jdt.internal.ui.JavaPlugin; |
|
Lines 64-69
Link Here
|
| 64 |
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext; |
71 |
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext; |
| 65 |
import org.eclipse.jdt.internal.ui.util.ElementValidator; |
72 |
import org.eclipse.jdt.internal.ui.util.ElementValidator; |
| 66 |
import org.eclipse.jdt.internal.ui.util.ExceptionHandler; |
73 |
import org.eclipse.jdt.internal.ui.util.ExceptionHandler; |
|
|
74 |
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabels; |
| 67 |
|
75 |
|
| 68 |
|
76 |
|
| 69 |
public class CreateNewConstructorAction extends SelectionDispatchAction { |
77 |
public class CreateNewConstructorAction extends SelectionDispatchAction { |
|
Lines 134-140
Link Here
|
| 134 |
try { |
142 |
try { |
| 135 |
IField[] selectedFields= getSelectedFields(selection); |
143 |
IField[] selectedFields= getSelectedFields(selection); |
| 136 |
// open an editor and work on a working copy |
144 |
// open an editor and work on a working copy |
| 137 |
IEditorPart editor= EditorUtility.openInEditor(getSelectedType(selection)); |
145 |
IEditorPart editor= null; |
|
|
146 |
if (selectedFields != null) |
| 147 |
editor= EditorUtility.openInEditor(selectedFields[0]); |
| 148 |
else |
| 149 |
editor= EditorUtility.openInEditor(getSelectedType(selection).getCompilationUnit()); |
| 138 |
|
150 |
|
| 139 |
if (canRunOn(selectedFields)){ |
151 |
if (canRunOn(selectedFields)){ |
| 140 |
run((IType)EditorUtility.getWorkingCopy(selectedFields[0].getDeclaringType()), selectedFields, editor, false); |
152 |
run((IType)EditorUtility.getWorkingCopy(selectedFields[0].getDeclaringType()), selectedFields, editor, false); |
|
Lines 318-325
Link Here
|
| 318 |
settings.createComments= dialog.getGenerateComment(); |
330 |
settings.createComments= dialog.getGenerateComment(); |
| 319 |
|
331 |
|
| 320 |
IJavaElement elementPosition= dialog.getElementPosition(); |
332 |
IJavaElement elementPosition= dialog.getElementPosition(); |
| 321 |
AddCustomConstructorOperation op= new AddCustomConstructorOperation(type, settings, selected, false, elementPosition); |
333 |
int superIndex= dialog.getSuperIndex(); |
| 322 |
|
334 |
AddCustomConstructorOperation op= new AddCustomConstructorOperation(type, settings, selected, false, elementPosition, superIndex); |
|
|
335 |
|
| 323 |
IRewriteTarget target= editor != null ? (IRewriteTarget) editor.getAdapter(IRewriteTarget.class) : null; |
336 |
IRewriteTarget target= editor != null ? (IRewriteTarget) editor.getAdapter(IRewriteTarget.class) : null; |
| 324 |
if (target != null) { |
337 |
if (target != null) { |
| 325 |
target.beginCompoundChange(); |
338 |
target.beginCompoundChange(); |
|
Lines 488-499
Link Here
|
| 488 |
|
501 |
|
| 489 |
private static class CreateNewConstructorSelectionDialog extends SourceActionDialog { |
502 |
private static class CreateNewConstructorSelectionDialog extends SourceActionDialog { |
| 490 |
private CreateNewConstructorContentProvider fContentProvider; |
503 |
private CreateNewConstructorContentProvider fContentProvider; |
|
|
504 |
private IType fType; |
| 505 |
private int fSuperIndex; |
| 506 |
|
| 491 |
private static final int UP_BUTTON= IDialogConstants.CLIENT_ID + 1; |
507 |
private static final int UP_BUTTON= IDialogConstants.CLIENT_ID + 1; |
| 492 |
private static final int DOWN_BUTTON= IDialogConstants.CLIENT_ID + 2; |
508 |
private static final int DOWN_BUTTON= IDialogConstants.CLIENT_ID + 2; |
| 493 |
|
509 |
|
| 494 |
public CreateNewConstructorSelectionDialog(Shell parent, ILabelProvider labelProvider, CreateNewConstructorContentProvider contentProvider, CompilationUnitEditor editor, IType type) { |
510 |
public CreateNewConstructorSelectionDialog(Shell parent, ILabelProvider labelProvider, CreateNewConstructorContentProvider contentProvider, CompilationUnitEditor editor, IType type) { |
| 495 |
super(parent, labelProvider, contentProvider, editor, type); |
511 |
super(parent, labelProvider, contentProvider, editor, type); |
| 496 |
fContentProvider= contentProvider; |
512 |
fContentProvider= contentProvider; |
|
|
513 |
fType= type; |
| 497 |
} |
514 |
} |
| 498 |
|
515 |
|
| 499 |
protected Composite createSelectionButtons(Composite composite) { |
516 |
protected Composite createSelectionButtons(Composite composite) { |
|
Lines 533-545
Link Here
|
| 533 |
} |
550 |
} |
| 534 |
|
551 |
|
| 535 |
private List getElementList() { |
552 |
private List getElementList() { |
| 536 |
Object elements[]= getTreeViewer().getCheckedElements(); |
553 |
IStructuredSelection selection= (IStructuredSelection) getTreeViewer().getSelection(); |
|
|
554 |
List elements= selection.toList(); |
| 537 |
ArrayList elementList= new ArrayList(); |
555 |
ArrayList elementList= new ArrayList(); |
| 538 |
for(int i = 0; i < elements.length; i++) |
556 |
|
| 539 |
elementList.add(elements[i]); |
557 |
for (int i= 0; i < elements.size(); i++) { |
|
|
558 |
elementList.add(elements.get(i)); |
| 559 |
} |
| 540 |
return elementList; |
560 |
return elementList; |
| 541 |
} |
561 |
} |
|
|
562 |
|
| 563 |
protected Composite createEntryPtCombo(Composite composite) { |
| 564 |
Composite entryComposite= super.createEntryPtCombo(composite); |
| 565 |
addSuperClassConstructorChoices(entryComposite); |
| 566 |
|
| 567 |
return entryComposite; |
| 568 |
} |
| 569 |
|
| 570 |
private Composite addSuperClassConstructorChoices(Composite composite) { |
| 571 |
try { |
| 572 |
Label label= new Label(composite, SWT.NONE); |
| 573 |
label.setText(ActionMessages.getString("CreateNewConstructorSelectionDialog.sort_constructor_choices.label")); //$NON-NLS-1$ |
| 574 |
GridData gd= new GridData(GridData.FILL_BOTH); |
| 575 |
label.setLayoutData(gd); |
| 542 |
|
576 |
|
|
|
577 |
final Combo combo= new Combo(composite, SWT.READ_ONLY); |
| 578 |
IMethod[] constructorMethods= StubUtility.getOverridableConstructors(fType); |
| 579 |
|
| 580 |
for (int i= 0; i < constructorMethods.length; i++) { |
| 581 |
combo.add(JavaElementLabels.getElementLabel(constructorMethods[i], JavaElementLabels.M_PARAMETER_TYPES)); |
| 582 |
} |
| 583 |
// TODO: Can we be a little more intelligent about guessing the super() ? |
| 584 |
combo.setText(combo.getItem(0)); |
| 585 |
combo.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 586 |
combo.addSelectionListener(new SelectionAdapter(){ |
| 587 |
public void widgetSelected(SelectionEvent e) { |
| 588 |
fSuperIndex= combo.getSelectionIndex(); |
| 589 |
} |
| 590 |
}); |
| 591 |
|
| 592 |
} catch (CoreException e) { |
| 593 |
} |
| 594 |
return composite; |
| 595 |
} |
| 596 |
|
| 597 |
public int getSuperIndex() { |
| 598 |
return fSuperIndex; |
| 599 |
} |
| 600 |
|
| 543 |
} |
601 |
} |
| 544 |
|
602 |
|
| 545 |
} |
603 |
} |