Author: dgeraskov
Date: 2008-11-24 09:28:10 -0500 (Mon, 24 Nov 2008)
New Revision: 11978
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameChange.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameParticipant.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/launch/core/refactoring/HibernateRefactoringUtil.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3179
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2008-11-24
13:58:02 UTC (rev 11977)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2008-11-24
14:28:10 UTC (rev 11978)
@@ -669,6 +669,19 @@
</with>
</enablement>
</renameParticipant>
+ <renameParticipant
+
class="org.hibernate.eclipse.launch.core.refactoring.ConnectionProfileRenameParticipant"
+
id="org.hibernate.eclipse.console.renameConnectionProfileParticipant"
+ name="name">
+ <enablement>
+ <with
+ variable="element">
+ <instanceof
+
value="org.eclipse.datatools.connectivity.IConnectionProfile">
+ </instanceof>
+ </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 2008-11-24
13:58:02 UTC (rev 11977)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java 2008-11-24
14:28:10 UTC (rev 11978)
@@ -516,6 +516,9 @@
public static String HibernateNature_reading_database_metadata_for;
public static String BasicWorkbenchAdapter_error_while_opening_configuration;
+
+ public static String ConnectionProfileRenameChange_update_connection_profile_name;
+ public static String ConnectionProfileRenameParticipant_launch_configurations_updates;
//
static {
// initialize resource bundle
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 2008-11-24
13:58:02 UTC (rev 11977)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2008-11-24
14:28:10 UTC (rev 11978)
@@ -507,3 +507,6 @@
HibernateNature_exception_when_trying_to_locate_hibernate_nature=Exception when trying to
locate Hibernate Nature
HibernateNature_reading_database_metadata=Reading database metadata
HibernateNature_reading_database_metadata_for=Reading database metadata for
+
+ConnectionProfileRenameChange_update_connection_profile_name=Update connection profile
name in launch configuration
+ConnectionProfileRenameParticipant_launch_configurations_updates=Launch Configurations
updates
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameChange.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameChange.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameChange.java 2008-11-24
14:28:10 UTC (rev 11978)
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2007-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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.launch.core.refactoring;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+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.datatools.connectivity.IConnectionProfile;
+import
org.eclipse.datatools.connectivity.internal.ui.refactoring.ConnectionProfileChange;
+import org.eclipse.debug.core.DebugPlugin;
+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.ltk.core.refactoring.participants.RenameArguments;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.launch.IConsoleConfigurationLaunchConstants;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class ConnectionProfileRenameChange extends ConnectionProfileChange {
+
+
+ private ILaunchConfiguration fLaunchConfiguration;
+
+ private RenameArguments fRenameArguments;
+
+ /**
+ * @param source
+ * @param renameArguments
+ */
+ public ConnectionProfileRenameChange(ILaunchConfiguration config, IConnectionProfile
source, RenameArguments renameArguments) {
+ super(source, null);
+ this.fLaunchConfiguration = config;
+ this.fRenameArguments = renameArguments;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#getName()
+ */
+ @Override
+ public String getName() {
+ return
HibernateConsoleMessages.ConnectionProfileRenameChange_update_connection_profile_name;
+ }
+
+ /* (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 {
+ if (fLaunchConfiguration.exists()){
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IWorkspaceRoot root = workspace.getRoot();
+ IPath rootLoacation = root.getLocation();
+ IPath location = fLaunchConfiguration.getLocation();
+
+ IFile[] files = root.findFilesForLocation(rootLoacation.append(location));
+ if (files.length > 0){
+ fLaunchConfiguration =
DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(files[0]);
+ }
+
+ final ILaunchConfigurationWorkingCopy wc = fLaunchConfiguration.getWorkingCopy();
+ String oldName =
wc.getAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME,
"");
+ wc.setAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME,
fRenameArguments.getNewName());
+ ILaunchConfiguration newConfig = wc.isDirty() ? wc.doSave() : fLaunchConfiguration;
+ RenameArguments args = new RenameArguments(oldName, true);
+ return new ConnectionProfileRenameChange(newConfig, mSource, args);
+ }
+
+ return null;
+ }
+
+}
Property changes on:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameChange.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
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
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameParticipant.java 2008-11-24
14:28:10 UTC (rev 11978)
@@ -0,0 +1,52 @@
+package org.hibernate.eclipse.launch.core.refactoring;
+
+import java.util.ArrayList;
+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.datatools.connectivity.IConnectionProfile;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.ltk.core.refactoring.Change;
+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.eclipse.console.HibernateConsoleMessages;
+
+public class ConnectionProfileRenameParticipant extends RenameParticipant {
+
+ IConnectionProfile profile;
+
+ @Override
+ public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext
context)
+ throws OperationCanceledException {
+ return new RefactoringStatus();
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor pm) throws CoreException,
OperationCanceledException {
+ ILaunchConfiguration[] configs =
HibernateRefactoringUtil.getAffectedLaunchConfigurations(profile);
+
+ List<Change> changes = new ArrayList<Change>();
+ Change change = null;
+ for (int i= 0; i < configs.length; i++) {
+ change = new ConnectionProfileRenameChange(configs[i], profile, getArguments());
+ changes.add(change);
+ }
+
+ return HibernateRefactoringUtil.createChangesFromList(changes, getName());
+ }
+
+ @Override
+ public String getName() {
+ return
HibernateConsoleMessages.ConnectionProfileRenameParticipant_launch_configurations_updates;
+ }
+
+ @Override
+ protected boolean initialize(Object element) {
+ profile = (IConnectionProfile) element;
+ return true;
+ }
+
+}
Property changes on:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameParticipant.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
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 2008-11-24
13:58:02 UTC (rev 11977)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java 2008-11-24
14:28:10 UTC (rev 11978)
@@ -33,10 +33,10 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.jdt.internal.launching.LaunchingPlugin;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.JavaRuntime;
@@ -321,7 +321,7 @@
try {
configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations();
List<ILaunchConfiguration> list = new ArrayList<ILaunchConfiguration>();
- for(int i = 0; i < configs.length; i++) {//refactor only hibernate launch
configurations
+ for(int i = 0; i < configs.length && configs[i].exists(); i++) {//refactor
only hibernate launch configurations
if
(!ICodeGenerationLaunchConstants.CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID.equals(configs[i].getType().getIdentifier()))
continue;
if (HibernateRefactoringUtil.isConfigurationAffected(configs[i], path))
list.add(configs[i]);
}
@@ -334,7 +334,27 @@
return configs;
}
+
+ public static ILaunchConfiguration[] getAffectedLaunchConfigurations(IConnectionProfile
profile){
+ ILaunchConfiguration[] configs = null;
+ try {
+ configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations();
+ List<ILaunchConfiguration> list = new ArrayList<ILaunchConfiguration>();
+ for(int i = 0; i < configs.length && configs[i].exists(); i++) {//refactor
only hibernate launch configurations
+ if
(!ICodeGenerationLaunchConstants.CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID.equals(configs[i].getType().getIdentifier()))
continue;
+ if
(profile.getName().equals(configs[i].getAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME,
"")))
+ 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;
+ }
+
/**
* @param changes - List of Change objects
* @return