Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e098a1093b67a1e166d93a43ed8f42a751073e00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*******************************************************************************
 * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik  
 * Rapperswil, University of applied sciences and others
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/epl-v10.html  
 *  
 * Contributors: 
 * Institute for Software - initial API and implementation
 * IBM Corporation
 *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;

import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;


public class ExtractFunctionInputPage extends UserInputWizardPage {

	private final ExtractFunctionInformation info;
	private ExtractFunctionComposite comp;
	protected final String NO_NAME_ERROR_LABEL = Messages.ExtractFunctionInputPage_EnterName; 


	public ExtractFunctionInputPage(String name, ExtractFunctionInformation info) {
		super(name);
		this.info = info;
	}

	public void createControl(final Composite parent) {

		comp = new ExtractFunctionComposite(parent, info, this);
		
		setPageComplete(false);
		
		comp.getMethodNameText().addKeyListener(new KeyListener(){

			public void keyPressed(KeyEvent e) {}

			public void keyReleased(KeyEvent e) {
				info.setMethodName(comp.getMethodName());	
				checkName();
			}
			
		});
		
		
		for (Control buttons : comp.getVisibiltyGroup().getChildren()) {
			buttons.addMouseListener(new MouseListener() {
	
				public void mouseDoubleClick(MouseEvent e) {}
	
				public void mouseDown(MouseEvent e) {}
	
				public void mouseUp(MouseEvent e) {
					String text = ((Button)e.getSource()).getText();
					visibilityChange(text);
				}				
			});
		}
		
		/* Disable until it works again.
		 * 
		 * comp.getReplaceSimilarButton().addSelectionListener(new SelectionListener(){

			public void widgetDefaultSelected(SelectionEvent e) {
				info.setReplaceDuplicates(comp.getReplaceSimilarButton().isEnabled());	
			}

			public void widgetSelected(SelectionEvent e) {
				widgetDefaultSelected(e);		
			}
			
		});*/
		
		setControl(comp);
		
	}

	protected void visibilityChange(String text) {
		info.setVisibility(VisibilityEnum.getEnumForStringRepresentation(text));
		
	}

	private void checkName() {

		String methodName = comp.getMethodName();
		IdentifierResult result = IdentifierHelper.checkIdentifierName(methodName);
		if(result.isCorrect()){
			setErrorMessage(null);
			setPageComplete(true);
		}
		else{
			setErrorMessage(Messages.ExtractFunctionInputPage_CheckFunctionName + " " + result.getMessage());  //$NON-NLS-1$
			setPageComplete(false);
		}
	}
	
	public void errorWithAfterUsedVariable(String variableUsedAfterBlock ) {
		if(variableUsedAfterBlock == null) {
			setErrorMessage(null);
			checkName();	
		}else {
			setErrorMessage("The parameter '" + variableUsedAfterBlock + "' " + Messages.ExtractFunctionInputPage_1);  //$NON-NLS-1$ //$NON-NLS-2$
		}
	}
}

Back to the top