Author: max.andersen(a)jboss.com
Date: 2007-09-25 03:27:00 -0400 (Tue, 25 Sep 2007)
New Revision: 3783
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettingsTab.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettingsTab.java
Removed:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettings.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettings.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/schema/exporters.exsd
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ExtensionManager.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterDefinition.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/UpDownListComposite.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterAttributes.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/HibernateLaunchConstants.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/LaunchConfigurationTabGroup.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ExporterTest.java
Log:
JBIDE-880
JBIDE-857
JBIDE-941
HBX-625
In short: eclipse code generation can now also have multiple exporters (of the same kind)
and supports <hbmtemplate> too.
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 2007-09-25
07:16:29 UTC (rev 3782)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -194,6 +194,7 @@
String str = properties.getProperty(
"hibernate.transaction.manager_lookup_class" );
if(str != null && StringHelper.isEmpty( str )) {
properties.setProperty( "hibernate.transaction.manager_lookup_class",
"org.hibernate.console.FakeTransactionManagerLookup");
+ //properties.setProperty( "hibernate.transaction.factory_class",
"");
}
}
@@ -201,6 +202,9 @@
if(localCfg==null) {
localCfg = buildConfiguration( properties, includeMappings );
} else {
+ //Properties origProperties = cfg.getProperties();
+ //origProperties.putAll(properties);
+ //cfg.setProperties(origProperties);
// TODO: this is actually only for jdbc reveng...
//localCfg = configureStandardConfiguration( includeMappings, localCfg, properties
);
}
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2007-09-25
07:16:29 UTC (rev 3782)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2007-09-25
07:27:00 UTC (rev 3783)
@@ -8,7 +8,7 @@
<perspective
icon="icons/hibernate_small_icon.gif"
class="org.hibernate.eclipse.console.HibernateConsolePerspectiveFactory"
- name="Hibernate Console"
+ name="Hibernate"
id="org.hibernate.eclipse.console.HibernateConsolePerspective"/>
</extension>
<extension
@@ -368,7 +368,7 @@
category="org.hibernate.eclipse.launchcategory"
id="org.hibernate.eclipse.launch.CodeGenerationLaunchGroup"
image="icons/images/hibernate_launch.png"
- label="Hibernate Code Generation..."
+ label="Hibernate Code Generation"
mode="run"
title="Select or configure a code generation to run"/>
<launchGroup
@@ -376,7 +376,7 @@
category="org.hibernate.eclipse.launchcategory"
id="org.hibernate.eclipse.launch.ConsoleConfigurationLaunchGroup"
image="icons/images/hibernate_launch.png"
- label="Hibernate Console Configuration..."
+ label="Hibernate Console Configuration"
mode="run"
title="Select or configure a console configuration to run"/>
</extension>
@@ -405,12 +405,33 @@
name="jdk5"
type="boolean"
value="false"/>
+ <property
+ description="Output directory"
+ name="outputdir"
+ type="directory"
+ value=""/>
+ <property
+ description="Template directory"
+ name="template_path"
+ type="path"
+ value=""/>
</exporter>
<exporter
classname="org.hibernate.tool.hbm2x.HibernateMappingExporter"
description="Hibernate XML Mappings (.hbm.xml)"
icon="icons/images/hibernate_mapping.gif"
- id="org.hibernate.tools.hbm2hbmxml"/>
+ id="org.hibernate.tools.hbm2hbmxml">
+ <property
+ description="Output directory"
+ name="outputdir"
+ type="directory"
+ value=""/>
+ <property
+ description="Template directory"
+ name="template_path"
+ type="path"
+ value=""/>
+ </exporter>
<exporter
classname="org.hibernate.tool.hbm2x.DAOExporter"
description="DAO code (.java)"
@@ -426,13 +447,65 @@
name="jdk5"
type="boolean"
value="false"/>
+ <property
+ description="Output directory"
+ name="outputdir"
+ type="directory"
+ value=""/>
+ <property
+ description="Template directory"
+ name="template_path"
+ type="path"
+ value=""/>
</exporter>
-
+ <exporter
+ classname="org.hibernate.tool.hbm2x.GenericExporter"
+ description="Generic Exporter (<hbmtemplate>)"
+ icon="icons/images/hibernate_mapping.gif"
+ id="org.hibernate.tools.hbmtemplate">
+ <property
+ description="Output directory"
+ name="outputdir"
+ type="directory"
+ value=""/>
+ <property
+ description="Template directory"
+ name="template_path"
+ type="path"
+ value=""/>
+ <property
+ description="File pattern"
+ name="file_pattern"
+ type="string"
+ value="${package-name}/${class-name}.java"/>
+ <property
+ description="For each"
+ name="for_each"
+ type="string"
+ value="entity, component"/>
+ <property
+ description="Template name"
+ name="template_name"
+ type="string"
+ value="pojo/Pojo.ftl"/>
+ </exporter>
+
<exporter
classname="org.hibernate.tool.hbm2x.HibernateConfigurationExporter"
description="Hibernate XML Configuration (.cfg.xml)"
icon="icons/hibernate_small_icon.gif"
- id="org.hibernate.tools.hbm2cfgxml"/>
+ id="org.hibernate.tools.hbm2cfgxml">
+ <property
+ description="Output directory"
+ name="outputdir"
+ type="directory"
+ value=""/>
+ <property
+ description="Template directory"
+ name="template_path"
+ type="path"
+ value=""/>
+ </exporter>
<exporter
classname="org.hibernate.tool.hbm2x.DocExporter"
description="Schema Documentation (.html)"
@@ -443,6 +516,16 @@
name="dot.executable"
type="string"
value="dot.exe"/>
+ <property
+ description="Output directory"
+ name="outputdir"
+ type="directory"
+ value=""/>
+ <property
+ description="Template directory"
+ name="template_path"
+ type="path"
+ value=""/>
</exporter>
<!-- <exporter
classname="org.hibernate.tool.hbm2x.seam.SeamExporter"
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/schema/exporters.exsd
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/schema/exporters.exsd 2007-09-25
07:16:29 UTC (rev 3782)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/schema/exporters.exsd 2007-09-25
07:27:00 UTC (rev 3783)
@@ -125,6 +125,10 @@
</enumeration>
<enumeration value="boolean">
</enumeration>
+ <enumeration value="directory">
+ </enumeration>
+ <enumeration value="path">
+ </enumeration>
</restriction>
</simpleType>
</attribute>
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ExtensionManager.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ExtensionManager.java 2007-09-25
07:16:29 UTC (rev 3782)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ExtensionManager.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -41,6 +41,8 @@
package org.hibernate.eclipse.console;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
@@ -53,7 +55,7 @@
{
public static final String EXPORTERS_EXTENSION_ID =
"org.hibernate.eclipse.console.exporters";
- public static IExtension[] findExtensions (String extensionId)
+ private static IExtension[] findExtensions (String extensionId)
{
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint extensionPoint = registry.getExtensionPoint(extensionId);
@@ -77,4 +79,19 @@
return (ExporterDefinition[]) exporters.toArray(new
ExporterDefinition[exporters.size()]);
}
+
+ /**
+ * return map of ExporterDefinitions keyed by id
+ */
+ public static Map findExporterDefinitionsAsMap() {
+ Map result = new HashMap();
+
+ ExporterDefinition[] findExporterDefinitions = findExporterDefinitions();
+ for (int i = 0; i < findExporterDefinitions.length; i++) {
+ ExporterDefinition exporterDefinition = findExporterDefinitions[i];
+ result.put(exporterDefinition.getId(), exporterDefinition);
+ }
+
+ return result;
+ }
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterDefinition.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterDefinition.java 2007-09-25
07:16:29 UTC (rev 3782)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterDefinition.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -40,8 +40,10 @@
*/
package org.hibernate.eclipse.console.model.impl;
+import java.io.File;
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@@ -49,11 +51,19 @@
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.hibernate.cfg.Configuration;
import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.eclipse.HibernatePlugin;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.tool.hbm2x.Exporter;
import org.hibernate.util.ReflectHelper;
+/**
+ * Represents what is specified in plugin.xml about possible exporters.
+ *
+ */
public class ExporterDefinition {
+
final private String classname;
final private String description;
@@ -105,6 +115,7 @@
return properties;
}
+
public Exporter createExporterInstance() {
Exporter exporter = null;
@@ -131,7 +142,7 @@
return iconDescriptor;
}
- public Map getProperties() {
+ public Map getExporterProperties() {
return properties;
}
@@ -144,7 +155,9 @@
enabled = configuration.getAttribute( id, false );
}
catch (CoreException e) {
- e.printStackTrace(); // TODO-marshall: bad!
+ // log and assume false
+ HibernateConsolePlugin.getDefault().log(e);
+ return false;
}
return enabled;
@@ -153,4 +166,6 @@
public String getId() {
return id;
}
+
+
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java 2007-09-25
07:16:29 UTC (rev 3782)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -1,14 +1,28 @@
package org.hibernate.eclipse.console.model.impl;
+import java.io.File;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
+import org.apache.lucene.util.StringHelper;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
+import org.hibernate.eclipse.launch.PathHelper;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.GenericExporter;
+/**
+ * ExporterFactory is used in UI to hold additional configuration for Exporter
definitions
+ * @author max
+ *
+ */
public class ExporterFactory {
private ExporterDefinition definition;
@@ -16,14 +30,17 @@
final Map inputProperties;
private boolean enabled = true;
+
+ private final String exporterId;
- public ExporterFactory(ExporterDefinition definition) {
+ public ExporterFactory(ExporterDefinition definition, String exporterId) {
this.definition = definition;
+ this.exporterId = exporterId;
inputProperties = new HashMap();
}
public Map getDefaultExporterProperties() {
- return definition.getProperties();
+ return definition.getExporterProperties();
}
@@ -39,7 +56,7 @@
if(inputProperties.containsKey( key )) {
return (String) inputProperties.get( key );
} else {
- ExporterProperty ep = (ExporterProperty) definition.getProperties().get( key );
+ ExporterProperty ep = (ExporterProperty) definition.getExporterProperties().get( key
);
if(ep!=null) {
return ep.getDefaultValue();
} else {
@@ -60,33 +77,60 @@
return definition;
}
+ // todo: move to ExporterAttributes together with isEnabled functionallity...
+ String getLaunchAttributePrefix(String exporterId) {
+ return HibernateLaunchConstants.ATTR_EXPORTERS + "." + exporterId;
+ }
+
public boolean isEnabled(ILaunchConfiguration configuration) {
boolean enabled = false;
try {
- // if we put this in some "namespace" we should have a way to either
- // migrate an existing one...
- enabled = configuration.getAttribute( definition.getId(), false );
+ if(configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS,
(List)null)==null) {
+ enabled = configuration.getAttribute( getId(), false );
+ } else {
+ enabled = configuration.getAttribute( getLaunchAttributePrefix( getId() ), false );
}
- catch (CoreException e) {
- e.printStackTrace(); // TODO-marshall: bad!
+ } catch(CoreException ce) {
+ // ignore; assume false
+ enabled=false;
}
-
+
setEnabled( enabled );
return isEnabled();
}
- public void setEnabled(ILaunchConfigurationWorkingCopy configuration, boolean enabled)
{
+ public void setEnabled(ILaunchConfigurationWorkingCopy configuration, boolean enabled,
boolean oldSettings) {
setEnabled( enabled );
- configuration.setAttribute( definition.getId(), isEnabled() );
+ if(oldSettings) {
+ configuration.setAttribute( getId(), isEnabled() );
+ } else {
+ configuration.setAttribute( getLaunchAttributePrefix( getId() ), isEnabled());
+ }
}
+
+ public void setEnabled(ILaunchConfigurationWorkingCopy configuration, boolean enabled)
{
+
+ boolean oldSettings = true;
+ try {
+ if(configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS,
(List)null)==null) {
+ oldSettings = true;
+ } else {
+ oldSettings = false;
+ }
+ } catch(CoreException ce) {
+ // ignore and assume settings are old
+ }
+ setEnabled(configuration, enabled, oldSettings);
+ }
+
public Map getProperties() {
return inputProperties;
}
public String getId() {
- return getExporterDefinition().getId(); // TODO: namespacing
+ return exporterId;
}
public void setProperties(Map props) {
@@ -95,11 +139,69 @@
}
public ExporterProperty getExporterProperty(String key) {
- return (ExporterProperty) definition.getProperties().get( key );
+ return (ExporterProperty) definition.getExporterProperties().get( key );
}
public boolean hasLocalValueFor(String string) {
return inputProperties.containsKey( string );
}
+ public Exporter createConfiguredExporter(Configuration cfg, File outputdir,
+ String[] templatePaths, Properties globalProperties) {
+ Exporter exporter = getExporterDefinition().createExporterInstance();
+
+ Properties props = new Properties();
+ props.putAll(globalProperties);
+ props.putAll(getProperties());
+
+ exporter.setProperties(props);
+
+ exporter.setOutputDirectory(outputdir);
+ if(props.containsKey("outputdir")) {
+ String loc =
PathHelper.getLocationAsStringPath(props.getProperty("outputdir"));
+ if(loc==null) {
+ throw new HibernateConsoleRuntimeException("Output directory '" +
props.getProperty("outputdir") + "' in " +
getExporterDefinition().getDescription() + " does not exist.");
+ }
+ props.remove("outputdir"); // done to avoid validation check in hibernate
tools templates
+ if(org.hibernate.util.StringHelper.isNotEmpty(loc)) { // only set if something valid
found
+ exporter.setOutputDirectory(new File(loc));
+ }
+ } else {
+
+ }
+
+ exporter.setConfiguration(cfg);
+
+ if(props.containsKey("template_path")) {
+ String locationAsStringPath =
PathHelper.getLocationAsStringPath(props.getProperty("template_path"));
+ if(locationAsStringPath==null) {
+ throw new HibernateConsoleRuntimeException("Template directory '" +
props.getProperty("template_path") + "' in " +
getExporterDefinition().getDescription() + " does not exist.");
+ }
+
+ String[] newPath = new String[templatePaths.length+1];
+ System.arraycopy(templatePaths, 0, newPath, 0, templatePaths.length);
+
+ newPath[templatePaths.length] = locationAsStringPath;
+
+ exporter.setTemplatePath(newPath);
+ props.remove("template_path"); // done to avoid validation check in
hibernate tools templates
+ } else {
+ exporter.setTemplatePath(templatePaths);
+ }
+
+ // special handling for GenericExporter (should be delegated via plugin.xml)
+ if(exporter instanceof GenericExporter) {
+ GenericExporter ge = (GenericExporter) exporter;
+
+ ge.setFilePattern(props.getProperty("file_pattern", null));
+ props.remove("file_pattern");
+ ge.setTemplateName(props.getProperty("template_name",null));
+ props.remove("template_name");
+ ge.setForEach(props.getProperty("for_each",null));
+ props.remove("for_each");
+
+ }
+ return exporter;
+ }
+
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/UpDownListComposite.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/UpDownListComposite.java 2007-09-25
07:16:29 UTC (rev 3782)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/UpDownListComposite.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -23,6 +23,9 @@
import java.util.Iterator;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
@@ -58,8 +61,12 @@
private Button[] addButtons;
private TableViewer tableView;
- private ILabelProvider provider = null;
+ private IBaseLabelProvider provider = null;
private final String title;
+
+ private final boolean checkboxInTable;
+
+ private IContentProvider contentProvider;
public UpDownListComposite(Composite parent, int style) {
@@ -67,13 +74,15 @@
}
public UpDownListComposite(Composite parent, int style, String title) {
- this( parent, style, title, null);
+ this( parent, style, title, false, null, null);
}
- public UpDownListComposite(Composite parent, int style, String title, ILabelProvider
provider) {
+ public UpDownListComposite(Composite parent, int style, String title, boolean
checkboxInTable, IBaseLabelProvider provider, IContentProvider contentProvider) {
super( parent, style );
this.title = title;
+ this.checkboxInTable = checkboxInTable;
this.provider = provider;
+ this.contentProvider = contentProvider;
initialize();
}
@@ -116,7 +125,7 @@
gridData1.heightHint = 20;
gridData1.widthHint = 20;
- table = new Table(group, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI );
+ table = new Table(group, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI |
(checkboxInTable?SWT.CHECK:SWT.NONE));
table.setHeaderVisible(false);
table.setLayoutData(gridData1);
table.setLinesVisible(false);
@@ -134,8 +143,9 @@
});
- tableView = new TableViewer(table);
+ tableView = checkboxInTable?new CheckboxTableViewer(table):new TableViewer(table);
if(provider!=null) tableView.setLabelProvider(provider);
+ if(contentProvider!=null) tableView.setContentProvider(contentProvider);
}
@@ -217,11 +227,11 @@
private void handleButtonPressed(Button button) {
if (button == removeButton) {
- handleRemoveButtonPressed(tableView);
+ handleRemove();
} else if (button == upButton) {
- moveSelectionUp(tableView);
+ moveSelectionUp();
} else if (button == downButton) {
- moveSelectionDown(tableView);
+ moveSelectionDown();
} else {
for (int i = 0; i < addButtons.length; i++) {
Button but = addButtons[i];
@@ -235,8 +245,8 @@
}
- private void moveSelectionDown(TableViewer viewer) {
- Table table = viewer.getTable();
+ protected void moveSelectionDown() {
+ Table table = tableView.getTable();
int indices[]= table.getSelectionIndices();
if (indices.length < 1) {
return;
@@ -246,25 +256,27 @@
for (int i = indices.length - 1; i >= 0; i--) {
int index= indices[i];
if (index < max) {
- move (viewer, table.getItem(index), index + 1);
+ move (tableView, table.getItem(index), index + 1);
newSelection[i]= index + 1;
}
}
table.setSelection(newSelection);
+ listChanged();
}
- private void moveSelectionUp(TableViewer viewer) {
- Table table = viewer.getTable();
+ protected void moveSelectionUp() {
+ Table table = tableView.getTable();
int indices[]= table.getSelectionIndices();
int newSelection[]= new int[indices.length];
for (int i = 0; i < indices.length; i++) {
int index= indices[i];
if (index > 0) {
- move (viewer, table.getItem(index), index - 1);
+ move (tableView, table.getItem(index), index - 1);
newSelection[i]= index - 1;
}
}
table.setSelection(newSelection);
+ listChanged();
}
/**
@@ -276,20 +288,22 @@
viewer.insert(data, index);
}
- private void handleRemoveButtonPressed(TableViewer viewer) {
- IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
+ protected void handleRemove() {
+ IStructuredSelection selection = (IStructuredSelection) tableView.getSelection();
if (selection != null) {
int numSelected= selection.size();
Iterator iterator= selection.iterator();
while (iterator.hasNext() ) {
Object item= iterator.next();
- viewer.remove(item);
+ tableView.remove(item);
}
listChanged();
}
}
+
+
private void handleAddButtonPressed(int i) {
Object[] o = handleAdd(i);
if(o!=null) {
@@ -320,7 +334,7 @@
Table builderTable= tableView.getTable();
TableItem[] items = builderTable.getSelection();
boolean validSelection= items != null && items.length > 0;
- boolean enableRemove= validSelection;
+ boolean enableRemove=validSelection;
boolean enableUp= validSelection;
boolean enableDown= validSelection;
if (validSelection) {
@@ -338,6 +352,10 @@
public Table getTable() {
return tableView.getTable();
}
+
+ public TableViewer getTableViewer() {
+ return tableView;
+ }
public void clear() {
tableView.getTable().removeAll();
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java 2007-09-25
07:16:29 UTC (rev 3782)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -176,7 +176,7 @@
}
private void refreshOutputDir(String outputdir) {
- IResource bufferRes = findMember(ResourcesPlugin.getWorkspace().getRoot(), outputdir);
+ IResource bufferRes = PathHelper.findMember(ResourcesPlugin.getWorkspace().getRoot(),
outputdir);
if (bufferRes != null && bufferRes.isAccessible()) {
try {
@@ -187,63 +187,41 @@
}
}
- private Path pathOrNull(String p) {
- if(p==null || p.trim().length()==0) {
- return null;
- } else {
- return new Path(p);
- }
- }
-
- private ArtifactCollector runExporters (final ExporterAttributes attributes, final
ExporterFactory[] exporters, final IProgressMonitor monitor)
+ private ArtifactCollector runExporters (final ExporterAttributes attributes, final
ExporterFactory[] exporterFactories, final IProgressMonitor monitor)
throws CoreException
{
- monitor.beginTask("Generating code for " +
attributes.getConsoleConfigurationName(), exporters.length + 1);
+ monitor.beginTask("Generating code for " +
attributes.getConsoleConfigurationName(), exporterFactories.length + 1);
if (monitor.isCanceled())
return null;
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- final IResource resource = findMember( root, attributes.getOutputPath() );
- final IResource templateres = findMember(root, attributes.getTemplatePath());
- String templatePath = null;
+ final String outputPathRes = PathHelper.getLocationAsStringPath(
attributes.getOutputPath() );
- if (new File(attributes.getTemplatePath()).exists())
- {
- templatePath = attributes.getTemplatePath();
- }
-
- /*if (!resource.exists() || !(resource instanceof IContainer) ) {
- throwCoreException("Output directory \"" + configName + "\"
does not exist.");
- }*/
- /*IContainer container = (IContainer) resource;*/
-
+ final String templatePath =
PathHelper.getLocationAsStringPath(attributes.getTemplatePath());
+
ConsoleConfiguration cc =
KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
if (attributes.isReverseEngineer()) {
monitor.subTask("reading jdbc metadata");
}
- final Configuration cfg = buildConfiguration(attributes, cc, root);
+ final Configuration cfg = buildConfiguration(attributes, cc,
ResourcesPlugin.getWorkspace().getRoot());
monitor.worked(1);
if (monitor.isCanceled())
return null;
-
- final String finalTemplatePath = templatePath;
+
return (ArtifactCollector) cc.execute(new Command() {
private ArtifactCollector artifactCollector = new ArtifactCollector();
public Object execute() {
- File outputdir = getLocation( resource ).toFile();
+ File outputdir = new File( outputPathRes );
String[] templatePaths = new String[0];
-
- if(templateres!=null) {
- templatePaths = new String[] { getLocation( templateres
).toOSString() }; // TODO: this should not be..should it ?
- } else if (finalTemplatePath != null) {
- templatePaths = new String[] { finalTemplatePath };
+
+ if(StringHelper.isNotEmpty(templatePath)) {
+ templatePaths = new String[] { templatePath };
}
// Global properties
@@ -251,32 +229,21 @@
props.put("ejb3", ""+attributes.isEJB3Enabled());
props.put("jdk5",
""+attributes.isJDK5Enabled());
- for (int i = 0; i < exporters.length; i++)
+ for (int i = 0; i < exporterFactories.length; i++)
{
-
monitor.subTask(exporters[i].getExporterDefinition().getDescription());
+
monitor.subTask(exporterFactories[i].getExporterDefinition().getDescription());
- Properties exporterProperties = new Properties();
- exporterProperties.putAll(props);
- exporterProperties.putAll(exporters[i].getProperties());
+ Properties globalProperties = new Properties();
+ globalProperties.putAll(props);
- Exporter exporter =
exporters[i].getExporterDefinition().createExporterInstance();
+ Exporter exporter =
exporterFactories[i].createConfiguredExporter(cfg, outputdir, templatePaths,
globalProperties);
- configureExporter (cfg, outputdir, templatePaths,
exporterProperties, exporter);
-
exporter.start();
monitor.worked(1);
}
return getArtififactCollector();
}
- private void configureExporter(final Configuration cfg, File outputdir, String[]
templatePaths, Properties props, Exporter exporter) {
- exporter.setProperties(props);
- exporter.setOutputDirectory(outputdir);
- exporter.setConfiguration(cfg);
- exporter.setTemplatePath(templatePaths);
- exporter.setArtifactCollector(getArtififactCollector());
- }
-
private ArtifactCollector getArtififactCollector() {
return artifactCollector ;
}
@@ -285,24 +252,11 @@
}
- private IResource findMember(IWorkspaceRoot root, String path) {
- Path pathOrNull = pathOrNull(path);
- if(pathOrNull==null) return null;
- return root.findMember(pathOrNull);
- }
-
- private IPath getLocation(final IResource resource) {
- if (resource.getRawLocation() == null) {
- return resource.getLocation();
- }
- else return resource.getRawLocation();
- }
-
private Configuration buildConfiguration(final ExporterAttributes attributes,
ConsoleConfiguration cc, IWorkspaceRoot root) {
final boolean reveng = attributes.isReverseEngineer();
final String reverseEngineeringStrategy = attributes.getRevengStrategy();
final boolean preferBasicCompositeids = attributes.isPreferBasicCompositeIds();
- final IResource revengres = findMember( root, attributes.getRevengSettings());
+ final IResource revengres = PathHelper.findMember( root,
attributes.getRevengSettings());
if(reveng) {
Configuration configuration = null;
@@ -332,7 +286,7 @@
if(revengres!=null) {
/*Configuration configuration = cc.buildWith(new Configuration(), false);*/
/*Settings settings = cc.getSettings(configuration);*/
- File file = getLocation( revengres ).toFile();
+ File file = PathHelper.getLocation( revengres ).toFile();
OverrideRepository repository = new
OverrideRepository();///*settings.getDefaultCatalogName(),settings.getDefaultSchemaName()*/);
repository.addFile(file);
res = repository.getReverseEngineeringStrategy(res);
Deleted:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettings.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettings.java 2007-09-25
07:16:29 UTC (rev 3782)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettings.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -1,480 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.hibernate.eclipse.launch;
-
-import java.io.File;
-
-import org.eclipse.core.resources.IProject;
-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.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
-import org.eclipse.jdt.core.JavaConventions;
-import org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField;
-import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
-import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
-import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
-import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
-import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
-import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.console.ImageConstants;
-import org.hibernate.console.KnownConfigurations;
-import org.hibernate.eclipse.console.HibernateConsolePlugin;
-import org.hibernate.eclipse.console.utils.DialogSelectionHelper;
-import org.hibernate.eclipse.console.utils.EclipseImages;
-import org.hibernate.eclipse.console.wizards.NewReverseEngineeringFileWizard;
-
-public class CodeGenerationSettings extends AbstractLaunchConfigurationTab {
-
- private ComboDialogField consoleConfigurationName;
-
- private IStructuredSelection selection;
-
- private SelectionButtonDialogField reverseengineer;
-
- private StringButtonDialogField outputdir;
-
- private StringButtonDialogField reverseEngineeringSettings;
-
- private StringButtonDialogField reverseEngineeringStrategy;
-
- private StringDialogField packageName;
-
- private SelectionButtonDialogField preferRawCompositeIds;
- private SelectionButtonDialogField autoVersioning;
- private SelectionButtonDialogField autoManyToMany;
-
- private SelectionButtonDialogField useOwnTemplates;
- private DirectoryBrowseField templatedir;
-
-
-
- public CodeGenerationSettings() {
- super();
- }
-
- public void createControl(Composite parent) {
-
- //initializeDialogUnits(parent);
-
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
-
- container.setLayout(layout);
- layout.numColumns = 4;
- layout.verticalSpacing = 10;
-
- consoleConfigurationName = new ComboDialogField(SWT.READ_ONLY);
- consoleConfigurationName.setLabelText("Console &configuration:");
- ConsoleConfiguration[] cfg =
KnownConfigurations.getInstance().getConfigurationsSortedByName();
- String[] names = new String[cfg.length];
- for (int i = 0; i < cfg.length; i++) {
- ConsoleConfiguration configuration = cfg[i];
- names[i] = configuration.getName();
- }
- consoleConfigurationName.setItems(names);
-
- IDialogFieldListener fieldlistener = new IDialogFieldListener() {
- public void dialogFieldChanged(DialogField field) {
- dialogChanged();
- }
- };
-
- consoleConfigurationName.setDialogFieldListener(fieldlistener);
-
- outputdir = new StringButtonDialogField(new IStringButtonAdapter() {
- public void changeControlPressed(DialogField field) {
- IPath[] paths = DialogSelectionHelper.chooseFileEntries(getShell(),
getOutputDirectory(), new IPath[0], "Select output directory", "Choose
directory in which the generated files will be stored", new String[]
{"cfg.xml"}, false, true, false);
- if(paths!=null && paths.length==1) {
- outputdir.setText( ( (paths[0]).toOSString() ) );
- }
- }
- });
- outputdir.setDialogFieldListener(fieldlistener);
- outputdir.setLabelText("Output &directory:");
- outputdir.setButtonLabel("&Browse...");
-
- templatedir = new DirectoryBrowseField(null, null, "Select template
directory", "Choose directory containing custom templates");
- templatedir.setDialogFieldListener(fieldlistener);
- templatedir.setLabelText("Template &directory:");
- templatedir.setFilesystemBrowseLabel("&Filesystem...");
- templatedir.setWorkspaceBrowseLabel("&Workspace...");
-
- packageName = new StringDialogField();
- packageName.setDialogFieldListener(fieldlistener);
- packageName.setLabelText("&Package:");
-
- reverseEngineeringStrategy = new StringButtonDialogField(new
IStringButtonAdapter() {
-
- public void changeControlPressed(DialogField field) {
- String string =
DialogSelectionHelper.chooseImplementation(ReverseEngineeringStrategy.class.getName(),
reverseEngineeringStrategy.getText(), "Choose a reverse engineering strategy",
getShell());
- if(string!=null) {
- reverseEngineeringStrategy.setText(string);
- }
- }
- });
- reverseEngineeringStrategy.setDialogFieldListener(fieldlistener);
- reverseEngineeringStrategy.setLabelText("reveng. s&trategy:");
- reverseEngineeringStrategy.setButtonLabel("&Browse...");
-
- reverseEngineeringSettings= new StringButtonDialogField(new IStringButtonAdapter() {
- public void changeControlPressed(DialogField field) {
- int defaultChoice = 0;
- IPath reverseEngineeringSettingsFile = getReverseEngineeringSettingsFile();
-
- if(reverseEngineeringSettingsFile==null) {
- defaultChoice = 0;
- } else {
- defaultChoice = 1;
- }
- MessageDialog dialog = new MessageDialog(getShell(),
- "Setup reverse engineering",
- null,
- "Do you want to create a new reveng.xml or use an existing file ?",
- MessageDialog.QUESTION,
- new String[] { "Create &new...", "Use &existing...",
IDialogConstants.CANCEL_LABEL},
- defaultChoice);
- int answer = dialog.open();
- if(answer==0) { // create new
- NewReverseEngineeringFileWizard wizard = new NewReverseEngineeringFileWizard();
- wizard.init(PlatformUI.getWorkbench(), selection );
- wizard.setSelectConfiguration(getConfigurationName());
- IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-
- WizardDialog wdialog = new WizardDialog(win.getShell(), wizard);
- wdialog.open(); // This opens a dialog
- IPath createdFilePath = wizard.getCreatedFilePath();
- if(createdFilePath!=null) {
- reverseEngineeringSettings.setText(createdFilePath.toOSString());
- }
- } else if (answer==1) { // use existing
- IPath[] paths = DialogSelectionHelper.chooseFileEntries(getShell(),
reverseEngineeringSettingsFile, new IPath[0], "Select reverse engineering settings
file", "Choose file from which settings for the reverse engineering will be
read", new String[] {"reveng.xml"}, false, false, true);
- if(paths!=null && paths.length==1) {
- reverseEngineeringSettings.setText( ( (paths[0]).toOSString() ) );
- }
- }
- }
- });
- reverseEngineeringSettings.setDialogFieldListener(fieldlistener);
- reverseEngineeringSettings.setLabelText("reveng.&xml:");
- reverseEngineeringSettings.setButtonLabel("&Setup...");
-
- reverseengineer = new SelectionButtonDialogField(SWT.CHECK);
- reverseengineer.setLabelText("Reverse engineer from JDBC Connection");
- reverseengineer.setDialogFieldListener(fieldlistener);
-
- useOwnTemplates = new SelectionButtonDialogField(SWT.CHECK);
- useOwnTemplates.setDialogFieldListener(fieldlistener);
- useOwnTemplates.setLabelText("Use custom templates (for custom file
generation)");
-
- preferRawCompositeIds = new SelectionButtonDialogField(SWT.CHECK);
- preferRawCompositeIds.setLabelText("Generate basic typed composite
ids");
- preferRawCompositeIds.setSelection(true);
- preferRawCompositeIds.setDialogFieldListener(fieldlistener);
-
- autoManyToMany = new SelectionButtonDialogField(SWT.CHECK);
- autoManyToMany.setLabelText("Detect many-to-many tables");
- autoManyToMany.setSelection(true);
- autoManyToMany.setDialogFieldListener(fieldlistener);
-
- autoVersioning = new SelectionButtonDialogField(SWT.CHECK);
- autoVersioning.setLabelText("Detect optimistic lock columns");
- autoVersioning.setSelection(true);
- autoVersioning.setDialogFieldListener(fieldlistener);
-
- useOwnTemplates.attachDialogField(templatedir);
- reverseengineer.attachDialogFields(new DialogField[] { packageName,
preferRawCompositeIds, reverseEngineeringSettings, reverseEngineeringStrategy,
autoManyToMany, autoVersioning });
-
- consoleConfigurationName.doFillIntoGrid(container, 4);
- Control[] controls = outputdir.doFillIntoGrid(container, 4);
- // Hack to tell the text field to stretch!
- ( (GridData)controls[1].getLayoutData() ).grabExcessHorizontalSpace=true;
- reverseengineer.doFillIntoGrid(container, 4);
- packageName.doFillIntoGrid(container, 4);
- reverseEngineeringSettings.doFillIntoGrid(container, 4);
- reverseEngineeringStrategy.doFillIntoGrid(container, 4);
-
- fillLabel(container);
- preferRawCompositeIds.doFillIntoGrid(container, 3);
- fillLabel(container);
- autoVersioning.doFillIntoGrid(container, 3);
- fillLabel(container);
- autoManyToMany.doFillIntoGrid(container, 3);
- useOwnTemplates.doFillIntoGrid(container, 4);
- controls = templatedir.doFillIntoGrid(container, 4);
- // Hack to tell the text field to stretch!
- ( (GridData)controls[1].getLayoutData() ).grabExcessHorizontalSpace=true;
-
- dialogChanged();
- setControl(container);
- }
-
- private void fillLabel(Composite container) {
- new Label(container, SWT.NULL);
- }
-
-
- private void dialogChanged() {
- boolean configSelected = getConfigurationName().length()==0;
- outputdir.setEnabled(!configSelected);
- reverseengineer.setEnabled(!configSelected);
- useOwnTemplates.setEnabled(!configSelected);
-
- if (configSelected) {
- updateStatus("Console configuration must be specified");
- return;
- }
-
- String msg = checkDirectory(getOutputDirectory(), "output directory",
false);
-
- if (msg!=null) {
- updateStatus(msg);
- return;
- }
-
- if(packageName.isEnabled() && getOutputPackage().length()>0) {
- IStatus val= JavaConventions.validatePackageName(getOutputPackage() );
- if (val.getSeverity() == IStatus.ERROR || val.getSeverity() ==
IStatus.WARNING) {
- updateStatus(val.getMessage() );
- return;
- }
- }
-
- if(reverseEngineeringSettings.getText().trim().length()>0) {
- msg = checkFile(getReverseEngineeringSettingsFile(), "reveng.xml");
- if(msg!=null) {
- updateStatus(msg);
- return;
- }
- }
-
- if(useOwnTemplates.isSelected() ) {
- msg = checkDirectory(getTemplateDirectory(), "template directory",
true);
- if (msg!=null) {
- updateStatus(msg);
- return;
- } else {
- // imprecise and inefficient to check recursively all for .vm
- /*IResource resource =
ResourcesPlugin.getWorkspace().getRoot().findMember(getTemplateDirectory() );
- IResource[] files = new IFile[0];
- boolean found = false;
-
- if(resource.getType() == IResource.FOLDER) {
- try {
- found = ( (IFolder)resource).accept(new IResourceProxyVisitor()
{
-
- public boolean visit(IResourceProxy proxy) throws CoreException {
- return false;
- }
-
- });
- } catch (CoreException e) {
- // noop
- }
- }
-
- if(!found) {
- setMessage("No templates (*.vm) found in template
directory", IMessageProvider.WARNING);
- } else {
- setMessage(null);
- }*/
- }
- } else {
- setMessage(null);
- }
-
- updateStatus(null);
- }
-
-
-
- protected String checkDirectory(IPath path, String name, boolean checkFilesystem) {
- if (checkFilesystem) {
- if (path != null && new File(path.toOSString()).exists()) {
- return null;
- }
- }
-
- IResource res= ResourcesPlugin.getWorkspace().getRoot().findMember(path);
- if (res != null) {
- int resType= res.getType();
- if (resType == IResource.PROJECT || resType == IResource.FOLDER) {
- IProject proj= res.getProject();
- if (!proj.isOpen() ) {
- return "Project for " + name + " is closed";
- }
- } else {
- return name + " has to be a folder or project";
- }
- } else {
- return name + " does not exist";
- }
- return null;
- }
-
- protected String checkFile(IPath path, String name) {
- IResource res= ResourcesPlugin.getWorkspace().getRoot().findMember(path);
- if (res != null) {
- int resType= res.getType();
- if (resType == IResource.FILE) {
- return null;
- } else {
- return name + " must be a file";
- }
- } else {
- return name + " does not exist";
- }
- }
-
- private void updateStatus(String message) {
- setErrorMessage(message);
- updateLaunchConfigurationDialog();
- }
-
- public String getConfigurationName() {
- return consoleConfigurationName.getText();
- }
-
- private Path pathOrNull(String p) {
- if(p==null || p.trim().length()==0) {
- return null;
- } else {
- return new Path(p);
- }
- }
-
-
- /**
- * @return
- */
- public boolean isReverseEngineerEnabled() {
- return reverseengineer.isSelected();
- }
-
- public IPath getOutputDirectory() {
- return pathOrNull(outputdir.getText() );
- }
-
- public IPath getTemplateDirectory() {
- return pathOrNull(templatedir.getText() );
- }
-
- public String getOutputPackage() {
- return packageName.getText();
- }
-
-
- private IPath getReverseEngineeringSettingsFile() {
- return pathOrNull(reverseEngineeringSettings.getText() );
- }
-
- private String getReverseEngineeringStrategy() {
- return reverseEngineeringStrategy.getText();
- }
-
- public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
-// try {
-// attributes = new ExporterAttributes(configuration);
-// } catch (CoreException ce) {
-// HibernateConsolePlugin.getDefault().logErrorMessage("Problem when
setting up defaults for launch configuration", ce);
-// }
- }
-
- public void initializeFrom(ILaunchConfiguration configuration) {
- try {
- ExporterAttributes attributes = new ExporterAttributes(configuration);
- consoleConfigurationName.setText(attributes.getConsoleConfigurationName());
- preferRawCompositeIds.setSelection(attributes.isPreferBasicCompositeIds());
- autoManyToMany.setSelection( attributes.detectManyToMany() );
- autoVersioning.setSelection( attributes.detectOptimisticLock() );
- outputdir.setText(safeText(attributes.getOutputPath()));
- reverseengineer.setSelection(attributes.isReverseEngineer());
- reverseEngineeringSettings.setText(safeText(attributes.getRevengSettings()));
- reverseEngineeringStrategy.setText(safeText(attributes.getRevengStrategy()));
- useOwnTemplates.setSelection(attributes.isUseOwnTemplates());
- packageName.setText(safeText(attributes.getPackageName()));
- templatedir.setText(safeText(attributes.getTemplatePath()));
- } catch (CoreException ce) {
- HibernateConsolePlugin.getDefault().logErrorMessage("Problem when reading
hibernate tools launch configuration", ce);
- }
- }
-
- private String safeText(String text) {
- return text==null?"":text;
- }
-
- private String strOrNull(String text) {
- if(text==null || text.trim().length()==0) {
- return null;
- } else {
- return text;
- }
- }
-
- public void performApply(ILaunchConfigurationWorkingCopy configuration) {
- configuration.setAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR,
strOrNull(outputdir.getText()));
- configuration.setAttribute(HibernateLaunchConstants.ATTR_PREFER_BASIC_COMPOSITE_IDS,
preferRawCompositeIds.isSelected());
- configuration.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_MANY_TO_MANY,
autoManyToMany.isSelected());
- configuration.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_VERSIONING,
autoVersioning.isSelected());
- configuration.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER,
isReverseEngineerEnabled());
- configuration.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_STRATEGY,
strOrNull(reverseEngineeringStrategy.getText()));
- configuration.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
strOrNull(reverseEngineeringSettings.getText()));
-
-
- configuration.setAttribute(HibernateLaunchConstants.ATTR_USE_OWN_TEMPLATES,
useOwnTemplates.isSelected());
- configuration.setAttribute(HibernateLaunchConstants.ATTR_TEMPLATE_DIR,
strOrNull(templatedir.getText()));
-
- configuration.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
getConfigurationName());
- configuration.setAttribute(HibernateLaunchConstants.ATTR_PACKAGE_NAME,
getOutputPackage());
-
- }
-
- public String getName() {
- return "Main";
- }
-
- public Image getImage() {
- return EclipseImages.getImage(ImageConstants.MINI_HIBERNATE);
- }
-
-
-}
Copied:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettingsTab.java
(from rev 3703,
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettings.java)
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettingsTab.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettingsTab.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -0,0 +1,447 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.eclipse.launch;
+
+
+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.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
+import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.ImageConstants;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.utils.DialogSelectionHelper;
+import org.hibernate.eclipse.console.utils.EclipseImages;
+import org.hibernate.eclipse.console.wizards.NewReverseEngineeringFileWizard;
+
+public class CodeGenerationSettingsTab extends AbstractLaunchConfigurationTab {
+
+ private ComboDialogField consoleConfigurationName;
+
+ private IStructuredSelection selection;
+
+ private SelectionButtonDialogField reverseengineer;
+
+ private StringButtonDialogField outputdir;
+
+ private StringButtonDialogField reverseEngineeringSettings;
+
+ private StringButtonDialogField reverseEngineeringStrategy;
+
+ private StringDialogField packageName;
+
+ private SelectionButtonDialogField preferRawCompositeIds;
+ private SelectionButtonDialogField autoVersioning;
+ private SelectionButtonDialogField autoManyToMany;
+
+ private SelectionButtonDialogField useOwnTemplates;
+ private DirectoryBrowseField templatedir;
+
+
+
+ public CodeGenerationSettingsTab() {
+ super();
+ }
+
+ public void createControl(Composite parent) {
+
+ //initializeDialogUnits(parent);
+
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+
+ container.setLayout(layout);
+ layout.numColumns = 4;
+ layout.verticalSpacing = 10;
+
+ consoleConfigurationName = new ComboDialogField(SWT.READ_ONLY);
+ consoleConfigurationName.setLabelText("Console &configuration:");
+ ConsoleConfiguration[] cfg =
KnownConfigurations.getInstance().getConfigurationsSortedByName();
+ String[] names = new String[cfg.length];
+ for (int i = 0; i < cfg.length; i++) {
+ ConsoleConfiguration configuration = cfg[i];
+ names[i] = configuration.getName();
+ }
+ consoleConfigurationName.setItems(names);
+
+ IDialogFieldListener fieldlistener = new IDialogFieldListener() {
+ public void dialogFieldChanged(DialogField field) {
+ dialogChanged();
+ }
+ };
+
+ consoleConfigurationName.setDialogFieldListener(fieldlistener);
+
+ outputdir = new StringButtonDialogField(new IStringButtonAdapter() {
+ public void changeControlPressed(DialogField field) {
+ IPath[] paths = DialogSelectionHelper.chooseFileEntries(getShell(),
getOutputDirectory(), new IPath[0], "Select output directory", "Choose
directory in which the generated files will be stored", new String[]
{"cfg.xml"}, false, true, false);
+ if(paths!=null && paths.length==1) {
+ outputdir.setText( ( (paths[0]).toOSString() ) );
+ }
+ }
+ });
+ outputdir.setDialogFieldListener(fieldlistener);
+ outputdir.setLabelText("Output &directory:");
+ outputdir.setButtonLabel("&Browse...");
+
+ templatedir = new DirectoryBrowseField(null, null, "Select template
directory", "Choose directory containing custom templates");
+ templatedir.setDialogFieldListener(fieldlistener);
+ templatedir.setLabelText("Template &directory:");
+ templatedir.setFilesystemBrowseLabel("&Filesystem...");
+ templatedir.setWorkspaceBrowseLabel("&Workspace...");
+
+ packageName = new StringDialogField();
+ packageName.setDialogFieldListener(fieldlistener);
+ packageName.setLabelText("&Package:");
+
+ reverseEngineeringStrategy = new StringButtonDialogField(new
IStringButtonAdapter() {
+
+ public void changeControlPressed(DialogField field) {
+ String string =
DialogSelectionHelper.chooseImplementation(ReverseEngineeringStrategy.class.getName(),
reverseEngineeringStrategy.getText(), "Choose a reverse engineering strategy",
getShell());
+ if(string!=null) {
+ reverseEngineeringStrategy.setText(string);
+ }
+ }
+ });
+ reverseEngineeringStrategy.setDialogFieldListener(fieldlistener);
+ reverseEngineeringStrategy.setLabelText("reveng. s&trategy:");
+ reverseEngineeringStrategy.setButtonLabel("&Browse...");
+
+ reverseEngineeringSettings= new StringButtonDialogField(new IStringButtonAdapter() {
+ public void changeControlPressed(DialogField field) {
+ int defaultChoice = 0;
+ IPath reverseEngineeringSettingsFile = getReverseEngineeringSettingsFile();
+
+ if(reverseEngineeringSettingsFile==null) {
+ defaultChoice = 0;
+ } else {
+ defaultChoice = 1;
+ }
+ MessageDialog dialog = new MessageDialog(getShell(),
+ "Setup reverse engineering",
+ null,
+ "Do you want to create a new reveng.xml or use an existing file ?",
+ MessageDialog.QUESTION,
+ new String[] { "Create &new...", "Use &existing...",
IDialogConstants.CANCEL_LABEL},
+ defaultChoice);
+ int answer = dialog.open();
+ if(answer==0) { // create new
+ NewReverseEngineeringFileWizard wizard = new NewReverseEngineeringFileWizard();
+ wizard.init(PlatformUI.getWorkbench(), selection );
+ wizard.setSelectConfiguration(getConfigurationName());
+ IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+
+ WizardDialog wdialog = new WizardDialog(win.getShell(), wizard);
+ wdialog.open(); // This opens a dialog
+ IPath createdFilePath = wizard.getCreatedFilePath();
+ if(createdFilePath!=null) {
+ reverseEngineeringSettings.setText(createdFilePath.toOSString());
+ }
+ } else if (answer==1) { // use existing
+ IPath[] paths = DialogSelectionHelper.chooseFileEntries(getShell(),
reverseEngineeringSettingsFile, new IPath[0], "Select reverse engineering settings
file", "Choose file from which settings for the reverse engineering will be
read", new String[] {"reveng.xml"}, false, false, true);
+ if(paths!=null && paths.length==1) {
+ reverseEngineeringSettings.setText( ( (paths[0]).toOSString() ) );
+ }
+ }
+ }
+ });
+ reverseEngineeringSettings.setDialogFieldListener(fieldlistener);
+ reverseEngineeringSettings.setLabelText("reveng.&xml:");
+ reverseEngineeringSettings.setButtonLabel("&Setup...");
+
+ reverseengineer = new SelectionButtonDialogField(SWT.CHECK);
+ reverseengineer.setLabelText("Reverse engineer from JDBC Connection");
+ reverseengineer.setDialogFieldListener(fieldlistener);
+
+ useOwnTemplates = new SelectionButtonDialogField(SWT.CHECK);
+ useOwnTemplates.setDialogFieldListener(fieldlistener);
+ useOwnTemplates.setLabelText("Use custom templates (for custom file
generation)");
+
+ preferRawCompositeIds = new SelectionButtonDialogField(SWT.CHECK);
+ preferRawCompositeIds.setLabelText("Generate basic typed composite
ids");
+ preferRawCompositeIds.setSelection(true);
+ preferRawCompositeIds.setDialogFieldListener(fieldlistener);
+
+ autoManyToMany = new SelectionButtonDialogField(SWT.CHECK);
+ autoManyToMany.setLabelText("Detect many-to-many tables");
+ autoManyToMany.setSelection(true);
+ autoManyToMany.setDialogFieldListener(fieldlistener);
+
+ autoVersioning = new SelectionButtonDialogField(SWT.CHECK);
+ autoVersioning.setLabelText("Detect optimistic lock columns");
+ autoVersioning.setSelection(true);
+ autoVersioning.setDialogFieldListener(fieldlistener);
+
+ useOwnTemplates.attachDialogField(templatedir);
+ reverseengineer.attachDialogFields(new DialogField[] { packageName,
preferRawCompositeIds, reverseEngineeringSettings, reverseEngineeringStrategy,
autoManyToMany, autoVersioning });
+
+ consoleConfigurationName.doFillIntoGrid(container, 4);
+ Control[] controls = outputdir.doFillIntoGrid(container, 4);
+ // Hack to tell the text field to stretch!
+ ( (GridData)controls[1].getLayoutData() ).grabExcessHorizontalSpace=true;
+ reverseengineer.doFillIntoGrid(container, 4);
+ packageName.doFillIntoGrid(container, 4);
+ reverseEngineeringSettings.doFillIntoGrid(container, 4);
+ reverseEngineeringStrategy.doFillIntoGrid(container, 4);
+
+ fillLabel(container);
+ preferRawCompositeIds.doFillIntoGrid(container, 3);
+ fillLabel(container);
+ autoVersioning.doFillIntoGrid(container, 3);
+ fillLabel(container);
+ autoManyToMany.doFillIntoGrid(container, 3);
+ useOwnTemplates.doFillIntoGrid(container, 4);
+ controls = templatedir.doFillIntoGrid(container, 4);
+ // Hack to tell the text field to stretch!
+ ( (GridData)controls[1].getLayoutData() ).grabExcessHorizontalSpace=true;
+
+ dialogChanged();
+ setControl(container);
+ }
+
+ private void fillLabel(Composite container) {
+ new Label(container, SWT.NULL);
+ }
+
+
+ private void dialogChanged() {
+ boolean configSelected = getConfigurationName().length()==0;
+ outputdir.setEnabled(!configSelected);
+ reverseengineer.setEnabled(!configSelected);
+ useOwnTemplates.setEnabled(!configSelected);
+
+ if (configSelected) {
+ updateStatus("Console configuration must be specified");
+ return;
+ }
+
+ String msg = PathHelper.checkDirectory(getOutputDirectory(), "output
directory", false);
+
+ if (msg!=null) {
+ updateStatus(msg);
+ return;
+ }
+
+ if(packageName.isEnabled() && getOutputPackage().length()>0) {
+ IStatus val= JavaConventions.validatePackageName(getOutputPackage() );
+ if (val.getSeverity() == IStatus.ERROR || val.getSeverity() ==
IStatus.WARNING) {
+ updateStatus(val.getMessage() );
+ return;
+ }
+ }
+
+ if(reverseEngineeringSettings.getText().trim().length()>0) {
+ msg = checkFile(getReverseEngineeringSettingsFile(), "reveng.xml");
+ if(msg!=null) {
+ updateStatus(msg);
+ return;
+ }
+ }
+
+ if(useOwnTemplates.isSelected() ) {
+ msg = PathHelper.checkDirectory(getTemplateDirectory(), "template
directory", true);
+ if (msg!=null) {
+ updateStatus(msg);
+ return;
+ } else {
+ // imprecise and inefficient to check recursively all for .vm
+ /*IResource resource =
ResourcesPlugin.getWorkspace().getRoot().findMember(getTemplateDirectory() );
+ IResource[] files = new IFile[0];
+ boolean found = false;
+
+ if(resource.getType() == IResource.FOLDER) {
+ try {
+ found = ( (IFolder)resource).accept(new IResourceProxyVisitor()
{
+
+ public boolean visit(IResourceProxy proxy) throws CoreException {
+ return false;
+ }
+
+ });
+ } catch (CoreException e) {
+ // noop
+ }
+ }
+
+ if(!found) {
+ setMessage("No templates (*.vm) found in template
directory", IMessageProvider.WARNING);
+ } else {
+ setMessage(null);
+ }*/
+ }
+ } else {
+ setMessage(null);
+ }
+
+ updateStatus(null);
+ }
+
+
+
+ protected String checkFile(IPath path, String name) {
+ IResource res= ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+ if (res != null) {
+ int resType= res.getType();
+ if (resType == IResource.FILE) {
+ return null;
+ } else {
+ return name + " must be a file";
+ }
+ } else {
+ return name + " does not exist";
+ }
+ }
+
+ private void updateStatus(String message) {
+ setErrorMessage(message);
+ updateLaunchConfigurationDialog();
+ }
+
+ public String getConfigurationName() {
+ return consoleConfigurationName.getText();
+ }
+
+
+
+ /**
+ * @return
+ */
+ public boolean isReverseEngineerEnabled() {
+ return reverseengineer.isSelected();
+ }
+
+ public IPath getOutputDirectory() {
+ return PathHelper.pathOrNull(outputdir.getText() );
+ }
+
+ public IPath getTemplateDirectory() {
+ return PathHelper.pathOrNull(templatedir.getText() );
+ }
+
+ public String getOutputPackage() {
+ return packageName.getText();
+ }
+
+
+ private IPath getReverseEngineeringSettingsFile() {
+ return PathHelper.pathOrNull(reverseEngineeringSettings.getText() );
+ }
+
+ private String getReverseEngineeringStrategy() {
+ return reverseEngineeringStrategy.getText();
+ }
+
+ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
+// try {
+// attributes = new ExporterAttributes(configuration);
+// } catch (CoreException ce) {
+// HibernateConsolePlugin.getDefault().logErrorMessage("Problem when
setting up defaults for launch configuration", ce);
+// }
+ }
+
+ public void initializeFrom(ILaunchConfiguration configuration) {
+ try {
+ ExporterAttributes attributes = new ExporterAttributes(configuration);
+ consoleConfigurationName.setText(attributes.getConsoleConfigurationName());
+ preferRawCompositeIds.setSelection(attributes.isPreferBasicCompositeIds());
+ autoManyToMany.setSelection( attributes.detectManyToMany() );
+ autoVersioning.setSelection( attributes.detectOptimisticLock() );
+ outputdir.setText(safeText(attributes.getOutputPath()));
+ reverseengineer.setSelection(attributes.isReverseEngineer());
+ reverseEngineeringSettings.setText(safeText(attributes.getRevengSettings()));
+ reverseEngineeringStrategy.setText(safeText(attributes.getRevengStrategy()));
+ useOwnTemplates.setSelection(attributes.isUseOwnTemplates());
+ packageName.setText(safeText(attributes.getPackageName()));
+ templatedir.setText(safeText(attributes.getTemplatePath()));
+ } catch (CoreException ce) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Problem when reading
hibernate tools launch configuration", ce);
+ }
+ }
+
+ private String safeText(String text) {
+ return text==null?"":text;
+ }
+
+ private String strOrNull(String text) {
+ if(text==null || text.trim().length()==0) {
+ return null;
+ } else {
+ return text;
+ }
+ }
+
+ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR,
strOrNull(outputdir.getText()));
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_PREFER_BASIC_COMPOSITE_IDS,
preferRawCompositeIds.isSelected());
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_MANY_TO_MANY,
autoManyToMany.isSelected());
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_VERSIONING,
autoVersioning.isSelected());
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER,
isReverseEngineerEnabled());
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_STRATEGY,
strOrNull(reverseEngineeringStrategy.getText()));
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
strOrNull(reverseEngineeringSettings.getText()));
+
+
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_USE_OWN_TEMPLATES,
useOwnTemplates.isSelected());
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_TEMPLATE_DIR,
strOrNull(templatedir.getText()));
+
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
getConfigurationName());
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_PACKAGE_NAME,
getOutputPackage());
+
+ }
+
+ public String getName() {
+ return "Main";
+ }
+
+ public Image getImage() {
+ return EclipseImages.getImage(ImageConstants.MINI_HIBERNATE);
+ }
+
+
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterAttributes.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterAttributes.java 2007-09-25
07:16:29 UTC (rev 3782)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterAttributes.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -42,12 +42,16 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.hibernate.console.HibernateConsoleRuntimeException;
import org.hibernate.eclipse.console.ExtensionManager;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.model.impl.ExporterDefinition;
@@ -99,24 +103,120 @@
templatePath = null;
}
- ExporterDefinition[] exDefinitions =
ExtensionManager.findExporterDefinitions();
-
- exporterFactories = new ArrayList();
- for (int i = 0; i < exDefinitions.length; i++) {
- ExporterDefinition expDef = exDefinitions[i];
- ExporterFactory exporterFactory = new ExporterFactory( expDef );
- exporterFactory.isEnabled( configuration );
- exporterFactories.add( exporterFactory );
- Map props = configuration.getAttribute( exporterFactory.getId()
- + ".properties", new HashMap() );
- exporterFactory.setProperties( props );
- }
+ exporterFactories = readExporterFactories(configuration);
} catch (CoreException e) {
throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
}
}
+
+ static String getLaunchAttributePrefix(String exporterId) {
+ return HibernateLaunchConstants.ATTR_EXPORTERS + "." + exporterId;
+ }
+ private List readExporterFactories(ILaunchConfiguration configuration) throws
CoreException {
+
+ List exporterNames =
configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, (List)null);
+
+ if(exporterNames!=null) {
+ Map exDefinitions = ExtensionManager.findExporterDefinitionsAsMap();
+ List factories = new ArrayList();
+
+ for (Iterator iterator = exporterNames.iterator(); iterator.hasNext();) {
+ String exporterId = (String) iterator.next();
+ String extensionId =
configuration.getAttribute(getLaunchAttributePrefix(exporterId) +
".extension_id", (String)null);
+
+ ExporterDefinition expDef = (ExporterDefinition) exDefinitions.get(extensionId);
+ if(expDef==null) {
+ throw new HibernateConsoleRuntimeException("Could not locate exporter for
'" + extensionId + "' in " + configuration.getName());
+ } else {
+ ExporterFactory exporterFactory = new ExporterFactory( expDef, exporterId );
+ exporterFactory.isEnabled( configuration );
+ factories.add( exporterFactory );
+ Map props = configuration.getAttribute(
getLaunchAttributePrefix(exporterFactory.getId())
+ + ".properties", new HashMap() );
+ exporterFactory.setProperties( props );
+ }
+ }
+ return factories;
+
+ } else {
+ // fall back to old way of reading if list of exporters does not exist.
+ ExporterDefinition[] exDefinitions = ExtensionManager.findExporterDefinitions();
+ List factories = new ArrayList();
+
+ for (int i = 0; i < exDefinitions.length; i++) {
+ ExporterDefinition expDef = exDefinitions[i];
+ ExporterFactory exporterFactory = new ExporterFactory( expDef, expDef.getId() );
+ exporterFactory.isEnabled( configuration );
+ factories.add( exporterFactory );
+ Map props = configuration.getAttribute(
getLaunchAttributePrefix(exporterFactory.getId())
+ + ".properties", new HashMap() );
+ exporterFactory.setProperties( props );
+ }
+
+ return factories;
+ }
+ }
+
+ public static void saveExporterFactories(
+ ILaunchConfigurationWorkingCopy configuration,
+ List exporterFactories, List enabledExporters, Set deletedExporterIds) {
+
+
+ List names = new ArrayList();
+ for (Iterator iter = exporterFactories.iterator(); iter.hasNext();) {
+ ExporterFactory ef = (ExporterFactory) iter.next();
+ configuration.setAttribute(getLaunchAttributePrefix(ef.getId()) +
".extension_id", ef.getExporterDefinition().getId());
+ boolean enabled = enabledExporters.contains( ef );
+ String propertiesId = getLaunchAttributePrefix(ef.getId()) + ".properties";
+ names.add(ef.getId());
+ ef.setEnabled( configuration, enabled, false );
+
+ HashMap map = new HashMap(ef.getProperties());
+
+ if(map.isEmpty()) {
+ configuration.setAttribute( propertiesId, (Map)null );
+ } else {
+ configuration.setAttribute( propertiesId, map );
+ }
+ }
+
+ deletedExporterIds.removeAll(names);
+
+ for (Iterator iterator = deletedExporterIds.iterator(); iterator.hasNext();) {
+ String deleted = (String) iterator.next();
+
+ configuration.setAttribute( getLaunchAttributePrefix( deleted ), (String)null);
+ configuration.setAttribute(getLaunchAttributePrefix(deleted ) +
".extension_id", (String)null);
+ configuration.setAttribute(getLaunchAttributePrefix(deleted), (String)null);
+ }
+
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, names);
+ }
+
+ public static void oldSaveExporterFactories(
+ ILaunchConfigurationWorkingCopy configuration,
+ List exporterFactories, List enabledExporters) {
+
+
+ for (Iterator iter = exporterFactories.iterator(); iter.hasNext();) {
+ ExporterFactory ef = (ExporterFactory) iter.next();
+ boolean enabled = enabledExporters.contains( ef );
+ String propertiesId = ef.getId() + ".properties";
+
+ ef.setEnabled( configuration, enabled, true );
+
+ HashMap map = new HashMap(ef.getProperties());
+
+ if(map.isEmpty()) {
+ configuration.setAttribute( propertiesId, (Map)null );
+ } else {
+ configuration.setAttribute( propertiesId, map );
+ }
+ }
+ }
+
private Path pathOrNull(String p) {
if(p==null || p.trim().length()==0) {
@@ -247,6 +347,7 @@
public boolean detectOptimisticLock() {
return autoVersioning;
}
+
Deleted:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettings.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettings.java 2007-09-25
07:16:29 UTC (rev 3782)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettings.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -1,605 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.hibernate.eclipse.launch;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.resources.IProject;
-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.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogPage;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.ui.views.properties.IPropertyDescriptor;
-import org.eclipse.ui.views.properties.IPropertySheetEntry;
-import org.eclipse.ui.views.properties.IPropertySheetEntryListener;
-import org.eclipse.ui.views.properties.IPropertySource;
-import org.eclipse.ui.views.properties.IPropertySourceProvider;
-import org.eclipse.ui.views.properties.PropertySheetEntry;
-import org.eclipse.ui.views.properties.PropertySheetPage;
-import org.hibernate.console.ImageConstants;
-import org.hibernate.eclipse.console.ExtensionManager;
-import org.hibernate.eclipse.console.HibernateConsolePlugin;
-import org.hibernate.eclipse.console.model.impl.ExporterDefinition;
-import org.hibernate.eclipse.console.model.impl.ExporterFactory;
-import org.hibernate.eclipse.console.utils.EclipseImages;
-
-public class ExporterSettings extends AbstractLaunchConfigurationTab {
- private Button enableEJB3annotations;
-
- private Button enableJDK5;
-
- private List selectedExporters;
-
- private CheckboxTableViewer exporterTable;
-
- private Button selectAll;
-
- private Button deselectAll;
-
- private PropertySheetPage propertySheet;
-
- private Button add;
-
- private Button remove;
-
- /**
- * Constructor for SampleNewWizardPage.
- *
- * @param pageName
- */
- public ExporterSettings() {
- super();
- }
-
- /**
- * @see IDialogPage#createControl(Composite)
- */
- public void createControl(Composite parent) {
- selectedExporters = new ArrayList();
-
- // ScrolledComposite scrolled = new ScrolledComposite(parent,
- // SWT.V_SCROLL | SWT.H_SCROLL);
-
- Composite container = new Composite( parent, SWT.NONE );
- GridData controlData = new GridData( GridData.FILL_BOTH );
- container.setLayoutData( controlData );
-
- GridLayout layout = new GridLayout();
- layout.marginHeight = 5;
- layout.marginWidth = 5;
- layout.verticalSpacing = 1;
- container.setLayout( layout );
-
- createGeneralSettings( container );
-
- createExporterTable( container );
-
- createExporterProperties( container );
-
- dialogChanged();
- setControl( container );
- }
-
- private void createExporterProperties(Composite parent) {
- Composite exportersComposite = createComposite( parent, "Properties:" );
-
- exportersComposite.setLayout( new GridLayout( 2, false ) );
-
- GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true );
- gd.minimumHeight = 100;
- exportersComposite.setLayoutData( gd );
-
- Group gr = new Group(exportersComposite, SWT.NONE);
-
- GridLayout gridLayout = new GridLayout();
- gridLayout.marginHeight = 0;
- gridLayout.marginWidth = 0;
-
- gr.setLayout( gridLayout );
- gd = new GridData( SWT.FILL, SWT.FILL, true, true );
- gd.verticalSpan = 2;
- gr.setLayoutData( gd );
-
- Control sheet = createPropertySheet( gr );
- gd = new GridData( SWT.FILL, SWT.FILL, true, true );
- sheet.setLayoutData( gd );
-
- add = new Button( exportersComposite, SWT.PUSH );
- add.setEnabled( false );
- add.setText( "Add..." );
- gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL
- | GridData.VERTICAL_ALIGN_BEGINNING );
- gd.horizontalIndent = 5;
- add.setLayoutData( gd );
- add.addSelectionListener( new SelectionAdapter() {
-
- public void widgetSelected(SelectionEvent e) {
- IStructuredSelection ss = (IStructuredSelection) exporterTable.getSelection();
- ExporterFactory ef = (ExporterFactory) ss.getFirstElement();
-
- if(ef!=null) {
- AddPropertyDialog dialog = new AddPropertyDialog(getShell(), ef);
- if(dialog.open()==Dialog.OK) {
- ef.setProperty( dialog.getPropertyName(), dialog.getPropertyValue() );
- dialogChanged();
- refreshPropertySheet();
- }
- }
- }
-
- } );
-
- remove = new Button( exportersComposite, SWT.PUSH );
- remove.setText( "Remove..." );
- remove.setEnabled( false );
- remove.addSelectionListener( new SelectionAdapter() {
-
- public void widgetSelected(SelectionEvent e) {
- if(currentDescriptor!=null) {
- IStructuredSelection ss = (IStructuredSelection) exporterTable.getSelection();
- ExporterFactory ef = (ExporterFactory) ss.getFirstElement();
- ef.removeProperty( (String) currentDescriptor.getId() );
- dialogChanged();
- refreshPropertySheet();
- }
- }
-
- } );
-
- gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL
- | GridData.VERTICAL_ALIGN_BEGINNING );
- gd.horizontalIndent = 5;
- remove.setLayoutData( gd );
-
- }
-
- public class MyPropertySheetEntry extends PropertySheetEntry {
-
- public IPropertyDescriptor getMyDescriptor() {
- return super.getDescriptor();
- }
-
- protected PropertySheetEntry createChildEntry() {
- return new MyPropertySheetEntry();
- }
- }
-
- // currently selected in the propertysheet
- private IPropertyDescriptor currentDescriptor;
-
- private Control createPropertySheet(Composite exportersComposite) {
- propertySheet = new PropertySheetPage() {
-
-
- public void handleEntrySelection(ISelection selection) {
- super.handleEntrySelection( selection );
- IStructuredSelection iss = (IStructuredSelection) selection;
- if(iss.isEmpty()) {
- currentDescriptor = null;
- } else {
- MyPropertySheetEntry mse = (MyPropertySheetEntry)iss.getFirstElement();
- currentDescriptor = mse.getMyDescriptor();
- }
- }
- };
-
- propertySheet.createControl( exportersComposite );
-
- final PropertySheetEntry propertySheetEntry = new MyPropertySheetEntry();
-
- propertySheetEntry
- .setPropertySourceProvider( new IPropertySourceProvider() {
-
- public IPropertySource getPropertySource(Object object) {
- if ( object instanceof ExporterFactory ) {
- return new ExporterFactoryPropertySource(
- (ExporterFactory) object ) {
- public void setPropertyValue(Object id, Object value) {
- super.setPropertyValue( id, value );
- dialogChanged();
- }
- };
- }
- else {
- return null;
- }
- }
- } );
- propertySheet.setRootEntry( propertySheetEntry );
- // propertySheetEntry.setValues( new Object[] { this });
-
- exporterTable
- .addSelectionChangedListener( new ISelectionChangedListener() {
-
- public void selectionChanged(SelectionChangedEvent event) {
- IStructuredSelection s = (IStructuredSelection) event
- .getSelection();
- if(s.isEmpty()) {
- if(add!=null) add.setEnabled( false );
- if(remove!=null) remove.setEnabled( false );
-
- } else {
- if(add!=null) add.setEnabled( true );
- if(remove!=null) remove.setEnabled( true );
-
- ExporterFactory ep = (ExporterFactory) s
- .getFirstElement();
- propertySheetEntry.setValues( new Object[] { ep } );
- // if(ep.isEnabled( configuration ))
- }
- }
-
- } );
-
- return propertySheet.getControl();
- }
-
- private void createExporterTable(Composite parent) {
- Composite exporterOptions = createComposite( parent, "Exporters:" );
-
- GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true );
- gd.minimumHeight = 100;
- exporterOptions.setLayoutData( gd );
-
- exporterOptions.setLayout( new GridLayout( 2, false ) );
-
- Table table = new Table( exporterOptions, SWT.CHECK | SWT.BORDER
- | SWT.V_SCROLL );
- exporterTable = new CheckboxTableViewer( table );
- exporterTable.setContentProvider( new ExporterContentProvider() );
- exporterTable.setLabelProvider( new ExporterLabelProvider() );
-
- // exporterTable.getControl().setLayoutData(
- // new GridData( SWT.FILL, SWT.FILL, true, true ) );
- exporterTable.setColumnProperties( new String[] { "", "Description"
} );
- exporterTable.addCheckStateListener( new ICheckStateListener() {
- public void checkStateChanged(CheckStateChangedEvent event) {
-
- ExporterFactory factory = (ExporterFactory) event.getElement();
-
- if ( !event.getChecked()
- && selectedExporters.contains( factory ) ) {
- selectedExporters.remove( factory );
- }
- else if ( event.getChecked()
- && !selectedExporters.contains( factory ) ) {
- selectedExporters.add( factory );
- }
-
- dialogChanged();
- }
- } );
-
- gd = new GridData( SWT.FILL, SWT.FILL, true, true );
- gd.verticalSpan = 2;
- gd.horizontalSpan = 1;
- table.setLayoutData( gd );
-
- selectAll = new Button( exporterOptions, SWT.PUSH );
- selectAll.setText( "Select All" );
- selectAll.addSelectionListener( new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- exporterTable.setAllChecked( true );
- dialogChanged();
- }
- } );
- gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL
- | GridData.VERTICAL_ALIGN_BEGINNING );
- gd.horizontalIndent = 5;
- selectAll.setLayoutData( gd );
-
- deselectAll = new Button( exporterOptions, SWT.PUSH );
- deselectAll.setText( "Deselect All" );
- deselectAll.addSelectionListener( new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- exporterTable.setAllChecked( false );
- dialogChanged();
- }
- } );
-
- gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL
- | GridData.VERTICAL_ALIGN_BEGINNING );
- gd.horizontalIndent = 5;
- deselectAll.setLayoutData( gd );
-
- }
-
- private void createGeneralSettings(Composite parent) {
-
- SelectionListener fieldlistener = new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected( e );
- }
-
- public void widgetSelected(SelectionEvent e) {
- dialogChanged();
- }
- };
- Composite generalSettingsComposite = createComposite( parent,
- "General settings:" );
- generalSettingsComposite.setLayoutData( new GridData( SWT.BEGINNING,
- SWT.BEGINNING, false, false ) );
-
- enableJDK5 = new Button( generalSettingsComposite, SWT.CHECK );
- enableJDK5.setText( "Use Java 5 syntax" );
- enableJDK5.addSelectionListener( fieldlistener );
-
- enableEJB3annotations = new Button( generalSettingsComposite, SWT.CHECK );
- enableEJB3annotations.setText( "Generate EJB3 annotations" );
- enableEJB3annotations.addSelectionListener( fieldlistener );
- }
-
- private class ExporterContentProvider implements IStructuredContentProvider {
-
- public Object[] getElements(Object inputElement) {
- return ((List) inputElement ).toArray();
- }
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- }
-
- private class ExporterLabelProvider implements ITableLabelProvider {
- Map exp2img = new HashMap(); // not the most optimized but better
-
- // than having a finalize method.
-
- public Image getColumnImage(Object element, int columnIndex) {
- ExporterFactory ef = (ExporterFactory) element;
- ExporterDefinition definition = ef.getExporterDefinition();
- Image image = (Image) exp2img.get( definition.getId() );
- if ( image == null ) {
- image = definition.getIconDescriptor().createImage();
- exp2img.put( definition.getId(), image );
- }
- return image;
- }
-
- public String getColumnText(Object element, int columnIndex) {
- ExporterFactory ef = (ExporterFactory) element;
- ExporterDefinition definition = ef.getExporterDefinition();
- return definition.getDescription();
- }
-
- public void addListener(ILabelProviderListener listener) {
- }
-
- public void dispose() {
-
- Iterator iterator = exp2img.values().iterator();
- while ( iterator.hasNext() ) {
- Image img = (Image) iterator.next();
- if ( img != null ) {
- img.dispose();
- }
- }
- }
-
- public boolean isLabelProperty(Object element, String property) {
- return true;
- }
-
- public void removeListener(ILabelProviderListener listener) {
- }
-
- }
-
- private Composite createComposite(Composite parent, String name) {
-
- new Label( parent, SWT.NONE ).setText( name );
- Composite client = new Composite( parent, SWT.NONE );
- client.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
- client.setLayout( new GridLayout() );
- // client.setBackground( ColorConstants.cyan );
- return client;
- }
-
- private void dialogChanged() {
- boolean configSelected = true; // TODO: only active if configname in
- // settings
- // ...getConfigurationName().length()==0;
-
- if ( !configSelected ) {
- updateStatus( "Console configuration must be specified" );
- return;
- }
-
- if ( selectedExporters.size() == 0 ) {
- updateStatus( "At least one exporter option must be selected" );
- return;
- }
- updateStatus( null );
- }
-
- protected String checkDirectory(IPath path, String name) {
- IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(
- path );
- if ( res != null ) {
- int resType = res.getType();
- if ( resType == IResource.PROJECT || resType == IResource.FOLDER ) {
- IProject proj = res.getProject();
- if ( !proj.isOpen() ) {
- return "Project for " + name + " is closed";
- }
- }
- else {
- return name + " has to be a folder or project";
- }
- }
- else {
- return name + " does not exist";
- }
- return null;
- }
-
- protected String checkFile(IPath path, String name) {
- IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(
- path );
- if ( res != null ) {
- int resType = res.getType();
- if ( resType == IResource.FILE ) {
- return null;
- }
- else {
- return name + " must be a file";
- }
- }
- else {
- return name + " does not exist";
- }
- }
-
- private void updateStatus(String message) {
- setErrorMessage( message );
- updateLaunchConfigurationDialog();
- }
-
- private Path pathOrNull(String p) {
- if ( p == null || p.trim().length() == 0 ) {
- return null;
- }
- else {
- return new Path( p );
- }
- }
-
- public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
- // ExporterAttributes tmpAttrs = new ExporterAttributes();
- // tmpAttrs.setEnableAllExporters(true);
- // tmpAttrs.save(configuration);
- }
-
- public void initializeFrom(ILaunchConfiguration configuration) {
- try {
- ExporterAttributes attributes = new ExporterAttributes(
- configuration );
- selectedExporters.clear();
-
- enableEJB3annotations.setSelection( attributes.isEJB3Enabled() );
- enableJDK5.setSelection( attributes.isJDK5Enabled() );
-
- List exporterFactories = attributes.getExporterFactories();
- exporterTable.setInput( exporterFactories );
- for (Iterator iter = exporterFactories.iterator(); iter.hasNext();) {
- ExporterFactory exporterFactory = (ExporterFactory) iter.next();
- if ( exporterFactory.isEnabled() ) {
- exporterTable.setChecked( exporterFactory, true );
- selectedExporters.add( exporterFactory );
- }
- else {
- exporterTable.setChecked( exporterFactory, false );
- }
- }
-
- refreshPropertySheet();
-
- dialogChanged();
-
- }
- catch (CoreException ce) {
- HibernateConsolePlugin
- .getDefault()
- .logErrorMessage(
- "Problem when reading hibernate tools launch configuration",
- ce );
- }
- }
-
- private void refreshPropertySheet() {
- exporterTable.setSelection( exporterTable.getSelection() ); // here to make sure the
dependent propertysheet actually will reread what ever the selection is.
- }
-
- public void performApply(ILaunchConfigurationWorkingCopy configuration) {
- configuration.setAttribute(
- HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS,
- enableEJB3annotations.getSelection() );
- configuration.setAttribute( HibernateLaunchConstants.ATTR_ENABLE_JDK5,
- enableJDK5.getSelection() );
-
- List exporterFactories = (List) exporterTable.getInput();
- for (Iterator iter = exporterFactories.iterator(); iter.hasNext();) {
- ExporterFactory ef = (ExporterFactory) iter.next();
- boolean enabled = selectedExporters.contains( ef );
-
- String propertiesId = ef.getId() + ".properties";
-
- ef.setEnabled( configuration, enabled );
-
-
- HashMap map = new HashMap(ef.getProperties());
-
- if(map.isEmpty()) {
- configuration.setAttribute( propertiesId, (Map)null );
- } else {
- configuration.setAttribute( propertiesId, map );
- }
- }
-
- }
-
- public String getName() {
- return "Exporters";
- }
-
- public Image getImage() {
- return EclipseImages.getImage( ImageConstants.MINI_HIBERNATE );
- }
-
-}
Copied:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettingsTab.java
(from rev 3703,
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettings.java)
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettingsTab.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettingsTab.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -0,0 +1,883 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.eclipse.launch;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+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.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.ui.JavaElementLabelProvider;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogPage;
+import org.eclipse.jface.viewers.AbstractTableViewer;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.IPropertySourceProvider;
+import org.eclipse.ui.views.properties.PropertySheetEntry;
+import org.eclipse.ui.views.properties.PropertySheetPage;
+import org.hibernate.console.ImageConstants;
+import org.hibernate.eclipse.console.ExtensionManager;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.model.impl.ExporterDefinition;
+import org.hibernate.eclipse.console.model.impl.ExporterFactory;
+import org.hibernate.eclipse.console.utils.EclipseImages;
+import org.hibernate.eclipse.console.wizards.UpDownListComposite;
+
+public class ExporterSettingsTab extends AbstractLaunchConfigurationTab {
+ private Button enableEJB3annotations;
+
+ private Button enableJDK5;
+
+ private List selectedExporters;
+
+ private Set deletedExporterIds;
+
+ //private CheckboxTableViewer exporterTable;
+
+ private Button selectAll;
+
+ private Button deselectAll;
+
+ private PropertySheetPage propertySheet;
+
+ private Button add;
+
+ private Button remove;
+
+ /**
+ * Constructor for SampleNewWizardPage.
+ *
+ * @param pageName
+ */
+ public ExporterSettingsTab() {
+ super();
+ }
+
+ /**
+ * @see IDialogPage#createControl(Composite)
+ */
+ public void createControl(Composite parent) {
+ selectedExporters = new ArrayList();
+ deletedExporterIds = new HashSet();
+ // ScrolledComposite scrolled = new ScrolledComposite(parent,
+ // SWT.V_SCROLL | SWT.H_SCROLL);
+
+ Composite container = new Composite( parent, SWT.NONE );
+ GridData controlData = new GridData( GridData.FILL_BOTH );
+ container.setLayoutData( controlData );
+
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 5;
+ layout.marginWidth = 5;
+ layout.verticalSpacing = 1;
+ container.setLayout( layout );
+
+ createGeneralSettings( container );
+
+ createExporterTable( container );
+
+ createExporterProperties( container );
+
+ dialogChanged();
+ setControl( container );
+ }
+
+ private void createExporterProperties(Composite parent) {
+ Composite exportersComposite = createComposite( parent, "Properties:" );
+
+ exportersComposite.setLayout( new GridLayout( 2, false ) );
+
+ GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true );
+ gd.minimumHeight = 100;
+ exportersComposite.setLayoutData( gd );
+
+ Group gr = new Group(exportersComposite, SWT.NONE);
+
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.marginHeight = 0;
+ gridLayout.marginWidth = 0;
+
+ gr.setLayout( gridLayout );
+ gd = new GridData( SWT.FILL, SWT.FILL, true, true );
+ gd.verticalSpan = 2;
+ gr.setLayoutData( gd );
+
+ Control sheet = createPropertySheet( gr );
+ gd = new GridData( SWT.FILL, SWT.FILL, true, true );
+ sheet.setLayoutData( gd );
+
+ add = new Button( exportersComposite, SWT.PUSH );
+ add.setEnabled( false );
+ add.setText( "Add..." );
+ gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.VERTICAL_ALIGN_BEGINNING );
+ gd.horizontalIndent = 5;
+ add.setLayoutData( gd );
+ add.addSelectionListener( new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ IStructuredSelection ss = (IStructuredSelection) getExporterTable().getSelection();
+ ExporterFactory ef = (ExporterFactory) ss.getFirstElement();
+
+ if(ef!=null) {
+ AddPropertyDialog dialog = new AddPropertyDialog(getShell(), ef);
+ if(dialog.open()==Dialog.OK) {
+ ef.setProperty( dialog.getPropertyName(), dialog.getPropertyValue() );
+ dialogChanged();
+ refreshPropertySheet();
+ }
+ }
+ }
+
+ } );
+
+ remove = new Button( exportersComposite, SWT.PUSH );
+ remove.setText( "Remove..." );
+ remove.setEnabled( false );
+ remove.addSelectionListener( new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ if(currentDescriptor!=null) {
+ IStructuredSelection ss = (IStructuredSelection) getExporterTable().getSelection();
+ ExporterFactory ef = (ExporterFactory) ss.getFirstElement();
+ ef.removeProperty( (String) currentDescriptor.getId() );
+ dialogChanged();
+ refreshPropertySheet();
+ }
+ }
+
+ } );
+
+ gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.VERTICAL_ALIGN_BEGINNING );
+ gd.horizontalIndent = 5;
+ remove.setLayoutData( gd );
+
+ }
+
+ public class MyPropertySheetEntry extends PropertySheetEntry {
+
+ public IPropertyDescriptor getMyDescriptor() {
+ return super.getDescriptor();
+ }
+
+ protected PropertySheetEntry createChildEntry() {
+ return new MyPropertySheetEntry();
+ }
+ }
+
+ // currently selected in the propertysheet
+ private IPropertyDescriptor currentDescriptor;
+
+ private UpDownListComposite exporterUpDown;
+
+ private ObservableFactoryList observableFactoryList;
+
+
+
+ private Control createPropertySheet(Composite exportersComposite) {
+ propertySheet = new PropertySheetPage() {
+
+
+ public void handleEntrySelection(ISelection selection) {
+ super.handleEntrySelection( selection );
+ IStructuredSelection iss = (IStructuredSelection) selection;
+ if(iss.isEmpty()) {
+ currentDescriptor = null;
+ } else {
+ MyPropertySheetEntry mse = (MyPropertySheetEntry)iss.getFirstElement();
+ currentDescriptor = mse.getMyDescriptor();
+ }
+ }
+ };
+
+ propertySheet.createControl( exportersComposite );
+
+ final PropertySheetEntry propertySheetEntry = new MyPropertySheetEntry();
+
+ propertySheetEntry
+ .setPropertySourceProvider( new IPropertySourceProvider() {
+
+ public IPropertySource getPropertySource(Object object) {
+ if ( object instanceof ExporterFactory ) {
+ return new ExporterFactoryPropertySource(
+ (ExporterFactory) object ) {
+ public void setPropertyValue(Object id, Object value) {
+ super.setPropertyValue( id, value );
+ dialogChanged();
+ }
+ };
+ }
+ else {
+ return null;
+ }
+ }
+ } );
+ propertySheet.setRootEntry( propertySheetEntry );
+ // propertySheetEntry.setValues( new Object[] { this });
+
+ getExporterTable()
+ .addSelectionChangedListener( new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection s = (IStructuredSelection) event
+ .getSelection();
+ if(s.isEmpty()) {
+ if(add!=null) add.setEnabled( false );
+ if(remove!=null) remove.setEnabled( false );
+
+ propertySheetEntry.setValues(new Object[0]);
+
+ } else {
+ if(add!=null) add.setEnabled( true );
+ if(remove!=null) remove.setEnabled( true );
+
+ ExporterFactory ep = (ExporterFactory) s
+ .getFirstElement();
+ propertySheetEntry.setValues( new Object[] { ep } );
+ // if(ep.isEnabled( configuration ))
+ }
+ }
+
+ } );
+
+ return propertySheet.getControl();
+ }
+
+ private void createExporterTable(Composite parent) {
+ exporterUpDown = new UpDownListComposite(parent, SWT.NONE, "Exporters:",
true, new ExporterLabelProvider(), new ExporterContentProvider()) {
+
+ protected Object[] handleAdd(int idx) {
+
+ switch (idx) {
+ case 0:
+ Object[] selectExporters = selectExporters(getShell(), "Add exporter",
"Select the exporter(s) you want to add");
+ for (int i = 0; i < selectExporters.length; i++) {
+ ExporterDefinition exporterDefinition = (ExporterDefinition) selectExporters[i];
+ addDef(exporterDefinition);
+ }
+ return new Object[0];// { exporterFactory };
+ case 1:
+ getExporterTable().setAllChecked( true );
+ break;
+ case 2:
+ getExporterTable().setAllChecked( false );
+ break;
+ default:
+ break;
+ }
+ return null;
+ }
+
+ private void addDef(ExporterDefinition expDef) {
+ int initialCount = getTable().getItemCount();
+ boolean duplicate = false;
+ do {
+ duplicate = false;
+ initialCount++;
+ Iterator iterator = observableFactoryList.getList().iterator();
+ while(iterator.hasNext()) {
+ ExporterFactory def = (ExporterFactory) iterator.next();
+ if(def.getId().equals(""+initialCount)) {
+ duplicate = true;
+ }
+ }
+ } while(duplicate);
+
+ String initialName = "" + initialCount;
+
+ ExporterFactory exporterFactory = new ExporterFactory( expDef, initialName );
+ observableFactoryList.add(exporterFactory);
+ ((CheckboxTableViewer)getTableViewer()).setChecked(exporterFactory, true);
+ }
+
+ protected void handleRemove() {
+ IStructuredSelection selection = (IStructuredSelection)
getTableViewer().getSelection();
+ if (selection != null) {
+ int numSelected= selection.size();
+
+ Iterator iterator= selection.iterator();
+ while (iterator.hasNext() ) {
+ Object item= iterator.next();
+ observableFactoryList.remove((ExporterFactory)item);
+ deletedExporterIds.add(((ExporterFactory)item).getId());
+ }
+ //getTableViewer().setSelection(StructuredSelection.EMPTY);
+ listChanged();
+ }
+ }
+
+ protected void moveSelectionDown() {
+ Table table = getTableViewer().getTable();
+ int indices[]= table.getSelectionIndices();
+ if (indices.length < 1) {
+ return;
+ }
+ int newSelection[]= new int[indices.length];
+ int max= table.getItemCount() - 1;
+ for (int i = indices.length - 1; i >= 0; i--) {
+ int index= indices[i];
+ if (index < max) {
+ ExporterFactory data = (ExporterFactory)
getTableViewer().getElementAt(index);
+ observableFactoryList.moveTo(index + 1, (ExporterFactory)data);
+ newSelection[i]= index + 1;
+ }
+ }
+ table.setSelection(newSelection);
+ listChanged();
+ }
+
+ protected void moveSelectionUp() {
+ Table table = getTableViewer().getTable();
+ int indices[]= table.getSelectionIndices();
+ int newSelection[]= new int[indices.length];
+ for (int i = 0; i < indices.length; i++) {
+ int index= indices[i];
+ if (index > 0) {
+ ExporterFactory data = (ExporterFactory)
getTableViewer().getElementAt(index);
+ observableFactoryList.moveTo(index - 1, (ExporterFactory)data);
+ newSelection[i]= index - 1;
+ }
+ }
+ table.setSelection(newSelection);
+ listChanged();
+ }
+
+ protected String[] getAddButtonLabels() {
+ return new String[] { "Add...", "Select all", "Deselect
all" };
+ }
+ protected void listChanged() {
+ dialogChanged();
+ }
+ };
+
+ getExporterTable().addCheckStateListener( new ICheckStateListener() {
+ public void checkStateChanged(CheckStateChangedEvent event) {
+
+ ExporterFactory factory = (ExporterFactory) event.getElement();
+
+ if ( !event.getChecked()
+ && selectedExporters.contains( factory ) ) {
+ selectedExporters.remove( factory );
+ }
+ else if ( event.getChecked()
+ && !selectedExporters.contains( factory ) ) {
+ selectedExporters.add( factory );
+ }
+
+ dialogChanged();
+ }
+ } );
+
+ GridData gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.grabExcessVerticalSpace = true;
+ gd.verticalAlignment = GridData.FILL;
+ gd.horizontalAlignment = GridData.FILL;
+ exporterUpDown.setLayoutData( gd );
+ }
+
+ private void createOldExporterTable(Composite parent) {
+ Composite exporterOptions = createComposite( parent, "Exporters:" );
+
+ GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true );
+ gd.minimumHeight = 100;
+ exporterOptions.setLayoutData( gd );
+
+ exporterOptions.setLayout( new GridLayout( 2, false ) );
+
+ Table table = new Table( exporterOptions, SWT.CHECK | SWT.BORDER
+ | SWT.V_SCROLL );
+ //setExporterTable(new CheckboxTableViewer( table ));
+ getExporterTable().setContentProvider( new ExporterContentProvider() );
+ getExporterTable().setLabelProvider( new ExporterLabelProvider() );
+
+ // exporterTable.getControl().setLayoutData(
+ // new GridData( SWT.FILL, SWT.FILL, true, true ) );
+ getExporterTable().setColumnProperties( new String[] { "",
"Description" } );
+ getExporterTable().addCheckStateListener( new ICheckStateListener() {
+ public void checkStateChanged(CheckStateChangedEvent event) {
+
+ ExporterFactory factory = (ExporterFactory) event.getElement();
+
+ if ( !event.getChecked()
+ && selectedExporters.contains( factory ) ) {
+ selectedExporters.remove( factory );
+ }
+ else if ( event.getChecked()
+ && !selectedExporters.contains( factory ) ) {
+ selectedExporters.add( factory );
+ }
+
+ dialogChanged();
+ }
+ } );
+
+ gd = new GridData( SWT.FILL, SWT.FILL, true, true );
+ gd.verticalSpan = 2;
+ gd.horizontalSpan = 1;
+ table.setLayoutData( gd );
+
+ selectAll = new Button( exporterOptions, SWT.PUSH );
+ selectAll.setText( "Select All" );
+ selectAll.addSelectionListener( new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ getExporterTable().setAllChecked( true );
+ dialogChanged();
+ }
+ } );
+ gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.VERTICAL_ALIGN_BEGINNING );
+ gd.horizontalIndent = 5;
+ selectAll.setLayoutData( gd );
+
+ deselectAll = new Button( exporterOptions, SWT.PUSH );
+ deselectAll.setText( "Deselect All" );
+ deselectAll.addSelectionListener( new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ getExporterTable().setAllChecked( false );
+ dialogChanged();
+ }
+ } );
+
+ gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.VERTICAL_ALIGN_BEGINNING );
+ gd.horizontalIndent = 5;
+ deselectAll.setLayoutData( gd );
+
+ }
+
+ private void createGeneralSettings(Composite parent) {
+
+ SelectionListener fieldlistener = new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected( e );
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ dialogChanged();
+ }
+ };
+ Composite generalSettingsComposite = createComposite( parent,
+ "General settings:" );
+ generalSettingsComposite.setLayoutData( new GridData( SWT.BEGINNING,
+ SWT.BEGINNING, false, false ) );
+
+ enableJDK5 = new Button( generalSettingsComposite, SWT.CHECK );
+ enableJDK5.setText( "Use Java 5 syntax" );
+ enableJDK5.addSelectionListener( fieldlistener );
+
+ enableEJB3annotations = new Button( generalSettingsComposite, SWT.CHECK );
+ enableEJB3annotations.setText( "Generate EJB3 annotations" );
+ enableEJB3annotations.addSelectionListener( fieldlistener );
+ }
+
+ private class ExporterContentProvider implements IStructuredContentProvider,
PropertyChangeListener {
+
+ private AbstractTableViewer viewer;
+
+ public Object[] getElements(Object inputElement) {
+ return ((ObservableFactoryList) inputElement ).getList().toArray();
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ this.viewer = (AbstractTableViewer) viewer;
+ ObservableFactoryList ol = (ObservableFactoryList) oldInput;
+ ObservableFactoryList newList = (ObservableFactoryList) newInput;
+
+ if(ol!=null) {
+ ol.removePropertyChangeListener(this);
+ }
+
+ if(newList!=null) {
+ newList.addPropertyChangeListener(this);
+ }
+ }
+
+ public void propertyChange(PropertyChangeEvent evt) {
+
+ if("addElement".equals(evt.getPropertyName())) {
+ viewer.add(evt.getNewValue());
+ }
+
+ if("removeElement".equals(evt.getPropertyName())) {
+ viewer.remove(evt.getOldValue());
+ }
+
+ if("insertElement".equals(evt.getPropertyName())) {
+ viewer.insert(evt.getNewValue(), ((Integer)evt.getOldValue()).intValue());
+ }
+ }
+
+ }
+
+ // Complete hack to get table to work with arbitrary exporters quickly.
+ private class ObservableFactoryList {
+
+ List underlyingList = new ArrayList();
+
+ PropertyChangeSupport pcs = new PropertyChangeSupport(this);
+
+ public ObservableFactoryList(List exporterFactories) {
+ underlyingList = exporterFactories;
+ }
+
+ public void moveTo(int i, ExporterFactory data) {
+ underlyingList.remove((ExporterFactory) data);
+ remove(data);
+ underlyingList.add(i, data);
+ pcs.firePropertyChange("insertElement", new Integer(i), data);
+
+ }
+
+ void addPropertyChangeListener(PropertyChangeListener pcl) {
+ pcs.addPropertyChangeListener(pcl);
+ }
+
+ public List getList() {
+ return Collections.unmodifiableList(underlyingList);
+ }
+
+ void removePropertyChangeListener(PropertyChangeListener pcl) {
+ pcs.removePropertyChangeListener(pcl);
+ }
+
+ boolean add(ExporterFactory o) {
+ boolean changed = underlyingList.add(o);
+ pcs.firePropertyChange("addElement", null, o);
+ return changed;
+ }
+
+ boolean remove(ExporterFactory o) {
+ boolean changed = underlyingList.remove(o);
+ pcs.firePropertyChange("removeElement", o, null);
+ return changed;
+ }
+
+
+ }
+
+ static private class ExporterLabelProvider implements ITableLabelProvider,
ILabelProvider {
+ Map exp2img = new HashMap(); // not the most optimized but better
+ // than having a finalize method.
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ ExporterDefinition definition = getExporterDefinition(element);
+ Image image = (Image) exp2img.get( definition.getId() );
+ if ( image == null ) {
+ image = definition.getIconDescriptor().createImage();
+ exp2img.put( definition.getId(), image );
+ }
+ return image;
+ }
+
+ private ExporterDefinition getExporterDefinition(Object element) {
+ if(element instanceof ExporterFactory) {
+ ExporterFactory ef = (ExporterFactory) element;
+ return ef.getExporterDefinition();
+ } else {
+ return (ExporterDefinition) element;
+ }
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ ExporterDefinition definition = getExporterDefinition(element);
+ return definition.getDescription();
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public void dispose() {
+
+ Iterator iterator = exp2img.values().iterator();
+ while ( iterator.hasNext() ) {
+ Image img = (Image) iterator.next();
+ if ( img != null ) {
+ img.dispose();
+ }
+ }
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return true;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ public Image getImage(Object element) {
+ return getColumnImage(element, 0);
+ }
+
+ public String getText(Object element) {
+ return getColumnText(element, 0);
+ }
+
+ }
+
+ private Composite createComposite(Composite parent, String name) {
+
+ new Label( parent, SWT.NONE ).setText( name );
+ Composite client = new Composite( parent, SWT.NONE );
+ client.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+ client.setLayout( new GridLayout() );
+ // client.setBackground( ColorConstants.cyan );
+ return client;
+ }
+
+ private void dialogChanged() {
+ boolean configSelected = true; // TODO: only active if configname in
+ // settings
+ // ...getConfigurationName().length()==0;
+
+ if ( !configSelected ) {
+ updateStatus( "Console configuration must be specified" );
+ return;
+ }
+
+ if ( selectedExporters.size() == 0 ) {
+ updateStatus( "At least one exporter option must be selected" );
+ return;
+ }
+
+
+ // hard-coded checks: this should be delegated to extension point that knows about the
different exporters.
+ Iterator iterator = observableFactoryList.getList().iterator();
+ while (iterator.hasNext()) {
+ ExporterFactory ef = (ExporterFactory) iterator.next();
+ String str = (String) ef.getProperties().get("outputdir");
+ String msg = null;
+ if(str!=null) {
+ msg = PathHelper.checkDirectory(PathHelper.pathOrNull(str), "Output directory
for " + ef.getExporterDefinition().getDescription(), false);
+ if(msg!=null) {
+ updateStatus(msg);
+ return;
+ }
+ }
+
+ str = (String) ef.getProperties().get("template_path");
+ if(str!=null) {
+ msg = PathHelper.checkDirectory(PathHelper.pathOrNull(str), "Template directory
for " + ef.getExporterDefinition().getDescription(), true);
+ if(msg!=null) {
+ updateStatus(msg);
+ return;
+ }
+ }
+
+ }
+ updateStatus( null );
+ }
+
+ protected String checkDirectory(IPath path, String name) {
+ IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(
+ path );
+ if ( res != null ) {
+ int resType = res.getType();
+ if ( resType == IResource.PROJECT || resType == IResource.FOLDER ) {
+ IProject proj = res.getProject();
+ if ( !proj.isOpen() ) {
+ return "Project for " + name + " is closed";
+ }
+ }
+ else {
+ return name + " has to be a folder or project";
+ }
+ }
+ else {
+ return name + " does not exist";
+ }
+ return null;
+ }
+
+ protected String checkFile(IPath path, String name) {
+ IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(
+ path );
+ if ( res != null ) {
+ int resType = res.getType();
+ if ( resType == IResource.FILE ) {
+ return null;
+ }
+ else {
+ return name + " must be a file";
+ }
+ }
+ else {
+ return name + " does not exist";
+ }
+ }
+
+ private void updateStatus(String message) {
+ setErrorMessage( message );
+ updateLaunchConfigurationDialog();
+ }
+
+ private Path pathOrNull(String p) {
+ if ( p == null || p.trim().length() == 0 ) {
+ return null;
+ }
+ else {
+ return new Path( p );
+ }
+ }
+
+ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
+ // ExporterAttributes tmpAttrs = new ExporterAttributes();
+ // tmpAttrs.setEnableAllExporters(true);
+ // tmpAttrs.save(configuration);
+ }
+
+ public void initializeFrom(ILaunchConfiguration configuration) {
+ try {
+ ExporterAttributes attributes = new ExporterAttributes(
+ configuration );
+ selectedExporters.clear();
+
+ enableEJB3annotations.setSelection( attributes.isEJB3Enabled() );
+ enableJDK5.setSelection( attributes.isJDK5Enabled() );
+
+ List exporterFactories = attributes.getExporterFactories();
+ observableFactoryList = new ObservableFactoryList(exporterFactories);
+ getExporterTable().setInput( observableFactoryList );
+ for (Iterator iter = exporterFactories.iterator(); iter.hasNext();) {
+ ExporterFactory exporterFactory = (ExporterFactory) iter.next();
+ if ( exporterFactory.isEnabled() ) {
+ getExporterTable().setChecked( exporterFactory, true );
+ selectedExporters.add( exporterFactory );
+ }
+ else {
+ getExporterTable().setChecked( exporterFactory, false );
+ }
+ }
+
+ refreshPropertySheet();
+
+ dialogChanged();
+
+ }
+ catch (CoreException ce) {
+ HibernateConsolePlugin
+ .getDefault()
+ .logErrorMessage(
+ "Problem when reading hibernate tools launch configuration",
+ ce );
+ }
+ }
+
+ private void refreshPropertySheet() {
+ getExporterTable().setSelection( getExporterTable().getSelection() ); // here to make
sure the dependent propertysheet actually will reread what ever the selection is.
+ }
+
+ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
+ configuration.setAttribute(
+ HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS,
+ enableEJB3annotations.getSelection() );
+ configuration.setAttribute( HibernateLaunchConstants.ATTR_ENABLE_JDK5,
+ enableJDK5.getSelection() );
+
+ List exporterFactories =
((ObservableFactoryList)getExporterTable().getInput()).getList();
+ ExporterAttributes.saveExporterFactories(configuration, exporterFactories,
selectedExporters, deletedExporterIds);
+
+ deletedExporterIds.clear();
+ }
+
+
+
+ public String getName() {
+ return "Exporters";
+ }
+
+ public Image getImage() {
+ return EclipseImages.getImage( ImageConstants.MINI_HIBERNATE );
+ }
+
+ private CheckboxTableViewer getExporterTable() {
+ return (CheckboxTableViewer) exporterUpDown.getTableViewer();
+ }
+
+ public static Object[] selectExporters(Shell shell, String title, String description) {
+ ILabelProvider labelProvider= new ExporterLabelProvider();
+ ElementListSelectionDialog dialog= new ElementListSelectionDialog(shell,
labelProvider);
+ dialog.setTitle(title);
+ dialog.setMessage(description);
+ dialog.setElements(ExtensionManager.findExporterDefinitionsAsMap().values().toArray());
+ dialog.setMultipleSelection(true);
+
+ if (dialog.open() == Window.OK) {
+ return dialog.getResult();
+ } else {
+ return new ExporterDefinition[0];
+ }
+ }
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/HibernateLaunchConstants.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/HibernateLaunchConstants.java 2007-09-25
07:16:29 UTC (rev 3782)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/HibernateLaunchConstants.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -44,6 +44,9 @@
{
public static final String ATTR_PREFIX = "org.hibernate.tools.";
+ // attribute to list of id for exporters configured in a specific launchconfig.
+ public static final String ATTR_EXPORTERS = ATTR_PREFIX + "exporters";
+
public static final String ATTR_CONSOLE_CONFIGURATION_NAME = ATTR_PREFIX +
"configurationname";
public static final String ATTR_OUTPUT_DIR = ATTR_PREFIX + "outputdir";
public static final String ATTR_REVERSE_ENGINEER = ATTR_PREFIX +
"schema2hbm";
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/LaunchConfigurationTabGroup.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/LaunchConfigurationTabGroup.java 2007-09-25
07:16:29 UTC (rev 3782)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/LaunchConfigurationTabGroup.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -36,8 +36,8 @@
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
- new CodeGenerationSettings(),
- new ExporterSettings(),
+ new CodeGenerationSettingsTab(),
+ new ExporterSettingsTab(),
new RefreshTab(),
new CommonTab()
};
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ExporterTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ExporterTest.java 2007-09-25
07:16:29 UTC (rev 3782)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ExporterTest.java 2007-09-25
07:27:00 UTC (rev 3783)
@@ -30,12 +30,12 @@
null);
- factory = new ExporterFactory(definition);
+ factory = new ExporterFactory(definition, definition.getId());
}
public void testExporters() {
- Map properties = definition.getProperties();
+ Map properties = definition.getExporterProperties();
assertEquals(properties, map);