Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcdumoulin2009-05-29 22:22:35 +0000
committercdumoulin2009-05-29 22:22:35 +0000
commit68a9263e48e267bc5208d0f066a5d8271b5572ee (patch)
treed888d3a891f9e1f8194c42a0b73b19f739c36ce4
parent4c496b7949a1b6f188b3238bbab979f8050f3f77 (diff)
downloadorg.eclipse.papyrus-68a9263e48e267bc5208d0f066a5d8271b5572ee.tar.gz
org.eclipse.papyrus-68a9263e48e267bc5208d0f066a5d8271b5572ee.tar.xz
org.eclipse.papyrus-68a9263e48e267bc5208d0f066a5d8271b5572ee.zip
NEW - bug 268777: [Sash Editor] List of existing diagram
https://bugs.eclipse.org/bugs/show_bug.cgi?id=268777 Enable a list of existing Diagrams.
-rw-r--r--plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/DiSashModelMngr.java20
-rw-r--r--plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/IPageMngr.java8
-rw-r--r--plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/TransactionalDiSashModelMngr.java21
-rw-r--r--plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/PageMngrImpl.java10
-rw-r--r--plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/TransactionalDiContentProvider.java5
-rw-r--r--plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/TransactionalPageMngrImpl.java146
-rw-r--r--plugins/core/org.eclipse.papyrus.sasheditor/test/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/ContentChangeListener.java42
-rw-r--r--plugins/core/org.eclipse.papyrus.sasheditor/test/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/PageMngrImplTest.java258
-rw-r--r--plugins/others/org.eclipse.papyrus.example.sashwindows.fulleditor/META-INF/MANIFEST.MF3
-rw-r--r--plugins/others/org.eclipse.papyrus.example.sashwindows.fulleditor/src/org/eclipse/papyrus/example/sashwindows/fulleditor/editor/DiMultiTextEditor.java139
10 files changed, 628 insertions, 24 deletions
diff --git a/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/DiSashModelMngr.java b/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/DiSashModelMngr.java
index 056dc595968..23cc3bc0028 100644
--- a/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/DiSashModelMngr.java
+++ b/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/DiSashModelMngr.java
@@ -131,17 +131,27 @@ public class DiSashModelMngr {
}
/**
- * Get the IPageMngr providing basic methods to manage Pages in the sash model.
- * @return
+ * Return the internal implementation of PageMngr.
+ * Create if if needed.
+ * This method should not be subclassed
+ * @return the PageMngrImpl
*/
- public IPageMngr getIPageMngr() {
-
+ protected final PageMngrImpl getPageMngrImpl()
+ {
if(pageMngr == null)
{
pageMngr = new PageMngrImpl(sashWindowMngr);
}
- return pageMngr;
+ return pageMngr;
+ }
+
+ /**
+ * Get the IPageMngr providing basic methods to manage Pages in the sash model.
+ * @return
+ */
+ public IPageMngr getIPageMngr() {
+ return getPageMngrImpl();
}
/**
diff --git a/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/IPageMngr.java b/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/IPageMngr.java
index 89d1b1e929f..af15625b2ed 100644
--- a/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/IPageMngr.java
+++ b/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/IPageMngr.java
@@ -35,21 +35,21 @@ public interface IPageMngr {
* {@link IPageModelFactory#createIPageModel(EObject)}. This identifier is stored in the sash model.
* It should be a reference on a EMF object identifying the page.
*/
- public void addPage(EObject pageIdentifier);
+ public void addPage(Object pageIdentifier);
/**
* Remove the page from the SashWindows system and from the list of page.
* The page will not be available anymore.
* @param pageIdentifier The object identifying the page
*/
- public void removePage(EObject pageIdentifier);
+ public void removePage(Object pageIdentifier);
/**
* Close the page corresponding to the identifier.
* The identifier is removed from the Sash Windows, but not from the list of pages.
* @param pageIdentifier The object identifying the page
*/
- public void closePage(EObject pageIdentifier);
+ public void closePage(Object pageIdentifier);
/**
@@ -62,7 +62,7 @@ public interface IPageMngr {
* {@link IPageModelFactory#createIPageModel(EObject)}. This identifier is stored in the sash model.
* It should be a reference on a EMF object identifying the page.
*/
- public void openPage(EObject pageIdentifier);
+ public void openPage(Object pageIdentifier);
/**
* Return all available page identifiers (open and closed pages).
diff --git a/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/TransactionalDiSashModelMngr.java b/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/TransactionalDiSashModelMngr.java
index bf55ffe150d..ef835feb104 100644
--- a/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/TransactionalDiSashModelMngr.java
+++ b/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/TransactionalDiSashModelMngr.java
@@ -8,6 +8,7 @@ import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.sasheditor.contentprovider.ISashWindowsContentProvider;
import org.eclipse.papyrus.sasheditor.contentprovider.di.internal.TransactionalDiContentProvider;
+import org.eclipse.papyrus.sasheditor.contentprovider.di.internal.TransactionalPageMngrImpl;
/**
@@ -19,6 +20,8 @@ public class TransactionalDiSashModelMngr extends DiSashModelMngr {
private TransactionalDiContentProvider transDiContentProvider;
+ private TransactionalPageMngrImpl transPageMngrImpl;
+
/**
*
* Constructor.
@@ -50,25 +53,29 @@ public class TransactionalDiSashModelMngr extends DiSashModelMngr {
// Create the TransactionalDiContentProvider
transDiContentProvider = new TransactionalDiContentProvider(getDiContentProvider(), editingDomain);
+ // Create the TransactionalPageMngrImpl
+ transPageMngrImpl = new TransactionalPageMngrImpl(getPageMngrImpl(), editingDomain);
}
/**
- * Get the internal implementation of TransactionalDiContentProvider.
+ * Return the transactional version
+ * @see org.eclipse.papyrus.sasheditor.contentprovider.di.DiSashModelMngr#getISashWindowsContentProvider()
* @return
+ *
*/
- protected TransactionalDiContentProvider getTransactionalDiContentProvider() {
+ @Override
+ public ISashWindowsContentProvider getISashWindowsContentProvider() {
return transDiContentProvider;
-
}
/**
* Return the transactional version
- * @see org.eclipse.papyrus.sasheditor.contentprovider.di.DiSashModelMngr#getISashWindowsContentProvider()
- * @return
+ * @see org.eclipse.papyrus.sasheditor.contentprovider.di.DiSashModelMngr#getIPageMngr()
*
+ * @return
*/
@Override
- public ISashWindowsContentProvider getISashWindowsContentProvider() {
- return transDiContentProvider;
+ public IPageMngr getIPageMngr() {
+ return transPageMngrImpl;
}
}
diff --git a/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/PageMngrImpl.java b/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/PageMngrImpl.java
index 3792b7821aa..c2797f724b8 100644
--- a/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/PageMngrImpl.java
+++ b/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/PageMngrImpl.java
@@ -48,7 +48,7 @@ public class PageMngrImpl implements IPageMngr {
*
* @param pageIdentifier
*/
- public void addPage(EObject pageIdentifier) {
+ public void addPage(Object pageIdentifier) {
diSashModel.getPageList().addPage(pageIdentifier);
}
@@ -77,7 +77,7 @@ public class PageMngrImpl implements IPageMngr {
*
* @param pageIdentifier
*/
- public void closePage(EObject pageIdentifier) {
+ public void closePage(Object pageIdentifier) {
diSashModel.getSashModel().removePage(pageIdentifier);
}
@@ -86,7 +86,7 @@ public class PageMngrImpl implements IPageMngr {
*
* @param pageIdentifier
*/
- public void openPage(EObject pageIdentifier) {
+ public void openPage(Object pageIdentifier) {
// Add the page to the SashModel and to the PageList
diSashModel.getPageList().addPage(pageIdentifier);
diSashModel.getSashModel().addPage(pageIdentifier);
@@ -97,9 +97,9 @@ public class PageMngrImpl implements IPageMngr {
*
* @param pageIdentifier
*/
- public void removePage(EObject pageIdentifier) {
+ public void removePage(Object pageIdentifier) {
// remove from pageList and from SashModel
- diSashModel.getPageList().addPage(pageIdentifier);
+ diSashModel.getPageList().removePage(pageIdentifier);
diSashModel.getSashModel().removePage(pageIdentifier);
}
diff --git a/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/TransactionalDiContentProvider.java b/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/TransactionalDiContentProvider.java
index 74054f43731..1f038e36f9e 100644
--- a/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/TransactionalDiContentProvider.java
+++ b/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/TransactionalDiContentProvider.java
@@ -13,7 +13,10 @@ import org.eclipse.papyrus.sasheditor.contentprovider.ITabFolderModel;
/**
- * @author dumoulin
+ * A content provider based on EMF di and using Transactions.
+ * This implementation is a wrapper on {@link DiContentProvider}.
+ * Each method is wrapped in a {@link RecordingCommand}.
+ * @author cedric dumoulin
*
*/
public class TransactionalDiContentProvider implements ISashWindowsContentProvider, IContentChangedProvider {
diff --git a/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/TransactionalPageMngrImpl.java b/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/TransactionalPageMngrImpl.java
new file mode 100644
index 00000000000..19900679bf9
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/TransactionalPageMngrImpl.java
@@ -0,0 +1,146 @@
+/*****************************************************************************
+ * Copyright (c) 2009 CEA LIST & LIFL
+ *
+ *
+ * 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.sasheditor.contentprovider.di.internal;
+
+import java.util.List;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.sasheditor.contentprovider.di.IPageMngr;
+
+
+/**
+ * A PageMngr based on EMF di and using Transactions.
+ * This implementation is a wrapper on {@link PageMngrImpl}.
+ * Each method is wrapped in a {@link RecordingCommand}.
+ * @author cedric dumoulin
+ */
+public class TransactionalPageMngrImpl implements IPageMngr {
+
+ /**
+ * wrapped ContentProvider. All commands will use this provider.
+ */
+ private PageMngrImpl pageMngr;
+
+ private TransactionalEditingDomain editingDomain;
+
+ /**
+ *
+ * Constructor.
+ * @param diContentProvider
+ */
+ public TransactionalPageMngrImpl(PageMngrImpl pageMngr, TransactionalEditingDomain editingDomain) {
+ this.pageMngr = pageMngr;
+ this.editingDomain = editingDomain;
+ }
+
+ /**
+ * Get the editing domain used to perform transactions.
+ * @return
+ */
+ private TransactionalEditingDomain getTransactionalEditingDomain() {
+ return editingDomain;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.sasheditor.contentprovider.di.IPageMngr#addPage(java.lang.Object)
+ *
+ * @param pageIdentifier
+ */
+ public void addPage(final Object pageIdentifier) {
+ TransactionalEditingDomain editingDomain = getTransactionalEditingDomain();
+
+ RecordingCommand command = new RecordingCommand(editingDomain) {
+
+ @Override
+ protected void doExecute() {
+ pageMngr.addPage(pageIdentifier);
+
+ }
+ };
+
+ editingDomain.getCommandStack().execute(command);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.sasheditor.contentprovider.di.IPageMngr#allPages()
+ *
+ * @return
+ */
+ public List<Object> allPages() {
+ return pageMngr.allPages();
+ }
+
+ /**
+ * @see org.eclipse.papyrus.sasheditor.contentprovider.di.IPageMngr#closePage(java.lang.Object)
+ *
+ * @param pageIdentifier
+ */
+ public void closePage(final Object pageIdentifier) {
+ TransactionalEditingDomain editingDomain = getTransactionalEditingDomain();
+
+ RecordingCommand command = new RecordingCommand(editingDomain) {
+
+ @Override
+ protected void doExecute() {
+ pageMngr.closePage(pageIdentifier);
+
+ }
+ };
+
+ editingDomain.getCommandStack().execute(command);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.sasheditor.contentprovider.di.IPageMngr#openPage(java.lang.Object)
+ *
+ * @param pageIdentifier
+ */
+ public void openPage(final Object pageIdentifier) {
+ TransactionalEditingDomain editingDomain = getTransactionalEditingDomain();
+
+ RecordingCommand command = new RecordingCommand(editingDomain) {
+
+ @Override
+ protected void doExecute() {
+ pageMngr.openPage(pageIdentifier);
+
+ }
+ };
+
+ editingDomain.getCommandStack().execute(command);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.sasheditor.contentprovider.di.IPageMngr#removePage(java.lang.Object)
+ *
+ * @param pageIdentifier
+ */
+ public void removePage(final Object pageIdentifier) {
+ TransactionalEditingDomain editingDomain = getTransactionalEditingDomain();
+
+ RecordingCommand command = new RecordingCommand(editingDomain) {
+
+ @Override
+ protected void doExecute() {
+ pageMngr.removePage(pageIdentifier);
+
+ }
+ };
+
+ editingDomain.getCommandStack().execute(command);
+ }
+
+}
diff --git a/plugins/core/org.eclipse.papyrus.sasheditor/test/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/ContentChangeListener.java b/plugins/core/org.eclipse.papyrus.sasheditor/test/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/ContentChangeListener.java
new file mode 100644
index 00000000000..e8fd1266a7e
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.sasheditor/test/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/ContentChangeListener.java
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * Copyright (c) 2009 CEA LIST & LIFL
+ *
+ *
+ * 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.sasheditor.contentprovider.di.internal;
+
+import org.eclipse.papyrus.sasheditor.contentprovider.IContentChangedListener;
+
+/**
+ * Listener on ContentChange for Tests.
+ * @author dumoulin
+ */
+public class ContentChangeListener implements IContentChangedListener {
+
+ /** Count number of change event */
+ private int changeCount = 0;
+
+ /**
+ * @return the changeCount
+ */
+ public int getChangeCount() {
+ return changeCount;
+ }
+
+ public void contentChanged(ContentEvent event) {
+ changeCount++;
+ }
+
+ public void reset() {
+ changeCount=0;
+ }
+}
diff --git a/plugins/core/org.eclipse.papyrus.sasheditor/test/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/PageMngrImplTest.java b/plugins/core/org.eclipse.papyrus.sasheditor/test/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/PageMngrImplTest.java
new file mode 100644
index 00000000000..ef89d7fddb8
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.sasheditor/test/org/eclipse/papyrus/sasheditor/contentprovider/di/internal/PageMngrImplTest.java
@@ -0,0 +1,258 @@
+/*****************************************************************************
+ * Copyright (c) 2009 CEA LIST & LIFL
+ *
+ *
+ * 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.sasheditor.contentprovider.di.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.papyrus.sasheditor.contentprovider.di.IPageModelFactory;
+import org.eclipse.papyrus.sashwindows.di.PageRef;
+import org.eclipse.papyrus.sashwindows.di.SashModel;
+import org.eclipse.papyrus.sashwindows.di.SashWindowsMngr;
+import org.eclipse.papyrus.sashwindows.di.util.DiUtils;
+
+import junit.framework.TestCase;
+
+
+/**
+ * @author dumoulin
+ */
+public class PageMngrImplTest extends TestCase {
+
+ /**
+ * The {@link PageMngrImpl} under test.
+ */
+ protected PageMngrImpl pageMngr;
+ /**
+ * The associated {@link DiContentProvider}. Not tested, but used to check events.
+ */
+ protected DiContentProvider contentProvider;
+
+
+ /**
+ * @param name
+ */
+ public PageMngrImplTest(String name) {
+ super(name);
+ }
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ *
+ * @throws java.lang.Exception
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ SashWindowsMngr diSashModel = DiUtils.createDefaultSashWindowsMngr();
+ pageMngr = new PageMngrImpl(diSashModel);
+
+ IPageModelFactory pageModelFactory = new FakePageModelFactory();
+ contentProvider = new DiContentProvider(diSashModel.getSashModel(), pageModelFactory);
+
+ }
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ *
+ * @throws java.lang.Exception
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.sasheditor.contentprovider.di.internal.PageMngrImpl#addPage(org.eclipse.emf.ecore.EObject)}.
+ */
+ public void testAddPage() {
+ // A listener on change event.
+ ContentChangeListener changeListener = new ContentChangeListener();
+
+ // Set change listener
+ contentProvider.addContentChangedListener(changeListener);
+
+ // Add identifiers
+ // Use Object as identifiers.
+ List<Object> identifiers = new ArrayList<Object>();
+ // Add 10 folders
+ for(int i=0; i<10; i++)
+ {
+ // reset change count
+ changeListener.reset();
+ // Add Editor
+ Object id = new Object();
+ identifiers.add(id);
+ pageMngr.addPage(id);
+
+ // Check no fired events
+ assertEquals("One event fired", 0, changeListener.getChangeCount());
+ }
+
+ // Check if pages are in PageList
+ assertEquals("all pages added", 10, pageMngr.allPages().size() );
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.sasheditor.contentprovider.di.internal.PageMngrImpl#allPages()}.
+ */
+ public void testAllPages() {
+ // A listener on change event.
+ ContentChangeListener changeListener = new ContentChangeListener();
+
+ // Set change listener
+ contentProvider.addContentChangedListener(changeListener);
+
+ // Add identifiers
+ // Use Object as identifiers.
+ List<Object> identifiers = new ArrayList<Object>();
+ // Add 10 folders
+ for(int i=0; i<10; i++)
+ {
+ // reset change count
+ changeListener.reset();
+ // Add Editor
+ Object id = new Object();
+ identifiers.add(id);
+ pageMngr.openPage(id);
+
+ // Check fired events
+ assertEquals("One event fired", 1, changeListener.getChangeCount());
+ }
+ // Check if pages are in PageList
+ assertEquals("all pages found", 10, pageMngr.allPages().size() );
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.sasheditor.contentprovider.di.internal.PageMngrImpl#closePage(org.eclipse.emf.ecore.EObject)}.
+ */
+ public void testClosePage() {
+ // A listener on change event.
+ ContentChangeListener changeListener = new ContentChangeListener();
+
+ // Set change listener
+ contentProvider.addContentChangedListener(changeListener);
+
+ // Add identifiers
+ // Use Object as identifiers.
+ List<Object> identifiers = new ArrayList<Object>();
+ // Add 10 folders
+ for(int i=0; i<10; i++)
+ {
+ // reset change count
+ changeListener.reset();
+ // Add Editor
+ Object id = new Object();
+ identifiers.add(id);
+ pageMngr.openPage(id);
+
+ // Check fired events
+ assertEquals("One event fired", 1, changeListener.getChangeCount());
+ }
+ // Check if pages are in PageList
+ assertEquals("all pages added", 10, pageMngr.allPages().size() );
+
+ // Close page
+ pageMngr.closePage(identifiers.get(3));
+
+ // Check page still in pages
+ assertEquals("all pages still in list", 10, pageMngr.allPages().size() );
+
+ // Check if pages are in SashStructure
+ PageRef pageRef = contentProvider.getDiSashModel().lookupPage(identifiers.get(3));
+ assertNull("Page removed from sashStructure ", pageRef);
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.sasheditor.contentprovider.di.internal.PageMngrImpl#openPage(org.eclipse.emf.ecore.EObject)}.
+ */
+ public void testOpenPage() {
+ // A listener on change event.
+ ContentChangeListener changeListener = new ContentChangeListener();
+
+ // Set change listener
+ contentProvider.addContentChangedListener(changeListener);
+
+ // Add identifiers
+ // Use Object as identifiers.
+ List<Object> identifiers = new ArrayList<Object>();
+ // Add 10 folders
+ for(int i=0; i<10; i++)
+ {
+ // reset change count
+ changeListener.reset();
+ // Add Editor
+ Object id = new Object();
+ identifiers.add(id);
+ pageMngr.openPage(id);
+
+ // Check fired events
+ assertEquals("One event fired", 1, changeListener.getChangeCount());
+ }
+
+ // Check if pages are in PageList
+ assertEquals("all pages added", 10, pageMngr.allPages().size() );
+
+ // Check if pages are in SashStructure
+ PageRef pageRef = contentProvider.getDiSashModel().lookupPage(identifiers.get(3));
+ assertNotNull("Page exist in sashStructure ", pageRef);
+ assertSame("found the right page", identifiers.get(3), pageRef.getPageIdentifier());
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.sasheditor.contentprovider.di.internal.PageMngrImpl#removePage(org.eclipse.emf.ecore.EObject)}.
+ */
+ public void testRemovePage() {
+ // A listener on change event.
+ ContentChangeListener changeListener = new ContentChangeListener();
+
+ // Set change listener
+ contentProvider.addContentChangedListener(changeListener);
+
+ // Add identifiers
+ // Use Object as identifiers.
+ List<Object> identifiers = new ArrayList<Object>();
+ // Add 10 folders
+ for(int i=0; i<10; i++)
+ {
+ // reset change count
+ changeListener.reset();
+ // Add Editor
+ Object id = new Object();
+ identifiers.add(id);
+ pageMngr.openPage(id);
+
+ // Check fired events
+ assertEquals("One event fired", 1, changeListener.getChangeCount());
+ }
+ // Check if pages are in PageList
+ assertEquals("all pages added", 10, pageMngr.allPages().size() );
+
+ // Close page
+ pageMngr.removePage(identifiers.get(3));
+
+ // Check page still in pages
+ assertEquals("page remove from list", 9, pageMngr.allPages().size() );
+
+ // Check if pages are in SashStructure
+ PageRef pageRef = contentProvider.getDiSashModel().lookupPage(identifiers.get(3));
+ assertNull("Page removed from sashStructure ", pageRef);
+ }
+
+
+
+}
diff --git a/plugins/others/org.eclipse.papyrus.example.sashwindows.fulleditor/META-INF/MANIFEST.MF b/plugins/others/org.eclipse.papyrus.example.sashwindows.fulleditor/META-INF/MANIFEST.MF
index 8fa186633f0..e288dc822a4 100644
--- a/plugins/others/org.eclipse.papyrus.example.sashwindows.fulleditor/META-INF/MANIFEST.MF
+++ b/plugins/others/org.eclipse.papyrus.example.sashwindows.fulleditor/META-INF/MANIFEST.MF
@@ -10,6 +10,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.resources,
org.eclipse.ui.editors,
org.eclipse.ui.ide,
- org.eclipse.papyrus.sasheditor;bundle-version="0.7.0"
+ org.eclipse.papyrus.sasheditor;bundle-version="0.7.0",
+ org.eclipse.emf.ecore.xmi;bundle-version="2.5.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/plugins/others/org.eclipse.papyrus.example.sashwindows.fulleditor/src/org/eclipse/papyrus/example/sashwindows/fulleditor/editor/DiMultiTextEditor.java b/plugins/others/org.eclipse.papyrus.example.sashwindows.fulleditor/src/org/eclipse/papyrus/example/sashwindows/fulleditor/editor/DiMultiTextEditor.java
index 98e7d5aea49..0b892a48af1 100644
--- a/plugins/others/org.eclipse.papyrus.example.sashwindows.fulleditor/src/org/eclipse/papyrus/example/sashwindows/fulleditor/editor/DiMultiTextEditor.java
+++ b/plugins/others/org.eclipse.papyrus.example.sashwindows.fulleditor/src/org/eclipse/papyrus/example/sashwindows/fulleditor/editor/DiMultiTextEditor.java
@@ -14,8 +14,19 @@
package org.eclipse.papyrus.example.sashwindows.fulleditor.editor;
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.util.DiagnosticException;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.papyrus.example.sashwindows.fulleditor.texteditor.TextEditorPartModel;
import org.eclipse.papyrus.sasheditor.contentprovider.IContentChangedListener;
import org.eclipse.papyrus.sasheditor.contentprovider.IPageModel;
@@ -45,6 +56,9 @@ public class DiMultiTextEditor extends /*MultiPageEditor */ AbstractMultiPageSas
/** SashModelMngr to add pages */
protected DiSashModelMngr sashModelMngr;
+ /** Resource mngr to load and save model */
+ protected ResourceMngr resourceMngr;
+
/**
* A listener on model change events.
*/
@@ -55,6 +69,7 @@ public class DiMultiTextEditor extends /*MultiPageEditor */ AbstractMultiPageSas
*/
public void contentChanged(ContentEvent event) {
System.out.println("contentChanged()");
+ markDirty();
refreshTabs();
}
};
@@ -86,13 +101,22 @@ public class DiMultiTextEditor extends /*MultiPageEditor */ AbstractMultiPageSas
}
/**
+ * Mark the editor as dirty, and fire appropriate event.
+ */
+ protected void markDirty() {
+ isDirty = true;
+ firePropertyChange(PROP_DIRTY);
+ }
+
+ /**
* Create and initialize the pageProvider.
*/
protected ISashWindowsContentProvider createPageProvider()
{
IPageModelFactory pageFactory = new SimplePageModelFactory();
- sashModelMngr = new DiSashModelMngr(pageFactory);
+// sashModelMngr = new DiSashModelMngr(pageFactory, resourceMngr.getDiResource() );
+ sashModelMngr = new DiSashModelMngr(pageFactory );
ISashWindowsContentProvider pageProvider = sashModelMngr.getISashWindowsContentProvider();
@@ -126,6 +150,12 @@ public class DiMultiTextEditor extends /*MultiPageEditor */ AbstractMultiPageSas
// Reset dirty flag.
isDirty = false;
}
+
+// try {
+// resourceMngr.saveResource(monitor);
+// } catch (IOException e) {
+// e.printStackTrace();
+// }
}
/**
@@ -162,7 +192,13 @@ public class DiMultiTextEditor extends /*MultiPageEditor */ AbstractMultiPageSas
if (!(editorInput instanceof IFileEditorInput))
throw new PartInitException("Invalid Input: Must be IFileEditorInput");
super.init(site, editorInput);
+
+ // Load model
+// IFile file = ((IFileEditorInput) editorInput).getFile();
+// resourceMngr = new ResourceMngr();
+// resourceMngr.loadResource(file);
}
+
/* (non-Javadoc)
* Method declared on IEditorPart.
*/
@@ -187,4 +223,105 @@ public class DiMultiTextEditor extends /*MultiPageEditor */ AbstractMultiPageSas
}
}
+
+ /**
+ * A class managing a Resource.
+ * @author cedric dumoulin
+ */
+ public class ResourceMngr {
+ private static final String DI_FILE_EXTENSION = "di";
+ private ResourceSet resourceSet;
+ private Resource diResource;
+
+
+ /**
+ * Constructor.
+ */
+ public ResourceMngr() {
+ createResourceSet();
+ }
+
+ /**
+ * Return the resource used for DI model.
+ * @return
+ */
+ public Resource getDiResource() {
+ return diResource;
+ }
+
+ /**
+ * Create the resourceSet.
+ */
+ protected void createResourceSet() {
+
+ if(resourceSet != null)
+ return;
+
+ // Create di resource
+ resourceSet = new ResourceSetImpl();
+
+ // Register the default resource factory -- only needed for stand-alone!
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
+ Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
+
+ }
+
+ /**
+ * Load resource using name provided in file.
+ * @param file
+ */
+ public void loadResource(IFile file)
+ {
+ // Extract file name, without extension
+ IPath fullPath = file.getFullPath().removeFileExtension();
+
+ IPath filePath;
+ filePath = fullPath.addFileExtension(DI_FILE_EXTENSION);
+
+ URI uri = URI.createPlatformResourceURI( filePath.toString(), true);
+ try {
+ diResource = resourceSet.getResource(uri, true);
+ } catch (Exception e) {
+// diResource = resourceSet.createResource(uri);
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * Load resource using name provided in file.
+ * @param file
+ */
+ public void createResource(IFile file)
+ {
+ // Extract file name, without extension
+ IPath fullPath = file.getFullPath().removeFileExtension();
+
+ IPath filePath;
+ filePath = fullPath.addFileExtension(DI_FILE_EXTENSION);
+
+ URI uri = URI.createPlatformResourceURI( filePath.toString(), true);
+ diResource = resourceSet.createResource(uri);
+
+ }
+
+ /**
+ * Save Resource associated to this manager.
+ * @throws IOException
+ */
+ public void saveResource() throws IOException
+ {
+ diResource.save(null);
+ }
+
+ public void saveResource(IProgressMonitor monitor) throws IOException {
+ monitor.beginTask("Saving resources", 3);
+ monitor.worked(1);
+ saveResource();
+ monitor.worked(1);
+ monitor.done();
+ }
+
+
+ }
}

Back to the top