Author: vyemialyanchyk
Date: 2009-12-03 12:29:43 -0500 (Thu, 03 Dec 2009)
New Revision: 19031
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/CloseConfigAction.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfigClassLoader.java
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.properties
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/viewers/xpl/MTreeViewer.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/execution/DefaultExecutionContext.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-1012 &
http://opensource.atlassian.com/projects/hibernate/browse/HBX-936 - fix
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfigClassLoader.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfigClassLoader.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfigClassLoader.java 2009-12-03
17:29:43 UTC (rev 19031)
@@ -0,0 +1,286 @@
+/*******************************************************************************
+ * 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.console;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Vector;
+import java.util.jar.JarFile;
+
+import org.hibernate.util.ReflectHelper;
+
+/**
+ * Workaround for jdk disgrace with open jar files & native libs,
+ * which is a reason of locked, "undelete" files.
+ *
+ * @author Vitali Yemialyanchyk
+ */
+public class ConsoleConfigClassLoader extends URLClassLoader {
+
+ protected HashSet<String> setJarFileNames2Close = new HashSet<String>();
+
+ public ConsoleConfigClassLoader(URL[] urls, ClassLoader parent) {
+ super(urls, parent);
+ }
+
+ public void close() {
+ setJarFileNames2Close.clear();
+ closeClassLoader(this);
+ finalizeNativeLibs(this);
+ cleanupJarFileFactory();
+ }
+
+ /**
+ * cleanup jar file factory cache
+ */
+ @SuppressWarnings({ "nls", "unchecked" })
+ public boolean cleanupJarFileFactory()
+ {
+ boolean res = false;
+ Class classJarURLConnection = null;
+ try {
+ classJarURLConnection =
ReflectHelper.classForName("sun.net.www.protocol.jar.JarURLConnection");
+ } catch (ClassNotFoundException e) {
+ //ignore
+ }
+ if (classJarURLConnection == null) {
+ return res;
+ }
+ Field f = null;
+ try {
+ f = classJarURLConnection.getDeclaredField("factory");
+ } catch (NoSuchFieldException e) {
+ //ignore
+ }
+ if (f == null) {
+ return res;
+ }
+ f.setAccessible(true);
+ Object obj = null;
+ try {
+ obj = f.get(null);
+ } catch (IllegalAccessException e) {
+ //ignore
+ }
+ if (obj == null) {
+ return res;
+ }
+ Class classJarFileFactory = obj.getClass();
+ //
+ HashMap fileCache = null;
+ try {
+ f = classJarFileFactory.getDeclaredField("fileCache");
+ f.setAccessible(true);
+ obj = f.get(null);
+ if (obj instanceof HashMap) {
+ fileCache = (HashMap)obj;
+ }
+ } catch (NoSuchFieldException e) {
+ } catch (IllegalAccessException e) {
+ //ignore
+ }
+ HashMap urlCache = null;
+ try {
+ f = classJarFileFactory.getDeclaredField("urlCache");
+ f.setAccessible(true);
+ obj = f.get(null);
+ if (obj instanceof HashMap) {
+ urlCache = (HashMap)obj;
+ }
+ } catch (NoSuchFieldException e) {
+ } catch (IllegalAccessException e) {
+ //ignore
+ }
+ if (urlCache != null) {
+ HashMap urlCacheTmp = (HashMap)urlCache.clone();
+ Iterator it = urlCacheTmp.keySet().iterator();
+ while (it.hasNext()) {
+ obj = it.next();
+ if (!(obj instanceof JarFile)) {
+ continue;
+ }
+ JarFile jarFile = (JarFile)obj;
+ if (setJarFileNames2Close.contains(jarFile.getName())) {
+ try {
+ jarFile.close();
+ } catch (IOException e) {
+ //ignore
+ }
+ if (fileCache != null) {
+ fileCache.remove(urlCache.get(jarFile));
+ }
+ urlCache.remove(jarFile);
+ }
+ }
+ res = true;
+ } else if (fileCache != null) {
+ // urlCache := null
+ HashMap fileCacheTmp = (HashMap)fileCache.clone();
+ Iterator it = fileCacheTmp.keySet().iterator();
+ while (it.hasNext()) {
+ Object key = it.next();
+ obj = fileCache.get(key);
+ if (!(obj instanceof JarFile)) {
+ continue;
+ }
+ JarFile jarFile = (JarFile)obj;
+ if (setJarFileNames2Close.contains(jarFile.getName())) {
+ try {
+ jarFile.close();
+ } catch (IOException e) {
+ //ignore
+ }
+ fileCache.remove(key);
+ }
+ }
+ res = true;
+ }
+ setJarFileNames2Close.clear();
+ return res;
+ }
+
+ /**
+ * close jar files of cl
+ * @param cl
+ * @return
+ */
+ @SuppressWarnings( { "nls", "unchecked" })
+ public boolean closeClassLoader(ClassLoader cl) {
+ boolean res = false;
+ if (cl == null) {
+ return res;
+ }
+ Class classURLClassLoader = URLClassLoader.class;
+ Field f = null;
+ try {
+ f = classURLClassLoader.getDeclaredField("ucp");
+ } catch (NoSuchFieldException e1) {
+ //ignore
+ }
+ if (f != null) {
+ f.setAccessible(true);
+ Object obj = null;
+ try {
+ obj = f.get(cl);
+ } catch (IllegalAccessException e1) {
+ //ignore
+ }
+ if (obj != null) {
+ final Object ucp = obj;
+ f = null;
+ try {
+ f = ucp.getClass().getDeclaredField("loaders");
+ } catch (NoSuchFieldException e1) {
+ //ignore
+ }
+ if (f != null) {
+ f.setAccessible(true);
+ ArrayList loaders = null;
+ try {
+ loaders = (ArrayList) f.get(ucp);
+ res = true;
+ } catch (IllegalAccessException e1) {
+ //ignore
+ }
+ for (int i = 0; loaders != null && i < loaders.size(); i++) {
+ obj = loaders.get(i);
+ f = null;
+ try {
+ f = obj.getClass().getDeclaredField("jar");
+ } catch (NoSuchFieldException e) {
+ //ignore
+ }
+ if (f != null) {
+ f.setAccessible(true);
+ try {
+ obj = f.get(obj);
+ } catch (IllegalAccessException e1) {
+ // ignore
+ }
+ if (obj instanceof JarFile) {
+ final JarFile jarFile = (JarFile)obj;
+ setJarFileNames2Close.add(jarFile.getName());
+ //try {
+ // jarFile.getManifest().clear();
+ //} catch (IOException e) {
+ // // ignore
+ //}
+ try {
+ jarFile.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return res;
+ }
+
+ /**
+ * finalize native libraries
+ * @param cl
+ * @return
+ */
+ @SuppressWarnings({ "nls", "unchecked" })
+ public boolean finalizeNativeLibs(ClassLoader cl) {
+ boolean res = false;
+ Class classClassLoader = ClassLoader.class;
+ java.lang.reflect.Field nativeLibraries = null;
+ try {
+ nativeLibraries = classClassLoader.getDeclaredField("nativeLibraries");
+ } catch (NoSuchFieldException e1) {
+ //ignore
+ }
+ if (nativeLibraries == null) {
+ return res;
+ }
+ nativeLibraries.setAccessible(true);
+ Object obj = null;
+ try {
+ obj = nativeLibraries.get(cl);
+ } catch (IllegalAccessException e1) {
+ //ignore
+ }
+ if (!(obj instanceof Vector)) {
+ return res;
+ }
+ res = true;
+ Vector java_lang_ClassLoader_NativeLibrary = (Vector)obj;
+ for (Object lib : java_lang_ClassLoader_NativeLibrary) {
+ java.lang.reflect.Method finalize = null;
+ try {
+ finalize = lib.getClass().getDeclaredMethod("finalize", new Class[0]);
+ } catch (NoSuchMethodException e) {
+ //ignore
+ }
+ if (finalize != null) {
+ finalize.setAccessible(true);
+ try {
+ finalize.invoke(lib, new Object[0]);
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
+ //ignore
+ }
+ }
+ }
+ return res;
+ }
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2009-12-03
17:29:10 UTC (rev 19030)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2009-12-03
17:29:43 UTC (rev 19031)
@@ -29,7 +29,8 @@
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
-import java.net.URLClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Driver;
@@ -37,6 +38,7 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -74,6 +76,7 @@
public class ConsoleConfiguration implements ExecutionContextHolder {
private ExecutionContext executionContext;
+ private ConsoleConfigClassLoader classLoader = null;
private Map<String, FakeDelegatingDriver> fakeDrivers = new HashMap<String,
FakeDelegatingDriver>();
@@ -106,8 +109,38 @@
// reseting state
configuration = null;
closeSessionFactory();
+ if (executionContext != null) {
+ executionContext.execute(new ExecutionContext.Command() {
+
+ public Object execute() {
+ Iterator<FakeDelegatingDriver> it = fakeDrivers.values().iterator();
+ while (it.hasNext()) {
+ try {
+ DriverManager.deregisterDriver(it.next());
+ } catch (SQLException e) {
+ // ignore
+ }
+ }
+ return null;
+ }
+ });
+ }
+ fakeDrivers.clear();
+ cleanUpClassLoader();
+ executionContext = null;
}
+ public void cleanUpClassLoader() {
+ ClassLoader classLoaderTmp = classLoader;
+ while (classLoaderTmp != null) {
+ if (classLoaderTmp instanceof ConsoleConfigClassLoader) {
+ ((ConsoleConfigClassLoader)classLoaderTmp).close();
+ }
+ classLoaderTmp = classLoaderTmp.getParent();
+ }
+ classLoader = null;
+ }
+
public void build() {
configuration = buildWith(null, true);
fireConfigurationBuilt();
@@ -237,39 +270,51 @@
}
return customClassPathURLs;
}
+
+ protected ConsoleConfigClassLoader createClassLoader() {
+ final URL[] customClassPathURLs = getCustomClassPathURLs();
+ ConsoleConfigClassLoader classLoader = AccessController.doPrivileged(new
PrivilegedAction<ConsoleConfigClassLoader>() {
+ public ConsoleConfigClassLoader run() {
+ return new ConsoleConfigClassLoader(customClassPathURLs, getParentClassLoader()) {
+ protected Class<?> findClass(String name) throws ClassNotFoundException {
+ try {
+ return super.findClass(name);
+ } catch (ClassNotFoundException cnfe) {
+ throw cnfe;
+ }
+ }
+
+ protected synchronized Class<?> loadClass(String name, boolean resolve) throws
ClassNotFoundException {
+ try {
+ return super.loadClass(name, resolve);
+ } catch (ClassNotFoundException cnfe) {
+ throw cnfe;
+ }
+ }
+
+ public Class<?> loadClass(String name) throws ClassNotFoundException {
+ try {
+ return super.loadClass(name);
+ } catch (ClassNotFoundException cnfe) {
+ throw cnfe;
+ }
+ }
+ };
+ }
+ });
+ return classLoader;
+ }
/**
* @return
*
*/
public Configuration buildWith(final Configuration cfg, final boolean includeMappings)
{
- URL[] customClassPathURLs = getCustomClassPathURLs();
- executionContext = new DefaultExecutionContext( getName(), new URLClassLoader(
customClassPathURLs, getParentClassLoader() ) {
- protected Class<?> findClass(String name) throws ClassNotFoundException {
- try {
- return super.findClass( name );
- } catch(ClassNotFoundException cnfe) {
- throw cnfe;
- }
- }
+ if (classLoader == null) {
+ classLoader = createClassLoader();
+ }
+ executionContext = new DefaultExecutionContext(getName(), classLoader);
- protected synchronized Class<?> loadClass(String name, boolean resolve) throws
ClassNotFoundException {
- try {
- return super.loadClass( name, resolve );
- } catch(ClassNotFoundException cnfe) {
- throw cnfe;
- }
- }
-
- public Class<?> loadClass(String name) throws ClassNotFoundException {
- try {
- return super.loadClass( name );
- } catch(ClassNotFoundException cnfe) {
- throw cnfe;
- }
- }
- });
-
Configuration result = (Configuration) executionContext.execute(new
ExecutionContext.Command() {
public Object execute() {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/execution/DefaultExecutionContext.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/execution/DefaultExecutionContext.java 2009-12-03
17:29:10 UTC (rev 19030)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/execution/DefaultExecutionContext.java 2009-12-03
17:29:43 UTC (rev 19031)
@@ -21,7 +21,6 @@
*/
package org.hibernate.console.execution;
-import java.net.URLClassLoader;
import java.util.Map;
import java.util.WeakHashMap;
@@ -31,13 +30,13 @@
public class DefaultExecutionContext implements ExecutionContext {
- final private URLClassLoader configurationClassLoader;
+ final private ClassLoader configurationClassLoader;
private volatile int installs;
private Map<Thread, ClassLoader> previousLoaders = new WeakHashMap<Thread,
ClassLoader>();
final String key;
- public DefaultExecutionContext(String key, URLClassLoader loader) {
+ public DefaultExecutionContext(String key, ClassLoader loader) {
configurationClassLoader = loader;
this.key = key;
}
@@ -45,7 +44,7 @@
/* (non-Javadoc)
* @see org.hibernate.console.IExecutionContext#installLoader()
*/
- public void installLoader() {
+ public synchronized void installLoader() {
installs++;
if(configurationClassLoader!=null &&
Thread.currentThread().getContextClassLoader() != configurationClassLoader) {
previousLoaders.put(Thread.currentThread(),
Thread.currentThread().getContextClassLoader() );
@@ -57,7 +56,7 @@
/* (non-Javadoc)
* @see
org.hibernate.console.IExecutionContext#execute(org.hibernate.console.ExecutionContext.Command)
*/
- public Object execute(Command c) {
+ public synchronized Object execute(Command c) {
try {
CurrentContext.push( key );
installLoader();
@@ -72,7 +71,7 @@
/* (non-Javadoc)
* @see org.hibernate.console.IExecutionContext#uninstallLoader()
*/
- public void uninstallLoader() {
+ public synchronized void uninstallLoader() {
installs--; // TODO: make more safe (synchronized) bookkeeping of the classloader
installation.
if(installs==0) {
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 2009-12-03
17:29:10 UTC (rev 19030)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java 2009-12-03
17:29:43 UTC (rev 19031)
@@ -49,6 +49,7 @@
public static String ConsoleConfigurationBasedAction_problem_while_executing;
public static String CriteriaEditorAction_hibernate_criteria_editor;
public static String CriteriaEditorAction_open_hibernate_criteria_editor;
+ public static String CloseConfigAction_close_config;
public static String DeleteConfigurationAction_delete_config;
public static String DeleteConfigurationAction_delete_console_config;
public static String DeleteConfigurationAction_do_you_wish_del_selected_config;
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 2009-12-03
17:29:10 UTC (rev 19030)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2009-12-03
17:29:43 UTC (rev 19031)
@@ -42,6 +42,7 @@
ConsoleConfigurationBasedAction_problem_while_executing=Problem while executing {0}
({1})
CriteriaEditorAction_hibernate_criteria_editor=Hibernate Criteria Editor
CriteriaEditorAction_open_hibernate_criteria_editor=Open Hibernate Criteria Editor
+CloseConfigAction_close_config=Close Configuration
DeleteConfigurationAction_delete_config=Delete Configuration
DeleteConfigurationAction_delete_console_config=Delete console configuration
DeleteConfigurationAction_do_you_wish_del_selected_config=Do you wish to delete the
selected console configuration
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/CloseConfigAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/CloseConfigAction.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/CloseConfigAction.java 2009-12-03
17:29:43 UTC (rev 19031)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.console.actions;
+
+import java.util.Iterator;
+
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.ui.actions.SelectionListenerAction;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.ImageConstants;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.utils.EclipseImages;
+import org.hibernate.eclipse.console.viewers.xpl.MTreeViewer;
+
+/**
+ * @author Vitali Yemialyanchyk
+ */
+public class CloseConfigAction extends SelectionListenerAction {
+
+ public static final String CLOSECONFIG_ACTIONID = "actionid.closeconfig";
//$NON-NLS-1$
+
+ private StructuredViewer viewer;
+
+ public CloseConfigAction(StructuredViewer sv) {
+ super(HibernateConsoleMessages.CloseConfigAction_close_config);
+ setEnabled(false);
+ this.viewer = sv;
+ setText(HibernateConsoleMessages.CloseConfigAction_close_config);
+ setImageDescriptor(EclipseImages.getImageDescriptor(ImageConstants.CLOSE));
+ setId(CLOSECONFIG_ACTIONID);
+ }
+
+ public void run() {
+ doCloseConfig();
+ }
+
+ protected void doCloseConfig() {
+ for (Iterator<?> i = getSelectedNonResources().iterator(); i.hasNext();) {
+ Object node = i.next();
+ if (!(node instanceof ConsoleConfiguration)) {
+ continue;
+ }
+ ConsoleConfiguration config = (ConsoleConfiguration) node;
+ ((MTreeViewer)viewer).clearChildren(null);
+ config.reset();
+ viewer.refresh(node);
+ }
+ }
+
+ @Override
+ public boolean isEnabled() {
+ boolean res = false;
+ for (Iterator<?> i = getSelectedNonResources().iterator(); i.hasNext();) {
+ Object node = i.next();
+ if (!(node instanceof ConsoleConfiguration)) {
+ continue;
+ }
+ ConsoleConfiguration config = (ConsoleConfiguration) node;
+ if (config.hasConfiguration()) {
+ res = true;
+ }
+ }
+ //return res;
+ return true;
+ }
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/viewers/xpl/MTreeViewer.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/viewers/xpl/MTreeViewer.java 2009-12-03
17:29:10 UTC (rev 19030)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/viewers/xpl/MTreeViewer.java 2009-12-03
17:29:43 UTC (rev 19031)
@@ -19,6 +19,7 @@
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Item;
+import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;
/**
@@ -46,6 +47,17 @@
super(parent, style);
}
+ public void clearChildren(Object node) {
+ Widget[] items = getChildren(node == null ? getTree() : (Widget)node);
+ for (int j = 0; j < items.length; j++) {
+ clearChildren(items[j]);
+ if (items[j] instanceof TreeItem) {
+ ((TreeItem)items[j]).setExpanded(false);
+ ((TreeItem)items[j]).clearAll(true);
+ }
+ }
+ }
+
/**
* Adds the given child elements to this viewer as children of the given
* parent element. If this viewer does not have a sorter, the elements are
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java 2009-12-03
17:29:10 UTC (rev 19030)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java 2009-12-03
17:29:43 UTC (rev 19031)
@@ -34,6 +34,7 @@
import org.eclipse.ui.actions.SelectionListenerAction;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.eclipse.console.actions.AddConfigurationAction;
+import org.hibernate.eclipse.console.actions.CloseConfigAction;
import org.hibernate.eclipse.console.actions.CriteriaEditorAction;
import org.hibernate.eclipse.console.actions.DeleteConfigurationAction;
import org.hibernate.eclipse.console.actions.EditConsoleConfiguration;
@@ -76,6 +77,7 @@
public static final String GROUP_OTHER_EDITORS_LAST =
"group.otherEditors.last"; //$NON-NLS-1$
private Action addConfigurationAction;
+ private SelectionListenerAction closeConfigAction;
private SelectionListenerAction deleteConfigurationAction;
private SelectionListenerAction refreshAction;
//private SelectionListenerAction connectAction;
@@ -93,6 +95,9 @@
this.selectionProvider = selectionProvider;
addConfigurationAction = new AddConfigurationAction(part);
+ closeConfigAction = new CloseConfigAction(selectionProvider);
+ selectionProvider.addSelectionChangedListener(closeConfigAction);
+
deleteConfigurationAction = new DeleteConfigurationAction(selectionProvider);
selectionProvider.addSelectionChangedListener(deleteConfigurationAction);
IActionBars actionBars= part.getViewSite().getActionBars();
@@ -133,6 +138,7 @@
public void dispose() {
super.dispose();
+ selectionProvider.removeSelectionChangedListener(closeConfigAction);
selectionProvider.removeSelectionChangedListener(deleteConfigurationAction);
selectionProvider.removeSelectionChangedListener(refreshAction);
selectionProvider.removeSelectionChangedListener(reloadConfigurationAction);
@@ -160,6 +166,7 @@
if (first instanceof ConsoleConfiguration) {
menu.appendToGroup(GROUP_CONSOLE_CONFIG, reloadConfigurationAction);
menu.appendToGroup(GROUP_CONSOLE_CONFIG, editConfigurationAction);
+ menu.appendToGroup(GROUP_CONSOLE_CONFIG, closeConfigAction);
menu.appendToGroup(GROUP_CONSOLE_CONFIG, deleteConfigurationAction);
}
menu.add(new GroupMarker(GROUP_CONSOLE_CONFIG_LAST));