Author: dgeraskov
Date: 2012-08-22 07:56:52 -0400 (Wed, 22 Aug 2012)
New Revision: 43159
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernatePropertiesResourceModel.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernatePropertiesResourceModelProvider.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/Messages.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/messages.properties
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaPlatformProvider.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaProject.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJptPlugin.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0PlatformProvider.java
Log:
https://issues.jboss.org/browse/JBIDE-12454
Revalidate JpaProject on hibernate.properties change
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaPlatformProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaPlatformProvider.java 2012-08-22
11:04:57 UTC (rev 43158)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaPlatformProvider.java 2012-08-22
11:56:52 UTC (rev 43159)
@@ -106,7 +106,8 @@
JavaResourceModelProvider.instance(),
JarResourceModelProvider.instance(),
PersistenceResourceModelProvider.instance(),
- OrmResourceModelProvider.instance()
+ OrmResourceModelProvider.instance(),
+ HibernatePropertiesResourceModelProvider.instance()
};
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaProject.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaProject.java 2012-08-22
11:04:57 UTC (rev 43158)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaProject.java 2012-08-22
11:56:52 UTC (rev 43159)
@@ -14,11 +14,20 @@
import java.util.List;
import java.util.Properties;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageInfoCompilationUnit;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable;
import org.eclipse.jpt.jpa.core.JpaFile;
@@ -27,6 +36,7 @@
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
import org.eclipse.jpt.jpa.core.internal.AbstractJpaProject;
+import org.eclipse.wst.validation.ValidationFramework;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.hibernate.cfg.Configuration;
@@ -34,6 +44,7 @@
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
import org.hibernate.eclipse.console.properties.HibernatePropertiesConstants;
import org.hibernate.eclipse.nature.HibernateNature;
import org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit;
@@ -49,9 +60,12 @@
public class HibernateJpaProject extends AbstractJpaProject {
private Boolean cachedNamingStrategyEnable;
+
+ private final JobCommand revalidateCommand;
public HibernateJpaProject(JpaProject.Config config){
super(config);
+ revalidateCommand = new RevalidateProjectCommand();
}
public ConsoleConfiguration getDefaultConsoleConfiguration(){
@@ -234,7 +248,36 @@
}
};
}
+
+ @Override
+ protected boolean synchronizeJpaFiles(IFile file, int deltaKind) {
+ boolean result = super.synchronizeJpaFiles(file, deltaKind);
+ ConsoleConfiguration cc = getDefaultConsoleConfiguration();
+ if (cc != null){
+ ConsoleConfigurationPreferences preferences = cc.getPreferences();
+ if (file.getLocation().toFile().equals(preferences.getPropertyFile())){
+ switch (deltaKind) {
+ case IResourceDelta.ADDED :
+ case IResourceDelta.REMOVED :
+ case IResourceDelta.CHANGED :
+ stateChanged();
+ revalidate();
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * I don't know what I do incorrectly but JpaProject isn't validated on the
stateChanged().
+ * This command is a temporary solution.
+ *
+ */
+ protected void revalidate() {
+ getManager().execute(revalidateCommand,
org.jboss.tools.hibernate.jpt.core.internal.Messages.HibernateJpaProject_Update_Hibernate_properties,
this);
+ }
+
@Override
protected void validate(List<IMessage> messages, IReporter reporter) {
super.validate(messages, reporter);
@@ -262,5 +305,18 @@
}
return null;
}
+
+ class RevalidateProjectCommand implements JobCommand {
+ public IStatus execute(IProgressMonitor monitor) {
+ try {
+ ValidationFramework.getDefault().validate(new
IProject[]{HibernateJpaProject.this.getProject()},
+ false, true, new NullProgressMonitor());
+ return Status.OK_STATUS;
+ } catch (CoreException e) {
+ return new Status(Status.ERROR, HibernateJptPlugin.ID, e.getMessage(), e);
+ }
+ }
+ }
+
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJptPlugin.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJptPlugin.java 2012-08-22
11:04:57 UTC (rev 43158)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJptPlugin.java 2012-08-22
11:56:52 UTC (rev 43159)
@@ -22,8 +22,10 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JpaProjectManager;
import org.hibernate.console.ConsoleConfiguration;
@@ -41,6 +43,11 @@
public static final String ID = "org.jboss.tools.hibernate.jpt.core";
//$NON-NLS-1$
private static HibernateJptPlugin inst = null;
+
+ private static String JAVA_PROPERTIES_CONTENT_TYPE_NAME =
"org.eclipse.jdt.core.javaProperties"; //$NON-NLS-1$
+
+ public static IContentType JAVA_PROPERTIES_CONTENT_TYPE =
Platform.getContentTypeManager()
+ .getContentType(JAVA_PROPERTIES_CONTENT_TYPE_NAME);
public static HibernateJptPlugin getDefault() {
return inst;
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernatePropertiesResourceModel.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernatePropertiesResourceModel.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernatePropertiesResourceModel.java 2012-08-22
11:56:52 UTC (rev 43159)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jpt.common.core.JptResourceModel;
+import org.eclipse.jpt.common.core.JptResourceModelListener;
+import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.jpa.core.JpaProject;
+
+/**
+ *
+ * @author Dmitry Geraskov (geraskov(a)gmail.com)
+ *
+ */
+public class HibernatePropertiesResourceModel implements JptResourceModel {
+
+ protected final JpaProject project;
+
+ protected final IFile file;
+
+ public HibernatePropertiesResourceModel(JpaProject project, IFile file){
+ this.project = project;
+ this.file = file;
+ }
+
+ public JptResourceType getResourceType() {
+ return new JptResourceType(HibernateJptPlugin.JAVA_PROPERTIES_CONTENT_TYPE);
+ }
+
+ public IFile getFile() {
+ return file;
+ }
+
+ // ********** JptResourceModel implementation **********
+
+ public void addResourceModelListener(JptResourceModelListener listener) {
+ //do nothing for now
+ }
+
+ public void removeResourceModelListener(JptResourceModelListener listener) {
+ //do nothing for now
+ }
+
+
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernatePropertiesResourceModelProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernatePropertiesResourceModelProvider.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernatePropertiesResourceModelProvider.java 2012-08-22
11:56:52 UTC (rev 43159)
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.JpaResourceModelProvider;
+
+/**
+ *
+ * @author Dmitry Geraskov (geraskov(a)gmail.com)
+ *
+ */
+public class HibernatePropertiesResourceModelProvider implements
+ JpaResourceModelProvider {
+
+ // singleton
+ private static final JpaResourceModelProvider INSTANCE = new
HibernatePropertiesResourceModelProvider();
+
+ /**
+ * Return the singleton.
+ */
+ public static JpaResourceModelProvider instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure single instance.
+ */
+ private HibernatePropertiesResourceModelProvider() {
+ super();
+ }
+
+ public IContentType getContentType() {
+ return HibernateJptPlugin.JAVA_PROPERTIES_CONTENT_TYPE;
+ }
+
+ public HibernatePropertiesResourceModel buildResourceModel(
+ JpaProject jpaProject, IFile file) {
+ return new HibernatePropertiesResourceModel(jpaProject, file);
+ }
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/Messages.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/Messages.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/Messages.java 2012-08-22
11:56:52 UTC (rev 43159)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ *
+ * @author Dmitry Geraskov (geraskov(a)gmail.com)
+ *
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME =
"org.jboss.tools.hibernate.jpt.core.internal.messages"; //$NON-NLS-1$
+ public static String HibernateJpaProject_Update_Hibernate_properties;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0PlatformProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0PlatformProvider.java 2012-08-22
11:04:57 UTC (rev 43158)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0PlatformProvider.java 2012-08-22
11:56:52 UTC (rev 43159)
@@ -36,6 +36,7 @@
import
org.eclipse.jpt.jpa.core.internal.jpa2.context.java.JavaElementCollectionMappingDefinition2_0;
import
org.eclipse.jpt.jpa.core.internal.jpa2.context.java.JavaEmbeddedMappingDefinition2_0;
import
org.eclipse.jpt.jpa.core.internal.jpa2.context.java.JavaOneToManyMappingDefinition2_0;
+import
org.jboss.tools.hibernate.jpt.core.internal.HibernatePropertiesResourceModelProvider;
import
org.jboss.tools.hibernate.jpt.core.internal.JavaPackageInfoResourceModelProviderPatched;
import
org.jboss.tools.hibernate.jpt.core.internal.context.definition.HibernateJavaBasicMappingDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.context.definition.HibernateJavaEntityDefinition;
@@ -110,7 +111,8 @@
JavaResourceModelProvider.instance(),
JarResourceModelProvider.instance(),
PersistenceResourceModelProvider.instance(),
- OrmResourceModelProvider.instance()
+ OrmResourceModelProvider.instance(),
+ HibernatePropertiesResourceModelProvider.instance()
};
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/messages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/messages.properties
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/messages.properties 2012-08-22
11:56:52 UTC (rev 43159)
@@ -0,0 +1 @@
+HibernateJpaProject_Update_Hibernate_properties=Update Hibernate properties