[jbosstools-commits] JBoss Tools SVN: r7116 - in trunk/seam: plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring and 4 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Tue Mar 25 12:14:01 EDT 2008


Author: akazakov
Date: 2008-03-25 12:14:01 -0400 (Tue, 25 Mar 2008)
New Revision: 7116

Added:
   trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderMoveChange.java
   trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderMoveParticipant.java
   trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamMoveParticipant.java
   trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/testwebroot/
   trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/webroot/
   trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/webroot/WebContent/
Removed:
   trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/WebContent/
Modified:
   trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml
   trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.settings/org.jboss.tools.seam.core.prefs
   trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamPropertyRefactoringTest.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1919 Added move folder refactoring.

Modified: trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml	2008-03-25 16:13:59 UTC (rev 7115)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml	2008-03-25 16:14:01 UTC (rev 7116)
@@ -291,7 +291,6 @@
 
    <extension
          point="org.eclipse.ltk.core.refactoring.renameParticipants">
-
       <renameParticipant
             class="org.jboss.tools.seam.internal.core.refactoring.SeamProjectRenameParticipant"
             id="org.jboss.tools.seam.internal.core.refactoring.SeamProjectRenameParticipant"
@@ -328,7 +327,21 @@
             </with>
          </enablement>
       </renameParticipant>
+	</extension>
 
+	<extension
+         point="org.eclipse.ltk.core.refactoring.moveParticipants">
+    <moveParticipant
+          class="org.jboss.tools.seam.internal.core.refactoring.SeamFolderMoveParticipant"
+          id="org.jboss.tools.seam.internal.core.refactoring.SeamFolderMoveParticipant"
+          name="name">
+       <enablement>
+            <with variable="element">
+                <or>
+                   <instanceof value="org.eclipse.core.resources.IFolder"/>
+                </or>
+            </with>
+       </enablement>
+    </moveParticipant>
 	</extension>
-
 </plugin>
\ No newline at end of file

Added: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderMoveChange.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderMoveChange.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderMoveChange.java	2008-03-25 16:14:01 UTC (rev 7116)
@@ -0,0 +1,103 @@
+ /*******************************************************************************
+  * Copyright (c) 2007 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.seam.internal.core.refactoring;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class SeamFolderMoveChange extends SeamProjectChange {
+
+	private IResource oldResource;
+	private IContainer destination;
+	private List<String> relevantProperties = new ArrayList<String>();
+
+	/**
+	 * @param project
+	 */
+	public SeamFolderMoveChange(IProject project, IResource oldResource, IContainer destination) {
+		super(project);
+		this.oldResource = oldResource;
+		this.destination = destination;
+
+		if(oldResource.getProject().equals(destination.getProject())) {
+			IEclipsePreferences ps = getSeamPreferences();
+			for (int i = 0; i < FOLDER_PROPERTIES.length; i++) {
+				String propertyValue = ps.get(FOLDER_PROPERTIES[i], null);
+				if(propertyValue==null) {
+					continue;
+				}
+				String oldPathString = oldResource.getFullPath().toString();
+				if(propertyValue.equals(oldPathString) ||
+						propertyValue.startsWith(oldPathString + "/")) {
+					relevantProperties.add(FOLDER_PROPERTIES[i]);
+				} 
+			}
+		}
+	}
+
+	/* (non-Javadoc)
+	 * @see org.jboss.tools.seam.internal.core.refactoring.SeamProjectChange#isRelevant()
+	 */
+	@Override
+	public boolean isRelevant() {
+		return relevantProperties.size()>0;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	@Override
+	public Change perform(IProgressMonitor pm) throws CoreException {
+		if(!isRelevant()) {
+			return null;
+		}
+		try {
+			pm.beginTask(getName(), 1);
+
+			IEclipsePreferences ps = getSeamPreferences();
+			for (String propertyName: relevantProperties) {
+				String propertyValue = ps.get(propertyName, "");
+				String oldPathString = oldResource.getFullPath().toString();
+				String newPath  = destination.getFullPath().append(oldResource.getName()).toString();
+				if(propertyValue.equals(oldPathString)) {
+					ps.put(propertyName, newPath);
+				} else if(propertyValue.startsWith(oldPathString + "/")) {
+					newPath = newPath + propertyValue.substring(oldPathString.length());
+					ps.put(propertyName, newPath);
+				}
+			}
+			try {
+				ps.flush();
+			} catch (BackingStoreException e) {
+				SeamCorePlugin.getPluginLog().logError(e);
+			}
+			IResource newResource = destination.getFile(new Path(oldResource.getName()));
+			IContainer oldContainer = oldResource.getParent();
+			return new SeamFolderMoveChange(project, newResource, oldContainer);
+		} finally {
+			pm.done();
+		}
+	}
+}
\ No newline at end of file

Added: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderMoveParticipant.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderMoveParticipant.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderMoveParticipant.java	2008-03-25 16:14:01 UTC (rev 7116)
@@ -0,0 +1,59 @@
+ /*******************************************************************************
+  * Copyright (c) 2007 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.seam.internal.core.refactoring;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class SeamFolderMoveParticipant extends SeamMoveParticipant {
+
+	private IResource oldResource;
+
+	public static final String PARTICIPANT_NAME="seam-FolderMoveParticipant";
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName()
+	 */
+	@Override
+	public String getName() {
+		return PARTICIPANT_NAME;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object)
+	 */
+	@Override
+	protected boolean initialize(Object element) {
+		if(!(element instanceof IFolder)) {
+			return false;
+		}
+		oldResource = (IResource)element;
+
+		return true;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.jboss.tools.seam.internal.core.refactoring.SeamMoveParticipant#createChange(org.eclipse.core.resources.IProject, java.lang.Object)
+	 */
+	@Override
+	protected SeamProjectChange createChange(IProject project, Object destination) {
+		if(destination instanceof IContainer) {
+			IContainer container = (IContainer)destination;
+			return new SeamFolderMoveChange(project, oldResource, container);
+		}
+		return null;
+	}
+}
\ No newline at end of file

Added: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamMoveParticipant.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamMoveParticipant.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamMoveParticipant.java	2008-03-25 16:14:01 UTC (rev 7116)
@@ -0,0 +1,61 @@
+ /*******************************************************************************
+  * Copyright (c) 2007 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.seam.internal.core.refactoring;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+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.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.MoveParticipant;
+
+/**
+ * @author Alexey Kazakov
+ */
+abstract public class SeamMoveParticipant extends MoveParticipant {
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
+	 */
+	@Override
+	public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException {
+		return null;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	@Override
+	public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+		if (!pm.isCanceled()) {
+			Object destination = getArguments().getDestination();
+			if(destination == null) {
+				return null;
+			}
+			CompositeChange change = new CompositeChange("Update Seam Projects");
+			IProject[] ps = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+			for (int i = 0; i < ps.length; i++) {
+				SeamProjectChange c = createChange(ps[i], destination);
+				if(c.isRelevant()) change.add(c);
+			}
+			if(change.getChildren().length > 0) {
+				return change;
+			}
+		}
+		return null;
+	}
+
+	abstract protected SeamProjectChange createChange(IProject project, Object destination);
+}
\ No newline at end of file

Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.settings/org.jboss.tools.seam.core.prefs
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.settings/org.jboss.tools.seam.core.prefs	2008-03-25 16:13:59 UTC (rev 7115)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.settings/org.jboss.tools.seam.core.prefs	2008-03-25 16:14:01 UTC (rev 7116)
@@ -8,7 +8,7 @@
 seam.project.connection.profile=DefaultDS
 seam.project.deployment.type=ear
 seam.project.settings.version=1.1
-seam.project.web.root.folder=/RefactoringTestProject-war/WebContent
+seam.project.web.root.folder=/RefactoringTestProject-war/webroot/WebContent
 seam.runtime.name=jboss-seam-2.0.0.GA
 seam.test.creating=true
 seam.test.project=RefactoringTestProject-test

Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamPropertyRefactoringTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamPropertyRefactoringTest.java	2008-03-25 16:13:59 UTC (rev 7115)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamPropertyRefactoringTest.java	2008-03-25 16:14:01 UTC (rev 7116)
@@ -31,6 +31,14 @@
 import org.eclipse.jdt.core.JavaModelException;
 import org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameRefactoring;
 import org.eclipse.jdt.internal.corext.refactoring.rename.RenameResourceProcessor;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.IConfirmQuery;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.ICreateTargetQueries;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.ICreateTargetQuery;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgQueries;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaMoveProcessor;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy.IMovePolicy;
+import org.eclipse.jdt.internal.corext.refactoring.structure.JavaMoveRefactoring;
 import org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating;
 import org.eclipse.jdt.internal.corext.refactoring.tagging.IReferenceUpdating;
 import org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating;
@@ -62,8 +70,9 @@
 	static String actionSourceFolderPath = "/" + ejbProjectName + "/" + actionSourceFolderName;
 	static String modelSourceFolderPath = "/" + warProjectName + "/" + modelSourceFolderName;
 	static String testSourceFolderPath = "/" + testProjectName + "/" + testSourceFolderName;
+	static String viewFolderParentName = "webroot";
 	static String viewFolderName = "WebContent";
-	static String viewFolderPath = "/" + warProjectName + "/" + viewFolderName;
+	static String viewFolderPath = "/" + warProjectName + "/" + viewFolderParentName + "/" + viewFolderName;
 	static String actionPackageName = "ejbdemo";
 	static String modelPackageName = "wardemo";
 	static String testPackageName = "testdemo";
@@ -184,6 +193,12 @@
 		assertCorrectProperties();
 	}
 
+	public void testViewFolderMove() throws CoreException {
+		viewFolderParentName = "testwebroot";
+		moveFolder(viewFolderPath, "/" + warProjectName + "/" + viewFolderParentName);
+		assertCorrectProperties();
+	}
+
 	private void assertCorrectProperties() {
 		updateFields();
 
@@ -227,7 +242,7 @@
 		actionSourceFolderPath = "/" + ejbProjectName + "/" + actionSourceFolderName;
 		modelSourceFolderPath = "/" + warProjectName + "/" + modelSourceFolderName;
 		testSourceFolderPath = "/" + testProjectName + "/" + testSourceFolderName;
-		viewFolderPath = "/" + warProjectName + "/" + viewFolderName;
+		viewFolderPath = "/" + warProjectName + "/" + viewFolderParentName + "/" + viewFolderName;
 	}
 
 	private IPackageFragmentRoot renameSourceFolder(String folderPath, String newFolderName) throws CoreException {
@@ -370,4 +385,62 @@
 		}
 		EditorTestHelper.joinBackgroundActivities();
 	}
+
+	private IFolder moveFolder(String folderPath, String destinationFolderPath) throws CoreException {
+		IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(folderPath);
+		assertNotNull("Can't find folder: " + folderPath, resource);
+		IResource destination = ResourcesPlugin.getWorkspace().getRoot().findMember(destinationFolderPath);
+		assertNotNull("Can't find destination folder: " + destinationFolderPath, destination);
+
+		IMovePolicy policy = null;
+		JavaMoveProcessor processor = null;
+		try {
+			policy = ReorgPolicyFactory.createMovePolicy(new IResource[]{resource}, new IJavaElement[0]);
+			processor = new JavaMoveProcessor(policy);
+			processor.setDestination(destination);
+		} catch (JavaModelException e) {
+			JUnitUtils.fail("Exception during perform folder moving: " + folderPath, e);
+		}
+		JavaMoveRefactoring refactoring = new JavaMoveRefactoring(processor);
+		processor.setCreateTargetQueries(new ICreateTargetQueries(){
+			public ICreateTargetQuery createNewPackageQuery() {
+				return null;
+			}
+		});
+		processor.setReorgQueries(new IReorgQueries(){
+			public IConfirmQuery createSkipQuery(String queryTitle, int queryID) {
+				return null;
+			}
+			public IConfirmQuery createYesNoQuery(String queryTitle, boolean allowCancel, int queryID) {
+				return null;
+			}
+			public IConfirmQuery createYesYesToAllNoNoToAllQuery(String queryTitle, boolean allowCancel, int queryID) {
+				return null;
+			}
+		});
+
+		// perform
+		Object[] elements = processor.getElements();
+		RenameSelectionState state = elements.length==1?new RenameSelectionState(elements[0]):null;
+		RefactoringExecutionHelper helper= new RefactoringExecutionHelper(refactoring,
+				RefactoringCore.getConditionCheckingFailedSeverity(),
+				RefactoringSaveHelper.SAVE_ALL,
+				WorkbenchUtils.getActiveShell(),
+				WorkbenchUtils.getWorkbench().getActiveWorkbenchWindow());
+		try {
+			helper.perform(true, true);
+		} catch (InterruptedException e) {
+			JUnitUtils.fail("Exception during perform folder moving: " + folderPath, e);
+		} catch (InvocationTargetException e) {
+			JUnitUtils.fail("Exception during perform folder moving: " + folderPath, e);
+		}
+
+		EditorTestHelper.joinBackgroundActivities();
+
+		String newFolderPath = destination.getFullPath().append(resource.getName()).toString();
+		resource = ResourcesPlugin.getWorkspace().getRoot().findMember(newFolderPath);
+		assertNotNull("Can't find folder: " + newFolderPath, resource);
+
+		return (IFolder)resource;
+	}
 }
\ No newline at end of file




More information about the jbosstools-commits mailing list