]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/code/ReplaceInvocationsInputPage.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui refactoring / org / eclipse / jdt / internal / ui / refactoring / code / ReplaceInvocationsInputPage.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.refactoring.code;
12
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;
21
22 import org.eclipse.jface.dialogs.Dialog;
23 import org.eclipse.jface.preference.IPreferenceStore;
24
25 import org.eclipse.jface.text.Document;
26 import org.eclipse.jface.text.DocumentEvent;
27 import org.eclipse.jface.text.IDocumentListener;
28
29 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
30 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
31
32 import org.eclipse.jdt.core.JavaModelException;
33
34 import org.eclipse.jdt.internal.corext.refactoring.code.ReplaceInvocationsRefactoring;
35
36 import org.eclipse.jdt.ui.JavaElementLabels;
37
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;
41
42
43 public class ReplaceInvocationsInputPage extends UserInputWizardPage {
44
45         public static final String PAGE_NAME= "ReplaceInvocationsInputPage";//$NON-NLS-1$
46
47         public ReplaceInvocationsRefactoring fRefactoring;
48
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;
50
51         public ReplaceInvocationsInputPage() {
52                 super(PAGE_NAME);
53         }
54
55         public void createControl(Composite parent) {
56                 initializeDialogUnits(parent);
57                 fRefactoring= (ReplaceInvocationsRefactoring) getRefactoring();
58
59                 Composite result= new Composite(parent, SWT.NONE);
60                 setControl(result);
61                 GridLayout layout= new GridLayout();
62                 result.setLayout(layout);
63
64                 createMethodSignature(result);
65
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);
70
71                 Label bodyLabel= new Label(result, SWT.NONE);
72                 bodyLabel.setText(RefactoringMessages.ReplaceInvocationsInputPage_replaceInvocationsBy);
73
74                 createBody(result);
75
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() {
83                         @Override
84                         public void widgetSelected(SelectionEvent event) {
85                                 boolean all= ((Button) event.widget).getSelection();
86                                 changeMode(all ? ReplaceInvocationsRefactoring.Mode.REPLACE_ALL : ReplaceInvocationsRefactoring.Mode.REPLACE_SINGLE);
87                         }
88                 });
89
90                 Dialog.applyDialogFont(result);
91         }
92
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);
97         }
98
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);
103
104                 bodyDocument.addDocumentListener(new IDocumentListener() {
105                         public void documentAboutToBeChanged(DocumentEvent event) {
106                         }
107                         public void documentChanged(DocumentEvent event) {
108                                 try {
109                                         fRefactoring.setBody(event.getDocument().get(), fRefactoring.getMethod().getParameterNames());
110                                 } catch (JavaModelException ex) {
111                                         // TODO Auto-generated catch block
112                                         JavaPlugin.log(ex);
113                                 }
114                         }
115                 });
116         }
117
118         public String getInitialBody() {
119                 //TODO
120                 return ""; //$NON-NLS-1$
121
122         }
123
124         private void changeMode(ReplaceInvocationsRefactoring.Mode mode) {
125                 RefactoringStatus status;
126                 try {
127                         status= fRefactoring.setCurrentMode(mode);
128                 } catch (JavaModelException e) {
129                         status= RefactoringStatus.createFatalErrorStatus(e.getMessage());
130                 }
131                 setPageComplete(status);
132         }
133 }