[jbosstools-commits] JBoss Tools SVN: r7049 - in trunk/seam/plugins/org.jboss.tools.seam.core: src/org/jboss/tools/seam/internal/core/refactoring and 1 other directory.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Thu Mar 20 13:52:21 EDT 2008
Author: akazakov
Date: 2008-03-20 13:52:21 -0400 (Thu, 20 Mar 2008)
New Revision: 7049
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamProjectChange.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderChange.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderParticipant.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectChange.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectParticipant.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1919 Added folder renaming.
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml 2008-03-20 17:48:43 UTC (rev 7048)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml 2008-03-20 17:52:21 UTC (rev 7049)
@@ -304,7 +304,19 @@
</with>
</enablement>
</renameParticipant>
+ <renameParticipant
+ class="org.jboss.tools.seam.internal.core.refactoring.SeamRenameFolderParticipant"
+ id="org.jboss.tools.seam.internal.core.refactoring.SeamRenameSourceFolderParticipant"
+ name="seam-RenameSourceFolderParticipant">
+ <enablement>
+ <with variable="element">
+ <or>
+ <instanceof value="org.eclipse.core.resources.IFolder"/>
+ </or>
+ </with>
+ </enablement>
+ </renameParticipant>
</extension>
-</plugin>
+</plugin>
\ No newline at end of file
Added: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamProjectChange.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamProjectChange.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamProjectChange.java 2008-03-20 17:52:21 UTC (rev 7049)
@@ -0,0 +1,97 @@
+ /*******************************************************************************
+ * 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.ProjectScope;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
+
+/**
+ * @author Alexey Kazakov
+ */
+public abstract class SeamProjectChange extends Change {
+
+ protected IProject project;
+
+ protected static String[] PROJECT_NAME_PROPERTIES = {
+ ISeamFacetDataModelProperties.SEAM_PARENT_PROJECT,
+ ISeamFacetDataModelProperties.SEAM_EAR_PROJECT,
+ ISeamFacetDataModelProperties.SEAM_EJB_PROJECT,
+ ISeamFacetDataModelProperties.SEAM_TEST_PROJECT
+ };
+
+ protected static String[] FOLDER_PROPERTIES = {
+ ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER,
+ ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER,
+ ISeamFacetDataModelProperties.TEST_SOURCE_FOLDER,
+ ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER
+ };
+
+ /**
+ * @param project Project that we are asked to check and update.
+ */
+ public SeamProjectChange(IProject project) {
+ this.project = project;
+ }
+
+ /**
+ * @return false if we is not going to update this project
+ */
+ abstract public boolean isRelevant();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#getModifiedElement()
+ */
+ @Override
+ public Object getModifiedElement() {
+ return project;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#getName()
+ */
+ @Override
+ public String getName() {
+ return "Update Seam Project Properties for " + project.getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#initializeValidationData(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void initializeValidationData(IProgressMonitor pm) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ return new RefactoringStatus();
+ }
+
+ /**
+ * @return preferences of project
+ */
+ protected IEclipsePreferences getSeamPreferences() {
+ IScopeContext projectScope = new ProjectScope(project);
+ return projectScope.getNode(SeamCorePlugin.PLUGIN_ID);
+ }
+}
\ No newline at end of file
Added: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderChange.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderChange.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderChange.java 2008-03-20 17:52:21 UTC (rev 7049)
@@ -0,0 +1,96 @@
+ /*******************************************************************************
+ * 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.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+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 SeamRenameFolderChange extends SeamProjectChange {
+
+ private IPath oldPath;
+ private IPath newPath;
+
+ private List<String> relevantProperties = new ArrayList<String>();
+
+ public SeamRenameFolderChange(IProject project, String newName, IPath oldPath) {
+ super(project);
+ this.oldPath = oldPath;
+ this.newPath = oldPath.removeLastSegments(1).append(newName);
+
+ 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 = oldPath.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 = oldPath.toString();
+ if(propertyValue.equals(oldPathString)) {
+ ps.put(propertyName, newPath.toString());
+ } else if(propertyValue.startsWith(oldPathString + "/")) {
+ String newPathString = newPath.toString() + propertyValue.substring(oldPathString.length());
+ ps.put(propertyName, newPathString);
+ }
+ }
+
+ try {
+ ps.flush();
+ } catch (BackingStoreException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ return new SeamRenameFolderChange(project, oldPath.lastSegment(), newPath);
+ } 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/SeamRenameFolderParticipant.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderParticipant.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderParticipant.java 2008-03-20 17:52:21 UTC (rev 7049)
@@ -0,0 +1,78 @@
+ /*******************************************************************************
+ * 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.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+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.RenameParticipant;
+
+/**
+ * Updates seam settings of seam projects if somebody renames source folder.
+ * @author Alexey Kazakov
+ */
+public class SeamRenameFolderParticipant extends RenameParticipant {
+ public static final String PARTICIPANT_NAME="seam-RenameSourceFolderParticipant";
+
+ private IPath oldPath;
+
+ public SeamRenameFolderParticipant() {
+ }
+
+ @Override
+ public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException {
+ return null;
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ if (!pm.isCanceled()) {
+ String newName = getArguments().getNewName();
+ if(newName == null || newName.trim().length() == 0) {
+ return null;
+ }
+ CompositeChange change = new CompositeChange("Update Seam Projects");
+ IProject[] ps = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for (int i = 0; i < ps.length; i++) {
+ SeamRenameFolderChange c = new SeamRenameFolderChange(ps[i], newName, oldPath);
+ if(c.isRelevant()) change.add(c);
+ }
+ if(change.getChildren().length > 0) {
+ return change;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return PARTICIPANT_NAME;
+ }
+
+ @Override
+ protected boolean initialize(Object element) {
+ if(!(element instanceof IFolder)) {
+ return false;
+ }
+ oldPath = ((IResource)element).getFullPath();
+
+ return true;
+ }
+}
\ No newline at end of file
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectChange.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectChange.java 2008-03-20 17:48:43 UTC (rev 7048)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectChange.java 2008-03-20 17:52:21 UTC (rev 7049)
@@ -15,46 +15,32 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ProjectScope;
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.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.ltk.core.refactoring.Change;
-import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
import org.osgi.service.prefs.BackingStoreException;
/**
* @author Viacheslav Kabanovich
*/
-public class SeamRenameProjectChange extends Change {
- IProject project;
- String newName;
- String oldName;
+public class SeamRenameProjectChange extends SeamProjectChange {
- static String[] PROJECT_NAME_PROPERTIES = {
- ISeamFacetDataModelProperties.SEAM_PARENT_PROJECT,
- ISeamFacetDataModelProperties.SEAM_EAR_PROJECT,
- ISeamFacetDataModelProperties.SEAM_EJB_PROJECT,
- ISeamFacetDataModelProperties.SEAM_TEST_PROJECT
- };
+ protected String newName;
+ protected String oldName;
- static String[] SOURCE_FOLDER_PROPERTIES = {
- ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER,
- ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER,
- ISeamFacetDataModelProperties.TEST_SOURCE_FOLDER,
- ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER
- };
+ private List<String> relevantProjectNameProperties = new ArrayList<String>();
+ private List<String> relevantSourceFolderProperties = new ArrayList<String>();
- List<String> relevantProjectNameProperties = new ArrayList<String>();
- List<String> relevantSourceFolderProperties = new ArrayList<String>();
-
+ /**
+ * @param project
+ * @param newName
+ * @param oldName
+ */
public SeamRenameProjectChange(IProject project, String newName, String oldName) {
- this.project = project;
+ super(project);
this.newName = newName;
this.oldName = oldName;
IEclipsePreferences ps = getSeamPreferences();
@@ -63,37 +49,27 @@
relevantProjectNameProperties.add(PROJECT_NAME_PROPERTIES[i]);
}
}
- for (int i = 0; i < SOURCE_FOLDER_PROPERTIES.length; i++) {
- if(ps.get(SOURCE_FOLDER_PROPERTIES[i], "").startsWith("/" + oldName + "/")) {
- relevantSourceFolderProperties.add(SOURCE_FOLDER_PROPERTIES[i]);
+ for (int i = 0; i < FOLDER_PROPERTIES.length; i++) {
+ if(ps.get(FOLDER_PROPERTIES[i], "").startsWith("/" + oldName + "/")) {
+ relevantSourceFolderProperties.add(FOLDER_PROPERTIES[i]);
}
}
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.seam.internal.core.refactoring.SeamProjectChange#isRelevant()
+ */
+ @Override
public boolean isRelevant() {
return relevantProjectNameProperties.size() > 0 || relevantSourceFolderProperties.size() > 0;
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
+ */
@Override
- public Object getModifiedElement() {
- return project;
- }
-
- @Override
- public String getName() {
- return "Update Seam Project Properties for " + project.getName();
- }
-
- @Override
- public void initializeValidationData(IProgressMonitor pm) {
- }
-
- @Override
- public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
- return new RefactoringStatus();
- }
-
- @Override
public Change perform(IProgressMonitor pm) throws CoreException {
if(!isRelevant()) return null;
try {
@@ -129,9 +105,4 @@
pm.done();
}
}
-
- public IEclipsePreferences getSeamPreferences() {
- IScopeContext projectScope = new ProjectScope(project);
- return projectScope.getNode(SeamCorePlugin.PLUGIN_ID);
- }
}
\ No newline at end of file
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectParticipant.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectParticipant.java 2008-03-20 17:48:43 UTC (rev 7048)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectParticipant.java 2008-03-20 17:52:21 UTC (rev 7049)
@@ -53,6 +53,9 @@
return null;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#getName()
+ */
@Override
public String getName() {
return PARTICIPANT_NAME;
More information about the jbosstools-commits
mailing list