Author: vyemialyanchyk
Date: 2010-12-08 10:46:33 -0500 (Wed, 08 Dec 2010)
New Revision: 27235
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/SchemaExportAction.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
Log:
https://jira.jboss.org/browse/JBIDE-7805 - fixed
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 2010-12-08
15:20:54 UTC (rev 27234)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2010-12-08
15:46:33 UTC (rev 27235)
@@ -32,7 +32,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import org.hibernate.Session;
@@ -247,7 +246,7 @@
int execcount;
- List<ConsoleConfigurationListener> consoleCfgListeners = new
ArrayList<ConsoleConfigurationListener>();
+ ArrayList<ConsoleConfigurationListener> consoleCfgListeners = new
ArrayList<ConsoleConfigurationListener>();
public QueryPage executeHQLQuery(final String hql) {
return executeHQLQuery(hql, new QueryInputModel());
@@ -281,32 +280,38 @@
});
}
+ @SuppressWarnings("unchecked")
+ // clone listeners to thread safe iterate over array
+ private ArrayList<ConsoleConfigurationListener> cloneConsoleCfgListeners() {
+ return (ArrayList<ConsoleConfigurationListener>)consoleCfgListeners.clone();
+ }
+
private void fireConfigurationBuilt() {
- for (ConsoleConfigurationListener view : consoleCfgListeners) {
+ for (ConsoleConfigurationListener view : cloneConsoleCfgListeners()) {
view.configurationBuilt(this);
}
}
private void fireConfigurationReset() {
- for (ConsoleConfigurationListener view : consoleCfgListeners) {
+ for (ConsoleConfigurationListener view : cloneConsoleCfgListeners()) {
view.configurationReset(this);
}
}
private void fireQueryPageCreated(QueryPage qp) {
- for (ConsoleConfigurationListener view : consoleCfgListeners) {
+ for (ConsoleConfigurationListener view : cloneConsoleCfgListeners()) {
view.queryPageCreated(qp);
}
}
private void fireFactoryBuilt() {
- for (ConsoleConfigurationListener view : consoleCfgListeners) {
+ for (ConsoleConfigurationListener view : cloneConsoleCfgListeners()) {
view.sessionFactoryBuilt(this, sessionFactory);
}
}
private void fireFactoryClosing(SessionFactory sessionFactory2) {
- for (ConsoleConfigurationListener view : consoleCfgListeners) {
+ for (ConsoleConfigurationListener view : cloneConsoleCfgListeners()) {
view.sessionFactoryClosing(this, sessionFactory2);
}
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/SchemaExportAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/SchemaExportAction.java 2010-12-08
15:20:54 UTC (rev 27234)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/SchemaExportAction.java 2010-12-08
15:46:33 UTC (rev 27235)
@@ -21,16 +21,23 @@
*/
package org.hibernate.eclipse.console.views;
+import java.util.HashSet;
import java.util.Iterator;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
import org.hibernate.HibernateException;
+import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.ConsoleConfigurationListener;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.KnownConfigurationsListener;
+import org.hibernate.console.QueryPage;
import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
@@ -41,11 +48,13 @@
* @author max
*
*/
-public class SchemaExportAction extends ConsoleConfigurationBasedAction {
+public class SchemaExportAction extends ConsoleConfigurationBasedAction implements
ConsoleConfigurationListener, KnownConfigurationsListener {
public static final String SCHEMAEXPORT_ACTIONID = "actionid.schemaexport";
//$NON-NLS-1$
private StructuredViewer viewer;
+
+ private HashSet<ConsoleConfiguration> vecMonitorConsoleConfigs = new
HashSet<ConsoleConfiguration>();
/**
* @param text
@@ -53,6 +62,7 @@
protected SchemaExportAction(String text) {
super( text );
setId(SCHEMAEXPORT_ACTIONID);
+ KnownConfigurations.getInstance().addConsoleConfigurationListener(this);
}
/**
@@ -62,6 +72,7 @@
super( HibernateConsoleMessages.SchemaExportAction_run_schemaexport );
this.viewer = selectionProvider;
setId(SCHEMAEXPORT_ACTIONID);
+ KnownConfigurations.getInstance().addConsoleConfigurationListener(this);
}
/**
@@ -130,13 +141,69 @@
}
}
}
+
+ @SuppressWarnings("unchecked")
+ private HashSet<ConsoleConfiguration> cloneMonitorConsoleConfigs() {
+ return (HashSet<ConsoleConfiguration>)vecMonitorConsoleConfigs.clone();
+ }
+
+ @SuppressWarnings("rawtypes")
+ protected void clearCache() {
+ final IStructuredSelection selection = getStructuredSelection();
+ HashSet<ConsoleConfiguration> vecMonitorConsoleConfigsTmp =
+ cloneMonitorConsoleConfigs();
+ for (ConsoleConfiguration consoleConfig : vecMonitorConsoleConfigsTmp) {
+ consoleConfig.removeConsoleConfigurationListener(this);
+ }
+ vecMonitorConsoleConfigsTmp.clear();
+ for (Iterator i = selection.iterator(); i.hasNext(); ) {
+ Object obj = i.next();
+ if (obj instanceof ConsoleConfiguration) {
+ ConsoleConfiguration consoleConfig = (ConsoleConfiguration)obj;
+ vecMonitorConsoleConfigsTmp.add(consoleConfig);
+ consoleConfig.addConsoleConfigurationListener(this);
+ }
+ }
+ vecMonitorConsoleConfigs = vecMonitorConsoleConfigsTmp;
+ super.clearCache();
+ }
/*
* (non-Javadoc)
*
* @see
org.hibernate.eclipse.console.actions.SessionFactoryBasedAction#updateState(org.hibernate.console.ConsoleConfiguration)
*/
- protected boolean updateState(ConsoleConfiguration consoleConfiguration) {
- return consoleConfiguration.hasConfiguration();
+ protected boolean updateState(ConsoleConfiguration ccfg) {
+ return ccfg.hasConfiguration();
}
+
+ public void updateEnableState() {
+ selectionChanged(getStructuredSelection());
+ }
+
+ public void queryPageCreated(QueryPage qp) {
+ }
+
+ public void sessionFactoryBuilt(ConsoleConfiguration ccfg, SessionFactory
builtSessionFactory) {
+ }
+
+ public void sessionFactoryClosing(ConsoleConfiguration ccfg, SessionFactory
aboutToCloseFactory) {
+ }
+
+ public void configurationBuilt(ConsoleConfiguration ccfg) {
+ updateEnableState();
+ }
+
+ public void configurationReset(ConsoleConfiguration ccfg) {
+ updateEnableState();
+ }
+
+ public void configurationAdded(ConsoleConfiguration root) {
+ }
+
+ public void configurationRemoved(ConsoleConfiguration ccfg, boolean forUpdate) {
+ if (vecMonitorConsoleConfigs.remove(ccfg)) {
+ ccfg.removeConsoleConfigurationListener(this);
+ }
+ }
}