-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
144 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,47 +13,30 @@ | |
|
||
import java.io.File; | ||
import java.net.MalformedURLException; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Map.Entry; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
import org.eclipse.draw2d.IFigure; | ||
import org.eclipse.draw2d.PositionConstants; | ||
import org.eclipse.emf.ecore.EClass; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.EStructuralFeature; | ||
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; | ||
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; | ||
import org.eclipse.jface.resource.ImageDescriptor; | ||
import org.eclipse.sirius.business.api.dialect.DialectManager; | ||
import org.eclipse.sirius.business.api.session.Session; | ||
import org.eclipse.sirius.business.api.session.SessionManager; | ||
import org.eclipse.sirius.diagram.DDiagram; | ||
import org.eclipse.sirius.diagram.DDiagramElement; | ||
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNode2EditPart; | ||
import org.eclipse.sirius.diagram.ui.internal.edit.parts.WorkspaceImageEditPart; | ||
import org.eclipse.sirius.diagram.ui.internal.refresh.listeners.WorkspaceFileResourceChangeListener; | ||
import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; | ||
import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath; | ||
import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; | ||
import org.eclipse.sirius.tests.support.api.TestsUtil; | ||
import org.eclipse.sirius.ui.business.api.dialect.DialectEditor; | ||
import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; | ||
import org.eclipse.sirius.ui.business.api.session.IEditingSession; | ||
import org.eclipse.sirius.ui.business.api.session.SessionUIManager; | ||
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; | ||
import org.eclipse.swt.graphics.Image; | ||
import org.eclipse.swt.graphics.ImageData; | ||
import org.eclipse.swt.graphics.Resource; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.junit.Assert; | ||
import org.polarsys.kitalpha.sirius.rotativeimage.figures.Rotative4ImagesSVGWorkspaceImageFigure; | ||
import org.polarsys.kitalpha.sirius.rotativeimage.figures.RotativeSVGWorkspaceImageFigure; | ||
import org.polarsys.kitalpha.sirius.rotativeimage.figures.RotativeWorkspaceImageFigure; | ||
|
@@ -65,7 +48,7 @@ | |
* | ||
* @author <a href="mailto:[email protected]">Arnaud Dieumegard</a> | ||
*/ | ||
public class RotativeImageDisplayTest extends SiriusDiagramTestCase { | ||
public class RotativeImageDisplayTest extends RotativeSiriusTest { | ||
|
||
protected static final String PLATFORM_PLUGIN_PATH = "platform:/plugin/"; | ||
|
||
|
@@ -118,7 +101,6 @@ public class RotativeImageDisplayTest extends SiriusDiagramTestCase { | |
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
Resource.setNonDisposeHandler(null); | ||
genericSetUp(TEST_XMI_PATH, TEST_ODESIGN_PATH, TEST_AIRD_PATH); | ||
|
||
// Set test data | ||
|
@@ -163,13 +145,13 @@ protected void setUp() throws Exception { | |
public void testSVGDiagramImages() { | ||
String repId = ID_REPRESENTATION_DESCRIPTOR_SVG; | ||
DDiagram ddiagram = getDDiagramFromId(repId); | ||
DialectEditor editor = getEditor(ddiagram); | ||
DiagramEditor editor = getEditor(ddiagram); | ||
|
||
for (Entry<String, Integer> entry : dDiagramElementToPositionConstantRotationSVG.entrySet()) { | ||
String elementId = entry.getKey(); | ||
int position = entry.getValue(); | ||
|
||
WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId); | ||
WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId, editor); | ||
assertNotNull(editPart); | ||
RotativeSVGWorkspaceImageFigure figure = (RotativeSVGWorkspaceImageFigure) editPart.getContentPane(); | ||
assertNotNull(figure); | ||
|
@@ -184,7 +166,7 @@ public void testSVGDiagramImages() { | |
String elementId = entry.getKey(); | ||
int position = entry.getValue(); | ||
|
||
WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId); | ||
WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId, editor); | ||
assertNotNull(editPart); | ||
Rotative4ImagesSVGWorkspaceImageFigure figure = (Rotative4ImagesSVGWorkspaceImageFigure) editPart.getContentPane(); | ||
assertNotNull(figure); | ||
|
@@ -205,15 +187,15 @@ public void testSVGDiagramImages() { | |
public void testPNGDiagramImages() { | ||
String repId = ID_REPRESENTATION_DESCRIPTOR_PNG; | ||
DDiagram ddiagram = getDDiagramFromId(repId); | ||
DialectEditor editor = getEditor(ddiagram); | ||
DiagramEditor editor = getEditor(ddiagram); | ||
|
||
// Ensure displayed images rely on the correct rotated image | ||
for (Entry<String, Integer> entry : dDiagramElementToPositionConstantRotationPNG.entrySet()) { | ||
String elementId = entry.getKey(); | ||
int position = entry.getValue(); | ||
|
||
// Get the EditPart and the Figure | ||
WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId); | ||
WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId, editor); | ||
assertNotNull(editPart); | ||
RotativeWorkspaceImageFigure figure = (RotativeWorkspaceImageFigure) editPart.getContentPane(); | ||
assertNotNull(figure); | ||
|
@@ -229,7 +211,7 @@ public void testPNGDiagramImages() { | |
int position = entry.getValue(); | ||
|
||
// Get the EditPart and the Figure | ||
WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId); | ||
WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId, editor); | ||
assertNotNull(editPart); | ||
RotativeWorkspaceImageFigure figure = (RotativeWorkspaceImageFigure) editPart.getContentPane(); | ||
assertNotNull(figure); | ||
|
@@ -248,12 +230,12 @@ public void testPNGDiagramImages() { | |
public void testFaultyRotativeDiagramImages() { | ||
String repId = ID_REPRESENTATION_DESCRIPTOR_FAULTY_4IMAGES; | ||
DDiagram ddiagram = getDDiagramFromId(repId); | ||
DialectEditor editor = getEditor(ddiagram); | ||
DiagramEditor editor = getEditor(ddiagram); | ||
for (Entry<String, String> entry : dDiagramElementsToFileExtensionForFauly4Images.entrySet()) { | ||
String elementId = entry.getKey(); | ||
String extension = entry.getValue(); | ||
|
||
IFigure figure = getFigure(ddiagram, elementId); | ||
IFigure figure = getFigure(ddiagram, elementId, editor); | ||
|
||
if (figure instanceof RotativeWorkspaceImageFigure) { | ||
// Get expected image | ||
|
@@ -268,10 +250,8 @@ public void testFaultyRotativeDiagramImages() { | |
} | ||
} | ||
|
||
private DialectEditor getEditor(DDiagram ddiagram) { | ||
DialectEditor editor = (DialectEditor) DialectUIManager.INSTANCE.openEditor(session, ddiagram, new NullProgressMonitor()); | ||
TestsUtil.synchronizationWithUIThread(); | ||
DialectUIManager.INSTANCE.refreshEditor(editor, new NullProgressMonitor()); | ||
private DiagramEditor getEditor(DDiagram ddiagram) { | ||
DiagramEditor editor = (DiagramEditor) DialectUIManager.INSTANCE.openEditor(session, ddiagram, new NullProgressMonitor()); | ||
TestsUtil.synchronizationWithUIThread(); | ||
return editor; | ||
} | ||
|
@@ -301,8 +281,8 @@ private Image getImageNotFoundImage() { | |
return DiagramUIPlugin.getPlugin().getImage(DiagramUIPlugin.Implementation.findImageWithDimensionDescriptor(DiagramImagesPath.IMAGE_NOT_FOUND)); | ||
} | ||
|
||
private IFigure getFigure(DDiagram ddiagram, String elementId) { | ||
WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId); | ||
private IFigure getFigure(DDiagram ddiagram, String elementId, DiagramEditor editor) { | ||
WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId, editor); | ||
assertNotNull(editPart); | ||
IFigure figure = editPart.getContentPane(); | ||
assertNotNull(figure); | ||
|
@@ -385,10 +365,10 @@ private void compareImageData(int rotation, ImageData expectedImageData, ImageDa | |
} | ||
|
||
@SuppressWarnings({ "unchecked", "restriction" }) | ||
private WorkspaceImageEditPart getImageEditPart(DDiagram ddiagram, String elementId) { | ||
private WorkspaceImageEditPart getImageEditPart(DDiagram ddiagram, String elementId, DiagramEditor editor) { | ||
List<DDiagramElement> diagramElementsFromLabel = getDiagramElementsFromUid(ddiagram, elementId, DDiagramElement.class); | ||
for (DDiagramElement dDiagramElement : diagramElementsFromLabel) { | ||
IGraphicalEditPart editPart = getEditPart(dDiagramElement); | ||
IGraphicalEditPart editPart = getEditPart(dDiagramElement, editor); | ||
if (editPart instanceof DNode2EditPart) { | ||
List<WorkspaceImageEditPart> childrens = (List<WorkspaceImageEditPart>) editPart.getChildren().stream().filter(WorkspaceImageEditPart.class::isInstance).collect(Collectors.toList()); | ||
assertNotNull(childrens); | ||
|
@@ -400,80 +380,4 @@ private WorkspaceImageEditPart getImageEditPart(DDiagram ddiagram, String elemen | |
return null; | ||
} | ||
|
||
private <T extends DDiagramElement> List<T> getDiagramElementsFromUid(final DDiagram diagram, final String uid, final Class<T> searchedClass) { | ||
final List<T> found = new ArrayList<>(); | ||
final Iterator<EObject> it = diagram.eAllContents(); | ||
while (it.hasNext()) { | ||
final EObject cur = it.next(); | ||
if (searchedClass.isInstance(cur) && (uidFeature(cur.eClass()) != null) && uid.equals(getUidValue(cur))) { | ||
found.add(searchedClass.cast(cur)); | ||
} | ||
} | ||
return found; | ||
} | ||
|
||
private String getUidValue(final EObject cur) { | ||
return (String) cur.eGet(uidFeature(cur.eClass())); | ||
} | ||
|
||
private EStructuralFeature uidFeature(final EClass class1) { | ||
return class1.getEStructuralFeature("uid"); | ||
} | ||
|
||
public DRepresentationDescriptor getRepresentationDescriptor(Session session, String id) { | ||
Collection<DRepresentationDescriptor> representationDescriptors = DialectManager.INSTANCE.getAllRepresentationDescriptors(session); | ||
for (DRepresentationDescriptor representationDescriptor : representationDescriptors) { | ||
|
||
String descriptorFragment; | ||
try { | ||
descriptorFragment = representationDescriptor.getRepPath().getResourceURI().fragment(); | ||
} catch (NullPointerException e) { | ||
descriptorFragment = ""; | ||
} | ||
|
||
String descriptorUid = representationDescriptor.getUid(); | ||
|
||
if (id.equals(descriptorFragment) || id.equals(descriptorUid)) { | ||
return representationDescriptor; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
protected void tearDown() throws Exception { | ||
doCleanup(); | ||
super.tearDown(); | ||
} | ||
|
||
private void doCleanup() { | ||
final IEditingSession sessionUI = SessionUIManager.INSTANCE.getUISession(session); | ||
if (sessionUI != null) { | ||
SessionUIManager.INSTANCE.remove(sessionUI); | ||
sessionUI.close(); | ||
TestsUtil.emptyEventsFromUIThread(); | ||
} | ||
if (session != null) { | ||
doRemoveSession(); | ||
doCloseSession(); | ||
session = null; | ||
} | ||
viewpoints.clear(); | ||
Collection<DialectEditor> editors = Stream.of(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences()).map(x -> x.getEditor(false)).filter(Objects::nonNull).filter(DialectEditor.class::isInstance).map(DialectEditor.class::cast).collect(Collectors.toSet()); | ||
editors.forEach(e -> DialectUIManager.INSTANCE.closeEditor(e, false)); | ||
TestsUtil.emptyEventsFromUIThread(); | ||
} | ||
|
||
private void doCloseSession() { | ||
session.close(new NullProgressMonitor()); | ||
Assert.assertFalse("Can't close the session", session.isOpen()); | ||
} | ||
|
||
private void doRemoveSession() { | ||
SessionManager.INSTANCE.remove(session); | ||
for (final Session session2 : SessionManager.INSTANCE.getSessions()) { | ||
Assert.assertFalse("Remove failed", session2.equals(session)); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.