Author: vyemialyanchyk
Date: 2009-06-19 12:07:29 -0400 (Fri, 19 Jun 2009)
New Revision: 16070
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/DialogSelectionHelper.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/ProjectUtils.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationTab.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4146 - fixed
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java 2009-06-19
15:58:27 UTC (rev 16069)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java 2009-06-19
16:07:29 UTC (rev 16070)
@@ -434,6 +434,8 @@
public static String ConsoleConfigurationMainTab_setup_configuration_file;
public static String ConsoleConfigurationMainTab_setup_property_file;
public static String ConsoleConfigurationMainTab_select_hibernate_cfg_xml_file;
+ public static String ConsoleConfigurationMainTab_select_persistence_unit;
+ public static String ConsoleConfigurationMainTab_jpa_selected_persistence_unit;
public static String ConsoleConfigurationMainTab_the_java_project_does_not_exist;
public static String ConsoleConfigurationMainTab_type;
public static String ConsoleConfigurationMainTab_use_existing;
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2009-06-19
15:58:27 UTC (rev 16069)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2009-06-19
16:07:29 UTC (rev 16070)
@@ -429,6 +429,8 @@
ConsoleConfigurationMainTab_property_file_2=Property file
ConsoleConfigurationMainTab_select_java_project=Select java project
ConsoleConfigurationMainTab_select_propertyfile=Select property file
+ConsoleConfigurationMainTab_select_persistence_unit=Select persistence unit
+ConsoleConfigurationMainTab_jpa_selected_persistence_unit=Available persistence units:
ConsoleConfigurationMainTab_setup_configuration_file=Setup configuration file
ConsoleConfigurationMainTab_setup_property_file=Setup property file
ConsoleConfigurationMainTab_select_hibernate_cfg_xml_file=Select hibernate.cfg.xml file
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/DialogSelectionHelper.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/DialogSelectionHelper.java 2009-06-19
15:58:27 UTC (rev 16069)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/DialogSelectionHelper.java 2009-06-19
16:07:29 UTC (rev 16070)
@@ -22,6 +22,7 @@
package org.hibernate.eclipse.console.utils;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.debug.internal.ui.stringsubstitution.StringVariableLabelProvider;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
@@ -44,6 +45,7 @@
* @author max
*
*/
+@SuppressWarnings("restriction")
public class DialogSelectionHelper extends
org.hibernate.eclipse.console.utils.xpl.DialogSelectionHelper {
@@ -76,6 +78,29 @@
return null;
}
+ /**
+ * Realize a Persistence Unit selection dialog and return the first selected persistence
unit,
+ * or null if there was none.
+ */
+ public static String choosePersistenceUnit(Shell shell, String initialSelection, String
title, String description,
+ IJavaProject javaProject) {
+ String[] availablePersistenceUnit =
ProjectUtils.availablePersistenceUnits(javaProject);
+ ILabelProvider labelProvider= new StringVariableLabelProvider();
+ ElementListSelectionDialog dialog= new ElementListSelectionDialog(shell,
labelProvider);
+ dialog.setTitle(title);
+ dialog.setMessage(description);
+ dialog.setElements(availablePersistenceUnit);
+
+ String persistenceUnit = initialSelection;
+ if (persistenceUnit != null) {
+ dialog.setInitialSelections(new Object[] { persistenceUnit });
+ }
+ if (dialog.open() == Window.OK) {
+ return (String) dialog.getFirstResult();
+ }
+ return initialSelection;
+ }
+
static public String chooseImplementation(String supertype, String initialSelection,
String title, Shell shell) {
SelectionDialog dialog= null;
try {
@@ -102,9 +127,8 @@
if (types != null && types.length > 0) {
IType type= (IType) types[0];
return type.getFullyQualifiedName('.');
- } else {
- return null;
}
+ return null;
}
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/ProjectUtils.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/ProjectUtils.java 2009-06-19
15:58:27 UTC (rev 16069)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/ProjectUtils.java 2009-06-19
16:07:29 UTC (rev 16070)
@@ -21,11 +21,16 @@
*/
package org.hibernate.eclipse.console.utils;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
import org.eclipse.core.internal.resources.File;
import org.eclipse.core.internal.resources.ICoreConstants;
import org.eclipse.core.internal.resources.ResourceInfo;
@@ -66,6 +71,7 @@
import org.hibernate.util.StringHelper;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
+import org.xml.sax.InputSource;
@SuppressWarnings("restriction")
public class ProjectUtils {
@@ -340,6 +346,7 @@
return lwType;
}
+ @SuppressWarnings("unchecked")
static public String getParentTypename(IJavaProject proj, String fullyQualifiedName) {
String res = null;
ICompilationUnit icu = findCompilationUnit(proj, fullyQualifiedName);
@@ -376,4 +383,47 @@
return res;
}
+ @SuppressWarnings("unchecked")
+ static public String[] availablePersistenceUnits(IJavaProject javaProject) {
+ if (javaProject == null || javaProject.getResource() == null) {
+ return new String[0];
+ }
+ IPath projPathFull = javaProject.getResource().getLocation();
+ IPath projPath = javaProject.getPath();
+ IPath path =
javaProject.readOutputLocation().append(OpenMappingUtilsEjb3.META_INF_PERS_XML);
+ path = path.makeRelativeTo(projPath);
+ path = projPathFull.append(path);
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
+ if (!exists(file)) {
+ return new String[0];
+ }
+ InputStream is = null;
+ org.dom4j.Document doc = null;
+ try {
+ is = file.getContents();
+ SAXReader saxReader = new SAXReader();
+ doc = saxReader.read(new InputSource(is));
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("CoreException: ", e);
//$NON-NLS-1$
+ } catch (DocumentException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("DocumentException: ",
e); //$NON-NLS-1$
+ } finally {
+ try {
+ if (is != null) is.close();
+ }
+ catch (IOException ioe) {
+ //ignore
+ }
+ }
+ if (doc == null || doc.getRootElement() == null) {
+ return new String[0];
+ }
+ Iterator it = doc.getRootElement().elements("persistence-unit").iterator();
//$NON-NLS-1$
+ ArrayList<String> res = new ArrayList<String>();
+ while (it.hasNext()) {
+ Element el = (Element)it.next();
+ res.add(el.attributeValue("name")); //$NON-NLS-1$
+ }
+ return res.toArray(new String[0]);
+ }
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java 2009-06-19
15:58:27 UTC (rev 16069)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java 2009-06-19
16:07:29 UTC (rev 16070)
@@ -49,6 +49,7 @@
import org.hibernate.eclipse.console.wizards.NewConfigurationWizardPage;
import org.hibernate.util.StringHelper;
+@SuppressWarnings("restriction")
public class ConsoleConfigurationMainTab extends ConsoleConfigurationTab {
protected boolean configurationFileWillBeCreated = false;
@@ -57,6 +58,7 @@
private Button jpaMode;
private Button annotationsMode;
private Button confbutton;
+ private Button persistenceUnitNameButton;
private Text propertyFileText;
private Text configurationFileText;
@@ -153,11 +155,12 @@
private void createPersistenceUnitEditor(Composite parent) {
Group group = createGroup( parent,
HibernateConsoleMessages.ConsoleConfigurationMainTab_persistence_unit );
- persistenceUnitNameText = new Text(group, SWT.BORDER | SWT.SINGLE);
- GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- persistenceUnitNameText.setFont( parent.getFont() );
- persistenceUnitNameText.setLayoutData(gd);
- persistenceUnitNameText.addModifyListener(getChangeListener());
+ persistenceUnitNameText = createBrowseEditor( parent, group);
+ persistenceUnitNameButton = createBrowseButton( group, new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ handlePersistenceUnitBrowse();
+ }
+ } );
}
@@ -241,6 +244,15 @@
}
}
+ private void handlePersistenceUnitBrowse() {
+ String persistenceUnit = DialogSelectionHelper.choosePersistenceUnit( getShell(),
persistenceUnitNameText.getText(),
HibernateConsoleMessages.ConsoleConfigurationMainTab_select_persistence_unit,
HibernateConsoleMessages.ConsoleConfigurationMainTab_jpa_selected_persistence_unit,
findJavaProject() );
+ if(persistenceUnit!=null) {
+ persistenceUnitNameText.setText( persistenceUnit );
+ } else {
+ persistenceUnitNameText.setText(""); //$NON-NLS-1$
+ }
+ }
+
private IJavaProject findJavaProject(){
IPath path = pathOrNull(getProjectName());
if (path != null && path.segmentCount() >= 1){
@@ -377,6 +389,7 @@
confbutton.setEnabled(!configurationFileWillBeCreated && !modeJPA);
persistenceUnitNameText.setEnabled(modeJPA);
+ persistenceUnitNameButton.setEnabled(modeJPA);
String cpName = nonEmptyTrimOrNull(connectionProfileCtrl.getSelectedConnectionName());
if(getProjectName()!=null && StringHelper.isNotEmpty(getProjectName().trim()))
{
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationTab.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationTab.java 2009-06-19
15:58:27 UTC (rev 16069)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationTab.java 2009-06-19
16:07:29 UTC (rev 16070)
@@ -1,6 +1,5 @@
package org.hibernate.eclipse.launch;
-import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
@@ -34,7 +33,6 @@
}
ChangeListener changeListener = new ChangeListener();
- private ILaunchConfiguration currentLaunchConfig;
protected Button createBrowseButton(Group group, SelectionListener selectionListener) {
Button button = createPushButton(group,
HibernateConsoleMessages.ConsoleConfigurationTab_browse, null);