1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.refactoring.code;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.SelectionAdapter;
15 import org.eclipse.swt.events.SelectionEvent;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.jface.dialogs.Dialog;
23 import org.eclipse.jface.preference.IPreferenceStore;
25 import org.eclipse.jface.text.Document;
26 import org.eclipse.jface.text.DocumentEvent;
27 import org.eclipse.jface.text.IDocumentListener;
29 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
30 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
32 import org.eclipse.jdt.core.JavaModelException;
34 import org.eclipse.jdt.internal.corext.refactoring.code.ReplaceInvocationsRefactoring;
36 import org.eclipse.jdt.ui.JavaElementLabels;
38 import org.eclipse.jdt.internal.ui.JavaPlugin;
39 import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer;
40 import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
43 public class ReplaceInvocationsInputPage extends UserInputWizardPage {
45 public static final String PAGE_NAME= "ReplaceInvocationsInputPage";//$NON-NLS-1$
47 public ReplaceInvocationsRefactoring fRefactoring;
49 public static final long LABEL_FLAGS= JavaElementLabels.M_PRE_TYPE_PARAMETERS | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_EXCEPTIONS;
51 public ReplaceInvocationsInputPage() {
55 public void createControl(Composite parent) {
56 initializeDialogUnits(parent);
57 fRefactoring= (ReplaceInvocationsRefactoring) getRefactoring();
59 Composite result= new Composite(parent, SWT.NONE);
61 GridLayout layout= new GridLayout();
62 result.setLayout(layout);
64 createMethodSignature(result);
66 Label separator= new Label(parent, SWT.NONE);
67 GridData gridData= new GridData(SWT.FILL, SWT.FILL, false, false);
68 gridData.heightHint= 5;
69 separator.setLayoutData(gridData);
71 Label bodyLabel= new Label(result, SWT.NONE);
72 bodyLabel.setText(RefactoringMessages.ReplaceInvocationsInputPage_replaceInvocationsBy);
76 Button replaceAll= new Button(result, SWT.CHECK);
77 replaceAll.setText(RefactoringMessages.ReplaceInvocationsInputPage_replaceAll);
78 boolean canSingle= fRefactoring.canReplaceSingle();
79 // replaceAll.setEnabled(canSingle);
80 replaceAll.setEnabled(false); // does not work for now...
81 replaceAll.setSelection(! canSingle);
82 replaceAll.addSelectionListener(new SelectionAdapter() {
84 public void widgetSelected(SelectionEvent event) {
85 boolean all= ((Button) event.widget).getSelection();
86 changeMode(all ? ReplaceInvocationsRefactoring.Mode.REPLACE_ALL : ReplaceInvocationsRefactoring.Mode.REPLACE_SINGLE);
90 Dialog.applyDialogFont(result);
93 private void createMethodSignature(Composite parent) {
94 IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore();
95 JavaSourceViewer signatureViewer= new JavaSourceViewer(parent, null, null, false, SWT.READ_ONLY | SWT.WRAP /*| SWT.BORDER*/, store);
96 signatureViewer.generated_3272343075298364199(parent, store, this);
99 private void createBody(Composite parent) {
100 IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore();
101 JavaSourceViewer bodyEditor= new JavaSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.WRAP | SWT.BORDER, store);
102 Document bodyDocument= bodyEditor.generated_2060298929755158601(store, this);
104 bodyDocument.addDocumentListener(new IDocumentListener() {
105 public void documentAboutToBeChanged(DocumentEvent event) {
107 public void documentChanged(DocumentEvent event) {
109 fRefactoring.setBody(event.getDocument().get(), fRefactoring.getMethod().getParameterNames());
110 } catch (JavaModelException ex) {
111 // TODO Auto-generated catch block
118 public String getInitialBody() {
120 return ""; //$NON-NLS-1$
124 private void changeMode(ReplaceInvocationsRefactoring.Mode mode) {
125 RefactoringStatus status;
127 status= fRefactoring.setCurrentMode(mode);
128 } catch (JavaModelException e) {
129 status= RefactoringStatus.createFatalErrorStatus(e.getMessage());
131 setPageComplete(status);