Author: dgeraskov
Date: 2009-06-15 09:31:55 -0400 (Mon, 15 Jun 2009)
New Revision: 15951
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/views/ConsoleConfigurationPropertySource.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3785
Added project, Connection and Mode properties.
Changes in Properties view call changes in configuration.
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-15
13:09:11 UTC (rev 15950)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java 2009-06-15
13:31:55 UTC (rev 15951)
@@ -114,6 +114,9 @@
//
public static String ConsoleConfigurationPropertySource_additional_mapping_files;
public static String ConsoleConfigurationPropertySource_config_file;
+ public static String ConsoleConfigurationPropertySource_project;
+ public static String ConsoleConfigurationPropertySource_connection;
+ public static String ConsoleConfigurationPropertySource_mode;
public static String ConsoleConfigurationPropertySource_error;
public static String ConsoleConfigurationPropertySource_name;
public static String ConsoleConfigurationPropertySource_properties_file;
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-15
13:09:11 UTC (rev 15950)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2009-06-15
13:31:55 UTC (rev 15951)
@@ -109,6 +109,9 @@
ConsoleConfigurationPropertySource_config_file=Configuration file
ConsoleConfigurationPropertySource_error=Error:
ConsoleConfigurationPropertySource_name=Name
+ConsoleConfigurationPropertySource_project=Project
+ConsoleConfigurationPropertySource_connection=Connection
+ConsoleConfigurationPropertySource_mode=Mode
ConsoleConfigurationPropertySource_properties_file=Properties file
DynamicSQLPreviewView_caused_by=\nCaused by:\n
DynamicSQLPreviewView_empty_hql_query=Empty HQL query.
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConsoleConfigurationPropertySource.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConsoleConfigurationPropertySource.java 2009-06-15
13:09:11 UTC (rev 15950)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConsoleConfigurationPropertySource.java 2009-06-15
13:31:55 UTC (rev 15951)
@@ -22,11 +22,20 @@
package org.hibernate.eclipse.console.views;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
+import org.eclipse.datatools.connectivity.ProfileManager;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jface.viewers.ICellEditorValidator;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
@@ -34,6 +43,7 @@
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
+import
org.hibernate.console.preferences.ConsoleConfigurationPreferences.ConfigurationMode;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.utils.LaunchHelper;
@@ -42,16 +52,34 @@
private ConsoleConfiguration cfg;
- static IPropertyDescriptor[] pd;
+ static List<IPropertyDescriptor> pd;
static {
+ ComboBoxPropertyDescriptor modeDescriptor = new ComboBoxPropertyDescriptor(
+ "mode", //$NON-NLS-1$
+ HibernateConsoleMessages.ConsoleConfigurationPropertySource_mode,
+ ConfigurationMode.values());
+ modeDescriptor.setLabelProvider(new LabelProvider(){
+
+ @Override
+ public String getText(Object element) {
+ if (ConfigurationMode.CORE.toString().equals(element)){
+ return "Core"; //$NON-NLS-1$
+ }
+ if (ConfigurationMode.ANNOTATIONS.toString().equals(element)){
+ return "Annotations"; //$NON-NLS-1$
+ }
+ return super.getText(element);
+ }
+ });
+
List<IPropertyDescriptor> l = new ArrayList<IPropertyDescriptor>();
l.add(new TextPropertyDescriptor("name",
HibernateConsoleMessages.ConsoleConfigurationPropertySource_name)); //$NON-NLS-1$
+ l.add(modeDescriptor);
l.add(new PropertyDescriptor("hibernate.cfg.xml",
HibernateConsoleMessages.ConsoleConfigurationPropertySource_config_file)); //$NON-NLS-1$
l.add(new PropertyDescriptor("hibernate.properties",
HibernateConsoleMessages.ConsoleConfigurationPropertySource_properties_file));
//$NON-NLS-1$
l.add(new PropertyDescriptor("mapping.files",
HibernateConsoleMessages.ConsoleConfigurationPropertySource_additional_mapping_files));
//$NON-NLS-1$
-
- pd = l.toArray( new IPropertyDescriptor[l.size()] );
+ pd = l;
}
public ConsoleConfigurationPropertySource(ConsoleConfiguration cfg) {
@@ -63,17 +91,69 @@
}
public IPropertyDescriptor[] getPropertyDescriptors() {
- return pd;
+ IPropertyDescriptor[] propertyDescriptors = new IPropertyDescriptor[pd.size() + 2];
+ pd.toArray(propertyDescriptors);
+ propertyDescriptors[propertyDescriptors.length - 2] = createProjectDescriptor();
+ propertyDescriptors[propertyDescriptors.length - 1] = createConnectionDescriptor();
+ return propertyDescriptors;
}
public Object getPropertyValue(Object id) {
try {
if("name".equals(id)) { //$NON-NLS-1$
return cfg.getName();
- }
+ }
// TODO: bring back more eclipse friendly file names
ConsoleConfigurationPreferences preferences = cfg.getPreferences();
-
+ if ("project".equals(id)){ //$NON-NLS-1$
+ try {
+ ILaunchConfiguration lc =
HibernateConsolePlugin.getDefault().findLaunchConfig(cfg.getName());
+ if (lc != null){
+ String projectName =
lc.getAttribute("org.eclipse.jdt.launching.PROJECT_ATTR", "");
//$NON-NLS-1$//$NON-NLS-2$
+ return Arrays.binarySearch(getSortedProjectNames(), projectName);
+ } else {
+ HibernateConsolePlugin.getDefault().log("Can't find Console Configuration
\"" + cfg.getName() + "\"");//$NON-NLS-1$//$NON-NLS-2$
+ }
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().log(e);
+ }
+ }
+ if("mode".equals(id)) { //$NON-NLS-1$
+ String[] values = ConfigurationMode.values();
+ String value = preferences.getConfigurationMode().toString();
+ for (int i = 0; i < values.length; i++) {
+ if (value.equals(values[i])){
+ return i;
+ }
+ }
+ return new RuntimeException("Unknown ConsoleConfiguration mode: " +
value); //$NON-NLS-1$
+ }
+ if("connection".equals(id)) { //$NON-NLS-1$
+ try {
+ ILaunchConfiguration lc =
HibernateConsolePlugin.getDefault().findLaunchConfig(cfg.getName());
+ if (lc != null){
+ String connectionName =
lc.getAttribute("org.hibernate.eclipse.launch.CONNECTION_PROFILE_NAME",
(String)null); //$NON-NLS-1$
+ if (connectionName == null){
+ connectionName =
lc.getAttribute("org.hibernate.eclipse.launch.USE_JPA_PROJECT_PROFILE",
Boolean.FALSE.toString());//$NON-NLS-1$
+ if (Boolean.TRUE.toString().equalsIgnoreCase(connectionName)){
+ connectionName =
HibernateConsoleMessages.ConnectionProfileCtrl_JPAConfiguredConnection;
+ } else {
+ connectionName =
HibernateConsoleMessages.ConnectionProfileCtrl_HibernateConfiguredConnection;
+ }
+ }
+ String[] values = getConnectionNames();
+ for (int i = 0; i < values.length; i++) {
+ if (values[i].equals(connectionName)){
+ return i;
+ }
+ }
+ } else {
+ HibernateConsolePlugin.getDefault().log("Can't find Console Configuration
\"" + cfg.getName() + "\"");//$NON-NLS-1$//$NON-NLS-2$
+ }
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().log(e);
+ }
+ }
if("hibernate.cfg.xml".equals(id)) { //$NON-NLS-1$
return preferences.getConfigXMLFile();
}
@@ -113,12 +193,127 @@
//find newly created console configuration
cfg = KnownConfigurations.getInstance().find(newName);
} else {
- HibernateConsolePlugin.getDefault().log("Can't find Console Configuration
\"" + oldName + "\"");
+ HibernateConsolePlugin.getDefault().log("Can't find Console Configuration
\"" + oldName + "\"");//$NON-NLS-1$//$NON-NLS-2$
}
} catch (CoreException e) {
HibernateConsolePlugin.getDefault().log(e);
}
+ } else if ("mode".equals(id) && value instanceof
Integer){ //$NON-NLS-1$
+ int index = (Integer) value;
+ try {
+ ILaunchConfiguration lc =
HibernateConsolePlugin.getDefault().findLaunchConfig(cfg.getName());
+ if (lc != null){
+ ILaunchConfigurationWorkingCopy wc = lc.getWorkingCopy();
+ wc.setAttribute("org.hibernate.eclipse.launch.CONFIGURATION_FACTORY",
ConfigurationMode.values()[index]);////$NON-NLS-1$
+ wc.doSave();
+ } else {
+ HibernateConsolePlugin.getDefault().log("Can't find Console Configuration
\"" + cfg.getName() + "\"");//$NON-NLS-1$//$NON-NLS-2$
+ }
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().log("Can't find Console Configuration
\"" + cfg.getName() + "\"");//$NON-NLS-1$//$NON-NLS-2$
+ }
+ } else if ("project".equals(id) && value instanceof
Integer){ //$NON-NLS-1$
+ int index = (Integer) value;
+ try {
+ ILaunchConfiguration lc =
HibernateConsolePlugin.getDefault().findLaunchConfig(cfg.getName());
+ if (lc != null){
+ ILaunchConfigurationWorkingCopy wc = lc.getWorkingCopy();
+ wc.setAttribute("org.eclipse.jdt.launching.PROJECT_ATTR",
getSortedProjectNames()[index]);////$NON-NLS-1$
+ wc.doSave();
+ } else {
+ HibernateConsolePlugin.getDefault().log("Can't find Console Configuration
\"" + cfg.getName() + "\"");//$NON-NLS-1$//$NON-NLS-2$
+ }
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().log("Can't find Console Configuration
\"" + cfg.getName() + "\"");//$NON-NLS-1$//$NON-NLS-2$
+ }
+ } else if ("connection".equals(id) && value instanceof
Integer){ //$NON-NLS-1$
+ int index = (Integer) value;
+ try {
+ ILaunchConfiguration lc =
HibernateConsolePlugin.getDefault().findLaunchConfig(cfg.getName());
+ if (lc != null){
+ ILaunchConfigurationWorkingCopy wc = lc.getWorkingCopy();
+ if (index == 0){//jpa
+ wc.setAttribute("org.hibernate.eclipse.launch.USE_JPA_PROJECT_PROFILE",
Boolean.TRUE.toString());////$NON-NLS-1$
+ wc.removeAttribute("org.hibernate.eclipse.launch.CONNECTION_PROFILE_NAME");////$NON-NLS-1$
+ } else if (index == 1){//hibernate
+ wc.removeAttribute("org.hibernate.eclipse.launch.USE_JPA_PROJECT_PROFILE");////$NON-NLS-1$
+ wc.removeAttribute("org.hibernate.eclipse.launch.CONNECTION_PROFILE_NAME");////$NON-NLS-1$
+ } else {//connection profile
+ String[] values = getConnectionNames();
+ wc.setAttribute("org.hibernate.eclipse.launch.CONNECTION_PROFILE_NAME",
values[index]);////$NON-NLS-1$
+ wc.removeAttribute("org.hibernate.eclipse.launch.USE_JPA_PROJECT_PROFILE");////$NON-NLS-1$
+ }
+ wc.doSave();
+ } else {
+ HibernateConsolePlugin.getDefault().log("Can't find Console Configuration
\"" + cfg.getName() + "\"");//$NON-NLS-1$//$NON-NLS-2$
+ }
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().log("Can't find Console Configuration
\"" + cfg.getName() + "\"");//$NON-NLS-1$//$NON-NLS-2$
+ }
}
}
+ private IPropertyDescriptor createProjectDescriptor(){
+ ComboBoxPropertyDescriptor projectDescriptor = new ComboBoxPropertyDescriptor(
+ "project", //$NON-NLS-1$
+ HibernateConsoleMessages.ConsoleConfigurationPropertySource_project,
+ getSortedProjectNames());
+ projectDescriptor.setValidator(new ICellEditorValidator(){
+ public String isValid(Object value) {
+ if (value instanceof Integer){
+ if (((Integer)value).intValue() < 0){
+ try {
+ ILaunchConfiguration lc =
HibernateConsolePlugin.getDefault().findLaunchConfig(cfg.getName());
+ if (lc != null){
+ String projectName =
lc.getAttribute("org.eclipse.jdt.launching.PROJECT_ATTR", (String)null);
//$NON-NLS-1$
+ if (projectName != null){
+ return
NLS.bind(HibernateConsoleMessages.ConsoleConfigurationMainTab_the_java_project_does_not_exist,
projectName);
+ }
+ } else {
+ HibernateConsolePlugin.getDefault().log("Can't find Console
Configuration \"" + cfg.getName() +
"\"");//$NON-NLS-1$//$NON-NLS-2$
+ }
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().log(e);
+ }
+ }
+ }
+ return null;
+ }
+ });
+ return projectDescriptor;
+ }
+
+ private IPropertyDescriptor createConnectionDescriptor(){
+ ComboBoxPropertyDescriptor connectionDescriptor = new ComboBoxPropertyDescriptor(
+ "connection", //$NON-NLS-1$
+ HibernateConsoleMessages.ConsoleConfigurationPropertySource_connection,
+ getConnectionNames());
+ return connectionDescriptor;
+ }
+
+ private String[] getSortedProjectNames(){
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();//get all
projects
+ String[] projectNames = new String[projects.length];
+ for (int i = 0; i < projects.length; i++ ) {
+ projectNames[i] = projects[i].getName();
+ };
+ Arrays.sort(projectNames);
+ return projectNames;
+ }
+
+ private String[] getConnectionNames(){
+ IConnectionProfile[] profiles = ProfileManager.getInstance()
+ .getProfilesByCategory("org.eclipse.datatools.connectivity.db.category");
//$NON-NLS-1$
+ String[] names = new String[profiles.length];
+ for (int i = 0; i < profiles.length; i ++){
+ names[i] = profiles[i].getName();
+ }
+ Arrays.sort(names);
+ String[] resNames = new String[names.length + 2];
+ resNames[0] = HibernateConsoleMessages.ConnectionProfileCtrl_JPAConfiguredConnection;
+ resNames[1] =
HibernateConsoleMessages.ConnectionProfileCtrl_HibernateConfiguredConnection;
+ System.arraycopy(names, 0, resNames, 2, names.length);
+ return resNames;
+ }
+
}
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-15
13:09:11 UTC (rev 15950)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java 2009-06-15
13:31:55 UTC (rev 15951)
@@ -5,7 +5,6 @@
import org.eclipse.core.resources.IFile;
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;
@@ -43,7 +42,6 @@
import
org.hibernate.console.preferences.ConsoleConfigurationPreferences.ConfigurationMode;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
-import org.hibernate.eclipse.console.actions.AddConfigurationAction;
import org.hibernate.eclipse.console.utils.DialogSelectionHelper;
import org.hibernate.eclipse.console.utils.EclipseImages;
import org.hibernate.eclipse.console.utils.ProjectUtils;