Author: vyemialyanchyk
Date: 2010-01-15 11:29:11 -0500 (Fri, 15 Jan 2010)
New Revision: 19780
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/FileUtils.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingPreviewPage.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFilePage.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5408 - fixed
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/FileUtils.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/FileUtils.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/FileUtils.java 2010-01-15
16:29:11 UTC (rev 19780)
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.hibernate.eclipse.console.utils;
+
+import java.io.File;
+
+/**
+ *
+ * @author vitali
+ */
+public class FileUtils {
+
+ /**
+ * Delete the whole directory
+ * @param path
+ */
+ public static boolean delete(File path) {
+ boolean res = true, tmp = true;
+ if (path.exists()) {
+ File[] files = path.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ tmp = delete(files[i]);;
+ } else {
+ tmp = deleteFile(files[i]);
+ }
+ res = res && tmp;
+ }
+ }
+ tmp = deleteFile(path);
+ res = res && tmp;
+ return res;
+ }
+
+ /**
+ * Delete single file
+ * @param file
+ */
+ public static boolean deleteFile(File file) {
+ boolean res = false;
+ if (file.exists()) {
+ if (file.delete()) {
+ res = true;
+ }
+ }
+ return res;
+ }
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFilePage.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFilePage.java 2010-01-15
16:22:20 UTC (rev 19779)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFilePage.java 2010-01-15
16:29:11 UTC (rev 19780)
@@ -94,7 +94,7 @@
viewer.setInput(null);
sc.setMinSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT));
- setControl(container);
+ setControl(sc);
}
public void setInput(Map<IJavaProject, Collection<EntityInfo>>
project_infos){
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java 2010-01-15
16:22:20 UTC (rev 19779)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java 2010-01-15
16:29:11 UTC (rev 19780)
@@ -31,6 +31,7 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
@@ -66,6 +67,7 @@
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.utils.EclipseImages;
+import org.hibernate.eclipse.console.utils.FileUtils;
import org.hibernate.eclipse.jdt.ui.internal.JdtUiMessages;
import org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo;
@@ -98,6 +100,8 @@
private WizardNewFileCreationPage cPage;
private NewHibernateMappingFilePage page2 = null;
+
+ private NewHibernateMappingPreviewPage previewPage = null;
public NewHibernateMappingFileWizard(){
setDefaultPageImageDescriptor(EclipseImages.getImageDescriptor(ImageConstants.NEW_WIZARD)
);
@@ -122,13 +126,15 @@
cPage.setTitle(
JdtUiMessages.NewHibernateMappingFileWizard_create_hibernate_xml_mapping_file );
cPage.setDescription(
JdtUiMessages.NewHibernateMappingFileWizard_create_empty_xml_mapping_file );
cPage.setFileName("hibernate.hbm.xml"); //$NON-NLS-1$
- addPage( cPage );
+ addPage(cPage);
page2 = new NewHibernateMappingFilePage(false);
page2.setTitle(JdtUiMessages.NewHibernateMappingFilePage_hibernate_xml_mapping_file);
page2.setMessage(JdtUiMessages.NewHibernateMappingFilePage_this_wizard_creates,
IMessageProvider.WARNING);
-
addPage(page2);
+
+ previewPage = new NewHibernateMappingPreviewPage();
+ addPage(previewPage);
}
@Override
@@ -150,9 +156,12 @@
}
public void handlePageChanging(PageChangingEvent event) {
- if (event.getTargetPage() == page2){
+ if (event.getTargetPage() == page2) {
updateCompilationUnits();
page2.setInput(project_infos);
+ } else if (event.getTargetPage() == previewPage) {
+ Map<IJavaProject, IPath> places2Gen = getPlaces2Gen();
+ previewPage.setPlaces2Gen(places2Gen);
}
}
@@ -229,7 +238,8 @@
@SuppressWarnings("unchecked")
@Override
protected void exportPOJO(Map additionalContext, POJOClass element) {
- File outputdir4File = getOutputDirectory();
+ File outputdir4FileOld = getOutputDirectory();
+ File outputdir4FileNew = outputdir4FileOld;
String fullyQualifiedName = element.getQualifiedDeclarationName();
ICompilationUnit icu = Utils.findCompilationUnit(proj, fullyQualifiedName);
if (icu != null) {
@@ -244,16 +254,79 @@
resource = resource.getParent();
}
if (resource != null) {
- outputdir4File = resource.getLocation().toFile();
+ final IPath projPath = proj.getResource().getLocation();
+ IPath place2Gen = projPath.append(".settings"); //$NON-NLS-1$
+ place2Gen =
place2Gen.append(NewHibernateMappingPreviewPage.HIBERNATE_NEW_HBM_XML_FOLDER_NAME);
+ //
+ IPath tmpPath = resource.getLocation();
+ tmpPath = tmpPath.makeRelativeTo(projPath);
+ place2Gen = place2Gen.append(tmpPath);
+ outputdir4FileNew = place2Gen.toFile();
}
}
- setOutputDirectory(outputdir4File);
+ if (!outputdir4FileNew.exists()) {
+ outputdir4FileNew.mkdirs();
+ }
+ setOutputDirectory(outputdir4FileNew);
super.exportPOJO(additionalContext, element);
+ setOutputDirectory(outputdir4FileOld);
}
}
+ protected Map<IJavaProject, IPath> getPlaces2Gen() {
+ updateCompilationUnits();
+ Map<IJavaProject, Configuration> configs = createConfigurations();
+ Map<IJavaProject, IPath> places2Gen = new HashMap<IJavaProject, IPath>();
+ for (Entry<IJavaProject, Configuration> entry : configs.entrySet()) {
+ Configuration config = entry.getValue();
+ HibernateMappingGlobalSettings hmgs = new HibernateMappingGlobalSettings();
+
+ final IPath projPath = entry.getKey().getProject().getLocation();
+ IPath place2Gen = projPath.append(".settings"); //$NON-NLS-1$
+ place2Gen =
place2Gen.append(NewHibernateMappingPreviewPage.HIBERNATE_NEW_HBM_XML_FOLDER_NAME);
+ places2Gen.put(entry.getKey(), place2Gen);
+
+ File folder2Gen = new File(place2Gen.toOSString());
+ FileUtils.delete(folder2Gen); // cleanup folder before gen info
+ if (!folder2Gen.exists()) {
+ folder2Gen.mkdirs();
+ }
+ HibernateMappingExporter2 hce = new HibernateMappingExporter2(
+ entry.getKey(), config, folder2Gen);
+
+ hce.setGlobalSettings(hmgs);
+ //hce.setForEach("entity");
+ //hce.setFilePattern(file.getName());
+ try {
+ hce.start();
+ } catch (Exception e){
+ e.getCause().printStackTrace();
+ }
+ }
+ return places2Gen;
+ }
+
+ protected void cleanUpGenFolders() {
+ Set<IJavaProject> projs = previewPage.getJavaProjects();
+ for (IJavaProject proj : projs) {
+ // cleanup gen folder
+ final IPath projPath = proj.getProject().getLocation();
+ IPath place2Gen = projPath.append(".settings"); //$NON-NLS-1$
+ place2Gen =
place2Gen.append(NewHibernateMappingPreviewPage.HIBERNATE_NEW_HBM_XML_FOLDER_NAME);
+ File folder2Gen = new File(place2Gen.toOSString());
+ FileUtils.delete(folder2Gen);
+ }
+ }
+
@Override
+ public boolean performCancel() {
+ cleanUpGenFolders();
+ return super.performCancel();
+ }
+
+ @Override
public boolean performFinish() {
+ boolean res = true;
if (page0.getSelection().isEmpty()){
final IFile file = cPage.createNewFile();
IRunnableWithProgress op = new IRunnableWithProgress() {
@@ -270,59 +343,35 @@
try {
getContainer().run(true, false, op);
} catch (InterruptedException e) {
- return false;
+ res = false;
} catch (InvocationTargetException e) {
Throwable realException = e.getTargetException();
HibernateConsolePlugin.getDefault().showError(getShell(),
HibernateConsoleMessages.NewReverseEngineeringFileWizard_error, realException);
- return false;
+ res = false;
}
- return true;
+ cleanUpGenFolders();
} else {
- updateCompilationUnits();
- Map<IJavaProject, Configuration> configs = createConfigurations();
- for (Entry<IJavaProject, Configuration> entry : configs.entrySet()) {
- Configuration config = entry.getValue();
- HibernateMappingGlobalSettings hmgs = new HibernateMappingGlobalSettings();
-
-
+ previewPage.performFinish();
+ // refresh
+ Set<IJavaProject> projs = previewPage.getJavaProjects();
+ for (IJavaProject proj : projs) {
try {
- /* IResource container = entry.getKey().getPackageFragmentRoots().length > 0
- ? entry.getKey().getPackageFragmentRoots()[0].getResource()
- : entry.getKey().getResource();
-
- IPath temp_path =
entry.getKey().getProject().getLocation().append(".settings").append("org.hibernate_tools.temp");
-
- IFolder temp_folder = entry.getKey().getProject().getFolder(new
Path(".settings/org.hibernate_tools.temp"));
- */
-
- IPackageFragmentRoot[] pfRoots = entry.getKey().getPackageFragmentRoots();
- IResource container = pfRoots.length > 0 ? pfRoots[0].getResource() :
entry.getKey().getResource();
-
- HibernateMappingExporter2 hce = new HibernateMappingExporter2(
- entry.getKey(), config, container.getLocation().toFile());
-
- hce.setGlobalSettings(hmgs);
- //hce.setForEach("entity");
- //hce.setFilePattern(file.getName());
- try {
- hce.start();
- } catch (Exception e){
- e.getCause().printStackTrace();
- }
+ IPackageFragmentRoot[] pfRoots = proj.getPackageFragmentRoots();
for (int i = 0; i < pfRoots.length; i++) {
- container = pfRoots[i].getResource();
+ IResource container = pfRoots[i].getResource();
if (container != null && container.getType() != IResource.FILE) {
container.refreshLocal(IResource.DEPTH_INFINITE, null);
}
}
- } catch (JavaModelException e1) {
- HibernateConsolePlugin.getDefault().log(e1);
+ } catch (JavaModelException e) {
+ HibernateConsolePlugin.getDefault().log(e);
} catch (CoreException e) {
HibernateConsolePlugin.getDefault().log(e);
}
}
- return true;
+ cleanUpGenFolders();
}
+ return res;
}
/**
@@ -472,30 +521,30 @@
project_infos.clear();
selection = page0.getSelection();
processDepth = page0.getProcessDepth();
- try {
- getContainer().run(false, false, new IRunnableWithProgress() {
+ try {
+ getContainer().run(false, false, new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException,
- InterruptedException {
- monitor.beginTask(JdtUiMessages.NewHibernateMappingFileWizard_look_for_dependent_cu,
selection.size() + 1);
- Iterator<?> it = selection.iterator();
- int done = 1;
- while (it.hasNext()) {
- Object obj = it.next();
- processJavaElements(obj, processDepth);
- monitor.worked(done++);
- }
- initEntitiesInfo();
- monitor.worked(1);
- monitor.done();
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException,
+ InterruptedException {
+ monitor.beginTask(JdtUiMessages.NewHibernateMappingFileWizard_look_for_dependent_cu,
selection.size() + 1);
+ Iterator<?> it = selection.iterator();
+ int done = 1;
+ while (it.hasNext()) {
+ Object obj = it.next();
+ processJavaElements(obj, processDepth);
+ monitor.worked(done++);
}
- });
- } catch (InvocationTargetException e) {
- HibernateConsolePlugin.getDefault().log(e);
- } catch (InterruptedException e) {
- HibernateConsolePlugin.getDefault().log(e);
- }
+ initEntitiesInfo();
+ monitor.worked(1);
+ monitor.done();
+ }
+ });
+ } catch (InvocationTargetException e) {
+ HibernateConsolePlugin.getDefault().log(e);
+ } catch (InterruptedException e) {
+ HibernateConsolePlugin.getDefault().log(e);
+ }
}
}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingPreviewPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingPreviewPage.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingPreviewPage.java 2010-01-15
16:29:11 UTC (rev 19780)
@@ -0,0 +1,303 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.hibernate.eclipse.jdt.ui.wizards;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+import org.eclipse.core.filebuffers.LocationKind;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.internal.corext.refactoring.nls.changes.CreateTextFileChange;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
+import org.eclipse.ltk.internal.ui.refactoring.PreviewWizardPage;
+import org.eclipse.text.edits.MalformedTreeException;
+import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.text.edits.TextEdit;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+
+/**
+ * Preview wizard page for new hibernate mappings.
+ *
+ * @author Vitali Yemialyanchyk
+ */
+@SuppressWarnings("restriction")
+public class NewHibernateMappingPreviewPage extends PreviewWizardPage {
+
+ public static final String HIBERNATE_NEW_HBM_XML_FOLDER_NAME =
"hibernateNewHbmXml"; //$NON-NLS-1$
+
+ protected Map<IJavaProject, IPath> places2Gen;
+ protected Set<IPath> paths2Disconnect = new HashSet<IPath>();
+
+ public NewHibernateMappingPreviewPage() {
+ super(true);
+ }
+
+ @Override
+ public void dispose() {
+ performDisconnect();
+ super.dispose();
+ }
+
+ public void setPlaces2Gen(Map<IJavaProject, IPath> places2Gen) {
+ this.places2Gen = places2Gen;
+ updateChanges();
+ }
+
+ public Set<IJavaProject> getJavaProjects() {
+ if (places2Gen == null) {
+ return new HashSet<IJavaProject>();
+ }
+ return places2Gen.keySet();
+ }
+
+ protected void performDisconnect() {
+ final ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
+ for (IPath filePathTo_Show : paths2Disconnect) {
+ try {
+ bufferManager.disconnect(filePathTo_Show, LocationKind.IFILE, null);
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("CoreException: ", e);
//$NON-NLS-1$
+ }
+ }
+ paths2Disconnect.clear();
+ }
+
+ protected void performCommit() {
+ final CompositeChange cc = (CompositeChange)getChange();
+ if (cc == null) {
+ return;
+ }
+ final ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
+ Change[] changes = cc.getChildren();
+ for (int i = 0; i < changes.length; i++) {
+ Change change = changes[i];
+ if (!(change instanceof TextFileChange)) {
+ continue;
+ }
+ TextFileChange tfc = (TextFileChange)change;
+ if (tfc.isEnabled() && tfc.getEdit() != null) {
+ IPath path = new Path(tfc.getName());
+ ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path,
LocationKind.IFILE);
+ IDocument document = textFileBuffer.getDocument();
+ try {
+ tfc.getEdit().apply(document);
+ } catch (MalformedTreeException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("MalformedTreeException:
", e); //$NON-NLS-1$
+ } catch (BadLocationException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("BadLocationException:
", e); //$NON-NLS-1$
+ }
+ try {
+ // commit changes to underlying file
+ textFileBuffer.commit(null, true);
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("CoreException: ", e);
//$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+ /**
+ * The function reads file content into the string.
+ * @param fileSrc
+ * @return
+ */
+ protected String readInto(File fileSrc) {
+ FileInputStream fis = null;
+ BufferedInputStream bis = null;
+ StringBuilder str = new StringBuilder();
+ try {
+ fis = new FileInputStream(fileSrc);
+ bis = new BufferedInputStream(fis);
+ byte[] buff = new byte[1<<14];
+ while (true) {
+ int n = -1;
+ try {
+ n = bis.read(buff);
+ } catch (IOException e) {
+ HibernateConsolePlugin.getDefault().log(e);
+ }
+ if (n == -1) {
+ break;
+ }
+ str.append(new String(buff, 0, n));
+ }
+ } catch (FileNotFoundException e) {
+ HibernateConsolePlugin.getDefault().log(e);
+ } finally {
+ if (bis != null) {
+ try {
+ bis.close();
+ } catch (IOException e) {}
+ }
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {}
+ }
+ }
+ return str.toString();
+ }
+
+ /**
+ * Try to create one change according with input file (fileSrc).
+ * In case of success change be added into cc and returns true.
+ * @param cc
+ * @param proj
+ * @param fileSrc
+ * @return
+ */
+ protected boolean updateOneChange(final CompositeChange cc, final IJavaProject proj,
File fileSrc) {
+ if (!fileSrc.exists()) {
+ return false;
+ }
+ if (fileSrc.isDirectory()) {
+ return false;
+ }
+ final IPath basePath = proj.getResource().getParent().getLocation();
+ final IPath projPath = proj.getResource().getLocation();
+ final IPath place2Gen =
projPath.append(".settings").append(HIBERNATE_NEW_HBM_XML_FOLDER_NAME);
//$NON-NLS-1$
+ IPath filePathFrom = new Path(fileSrc.getPath());
+ IPath filePathTo = filePathFrom.makeRelativeTo(place2Gen);
+ filePathTo = projPath.append(filePathTo);
+ final IPath filePathTo_Show = filePathTo.makeRelativeTo(basePath);
+ File fileOrig = filePathTo.toFile();
+ if (fileOrig.exists()) {
+ final IPath filePathTo_Proj = filePathTo.makeRelativeTo(projPath);
+ class ResHolder {
+ public IResource res2Update = null;
+ }
+ final ResHolder res2UpdateHolder = new ResHolder();
+ IResourceVisitor visitor = new IResourceVisitor() {
+
+ public boolean visit(IResource resource) throws CoreException {
+ if (resource.getProjectRelativePath().equals(filePathTo_Proj)) {
+ res2UpdateHolder.res2Update = resource;
+ return false;
+ }
+ if (resource.getProjectRelativePath().isPrefixOf(filePathTo_Proj)) {
+ return true;
+ }
+ return false;
+ }
+
+ };
+ try {
+ proj.getResource().accept(visitor);
+ } catch (CoreException e1) {
+ //ignore
+ }
+ if (res2UpdateHolder.res2Update != null) {
+ final ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
+ ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(filePathTo_Show,
LocationKind.IFILE);
+ if (textFileBuffer == null) {
+ try {
+ bufferManager.connect(filePathTo_Show, LocationKind.IFILE, null);
+ paths2Disconnect.add(filePathTo_Show);
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("CoreException: ",
e); //$NON-NLS-1$
+ }
+ textFileBuffer = bufferManager.getTextFileBuffer(filePathTo_Show,
LocationKind.IFILE);
+ }
+ if (textFileBuffer != null) {
+ IDocument documentChange = textFileBuffer.getDocument();
+ //
+ String str = readInto(fileSrc);
+ TextEdit textEdit = new ReplaceEdit(0, documentChange.getLength(), str.toString());
+ //
+ TextFileChange change = new TextFileChange(filePathTo_Show.toString(),
+ (IFile)res2UpdateHolder.res2Update);
+ change.setSaveMode(TextFileChange.LEAVE_DIRTY);
+ change.setEdit(textEdit);
+ cc.add(change);
+ }
+ }
+ } else {
+ String str = readInto(fileSrc);
+ CreateTextFileChange change = new CreateTextFileChange(filePathTo_Show,
str.toString(), null, "hbm.xml"); //$NON-NLS-1$
+ cc.add(change);
+ }
+ return true;
+ }
+
+ /**
+ * Try to create changes according with all files in the input directory (dir).
+ * Changes be added into cc.
+ * @param cc
+ * @param proj
+ * @param dir
+ */
+ protected void updateChanges(final CompositeChange cc, final IJavaProject proj, File
dir) {
+ if (!dir.exists()) {
+ return;
+ }
+ if (!dir.isDirectory()) {
+ updateOneChange(cc, proj, dir);
+ return;
+ }
+ File[] files = dir.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ updateChanges(cc, proj, files[i]);
+ } else {
+ updateOneChange(cc, proj, files[i]);
+ }
+ }
+ }
+
+ protected void updateChanges() {
+ performDisconnect();
+ final CompositeChange cc = new CompositeChange(""); //$NON-NLS-1$
+ for (Entry<IJavaProject, IPath> entry : places2Gen.entrySet()) {
+ updateChanges(cc, entry.getKey(), entry.getValue().toFile());
+ }
+ cc.markAsSynthetic();
+ setChange(cc);
+ }
+
+ /**
+ * Apply changes.
+ */
+ @Override
+ public boolean performFinish() {
+ if (getChange() == null) {
+ return false;
+ }
+ performCommit();
+ try {
+ getChange().perform(new NullProgressMonitor());
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("CoreException: ", e);
//$NON-NLS-1$
+ }
+ performDisconnect();
+ return true;
+ }
+}