Author: dgeraskov
Date: 2011-02-11 07:54:26 -0500 (Fri, 11 Feb 2011)
New Revision: 29112
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/CodeGenerationConsoleNameChange.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigurationRenameParticipant.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigurationRenameProcessor.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/Messages.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ProjectDefaultConfigurationChange.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/messages.properties
Removed:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/CodeGenerationReseourceNameChange.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsolePlugin.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameParticipant.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigurationITypeRenameParticipant.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java
Log:
https://issues.jboss.org/browse/JBIDE-8236
Refactoring: rename console configuration as refactoring change
Update console configuration associated with a project and code generation configuration.
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2011-02-11
12:30:01 UTC (rev 29111)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2011-02-11
12:54:26 UTC (rev 29112)
@@ -714,6 +714,21 @@
</with>
</enablement>
</renameParticipant>
+ <renameParticipant
+
class="org.hibernate.eclipse.launch.core.refactoring.ConsoleConfigurationRenameParticipant"
+ id="org.hibernate.eclipse.console.renameParticipant1"
+ name="ConsoleConfigurationRenameParticipant">
+ <enablement>
+ <with
+ variable="element">
+ <and>
+ <instanceof
+
value="org.eclipse.debug.internal.core.LaunchConfiguration">
+ </instanceof>
+ </and>
+ </with>
+ </enablement>
+ </renameParticipant>
</extension>
<extension
point="org.eclipse.ltk.core.refactoring.moveParticipants">
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java 2011-02-11
12:30:01 UTC (rev 29111)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java 2011-02-11
12:54:26 UTC (rev 29112)
@@ -485,6 +485,8 @@
public static String PathHelper_has_to_be_folder_or_project;
public static String PathHelper_has_to_be_file;
public static String PathHelper_project_for_is_closed;
+
+ public static String EditConsoleConfiguration_rename_refactoring_error_totle;
//
public static String HibernateRefactoringUtil_error_during_refactoring;
public static String HibernateRefactoringUtil_error_occured_while_updating_classpath;
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2011-02-11
12:30:01 UTC (rev 29111)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2011-02-11
12:54:26 UTC (rev 29112)
@@ -492,6 +492,8 @@
PathHelper_has_to_be_file={0} has to be a file [{1}]
PathHelper_project_for_is_closed=Project for {0} is closed [{1}]
+EditConsoleConfiguration_rename_refactoring_error_totle = Refactoring Error
+
HibernateRefactoringUtil_error_during_refactoring=Error during refactoring
HibernateRefactoringUtil_error_occured_while_updating_classpath=Error occured while
updating classpath.
LaunchConfigurationResourceNameChange_update_resource_path_in_launch_cfg=Update resource
path in launch configuration ''{0}''
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsolePlugin.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsolePlugin.java 2011-02-11
12:30:01 UTC (rev 29111)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsolePlugin.java 2011-02-11
12:54:26 UTC (rev 29112)
@@ -28,10 +28,12 @@
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
@@ -47,6 +49,9 @@
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jpt.core.JptCorePlugin;
+import org.eclipse.ltk.core.refactoring.CheckConditionsOperation;
+import org.eclipse.ltk.core.refactoring.PerformRefactoringOperation;
+import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
@@ -69,6 +74,7 @@
import org.hibernate.eclipse.hqleditor.HQLEditorInput;
import org.hibernate.eclipse.hqleditor.HQLEditorStorage;
import org.hibernate.eclipse.launch.ICodeGenerationLaunchConstants;
+import
org.hibernate.eclipse.launch.core.refactoring.ConsoleConfigurationRenameProcessor;
import org.hibernate.eclipse.logging.PluginLogger;
import org.hibernate.eclipse.logging.xpl.EclipseLogger;
import org.osgi.framework.BundleContext;
@@ -196,6 +202,7 @@
KnownConfigurations instance = KnownConfigurations.getInstance();
ConsoleConfiguration oldcfg = instance.find( movedFrom.getName() );
if(oldcfg!=null) {
+ refactor(movedFrom, configuration);//call this before we remove old configuration
oldcfg.reset(); // reset it no matter what.
instance.removeConfiguration(oldcfg, false);
}
@@ -209,9 +216,34 @@
instance.addConfiguration(new ConsoleConfiguration(adapter), true);
}
- }
}
+ }
+
+ private void refactor (ILaunchConfiguration oldConfiguration, ILaunchConfiguration
newConfiguration) {
+ if (!oldConfiguration.getName().equals(newConfiguration.getName())){
+ //only rename of console configuration refactoring is supported.
+ ConsoleConfigurationRenameProcessor proc = new
ConsoleConfigurationRenameProcessor(oldConfiguration, newConfiguration.getName());
+ // Refactor for rename
+ PerformRefactoringOperation refOperation = new PerformRefactoringOperation(
+ new ProcessorBasedRefactoring(proc),
+ CheckConditionsOperation.ALL_CONDITIONS);
+ try
+ {
+ ResourcesPlugin.getWorkspace().run(refOperation, null);
+ }
+ catch (OperationCanceledException oce)
+ {
+ throw new OperationCanceledException();
+ }
+ catch (CoreException ce)
+ {
+ HibernateConsolePlugin.openError(new Shell(),
HibernateConsoleMessages.EditConsoleConfiguration_rename_refactoring_error_totle,
+ ce.getLocalizedMessage(), ce, HibernateConsolePlugin.PERFORM_SYNC_EXEC);
+ }
+ }
+ }
+
private boolean isTemporary(ILaunchConfiguration configuration) {
boolean temporary = true;
try {
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/CodeGenerationConsoleNameChange.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/CodeGenerationConsoleNameChange.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/CodeGenerationConsoleNameChange.java 2011-02-11
12:54:26 UTC (rev 29112)
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.launch.core.refactoring;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class CodeGenerationConsoleNameChange extends Change {
+
+ private ILaunchConfiguration fLaunchConfiguration;
+
+ private String newCCName;
+
+ public CodeGenerationConsoleNameChange(ILaunchConfiguration launchConfiguration, String
newCCName){
+ assert
KnownConfigurations.getInstance().isKnownConfiguration(launchConfiguration.getName());
+ this.fLaunchConfiguration = launchConfiguration;
+ this.newCCName = newCCName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#getName()
+ */
+ @Override
+ public String getName() {
+ return NLS.bind(Messages.CodeGenerationConsoleNameChange_update,
fLaunchConfiguration.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 {
+ if
(fLaunchConfiguration.getAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
(String)null) == null){
+ return
RefactoringStatus.createFatalErrorStatus(Messages.CodeGenerationConsoleNameChange_error_null_confi);
+ } else if (newCCName == null || newCCName.trim().length() == 0){
+ return
RefactoringStatus.createFatalErrorStatus(Messages.CodeGenerationConsoleNameChange_error_empty_name);
+ }
+ return new RefactoringStatus();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ String oldName =
fLaunchConfiguration.getAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
new String());
+ ILaunchConfigurationWorkingCopy wc = fLaunchConfiguration.getWorkingCopy();
+ wc.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME, newCCName);
+ ILaunchConfiguration newLaunchConfig = wc.doSave();
+ return new CodeGenerationConsoleNameChange(newLaunchConfig, oldName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#getModifiedElement()
+ */
+ @Override
+ public Object getModifiedElement() {
+ return fLaunchConfiguration;
+ }
+
+}
Deleted:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/CodeGenerationReseourceNameChange.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/CodeGenerationReseourceNameChange.java 2011-02-11
12:30:01 UTC (rev 29111)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/CodeGenerationReseourceNameChange.java 2011-02-11
12:54:26 UTC (rev 29112)
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-
-package org.hibernate.eclipse.launch.core.refactoring;
-
-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.debug.core.ILaunchConfiguration;
-import org.eclipse.ltk.core.refactoring.Change;
-import org.eclipse.ltk.core.refactoring.RefactoringStatus;
-import org.eclipse.osgi.util.NLS;
-import org.hibernate.eclipse.console.HibernateConsoleMessages;
-
-/**
- * @author Dmitry Geraskov
- *
- */
-public class CodeGenerationReseourceNameChange extends Change {
-
- private ILaunchConfiguration fLaunchConfiguration;
- private IPath fOldPath;
- private IPath fNewPath;
-
- CodeGenerationReseourceNameChange(ILaunchConfiguration launchConfiguration, IPath
oldPath, IPath newPath){
- fLaunchConfiguration = launchConfiguration;
- fOldPath = oldPath;
- fNewPath = newPath;
- }
-
- @Override
- public Object getModifiedElement() {
- return fLaunchConfiguration;
- }
-
- @Override
- public String getName() {
- return
NLS.bind(HibernateConsoleMessages.LaunchConfigurationResourceNameChange_update_resource_path_in_launch_cfg,
fLaunchConfiguration.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 {
- fLaunchConfiguration =
HibernateRefactoringUtil.updateCodeGenerationConfig(fLaunchConfiguration, fOldPath,
fNewPath);
- return new CodeGenerationReseourceNameChange(fLaunchConfiguration, fNewPath,
fOldPath);
- }
-
-}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameParticipant.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameParticipant.java 2011-02-11
12:30:01 UTC (rev 29111)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameParticipant.java 2011-02-11
12:54:26 UTC (rev 29112)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.hibernate.eclipse.launch.core.refactoring;
import java.util.ArrayList;
@@ -14,6 +24,10 @@
import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
+/**
+ * @author Dmitry Geraskov
+ *
+ */
public class ConnectionProfileRenameParticipant extends RenameParticipant {
IConnectionProfile profile;
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigurationITypeRenameParticipant.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigurationITypeRenameParticipant.java 2011-02-11
12:30:01 UTC (rev 29111)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigurationITypeRenameParticipant.java 2011-02-11
12:54:26 UTC (rev 29112)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2009-2011 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.hibernate.eclipse.launch.core.refactoring;
import org.eclipse.core.runtime.CoreException;
@@ -9,6 +19,10 @@
import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
+/**
+ * @author Dmitry Geraskov
+ *
+ */
public class ConsoleConfigurationITypeRenameParticipant extends
RenameParticipant {
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigurationRenameParticipant.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigurationRenameParticipant.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigurationRenameParticipant.java 2011-02-11
12:54:26 UTC (rev 29112)
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.launch.core.refactoring;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+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;
+import org.hibernate.console.KnownConfigurations;
+
+/**
+ *
+ * @author Dmitry Geraskov
+ *
+ */
+public class ConsoleConfigurationRenameParticipant extends RenameParticipant {
+
+ private String oldName;
+
+ @Override
+ protected boolean initialize(Object element) {
+ if (element instanceof ILaunchConfiguration) {
+ oldName = ((ILaunchConfiguration) element).getName();
+ return KnownConfigurations.getInstance().isKnownConfiguration(oldName);
+ }
+ return false;
+ }
+
+ @Override
+ public String getName() {
+ return Messages.ConsoleConfigurationRenameParticipant_name;
+ }
+
+ @Override
+ public RefactoringStatus checkConditions(IProgressMonitor pm,
+ CheckConditionsContext context) throws OperationCanceledException {
+ return new RefactoringStatus();
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException {
+ CompositeChange change = new
CompositeChange(Messages.ConsoleConfigurationRenameParticipant_change_name);
+ change.markAsSynthetic();
+ CompositeChange change1 = new
CompositeChange(Messages.ConsoleConfigurationRenameParticipant_update_code_generations);
+ change1.addAll(getCodeGenerationConsoleNameChanges());
+ CompositeChange change2 = new
CompositeChange(Messages.ConsoleConfigurationRenameParticipant_update_project_config);
+ change2.addAll(getProjectDefaultConfigurationChanges());
+ change.add(change1);
+ change.add(change2);
+ return change;
+ }
+
+ /**
+ * @return CodeGenerationConsoleNameChanges
+ */
+ private Change[] getCodeGenerationConsoleNameChanges() {
+ ILaunchConfiguration[] affectedConfigurations =
HibernateRefactoringUtil.getAffectedCodeGenerationConfigs(oldName);
+ Change[] changes = new Change[affectedConfigurations.length];
+ for (int i = 0; i < affectedConfigurations.length; i++) {
+ changes[i] = new CodeGenerationConsoleNameChange(affectedConfigurations[i],
getArguments().getNewName());
+ }
+ return changes;
+ }
+
+ /**
+ * @return
+ */
+ private Change[] getProjectDefaultConfigurationChanges() {
+ IProject[] affectedProjects = HibernateRefactoringUtil.getAffectedProjects(oldName);
+ Change[] changes = new Change[affectedProjects.length];
+ for (int i = 0; i < affectedProjects.length; i++) {
+ changes[i] = new ProjectDefaultConfigurationChange(affectedProjects[i],
getArguments().getNewName());
+ }
+ return changes;
+ }
+
+}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigurationRenameProcessor.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigurationRenameProcessor.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigurationRenameProcessor.java 2011-02-11
12:54:26 UTC (rev 29112)
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.launch.core.refactoring;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.NullChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.ParticipantManager;
+import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
+import org.eclipse.ltk.core.refactoring.participants.RenameArguments;
+import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
+import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
+import org.hibernate.console.KnownConfigurations;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class ConsoleConfigurationRenameProcessor extends RenameProcessor {
+
+ public static final String PROCESSOR_ID =
"org.hibernate.eclipse.console.renameProcessor"; //$NON-NLS-1$
+
+ private ILaunchConfiguration config;
+
+ private String newName;
+
+ public ConsoleConfigurationRenameProcessor(ILaunchConfiguration config, String
newName){
+ assert KnownConfigurations.getInstance().isKnownConfiguration(config.getName());
+ this.config = config;
+ this.newName = newName;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public Change createChange(IProgressMonitor pm) throws CoreException,
OperationCanceledException
+ {
+ // actual renaming processed in DebugPlugin.
+ return new NullChange();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getElements()
+ */
+ @Override
+ public Object[] getElements() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getIdentifier()
+ */
+ @Override
+ public String getIdentifier() {
+ return PROCESSOR_ID;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getProcessorName()
+ */
+ @Override
+ public String getProcessorName() {
+ return Messages.ConsoleConfigurationRenameProcessor_name;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#isApplicable()
+ */
+ @Override
+ public boolean isApplicable() throws CoreException {
+ return true;
+ }
+
+ /* (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 {
+ return new RefactoringStatus();
+ }
+
+ /* (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 {
+ return new RefactoringStatus();
+ }
+
+ /* (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 {
+ List<RefactoringParticipant> participants = new
ArrayList<RefactoringParticipant>();
+ participants.addAll(Arrays.asList(ParticipantManager.loadRenameParticipants(status,
this, config,
+ new RenameArguments(newName, true), new String[0], sharedParticipants)));
+ return (RefactoringParticipant[]) participants.toArray(new
RefactoringParticipant[participants.size()]);
+ }
+
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java 2011-02-11
12:30:01 UTC (rev 29111)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java 2011-02-11
12:54:26 UTC (rev 29112)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Copyright (c) 2007-2011 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,
@@ -30,12 +30,15 @@
import javax.xml.transform.stream.StreamResult;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
@@ -43,6 +46,7 @@
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.JavaRuntime;
@@ -51,9 +55,12 @@
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.model.impl.ExporterFactoryStrings;
+import org.hibernate.eclipse.console.properties.HibernatePropertiesConstants;
import org.hibernate.eclipse.console.utils.LaunchHelper;
import org.hibernate.eclipse.launch.HibernateLaunchConstants;
import org.hibernate.eclipse.launch.IConsoleConfigurationLaunchConstants;
+import org.hibernate.eclipse.nature.HibernateNature;
+import org.osgi.service.prefs.Preferences;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -96,6 +103,10 @@
public static boolean isCodeGenerationConfigAffected(ILaunchConfiguration config, IPath
oldPath) throws CoreException{
return isAttributesAffected(config, oldPath, cgKeys) || isExportersAffected(config,
oldPath);
}
+
+ public static boolean isCodeGenerationConfigAffected(ILaunchConfiguration config, String
oldCCName) throws CoreException{
+ return isAttributesAffected(config, oldCCName,
HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME);
+ }
private static boolean isAttributesAffected(ILaunchConfiguration config, IPath oldPath,
String[] paths) throws CoreException{
String attrib = null;
@@ -107,6 +118,22 @@
return false;
}
+ private static boolean isAttributesAffected(ILaunchConfiguration config, String
oldValue, String attribute) throws CoreException{
+ String value = config.getAttribute(attribute, (String)null);
+ return value == null ? (oldValue == null) : value.equals(oldValue);
+ }
+
+ private static boolean isProjectAffected(IProject project, String oldCCName) throws
CoreException {
+ if (project.isOpen() && project.hasNature(HibernateNature.ID)){
+ IScopeContext scope = new ProjectScope(project);
+
+ Preferences node =
scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE);
+ String defaultConfiguration =
node.get(HibernatePropertiesConstants.DEFAULT_CONFIGURATION, "");
+ return defaultConfiguration.equals(oldCCName);
+ }
+ return false;
+ }
+
@SuppressWarnings("unchecked")
private static boolean isListAttributesAffected(ILaunchConfiguration config, IPath
oldPath, String[] listPaths) throws CoreException{
for (int i = 0; i < listPaths.length; i++) {
@@ -448,6 +475,38 @@
return configs;
}
+ public static IProject[] getAffectedProjects(String oldConsoleConfigurationName){
+ List<IProject> affectedProjects = new ArrayList<IProject>();
+ for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
+ try {
+ if (isProjectAffected(project, oldConsoleConfigurationName)){
+ affectedProjects.add(project);
+ }
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage( ERROR_MESS, e );
+ }
+ }
+ return affectedProjects.toArray(new IProject[affectedProjects.size()]);
+ }
+
+ public static ILaunchConfiguration[] getAffectedCodeGenerationConfigs(String
oldCCName){
+ ILaunchConfiguration[] configs = null;
+ try {
+ configs = LaunchHelper.findCodeGenerationConfigs();
+ List<ILaunchConfiguration> list = new ArrayList<ILaunchConfiguration>();
+ for(int i = 0; i < configs.length && configs[i].exists(); i++) {
+ if (HibernateRefactoringUtil.isCodeGenerationConfigAffected(configs[i], oldCCName))
list.add(configs[i]);
+ }
+ configs = list.toArray(new ILaunchConfiguration[list.size()]);
+ }
+ catch(CoreException e) {
+ configs = new ILaunchConfiguration[0];
+ HibernateConsolePlugin.getDefault().logErrorMessage( ERROR_MESS, e );
+ }
+
+ return configs;
+ }
+
public static ILaunchConfiguration[] getAffectedLaunchConfigurations(IProject project){
ILaunchConfiguration[] configs = null;
try {
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/Messages.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/Messages.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/Messages.java 2011-02-11
12:54:26 UTC (rev 29112)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.launch.core.refactoring;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME =
"org.hibernate.eclipse.launch.core.refactoring.messages"; //$NON-NLS-1$
+ public static String CodeGenerationConsoleNameChange_error_empty_name;
+ public static String CodeGenerationConsoleNameChange_error_null_confi;
+ public static String CodeGenerationConsoleNameChange_update;
+ public static String ConsoleConfigurationRenameParticipant_change_name;
+ public static String ConsoleConfigurationRenameParticipant_name;
+ public static String ConsoleConfigurationRenameParticipant_update_code_generations;
+ public static String ConsoleConfigurationRenameParticipant_update_project_config;
+ public static String ConsoleConfigurationRenameProcessor_name;
+ public static String ProjectDefaultConfigurationChange_error_title;
+ public static String ProjectDefaultConfigurationChange_name;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ProjectDefaultConfigurationChange.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ProjectDefaultConfigurationChange.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ProjectDefaultConfigurationChange.java 2011-02-11
12:54:26 UTC (rev 29112)
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.launch.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.IScopeContext;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.NullChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.swt.widgets.Shell;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.properties.HibernatePropertiesConstants;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class ProjectDefaultConfigurationChange extends Change {
+
+ private IProject project;
+
+ private String newConsoleName;
+
+ public ProjectDefaultConfigurationChange(IProject project, String newCCName){
+ this.project = project;
+ this.newConsoleName = newCCName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#getName()
+ */
+ @Override
+ public String getName() {
+ return Messages.ProjectDefaultConfigurationChange_name + 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();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ try {
+ IScopeContext scope = new ProjectScope(project);
+
+ Preferences node =
scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE);
+ String oldName = node.get(HibernatePropertiesConstants.DEFAULT_CONFIGURATION, null);
+
+ node.putBoolean(HibernatePropertiesConstants.HIBERNATE3_ENABLED, true );
+ node.put(HibernatePropertiesConstants.DEFAULT_CONFIGURATION, newConsoleName );
+ node.flush();
+ return new ProjectDefaultConfigurationChange(project, oldName);
+ } catch (BackingStoreException e) {
+ HibernateConsolePlugin.openError(new Shell(),
Messages.ProjectDefaultConfigurationChange_error_title , e.getLocalizedMessage(), e,
HibernateConsolePlugin.PERFORM_SYNC_EXEC);
+ return new NullChange();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#getModifiedElement()
+ */
+ @Override
+ public Object getModifiedElement() {
+ return project;
+ }
+
+}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/messages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/messages.properties
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/messages.properties 2011-02-11
12:54:26 UTC (rev 29112)
@@ -0,0 +1,10 @@
+CodeGenerationConsoleNameChange_error_empty_name=Console Configuration name can't be
empty
+CodeGenerationConsoleNameChange_error_null_confi=Error while try to rename null Console
Configuration
+CodeGenerationConsoleNameChange_update=Update {0} Code Generation Configuration
+ConsoleConfigurationRenameParticipant_change_name=Console Configuration Rename Change
+ConsoleConfigurationRenameParticipant_name=Console Configuration Rename Participant
+ConsoleConfigurationRenameParticipant_update_code_generations=Update Code Generation
Configurations
+ConsoleConfigurationRenameParticipant_update_project_config=Update Default Project
Console Configurations
+ConsoleConfigurationRenameProcessor_name=Console Configuration Rename Processor
+ProjectDefaultConfigurationChange_error_title=Error
+ProjectDefaultConfigurationChange_name=Change associated Console Configuration in project