[jboss-cvs] jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console ...
Max Rydahl Andersen
mandersen at jboss.com
Tue Feb 20 08:21:51 EST 2007
User: mandersen
Date: 07/02/20 08:21:50
Modified: hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console
HibernateConsoleSaveParticipant.java
ConfigurationCombo.java
EclipseConsoleConfigurationPreferences.java
HibernateConsolePlugin.java
Added: hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console
EclipseLaunchConsoleConfigurationPreferences.java
Log:
HBX-889 sort console configuration lists in ui
HBX-637 Provide ability to import/export console configs
HBX-863 Hibernate Code Generation toolbar group is appearing in all Eclipse perspectives.
Revision Changes Path
1.8 +0 -1 jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleSaveParticipant.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: HibernateConsoleSaveParticipant.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleSaveParticipant.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- HibernateConsoleSaveParticipant.java 17 Nov 2006 19:57:32 -0000 1.7
+++ HibernateConsoleSaveParticipant.java 20 Feb 2007 13:21:50 -0000 1.8
@@ -23,7 +23,6 @@
import java.io.File;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ISaveContext;
import org.eclipse.core.resources.ISaveParticipant;
import org.eclipse.core.resources.ISavedState;
1.2 +1 -1 jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ConfigurationCombo.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ConfigurationCombo.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ConfigurationCombo.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ConfigurationCombo.java 27 Oct 2006 13:35:25 -0000 1.1
+++ ConfigurationCombo.java 20 Feb 2007 13:21:50 -0000 1.2
@@ -65,7 +65,7 @@
protected void populateComboBox() {
ConsoleConfiguration[] configurations = KnownConfigurations
- .getInstance().getConfigurations();
+ .getInstance().getConfigurationsSortedByName();
final String[] names = new String[configurations.length];
for (int i = 0; i < configurations.length; i++) {
names[i] = configurations[i].getName();
1.12 +7 -9 jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseConsoleConfigurationPreferences.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: EclipseConsoleConfigurationPreferences.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseConsoleConfigurationPreferences.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- EclipseConsoleConfigurationPreferences.java 14 Dec 2006 11:52:54 -0000 1.11
+++ EclipseConsoleConfigurationPreferences.java 20 Feb 2007 13:21:50 -0000 1.12
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Collections;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -35,12 +36,15 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.launching.JavaRuntime;
import org.hibernate.console.HibernateConsoleRuntimeException;
import org.hibernate.console.preferences.AbstractConsoleConfigurationPreferences;
+import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
import org.hibernate.eclipse.console.utils.ClassLoaderHelper;
import org.hibernate.eclipse.console.utils.ProjectUtils;
+import org.hibernate.eclipse.launch.IConsoleConfigurationLaunchConstants;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -54,8 +58,8 @@
private IPath cfgFile;
private IPath propertyFilename;
- private IPath[] mappings;
- private IPath[] customClasspath;
+ private IPath[] mappings = new IPath[0];
+ private IPath[] customClasspath = new IPath[0];
public EclipseConsoleConfigurationPreferences(String configName, ConfigurationMode cmode, String projectName, boolean useProjectClasspath, String entityResolver, IPath cfgFile, IPath propertyFilename, IPath[] mappings, IPath[] classpaths, String persistenceUnitName, String namingStrategy) {
@@ -220,10 +224,4 @@
}
}
-
-
-
-
-
-
-}
+ }
1.31 +105 -3 jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsolePlugin.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: HibernateConsolePlugin.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsolePlugin.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- HibernateConsolePlugin.java 23 Oct 2006 13:22:55 -0000 1.30
+++ HibernateConsolePlugin.java 20 Feb 2007 13:21:50 -0000 1.31
@@ -34,6 +34,11 @@
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationListener;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.ui.text.JavaTextTools;
import org.eclipse.jface.dialogs.ErrorDialog;
@@ -54,6 +59,7 @@
import org.hibernate.eclipse.criteriaeditor.CriteriaEditorStorage;
import org.hibernate.eclipse.hqleditor.HQLEditorInput;
import org.hibernate.eclipse.hqleditor.HQLEditorStorage;
+import org.hibernate.eclipse.launch.ICodeGenerationLaunchConstants;
import org.hibernate.eclipse.logging.xpl.EclipseLogger;
import org.osgi.framework.BundleContext;
import org.hibernate.eclipse.logging.PluginLogger;
@@ -77,6 +83,8 @@
private JavaTextTools javaTextTools;
+ private ILaunchConfigurationListener icl;
+
/**
* The constructor.
*/
@@ -85,19 +93,109 @@
plugin = this;
}
+
+
/**
* This method is called upon plug-in activation
*/
public void start(BundleContext context) throws Exception {
super.start(context);
logger=new EclipseLogger(context.getBundle());
- HibernateConsoleSaveParticipant participant = new HibernateConsoleSaveParticipant();
- participant.doStart(this);
+ //HibernateConsoleSaveParticipant participant = new HibernateConsoleSaveParticipant();
+ //participant.doStart(this);
IAdapterManager adapterManager = Platform.getAdapterManager();
ConfigurationAdapterFactory fact = new ConfigurationAdapterFactory();
fact.registerAdapters(adapterManager);
+ loadExistingConfigurations();
+
+ listenForConfigurations();
+
+ }
+
+ private void listenForConfigurations() {
+ final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+
+ icl = new ILaunchConfigurationListener() {
+
+ boolean isConsoleConfiguration(ILaunchConfiguration configuration) {
+ try {
+ return configuration.getType().getIdentifier().equals(ICodeGenerationLaunchConstants.CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID);
+ }
+ catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().log( e );
+ }
+ return false;
+ }
+
+ public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
+ ConsoleConfiguration cfg = KnownConfigurations.getInstance().find( configuration.getName() );
+ if(cfg!=null) {
+ KnownConfigurations.getInstance().removeConfiguration( cfg );
+ }
+ }
+
+ public void launchConfigurationChanged(ILaunchConfiguration configuration) {
+ if(configuration.isWorkingCopy()) {
+ return;
+ }
+ if(isConsoleConfiguration( configuration )) {
+ KnownConfigurations instance = KnownConfigurations.getInstance();
+ ConsoleConfiguration oldcfg = instance.find( configuration.getName() );
+ if(oldcfg!=null) {
+ oldcfg.reset(); // reset it no matter what.
+ instance.removeConfiguration(oldcfg);
+
+ ConsoleConfigurationPreferences adapter = buildConfigurationPreferences(configuration);
+ instance.addConfiguration(new ConsoleConfiguration(adapter), true);
+ }
+ }
+ }
+
+ private ConsoleConfigurationPreferences buildConfigurationPreferences(ILaunchConfiguration configuration) {
+ return new EclipseLaunchConsoleConfigurationPreferences(configuration);
+ }
+
+ public void launchConfigurationAdded(ILaunchConfiguration configuration) {
+ if(isConsoleConfiguration( configuration )) {
+
+ ILaunchConfiguration movedFrom = launchManager.getMovedFrom( configuration );
+ if(movedFrom!=null && isConsoleConfiguration( movedFrom )) {
+ KnownConfigurations instance = KnownConfigurations.getInstance();
+ ConsoleConfiguration oldcfg = instance.find( movedFrom.getName() );
+ if(oldcfg!=null) {
+ oldcfg.reset(); // reset it no matter what.
+ instance.removeConfiguration(oldcfg);
+ }
+ }
+
+ KnownConfigurations instance = KnownConfigurations.getInstance();
+ ConsoleConfigurationPreferences adapter = buildConfigurationPreferences(configuration);
+ instance.addConfiguration(new ConsoleConfiguration(adapter), true);
+
+ }
+ }
+ };
+ launchManager.addLaunchConfigurationListener( icl );
+ }
+
+ private void stopListeningForConfigurations() {
+ final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ launchManager.removeLaunchConfigurationListener( icl );
+ }
+
+
+
+ private void loadExistingConfigurations() throws CoreException {
+ final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+
+ ILaunchConfigurationType lct = launchManager.getLaunchConfigurationType( ICodeGenerationLaunchConstants.CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID );
+ ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations( lct );
+ for (int i = 0; i < launchConfigurations.length; i++) {
+ KnownConfigurations.getInstance().addConfiguration(
+ new ConsoleConfiguration(new EclipseLaunchConsoleConfigurationPreferences(launchConfigurations[i])), false );
+ }
}
@@ -106,10 +204,14 @@
*/
public void stop(BundleContext context) throws Exception {
super.stop(context);
+ stopListeningForConfigurations();
plugin = null;
resourceBundle = null;
}
+
+
+
/**
* Returns the shared instance.
*/
1.1 date: 2007/02/20 13:21:50; author: mandersen; state: Exp;jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseLaunchConsoleConfigurationPreferences.java
Index: EclipseLaunchConsoleConfigurationPreferences.java
===================================================================
package org.hibernate.eclipse.console;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.hibernate.console.HibernateConsoleRuntimeException;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
import org.hibernate.eclipse.console.utils.ClassLoaderHelper;
import org.hibernate.eclipse.launch.IConsoleConfigurationLaunchConstants;
import org.w3c.dom.Element;
public class EclipseLaunchConsoleConfigurationPreferences implements ConsoleConfigurationPreferences {
private final ILaunchConfiguration launchConfiguration;
public EclipseLaunchConsoleConfigurationPreferences(ILaunchConfiguration configuration) {
this.launchConfiguration = configuration;
}
private File strToFile(String epath) {
if(epath==null) return null;
IPath path = new Path(epath);
return pathToFile( path );
}
private File pathToFile(IPath path) {
if(path==null) return null;
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
return pathToFile(path.toString(), resource);
}
private File pathToFile(String path, IResource resource) {
if(resource != null) {
IPath rawLocation = resource.getRawLocation();
if(rawLocation !=null) {
return rawLocation.toFile();
}
}
throw new HibernateConsoleRuntimeException("Could not resolve " + path + " to a file");
}
protected String getAttribute( String attr, String defaultValue ) {
try {
String value = launchConfiguration.getAttribute( attr, defaultValue );
return value;
}
catch (CoreException e) {
throw new HibernateConsoleRuntimeException(e);
}
}
public File getConfigXMLFile() {
String file = getAttribute( IConsoleConfigurationLaunchConstants.CFG_XML_FILE, null );
return strToFile( file );
}
public ConfigurationMode getConfigurationMode() {
return ConfigurationMode.parse( getAttribute( IConsoleConfigurationLaunchConstants.CONFIGURATION_FACTORY, "" ) );
}
public URL[] getCustomClassPathURLS() {
try {
String[] classpath = ClassLoaderHelper.getClasspath( launchConfiguration );
URL[] cp = new URL[classpath.length];
for (int i = 0; i < classpath.length; i++) {
String str = classpath[i];
cp[i] = new File(str).toURL();
}
return cp;
}
catch (CoreException e) {
throw new HibernateConsoleRuntimeException("Could not compute classpath", e);
}
catch (MalformedURLException e) {
throw new HibernateConsoleRuntimeException("Could not compute classpath", e);
}
}
public String getEntityResolverName() {
return getAttribute( IConsoleConfigurationLaunchConstants.ENTITY_RESOLVER, null );
}
public File[] getMappingFiles() {
try {
List mappings = launchConfiguration.getAttribute( IConsoleConfigurationLaunchConstants.FILE_MAPPINGS, Collections.EMPTY_LIST );
File[] result = new File[mappings.size()];
int i = 0;
Iterator iter = mappings.iterator();
while ( iter.hasNext() ) {
String element = (String) iter.next();
result[i++] = strToFile( element );
}
return result;
}
catch (CoreException e) {
throw new HibernateConsoleRuntimeException(e);
}
}
public String getName() {
return launchConfiguration.getName();
}
public String getNamingStrategy() {
return getAttribute( IConsoleConfigurationLaunchConstants.NAMING_STRATEGY, null );
}
public String getPersistenceUnitName() {
return getAttribute( IConsoleConfigurationLaunchConstants.PERSISTENCE_UNIT_NAME, null );
}
public Properties getProperties() {
File propFile = getPropertyFile();
if(propFile==null) return null;
try {
Properties p = new Properties();
p.load(new FileInputStream(propFile) );
return p;
}
catch(IOException io) {
throw new HibernateConsoleRuntimeException("Could not load property file " + propFile, io);
}
}
public File getPropertyFile() {
return strToFile(getAttribute( IConsoleConfigurationLaunchConstants.PROPERTY_FILE, null ));
}
public void readStateFrom(Element element) {
throw new IllegalStateException("Cannot read from xml");
}
public void setName(String name) {
throw new IllegalStateException(getName() + " cannot be renamed");
}
public void writeStateTo(Element node) {
throw new IllegalStateException("Cannot write to xml");
}
}
More information about the jboss-cvs-commits
mailing list