Author: max.andersen(a)jboss.com
Date: 2007-07-30 13:00:23 -0400 (Mon, 30 Jul 2007)
New Revision: 2727
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsolePlugin.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java
Log:
fixed JBIDE-625 Hibernate Configurations can't be deleted
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java 2007-07-30
16:37:04 UTC (rev 2726)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java 2007-07-30
17:00:23 UTC (rev 2727)
@@ -53,6 +53,7 @@
import org.hibernate.SessionFactory;
import org.hibernate.console.node.BaseNode;
import org.hibernate.console.node.ConfigurationListNode;
+import org.hibernate.eclipse.HibernatePlugin;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -145,7 +146,7 @@
// Cache the location instance for later retrieval
getRepositoriesMap().put(configuration.getName(), configuration);
configuration.addConsoleConfigurationListener(sfListener);
- //TODO: location.storePreferences();
+
existingConfiguration = configuration;
}
@@ -180,6 +181,7 @@
});
oldConfig.reset();
removeLoggingStream( oldConfig );
+
}
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 2007-07-30
16:37:04 UTC (rev 2726)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsolePlugin.java 2007-07-30
17:00:23 UTC (rev 2727)
@@ -51,9 +51,11 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.hibernate.HibernateException;
+import org.hibernate.SessionFactory;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.HibernateConsoleRuntimeException;
import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.KnownConfigurationsListener;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
import org.hibernate.eclipse.console.workbench.ConfigurationAdapterFactory;
import org.hibernate.eclipse.criteriaeditor.CriteriaEditorInput;
@@ -85,6 +87,7 @@
private JavaTextTools javaTextTools;
private ILaunchConfigurationListener icl;
+ private KnownConfigurationsListener kcl;
/**
* The constructor.
@@ -118,6 +121,38 @@
private void listenForConfigurations() {
final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ kcl = new KnownConfigurationsListener() {
+
+ public void sessionFactoryClosing(ConsoleConfiguration configuration,
+ SessionFactory closingFactory) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void sessionFactoryBuilt(ConsoleConfiguration ccfg,
+ SessionFactory builtFactory) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void configurationRemoved(ConsoleConfiguration root) {
+ try {
+ removeConfiguration(root.getName());
+ } catch (CoreException e) {
+ logErrorMessage("Could not delete launch configuration for: " +
root.getName(), e);
+ }
+
+ }
+
+ public void configurationAdded(ConsoleConfiguration root) {
+ // TODO Auto-generated method stub
+
+ }
+
+ };
+
+ KnownConfigurations.getInstance().addConsoleConfigurationListener(kcl);
+
icl = new ILaunchConfigurationListener() {
boolean isConsoleConfiguration(ILaunchConfiguration configuration) {
@@ -187,6 +222,7 @@
private void stopListeningForConfigurations() {
final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
launchManager.removeLaunchConfigurationListener( icl );
+ KnownConfigurations.getInstance().removeConfigurationListener(kcl);
}
@@ -203,6 +239,34 @@
}
+ private void removeConfiguration(String name) throws CoreException {
+ ILaunchConfiguration findLaunchConfig = findLaunchConfig(name);
+ if (findLaunchConfig != null) {
+ findLaunchConfig.delete();
+ }
+ }
+
+ private ILaunchConfiguration findLaunchConfig(String name)
+ throws CoreException {
+ ILaunchManager launchManager = DebugPlugin.getDefault()
+ .getLaunchManager();
+ ILaunchConfigurationType launchConfigurationType = launchManager
+ .getLaunchConfigurationType(ICodeGenerationLaunchConstants.CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID);
+ ILaunchConfiguration[] launchConfigurations = launchManager
+ .getLaunchConfigurations(launchConfigurationType);
+
+ for (int i = 0; i < launchConfigurations.length; i++) { // can't believe
+ // there is no
+ // look up by
+ // name API
+ ILaunchConfiguration launchConfiguration = launchConfigurations[i];
+ if (launchConfiguration.getName().equals(name)) {
+ return launchConfiguration;
+ }
+ }
+ return null;
+ }
+
/**
* This method is called when the plug-in is stopped
*/
Show replies by date