Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortle2011-05-19 19:12:31 +0000
committertle2011-05-19 19:12:31 +0000
commit1cbf7c0d8f8475d60b95d5c3cf5afa63621f9d7a (patch)
treea45ab31f92e8814a26c057f65b2cc9feb41cb317 /jpa_diagram_editor
parent931c14d62bf4956cff068405632162cb9b2b8b56 (diff)
downloadwebtools.dali-1cbf7c0d8f8475d60b95d5c3cf5afa63621f9d7a.tar.gz
webtools.dali-1cbf7c0d8f8475d60b95d5c3cf5afa63621f9d7a.tar.xz
webtools.dali-1cbf7c0d8f8475d60b95d5c3cf5afa63621f9d7a.zip
345274 - diagram.xmi is modified when editor opens (patch from JPAE team)
Diffstat (limited to 'jpa_diagram_editor')
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF3
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java12
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java16
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties8
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java93
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorDiagramTypeProvider.java29
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntitiesCoordinatesXML.java217
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java18
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java4
10 files changed, 366 insertions, 36 deletions
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF
index bcae287be2..2e5dd66285 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF
@@ -27,7 +27,8 @@ Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)",
org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)",
org.eclipse.ui.views.properties.tabbed;bundle-version="[3.4.0,4.0.0)",
org.eclipse.wst.common.emf;bundle-version="[1.1.200,2.0.0)",
- org.eclipse.wst.common.project.facet.core;bundle-version="[1.3.0,2.0.0)"
+ org.eclipse.wst.common.project.facet.core;bundle-version="[1.3.0,2.0.0)",
+ org.eclipse.core.filesystem;bundle-version="1.3.100"
Export-Package: org.eclipse.jpt.jpadiagrameditor.ui.internal;x-internal:=true,
org.eclipse.jpt.jpadiagrameditor.ui.internal.dialog;x-internal:=true,
org.eclipse.jpt.jpadiagrameditor.ui.internal.facade;x-internal:=true,
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java
index 04ef018a38..349533b3ff 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java
@@ -20,6 +20,7 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -57,6 +58,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelI
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorContextMenuProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorDiagramTypeProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.EntitiesCoordinatesXML;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPACheckSum;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
@@ -178,6 +180,12 @@ public class JPADiagramEditor extends DiagramEditor {
}
});
+
+ IProject project = ModelIntegrationUtil.getProjectByDiagram(d).getProject();
+ EntitiesCoordinatesXML xml = new EntitiesCoordinatesXML(project, d);
+ xml.store();
+ xml.close();
+
super.doSave(monitor);
}
@@ -239,7 +247,7 @@ public class JPADiagramEditor extends DiagramEditor {
}
public void init(IEditorSite site, IEditorInput input)
- throws PartInitException {
+ throws PartInitException {
IFile entityFile = (IFile) input.getAdapter(IFile.class);
if (entityFile != null && entityFile.getFileExtension().equals("java")) { //$NON-NLS-1$
@@ -247,7 +255,7 @@ public class JPADiagramEditor extends DiagramEditor {
} else
super.init(site, input);
}
-
+
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
super.selectionChanged(part, selection);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java
index 3a9be17efa..96308fdfe2 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java
@@ -53,6 +53,8 @@ class GraphicalRemoveAttributeFeature extends AbstractCustomFeature {
if (pe == null)
return;
TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(pe);
+ if (ted == null)
+ return;
ted.getCommandStack().execute(new RecordingCommand(ted) {
protected void doExecute() {
Shape sh = (Shape) pe;
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java
index 7b88767ff0..28e922a9d5 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java
@@ -228,6 +228,22 @@ public class JPAEditorMessages extends NLS {
public static String BTN_OK;
public static String BTN_CANCEL;
+ public static String EntitiesCoordinatesXML_CannotCloseFileStreamErrorMSG;
+
+ public static String EntitiesCoordinatesXML_CannotCreateDOMFileErrorMSG;
+
+ public static String EntitiesCoordinatesXML_CannotFindFileErrorMSG;
+
+ public static String EntitiesCoordinatesXML_CannotObtainProjectErrorMSG;
+
+ public static String EntitiesCoordinatesXML_CannotParseFileErrorMSG;
+
+ public static String EntitiesCoordinatesXML_CannotReadFileErrorMSG;
+
+ public static String EntitiesCoordinatesXML_CannotRefrfreshFile;
+
+ public static String ModelIntegrationUtil_CannotSetFileContentErrorMSG;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, JPAEditorMessages.class);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties
index d34e28678c..fcbc510027 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties
@@ -180,6 +180,13 @@ PaletteCompartment_Objects=Entities
BTN_OK=OK
BTN_CANCEL=Cancel
+EntitiesCoordinatesXML_CannotCloseFileStreamErrorMSG=Cannot close the stream
+EntitiesCoordinatesXML_CannotCreateDOMFileErrorMSG=Cannot create DOM file.
+EntitiesCoordinatesXML_CannotFindFileErrorMSG=Cannot find file.
+EntitiesCoordinatesXML_CannotObtainProjectErrorMSG=Cannot obtain project.
+EntitiesCoordinatesXML_CannotParseFileErrorMSG=Cannot parse file.
+EntitiesCoordinatesXML_CannotReadFileErrorMSG=Cannot read file.
+EntitiesCoordinatesXML_CannotRefrfreshFile=Cannot refresh the diagram xml file.
SelectTypeDialog_chooseAttributeTypeDialogText=Select a primitive type for the attribute "{0}" of the entity "{1}" or choose the "Browse" button to select a class type.
SelectTypeDialog_browseBtnTxt=&Browse...
@@ -193,6 +200,7 @@ SelectTypeDialog_emptyTypeErrorText=The new type name must not be empty
JPASolver_closeWarningMsg=The entity "{0}" is open elsewhere with identical changes. Using this button will not lose those changes. Close the other editor(s), where the entity "{0}" is open and try again!
JPASolver_closeEditors=Close Editors
+ModelIntegrationUtil_CannotSetFileContentErrorMSG=Cannot set file content.
RemoveJPAEntityFeature_discardWarningMsg=The entity "{0}" is open elsewhere with identical changes. Using this button will remove the entity from the diagram, but will not lose those changes. In order to lose the changes you need first to close the other editor(s), where the entity "{0}" is open and try again!\n\nDo you want to continue with removing anyway?
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java
index 0fe2825187..5841e97df4 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java
@@ -15,7 +15,9 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.HashMap;
@@ -23,10 +25,18 @@ import java.util.Iterator;
import java.util.Properties;
import java.util.WeakHashMap;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileInfo;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.filesystem.IFileSystem;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
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.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
@@ -39,9 +49,11 @@ import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.ui.editor.DiagramEditorFactory;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorDiagramTypeProvider;
@@ -49,20 +61,70 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorDiagramTyp
public class ModelIntegrationUtil {
public static final String DIAGRAM_FILE_EXTENSION = "xmi"; //$NON-NLS-1$
+ public static final String DIAGRAM_XML_FILE_EXTENSION = "xml"; //$NON-NLS-1$
public static final String JPA_DIAGRAM_TYPE = "JPA Diagram"; //$NON-NLS-1$
public static final String DEFAULT_RES_FOLDER = "src"; //$NON-NLS-1$
private static WeakHashMap<Diagram, WeakReference<JpaProject>> diagramsToProjects = new WeakHashMap<Diagram, WeakReference<JpaProject>>();
private static WeakHashMap<Diagram, WeakReference<JPAEditorDiagramTypeProvider>> diagramsToProviders = new WeakHashMap<Diagram, WeakReference<JPAEditorDiagramTypeProvider>>();
private static HashMap<Diagram, Resource> diagramsToResources = new HashMap<Diagram, Resource>();
+ private static boolean xmiExists = false;
public static IPath createDiagramPath(PersistenceUnit persistenceUnit) throws CoreException {
IProject project = persistenceUnit.getJpaProject().getProject();
- IPath projectPath = project.getFullPath();
String diagramName = persistenceUnit.getName();
- IPath path = getDiagramsFolderPath(project).append(diagramName).addFileExtension(DIAGRAM_FILE_EXTENSION);
- path = projectPath.append(path);
- return path;
+ IPath newXMIFilePath = getDiagramsFolderPath(project).append(diagramName).addFileExtension(DIAGRAM_FILE_EXTENSION);
+ IFileSystem fileSystem = EFS.getLocalFileSystem();
+ IFileStore newXMIFile = fileSystem.getStore(newXMIFilePath);
+
+ IPath folderPath = copyExistingXMIContentAndDeleteFile(project, diagramName, newXMIFile);
+ if(folderPath != null){
+ IFile diagramXMLFile = ResourcesPlugin.getWorkspace().getRoot().getFile(folderPath.append(diagramName).addFileExtension(DIAGRAM_XML_FILE_EXTENSION));
+ String content = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"+ //$NON-NLS-1$
+ "<entities>\n"+ //$NON-NLS-1$
+ "</entities>\n"; //$NON-NLS-1$
+ if(diagramXMLFile == null || !diagramXMLFile.exists()){
+ InputStream source = new ByteArrayInputStream(content.getBytes());
+ diagramXMLFile.create(source, true, new NullProgressMonitor());
+ } else
+ try {
+ if(diagramXMLFile.getContents().read() == -1){
+ diagramXMLFile.setContents(new ByteArrayInputStream(content.getBytes()), true, false, new NullProgressMonitor());
+ }
+ } catch (IOException e) {
+ JPADiagramEditorPlugin.logError(JPAEditorMessages.ModelIntegrationUtil_CannotSetFileContentErrorMSG, e);
+ }
+ }
+
+ return newXMIFilePath;
+ }
+
+ private static IPath copyExistingXMIContentAndDeleteFile(IProject project,
+ String diagramName, IFileStore newXMIFile) throws JavaModelException, CoreException {
+ IPath folderPath = null;
+ IResource[] resources = project.members();
+ for(IResource res : resources){
+ if(res instanceof IFolder){
+ folderPath = ((IFolder)res).getFullPath();
+ IFile existingXMIFile =((IFolder)res).getFile(diagramName + "." +DIAGRAM_FILE_EXTENSION); //$NON-NLS-1$
+ if(existingXMIFile != null && existingXMIFile.exists()){
+ IFileStore folder = EFS.getLocalFileSystem().getStore(existingXMIFile.getLocationURI());
+ folder.copy(newXMIFile, EFS.OVERWRITE, null);
+ existingXMIFile.delete(true, new NullProgressMonitor());
+ setXmiExists(true);
+ return folderPath;
+ }
+ }
+ }
+
+ IPath projectPath = project.getFullPath();
+ folderPath = projectPath.append(getDiagramsXMLFolderPath(project));
+ IFileStore xmlFileStore = EFS.getLocalFileSystem().getStore(folderPath.append(diagramName).addFileExtension(DIAGRAM_XML_FILE_EXTENSION));
+ IFileInfo info = xmlFileStore.fetchInfo();
+ if(!info.exists() && info.isDirectory()){
+ xmlFileStore.mkdir(EFS.NONE, null);
+ }
+ return folderPath;
}
public static Diagram createDiagram(PersistenceUnit persistenceUnit,
@@ -104,11 +166,9 @@ public class ModelIntegrationUtil {
TransactionalEditingDomain defaultTransEditDomain = DiagramEditorFactory.createResourceSetAndEditingDomain();
ResourceSet resourceSet = defaultTransEditDomain.getResourceSet();
- IFile diagramFile = project.getFile(diagramFileName.removeFirstSegments(1));
- IPath diagramFilePath = diagramFile.getFullPath();
- String pathName = diagramFilePath.toString();
- URI resourceURI = URI.createPlatformResourceURI(pathName, true);
+ String pathName = diagramFileName.toString();
+ URI resourceURI = URI.createFileURI(pathName);
final Resource resource = resourceSet.createResource(resourceURI);
//resource.setTrackingModification(false);
//(ResourceSetManager.getProjectForResourceSet(resourceSet));
@@ -176,11 +236,15 @@ public class ModelIntegrationUtil {
return project.getProjectRelativePath().append(DEFAULT_RES_FOLDER);
}
- public static IPath getDiagramsFolderPath(IProject project) {
+ public static IPath getDiagramsXMLFolderPath(IProject project) {
Properties props = JPADiagramPropertyPage.loadProperties(project);
return new Path(JPADiagramPropertyPage.getDefaultFolder(project, props));
}
+ public static IPath getDiagramsFolderPath(IProject project){
+ return JPADiagramEditorPlugin.getDefault().getStateLocation();
+ }
+
public static void mapDiagramToProject(Diagram diagram, JpaProject project) {
diagramsToProjects.put(diagram, new WeakReference<JpaProject>(project));
}
@@ -222,7 +286,12 @@ public class ModelIntegrationUtil {
public static void mapDiagramToProvider(Diagram diagram, JPAEditorDiagramTypeProvider provider) {
diagramsToProviders.put(diagram, new WeakReference<JPAEditorDiagramTypeProvider>(provider));
}
-
-
-
+
+ public static boolean isXmiExists() {
+ return xmiExists;
+ }
+
+ public static void setXmiExists(boolean xmiExists) {
+ ModelIntegrationUtil.xmiExists = xmiExists;
+ }
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorDiagramTypeProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorDiagramTypeProvider.java
index 3c61f50815..6ef53a04da 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorDiagramTypeProvider.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorDiagramTypeProvider.java
@@ -37,7 +37,6 @@ import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.impl.AddContext;
import org.eclipse.graphiti.features.context.impl.CustomContext;
import org.eclipse.graphiti.features.context.impl.RemoveContext;
-import org.eclipse.graphiti.mm.algorithms.RoundedRectangle;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
@@ -58,6 +57,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddJPAEntityFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.RemoveRelationFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.EntitiesCoordinatesXML;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPACheckSum;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPASolver;
@@ -168,7 +168,7 @@ public class JPAEditorDiagramTypeProvider extends AbstractDiagramTypeProvider {
PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(proj);
String diagramName = pu.getName();
IPath path = ModelIntegrationUtil.getDiagramsFolderPath(project).append(diagramName).addFileExtension(ModelIntegrationUtil.DIAGRAM_FILE_EXTENSION);
- final IFile f = project.getFile(path);
+ final IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
boolean readOnly = (f != null) && f.exists() && f.isReadOnly();
if (readOnly) {
if (JPACheckSum.INSTANCE().isModelDifferentFromDiagram(diagram, proj) || hasToAdd) {
@@ -214,22 +214,21 @@ public class JPAEditorDiagramTypeProvider extends AbstractDiagramTypeProvider {
removeConnections();
- final Hashtable<String, SizePosition> marks = new Hashtable<String, SizePosition>();
+ final Hashtable<String, SizePosition> marks = new Hashtable<String, SizePosition>();
+ EntitiesCoordinatesXML xml = new EntitiesCoordinatesXML(project, getDiagram());
+ xml.load(marks);
+
List<Shape> picts = diagram.getChildren();
- if (picts.size() == 0)
- return readOnly;
Iterator<Shape> it = picts.iterator();
HashSet<Shape> toDelete = new HashSet<Shape>();
// collecting data from the saved pictograms
while (it.hasNext()) {
Shape pict = it.next();
- String name = Graphiti.getPeService().getPropertyValue(pict, JPAEditorConstants.PROP_ENTITY_CLASS_NAME);
- SizePosition rectSP = loadSizeAndPosition(pict);
- marks.put(name, rectSP);
toDelete.add(pict);
}
- final Iterator<Shape> iter = toDelete.iterator();
+ final Iterator<Shape> iter = toDelete.iterator();
+
TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(diagram);
ted.getCommandStack().execute(new RecordingCommand(ted) {
protected void doExecute() {
@@ -272,17 +271,6 @@ public class JPAEditorDiagramTypeProvider extends AbstractDiagramTypeProvider {
return false;
}
- private SizePosition loadSizeAndPosition(Shape pict) {
- RoundedRectangle rect = (RoundedRectangle)pict.getGraphicsAlgorithm();
- SizePosition rectSP = new SizePosition(rect.getWidth(), rect.getHeight(),
- rect.getX(), rect.getY());
-
- rectSP.primaryCollapsed = JPAEditorConstants.TRUE_STRING.equals(Graphiti.getPeService().getPropertyValue(pict, JPAEditorConstants.PRIMARY_COLLAPSED));
- rectSP.relationCollapsed = JPAEditorConstants.TRUE_STRING.equals(Graphiti.getPeService().getPropertyValue(pict, JPAEditorConstants.RELATION_COLLAPSED));
- rectSP.basicCollapsed = JPAEditorConstants.TRUE_STRING.equals(Graphiti.getPeService().getPropertyValue(pict, JPAEditorConstants.BASIC_COLLAPSED));
- return rectSP;
- }
-
private void removeConnections() {
Collection<org.eclipse.graphiti.mm.pictograms.Connection> cons = getDiagram().getConnections();
Iterator<org.eclipse.graphiti.mm.pictograms.Connection> consIt = cons.iterator();
@@ -317,5 +305,4 @@ public class JPAEditorDiagramTypeProvider extends AbstractDiagramTypeProvider {
setFeatureProvider(null);
isDisposed = true;
}
-
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntitiesCoordinatesXML.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntitiesCoordinatesXML.java
new file mode 100644
index 0000000000..117806c73f
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntitiesCoordinatesXML.java
@@ -0,0 +1,217 @@
+package org.eclipse.jpt.jpadiagrameditor.ui.internal.util;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.graphiti.mm.algorithms.RoundedRectangle;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xml.sax.SAXException;
+
+public class EntitiesCoordinatesXML {
+
+ private Diagram diagram;
+ private File file;
+ private Document document;
+ private Element rootElement;
+ private IFile existingXMLFile;
+
+ public static final String XML_ELEMENT_POSITION = "\n\t\t"; //$NON-NLS-1$
+
+ public EntitiesCoordinatesXML(IProject project, Diagram diagram){
+ this.diagram = diagram;
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ try {
+ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+ file = findXMLFile(project);
+ document = documentBuilder.parse(file);
+ rootElement = document.getDocumentElement();
+ } catch (ParserConfigurationException e) {
+ JPADiagramEditorPlugin.logError(JPAEditorMessages.EntitiesCoordinatesXML_CannotParseFileErrorMSG, e);
+ } catch (SAXException e) {
+ JPADiagramEditorPlugin.logError(JPAEditorMessages.EntitiesCoordinatesXML_CannotParseFileErrorMSG, e);
+ } catch (IOException e) {
+ JPADiagramEditorPlugin.logError(JPAEditorMessages.EntitiesCoordinatesXML_CannotReadFileErrorMSG, e);
+ }
+ }
+
+
+ private File findXMLFile(IProject project){
+ try {
+ IResource[] resources = project.members();
+ for (IResource res : resources) {
+ if (res instanceof IFolder) {
+ existingXMLFile = ((IFolder) res).getFile(diagram.getName() + "." + ModelIntegrationUtil.DIAGRAM_XML_FILE_EXTENSION); //$NON-NLS-1$
+ if (existingXMLFile != null && existingXMLFile.exists()) {
+ return new File(existingXMLFile.getLocationURI());
+ }
+ }
+ }
+ } catch (CoreException e) {
+ JPADiagramEditorPlugin.logError(JPAEditorMessages.EntitiesCoordinatesXML_CannotObtainProjectErrorMSG, e);
+ }
+ existingXMLFile = project.getFile(ModelIntegrationUtil.getDiagramsXMLFolderPath(project).append(diagram.getName()).addFileExtension(ModelIntegrationUtil.DIAGRAM_XML_FILE_EXTENSION));
+ return new File(existingXMLFile.getLocationURI());
+ }
+
+ public void store() {
+
+ List<Shape> picts = diagram.getChildren();
+ Iterator<Shape> it = picts.iterator();
+ // collecting data from the saved pictograms
+ document.removeChild(rootElement);
+ rootElement = document.createElement("entities"); //$NON-NLS-1$
+ document.appendChild(rootElement);
+
+ while (it.hasNext()) {
+ Shape pict = it.next();
+ String name = Graphiti.getPeService().getPropertyValue(pict, JPAEditorConstants.PROP_ENTITY_CLASS_NAME);
+
+ RoundedRectangle rect = (RoundedRectangle) pict.getGraphicsAlgorithm();
+
+ boolean isPrimaryCollapsed = JPAEditorConstants.TRUE_STRING.equals(Graphiti.getPeService().getPropertyValue(pict,
+ JPAEditorConstants.PRIMARY_COLLAPSED));
+ boolean isRelationCollapsed = JPAEditorConstants.TRUE_STRING.equals(Graphiti.getPeService().getPropertyValue(pict,
+ JPAEditorConstants.RELATION_COLLAPSED));
+ boolean isBasicCollapsed = JPAEditorConstants.TRUE_STRING.equals(Graphiti.getPeService().getPropertyValue(pict,
+ JPAEditorConstants.BASIC_COLLAPSED));
+
+ Element entity = createEntityElementTag(document, rootElement, JPAEditorConstants.ENTITY_XML_TAG, XML_ELEMENT_POSITION);
+ Text nameText = document.createTextNode(name);
+ Element entityName = document.createElement(JPAEditorConstants.ENTITY_NAME_TAG);
+ createChildElementTag(document, nameText, entityName, entity, XML_ELEMENT_POSITION);
+
+ Text width = document.createTextNode(String.valueOf(rect.getWidth()));
+ Element entityWidth = document.createElement(JPAEditorConstants.ENTITY_WIDTH_TAG);
+ createChildElementTag(document, width, entityWidth, entity, XML_ELEMENT_POSITION);
+
+ Text height = document.createTextNode(String.valueOf(rect.getHeight()));
+ Element entityHeight = document.createElement(JPAEditorConstants.ENTITY_HEIGHT_TAG);
+ createChildElementTag(document, height, entityHeight, entity, XML_ELEMENT_POSITION);
+
+ Text xCoordinate = document.createTextNode(String.valueOf(rect.getX()));
+ Element entityXCoordinate = document.createElement(JPAEditorConstants.ENTITY_X_COORDINATE_TAG);
+ createChildElementTag(document, xCoordinate, entityXCoordinate, entity, XML_ELEMENT_POSITION);
+
+ Text yCoordinate = document.createTextNode(String.valueOf(rect.getY()));
+ Element entityYCoordinate = document.createElement(JPAEditorConstants.ENTITY_Y_COORDINATE_TAG);
+ createChildElementTag(document, yCoordinate, entityYCoordinate, entity, XML_ELEMENT_POSITION);
+
+ Text primaryCollapsed = document.createTextNode(String.valueOf(isPrimaryCollapsed));
+ Element entityPrimaryCollapsed = document.createElement(JPAEditorConstants.ENTITY_PRIMARY_SECTION_STATE_TAG);
+ createChildElementTag(document, primaryCollapsed, entityPrimaryCollapsed, entity, XML_ELEMENT_POSITION);
+
+ Text relationCollapsed = document.createTextNode(String.valueOf(isRelationCollapsed));
+ Element entityRelationCollapsed = document.createElement(JPAEditorConstants.ENTITY_RELATION_SECTION_STATE_TAG);
+ createChildElementTag(document, relationCollapsed, entityRelationCollapsed, entity, XML_ELEMENT_POSITION);
+
+ Text basicCollapsed = document.createTextNode(String.valueOf(isBasicCollapsed));
+ Element entityBasicCollapsed = document.createElement(JPAEditorConstants.ENTITY_BASIC_SECTION_STATE_TAG);
+ createChildElementTag(document, basicCollapsed, entityBasicCollapsed, entity, "\n\t"); //$NON-NLS-1$
+
+ rootElement.appendChild(document.createTextNode("\n")); //$NON-NLS-1$
+
+ }
+ ModelIntegrationUtil.setXmiExists(false);
+ }
+
+ public void load(Hashtable<String, SizePosition> marks){
+
+ if(rootElement.getChildNodes().getLength()<=1){
+ if(ModelIntegrationUtil.isXmiExists()){
+ store();
+ close();
+ }
+ }
+
+ NodeList nodeList = rootElement.getElementsByTagName(JPAEditorConstants.ENTITY_XML_TAG);
+ for(int i=0; i<nodeList.getLength();i++){
+ Element node = (Element) nodeList.item(i);
+ String entityName = node.getElementsByTagName(JPAEditorConstants.ENTITY_NAME_TAG).item(0).getTextContent();
+ int width = Integer.parseInt(node.getElementsByTagName(JPAEditorConstants.ENTITY_WIDTH_TAG).item(0).getTextContent());
+ int height = Integer.parseInt(node.getElementsByTagName(JPAEditorConstants.ENTITY_HEIGHT_TAG).item(0).getTextContent());
+ int xCoordinate = Integer.parseInt(node.getElementsByTagName(JPAEditorConstants.ENTITY_X_COORDINATE_TAG).item(0).getTextContent());
+ int yCoordinate = Integer.parseInt(node.getElementsByTagName(JPAEditorConstants.ENTITY_Y_COORDINATE_TAG).item(0).getTextContent());
+ boolean isPrimaryCollapsed = Boolean.parseBoolean(node.getElementsByTagName(JPAEditorConstants.ENTITY_PRIMARY_SECTION_STATE_TAG).item(0).getTextContent());
+ boolean isRelationCollapsed = Boolean.parseBoolean(node.getElementsByTagName(JPAEditorConstants.ENTITY_RELATION_SECTION_STATE_TAG).item(0).getTextContent());
+ boolean isBasicCollapsed = Boolean.parseBoolean(node.getElementsByTagName(JPAEditorConstants.ENTITY_BASIC_SECTION_STATE_TAG).item(0).getTextContent());
+
+ SizePosition rectSP = new SizePosition(width, height, xCoordinate, yCoordinate);
+ rectSP.primaryCollapsed = isPrimaryCollapsed;
+ rectSP.relationCollapsed = isRelationCollapsed;
+ rectSP.basicCollapsed = isBasicCollapsed;
+
+ marks.put(entityName, rectSP);
+ }
+
+ }
+
+ private Element createEntityElementTag(Document document, Element scheduleElement, String descr, String position) {
+ Element job = document.createElement(descr);
+ scheduleElement.appendChild(document.createTextNode("\n\t")); //$NON-NLS-1$
+ scheduleElement.appendChild(job);
+ job.appendChild(document.createTextNode(position));
+
+ return job;
+ }
+
+ private void createChildElementTag(Document document, Text nameText, Element nameEl, Element parentElement, String position) {
+ parentElement.appendChild(nameEl);
+ nameEl.appendChild(nameText);
+ parentElement.appendChild(document.createTextNode(position));
+ }
+
+ public void close() {
+ OutputStream os;
+ try {
+ os = new FileOutputStream(file);
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ transformer.transform(new DOMSource(document), new StreamResult(os));
+ os.close();
+ } catch (FileNotFoundException e) {
+ JPADiagramEditorPlugin.logError(JPAEditorMessages.EntitiesCoordinatesXML_CannotFindFileErrorMSG, e);
+ } catch (TransformerException e) {
+ JPADiagramEditorPlugin.logError(JPAEditorMessages.EntitiesCoordinatesXML_CannotCreateDOMFileErrorMSG, e);
+ } catch (IOException e) {
+ JPADiagramEditorPlugin.logError(JPAEditorMessages.EntitiesCoordinatesXML_CannotCloseFileStreamErrorMSG, e);
+ }
+
+ try {
+ existingXMLFile.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ } catch (CoreException e) {
+ JPADiagramEditorPlugin.logError(JPAEditorMessages.EntitiesCoordinatesXML_CannotRefrfreshFile, e);
+ }
+ }
+
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java
index f34bad2476..600b0072e0 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java
@@ -202,5 +202,23 @@ public class JPAEditorConstants {
public static final String PROP_ENTITY_CHECKSUM = "diagram.checksum"; //$NON-NLS-1$
public static final String JPA_SUPPORT_DIALOG_ID = "jpa_support_warning"; //$NON-NLS-1$
+
+ public static final String ENTITY_XML_TAG = "entity"; //$NON-NLS-1$
+
+ public static final String ENTITY_NAME_TAG = "entity-name"; //$NON-NLS-1$
+
+ public static final String ENTITY_WIDTH_TAG = "entity-width"; //$NON-NLS-1$
+
+ public static final String ENTITY_HEIGHT_TAG = "entity-height"; //$NON-NLS-1$
+
+ public static final String ENTITY_X_COORDINATE_TAG = "entity-X-Coordinate"; //$NON-NLS-1$
+
+ public static final String ENTITY_Y_COORDINATE_TAG = "entity-Y-Coordinate"; //$NON-NLS-1$
+
+ public static final String ENTITY_PRIMARY_SECTION_STATE_TAG = "primary-collapsed"; //$NON-NLS-1$
+
+ public static final String ENTITY_RELATION_SECTION_STATE_TAG = "relation-collapsed"; //$NON-NLS-1$
+
+ public static final String ENTITY_BASIC_SECTION_STATE_TAG = "basic-collapsed"; //$NON-NLS-1$
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java
index 2c4bb35fad..70aa80bea0 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java
@@ -430,6 +430,8 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
public void renewAttributeJoiningStrategyPropertyListener(JavaPersistentAttribute jpa) {
AttributeJoiningStrategyPropertyChangeListener lsn = null;
+ if (attributeJoiningStrategyToPropListener == null)
+ return;
WeakReference<AttributeJoiningStrategyPropertyChangeListener> ref = attributeJoiningStrategyToPropListener.remove(jpa);
if (ref != null)
lsn = ref.get();
@@ -1199,6 +1201,8 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
renewAttributeJoiningStrategyPropertyListener(jpa);
if (!jpa.getParent().getParent().getResource().exists())
return;
+ if (featureProvider == null)
+ return;
PictogramElement pe = featureProvider.getPictogramElementForBusinessObject(jpa.getParent());
final UpdateAttributeFeature ft = new UpdateAttributeFeature(featureProvider);
final CustomContext ctx = new CustomContext();

Back to the top