Author: scabanovich
Date: 2008-02-12 10:26:24 -0500 (Tue, 12 Feb 2008)
New Revision: 6262
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/
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
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF
trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml
Log:
JBIDE-1758
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF 2008-02-12 14:58:42
UTC (rev 6261)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF 2008-02-12 15:26:24
UTC (rev 6262)
@@ -37,6 +37,8 @@
org.jboss.ide.eclipse.as.core,
org.eclipse.wst.server.core,
org.eclipse.core.filesystem,
+ org.eclipse.ltk.core.refactoring,
+ org.eclipse.ltk.ui.refactoring,
org.eclipse.jst.j2ee.ejb,
org.eclipse.jst.jsf.ui,
org.jboss.tools.jst.web,
@@ -44,7 +46,8 @@
Provide-Package: org.jboss.tools.seam.core,
org.jboss.tools.seam.internal.core,
org.jboss.tools.seam.internal.core.scanner,
- org.jboss.tools.seam.internal.core.preferences
+ org.jboss.tools.seam.internal.core.preferences,
+ org.jboss.tools.seam.internal.core.refactoring
Bundle-Version: 2.0.0
Export-Package: org.jboss.tools.seam.core,
org.jboss.tools.seam.core.event,
@@ -56,4 +59,5 @@
org.jboss.tools.seam.internal.core.scanner.java,
org.jboss.tools.seam.internal.core.scanner.lib,
org.jboss.tools.seam.internal.core.scanner.xml,
- org.jboss.tools.seam.internal.core.validation
+ org.jboss.tools.seam.internal.core.validation,
+ org.jboss.tools.seam.internal.core.refactoring
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml 2008-02-12 14:58:42 UTC (rev
6261)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml 2008-02-12 15:26:24 UTC (rev
6262)
@@ -289,4 +289,22 @@
class="org.jboss.tools.seam.internal.core.el.SeamPromptingProvider"/>
</extension>
+ <extension
+ point="org.eclipse.ltk.core.refactoring.renameParticipants">
+
+ <renameParticipant
+
class="org.jboss.tools.seam.internal.core.refactoring.SeamRenameProjectParticipant"
+
id="org.jboss.tools.seam.internal.core.refactoring.SeamRenameProjectParticipant"
+ name="seam-RenameProjectParticipant">
+ <enablement>
+ <with variable="element">
+ <or>
+ <instanceof
value="org.eclipse.core.resources.IProject"/>
+ </or>
+ </with>
+ </enablement>
+ </renameParticipant>
+
+ </extension>
+
</plugin>
Added:
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
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectChange.java 2008-02-12
15:26:24 UTC (rev 6262)
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * 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.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.osgi.service.prefs.BackingStoreException;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class SeamRenameProjectChange extends Change {
+ IProject project;
+ String newName;
+ String oldName;
+
+ static String[] PROPERTIES = {
+ "seam.parent.project",
+ "seam.ear.project",
+ "seam.ejb.project",
+ "seam.test.project"
+ };
+
+ List<String> relevantProperties = new ArrayList<String>();
+
+ public SeamRenameProjectChange(IProject project, String newName, String oldName) {
+ this.project = project;
+ this.newName = newName;
+ this.oldName = oldName;
+ IEclipsePreferences ps = getSeamPreferences();
+ for (int i = 0; i < PROPERTIES.length; i++) {
+ if(oldName.equals(ps.get(PROPERTIES[i], null))) {
+ relevantProperties.add(PROPERTIES[i]);
+ }
+ }
+ }
+
+ public boolean isRelevant() {
+ return relevantProperties.size() > 0;
+ }
+
+ @Override
+ public Object getModifiedElement() {
+ return project;
+ }
+
+ @Override
+ public String getName() {
+ return 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 {
+ pm.beginTask(getName(), 1);
+
+ IEclipsePreferences ps = getSeamPreferences();
+ for (String property: relevantProperties) {
+ if(oldName.equals(ps.get(property, null))) {
+ ps.put(property, newName);
+ }
+ }
+ try {
+ ps.flush();
+ } catch (BackingStoreException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ return new SeamRenameProjectChange(project, oldName, newName);
+ } finally {
+ pm.done();
+ }
+ }
+
+ public IEclipsePreferences getSeamPreferences() {
+ IScopeContext projectScope = new ProjectScope(project);
+ return projectScope.getNode(SeamCorePlugin.PLUGIN_ID);
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectParticipant.java 2008-02-12
15:26:24 UTC (rev 6262)
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * 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.RenameParticipant;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class SeamRenameProjectParticipant extends RenameParticipant {
+ public static final String PARTICIPANT_NAME="seam-RenameProjectParticipant";
+
+ IProject project;
+ String oldName;
+
+ public SeamRenameProjectParticipant() {}
+
+ @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++) {
+ SeamRenameProjectChange c = new SeamRenameProjectChange(ps[i], newName, oldName);
+ 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 IProject)) {
+ return false;
+ }
+ project = (IProject)element;
+ oldName = project.getName();
+ return true;
+ }
+
+}