Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcdumoulin2013-06-04 18:40:38 -0400
committercdumoulin2013-06-04 18:40:38 -0400
commit4c1ace9f7d5b6174decab9d5c5e0c66756ab6935 (patch)
treeb2275c47863d673a4f49c502ee2d55993f34f1b7 /tests/junit/plugins/core
parent86bc96a9feeb841c45736f3e15a1137ec639fdc3 (diff)
downloadorg.eclipse.papyrus-4c1ace9f7d5b6174decab9d5c5e0c66756ab6935.tar.gz
org.eclipse.papyrus-4c1ace9f7d5b6174decab9d5c5e0c66756ab6935.tar.xz
org.eclipse.papyrus-4c1ace9f7d5b6174decab9d5c5e0c66756ab6935.zip
ASSIGNED - bug 404142: [sasheditor] Rename diagram command from sash tab
https://bugs.eclipse.org/bugs/show_bug.cgi?id=404142 Add test suite related to classes modified for the rename command. Allow to build ContentProvider models by using expressions (Folder(f1, page(p1), Page(p2))
Diffstat (limited to 'tests/junit/plugins/core')
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.editor.integration.tests/src/org/eclipse/papyrus/editor/integration/tests/tests/PageManagerTests.java7
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/META-INF/MANIFEST.MF3
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/CheckVisitor.java119
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/CreateModelVisitor.java145
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/DiContentProviderBaseVisitor.java327
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/DiContentProviderFacade.java440
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/DiContentProviderFacadeTest.java44
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/QueryVisitor.java138
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/META-INF/MANIFEST.MF3
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/AbstractSashWindowContentProviderFacadeTest.java272
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/ISashWindowsContentProviderFacade.java220
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/CreateModelInSimpleContentProviderVisitor.java4
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleContentProviderBaseVisitor.java11
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContainerTestFacade.java452
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContainerTestFacadeCommonTest.java44
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContainerTestFacadeTest.java91
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderFacade.java368
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderFacadeTest.java151
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderFacadeTest2.java44
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderUtils.java22
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowsContentProviderTest.java170
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/FakeFolderLifeCycleEventsListener.java143
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/FakeTabFolderPart.java (renamed from tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/IModelExp.java)22
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/FolderLifeCycleEventsThrownFromContainerTest.java163
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/SashWindowsContainerTest.java109
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/TabFolderListManagerTest.java95
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/AbstractSash.java95
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/BadNameException.java (renamed from tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/NoMatchException.java)21
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/Folder.java86
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/HSash.java66
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/IModelObject.java38
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/IPagesModelVisitor.java68
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/NotFoundException.java (renamed from tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/PagesModelException.java)50
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/Page.java116
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/PanelTerm.java74
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/SashPagesModel.java103
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/SashPagesModelFactory.java98
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/VSash.java66
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/WindowTerm.java83
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/tests/utils/ISashWindowsContentProviderTestUtils.java78
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/tests/utils/package-info.java (renamed from tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/package-info.java)4
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/utils/FakeObservableListener.java84
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/utils/ObservableListTest.java173
43 files changed, 3960 insertions, 950 deletions
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.editor.integration.tests/src/org/eclipse/papyrus/editor/integration/tests/tests/PageManagerTests.java b/tests/junit/plugins/core/org.eclipse.papyrus.editor.integration.tests/src/org/eclipse/papyrus/editor/integration/tests/tests/PageManagerTests.java
index 19fc105280f..cb83c2d4004 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.editor.integration.tests/src/org/eclipse/papyrus/editor/integration/tests/tests/PageManagerTests.java
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.editor.integration.tests/src/org/eclipse/papyrus/editor/integration/tests/tests/PageManagerTests.java
@@ -40,6 +40,8 @@ import org.eclipse.papyrus.infra.core.extension.commands.IModelCreationCommand;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
import org.eclipse.papyrus.infra.core.services.ExtensionServicesRegistry;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
@@ -220,6 +222,11 @@ public class PageManagerTests extends AbstractEditorIntegrationTest {
editingDomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(new OpenDiagramCommand(editingDomain, timingDiagram)));
Assert.assertTrue(editor.getActiveEditor() instanceof UmlTimingDiagramForMultiEditor);
+
+ // Check type requested by selectPage
+ ISashWindowsContainer container = editor.getServicesRegistry().getService(ISashWindowsContainer.class);
+ IPage selectedPage = container.getActiveSashWindowsPage();
+
//FIXME: Does not work yet. See Bug 401107: [IPageManager] selectPage does not work
//TODO: There should be a specific test for selectPage, with a basic and a complex model
pageManager.selectPage(classDiagram);
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/META-INF/MANIFEST.MF
index 55f61e7bf46..4ec900b649c 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/META-INF/MANIFEST.MF
@@ -6,7 +6,6 @@ Fragment-Host: org.eclipse.papyrus.infra.core.sasheditor.di;bundle-ver
Bundle-Version: 0.10.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.eclipse.papyrus.infra.core.sasheditor.di.test
- s
+Bundle-SymbolicName: org.eclipse.papyrus.infra.core.sasheditor.di.tests
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/CheckVisitor.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/CheckVisitor.java
new file mode 100644
index 00000000000..d0e8a6b105a
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/CheckVisitor.java
@@ -0,0 +1,119 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.internal;
+
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Folder;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.HSash;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IPagesModelVisitor;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.NoMatchException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.VSash;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.WindowTerm;
+import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef;
+import org.eclipse.papyrus.infra.core.sashwindows.di.SashPanel;
+import org.eclipse.papyrus.infra.core.sashwindows.di.TabFolder;
+import org.eclipse.papyrus.infra.core.sashwindows.di.Window;
+import org.eclipse.swt.SWT;
+
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class CheckVisitor extends DiContentProviderBaseVisitor implements IPagesModelVisitor<Object> {
+
+ /**
+ * @return the isVisitingParentFirst
+ */
+ @Override
+ public boolean isVisitingParentFirst() {
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.WindowTerm, org.eclipse.papyrus.infra.core.sashwindows.di.Window)
+ *
+ * @param windowTerm
+ * @param windowModel
+ */
+ @Override
+ public void visit(WindowTerm windowTerm, Window windowModel) {
+ // TODO Auto-generated method stub
+
+ }
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.Folder)
+ *
+ * @param folder
+ */
+ @Override
+ public void visit(Folder folder, TabFolder folderModel) {
+ // Check name
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.HSash)
+ *
+ * @param sash
+ * @throws NoMatchException
+ */
+ @Override
+ public void visit(HSash sash, SashPanel sashModel) throws NoMatchException {
+ // Check orientation
+ if( sashModel.getDirection() != SWT.HORIZONTAL) {
+ throw new NoMatchException( this.toString() + " - SashOrientation does not match 'HORIZONTAL'" );
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.VSash)
+ *
+ * @param sash
+ * @throws NoMatchException
+ */
+ @Override
+ public void visit(VSash sash , SashPanel sashModel) throws NoMatchException {
+ // Check orientation
+ if( sashModel.getDirection() != SWT.VERTICAL) {
+ throw new NoMatchException( this.toString() + " - SashOrientation does not match 'VERTICAL'" );
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.Page)
+ *
+ * @param page
+ * @throws NoMatchException
+ */
+ @Override
+ public void visit(Page page, PageRef pageModel) throws PagesModelException {
+ //check name
+ if(page.getIdentifier() != null) {
+ checkName(page.getIdentifier(), pageModel.getPageIdentifier()) ;
+ }
+ else if(page.getName() != null) {
+ checkName(page.getName(), pageModel.getPageIdentifier()) ;
+ }
+ }
+
+
+ protected void checkName( Object expectedName, Object foundName) throws NoMatchException {
+ if( expectedName != foundName )
+ throw new NoMatchException( "Names do not match (expected="
+ + expectedName + ", found="+ foundName );
+ }
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/CreateModelVisitor.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/CreateModelVisitor.java
new file mode 100644
index 00000000000..784bbeba21b
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/CreateModelVisitor.java
@@ -0,0 +1,145 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.internal;
+
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.AbstractSash;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Folder;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.HSash;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IPagesModelVisitor;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PanelTerm;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.VSash;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.WindowTerm;
+import org.eclipse.papyrus.infra.core.sashwindows.di.DiFactory;
+import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef;
+import org.eclipse.papyrus.infra.core.sashwindows.di.SashPanel;
+import org.eclipse.papyrus.infra.core.sashwindows.di.TabFolder;
+import org.eclipse.papyrus.infra.core.sashwindows.di.Window;
+import org.eclipse.swt.SWT;
+
+/**
+ * This visitor is used with {@link IQueryTerm} to create a {@link SashModel} instancied
+ * with the Sash, folders and pages specified in the query.
+ *
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class CreateModelVisitor extends DiContentProviderBaseVisitor implements IPagesModelVisitor<Object> {
+
+ /**
+ * @return the isVisitingParentFirst
+ */
+ public boolean isVisitingParentFirst() {
+ return true;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.WindowTerm, org.eclipse.papyrus.infra.core.sashwindows.di.Window)
+ *
+ * @param windowTerm
+ * @param windowModel
+ */
+ public void visit(WindowTerm windowTerm, Window windowModel) {
+ // Create children of the sash
+ PanelTerm panel = windowTerm.getPanel();
+ if(panel instanceof AbstractSash) {
+ windowModel.setPanel(DiFactory.eINSTANCE.createSashPanel());
+ }
+ else if (panel instanceof Folder) {
+ windowModel.setPanel(DiFactory.eINSTANCE.createTabFolder());
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.Folder, org.eclipse.papyrus.infra.core.sashwindows.di.TabFolder)
+ *
+ * @param folder
+ * @param folderModel
+ */
+ public void visit(Folder folder, TabFolder folderModel) {
+
+ // Create children of the folder
+ for( Page page : folder.getPages() ) {
+ folderModel.getChildren().add(DiFactory.eINSTANCE.createPageRef());
+ }
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.HSash, org.eclipse.papyrus.infra.core.sashwindows.di.SashPanel)
+ *
+ * @param sashQuery
+ * @param sashModel
+ */
+ public void visit(HSash sashQuery, SashPanel sashModel) {
+
+ // sash orientation
+ sashModel.setDirection(SWT.HORIZONTAL);
+ // Create children of the sash
+
+ createPanelOrFolder(sashQuery.getLeftup(), sashModel);
+ createPanelOrFolder(sashQuery.getRightdown(), sashModel);
+ }
+
+ /**
+ * @param sashModel
+ * @param panel
+ */
+ private void createPanelOrFolder(PanelTerm panel, SashPanel parent ) {
+ if(panel instanceof AbstractSash) {
+ parent.getChildren().add(DiFactory.eINSTANCE.createSashPanel());
+ }
+ else if (panel instanceof Folder) {
+ parent.getChildren().add(DiFactory.eINSTANCE.createTabFolder());
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.VSash, org.eclipse.papyrus.infra.core.sashwindows.di.SashPanel)
+ *
+ * @param sash
+ * @param sashModel
+ */
+ public void visit(VSash sashQuery, SashPanel sashModel) {
+ // sash orientation
+ sashModel.setDirection(SWT.VERTICAL);
+ // Create children of the sash
+ createPanelOrFolder(sashQuery.getLeftup(), sashModel);
+ createPanelOrFolder(sashQuery.getRightdown(), sashModel);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.Page, org.eclipse.papyrus.infra.core.sashwindows.di.PageRef)
+ *
+ * @param page
+ * @param pageModel
+ */
+ public void visit(Page page, PageRef pageModel) {
+
+
+ if(page.getIdentifier() != null) {
+ pageModel.setPageIdentifier(page.getIdentifier());
+ }
+ else if(page.getName() != null) {
+ pageModel.setPageIdentifier(page.getName());
+ }
+ else {
+ pageModel.setPageIdentifier(new Object());
+ }
+
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/DiContentProviderBaseVisitor.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/DiContentProviderBaseVisitor.java
new file mode 100644
index 00000000000..c81ee1818fd
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/DiContentProviderBaseVisitor.java
@@ -0,0 +1,327 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.internal;
+
+import java.util.Iterator;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Folder;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.HSash;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IPagesModelVisitor;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.NoMatchException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModel;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.VSash;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.WindowTerm;
+import org.eclipse.papyrus.infra.core.sashwindows.di.AbstractPanel;
+import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef;
+import org.eclipse.papyrus.infra.core.sashwindows.di.SashModel;
+import org.eclipse.papyrus.infra.core.sashwindows.di.SashPanel;
+import org.eclipse.papyrus.infra.core.sashwindows.di.TabFolder;
+import org.eclipse.papyrus.infra.core.sashwindows.di.Window;
+import org.eclipse.swt.SWT;
+
+/**
+ * A base implementation of {@link IPagesModelVisitor} to visit conjointly SashPagesModel and
+ * {@link DiContentProvider}.
+ *
+ * This implementation separate the navigation part (walk(term, contentProviderModel)) and
+ * the visit part (visit(term, contentProviderModel)). It implements the navigation part.
+ * <br>
+ * The visit part should be implemented by subclasses.
+ *
+ *
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class DiContentProviderBaseVisitor implements IPagesModelVisitor<Object> {
+
+ /**
+ * @return the isVisitingParentFirst
+ */
+ public boolean isVisitingParentFirst() {
+ return true;
+ }
+
+ /**
+ * Visit the model.
+ * The second argument should be a SashModel, or one of its container (ex: DiContentProvider).
+ *
+ * @param pagesModel
+ * @param diPagesModel
+ * @throws PagesModelException
+ */
+ public void walk(SashPagesModel pagesModel, Object diPagesModel) throws PagesModelException {
+ // Check associated model type
+ // It can be of different type: DiContentProvider or SashModel
+ //
+ SashModel sashModel = null;
+ if( diPagesModel instanceof SashModel) {
+ sashModel = (SashModel)diPagesModel;
+ }
+ else if(diPagesModel instanceof DiContentProvider) {
+ sashModel = ((DiContentProvider)diPagesModel).getDiSashModel();
+ }
+ else {
+ throw new NoMatchException( "ContentProvider type ("+ diPagesModel.getClass().getName()+ ") does not match to SashModel or one of its container" );
+ }
+
+
+ if( isVisitingParentFirst() ) {
+ visit(pagesModel, sashModel);
+ }
+ // visit children
+ for( WindowTerm windowTerm : pagesModel.getWindows() ) {
+ // Only one window
+ Window windowModel = sashModel.getWindows().get(0);
+ windowTerm.getPanel().accept(this, windowModel);
+ }
+ if( ! isVisitingParentFirst() ) {
+ visit(pagesModel, sashModel);
+ }
+ }
+
+ /**
+ * Walk the WindowTerm and its child.
+ * @param windowTerm
+ * @param windowModel
+ * @throws PagesModelException
+ */
+ public void walk(WindowTerm windowTerm, Object windowModel) throws PagesModelException {
+ // Check associated model type
+ if(! (windowModel instanceof Window) ) {
+ throw new NoMatchException( "ContentProvider type ("+ windowModel.getClass().getName()+ ") does not match to Window" );
+ }
+
+ Window window = (Window)windowModel;
+
+ if( isVisitingParentFirst() ) {
+ visit(windowTerm, window);
+ }
+ // visit children
+ for( AbstractPanel panel : window.getChildren())
+ windowTerm.getPanel().accept(this, panel);
+
+ if( ! isVisitingParentFirst() ) {
+ visit(windowTerm, window);
+ }
+ }
+
+ /**
+ * Walk folder and its children.
+ *
+ * @param folder
+ * @param folderModel
+ * @throws PagesModelException
+ */
+ public void walk(Folder folder, Object model) throws PagesModelException {
+ // Check associated model type
+ if(! (model instanceof TabFolder) ) {
+ throw new NoMatchException( this.toString()
+ + "\n" + folder
+ + "\n - Model object type does not match to FolderQueryPart."
+ + " Expected TabFolder, found '" + model.getClass().getSimpleName() + "'."
+ + " (" + folder.getName() +")" );
+ }
+ TabFolder folderModel = (TabFolder)model;
+
+ // Visit this
+ if( isVisitingParentFirst() ) {
+ visit(folder, folderModel);
+ }
+
+ // visit children
+ Iterator<PageRef> pageRefs = folderModel.getChildren().iterator();
+ Iterator<Page> pageQueries = folder.getPages().iterator();
+ while (pageRefs.hasNext() && pageQueries.hasNext() ) {
+ PageRef pageRef = pageRefs.next();
+ Page query = pageQueries.next();
+
+ query.accept(this, pageRef);
+ }
+ if (pageRefs.hasNext()) {
+ // some page left
+ throw new NoMatchException( "Folder matching - "
+ + this.toString()
+ +" folder model have more pages than folder query. ("+folder.getName()+")" );
+ } else if (pageQueries.hasNext() ) {
+ // some queries left
+ throw new NoMatchException( "Folder matching - "
+ + this.toString()
+ +" folder query have more page than folder model. ("+folder.getName()+")" );
+ }
+ // Visit this
+ if( ! isVisitingParentFirst() ) {
+ visit(folder, folderModel);
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IPagesModelVisitor#walk(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.HSash, java.lang.Object)
+ *
+ * @param sash
+ * @param sashModel
+ * @throws PagesModelException
+ */
+ public void walk(HSash sash, Object model) throws PagesModelException {
+ // Check associated model type
+ if(! (model instanceof SashPanel) ) {
+ throw new NoMatchException( this.toString() + " - Model object type does not match to SashPanel (found "
+ + model.getClass()
+ + " )");
+ }
+
+ SashPanel sashModel = (SashPanel)model;
+
+// // Check orientation
+// if( sashModel.getDirection() != SWT.HORIZONTAL) {
+// throw new NoMatchException( this.toString() + " - SashOrientation does not match 'HORIZONTAL'" );
+// }
+ // Visit this
+ if( isVisitingParentFirst() ) {
+ visit(sash, sashModel);
+ }
+
+ // Visit children
+ sash.getLeftup().accept(this, sashModel.getChildren().get(0));
+ sash.getRightdown().accept(this, sashModel.getChildren().get(1));
+
+ if( !isVisitingParentFirst() ) {
+ visit(sash, sashModel);
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IPagesModelVisitor#walk(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.VSash, java.lang.Object)
+ *
+ * @param sash
+ * @param sashModel
+ * @throws PagesModelException
+ */
+ public void walk(VSash sash, Object model) throws PagesModelException {
+ // Check associated model type
+ if(! (model instanceof SashPanel) ) {
+ throw new NoMatchException( this.toString() + " - Model object type does not match to SashPanel (found "
+ + model.getClass()
+ + " )");
+ }
+
+ SashPanel sashModel = (SashPanel)model;
+
+// // Check orientation
+// if( sashModel.getDirection() != SWT.VERTICAL) {
+// throw new NoMatchException( this.toString() + " - SashOrientation does not match 'VERTICAL'" );
+// }
+ // Visit this
+ if( isVisitingParentFirst() ) {
+ visit(sash, sashModel);
+ }
+
+ // Visit children
+ sash.getLeftup().accept(this, sashModel.getChildren().get(0));
+ sash.getRightdown().accept(this, sashModel.getChildren().get(1));
+
+ if( !isVisitingParentFirst() ) {
+ visit(sash, sashModel);
+ }
+ }
+
+ /**
+ * Walk the page. Simply call the corresponding {@link DiContentProviderBaseVisitor#visit(Page, IPageModel)} method.
+ * @param page
+ * @param pageModel
+ * @throws PagesModelException
+ */
+ public void walk(Page page, Object model) throws PagesModelException {
+ // Check associated model type
+ if(! (model instanceof PageRef) ) {
+ throw new NoMatchException( this.toString() + " - Model object type does not match to PageRef" );
+ }
+ PageRef pageModel = (PageRef)model;
+ visit(page, pageModel);
+ }
+
+
+ /**
+ * Visit the model. Actually, there is no counterpart for {@link SashPagesModel} in {@link SimpleContentProvider}.
+ *
+ * @param windowTerm
+ * @param windowModel
+ * @throws PagesModelException
+ */
+ public void visit(SashPagesModel pagesModel, SashModel windowModel) throws PagesModelException {
+
+ }
+
+ /**
+ * Visit the corresponding node.
+ * To be implemented by subclass.
+ *
+ *
+ * @param windowTerm
+ * @param windowModel
+ */
+ public void visit(WindowTerm windowTerm, Window windowModel) throws PagesModelException {
+ // To be implemented by subclass.
+ }
+
+ /**
+ * Visit the corresponding node.
+ * To be implemented by subclass.
+ *
+ * @param folder
+ * @param folderModel
+ */
+ public void visit(Folder folder, TabFolder folderModel) throws PagesModelException{
+
+ }
+
+ /**
+ * Visit the corresponding node.
+ * To be implemented by subclass.
+ *
+ * @param sashQuery
+ * @param sashModel
+ */
+ public void visit(HSash sashQuery, SashPanel sashModel) throws PagesModelException {
+
+ }
+
+ /**
+ * Visit the corresponding node.
+ * To be implemented by subclass.
+ *
+ *
+ * @param sash
+ * @param sashModel
+ */
+ public void visit(VSash sashQuery, SashPanel sashModel) throws PagesModelException{
+ }
+
+ /**
+ * Visit the corresponding node.
+ * To be implemented by subclass.
+ *
+ *
+ * @param page
+ * @param pageModel
+ */
+ public void visit(Page page, PageRef pageModel) throws PagesModelException {
+
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/DiContentProviderFacade.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/DiContentProviderFacade.java
new file mode 100644
index 00000000000..82677ca3e8d
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/DiContentProviderFacade.java
@@ -0,0 +1,440 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IAbstractPanelModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProviderFacade;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IPageModelFactory;
+import org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.QueryException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.BadNameException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.NotFoundException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PanelTerm;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.WindowTerm;
+import org.eclipse.papyrus.infra.core.sashwindows.di.AbstractPanel;
+import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef;
+import org.eclipse.papyrus.infra.core.sashwindows.di.SashModel;
+import org.eclipse.papyrus.infra.core.sashwindows.di.TabFolder;
+import org.eclipse.papyrus.infra.core.sashwindows.di.Window;
+import org.eclipse.papyrus.infra.core.sashwindows.di.util.DiUtils;
+
+/**
+ * Class providing a facade to test the {@link SimpleSashWindowsContentProvider} class.
+ * <br>
+ * This facade own a {@link DiContentProvider} and provides methods to manipulate it with
+ * the help of names. Each element in the {@link DiContentProvider} can be identified
+ * by a name (String). Then, the facade provide methods similar to {@link ISashWindowsContentProvider}, but using
+ * names rather than {@link IAbstractPanelModel} and {@link ITabFolderModel}.
+ * <br>
+ * The facade maintains a mapping between the names and the {@link ISashWindowsContentProvider} models.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class DiContentProviderFacade implements ISashWindowsContentProviderFacade {
+
+ /**
+ * The internal content provider this facade is for.
+ */
+ protected DiContentProvider contentProvider;
+
+ /**
+ * Mapping between names provided in the expressions and internal implementations of the {@link SashModel}.
+ * This mapping is maintained when elements are added or removed.
+ *
+ */
+ protected Map<String, Object> namesMapping;
+ /**
+ * Cache used to maintain wrappers used to wrap internal SashModel object
+ * to {@link ISashWindowsContentProvider} model.
+ */
+ protected Map<String, Object> contentProviderWrapperCache = new HashMap<String, Object>();
+
+ /**
+ * Constructor.
+ * Create a default internal {@link SimpleSashWindowsContentProvider};
+ * @param modelMngr
+ */
+ public DiContentProviderFacade() {
+ IPageModelFactory pageModelFactory = new FakePageModelFactory();
+ SashModel diSashModel = DiUtils.createDefaultSashModel();
+ this.contentProvider = new DiContentProvider(diSashModel, pageModelFactory);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param modelMngr
+ */
+ public DiContentProviderFacade(DiContentProvider contentProvider) {
+ this.contentProvider = contentProvider;
+ }
+
+ /**
+ * @return the contentProvider
+ */
+ public ISashWindowsContentProvider getIContentProvider() {
+ return contentProvider;
+ }
+
+
+ /**
+ * Reset the namesMapping context accordingly to the provided expr.
+ * A side effect is that the internal structure is checked against the expr.
+ * <br>
+ * Reseting the names context allows to remove or add names to the context.
+ * It is used to add names of newly created elements (created with addPage() or createFolder() )
+
+ * @param expr
+ * @throws PagesModelException
+ */
+ public void resetNamesContext(IModelExp expr) throws PagesModelException {
+ namesMapping = queryModel(expr);
+ }
+
+ /**
+ * Check if the internal {@link ISashWindowsContentProvider} is conformed to the specified expression.
+ * @param expr
+ * @throws QueryException
+ */
+ public void assertConform(IModelExp expr) throws PagesModelException {
+
+ Object first;
+ if( expr instanceof WindowTerm) {
+ first = getFirstWindowModel();
+ }
+ else if( expr instanceof PanelTerm) {
+ first = getFirstPanelModel();
+ }
+ else {
+ throw new PagesModelException("Don't know how to get the model associated to the first term of the expression (" + expr.toString() + ")");
+ }
+
+ CheckVisitor visitor = new CheckVisitor();
+ expr.accept(visitor, first);
+ }
+
+ /**
+ * Create an internal model conform to the specified expression.
+ * Any previous model is disguarded.
+ *
+ * This method should only be called once on a {@link SimpleSashWindowsContentProvider}.
+ * <br>
+ * If an expr term have a name, this name is kept in the facade and can be used later in methods like move, delete, ...
+ *
+ * @param expr Expression denoting the configuration to create. Must be one of (Folder, HSash, VSash)
+ * @throws QueryException
+ *
+ * TODO Ensure that the method can only be called once. For example,
+ * let this class extends {@link SimpleSashWindowsContentProvider}, and the constructor
+ * call this method.
+ */
+ public void createModel(IModelExp expr) throws PagesModelException {
+
+ Window first ;
+ if( expr instanceof PanelTerm) {
+ first = getFirstWindowModel();
+ }
+ else {
+ throw new PagesModelException("Don't know how to get the model associated to the first term of the expression (" + expr.toString() + ")");
+ }
+
+ // Create a surrounding WindowTerm
+ WindowTerm windowTerm = new WindowTerm((PanelTerm)expr);
+
+ CreateModelVisitor visitor = new CreateModelVisitor();
+ windowTerm.accept(visitor, first);
+
+ // Fill mapping
+ namesMapping = queryModel(expr);
+ }
+
+ /**
+ * Get element in the model.
+ * Each model element whose corresponding model query part as a name is added to the result map.
+ * The element is then accessible with the name set in the query part.
+ *
+ * @param query
+ * @return
+ * @throws QueryException
+ */
+ public Map<String, Object> queryModel(IModelExp query) throws PagesModelException {
+
+ Object first;
+ if( query instanceof WindowTerm) {
+ first = getFirstWindowModel();
+ }
+ else if( query instanceof PanelTerm) {
+ first = getFirstPanelModel();
+ }
+ else {
+ throw new PagesModelException("Don't know how to get the model associated to the first term of the expression (" + query.toString() + ")");
+ }
+
+ QueryVisitor visitor = new QueryVisitor();
+ query.accept(visitor, first);
+
+ return visitor.getResult();
+ }
+
+ /**
+ * Get the model of the first the first window (in actual implementation their is only one window).
+ * @return
+ */
+ private Window getFirstWindowModel() {
+ // Silly method to get the RootModel
+ return contentProvider.getDiSashModel().getWindows().get(0);
+ }
+
+ /**
+ * Get the panel of the first window (in actual implementation their is only one window).
+ * @return
+ */
+ private AbstractPanel getFirstPanelModel() {
+ //
+ return contentProvider.getDiSashModel().getWindows().get(0).getPanel();
+ }
+
+ /**
+ * Add a page to the model
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProviderFacade#addPage(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page, java.lang.String, int)
+ *
+ * @param page
+ * @param folderName
+ * @param index
+ * @throws PagesModelException
+ */
+ public void /*IPageModel*/ addPage(Page page, String folderName, int index) throws PagesModelException {
+ // Get the folder
+ TabFolderModel folderModel = getITabFolderModel( folderName );
+
+ Object pageRawModel = createPageRawModel(page);
+
+ contentProvider.addPage(folderModel, index, pageRawModel);
+
+ // Create the IContentProvider model, and return it.
+// IPageModel pageModel = folderModel.createChildSashModel(???);
+// return pageModel;
+ }
+
+ /**
+ * Add a page to the model
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProviderFacade#addPage(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page, java.lang.String, int)
+ *
+ * @param page
+ * @param folderName
+ * @throws PagesModelException
+ */
+ public void /*IPageModel*/ addPage(Page page, String folderName) throws PagesModelException {
+ // Get the folder
+ TabFolderModel folderModel = getITabFolderModel( folderName );
+
+
+ Object pageRawModel = createPageRawModel(page);
+
+ contentProvider.addPage(folderModel, pageRawModel);
+
+ // Create the IContentProvider model, and return it.
+ // createChildSashModel() require a PageRef
+// IPageModel pageModel = folderModel.createChildSashModel(???);
+// return pageModel;
+ }
+
+ /**
+ * Get the pageModel used as identifier of a page.
+ * In the {@link DiContentProvider} implementation, the pageModel
+ * is an Object.
+ * In this implementation, we simply return the identifier of the name found in the
+ * declared page. If none is set, return a new Object.
+ *
+ * @param page
+ * @return an identifier for te page
+ */
+ static public Object createPageRawModel( Page page ) {
+
+ if(page.getIdentifier() != null) {
+ return page.getIdentifier();
+ }
+ else if(page.getName() != null) {
+ return page.getName();
+ }
+ else {
+ return new Object();
+ }
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProviderFacade#movePage(java.lang.String, int, int)
+ *
+ * @param folderName
+ * @param oldIndex
+ * @param newIndex
+ * @throws NotFoundException
+ */
+ public void movePage(String folderName, int oldIndex, int newIndex) throws NotFoundException {
+ // Get the folder
+ ITabFolderModel folderModel = getITabFolderModel( folderName );
+
+ contentProvider.movePage(folderModel, oldIndex, newIndex);
+ }
+
+ public void movePage(String srcFolderName, int sourceIndex, String targetFolderName, int targetIndex) throws NotFoundException {
+ // Get the folders
+ ITabFolderModel srcFolderModel = getITabFolderModel( srcFolderName );
+ ITabFolderModel targetFolderModel = getITabFolderModel( targetFolderName );
+
+ contentProvider.movePage(srcFolderModel, sourceIndex, targetFolderModel, targetIndex);
+ }
+
+ public void removePage(String pageName) throws NotFoundException {
+ IPageModel pageModel = getIPageModel(pageName);
+
+ contentProvider.removePage(pageModel);
+
+ }
+
+ public void removePage(String folderName, int tabIndex) throws NotFoundException {
+ // Get the folder
+ ITabFolderModel folderModel = getITabFolderModel( folderName );
+
+ contentProvider.removePage(folderModel, tabIndex);
+ // TODO remove page name from context
+ }
+
+ public void createFolder(String tabFolderName, int tabIndex, String targetFolderName, int side) throws PagesModelException {
+ // Get the folders
+ ITabFolderModel srcFolderModel = getITabFolderModel( tabFolderName );
+ TabFolderModel targetFolderModel = getITabFolderModel( targetFolderName );
+
+ contentProvider.createFolder(srcFolderModel, tabIndex, targetFolderModel, side);
+
+ }
+
+ /**
+ * Add an element in namesMapping. Throw an exception if the name already exist or if the name is not correct.
+ *
+ * @param name
+ * @param element
+ * @throws BadNameException
+ */
+ protected void putNameMapping( String name, Object element) throws BadNameException {
+
+ if( name == null || name.length() == 0 ) {
+ throw new BadNameException("Name '" + name + "' is not valid.");
+ }
+
+ if(namesMapping.containsKey(name)) {
+ throw new BadNameException("Name '" + name + "' already exist in the context. Can't add it (but element is created).");
+ }
+
+ }
+ /**
+ * Get the {@link ITabFolderModel} associated to the name.
+ * In this implementation, each internal model is wrapped with its {@link ISashWindowsContentProvider} counterpart.
+ * For a folder, the wrapper is a {@link TabFolderModel}.
+ * The wrapper are cached in an associated cache.
+ * @param folderName
+ * @return
+ * @throws NotFoundException
+ */
+ public TabFolderModel getITabFolderModel(String folderName) throws NotFoundException {
+
+ // Check if the wrapper is already in the cache
+ Object cachedModel = contentProviderWrapperCache.get(folderName);
+ if(cachedModel != null) {
+ // Check the type
+ if( ! (cachedModel instanceof TabFolderModel) )
+ throw new NotFoundException("An element named '" + folderName + "' is found but it is not of the expected type (ITabFolderModel). " );
+
+ // Found
+ return (TabFolderModel)cachedModel;
+ }
+ // Not found, create it
+ // Create a new wrapper
+ // First, get the corresponding internal representation
+ Object rawModel = namesMapping.get(folderName);
+ if( rawModel == null )
+ throw new NotFoundException("Folder named '" + folderName + "' not found in the context of the expression.");
+ if( ! (rawModel instanceof TabFolder) )
+ throw new NotFoundException("An element named '" + folderName + "' is found but it is not of the expected type (TabFolder). " );
+
+ // Create a wrapper and put it in the cache
+ TabFolderModel tabFolderModel = (TabFolderModel)contentProvider.createChildSashModel(rawModel);
+ contentProviderWrapperCache.put(folderName, tabFolderModel);
+
+ // result
+ return tabFolderModel;
+
+ }
+
+ /**
+ * Get the {@link IPageModel} associated to the name.
+ * In this implementation, this is the internal element.
+ * @param pageName
+ * @return
+ * @throws NotFoundException
+ */
+ public IPageModel getIPageModel(String pageName) throws NotFoundException {
+
+ // Check if the wrapper is already in the cache
+ Object cachedModel = contentProviderWrapperCache.get(pageName);
+ if(cachedModel != null) {
+ // Check the type
+ if( ! (cachedModel instanceof IPageModel) )
+ throw new NotFoundException("An element named '" + pageName + "' is found but it is not of the expected type (IPageModel). " );
+
+ // Found
+ return (IPageModel)cachedModel;
+ }
+ // Not found, create it
+ // Create a new wrapper
+ // First, get the corresponding internal representation
+ Object rawModel = namesMapping.get(pageName);
+ if( rawModel == null )
+ throw new NotFoundException("Page named '" + pageName + "' not found in the context of the expression.");
+ if( ! (rawModel instanceof PageRef) )
+ throw new NotFoundException("An element named '" + pageName + "' is found but it is not of the expected type (PageRef). " );
+
+ // Create a wrapper and put it in the cache
+ IPageModel pageModel = (IPageModel)contentProvider.createChildSashModel(rawModel);
+ contentProviderWrapperCache.put(pageName, pageModel);
+
+ // result
+ return pageModel;
+
+ }
+
+ /**
+ * Return the associated maps of (names, internal representation).
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProviderFacade#getNamesToInternalMap()
+ *
+ * @return
+ */
+ public Map<String, Object> getNamesToInternalMap() {
+ return namesMapping;
+ }
+
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/DiContentProviderFacadeTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/DiContentProviderFacadeTest.java
new file mode 100644
index 00000000000..66d662675a5
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/DiContentProviderFacadeTest.java
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.internal;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.AbstractSashWindowContentProviderFacadeTest;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProviderFacade;
+
+
+/**
+ * @author dumoulin
+ *
+ */
+public class DiContentProviderFacadeTest extends AbstractSashWindowContentProviderFacadeTest {
+
+ /**
+ * Constructor.
+ *
+ */
+ public DiContentProviderFacadeTest() {
+ super();
+ }
+
+ /**
+ * Return the concrete implementation under test.
+ * @return
+ */
+ @Override
+ public ISashWindowsContentProviderFacade createISashWindowsContentProviderFacade() {
+ return new DiContentProviderFacade();
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/QueryVisitor.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/QueryVisitor.java
new file mode 100644
index 00000000000..0d3b5006ade
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.di.tests/test/org/eclipse/papyrus/infra/core/sasheditor/di/contentprovider/internal/QueryVisitor.java
@@ -0,0 +1,138 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryTerm;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Folder;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.HSash;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelObject;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IPagesModelVisitor;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.VSash;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.WindowTerm;
+import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef;
+import org.eclipse.papyrus.infra.core.sashwindows.di.SashPanel;
+import org.eclipse.papyrus.infra.core.sashwindows.di.TabFolder;
+import org.eclipse.papyrus.infra.core.sashwindows.di.Window;
+
+/**
+ * Visitor used to collect element in the model.
+ * Each element in the model associated with a{@link IQueryTerm} whose name is set is collectted.
+ * The collected element is then accessible from the result map, using the name set in the IQueryTerm.
+ *
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class QueryVisitor extends DiContentProviderBaseVisitor implements IPagesModelVisitor<Object> {
+
+ /**
+ * The result map.
+ */
+ protected Map<String, Object>result = new HashMap<String, Object>();
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.WindowTerm, org.eclipse.papyrus.infra.core.sashwindows.di.Window)
+ *
+ * @param windowTerm
+ * @param windowModel
+ */
+ @Override
+ public void visit(WindowTerm windowTerm, Window windowModel) {
+ collect( windowTerm, windowModel);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.Folder, org.eclipse.papyrus.infra.core.sashwindows.di.TabFolder)
+ *
+ * @param folder
+ * @param folderModel
+ */
+ @Override
+ public void visit(Folder folder, TabFolder folderModel) {
+ collect(folder, folderModel);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.HSash, org.eclipse.papyrus.infra.core.sashwindows.di.SashPanel)
+ *
+ * @param sash
+ * @param sashModel
+ */
+ @Override
+ public void visit(HSash sash, SashPanel sashModel) {
+ collect(sash, sashModel);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.VSash, org.eclipse.papyrus.infra.core.sashwindows.di.SashPanel)
+ *
+ * @param sash
+ * @param sashModel
+ */
+ @Override
+ public void visit(VSash sash, SashPanel sashModel) {
+ collect(sash, sashModel);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#visit(org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.Page, org.eclipse.papyrus.infra.core.sashwindows.di.PageRef)
+ *
+ * @param page
+ * @param pageModel
+ */
+ @Override
+ public void visit(Page page, PageRef pageModel) {
+ collect(page, pageModel);
+
+ }
+
+ /**
+ * Add the element associated to the query to the result, if the query has a name.
+ * @param iQueryTerm
+ * @param element
+ */
+ protected void collect( IModelObject iQueryTerm, Object element) {
+
+ if( iQueryTerm.getName() == null) {
+ return;
+ }
+
+ result.put(iQueryTerm.getName(), element);
+ }
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.IQueryVisitor#isVisitingParentFirst()
+ *
+ * @return
+ */
+ @Override
+ public boolean isVisitingParentFirst() {
+ return true;
+ }
+
+ /**
+ * @return the result
+ */
+ public Map<String, Object> getResult() {
+ return result;
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/META-INF/MANIFEST.MF
index 7685fdd6551..7e2f4eb509e 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/META-INF/MANIFEST.MF
@@ -14,4 +14,5 @@ Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.papyrus.infra.core.sasheditor.tests;s
ingleton:=true
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-
+Export-Package: org.eclipse.papyrus.infra.core.sasheditor.contentprovider,
+ org.eclipse.papyrus.infra.core.sasheditor.pagesmodel
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/AbstractSashWindowContentProviderFacadeTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/AbstractSashWindowContentProviderFacadeTest.java
new file mode 100644
index 00000000000..4f75964c4e1
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/AbstractSashWindowContentProviderFacadeTest.java
@@ -0,0 +1,272 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.contentprovider;
+
+import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.folder;
+import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.page;
+import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.vSash;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
+import org.eclipse.swt.SWT;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Test suite for {@link ISashWindowsContentProviderFacade} implementations.
+ * Each implementation of {@link ISashWindowsContentProviderFacade} can be tested with this suite.
+ * This class provides the tests common to all implementation.
+ *
+ * An implementation can be tested by subclassing this class, and by implementing the
+ * getIcontentProviderFacade method. This later should return the implementation of
+ * {@link ISashWindowsContentProviderFacade} to test.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public abstract class AbstractSashWindowContentProviderFacadeTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Create an instance of the {@link ISashWindowsContentProviderFacade} to test.
+ *
+ * @return an instance of {@link ISashWindowsContentProviderFacade};
+ */
+ abstract public ISashWindowsContentProviderFacade createISashWindowsContentProviderFacade();
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContentProviderUtils#assertConform(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp)}.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testAssertConform() throws PagesModelException {
+ ISashWindowsContentProviderFacade helper = createISashWindowsContentProviderFacade();
+
+ assertNotNull("helper created", helper);
+ // Create a query
+ IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
+ // Try to create the model
+ helper.createModel(expr);
+
+ // Try to check model
+ helper.assertConform(expr);
+
+ }
+
+ /**
+ * Test assertConform with expr starting with a folder.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testAssertConformExprStartngWithFolder() throws PagesModelException {
+ ISashWindowsContentProviderFacade helper = createISashWindowsContentProviderFacade();
+
+ assertNotNull("helper created", helper);
+ // Create a query
+ IModelExp expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
+ page("p5"), page("p6"), page("p7"), page("p8"));
+ // Try to create the model
+ helper.createModel(expr);
+
+
+ // Check if conform
+ helper.assertConform(expr);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContentProviderUtils#createModel(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp)}.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testCreateModel() throws PagesModelException {
+ ISashWindowsContentProviderFacade helper = createISashWindowsContentProviderFacade();
+
+ assertNotNull("helper created", helper);
+ // Create a query
+ IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
+ // Try to create the model
+ helper.createModel(expr);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContentProviderUtils#queryModel(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp)}.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testQueryModel() throws PagesModelException {
+ ISashWindowsContentProviderFacade helper = createISashWindowsContentProviderFacade();
+
+ assertNotNull("helper created", helper);
+ // Create a query
+ IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
+ // Try to create the model
+ helper.createModel(expr);
+
+ // Query model
+ Map<String, Object> res = helper.queryModel(expr);
+ assertNotNull("found f1", res.get("f1"));
+// assertTrue("right type", res.get("f1") instanceof TabFolderModel );
+
+ assertNotNull("found f2", res.get("f2"));
+// assertTrue("right type", res.get("f2") instanceof TabFolderModel );
+
+ assertNotNull("found p2", res.get("p2"));
+// assertTrue("right type", res.get("p2") instanceof IPageModel );
+ }
+
+ /**
+ * Test folder creation.
+ * Use the pagemodels utilities {@link SimpleSashWindowContentProviderUtils}.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testCreateFolder() throws PagesModelException {
+
+
+ ISashWindowsContentProviderFacade contentFacade = createISashWindowsContentProviderFacade();
+
+ assertNotNull("helper created", contentFacade);
+ // Create a query
+// IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
+ IModelExp expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
+ page("p5"), page("p6"), page("p7"), page("p8"));
+ // Try to create the model
+ contentFacade.createModel(expr);
+
+ // Create another folder
+ contentFacade.createFolder("f1", 0, "f1", SWT.UP);
+ // Check the content configuration
+ IModelExp conf1Expr = vSash(
+ folder( "f2", page("p1") ),
+ folder( "f1", page("p2"), page("p3"), page("p4"),
+ page("p5"), page("p6"), page("p7"), page("p8") )
+ );
+ // Check if conform
+ contentFacade.assertConform(conf1Expr);
+
+ // Check resetContext
+ contentFacade.resetNamesContext(conf1Expr);
+
+ assertNotNull("new name found", contentFacade.getNamesToInternalMap().get("f2"));
+ }
+
+
+ /**
+ * Test page creation.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testCreateNewPage() throws PagesModelException {
+ ISashWindowsContentProviderFacade helper = createISashWindowsContentProviderFacade();
+
+ assertNotNull("helper created", helper);
+ // Create a query
+ IModelExp expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
+ page("p5"), page("p6"), page("p7"), page("p8"));
+ // Try to create the model
+ helper.createModel(expr);
+
+ // Create a new page
+ helper.addPage(page("newPage"), "f1");
+
+ // Check the content configuration
+ IModelExp conf1Expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
+ page("p5"), page("p6"), page("p7"), page("p8"), page("newPage"));
+
+ // Check if conform
+ helper.assertConform(conf1Expr);
+
+ }
+
+ /**
+ * Test page deletion.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testClosePage() throws PagesModelException {
+ ISashWindowsContentProviderFacade helper = createISashWindowsContentProviderFacade();
+
+ assertNotNull("helper created", helper);
+ // Create a query
+ IModelExp expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
+ page("p5"), page("p6"), page("p7"), page("p8"));
+ // Try to create the model
+ helper.createModel(expr);
+
+ // Create a new page
+ helper.removePage( "p8");
+
+ // Check the content configuration
+ IModelExp conf1Expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
+ page("p5"), page("p6"), page("p7"));
+
+ // Check if conform
+ helper.assertConform(conf1Expr);
+
+ }
+
+ /**
+ * Test folder deletion.
+ * Use the pagemodels utilities {@link SimpleSashWindowContentProviderUtils}.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testDeleteFolder() throws PagesModelException {
+
+
+ ISashWindowsContentProviderFacade contentFacade = createISashWindowsContentProviderFacade();
+
+ assertNotNull("helper created", contentFacade);
+ // Create a query
+// IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
+ IModelExp expr = vSash(
+ folder( "f1", page("p2"), page("p3"), page("p4") ),
+ folder( "f2", page("p1") )
+ );
+ // Try to create the model
+ contentFacade.createModel(expr);
+
+ // Create the folder.
+ // This is done by closing the last page
+ contentFacade.removePage("p1");
+
+ // Check the content configuration
+ IModelExp conf1Expr = folder( "f1", page("p2"), page("p3"), page("p4"));
+ // Check if conform
+ contentFacade.assertConform(conf1Expr);
+
+ }
+
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/ISashWindowsContentProviderFacade.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/ISashWindowsContentProviderFacade.java
new file mode 100644
index 00000000000..46c057284e4
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/ISashWindowsContentProviderFacade.java
@@ -0,0 +1,220 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.contentprovider;
+
+import java.util.Map;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IAbstractPanelModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.NotFoundException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
+
+
+/**
+ * Interface providing a common facade to test the {@link ISashWindowsContentProvider} implementations.
+ * <br>
+ * This facade provides methods to manipulate {@link ISashWindowsContentProvider} with
+ * the help of names. Each element in the {@link SimpleSashWindowsContentProvider} can be identified
+ * by a name (String). Then, the facade provide methods similar to {@link ISashWindowsContentProvider}, but using
+ * names rather than {@link IAbstractPanelModel} and {@link ITabFolderModel}.
+ * <br>
+ * The facade maintains a mapping between the names and the {@link ISashWindowsContentProvider} models.
+
+ * <br>
+ * Implementations of this class
+ * allow to create an internal model according to a provided {@link IModelExp}. It is also possible
+ * to check if the internal model is conform to the {@link IModelExp}.
+ *
+ * <br>
+ * There is several {@link ISashWindowsContentProvider} implementations, but a lot of tests are commons to
+ * all the implementations. The interface allows to develop common tests regardless of the real implementation.
+ * <br>
+ * One develop common tests using {@link ISashWindowsContentProvider} and {@link ISashWindowsContentProviderFacade}. Then,
+ * this test is subclassed and the appropriate implementations are specified in the subclasses.
+ *
+ *
+ * @author cedric dumoulin
+ *
+ */
+public interface ISashWindowsContentProviderFacade {
+
+ /**
+ * Create an internal model conform to the specified query.
+ * Any previous model is disguarded.
+ *
+ * Some implementations do not allow to call this method more than once. In this case,
+ * the implementation should throw an Exception.
+ *
+ * @param query Should be a subtype PanelTerm (Folder, HSash, VSash)
+ * @throws QueryException
+ *
+ */
+ public abstract void createModel(IModelExp query) throws PagesModelException;
+
+ /**
+ * Check if the internal model is conformed to the specified query.
+ * @param query
+ * @throws QueryException
+ */
+ public abstract void assertConform(IModelExp query) throws PagesModelException;
+
+ /**
+ * Get element in the model.
+ * Each model element whose corresponding model query part as a name is added to the result map.
+ * The element is then accessible with the name set in the query part.
+ *
+ * @param query
+ * @return
+ * @throws QueryException
+ */
+ public abstract Map<String, Object> queryModel(IModelExp query) throws PagesModelException;
+
+ /**
+ * Get the {@link ISashWindowsContentProvider} associated to this utility class.
+ * @return
+ */
+ public ISashWindowsContentProvider getIContentProvider();
+
+ /**
+ * Add a page at the specified index of TabFolder.
+ * <br>
+ * This method is not used by the {@link ISashWindowsContainer}.
+ *
+ * @param page
+ * An object identifying the page to add. The object could be anything. It will be
+ * passed to the {@link ITabFolderModel#createChildSashModel(Object)} method.
+ * @param index
+ * Index to where the tabItem should be added.
+ * @throws NotFoundException
+ */
+ public void /*IPageModel*/ addPage(Page page, String folderName, int index) throws PagesModelException;
+
+ /**
+ * Add a page at the end of TabFolder.
+ * <br>
+ * This method is not used by the {@link ISashWindowsContainer}.
+ *
+ * @param page
+ * An object identifying the page to add. The object could be anything. It will be
+ * passed to the {@link ITabFolderModel#createChildSashModel(Object)} method.
+ * @return
+ * @throws NotFoundException
+ */
+ public void /*IPageModel*/ addPage(Page page, String folderName) throws PagesModelException;
+
+ /**
+ * Move a tab inside the specified folder.
+ *
+ * @param model
+ * @param oldIndex
+ * @param newIndex
+ * @throws NotFoundException
+ */
+ public void movePage(String folderName, int oldIndex, int newIndex) throws NotFoundException;
+
+ /**
+ * Move a tab from folder to folder.
+ *
+ * @param model
+ * @param sourceIndex
+ * @param model2
+ * @param targetIndex
+ */
+ public void movePage(String srcFolderName, int sourceIndex, String targetFolderName, int targetIndex) throws NotFoundException;
+
+ /**
+ * Remove the page from the sashes window.
+ * Look for the folder containing the page.
+ *
+ * @param page
+ * The Object identifying the page. This is the object used in {@link #addPage(Object)}.
+ */
+ public void removePage(String pageName) throws NotFoundException;
+
+ /**
+ * Remove the specified page from the parentFolder.
+ *
+ * @param tabItem
+ */
+ public void removePage(String folderName, int tabIndex) throws NotFoundException;
+
+ /**
+ * Ask the model to move the specified tab to the specified side of the specified targetFolder.
+ * This method
+ * is called by the the SashTileContainer when the user
+ * have drag a tab in a correct place. The SashTileContainer has not change is presentation yet. This
+ * will be done when the corresponding event will occur.
+ *
+ * @param tabFolder
+ * The folder containing the tab to move
+ * @param tabIndex
+ * The index of the tab to move
+ * @param targetFolder
+ * The folder to which the side refer to
+ * @param side
+ * Side where node should be inserted : SWT.LEFT, SWT.RIGHT, SWT.TOP, SWT.DOWN.
+ * @throws PagesModelException
+ */
+ public void createFolder(String tabFolder, int tabIndex, String targetFolder, int side) throws PagesModelException;
+
+ /**
+ *
+ * Reset the namesMapping context accordingly to the provided expr.
+ * The names mapping is used to lookup Model element by there name.
+ * The name mapping should be reset when the internal structure has change,
+ * and especially when an element is added.
+ * <br>
+ * Reseting the names context allows to remove or add names to the context.
+ * It is used to add names of newly created elements (created with addPage() or createFolder() )
+
+ * @param expr
+ * @throws PagesModelException
+ */
+ public void resetNamesContext(IModelExp expr) throws PagesModelException;
+
+ /**
+ * A facade is associated to a names and internal models map that is internally used
+ * to lookup elements.
+ * This maps is reset with {@link #resetNamesContext(IModelExp)}
+ * @return The names to internal maps.
+ */
+ public Map<String, Object> getNamesToInternalMap();
+
+ /**
+ * Ask the model to move the specified tab to the specified side of the specified targetFolder.
+ * This method
+ * is called by the the SashTileContainer when the user
+ * have drag a tab in a correct place. The SashTileContainer has not change is presentation yet. This
+ * will be done when the corresponding event will occur.
+ *
+ * @param tabFolder
+ * The folder containing the tab to move
+ * @param tabIndex
+ * The index of the tab to move
+ * @param targetFolder
+ * The folder to which the side refer to
+ * @param side
+ * Side where node should be inserted : SWT.LEFT, SWT.RIGHT, SWT.TOP, SWT.DOWN.
+ * @throws PagesModelException
+ */
+// public void createFolder(String newFolderName, String tabFolder, int tabIndex, String targetFolder, int side) throws PagesModelException;
+
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/CreateModelInSimpleContentProviderVisitor.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/CreateModelInSimpleContentProviderVisitor.java
index 577ac4ef644..1987f1b0322 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/CreateModelInSimpleContentProviderVisitor.java
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/CreateModelInSimpleContentProviderVisitor.java
@@ -122,7 +122,9 @@ public class CreateModelInSimpleContentProviderVisitor extends SimpleContentProv
return new SashPanelModel(parent, null, null, SWT.VERTICAL);
}
else /*if (panel instanceof Folder)*/ {
- return new TabFolderModel(contentProvider);
+ TabFolderModel folder = new TabFolderModel(contentProvider);
+ folder.setParent(parent);
+ return folder;
}
}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleContentProviderBaseVisitor.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleContentProviderBaseVisitor.java
index 44c9f77204b..d84f0399f0d 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleContentProviderBaseVisitor.java
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleContentProviderBaseVisitor.java
@@ -120,7 +120,11 @@ public class SimpleContentProviderBaseVisitor implements IPagesModelVisitor<Obje
public void walk(Folder folder, Object model) throws PagesModelException {
// Check associated model type
if(! (model instanceof TabFolderModel) ) {
- throw new NoMatchException( this.toString() + " - Model object type does not match to FolderQueryPart" );
+ throw new NoMatchException( this.toString()
+ + "\n" + folder
+ + "\n - Model object type does not match to FolderQueryPart."
+ + " Expected TabFolderModel, found '" + model.getClass().getSimpleName() + "'."
+ + " (" + folder.getName() +")" );
}
TabFolderModel folderModel = (TabFolderModel)model;
@@ -142,14 +146,13 @@ public class SimpleContentProviderBaseVisitor implements IPagesModelVisitor<Obje
// some page left
throw new NoMatchException( "Folder matching - "
+ this.toString()
- +" folder model have more pages than folder query." );
+ +" folder model have more pages than folder query. ("+folder.getName()+")" );
} else if (pageQueries.hasNext() ) {
// some queries left
throw new NoMatchException( "Folder matching - "
+ this.toString()
- +" folder query have more page than folder model." );
+ +" folder query have more page than folder model. ("+folder.getName()+")" );
}
-
// Visit this
if( ! isVisitingParentFirst() ) {
visit(folder, folderModel);
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContainerTestFacade.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContainerTestFacade.java
new file mode 100644
index 00000000000..5f6fcdf1fcf
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContainerTestFacade.java
@@ -0,0 +1,452 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple;
+
+import java.util.Map;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IAbstractPanelModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.MessagePartModel;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.SashWindowsContainer;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.BadNameException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.NotFoundException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PanelTerm;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.WindowTerm;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProviderFacade;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Class providing a facade to test the {@link SashWindowsContainer} class.
+ * <br>
+ * This facade own a {@link SimpleSashWindowsContentProvider}, a {@link SashWindowsContainer} and
+ * provides methods to manipulate it with the help of names.
+ * <br>
+ * The facade allows to create pages and folders in the sashContainer, thru the ContentProvider.
+ * It also allows to check the resulting structure inside the SashContainer.
+ * The facade can also be used to create a particular configuration of the SashContainer, and apply
+ * tests on this configuration.
+ * <br>
+ * Each element in the {@link SimpleSashWindowsContentProvider} can be identified
+ * by a name (String). Then, the facade provide methods similar to {@link ISashWindowsContentProvider}, but using
+ * names rather than {@link IAbstractPanelModel} and {@link ITabFolderModel}.
+ * <br>
+ * The facade maintains a mapping between the names and the {@link ISashWindowsContentProvider} models.
+ * <br>
+ * The
+ * @author cedric dumoulin
+ *
+ */
+public class SimpleSashWindowContainerTestFacade implements ISashWindowsContentProviderFacade {
+
+ /**
+ * The internal content provider this facade is for.
+ */
+ protected SimpleSashWindowsContentProvider contentProvider;
+
+ /**
+ * The associated SashContainer
+ */
+ protected SashWindowsContainer sashContainer;
+ /**
+ * Display used to create windows.
+ */
+ protected Display display;
+
+
+ /**
+ * Mapping between names provided in the expressions and internal implementations of the {@link SimpleSashWindowsContentProvider}.
+ * This mapping is maintained when elements are added or removed.
+ *
+ */
+ protected Map<String, Object> namesMapping;
+
+ /**
+ * Constructor.
+ * Create a default internal {@link SimpleSashWindowsContentProvider};
+ * @param modelMngr
+ */
+ public SimpleSashWindowContainerTestFacade() {
+ this.contentProvider = new SimpleSashWindowsContentProvider();
+ initDisplay();
+ sashContainer = createSashWindowsContainer(contentProvider);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param modelMngr
+ */
+ public SimpleSashWindowContainerTestFacade(SimpleSashWindowsContentProvider contentProvider) {
+ this.contentProvider = contentProvider;
+ initDisplay();
+ sashContainer = createSashWindowsContainer(contentProvider);
+ }
+
+ /**
+ * Init the display object.
+ */
+ protected void initDisplay() {
+ display = Display.getCurrent();
+ if(display == null) {
+ display = new Display();
+ }
+ }
+ /**
+ * Create a {@link SashWindowsContainer} to test. Initialize it with provided {@link ISashWindowsContentProvider}.
+ *
+ * @param contentProvider
+ * @return
+ */
+ protected SashWindowsContainer createSashWindowsContainer(ISashWindowsContentProvider contentProvider) {
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+
+ //
+ //new ShellEditor(shell);
+ SashWindowsContainer sashWindowContainer = new SashWindowsContainer();
+
+ sashWindowContainer.setContentProvider(contentProvider);
+
+ sashWindowContainer.createPartControl(shell);
+ // shell.open();
+ return sashWindowContainer;
+ }
+
+
+ /**
+ * @return the sashContainer
+ */
+ public SashWindowsContainer getSashContainer() {
+ return sashContainer;
+ }
+
+ /**
+ * @return the ISashWindowsContainer interface
+ */
+ public ISashWindowsContainer getISashWindowsContainer() {
+ return sashContainer;
+ }
+
+ /**
+ * @return the contentProvider
+ */
+ public ISashWindowsContentProvider getIContentProvider() {
+ return contentProvider;
+ }
+
+ /**
+ * Dispose the facade
+ */
+ public void dispose() {
+ sashContainer.dispose();
+ // display.dispose();
+ if(namesMapping != null) {
+ namesMapping.clear();
+ }
+ contentProvider = null;
+ sashContainer = null;
+ }
+
+ /**
+ * Reset the namesMapping context accordingly to the provided expr.
+ * A side effect is that the internal structure is checked against the expr.
+ * <br>
+ * Reseting the names context allows to remove or add names to the context.
+ * It is used to add names of newly created elements (created with addPage() or createFolder() )
+
+ * @param expr
+ * @throws PagesModelException
+ */
+ public void resetNamesContext(IModelExp expr) throws PagesModelException {
+ namesMapping = queryModel(expr);
+ }
+
+ /**
+ * Check if the internal {@link ISashWindowsContentProvider} is conformed to the specified expression.
+ * @param expr
+ * @throws QueryException
+ */
+ public void assertConform(IModelExp expr) throws PagesModelException {
+
+ Object first;
+ if( expr instanceof WindowTerm) {
+ first = getFirstWindowModel();
+ }
+ else if( expr instanceof PanelTerm) {
+ first = getFirstPanelModel();
+ }
+ else {
+ throw new PagesModelException("Don't know how to get the model associated to the first term of the expression (" + expr.toString() + ")");
+ }
+
+ CheckVisitor visitor = new CheckVisitor();
+ expr.accept(visitor, first);
+ }
+
+ /**
+ * Create an internal model conform to the specified expression.
+ * Any previous model is disguarded.
+ *
+ * This method should only be called once on a {@link SimpleSashWindowsContentProvider}.
+ * <br>
+ * If an expr term have a name, this name is kept in the facade and can be used later in methods like move, delete, ...
+ *
+ * @param expr Expression denoting the configuration to create. Must be one of (Folder, HSash, VSash)
+ * @throws QueryException
+ *
+ * TODO Ensure that the method can only be called once. For example,
+ * let this class extends {@link SimpleSashWindowsContentProvider}, and the constructor
+ * call this method.
+ */
+ public void createModel(IModelExp expr) throws PagesModelException {
+
+ Object first ;
+ if( expr instanceof PanelTerm) {
+ first = getFirstWindowModel();
+ }
+ else {
+ throw new PagesModelException("Don't know how to get the model associated to the first term of the expression (" + expr.toString() + ")");
+ }
+
+ // Create a surrounding WindowTerm
+ WindowTerm windowTerm = new WindowTerm((PanelTerm)expr);
+
+ CreateModelInSimpleContentProviderVisitor visitor = new CreateModelInSimpleContentProviderVisitor(contentProvider);
+ windowTerm.accept(visitor, first);
+
+ // Fill mapping
+ namesMapping = queryModel(expr);
+ }
+
+ /**
+ * Get element in the model.
+ * Each model element whose corresponding model query part as a name is added to the result map.
+ * The element is then accessible with the name set in the query part.
+ *
+ * @param query
+ * @return
+ * @throws QueryException
+ */
+ public Map<String, Object> queryModel(IModelExp query) throws PagesModelException {
+
+ Object first;
+ if( query instanceof WindowTerm) {
+ first = getFirstWindowModel();
+ }
+ else if( query instanceof PanelTerm) {
+ first = getFirstPanelModel();
+ }
+ else {
+ throw new PagesModelException("Don't know how to get the model associated to the first term of the expression (" + query.toString() + ")");
+ }
+
+ QueryVisitor visitor = new QueryVisitor();
+ query.accept(visitor, first);
+
+ return visitor.getResult();
+ }
+
+ /**
+ * Get the model of the first the first window (in actual implementation their is only one window).
+ * @return
+ */
+ private RootModel getFirstWindowModel() {
+ // Silly method to get the RootModel
+ return (RootModel)((AbstractPanelModel)contentProvider.getRootModel()).getParent();
+ }
+
+ /**
+ * Get the panel of the first window (in actual implementation their is only one window).
+ * @return
+ */
+ private AbstractPanelModel getFirstPanelModel() {
+ // In this implementation, the root is always of type AbstractPanelModel
+ return (AbstractPanelModel)contentProvider.getRootModel();
+ }
+
+ /**
+ * Add a page to the model
+ * @see org.eclipse.papyrus.infra.core.sasheditor.tests.common.ISashWindowsContentProviderFacade#addPage(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page, java.lang.String, int)
+ *
+ * @param page
+ * @param folderName
+ * @param index
+ * @throws PagesModelException
+ */
+ public void /*IPageModel*/ addPage(Page page, String folderName, int index) throws PagesModelException {
+ // Get the folder
+ TabFolderModel folderModel = getITabFolderModel( folderName );
+
+ IPageModel pageModel = createPageModel(page);
+
+ contentProvider.addPage(folderModel, index, pageModel);
+
+// return pageModel;
+ }
+
+ /**
+ * Add a page to the model
+ * @see org.eclipse.papyrus.infra.core.sasheditor.tests.common.ISashWindowsContentProviderFacade#addPage(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page, java.lang.String, int)
+ *
+ * @param page
+ * @param folderName
+ * @throws PagesModelException
+ */
+ public void /*IPageModel*/ addPage(Page page, String folderName) throws PagesModelException {
+ // Get the folder
+ TabFolderModel folderModel = getITabFolderModel( folderName );
+
+ IPageModel pageModel = createPageModel(page);
+
+ contentProvider.addPage(folderModel, pageModel);
+
+// return pageModel;
+ }
+
+ /**
+ * Create a {@link IPageModel} for the specified {@link Page}.
+ * @param page
+ * @return
+ */
+ static public IPageModel createPageModel( Page page ) {
+ return new MessagePartModel( page.getName(), page.getName() );
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.tests.common.ISashWindowsContentProviderFacade#movePage(java.lang.String, int, int)
+ *
+ * @param folderName
+ * @param oldIndex
+ * @param newIndex
+ * @throws NotFoundException
+ */
+ public void movePage(String folderName, int oldIndex, int newIndex) throws NotFoundException {
+ // Get the folder
+ ITabFolderModel folderModel = getITabFolderModel( folderName );
+
+ contentProvider.movePage(folderModel, oldIndex, newIndex);
+ }
+
+ public void movePage(String srcFolderName, int sourceIndex, String targetFolderName, int targetIndex) throws NotFoundException {
+ // Get the folders
+ ITabFolderModel srcFolderModel = getITabFolderModel( srcFolderName );
+ ITabFolderModel targetFolderModel = getITabFolderModel( targetFolderName );
+
+ contentProvider.movePage(srcFolderModel, sourceIndex, targetFolderModel, targetIndex);
+ }
+
+ public void removePage(String pageName) throws NotFoundException {
+ IPageModel pageModel = getIPageModel(pageName);
+
+ contentProvider.removePage(pageModel);
+
+ }
+
+ public void removePage(String folderName, int tabIndex) throws NotFoundException {
+ // Get the folder
+ ITabFolderModel folderModel = getITabFolderModel( folderName );
+
+ contentProvider.removePage(folderModel, tabIndex);
+ // TODO remove page name from context
+ }
+
+ public void createFolder(String tabFolderName, int tabIndex, String targetFolderName, int side) throws PagesModelException {
+ // Get the folders
+ ITabFolderModel srcFolderModel = getITabFolderModel( tabFolderName );
+ TabFolderModel targetFolderModel = getITabFolderModel( targetFolderName );
+
+ contentProvider.createFolder(srcFolderModel, tabIndex, targetFolderModel, side);
+
+ }
+
+ /**
+ * Add an element in namesMapping. Throw an exception if the name already exist or if the name is not correct.
+ *
+ * @param name
+ * @param element
+ * @throws BadNameException
+ */
+ protected void putNameMapping( String name, Object element) throws BadNameException {
+
+ if( name == null || name.length() == 0 ) {
+ throw new BadNameException("Name '" + name + "' is not valid.");
+ }
+
+ if(namesMapping.containsKey(name)) {
+ throw new BadNameException("Name '" + name + "' already exist in the context. Can't add it (but element is created).");
+ }
+
+ }
+ /**
+ * Get the {@link ITabFolderModel} associated to the name.
+ * In this implementation, this is the internal folder.
+ * @param folderName
+ * @return
+ * @throws NotFoundException
+ */
+ public TabFolderModel getITabFolderModel(String folderName) throws NotFoundException {
+
+
+ Object res = namesMapping.get(folderName);
+ if(res == null)
+ throw new NotFoundException("Folder named '" + folderName + "' not found in the context of the expression.");
+
+ if( ! (res instanceof TabFolderModel) )
+ throw new NotFoundException("An element named '" + folderName + "' is found but it is not of the expected type (ITabFolderModel). " );
+
+ return (TabFolderModel)res;
+ }
+
+ /**
+ * Get the {@link IPageModel} associated to the name.
+ * In this implementation, this is the internal element.
+ * @param pageName
+ * @return
+ * @throws NotFoundException
+ */
+ public IPageModel getIPageModel(String pageName) throws NotFoundException {
+
+
+ Object res = namesMapping.get(pageName);
+ if(res == null)
+ throw new NotFoundException("Page named '" + pageName + "' not found in the context of the expression.");
+
+ if( ! (res instanceof IPageModel) )
+ throw new NotFoundException("An element named '" + pageName + "' is found but it is not of the expected type (IPageModel). " );
+
+ return (IPageModel)res;
+ }
+
+ /**
+ * Return the associated maps of (names, internal representation).
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProviderFacade#getNamesToInternalMap()
+ *
+ * @return
+ */
+ public Map<String, Object> getNamesToInternalMap() {
+ return namesMapping;
+ }
+
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContainerTestFacadeCommonTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContainerTestFacadeCommonTest.java
new file mode 100644
index 00000000000..fe1c269c852
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContainerTestFacadeCommonTest.java
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.AbstractSashWindowContentProviderFacadeTest;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProviderFacade;
+
+
+/**
+ * @author dumoulin
+ *
+ */
+public class SimpleSashWindowContainerTestFacadeCommonTest extends AbstractSashWindowContentProviderFacadeTest {
+
+ /**
+ * Constructor.
+ *
+ */
+ public SimpleSashWindowContainerTestFacadeCommonTest() {
+ super();
+ }
+
+ /**
+ * Return the concrete implementation under test.
+ * @return
+ */
+ @Override
+ public ISashWindowsContentProviderFacade createISashWindowsContentProviderFacade() {
+ return new SimpleSashWindowContainerTestFacade();
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContainerTestFacadeTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContainerTestFacadeTest.java
new file mode 100644
index 00000000000..255bdef7a26
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContainerTestFacadeTest.java
@@ -0,0 +1,91 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * @author dumoulin
+ *
+ */
+public class SimpleSashWindowContainerTestFacadeTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContainerTestFacade#SimpleSashWindowContainerTestFacade()}.
+ */
+ @Test
+ public void testSimpleSashWindowContainerTestFacade() {
+ SimpleSashWindowContainerTestFacade facade = new SimpleSashWindowContainerTestFacade();
+
+ assertNotNull("Facade created", facade);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContainerTestFacade#getSashContainer()}.
+ */
+ @Test
+ public void testGetSashContainer() {
+ SimpleSashWindowContainerTestFacade facade = new SimpleSashWindowContainerTestFacade();
+
+ assertNotNull("Facade created", facade);
+ assertNotNull("container created", facade.getISashWindowsContainer() );
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContainerTestFacade#getIContentProvider()}.
+ */
+ @Test
+ public void testGetIContentProvider() {
+ SimpleSashWindowContainerTestFacade facade = new SimpleSashWindowContainerTestFacade();
+
+ assertNotNull("Facade created", facade);
+ assertNotNull("contentProvider created", facade.getIContentProvider() );
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContainerTestFacade#dispose()}.
+ */
+ @Test
+ public void testDispose() {
+ SimpleSashWindowContainerTestFacade facade = new SimpleSashWindowContainerTestFacade();
+
+ assertNotNull("Facade created", facade);
+
+ facade.dispose();
+ assertNull("contentProvider deleted", facade.getIContentProvider() );
+ assertNull("container deleted", facade.getISashWindowsContainer() );
+
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderFacade.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderFacade.java
new file mode 100644
index 00000000000..bfc1716e58d
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderFacade.java
@@ -0,0 +1,368 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple;
+
+import java.util.Map;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IAbstractPanelModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.MessagePartModel;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.BadNameException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.NotFoundException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PanelTerm;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.WindowTerm;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProviderFacade;
+
+/**
+ * Class providing a facade to test the {@link SimpleSashWindowsContentProvider} class.
+ * <br>
+ * This facade own a {@link SimpleSashWindowsContentProvider} and provide methods to manipulate it with
+ * the help of names. Each element in the {@link SimpleSashWindowsContentProvider} can be identified
+ * by a name (String). Then, the facade provide methods similar to {@link ISashWindowsContentProvider}, but using
+ * names rather than {@link IAbstractPanelModel} and {@link ITabFolderModel}.
+ * <br>
+ * The facade maintains a mapping between the names and the {@link ISashWindowsContentProvider} models.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class SimpleSashWindowContentProviderFacade implements ISashWindowsContentProviderFacade {
+
+ /**
+ * The internal content provider this facade is for.
+ */
+ protected SimpleSashWindowsContentProvider contentProvider;
+
+ /**
+ * Mapping between names provided in the expressions and internal implementations of the {@link SimpleSashWindowsContentProvider}.
+ * This mapping is maintained when elements are added or removed.
+ *
+ */
+ protected Map<String, Object> namesMapping;
+
+ /**
+ * Constructor.
+ * Create a default internal {@link SimpleSashWindowsContentProvider};
+ * @param modelMngr
+ */
+ public SimpleSashWindowContentProviderFacade() {
+ this.contentProvider = new SimpleSashWindowsContentProvider();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param modelMngr
+ */
+ public SimpleSashWindowContentProviderFacade(SimpleSashWindowsContentProvider contentProvider) {
+ this.contentProvider = contentProvider;
+ }
+
+ /**
+ * @return the contentProvider
+ */
+ public ISashWindowsContentProvider getIContentProvider() {
+ return contentProvider;
+ }
+
+
+ /**
+ * Reset the namesMapping context accordingly to the provided expr.
+ * A side effect is that the internal structure is checked against the expr.
+ * <br>
+ * Reseting the names context allows to remove or add names to the context.
+ * It is used to add names of newly created elements (created with addPage() or createFolder() )
+
+ * @param expr
+ * @throws PagesModelException
+ */
+ public void resetNamesContext(IModelExp expr) throws PagesModelException {
+ namesMapping = queryModel(expr);
+ }
+
+ /**
+ * Check if the internal {@link ISashWindowsContentProvider} is conformed to the specified expression.
+ * @param expr
+ * @throws QueryException
+ */
+ public void assertConform(IModelExp expr) throws PagesModelException {
+
+ Object first;
+ if( expr instanceof WindowTerm) {
+ first = getFirstWindowModel();
+ }
+ else if( expr instanceof PanelTerm) {
+ first = getFirstPanelModel();
+ }
+ else {
+ throw new PagesModelException("Don't know how to get the model associated to the first term of the expression (" + expr.toString() + ")");
+ }
+
+ CheckVisitor visitor = new CheckVisitor();
+ expr.accept(visitor, first);
+ }
+
+ /**
+ * Create an internal model conform to the specified expression.
+ * Any previous model is disguarded.
+ *
+ * This method should only be called once on a {@link SimpleSashWindowsContentProvider}.
+ * <br>
+ * If an expr term have a name, this name is kept in the facade and can be used later in methods like move, delete, ...
+ *
+ * @param expr Expression denoting the configuration to create. Must be one of (Folder, HSash, VSash)
+ * @throws QueryException
+ *
+ * TODO Ensure that the method can only be called once. For example,
+ * let this class extends {@link SimpleSashWindowsContentProvider}, and the constructor
+ * call this method.
+ */
+ public void createModel(IModelExp expr) throws PagesModelException {
+
+ Object first ;
+ if( expr instanceof PanelTerm) {
+ first = getFirstWindowModel();
+ }
+ else {
+ throw new PagesModelException("Don't know how to get the model associated to the first term of the expression (" + expr.toString() + ")");
+ }
+
+ // Create a surrounding WindowTerm
+ WindowTerm windowTerm = new WindowTerm((PanelTerm)expr);
+
+ CreateModelInSimpleContentProviderVisitor visitor = new CreateModelInSimpleContentProviderVisitor(contentProvider);
+ windowTerm.accept(visitor, first);
+
+ // Fill mapping
+ namesMapping = queryModel(expr);
+ }
+
+ /**
+ * Get element in the model.
+ * Each model element whose corresponding model query part as a name is added to the result map.
+ * The element is then accessible with the name set in the query part.
+ *
+ * @param query
+ * @return
+ * @throws QueryException
+ */
+ public Map<String, Object> queryModel(IModelExp query) throws PagesModelException {
+
+ Object first;
+ if( query instanceof WindowTerm) {
+ first = getFirstWindowModel();
+ }
+ else if( query instanceof PanelTerm) {
+ first = getFirstPanelModel();
+ }
+ else {
+ throw new PagesModelException("Don't know how to get the model associated to the first term of the expression (" + query.toString() + ")");
+ }
+
+ QueryVisitor visitor = new QueryVisitor();
+ query.accept(visitor, first);
+
+ return visitor.getResult();
+ }
+
+ /**
+ * Get the model of the first the first window (in actual implementation their is only one window).
+ * @return
+ */
+ private RootModel getFirstWindowModel() {
+ // Silly method to get the RootModel
+ return (RootModel)((AbstractPanelModel)contentProvider.getRootModel()).getParent();
+ }
+
+ /**
+ * Get the panel of the first window (in actual implementation their is only one window).
+ * @return
+ */
+ private AbstractPanelModel getFirstPanelModel() {
+ // In this implementation, the root is always of type AbstractPanelModel
+ return (AbstractPanelModel)contentProvider.getRootModel();
+ }
+
+ /**
+ * Add a page to the model
+ * @see org.eclipse.papyrus.infra.core.sasheditor.tests.common.ISashWindowsContentProviderFacade#addPage(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page, java.lang.String, int)
+ *
+ * @param page
+ * @param folderName
+ * @param index
+ * @throws PagesModelException
+ */
+ public void /*IPageModel*/ addPage(Page page, String folderName, int index) throws PagesModelException {
+ // Get the folder
+ TabFolderModel folderModel = getITabFolderModel( folderName );
+
+ IPageModel pageModel = createPageModel(page);
+
+ contentProvider.addPage(folderModel, index, pageModel);
+
+// return pageModel;
+ }
+
+ /**
+ * Add a page to the model
+ * @see org.eclipse.papyrus.infra.core.sasheditor.tests.common.ISashWindowsContentProviderFacade#addPage(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.Page, java.lang.String, int)
+ *
+ * @param page
+ * @param folderName
+ * @throws PagesModelException
+ */
+ public void /*IPageModel*/ addPage(Page page, String folderName) throws PagesModelException {
+ // Get the folder
+ TabFolderModel folderModel = getITabFolderModel( folderName );
+
+ IPageModel pageModel = createPageModel(page);
+
+ contentProvider.addPage(folderModel, pageModel);
+
+// return pageModel;
+ }
+
+ /**
+ * Create a {@link IPageModel} for the specified {@link Page}.
+ * @param page
+ * @return
+ */
+ static public IPageModel createPageModel( Page page ) {
+ return new MessagePartModel( page.getName(), page.getName() );
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.tests.common.ISashWindowsContentProviderFacade#movePage(java.lang.String, int, int)
+ *
+ * @param folderName
+ * @param oldIndex
+ * @param newIndex
+ * @throws NotFoundException
+ */
+ public void movePage(String folderName, int oldIndex, int newIndex) throws NotFoundException {
+ // Get the folder
+ ITabFolderModel folderModel = getITabFolderModel( folderName );
+
+ contentProvider.movePage(folderModel, oldIndex, newIndex);
+ }
+
+ public void movePage(String srcFolderName, int sourceIndex, String targetFolderName, int targetIndex) throws NotFoundException {
+ // Get the folders
+ ITabFolderModel srcFolderModel = getITabFolderModel( srcFolderName );
+ ITabFolderModel targetFolderModel = getITabFolderModel( targetFolderName );
+
+ contentProvider.movePage(srcFolderModel, sourceIndex, targetFolderModel, targetIndex);
+ }
+
+ public void removePage(String pageName) throws NotFoundException {
+ IPageModel pageModel = getIPageModel(pageName);
+
+ contentProvider.removePage(pageModel);
+
+ }
+
+ public void removePage(String folderName, int tabIndex) throws NotFoundException {
+ // Get the folder
+ ITabFolderModel folderModel = getITabFolderModel( folderName );
+
+ contentProvider.removePage(folderModel, tabIndex);
+ // TODO remove page name from context
+ }
+
+ public void createFolder(String tabFolderName, int tabIndex, String targetFolderName, int side) throws PagesModelException {
+ // Get the folders
+ ITabFolderModel srcFolderModel = getITabFolderModel( tabFolderName );
+ TabFolderModel targetFolderModel = getITabFolderModel( targetFolderName );
+
+ contentProvider.createFolder(srcFolderModel, tabIndex, targetFolderModel, side);
+
+ }
+
+ /**
+ * Add an element in namesMapping. Throw an exception if the name already exist or if the name is not correct.
+ *
+ * @param name
+ * @param element
+ * @throws BadNameException
+ */
+ protected void putNameMapping( String name, Object element) throws BadNameException {
+
+ if( name == null || name.length() == 0 ) {
+ throw new BadNameException("Name '" + name + "' is not valid.");
+ }
+
+ if(namesMapping.containsKey(name)) {
+ throw new BadNameException("Name '" + name + "' already exist in the context. Can't add it (but element is created).");
+ }
+
+ }
+ /**
+ * Get the {@link ITabFolderModel} associated to the name.
+ * In this implementation, this is the internal folder.
+ * @param folderName
+ * @return
+ * @throws NotFoundException
+ */
+ public TabFolderModel getITabFolderModel(String folderName) throws NotFoundException {
+
+
+ Object res = namesMapping.get(folderName);
+ if(res == null)
+ throw new NotFoundException("Folder named '" + folderName + "' not found in the context of the expression.");
+
+ if( ! (res instanceof TabFolderModel) )
+ throw new NotFoundException("An element named '" + folderName + "' is found but it is not of the expected type (ITabFolderModel). " );
+
+ return (TabFolderModel)res;
+ }
+
+ /**
+ * Get the {@link IPageModel} associated to the name.
+ * In this implementation, this is the internal element.
+ * @param pageName
+ * @return
+ * @throws NotFoundException
+ */
+ public IPageModel getIPageModel(String pageName) throws NotFoundException {
+
+
+ Object res = namesMapping.get(pageName);
+ if(res == null)
+ throw new NotFoundException("Page named '" + pageName + "' not found in the context of the expression.");
+
+ if( ! (res instanceof IPageModel) )
+ throw new NotFoundException("An element named '" + pageName + "' is found but it is not of the expected type (IPageModel). " );
+
+ return (IPageModel)res;
+ }
+
+ /**
+ * Return the associated maps of (names, internal representation).
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProviderFacade#getNamesToInternalMap()
+ *
+ * @return
+ */
+ public Map<String, Object> getNamesToInternalMap() {
+ return namesMapping;
+ }
+
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderFacadeTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderFacadeTest.java
new file mode 100644
index 00000000000..f633f705aa4
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderFacadeTest.java
@@ -0,0 +1,151 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple;
+
+import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.folder;
+import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.page;
+import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.vSash;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
+import org.eclipse.swt.SWT;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * @author dumoulin
+ *
+ */
+public class SimpleSashWindowContentProviderFacadeTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContentProviderUtils#assertConform(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp)}.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testAssertConform() throws PagesModelException {
+ SimpleSashWindowContentProviderFacade helper = new SimpleSashWindowContentProviderFacade();
+
+ assertNotNull("helper created", helper);
+ // Create a query
+ IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
+ // Try to create the model
+ helper.createModel(expr);
+
+ // Try to check model
+ helper.assertConform(expr);
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContentProviderUtils#createModel(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp)}.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testCreateModel() throws PagesModelException {
+ SimpleSashWindowContentProviderFacade helper = new SimpleSashWindowContentProviderFacade();
+
+ assertNotNull("helper created", helper);
+ // Create a query
+ IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
+ // Try to create the model
+ helper.createModel(expr);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContentProviderUtils#queryModel(org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp)}.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testQueryModel() throws PagesModelException {
+ SimpleSashWindowContentProviderFacade helper = new SimpleSashWindowContentProviderFacade();
+
+ assertNotNull("helper created", helper);
+ // Create a query
+ IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
+ // Try to create the model
+ helper.createModel(expr);
+
+ // Query model
+ Map<String, Object> res = helper.queryModel(expr);
+ assertNotNull("found f1", res.get("f1"));
+ assertTrue("right type", res.get("f1") instanceof TabFolderModel );
+
+ assertNotNull("found f2", res.get("f2"));
+ assertTrue("right type", res.get("f2") instanceof TabFolderModel );
+
+ assertNotNull("found p2", res.get("p2"));
+ assertTrue("right type", res.get("p2") instanceof IPageModel );
+ }
+
+ /**
+ * Test folder creation.
+ * Use the pagemodels utilities {@link SimpleSashWindowContentProviderUtils}.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testCreateFolder() throws PagesModelException {
+
+
+ SimpleSashWindowContentProviderFacade helper = new SimpleSashWindowContentProviderFacade();
+
+ assertNotNull("helper created", helper);
+ // Create a query
+// IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
+ IModelExp expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
+ page("p5"), page("p6"), page("p7"), page("p8"));
+ // Try to create the model
+ helper.createModel(expr);
+
+ // Create another folder
+ helper.createFolder("f1", 0, "f1", SWT.UP);
+ // Check the content configuration
+ IModelExp conf1Expr = vSash(
+ folder( "f2", page("p1") ),
+ folder( "f1", page("p2"), page("p3"), page("p4"),
+ page("p5"), page("p6"), page("p7"), page("p8") )
+ );
+ // Check if conform
+ helper.assertConform(conf1Expr);
+
+ // Check resetContext
+ helper.resetNamesContext(conf1Expr);
+
+ assertNotNull("new name found", helper.getITabFolderModel("f2"));
+ }
+
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderFacadeTest2.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderFacadeTest2.java
new file mode 100644
index 00000000000..a27b626cd94
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderFacadeTest2.java
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.AbstractSashWindowContentProviderFacadeTest;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProviderFacade;
+
+
+/**
+ * @author dumoulin
+ *
+ */
+public class SimpleSashWindowContentProviderFacadeTest2 extends AbstractSashWindowContentProviderFacadeTest {
+
+ /**
+ * Constructor.
+ *
+ */
+ public SimpleSashWindowContentProviderFacadeTest2() {
+ super();
+ }
+
+ /**
+ * Return the concrete implementation under test.
+ * @return
+ */
+ @Override
+ public ISashWindowsContentProviderFacade createISashWindowsContentProviderFacade() {
+ return new SimpleSashWindowContentProviderFacade();
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderUtils.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderUtils.java
index 8742d3c4071..57e3a539b50 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderUtils.java
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowContentProviderUtils.java
@@ -16,10 +16,12 @@ package org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple;
import java.util.Map;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp;
import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PanelTerm;
import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.WindowTerm;
+import org.eclipse.papyrus.infra.core.sasheditor.tests.utils.ISashWindowsContentProviderTestUtils;
/**
* Class providing some utilities to check the {@link SimpleSashWindowsContentProvider} class.
@@ -30,7 +32,7 @@ import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.WindowTerm;
* @author cedric dumoulin
*
*/
-public class SimpleSashWindowContentProviderUtils {
+public class SimpleSashWindowContentProviderUtils implements ISashWindowsContentProviderTestUtils {
/**
* ContentProvider used .
@@ -39,6 +41,15 @@ public class SimpleSashWindowContentProviderUtils {
/**
* Constructor.
+ * Create a default internal {@link SimpleSashWindowsContentProvider};
+ * @param modelMngr
+ */
+ public SimpleSashWindowContentProviderUtils() {
+ this.contentProvider = new SimpleSashWindowsContentProvider();
+ }
+
+ /**
+ * Constructor.
*
* @param modelMngr
*/
@@ -47,6 +58,15 @@ public class SimpleSashWindowContentProviderUtils {
}
+
+ /**
+ * @return the contentProvider
+ */
+ public ISashWindowsContentProvider getIContentProvider() {
+ return contentProvider;
+ }
+
+
/**
* Check if the sashModel is conformed to the specified query.
* @param query
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowsContentProviderTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowsContentProviderTest.java
index c8f06457f59..dcca76b5f51 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowsContentProviderTest.java
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/contentprovider/simple/SimpleSashWindowsContentProviderTest.java
@@ -13,21 +13,33 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple;
+import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.folder;
+import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.page;
+import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.vSash;
+import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.hSash;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+
import java.util.ArrayList;
import java.util.List;
-
-import junit.framework.TestCase;
+import java.util.Map;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
import org.eclipse.swt.SWT;
import org.junit.Before;
+import org.junit.Test;
/**
- * @author dumoulin
+ * @author cedric dumoulin
*/
-public class SimpleSashWindowsContentProviderTest extends TestCase {
+public class SimpleSashWindowsContentProviderTest {
protected SimpleSashWindowsContentProvider contentProvider;
@@ -35,9 +47,7 @@ public class SimpleSashWindowsContentProviderTest extends TestCase {
* Initialize the tree {@inheritDoc}
*/
@Before
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ public void setUp() throws Exception {
createContentProvider();
}
@@ -53,6 +63,7 @@ public class SimpleSashWindowsContentProviderTest extends TestCase {
* {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider#addPage(org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel)}
* .
*/
+ @Test
public void testAddTabIPageModel() {
IPageModel newModel = new FakePageModel();
contentProvider.addPage(newModel);
@@ -83,6 +94,7 @@ public class SimpleSashWindowsContentProviderTest extends TestCase {
* {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider#createFolder(org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int, org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int)}
* .
*/
+ @Test
public void testCreateFolder() {
// Create pages and add them to the default folder
@@ -137,7 +149,6 @@ public class SimpleSashWindowsContentProviderTest extends TestCase {
contentProvider.createFolder(folder, 0, folder, SWT.LEFT);
ITabFolderModel newFolder5 = contentProvider.getParentFolder(movedTab);
assertFolderCreated(folder, newFolder5, movedTab);
-
}
/**
@@ -145,6 +156,7 @@ public class SimpleSashWindowsContentProviderTest extends TestCase {
* {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider#createFolder(org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int, org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int)}
* .
*/
+ @Test
public void testCreateFolder_ITabFolderModel_int() {
// Create pages and add them to the default folder
@@ -194,6 +206,148 @@ public class SimpleSashWindowsContentProviderTest extends TestCase {
/**
* Test method for
+ * {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider#movePage(org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int, int)}
+ * .
+ */
+ // public void testMoveTabITabFolderModelIntInt() {
+ // fail("Not yet implemented");
+ // }
+
+ /**
+ * Test method for
+ * {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider#movePage(org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int, org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int)}
+ * .
+ */
+ // public void testMoveTabITabFolderModelIntITabFolderModelInt() {
+ // fail("Not yet implemented");
+ // }
+
+ /**
+ * Test folder creation.
+ * Use the pagemodels utilities {@link SimpleSashWindowContentProviderUtils}.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testCreateFolder2() throws PagesModelException {
+
+
+ SimpleSashWindowsContentProvider contentProvider = new SimpleSashWindowsContentProvider();
+ SimpleSashWindowContentProviderUtils helper = new SimpleSashWindowContentProviderUtils(contentProvider);
+
+ assertNotNull("helper created", helper);
+ // Create a query
+// IModelExp expr = vSash( folder( "f1", page("p1")), folder( "f2", page("p2")));
+ IModelExp expr = folder( "f1", page("p1"), page("p2"), page("p3"), page("p4"),
+ page("p5"), page("p6"), page("p7"), page("p8"));
+ // Try to create the model
+ helper.createModel(expr);
+
+ // Query model
+ Map<String, Object> res = helper.queryModel(expr);
+ // Get a folder
+ ITabFolderModel folder = (ITabFolderModel)res.get("f1");
+
+ // Create another folder
+ IPageModel movedTab = (IPageModel)res.get("p1");
+ assertEquals("moved tab is the first in tab", movedTab, folder.getChildren().get(0));
+ contentProvider.createFolder(folder, 0, folder, SWT.UP);
+ // Find created folder
+ ITabFolderModel newFolder2 = contentProvider.getParentFolder(movedTab);
+ assertFolderCreated(folder, newFolder2, movedTab);
+
+ // Check the content configuration
+ IModelExp conf1Expr = vSash(
+ folder( "f2", page("p1") ),
+ folder( "f1", page("p2"), page("p3"), page("p4"),
+ page("p5"), page("p6"), page("p7"), page("p8") )
+ );
+ // Check if conform
+ helper.assertConform(conf1Expr);
+
+ Map<String, Object> conf1 = helper.queryModel(conf1Expr);
+ assertEquals("right page moved", res.get("p1"), conf1.get("p1"));
+
+
+
+ movedTab = (IPageModel)res.get("p2");
+ assertEquals("moved tab is the first in tab", movedTab, folder.getChildren().get(0));
+ contentProvider.createFolder(folder, 0, newFolder2, SWT.UP);
+ ITabFolderModel newFolder3 = contentProvider.getParentFolder(movedTab);
+ assertFolderCreated(folder, newFolder3, movedTab);
+
+ // Check the content configuration
+ IModelExp conf2Expr = vSash(
+ vSash(
+ folder( "f3", page("p2") ),
+ folder( "f2", page("p1") )
+ ),
+ folder( "f1", page("p3"), page("p4"),
+ page("p5"), page("p6"), page("p7"), page("p8") )
+ );
+ // Check if conform
+ helper.assertConform(conf2Expr);
+
+ Map<String, Object> conf2 = helper.queryModel(conf2Expr);
+ assertEquals("right page moved", res.get("p2"), conf2.get("p2"));
+
+
+ // Next move
+ movedTab = (IPageModel)res.get("p3");
+ assertEquals("moved tab is the first in tab", movedTab, folder.getChildren().get(0));
+ contentProvider.createFolder(folder, 0, newFolder2, SWT.DOWN);
+ ITabFolderModel newFolder4 = contentProvider.getParentFolder(movedTab);
+ assertFolderCreated(folder, newFolder4, movedTab);
+
+ // Check the content configuration
+ IModelExp conf3Expr = vSash(
+ vSash(
+ folder( "f3", page("p2") ),
+ vSash(
+ folder( "f2", page("p1") ),
+ folder( "f4", page("p3") )
+ )
+ ),
+ folder( "f1", page("p4"),
+ page("p5"), page("p6"), page("p7"), page("p8") )
+ );
+ // Check if conform
+ helper.assertConform(conf3Expr);
+
+ Map<String, Object> conf3 = helper.queryModel(conf3Expr);
+ assertEquals("right page moved", res.get("p3"), conf3.get("p3"));
+
+ // Move next folder
+ movedTab = (IPageModel)res.get("p4");
+ assertEquals("moved tab is the first in tab", movedTab, folder.getChildren().get(0));
+ contentProvider.createFolder(folder, 0, folder, SWT.LEFT);
+ ITabFolderModel newFolder5 = contentProvider.getParentFolder(movedTab);
+ assertFolderCreated(folder, newFolder5, movedTab);
+
+ // Check the content configuration
+ IModelExp conf4Expr = vSash(
+ vSash(
+ folder( "f3", page("p2") ),
+ vSash(
+ folder( "f2", page("p1") ),
+ folder( "f4", page("p3") )
+ )
+ ),
+ hSash(
+ folder( "f5", page("p4") ),
+ folder( "f1", page("p5"), page("p6"), page("p7"), page("p8") )
+ )
+ );
+ // Check if conform
+ helper.assertConform(conf4Expr);
+
+ Map<String, Object> conf4 = helper.queryModel(conf4Expr);
+ assertEquals("right page moved", res.get("p4"), conf4.get("p4"));
+
+
+ }
+
+ /**
+ * Test method for
* {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider#removePage(org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel)}
* .
*/
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/FakeFolderLifeCycleEventsListener.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/FakeFolderLifeCycleEventsListener.java
new file mode 100644
index 00000000000..5dbff211240
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/FakeFolderLifeCycleEventsListener.java
@@ -0,0 +1,143 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * A fake listener implementation for testing purpose.
+ * @author cedric dumoulin
+ *
+ */
+public class FakeFolderLifeCycleEventsListener implements ITabFolderPartLifeCycleEventsListener {
+
+ public static final String FOLDER_CREATED = "folderCreated";
+
+ public static final String FOLDER_DISPOSED = "folderDisposed";
+
+
+ /** */
+ public int eventCount = 0;
+
+ /** */
+ public List<String> traces;
+
+ /** */
+ public List<TabFolderPart> events;
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public FakeFolderLifeCycleEventsListener() {
+ traces = new ArrayList<String>();
+ events = new ArrayList<TabFolderPart>();
+ }
+
+
+ /**
+ * @return the eventCount
+ */
+ public int getEventCount() {
+ return eventCount;
+ }
+
+
+ /**
+ * @return the trace
+ */
+ public List<String> getTraces() {
+ return traces;
+ }
+
+ /**
+ * @return the trace
+ */
+ public String getTrace(int index) {
+ return traces.get(index);
+ }
+
+ /**
+ * @return the trace
+ */
+ public List<TabFolderPart> getEvents() {
+ return events;
+ }
+
+ /**
+ * @return the trace
+ */
+ public TabFolderPart getEvent(int index) {
+ return events.get(index);
+ }
+
+ /**
+ *
+ */
+ public void resetChangeCount() {
+ eventCount = 0;
+ }
+
+ /**
+ *
+ */
+ public void resetTraces() {
+ traces.clear();
+ events.clear();
+ }
+
+ /* ************************** */
+ /* Methods */
+ /* ************************** */
+
+
+ public void folderCreated(TabFolderPart folder) {
+ traces.add(FOLDER_CREATED);
+ events.add(folder);
+ eventCount++;
+ }
+
+
+ public void folderDisposed(TabFolderPart folder) {
+ traces.add(FOLDER_DISPOSED);
+ events.add(folder);
+ eventCount++;
+ }
+
+ @Override
+ public String toString() {
+
+ StringBuffer buf = new StringBuffer();
+ buf.append("{");
+ for( int i=0; i<events.size(); i++) {
+ buf.append("[")
+ .append(traces.get(i) )
+ .append("-")
+ .append( events.get(i).getClass().getSimpleName())
+ .append("]");
+
+ if(i<events.size()) {
+ buf.append(",");
+ }
+ }
+ buf.append("}");
+
+ return buf.toString();
+ }
+}
+ \ No newline at end of file
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/IModelExp.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/FakeTabFolderPart.java
index 83654ea81f8..f1f823a595e 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/IModelExp.java
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/FakeTabFolderPart.java
@@ -12,17 +12,25 @@
*
*****************************************************************************/
-package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
+package org.eclipse.papyrus.infra.core.sasheditor.internal;
+
/**
- * A Model Expression represent an expression used to describe a PagesModel.
- * Term implementing this interface can be used as starting point of expression.
- * <br>
- * Following classses are expressions: {@link PanelTerm}, {@link WindowTerm}, {@link PagesModel}.
+ * A fake {@link TabFolderPart} for testing purpose.
+ * Do not use in a SashContainer.
+ * This class allows to instanciate a {@link TabFolderPart}.
*
* @author cedric dumoulin
- * TODO Rename to IModelExp
+ *
*/
-public interface IModelExp extends IModelObject {
+public class FakeTabFolderPart extends TabFolderPart {
+ /**
+ * Create a fake {@link TabFolderPart}
+ * Constructor.
+ *
+ */
+ public FakeTabFolderPart() {
+ super( new RootPart(null), null, null);
+ }
}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/FolderLifeCycleEventsThrownFromContainerTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/FolderLifeCycleEventsThrownFromContainerTest.java
new file mode 100644
index 00000000000..1cb877459b3
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/FolderLifeCycleEventsThrownFromContainerTest.java
@@ -0,0 +1,163 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.sasheditor.internal;
+
+import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.folder;
+import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.page;
+import static org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.SashPagesModelFactory.vSash;
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContainerTestFacade;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
+import org.eclipse.swt.SWT;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Test if the {@link SashWindowsContainer} send the events of a folder lifecycle.
+ * Test if the folder lifecycle events are correctly thrown by the {@link SashWindowsContainer} when
+ * folder are added/removed, ...
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class FolderLifeCycleEventsThrownFromContainerTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+
+ /**
+ * Lookup a page by its raw model.
+ * @param container
+ * @param rawModel
+ * @return
+ */
+ protected IPage lookupTabFolderPart(SashWindowsContainer container, Object rawModel) {
+
+ LookupModelPageVisitor visitor = new LookupModelPageVisitor(rawModel);
+ container.visit(visitor);
+ return visitor.result();
+ }
+
+
+ /**
+ * Test if the FOLDER_ADDED event is sent when a folder is added.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testFolderAddedEvent() throws PagesModelException {
+
+ SimpleSashWindowContainerTestFacade containerFacade = new SimpleSashWindowContainerTestFacade();
+ // get container and contentProvider
+ ISashWindowsContentProvider contentProvider = containerFacade.getIContentProvider();
+ SashWindowsContainer container = containerFacade.getSashContainer();
+
+ // Create listener and attach it
+ FakeFolderLifeCycleEventsListener listener = new FakeFolderLifeCycleEventsListener();
+ container.getFolderLifeCycleEventProvider().addListener(listener);
+
+ // init the container
+ IModelExp expr = vSash(
+ folder( "f1", page("p2"), page("p3"), page("p4") ),
+ folder( "f2", page("p1") )
+ );
+ containerFacade.createModel(expr);
+
+ // Do refresh. This fire events
+ container.refreshTabs();
+ // Check events
+ assertEquals("event fired. listener=" + listener.toString(), 3, listener.getEventCount());
+ int i=0;
+ assertEquals("right event", FakeFolderLifeCycleEventsListener.FOLDER_CREATED, listener.getTraces().get(i));
+ assertEquals("right object", containerFacade.getNamesToInternalMap().get("f1"), listener.getEvents().get(i++).getRawModel());
+ assertEquals("right event", FakeFolderLifeCycleEventsListener.FOLDER_CREATED, listener.getTraces().get(i));
+ assertEquals("right object", containerFacade.getNamesToInternalMap().get("f2"), listener.getEvents().get(i++).getRawModel());
+ // There is 3 events. The last one is the disposal of the folder that exist before the refresh, and replaced by
+ // two other folders.
+ assertEquals("right event", FakeFolderLifeCycleEventsListener.FOLDER_DISPOSED, listener.getTraces().get(i));
+
+
+ // Reset the listener
+ listener.resetChangeCount();
+ listener.resetTraces();
+
+ // Add a folder
+ containerFacade.createFolder("f1", 0, "f1", SWT.RIGHT);
+ container.refreshTabs();
+
+ // check events
+ assertEquals("event fired", 1, listener.getEventCount());
+ i=0;
+ assertEquals("right event", FakeFolderLifeCycleEventsListener.FOLDER_CREATED, listener.getTraces().get(i++));
+ }
+
+ /**
+ * Test if the FOLDER_DISPOSED event is sent when a folder is added.
+ * @throws PagesModelException
+ */
+ @Test
+ public void testFolderDisposedEvent() throws PagesModelException {
+
+ SimpleSashWindowContainerTestFacade containerFacade = new SimpleSashWindowContainerTestFacade();
+ // get container and contentProvider
+ ISashWindowsContentProvider contentProvider = containerFacade.getIContentProvider();
+ SashWindowsContainer container = containerFacade.getSashContainer();
+
+ // Create listener and attach it
+ FakeFolderLifeCycleEventsListener listener = new FakeFolderLifeCycleEventsListener();
+ container.getFolderLifeCycleEventProvider().addListener(listener);
+
+ // init the container
+ IModelExp expr = vSash(
+ folder( "f1", page("p2"), page("p3"), page("p4") ),
+ folder( "f2", page("p1") )
+ );
+ containerFacade.createModel(expr);
+
+ // Do refresh. This fire events
+ container.refreshTabs();
+
+ // Reset the listener
+ listener.resetChangeCount();
+ listener.resetTraces();
+
+ // Remove page. This should remove the folder
+ containerFacade.removePage("p1");
+ container.refreshTabs();
+
+ // check events
+ assertEquals("event fired " + listener.toString(), 1, listener.getEventCount());
+ int i=0;
+ assertEquals("right event", FakeFolderLifeCycleEventsListener.FOLDER_DISPOSED, listener.getTraces().get(i));
+ assertEquals("right object", containerFacade.getNamesToInternalMap().get("f2"), listener.getEvents().get(i++).getRawModel());
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/SashWindowsContainerTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/SashWindowsContainerTest.java
index ff86a968633..616bc180b35 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/SashWindowsContainerTest.java
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/SashWindowsContainerTest.java
@@ -30,15 +30,19 @@ import org.eclipse.jface.action.MenuManager;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContainerTestFacade;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowContentProviderUtils;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider;
import org.eclipse.papyrus.infra.core.sasheditor.editor.IComponentPage;
import org.eclipse.papyrus.infra.core.sasheditor.editor.IEditorPage;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IFolder;
import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
import org.eclipse.papyrus.infra.core.sasheditor.editor.IPageVisitor;
import org.eclipse.papyrus.infra.core.sasheditor.editor.MessagePartModel;
import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp;
import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
+import org.eclipse.papyrus.infra.core.sasheditor.utils.FakeObservableListener;
+import org.eclipse.papyrus.infra.core.sasheditor.utils.IObservableList;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
@@ -543,4 +547,109 @@ public class SashWindowsContainerTest {
container.visit(visitor);
return visitor.result();
}
+
+ /**
+ * Test If the FolderList is properly populated.
+ *
+ * * @throws PagesModelException
+ */
+ @Test
+ public void testFolderList() throws PagesModelException {
+ // Create populated content provider
+ SimpleSashWindowsContentProvider contentProvider = new SimpleSashWindowsContentProvider();
+ SimpleSashWindowContentProviderUtils helper = new SimpleSashWindowContentProviderUtils(contentProvider);
+
+ // define how to populate contentProvider
+ IModelExp expr = vSash( folder( "f1", page("p11"), page("p12")), folder( "f2", page("p21"), page("p22")));
+ // Try to create the model
+ helper.createModel(expr);
+ // Get the references
+ Map<String, Object> models = helper.queryModel(expr);
+
+ // Create the container
+ SashWindowsContainer container = createSashWindowsContainer(contentProvider);
+
+ // Check the folder list
+ IObservableList<IFolder> list = container.getIFolderList();
+ // Listener on the list
+ FakeObservableListener<IFolder> listener = new FakeObservableListener<IFolder>();
+ list.addListener(listener);
+
+ // Check list before
+ assertNotNull("List exist", list );
+ assertEquals("list size", 2, list.size() );
+
+ // create a folder
+ ITabFolderModel folder = (ITabFolderModel)models.get("f2");
+ assertNotNull( "folder found", folder);
+ contentProvider.createFolder(folder, 0, folder, SWT.UP);
+ // Refresh tabs, so that tabfolder is created.
+ container.refreshTabs();
+
+ // Check if the list contains the new folder
+ assertEquals("list size", 3, list.size() );
+ // check event fired
+ assertNotNull( "event sent", listener.getLastAddEvents() );
+// assertEquals( "event sent", folder, listener.getLastAddEvents().getRawModel() );
+
+ }
+
+ /**
+ * Test If the FolderList is properly populated.
+ *
+ * * @throws PagesModelException
+ */
+ @Test
+ public void testFolderList2() throws PagesModelException {
+
+ SimpleSashWindowContainerTestFacade containerFacade = new SimpleSashWindowContainerTestFacade();
+
+ // define how to populate contentProvider
+ IModelExp expr = vSash( folder( "f1", page("p11"), page("p12")), folder( "f2", page("p21"), page("p22")));
+ // Try to create the model
+ containerFacade.createModel(expr);
+
+ // Create the container
+ SashWindowsContainer container = containerFacade.getSashContainer();
+
+ // Refresh container, so that pages are created.
+ container.refreshTabs();
+
+ // Check the folder list
+ IObservableList<IFolder> list = container.getIFolderList();
+ // Listener on the list
+ FakeObservableListener<IFolder> listener = new FakeObservableListener<IFolder>();
+ list.addListener(listener);
+
+ // Check list before
+ assertNotNull("List exist", list );
+ assertEquals("list size", 2, list.size() );
+
+ // create a folder
+ containerFacade.createFolder("f2", 0, "f2", SWT.UP);
+ // Refresh tabs, so that tabfolder is created.
+ container.refreshTabs();
+
+ // build expr corresponding to new configuration
+ IModelExp newExpr = vSash(
+ folder( "f1", page("p11"), page("p12")),
+ vSash(
+ folder( "f3", page("p21")),
+ folder( "f2", page("p22"))
+ )
+ );
+ // Reset facade names to correspond to new configuration.
+ containerFacade.resetNamesContext(newExpr);
+ ITabFolderModel folder = containerFacade.getITabFolderModel("f3");
+
+ // Check if the list contains the new folder
+ assertEquals("list size", 3, list.size() );
+
+
+ // check event fired
+ assertNotNull( "event sent", listener.getLastAddEvents() );
+ assertEquals( "event sent", folder, listener.getLastAddEvents().getRawModel() );
+
+ }
+
}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/TabFolderListManagerTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/TabFolderListManagerTest.java
new file mode 100644
index 00000000000..227aa9c6949
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/internal/TabFolderListManagerTest.java
@@ -0,0 +1,95 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.internal;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Tests for the {@link SashContainerFolderEventsProvider} class.
+ * @author cedric dumoulin
+ *
+ */
+public class TabFolderListManagerTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test addition of a folder. Check if the folder is added to the list, and event added.
+ *
+ */
+ @Test
+ public void testFolderAdded() {
+
+ // Create listManager and folder event provider
+ TabFolderListManager listManager = new TabFolderListManager();
+ SashContainerFolderEventsProvider folderEventProvider = new SashContainerFolderEventsProvider();
+ folderEventProvider.addListener(listManager);
+
+ // fire folder added event
+ TabFolderPart folder1= new FakeTabFolderPart();
+ folderEventProvider.fireFolderCreatedEvent(folder1);
+
+ // Check the list
+ assertTrue( "folder added", listManager.getFolderList().contains(folder1) );
+
+ }
+
+ /**
+ * Test addition of a folder. Check if the folder is added to the list, and event added.
+ */
+ @Test
+ public void testFolderRemoved() {
+ // Create listManager and folder event provider
+ TabFolderListManager listManager = new TabFolderListManager();
+ SashContainerFolderEventsProvider folderEventProvider = new SashContainerFolderEventsProvider();
+ folderEventProvider.addListener(listManager);
+
+ // fire folder added event
+ TabFolderPart folder1= new FakeTabFolderPart();
+ folderEventProvider.fireFolderCreatedEvent(folder1);
+
+ TabFolderPart folder2= new FakeTabFolderPart();
+ folderEventProvider.fireFolderCreatedEvent(folder2);
+
+ // Check the list
+ assertTrue( "folder added", listManager.getFolderList().contains(folder1) );
+ assertTrue( "folder added", listManager.getFolderList().contains(folder2) );
+
+ // remove the folder
+ folderEventProvider.fireFolderDisposedEvent(folder1);
+ assertFalse( "folder removed", listManager.getFolderList().contains(folder1) );
+ assertTrue( "folder added", listManager.getFolderList().contains(folder2) );
+
+
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/AbstractSash.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/AbstractSash.java
deleted file mode 100644
index 0d1cfcd8c1c..00000000000
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/AbstractSash.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2013 Cedric Dumoulin.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are 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
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
-
-
-/**
- * Base class for structure representing sash in Checker
- * @author cedric dumoulin
- *
- */
-public abstract class AbstractSash extends PanelTerm {
-
- protected PanelTerm leftup;
- protected PanelTerm rightdown;
-
- /**
- * Constructor.
- *
- */
- public AbstractSash(PanelTerm left, PanelTerm right) {
- this.leftup = left;
- this.rightdown = right;
- }
-
- /**
- * Constructor.
- *
- * @param name
- * @param up
- * @param down
- */
- public AbstractSash(String name, PanelTerm left, PanelTerm right) {
- super(name);
- this.leftup = left;
- this.rightdown = right;
- }
-
- /**
- * @return the leftup
- */
- public PanelTerm getLeftup() {
- return leftup;
- }
-
- /**
- * @return the rightdown
- */
- public PanelTerm getRightdown() {
- return rightdown;
- }
-
- /**
- *
- * @param visitor
- * @throws PagesModelException
- */
- abstract public <M> void accept(IPagesModelVisitor<M> visitor, M modelObject) throws PagesModelException ;
-
- /**
- * @return The name used in toString
- */
- protected abstract String getStringName();
-
- /**
- * @see java.lang.Object#toString()
- *
- * @return
- */
- @Override
- public String toString() {
-
- StringBuffer buff = new StringBuffer(getStringName());
-
- buff.append("(");
- buff.append(leftup.toString());
- buff.append(", ");
- buff.append(rightdown.toString());
- buff.append(")");
-
- return buff.toString();
- }
-
-}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/NoMatchException.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/BadNameException.java
index 3a3fcc211f7..3c5c56528aa 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/NoMatchException.java
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/BadNameException.java
@@ -14,13 +14,13 @@
package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
+
+
/**
- * Exception thrown when a query part does not match a modelpart.
- *
* @author cedric dumoulin
*
*/
-public class NoMatchException extends PagesModelException {
+public class BadNameException extends PagesModelException {
/**
*
@@ -31,7 +31,8 @@ public class NoMatchException extends PagesModelException {
* Constructor.
*
*/
- public NoMatchException() {
+ public BadNameException() {
+ // TODO Auto-generated constructor stub
}
/**
@@ -39,8 +40,9 @@ public class NoMatchException extends PagesModelException {
*
* @param arg0
*/
- public NoMatchException(String arg0) {
+ public BadNameException(String arg0) {
super(arg0);
+ // TODO Auto-generated constructor stub
}
/**
@@ -48,8 +50,9 @@ public class NoMatchException extends PagesModelException {
*
* @param arg0
*/
- public NoMatchException(Throwable arg0) {
+ public BadNameException(Throwable arg0) {
super(arg0);
+ // TODO Auto-generated constructor stub
}
/**
@@ -58,8 +61,9 @@ public class NoMatchException extends PagesModelException {
* @param arg0
* @param arg1
*/
- public NoMatchException(String arg0, Throwable arg1) {
+ public BadNameException(String arg0, Throwable arg1) {
super(arg0, arg1);
+ // TODO Auto-generated constructor stub
}
/**
@@ -70,8 +74,9 @@ public class NoMatchException extends PagesModelException {
* @param arg2
* @param arg3
*/
- public NoMatchException(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
+ public BadNameException(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
super(arg0, arg1, arg2, arg3);
+ // TODO Auto-generated constructor stub
}
}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/Folder.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/Folder.java
deleted file mode 100644
index 5ff7f193e1d..00000000000
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/Folder.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2013 Cedric Dumoulin.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are 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
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * This represent a Folder in the Checker query.
- *
- * @author cedric dumoulin
- */
-public class Folder extends PanelTerm implements IModelObject {
-
- protected List<Page> pages;
-
- /**
- * Constructor.
- *
- */
- public Folder(Page ... pages) {
- this.pages = Arrays.asList(pages);
- }
-
- /**
- * Constructor.
- *
- */
- public Folder(String name, Page ... pages) {
- super(name);
- this.pages = Arrays.asList(pages);
- }
-
- /**
- * @return the pages
- */
- public List<Page> getPages() {
- return pages;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.sasheditor.IModelObject.sashmodel.query.IQueryTerm#accept(IPagesModelVisitor, EObject)
- *
- * @param visitor
- * @throws PagesModelException
- */
- public <M> void accept(IPagesModelVisitor<M> visitor, M modelObject) throws PagesModelException {
-
- visitor.walk(this, modelObject);
- }
-
- /**
- * @see java.lang.Object#toString()
- *
- * @return
- */
- @Override
- public String toString() {
-
- StringBuffer buff = new StringBuffer("Folder(");
-
- for(Page page : pages ) {
- buff.append(page.toString()).append(", ");
- }
- // Remove extra ,
- int length = buff.length();
- if(buff.charAt(length-1) == ' ') {
- buff.delete(length-2, length );
- }
- buff.append(")");
-
- return buff.toString();
- }
-}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/HSash.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/HSash.java
deleted file mode 100644
index cbaedf11103..00000000000
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/HSash.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2013 Cedric Dumoulin.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are 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
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
-
-
-/**
- * @author dumoulin
- *
- */
-public class HSash extends AbstractSash {
-
- /**
- * Constructor.
- *
- * @param leftup
- * @param rightdown
- */
- public HSash(PanelTerm up, PanelTerm down) {
- super(up, down);
- }
-
- /**
- * Constructor.
- *
- * @param leftup
- * @param rightdown
- */
- public HSash(String name, PanelTerm up, PanelTerm down) {
- super(name, up, down);
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.sasheditor.IModelObject.sashmodel.query.IQueryTerm#accept(IPagesModelVisitor, EObject)
- *
- * @param visitor
- * @throws PagesModelException
- */
- public <M> void accept(IPagesModelVisitor<M> visitor, M modelObject) throws PagesModelException {
-
- visitor.walk(this, modelObject);
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.AbstractSash#getStringName()
- *
- * @return
- */
- @Override
- protected String getStringName() {
- return "HSash";
- }
-
-
-}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/IModelObject.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/IModelObject.java
deleted file mode 100644
index e16bfd38324..00000000000
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/IModelObject.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2013 Cedric Dumoulin.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are 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
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
-
-
-/**
- * Common ancestor of all object in the Model.
- * All object that can be used in a query should implement this interface.
- *
- * @author cedric dumoulin
- */
-public interface IModelObject {
-
- /**
- * Visit the query.
- * @param visitor
- * @throws PagesModelException
- */
- public <M> void accept(IPagesModelVisitor<M> visitor, M panel) throws PagesModelException;
-
- /**
- * Get the name associated to the query part.
- * Can return null;
- */
- public String getName();
-}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/IPagesModelVisitor.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/IPagesModelVisitor.java
deleted file mode 100644
index a87f02e2fff..00000000000
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/IPagesModelVisitor.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2013 Cedric Dumoulin.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are 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
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
-
-/**
- * Visitor used to visit query structure.
- *
- * @author cedric dumoulin
- *
- * @param M Type of the models provided to visit() and walk(). This is the common
- * ancestor of the provided types.
- *
- */
-public interface IPagesModelVisitor <M>{
-
- /**
- * If true, parent are visited before children.
- * If false, parent are visited after children.
- * @return
- */
- public boolean isVisitingParentFirst();
-
- /**
- * Walk the node and its children. Call visit visit method appropiatly.
- * This method encapsulate the navigation between nodes.
- *
- * @param windowTerm The term to navigate
- * @param windowModel the model that maybe correspond to the term.
- * @throws PagesModelException
- *
- */
- public void walk( SashPagesModel windowTerm, M windowModel ) throws PagesModelException;
- public void walk( WindowTerm windowTerm, M windowModel ) throws PagesModelException;
- public void walk( Folder folder, M folderModel ) throws PagesModelException;
-
- public void walk(HSash sash, M sashModel) throws PagesModelException;
- public void walk(VSash sash, M sashModel) throws PagesModelException;
-
- public void walk(Page page, M pageModel) throws PagesModelException;
-
-
- /**
- * Visit the corresponding term.
- * @param windowTerm The term to visit
- * @param windowModel The corresponding model found while walking the expr.
- */
-// public void visit( SashPagesModel windowTerm, M windowModel ) throws PagesModelException;
-// public void visit( WindowTerm windowTerm, M windowModel ) throws PagesModelException;
-// public void visit( Folder folder, M folderModel ) throws PagesModelException;
-//
-// public void visit(HSash sash, M sashModel) throws PagesModelException;
-// public void visit(VSash sash, M sashModel) throws PagesModelException;
-//
-// public void visit(Page page, M pageModel) throws PagesModelException;
-
-}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/PagesModelException.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/NotFoundException.java
index 912da20781e..eeca81273f3 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/PagesModelException.java
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/NotFoundException.java
@@ -14,14 +14,12 @@
package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
+
/**
- * Root Exception of the pagesmodel package
- *
* @author cedric dumoulin
- *
- * TODO Rename to PagesModelException
+ *
*/
-public class PagesModelException extends Exception {
+public class NotFoundException extends PagesModelException {
/**
*
@@ -30,49 +28,55 @@ public class PagesModelException extends Exception {
/**
* Constructor.
- *
+ *
*/
- public PagesModelException() {
+ public NotFoundException() {
+ super();
+ // TODO Auto-generated constructor stub
}
/**
* Constructor.
- *
+ *
* @param arg0
+ * @param arg1
+ * @param arg2
+ * @param arg3
*/
- public PagesModelException(String arg0) {
- super(arg0);
+ public NotFoundException(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
+ super(arg0, arg1, arg2, arg3);
+ // TODO Auto-generated constructor stub
}
/**
* Constructor.
- *
+ *
* @param arg0
+ * @param arg1
*/
- public PagesModelException(Throwable arg0) {
- super(arg0);
+ public NotFoundException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ // TODO Auto-generated constructor stub
}
/**
* Constructor.
- *
+ *
* @param arg0
- * @param arg1
*/
- public PagesModelException(String arg0, Throwable arg1) {
- super(arg0, arg1);
+ public NotFoundException(String arg0) {
+ super(arg0);
+ // TODO Auto-generated constructor stub
}
/**
* Constructor.
- *
+ *
* @param arg0
- * @param arg1
- * @param arg2
- * @param arg3
*/
- public PagesModelException(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
- super(arg0, arg1);//, arg2, arg3);
+ public NotFoundException(Throwable arg0) {
+ super(arg0);
+ // TODO Auto-generated constructor stub
}
}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/Page.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/Page.java
deleted file mode 100644
index 5bd2fa904bb..00000000000
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/Page.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2013 Cedric Dumoulin.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are 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
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
-
-
-/**
- * This represent a page in the Checker query.
- *
- * @author cedric dumoulin
- *
- */
-public class Page implements IModelObject {
-
- protected Object identifier;
-
- protected String name;
-
- /** To generate automatic name */
- static int count=1;
-
- /**
- * Constructor.
- *
- */
- public Page() {
- // Automatic name generation
- this( "page"+count++);
- }
-
- /**
- * Constructor.
- *
- * @param identifier
- */
- public Page(Object identifier) {
- this.identifier = identifier;
- this.name = identifier.toString();
- }
-
- /**
- * Constructor.
- *
- * @param name
- * @param identifier
- */
- public Page(String name) {
- this.name = name;
- this.identifier = name;
- }
-
- /**
- * Constructor.
- *
- * @param name
- * @param identifier
- */
- public Page(String name, Object identifier) {
- this.name = name;
- this.identifier = identifier;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.sasheditor.IModelObject.sashmodel.query.IQueryTerm#accept(IPagesModelVisitor, EObject)
- *
- * @param visitor
- * @throws PagesModelException
- */
- public <M> void accept(IPagesModelVisitor<M> visitor, M modelObject) throws PagesModelException {
-
- visitor.walk(this, modelObject);
- }
-
- /**
- * @return the identifier
- */
- public Object getIdentifier() {
- return identifier;
- }
-
- /**
- * @param identifier the identifier to set
- */
- public void setIdentifier(Object identifier) {
- this.identifier = identifier;
- }
-
- /**
- * @see java.lang.Object#toString()
- *
- * @return
- */
- @Override
- public String toString() {
-
- return "Page()";
- }
-
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
-}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/PanelTerm.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/PanelTerm.java
deleted file mode 100644
index bd1d79b05bf..00000000000
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/PanelTerm.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2013 Cedric Dumoulin.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are 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
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
-
-
-/**
- * Common ancestor of Panel (Folder and Sash) in queries structure.
- * <br>
- * This class can also be used a starting point of query expression (and so Folder, VSash and HSash).
- *
- * @author cedric dumoulin
- *
- */
-public abstract class PanelTerm implements IModelExp {
-
- protected String name;
-
-
- /**
- * Constructor.
- *
- */
- public PanelTerm() {
- }
-
- /**
- * Constructor.
- *
- * @param name
- */
- public PanelTerm(String name) {
- this.name = name;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.sasheditor.IModelObject.sashmodel.query.IQueryTerm#accept(org.eclipse.papyrus.infra.core.sasheditor.IPagesModelVisitor.sashmodel.query.IQueryVisitor, org.eclipse.emf.ecore.EObject)
- *
- * @param visitor
- * @param panel
- * @throws PagesModelException
- */
- public <M> void accept(IPagesModelVisitor<M> visitor, M panel)
- throws PagesModelException {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
-}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/SashPagesModel.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/SashPagesModel.java
deleted file mode 100644
index a08aa1521f6..00000000000
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/SashPagesModel.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2013 Cedric Dumoulin.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are 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
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Sash Pages model allow to create a models of the pages represented by the {@link SashWindowsContainer}.
- * Such model can then be used to create corresponding pages and intermediate artifact in a {@link ISashWindowsContentProvider},
- * or to check the structure, ....
- *
- * <br>
- * The model contains windows. Actually, the {@link SashWindowsContainer} only support one window.
- *
- * @author cedric dumoulin
- *
- */
-public class SashPagesModel implements IModelExp {
-
- /**
- * A window have only one panel.
- */
- protected List<WindowTerm> windows = new ArrayList<WindowTerm>();
-
- protected String name;
-
- /**
- * Constructor.
- *
- * @param panel
- */
- public SashPagesModel(WindowTerm window) {
- this.windows.add(window);
- }
-
- /**
- * Constructor.
- *
- * @param name
- * @param panel
- */
- public SashPagesModel(String name, WindowTerm window) {
- this.name = name;
- this.windows.add(window);
- }
-
-
- /**
- * @see org.eclipse.papyrus.infra.core.sasheditor.IModelObject.sashmodel.query.IQueryTerm#accept(org.eclipse.papyrus.infra.core.sasheditor.IPagesModelVisitor.sashmodel.query.IQueryVisitor, org.eclipse.emf.ecore.EObject)
- *
- * @param visitor
- * @param panel
- * @throws PagesModelException
- */
- public <M> void accept(IPagesModelVisitor<M> visitor, M model) throws PagesModelException {
-
- visitor.walk(this, model);
-
- }
-
-
- /**
- * @return the panel
- * @throws PagesModelException
- */
- public WindowTerm getFirstWindow() throws PagesModelException {
- if( windows.size() >0) {
- return windows.get(0);
- }
-
- // no elements
- throw new PagesModelException("No window found in model.");
- }
-
- /**
- * @return the panel
- */
- public List<WindowTerm> getWindows() {
- return windows;
- }
-
-
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
-
-}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/SashPagesModelFactory.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/SashPagesModelFactory.java
deleted file mode 100644
index c29154cafd3..00000000000
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/SashPagesModelFactory.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2013 Cedric Dumoulin.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are 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
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
-
-
-/**
- * This class provides a set of static constructor helping in writing model.
- * <br>
- * Examples:
- * <ul>
- * <li>PanelTerm query = folder("a", page(), page() );</li>
- * <li>query = hSash( folder( page("p1"), page() ), vSash("s2", folder( page() ), folder( page() )) );</li>
- * <li>PanelTerm query = hSash( folder("f1", page("p1"), page("p2"), page("p3") ), folder("f2", page("p4") ) );</li>
- * <li></li>
- * </ul>
- *
- * @author cedric dumoulin
- *
- */
-public class SashPagesModelFactory {
-
- /**
- * Static constructor for {@link Page}.
- * @return
- */
- static public Page page() {
- return new Page();
- }
-
- /**
- * Static constructor for {@link Page}.
- * @return
- */
- static public Page page(String name) {
- return new Page(name);
- }
-
- /**
- * Static constructor for {@link Folder}.
- * @return
- */
- static public Folder folder( Page ...pages ) {
- return new Folder(pages);
- }
-
- /**
- * Static constructor for {@link Folder}.
- * @return
- */
- static public Folder folder( String name, Page ...pages ) {
- return new Folder(name, pages);
- }
-
- /**
- * Static constructor for {@link VSash}.
- * @return
- */
- static public VSash vSash( String name, PanelTerm up, PanelTerm down) {
- return new VSash(name, up, down);
- }
-
- /**
- * Static constructor for {@link VSash}.
- * @return
- */
- static public VSash vSash( PanelTerm up, PanelTerm down) {
- return new VSash(up, down);
- }
-
- /**
- * Static constructor for {@link HSash}.
- * @return
- */
- static public HSash hSash( String name, PanelTerm left, PanelTerm right) {
- return new HSash(name, left, right);
- }
-
- /**
- * Static constructor for {@link HSash}.
- * @return
- */
- static public HSash hSash( PanelTerm left, PanelTerm right) {
- return new HSash(left, right);
- }
-
-}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/VSash.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/VSash.java
deleted file mode 100644
index f3e020c216b..00000000000
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/VSash.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2013 Cedric Dumoulin.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are 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
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
-
-
-/**
- * Class for structure representing vertical sash in Checker
- *
- * @author dumoulin
- *
- */
-public class VSash extends AbstractSash {
-
- /**
- * Constructor.
- *
- * @param leftup
- * @param rightdown
- */
- public VSash(PanelTerm left, PanelTerm right) {
- super(left, right);
- }
-
- /**
- * Constructor.
- *
- * @param leftup
- * @param rightdown
- */
- public VSash(String name, PanelTerm left, PanelTerm right) {
- super(name, left, right);
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.sasheditor.IModelObject.sashmodel.query.IQueryTerm#accept(IPagesModelVisitor, EObject)
- *
- * @param visitor
- * @throws PagesModelException
- */
- public <M> void accept(IPagesModelVisitor<M> visitor, M modelObject) throws PagesModelException {
- visitor.walk(this, modelObject);
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.sasheditor.di.sashmodel.query.AbstractSash#getStringName()
- *
- * @return
- */
- @Override
- protected String getStringName() {
- return "VSash";
- }
-
-}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/WindowTerm.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/WindowTerm.java
deleted file mode 100644
index 27399c58c99..00000000000
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/WindowTerm.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2013 Cedric Dumoulin.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are 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
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel;
-
-
-/**
- * A term representing a Window in the query
- *
- * @author cedric dumoulin
- *
- */
-public class WindowTerm implements IModelExp {
-
- /**
- * A window have only one panel.
- */
- protected PanelTerm panel;
-
- protected String name;
-
- /**
- * Constructor.
- *
- * @param panel
- */
- public WindowTerm(PanelTerm panel) {
- this.panel = panel;
- }
-
- /**
- * Constructor.
- *
- * @param name
- * @param panel
- */
- public WindowTerm(String name, PanelTerm panel) {
- this.name = name;
- this.panel = panel;
- }
-
-
- /**
- * @see org.eclipse.papyrus.infra.core.sasheditor.IModelObject.sashmodel.query.IQueryTerm#accept(org.eclipse.papyrus.infra.core.sasheditor.IPagesModelVisitor.sashmodel.query.IQueryVisitor, org.eclipse.emf.ecore.EObject)
- *
- * @param visitor
- * @param panel
- * @throws PagesModelException
- */
- public <M> void accept(IPagesModelVisitor<M> visitor, M windowModel) throws PagesModelException {
-
- visitor.walk(this, windowModel);
-
- }
-
-
- /**
- * @return the panel
- */
- public PanelTerm getPanel() {
- return panel;
- }
-
-
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
-
-}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/tests/utils/ISashWindowsContentProviderTestUtils.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/tests/utils/ISashWindowsContentProviderTestUtils.java
new file mode 100644
index 00000000000..d647f9bc261
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/tests/utils/ISashWindowsContentProviderTestUtils.java
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.tests.utils;
+
+import java.util.Map;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.IModelExp;
+import org.eclipse.papyrus.infra.core.sasheditor.pagesmodel.PagesModelException;
+
+
+/**
+ * Common interface for utilities dedicated to IContentProvider tests. Implementations of this class
+ * allow to create an internal model according to a provided {@link IModelExp}. It is also possible
+ * to check if the internal model is conform to the {@link IModelExp}.
+ *
+ * <br>
+ * There is several {@link ISashWindowsContentProvider} implementations, but a lot of tests are commons to
+ * all the implementations. The interface allows to develop common tests regardless of the real implementation.
+ * <br>
+ * One develop common tests using {@link ISashWindowsContentProvider} and {@link IContentProviderTestUtils}. Then,
+ * this test is subclassed and the appropriate implementations are specified in the subclasses.
+ *
+ *
+ * @author cedric dumoulin
+ *
+ */
+public interface ISashWindowsContentProviderTestUtils {
+
+ /**
+ * Create an internal model conform to the specified query.
+ * Any previous model is disguarded.
+ *
+ * Some implementations do not allow to call this method more than once. In this case,
+ * the implementation should throw an Exception.
+ *
+ * @param query Should be a subtype PanelTerm (Folder, HSash, VSash)
+ * @throws QueryException
+ *
+ */
+ public abstract void createModel(IModelExp query) throws PagesModelException;
+
+ /**
+ * Check if the internal model is conformed to the specified query.
+ * @param query
+ * @throws QueryException
+ */
+ public abstract void assertConform(IModelExp query) throws PagesModelException;
+
+ /**
+ * Get element in the model.
+ * Each model element whose corresponding model query part as a name is added to the result map.
+ * The element is then accessible with the name set in the query part.
+ *
+ * @param query
+ * @return
+ * @throws QueryException
+ */
+ public abstract Map<String, Object> queryModel(IModelExp query) throws PagesModelException;
+
+ /**
+ * Get the {@link ISashWindowsContentProvider} associated to this utility class.
+ * @return
+ */
+ public ISashWindowsContentProvider getIContentProvider();
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/package-info.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/tests/utils/package-info.java
index cdc2289dac8..ee1b85d4846 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/pagesmodel/package-info.java
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/tests/utils/package-info.java
@@ -13,7 +13,7 @@
*****************************************************************************/
/**
- * @author cedric dumoulin
+ * @author dumoulin
*
*/
-package org.eclipse.papyrus.infra.core.sasheditor.pagesmodel; \ No newline at end of file
+package org.eclipse.papyrus.infra.core.sasheditor.tests.utils; \ No newline at end of file
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/utils/FakeObservableListener.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/utils/FakeObservableListener.java
new file mode 100644
index 00000000000..fb123b1d04c
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/utils/FakeObservableListener.java
@@ -0,0 +1,84 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * A fake listener for testing purpose.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class FakeObservableListener<E> implements IObservableListListener<E> {
+
+ /**
+ * Trace of event received
+ */
+ protected List<E> addEvents = new ArrayList<E>();
+
+ /**
+ * Trace of event received
+ */
+ protected List<E> removeEvents = new ArrayList<E>();
+
+
+ /**
+ * @return the events
+ */
+ public List<E> getAddEvents() {
+ return addEvents;
+ }
+
+ /**
+ * @return the events
+ */
+ public E getLastAddEvents() {
+ if(addEvents.size()>0) {
+ return addEvents.get(addEvents.size() -1);
+ }
+
+ return null;
+ }
+
+ /**
+ * @return the events
+ */
+ public List<E> getRemoveEvents() {
+ return removeEvents;
+ }
+
+ /**
+ * @return the events
+ */
+ public E getLastRemoveEvents() {
+ if(removeEvents.size()>0) {
+ return removeEvents.get(removeEvents.size() -1);
+ }
+
+ return null;
+ }
+
+ public void elementAdded(E element) {
+ addEvents.add(element);
+ }
+
+ public void elementRemoved(E element) {
+ removeEvents.add(element);
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/utils/ObservableListTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/utils/ObservableListTest.java
new file mode 100644
index 00000000000..b46062e7339
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.sasheditor.tests/test/org/eclipse/papyrus/infra/core/sasheditor/utils/ObservableListTest.java
@@ -0,0 +1,173 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.utils;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class ObservableListTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.utils.ObservableList#ObservableList()}.
+ */
+ @Test
+ public void testObservableList() {
+ ObservableList<String> list = new ObservableList<String>();
+ assertNotNull("list created", list);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.utils.ObservableList#addListener(org.eclipse.papyrus.infra.core.sasheditor.utils.IObservableListListener)}.
+ */
+ @Test
+ public void testAddListener() {
+ ObservableList<String> list = new ObservableList<String>();
+ assertNotNull("list created", list);
+
+ FakeObservableListener<String> listener = new FakeObservableListener<String>();
+
+ // add a listener
+ list.addListener(listener);
+ // Check if added
+ assertTrue("listener added", list.getListeners().contains(listener));
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.utils.ObservableList#removeListener(org.eclipse.papyrus.infra.core.sasheditor.utils.IObservableListListener)}.
+ */
+ @Test
+ public void testRemoveListener() {
+ ObservableList<String> list = new ObservableList<String>();
+ assertNotNull("list created", list);
+
+ FakeObservableListener<String> listener = new FakeObservableListener<String>();
+
+ // add a listener
+ list.addListener(listener);
+ // Check if added
+ assertTrue("listener added", list.getListeners().contains(listener));
+
+ list.removeListener(listener);
+ // Check if added
+ assertFalse("list contains listener", list.getListeners().contains(listener));
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.utils.ObservableList#fireElementAddedEvent(java.lang.Object)}.
+ */
+ @Test
+ public void testFireElementAddedEvent() {
+ ObservableList<String> list = new ObservableList<String>();
+ assertNotNull("list created", list);
+
+ FakeObservableListener<String> listener = new FakeObservableListener<String>();
+
+ // add a listener
+ list.addListener(listener);
+ // Check event
+
+ list.fireElementAddedEvent("string1");
+ assertEquals( "event fired", "string1", listener.getLastAddEvents() );
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.utils.ObservableList#fireElementRemovedEvent(java.lang.Object)}.
+ */
+ @Test
+ public void testFireElementRemovedEvent() {
+ ObservableList<String> list = new ObservableList<String>();
+ assertNotNull("list created", list);
+
+ FakeObservableListener<String> listener = new FakeObservableListener<String>();
+
+ // add a listener
+ list.addListener(listener);
+ // Check event
+ String element = "string1";
+ list.fireElementRemovedEvent(element);
+ assertEquals( "event fired", element, listener.getLastRemoveEvents() );
+ }
+
+ /**
+ * Test method for add}.
+ */
+ @Test
+ public void testAdd() {
+ ObservableList<String> list = new ObservableList<String>();
+ assertNotNull("list created", list);
+
+ FakeObservableListener<String> listener = new FakeObservableListener<String>();
+
+ // add a listener
+ list.addListener(listener);
+ // Check event
+
+ String element = "string1";
+
+ list.add(element);
+ assertEquals( "event fired", element, listener.getLastAddEvents() );
+ assertEquals( "element added to list", element, list.get(list.size()-1) );
+
+ }
+
+ /**
+ * Test method for add}.
+ */
+ @Test
+ public void testRemove() {
+ ObservableList<String> list = new ObservableList<String>();
+ assertNotNull("list created", list);
+
+ FakeObservableListener<String> listener = new FakeObservableListener<String>();
+
+ // add a listener
+ list.addListener(listener);
+ // Check event
+
+ String element = "string1";
+ list.add(element);
+ assertEquals( "element added to list", element, list.get(list.size()-1) );
+
+ list.remove(element);
+ assertFalse( "element removed from list", list.contains(element) );
+ assertEquals( "event fired", element, listener.getLastRemoveEvents() );
+
+ }
+
+
+}

Back to the top