[jbosstools-commits] JBoss Tools SVN: r23500 - in trunk: common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver and 5 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Jul 16 11:04:32 EDT 2010


Author: dazarov
Date: 2010-07-16 11:04:31 -0400 (Fri, 16 Jul 2010)
New Revision: 23500

Added:
   trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/RenameMessagePropertyWizard.java
   trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyProcessor.java
   trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyRefactoring.java
Removed:
   trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameELVariableRefactoring.java
Modified:
   trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ElCoreMessages.java
   trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/messages.properties
   trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java
   trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/JsfUIMessages.java
   trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/ELRefactorContributionFactory.java
   trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/messages.properties
   trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java
   trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java
Log:
https://jira.jboss.org/browse/JBIDE-4858

Modified: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ElCoreMessages.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ElCoreMessages.java	2010-07-16 13:46:47 UTC (rev 23499)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ElCoreMessages.java	2010-07-16 15:04:31 UTC (rev 23500)
@@ -27,6 +27,7 @@
 	public static String EL_RENAME_PROCESSOR_ERROR_PHANTOM_FILE;
 	public static String EL_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE;
 	public static String RENAME_EL_VARIABLE_PROCESSOR_TITLE;
+	public static String RENAME_MESSAGE_PROPERTY_PROCESSOR_TITLE;
 	public static String RENAME_EL_VARIABLE_PROCESSOR_CAN_NOT_FIND_EL_VARIABLE;
 	
 	static {

Modified: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/messages.properties
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/messages.properties	2010-07-16 13:46:47 UTC (rev 23499)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/messages.properties	2010-07-16 15:04:31 UTC (rev 23500)
@@ -20,5 +20,6 @@
 EL_RENAME_PROCESSOR_ERROR_PHANTOM_FILE=Cannot change phantom file: ''{0}''.
 EL_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE=Cannot change read-only file: ''{0}''.
 RENAME_EL_VARIABLE_PROCESSOR_TITLE=Rename EL Variable
+RENAME_MESSAGE_PROPERTY_PROCESSOR_TITLE=Rename Resource Bundle Message
 RENAME_EL_VARIABLE_PROCESSOR_CAN_NOT_FIND_EL_VARIABLE=Can not find EL Variable: ''{0}''.
 

Modified: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java	2010-07-16 13:46:47 UTC (rev 23499)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java	2010-07-16 15:04:31 UTC (rev 23500)
@@ -77,7 +77,7 @@
 	public List<ELSegment> findSegmentsByMessageProperty(String baseName, String propertyName) {
 		ArrayList<ELSegment> list = new ArrayList<ELSegment>();
 		for(ELSegment segment : segments){
-			if(segment instanceof MessagePropertyELSegment){
+			if(segment instanceof MessagePropertyELSegment && ((MessagePropertyELSegment)segment).getBaseName() != null){
 				if(((MessagePropertyELSegment)segment).getBaseName().equals(baseName) && segment.getToken().getText().equals(propertyName))
 					 list.add(segment);
 			}

Deleted: trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameELVariableRefactoring.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameELVariableRefactoring.java	2010-07-16 13:46:47 UTC (rev 23499)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameELVariableRefactoring.java	2010-07-16 15:04:31 UTC (rev 23500)
@@ -1,24 +0,0 @@
- /*******************************************************************************
-  * Copyright (c) 2008 Red Hat, Inc.
-  * Distributed under license by Red Hat, Inc. All rights reserved.
-  * This program is 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:
-  *     Red Hat, Inc. - initial API and implementation
-  ******************************************************************************/
-package org.jboss.tools.jsf.el.refactoring;
-
-import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
-import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring;
-
-/**
- * @author Alexey Kazakov
- */
-public class RenameELVariableRefactoring extends RenameRefactoring {
-
-	public RenameELVariableRefactoring(RenameProcessor processor) {
-		super(processor);
-	}
-}
\ No newline at end of file

Added: trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyProcessor.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyProcessor.java	                        (rev 0)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyProcessor.java	2010-07-16 15:04:31 UTC (rev 23500)
@@ -0,0 +1,199 @@
+ /*******************************************************************************
+  * Copyright (c) 2009 Red Hat, Inc.
+  * Distributed under license by Red Hat, Inc. All rights reserved.
+  * This program is 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:
+  *     Red Hat, Inc. - initial API and implementation
+  ******************************************************************************/
+package org.jboss.tools.jsf.el.refactoring;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
+import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
+import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.text.edits.TextEdit;
+import org.jboss.tools.common.el.core.ELReference;
+import org.jboss.tools.common.el.core.ElCoreMessages;
+import org.jboss.tools.common.el.core.model.ELExpression;
+import org.jboss.tools.common.el.core.resolver.ELCompletionEngine;
+import org.jboss.tools.common.el.core.resolver.ELContext;
+import org.jboss.tools.common.el.core.resolver.ELResolution;
+import org.jboss.tools.common.el.core.resolver.ELResolver;
+import org.jboss.tools.common.el.core.resolver.ELSegment;
+import org.jboss.tools.common.el.core.resolver.MessagePropertyELSegment;
+import org.jboss.tools.jst.web.kb.PageContextFactory;
+import org.jboss.tools.jst.web.kb.refactoring.RefactorSearcher;
+
+/**
+ * @author Daniel Azarov
+ */
+public class RenameMessagePropertyProcessor extends ELRenameProcessor {
+	IFile file;
+	MessagePropertyELSegment segment;
+	MessagePropertySearcher searcher;
+	
+	/**
+	 * @param file where refactor was called
+	 */
+	public RenameMessagePropertyProcessor(IFile file, MessagePropertyELSegment segment) {
+		super(file, segment.getToken().getText());
+		this.file = file;
+		this.segment = segment;
+		setOldName(segment.getToken().getText());
+		searcher = new MessagePropertySearcher(file, segment.getToken().getText());
+	}
+	
+	protected RefactorSearcher getSearcher(){
+		return searcher;
+	}
+
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
+	 */
+	@Override
+	public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
+			CheckConditionsContext context) throws CoreException,
+			OperationCanceledException {
+		status = new RefactoringStatus();
+		
+		rootChange = new CompositeChange(ElCoreMessages.RENAME_MESSAGE_PROPERTY_PROCESSOR_TITLE);
+		
+		renameELVariable(pm, file);
+		
+		return status;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	@Override
+	public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
+			throws CoreException, OperationCanceledException {
+		RefactoringStatus result = new RefactoringStatus();
+		
+		//if(findManagedBean(file, getOldName()) == null)
+			//result.addFatalError(Messages.format(ElCoreMessages.RENAME_EL_VARIABLE_PROCESSOR_CAN_NOT_FIND_EL_VARIABLE, getOldName()));
+		return result;
+	}
+	
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	@Override
+	public Change createChange(IProgressMonitor pm) throws CoreException,
+			OperationCanceledException {
+		
+		return rootChange;
+	}
+	
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getElements()
+	 */
+	@Override
+	public Object[] getElements() {
+		return new String[]{getNewName()};
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getIdentifier()
+	 */
+	@Override
+	public String getIdentifier() {
+		return getClass().getName();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getProcessorName()
+	 */
+	@Override
+	public String getProcessorName() {
+		return ElCoreMessages.RENAME_MESSAGE_PROPERTY_PROCESSOR_TITLE;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#isApplicable()
+	 */
+	@Override
+	public boolean isApplicable() throws CoreException {
+		return getNewName()!=null;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#loadParticipants(org.eclipse.ltk.core.refactoring.RefactoringStatus, org.eclipse.ltk.core.refactoring.participants.SharableParticipants)
+	 */
+	@Override
+	public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
+			SharableParticipants sharedParticipants) throws CoreException {
+		return EMPTY_REF_PARTICIPANT;
+	}
+	
+	private void renameELVariable(IProgressMonitor pm, IFile file){
+		TextFileChange change = getChange((IFile)segment.getMessageBundleResource());
+		TextEdit edit = new ReplaceEdit(segment.getMessagePropertySourceReference().getStartPosition(), segment.getMessagePropertySourceReference().getLength(), getNewName());
+		change.addEdit(edit);
+		getSearcher().findELReferences();
+	}
+	
+	class MessagePropertySearcher extends ELSearcher{
+
+		public MessagePropertySearcher(IFile file, String oldName) {
+			super(file, oldName);
+		}
+		
+		protected void searchInCach(IFile file){
+			ELContext context = PageContextFactory.createPageContext(file);
+			
+			if(context == null)
+				return;
+			
+			ELReference[] references = context.getELReferences();
+			ELResolver[] resolvers = context.getElResolvers();
+			
+			for(ELReference reference : references){
+				int offset = reference.getStartPosition();
+				for(ELExpression operand : reference.getEl()){
+					for (ELResolver resolver : resolvers) {
+						if (!(resolver instanceof ELCompletionEngine))
+							continue;
+						
+						ELResolution resolution = resolver.resolve(context, operand, offset);
+						
+						if(resolution == null)
+							continue;
+	
+						List<ELSegment> segments = resolution.findSegmentsByMessageProperty(segment.getBaseName(), propertyName);
+						
+						for(ELSegment segment : segments){
+							match(file, offset+segment.getSourceReference().getStartPosition(), segment.getSourceReference().getLength());
+						}
+					}
+				}
+			}
+			
+		}
+		
+	}
+	
+}
\ No newline at end of file


Property changes on: trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyProcessor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyRefactoring.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyRefactoring.java	                        (rev 0)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyRefactoring.java	2010-07-16 15:04:31 UTC (rev 23500)
@@ -0,0 +1,24 @@
+ /*******************************************************************************
+  * Copyright (c) 2008 Red Hat, Inc.
+  * Distributed under license by Red Hat, Inc. All rights reserved.
+  * This program is 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:
+  *     Red Hat, Inc. - initial API and implementation
+  ******************************************************************************/
+package org.jboss.tools.jsf.el.refactoring;
+
+import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
+import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class RenameMessagePropertyRefactoring extends RenameRefactoring {
+
+	public RenameMessagePropertyRefactoring(RenameProcessor processor) {
+		super(processor);
+	}
+}
\ No newline at end of file


Property changes on: trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyRefactoring.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java	2010-07-16 13:46:47 UTC (rev 23499)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java	2010-07-16 15:04:31 UTC (rev 23500)
@@ -455,6 +455,8 @@
 	}
 	
 	private void processMessagePropertySegment(ELInvocationExpression expr, MessagePropertyELSegmentImpl segment, List<Variable> variables){
+		if(segment.getToken() == null)
+			return;
 		for(Variable variable : variables){
 			if(expr.getFirstToken().getText().equals(variable.name)){
 				
@@ -471,7 +473,7 @@
 				if(propFile == null)
 					return;
 				segment.setMessageBundleResource(propFile);
-				XModelObject property = properties.getChildByPath(expr.getText());
+				XModelObject property = properties.getChildByPath(segment.getToken().getText());
 				if(property != null){
 					try {
 						String content = FileUtil.readStream(propFile);
@@ -491,9 +493,7 @@
 		String nvs = property.getAttributeValue("name-value-separator"); //$NON-NLS-1$
 		int i = content.indexOf(name + nvs);
 		if(i < 0) return false;
-		int j = content.indexOf('\n', i);
-		if(j < 0) j = content.length();
-		segment.setMessagePropertySourceReference(i, j - i);
+		segment.setMessagePropertySourceReference(i, name.length());
 		return true;
 	}
 	

Modified: trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/JsfUIMessages.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/JsfUIMessages.java	2010-07-16 13:46:47 UTC (rev 23499)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/JsfUIMessages.java	2010-07-16 15:04:31 UTC (rev 23500)
@@ -27,8 +27,10 @@
 	
 	public static String REFACTOR_CONTRIBUTOR_MAIN_MENU;
 	public static String REFACTOR_CONTRIBUTOR_RENAME_EL_VARIABLE;
+	public static String REFACTOR_CONTRIBUTOR_RENAME_MESSAGE_PROPERTY;
 	public static String EL_REFACTOR_RENAME_HANDLER_ERROR;
 	public static String RENAME_EL_VARIABLE_WIZARD_EL_VARIABLE_NAME;
+	public static String RENAME_MESSAGE_PROPERTY_WIZARD_PROPERTY_NAME;
 	
 	public static String IS_JSF_CHECK_NEED;
 	public static String IS_KB_NATURE_CHECK_NEED;

Modified: trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/ELRefactorContributionFactory.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/ELRefactorContributionFactory.java	2010-07-16 13:46:47 UTC (rev 23499)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/ELRefactorContributionFactory.java	2010-07-16 15:04:31 UTC (rev 23500)
@@ -11,6 +11,7 @@
 package org.jboss.tools.jsf.ui.el.refactoring;
 
 import java.io.IOException;
+import java.util.List;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.ResourcesPlugin;
@@ -29,6 +30,7 @@
 import org.eclipse.jface.text.rules.Token;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring;
 import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IEditorPart;
@@ -47,19 +49,30 @@
 import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
 import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
 import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+import org.jboss.tools.common.el.core.ELReference;
+import org.jboss.tools.common.el.core.model.ELExpression;
 import org.jboss.tools.common.el.core.model.ELInstance;
 import org.jboss.tools.common.el.core.model.ELInvocationExpression;
 import org.jboss.tools.common.el.core.model.ELModel;
 import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
 import org.jboss.tools.common.el.core.parser.ELParser;
 import org.jboss.tools.common.el.core.parser.ELParserUtil;
+import org.jboss.tools.common.el.core.resolver.ELCompletionEngine;
+import org.jboss.tools.common.el.core.resolver.ELContext;
+import org.jboss.tools.common.el.core.resolver.ELResolution;
+import org.jboss.tools.common.el.core.resolver.ELResolver;
+import org.jboss.tools.common.el.core.resolver.ELSegment;
+import org.jboss.tools.common.el.core.resolver.ELSegmentImpl;
+import org.jboss.tools.common.el.core.resolver.JavaMemberELSegmentImpl;
+import org.jboss.tools.common.el.core.resolver.MessagePropertyELSegment;
 import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
 import org.jboss.tools.common.propertieseditor.PropertiesCompoundEditor;
 import org.jboss.tools.common.util.FileUtil;
 import org.jboss.tools.jsf.el.refactoring.RenameELVariableProcessor;
-import org.jboss.tools.jsf.el.refactoring.RenameELVariableRefactoring;
+import org.jboss.tools.jsf.el.refactoring.RenameMessagePropertyProcessor;
 import org.jboss.tools.jsf.ui.JsfUIMessages;
 import org.jboss.tools.jsf.ui.JsfUiPlugin;
+import org.jboss.tools.jst.web.kb.PageContextFactory;
 import org.jboss.tools.jst.web.ui.editors.WebCompoundEditor;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -158,16 +171,69 @@
 					status = checkContextVariableInDOM(editorFile, fileContent, selection);
 				else if(PROPERTIES_EXT.equalsIgnoreCase(ext))
 					status = checkContextVariableInProperties(editorFile, fileContent, selection);
+				
+				MessagePropertyELSegment messageSegment = checkMessageProperty(editorFile, selection);
+				if(messageSegment != null){
+					mm.add(new RenameMessagePropertyAction(messageSegment));
 
+					if(!separatorIsAdded){
+						additions.addContributionItem(new Separator(), null);
+						separatorIsAdded = true;
+					}
+				}
+
 				if(status){
 					mm.add(new RenameELVariableAction());
 
-					if(!separatorIsAdded)
+					if(!separatorIsAdded){
 						additions.addContributionItem(new Separator(), null);
+						separatorIsAdded = true;
+					}
+				}
+				if(mm.getSize() > 0)
 					additions.addContributionItem(mm, null);
+			}
+		}
+	}
+	
+	private MessagePropertyELSegment checkMessageProperty(IFile file, TextSelection selection){
+		ELContext context = PageContextFactory.createPageContext(file);
+		
+		if(context == null)
+			return null;
+		
+		ELReference[] references = context.getELReferences();
+		ELResolver[] resolvers = context.getElResolvers();
+		
+		for(ELReference reference : references){
+			for(ELExpression operand : reference.getEl()){
+				for (ELResolver resolver : resolvers) {
+					if (!(resolver instanceof ELCompletionEngine))
+						continue;
+					
+					ELResolution resolution = resolver.resolve(context, operand, selection.getOffset());
+					
+					if(resolution == null)
+						continue;
+					
+					List<ELSegment> segments = resolution.getSegments();
+					
+					for(ELSegment segment : segments){
+						if(!segment.isResolved())
+							continue;
+						
+						if(segment instanceof MessagePropertyELSegment &&
+								selection.getOffset() <= reference.getStartPosition()+segment.getSourceReference().getStartPosition() &&
+								selection.getOffset()+selection.getLength() >= reference.getStartPosition()+segment.getSourceReference().getStartPosition()+segment.getSourceReference().getLength()){
+							MessagePropertyELSegment messageSegment = (MessagePropertyELSegment)segment;
+							return messageSegment;
+						}
+					}
+
 				}
 			}
 		}
+		return null;
 	}
 	
 	private boolean checkContextVariableInJava(IFile file, String content, TextSelection selection){
@@ -302,18 +368,6 @@
 		return scanString(file, content, 0, selection);
 	}
 	
-	private String getPropertyName(IMethod method){
-		String name = method.getElementName();
-		
-		if(name.startsWith(GET) || name.startsWith(SET))
-			return name.substring(3).toLowerCase();
-		
-		if(name.startsWith(IS))
-			return name.substring(2).toLowerCase();
-		
-		return name.toLowerCase();
-	}
-	
 	private static void saveAndBuild(){
 		if(!JsfUiPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().saveAllEditors(true))
 			return;
@@ -329,7 +383,7 @@
 		saveAndBuild();
 		
 		RenameELVariableProcessor processor = new RenameELVariableProcessor(editorFile, selectedText);
-		RenameELVariableRefactoring refactoring = new RenameELVariableRefactoring(processor);
+		RenameRefactoring refactoring = new RenameRefactoring(processor);
 		RenameELVariableWizard wizard = new RenameELVariableWizard(refactoring, editorFile);
 		RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
 		try {
@@ -339,6 +393,21 @@
 			// operation was canceled
 		}
 	}
+
+	public static void invokeRenameMessagePropertyWizard(MessagePropertyELSegment segment, Shell activeShell) {
+		saveAndBuild();
+		
+		RenameMessagePropertyProcessor processor = new RenameMessagePropertyProcessor(editorFile, segment);
+		RenameRefactoring refactoring = new RenameRefactoring(processor);
+		RenameMessagePropertyWizard wizard = new RenameMessagePropertyWizard(refactoring, editorFile);
+		RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
+		try {
+			String titleForFailedChecks = JsfUIMessages.EL_REFACTOR_RENAME_HANDLER_ERROR;
+			op.run(activeShell, titleForFailedChecks);
+		} catch (final InterruptedException irex) {
+			// operation was canceled
+		}
+	}
 	
 	class RenameELVariableAction extends Action{
 		public RenameELVariableAction(){
@@ -350,5 +419,18 @@
 			invokeRenameELVariableWizard(selectedText, shell);
 		}
 	}
+
+	class RenameMessagePropertyAction extends Action{
+		MessagePropertyELSegment segment;
+		public RenameMessagePropertyAction(MessagePropertyELSegment segment){
+			super(JsfUIMessages.REFACTOR_CONTRIBUTOR_RENAME_MESSAGE_PROPERTY);
+			this.segment = segment;
+		}
+		public void run(){
+			saveAndBuild();
+			
+			invokeRenameMessagePropertyWizard(segment, shell);
+		}
+	}
 	
 }

Added: trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/RenameMessagePropertyWizard.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/RenameMessagePropertyWizard.java	                        (rev 0)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/RenameMessagePropertyWizard.java	2010-07-16 15:04:31 UTC (rev 23500)
@@ -0,0 +1,110 @@
+ /*******************************************************************************
+  * Copyright (c) 2010 Red Hat, Inc.
+  * Distributed under license by Red Hat, Inc. All rights reserved.
+  * This program is 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:
+  *     Red Hat, Inc. - initial API and implementation
+  ******************************************************************************/
+package org.jboss.tools.jsf.ui.el.refactoring;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.ltk.core.refactoring.Refactoring;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
+import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.jboss.tools.common.ui.widget.editor.CompositeEditor;
+import org.jboss.tools.common.ui.widget.editor.IFieldEditor;
+import org.jboss.tools.jsf.el.refactoring.RenameELVariableProcessor;
+import org.jboss.tools.jsf.el.refactoring.RenameMessagePropertyProcessor;
+import org.jboss.tools.jsf.ui.JsfUIMessages;
+
+/**
+ * @author Daniel Azarov
+ */
+public class RenameMessagePropertyWizard extends RefactoringWizard {
+
+	private String propertyName;
+	private IFieldEditor editor;
+
+	public RenameMessagePropertyWizard(Refactoring refactoring, IFile editorFile) {
+		super(refactoring, WIZARD_BASED_USER_INTERFACE);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.ui.refactoring.RefactoringWizard#addUserInputPages()
+	 */
+	@Override
+	protected void addUserInputPages() {
+	    setDefaultPageTitle(getRefactoring().getName());
+	    RenameMessagePropertyProcessor processor= (RenameMessagePropertyProcessor) getRefactoring().getAdapter(RenameMessagePropertyProcessor.class);
+	    addPage(new RenameMessagePropertyWizardPage(processor));
+	}
+	
+	class RenameMessagePropertyWizardPage extends UserInputWizardPage{
+		private RenameMessagePropertyProcessor processor;
+		
+		public RenameMessagePropertyWizardPage(RenameMessagePropertyProcessor processor){
+			super("");
+			this.processor = processor;
+			propertyName = processor.getOldName();
+		}
+
+		public void createControl(Composite parent) {
+			Composite container = new Composite(parent, SWT.NULL);
+			container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+	        GridLayout layout = new GridLayout();
+	        container.setLayout(layout);
+	        layout.numColumns = 2;
+	        
+	        String defaultName = propertyName;
+	        editor = FieldEditorFactory.createTextEditor(propertyName, JsfUIMessages.RENAME_MESSAGE_PROPERTY_WIZARD_PROPERTY_NAME, defaultName);
+	        editor.doFillIntoGrid(container);
+	        
+	        ((CompositeEditor)editor).addPropertyChangeListener(new PropertyChangeListener(){
+	        	public void propertyChange(PropertyChangeEvent evt){
+	        		validatePage();
+	        	}
+	        });
+	        setControl(container);
+	        setPageComplete(false);
+		}
+		
+		protected final void validatePage() {
+			RefactoringStatus status= new RefactoringStatus();
+			setPageComplete(status);
+		}
+		
+		/* (non-Javadoc)
+		 * @see org.eclipse.ltk.ui.refactoring.UserInputWizardPage#performFinish()
+		 */
+		protected boolean performFinish() {
+			
+			initializeRefactoring();
+			return super.performFinish();
+		}
+
+		/* (non-Javadoc)
+		 * @see org.eclipse.ltk.ui.refactoring.UserInputWizardPage#getNextPage()
+		 */
+		public IWizardPage getNextPage() {
+			initializeRefactoring();
+			return super.getNextPage();
+		}
+		
+		private void initializeRefactoring() {
+			processor.setNewName(editor.getValueAsString());
+		}
+		
+	}
+}
\ No newline at end of file


Property changes on: trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/RenameMessagePropertyWizard.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/messages.properties
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/messages.properties	2010-07-16 13:46:47 UTC (rev 23499)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/messages.properties	2010-07-16 15:04:31 UTC (rev 23500)
@@ -20,7 +20,9 @@
 RESOURCE_BUNDLES_RENAME_PARTICIPANT_UPDATE_BUNDLE_REFERENCES=Update bundle references in EL 
 REFACTOR_CONTRIBUTOR_MAIN_MENU=EL Refactor
 REFACTOR_CONTRIBUTOR_RENAME_EL_VARIABLE=Rename EL Variable
+REFACTOR_CONTRIBUTOR_RENAME_MESSAGE_PROPERTY=Rename Resource Bundle Message
 RENAME_EL_VARIABLE_WIZARD_EL_VARIABLE_NAME=EL Variable name:
+RENAME_MESSAGE_PROPERTY_WIZARD_PROPERTY_NAME=Resource Bundle Message:
 IS_JSF_CHECK_NEED=Is JSF check
 IS_KB_NATURE_CHECK_NEED=Is KB natures check
 IS_JSF_NATURE_CHECK_NEED=Is JSF natures check

Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java	2010-07-16 13:46:47 UTC (rev 23499)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java	2010-07-16 15:04:31 UTC (rev 23500)
@@ -190,7 +190,7 @@
 		}
 	}
 	
-	private void searchInCach(IFile file){
+	protected void searchInCach(IFile file){
 		ELContext context = PageContextFactory.createPageContext(file);
 		
 		if(context == null)



More information about the jbosstools-commits mailing list