Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcdumoulin2009-06-15 22:35:11 +0000
committercdumoulin2009-06-15 22:35:11 +0000
commita7e42f5a02babab5730c4c7a5ee6cd135f1125df (patch)
tree339009fb3015c7da7974d2f74aad848a86fa5206
parentb231ab5449fed694d4bc1963e2a19341b07d7435 (diff)
downloadorg.eclipse.papyrus-a7e42f5a02babab5730c4c7a5ee6cd135f1125df.tar.gz
org.eclipse.papyrus-a7e42f5a02babab5730c4c7a5ee6cd135f1125df.tar.xz
org.eclipse.papyrus-a7e42f5a02babab5730c4c7a5ee6cd135f1125df.zip
ASSIGNED - bug 279226: [Sash System] Selected Active tab should follow user actions
https://bugs.eclipse.org/bugs/show_bug.cgi?id=279226 Added a new State in GarbageState : UNVISITED Also, keep track of created Part during syncronization. This allows to set the activePage with created track. Set the active page at the end of refreshTabs(). Move some common method in common ancestor.
-rw-r--r--org.eclipse.papyrus.core/src/org/eclipse/papyrus/core/multidiagram/actionbarcontributor/CoreComposedActionBarContributor.java8
-rw-r--r--org.eclipse.papyrus.sasheditor.di/src/org/eclipse/papyrus/sashwindows/di/impl/SashModelImpl.java94
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/editor/actionbarcontributor/ComposedActionBarContributor.java6
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/AbstractPanelPart.java30
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/AbstractPart.java20
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/ActiveEditorServicesSwitcher.java7
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/ComponentPart.java28
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/EditorPart.java33
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/PagePart.java40
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/PartLists.java53
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/RootPart.java5
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/SashPanelPart.java7
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/SashWindowsContainer.java47
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/TabFolderPart.java79
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/TabItemPart.java2
-rw-r--r--org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/eclipsecopy/AbstractTabFolderPart.java4
-rw-r--r--org.eclipse.papyrus.sasheditor/test/org/eclipse/papyrus/sasheditor/internal/SashWindowsContainerTest.java119
17 files changed, 493 insertions, 89 deletions
diff --git a/org.eclipse.papyrus.core/src/org/eclipse/papyrus/core/multidiagram/actionbarcontributor/CoreComposedActionBarContributor.java b/org.eclipse.papyrus.core/src/org/eclipse/papyrus/core/multidiagram/actionbarcontributor/CoreComposedActionBarContributor.java
index d00dc5c621a..863c2604241 100644
--- a/org.eclipse.papyrus.core/src/org/eclipse/papyrus/core/multidiagram/actionbarcontributor/CoreComposedActionBarContributor.java
+++ b/org.eclipse.papyrus.core/src/org/eclipse/papyrus/core/multidiagram/actionbarcontributor/CoreComposedActionBarContributor.java
@@ -69,7 +69,7 @@ public class CoreComposedActionBarContributor extends ComposedActionBarContribut
*/
public void dispose() {
- System.err.println("ActionBarContributor.dispose()" + this);
+ System.err.println( this.getClass().getSimpleName() + ".dispose()" );
// Dispose nested contributors.
for(EditorActionBarContributor contributor : contributors )
{
@@ -83,7 +83,7 @@ public class CoreComposedActionBarContributor extends ComposedActionBarContribut
*/
public void init(IActionBars bars, IWorkbenchPage page) {
- System.err.println("ActionBarContributor.init() - " + this);
+ System.err.println(this.getClass().getSimpleName() + ".init() ");
super.init(bars, page);
buildActions();
@@ -91,7 +91,7 @@ public class CoreComposedActionBarContributor extends ComposedActionBarContribut
// init nested contributors.
for(EditorActionBarContributor contributor : contributors )
{
- System.out.println(this.getClass().getSimpleName() + ".init() : " + contributor.getClass().getName());
+ System.out.println(this.getClass().getSimpleName() + ".init() - addSubContributor: " + contributor.getClass().getName());
contributor.init(bars, page);
}
@@ -109,7 +109,7 @@ public class CoreComposedActionBarContributor extends ComposedActionBarContribut
public void setActiveEditor(IEditorPart targetEditor) {
- System.err.println("ActionBarContributor.setActiveEditor(" + targetEditor + ") - " + this);
+ System.err.println( this.getClass().getSimpleName() + ".setActiveEditor(" + targetEditor + ") " );
super.setActiveEditor(targetEditor);
}
diff --git a/org.eclipse.papyrus.sasheditor.di/src/org/eclipse/papyrus/sashwindows/di/impl/SashModelImpl.java b/org.eclipse.papyrus.sasheditor.di/src/org/eclipse/papyrus/sashwindows/di/impl/SashModelImpl.java
index f6e361e6b87..62a0460943d 100644
--- a/org.eclipse.papyrus.sasheditor.di/src/org/eclipse/papyrus/sashwindows/di/impl/SashModelImpl.java
+++ b/org.eclipse.papyrus.sasheditor.di/src/org/eclipse/papyrus/sashwindows/di/impl/SashModelImpl.java
@@ -254,6 +254,95 @@ public class SashModelImpl extends EObjectImpl implements SashModel {
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
+ * TODO Add method to metamodel
+ * @generated NOT
+ */
+ public TabFolder lookupFirstFolder() {
+
+ // Create appropriate visitor.
+ DiSwitch<TabFolder> visitor = new DiSwitch<TabFolder>( ) {
+
+ /**
+ * Iterate over windows
+ * @see org.eclipse.papyrus.sashwindows.di.util.DiSwitch#caseSashModel(org.eclipse.papyrus.sashwindows.di.SashModel)
+ *
+ * @param object
+ * @return
+ */
+ public TabFolder caseSashModel(SashModel object) {
+ TabFolder res = null;
+ for( Window window : object.getWindows() )
+ {
+ res = this.doSwitch(window);
+ if(res != null)
+ return res;
+ }
+
+ return super.caseSashModel(object);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.sashwindows.di.util.DiSwitch#caseWindow(org.eclipse.papyrus.sashwindows.di.Window)
+ *
+ * @param object
+ * @return
+ */
+ public TabFolder caseWindow(Window window) {
+
+ AbstractPanel panel = window.getPanel();
+ if(panel == null)
+ return null;
+
+
+ TabFolder res = this.doSwitch(panel);
+ if(res != null)
+ return res;
+
+ return super.caseWindow(window);
+ }
+
+ /**
+ * Iterate over children
+ * @see org.eclipse.papyrus.sashwindows.di.util.DiSwitch#caseSashPanel(org.eclipse.papyrus.sashwindows.di.SashPanel)
+ *
+ * @param object
+ * @return
+ */
+ public TabFolder caseSashPanel(SashPanel object) {
+ TabFolder res = null;
+ for( AbstractPanel panel : object.getChildren() )
+ {
+ res = this.doSwitch(panel);
+ if(res != null)
+ return res;
+ }
+
+ return super.caseSashPanel(object);
+ }
+
+ /**
+ * Iterate over PageRef
+ * @see org.eclipse.papyrus.sashwindows.di.util.DiSwitch#caseTabFolder(org.eclipse.papyrus.sashwindows.di.TabFolder)
+ *
+ * @param object
+ * @return
+ */
+ public TabFolder caseTabFolder(TabFolder object) {
+ return object;
+ }
+
+ };
+
+ // Do lookup
+ TabFolder res = visitor.doSwitch(this);
+
+ return res;
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
* @generated NOT
*/
public void movePage(TabFolder srcParentFolder, int srcIndex, TabFolder targetParentFolder, int targetIndex) {
@@ -353,6 +442,11 @@ public class SashModelImpl extends EObjectImpl implements SashModel {
// Parent is a sash. Ask it to remove the child and itself
((SashPanel)parent).delete(folder);
+ // adjust current selection if the old folder was the currentSelection
+ if(getCurrentSelection() == folder)
+ {
+ setCurrentSelection(lookupFirstFolder());
+ }
}
/**
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/editor/actionbarcontributor/ComposedActionBarContributor.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/editor/actionbarcontributor/ComposedActionBarContributor.java
index 6b2ec31fe88..63707f435b9 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/editor/actionbarcontributor/ComposedActionBarContributor.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/editor/actionbarcontributor/ComposedActionBarContributor.java
@@ -77,9 +77,9 @@ public class ComposedActionBarContributor extends MultiPageEditorActionBarContri
activeNestedEditor = activeEditor;
-// System.out.println(this.getClass().getSimpleName()
-// + ".setActivePage(" + activeEditor
-// + ") :" + getActiveContributor() );
+ System.out.println(this.getClass().getSimpleName()
+ + ".setActivePage(" + activeEditor
+ + ") :" + getActiveContributor() );
// Propagate call if possible
// Call setActiveEditor() on nested contributor.
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/AbstractPanelPart.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/AbstractPanelPart.java
index 627e24eab8d..1777f7f1e39 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/AbstractPanelPart.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/AbstractPanelPart.java
@@ -14,6 +14,7 @@
package org.eclipse.papyrus.sasheditor.internal;
+import org.eclipse.papyrus.sasheditor.internal.AbstractPart.GarbageState;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.internal.dnd.IDropTarget;
@@ -80,7 +81,34 @@ public abstract class AbstractPanelPart extends AbstractPart {
* {@link GarbageState.ORPHANED}.
* This method as no effect if the Tile has already been reparented.
*/
- abstract public void orphan();
+ public void orphan() {
+ // orphan only if we are in UNCHANGED state
+ if (garbageState == GarbageState.UNVISITED) {
+ garbageState = GarbageState.ORPHANED;
+ parent = null;
+ }
+ }
+
+
+ /**
+ * Mark this Page as UNCHANGED.
+ * The PAge should be in the COLLECTED state.
+ *
+ * @see
+ * @return the parent
+ */
+ public void unchanged() {
+ // orphan only if we are in COLLECTED state
+ if (garbageState == GarbageState.UNVISITED || garbageState == GarbageState.ORPHANED ) {
+ garbageState = GarbageState.UNCHANGED;
+ }
+ else
+ {
+ // Bad state, this is an internal error
+ // TODO : log a warning ?
+ throw new IllegalStateException("Try to change state from "+ garbageState.toString() + " to UNCHANGED. This is forbidden.");
+ }
+ }
/**
* Change the parent of the Part. The parent is changed, and the control is
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/AbstractPart.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/AbstractPart.java
index b3f9e5842f3..6b2c95bc739 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/AbstractPart.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/AbstractPart.java
@@ -27,10 +27,19 @@ public abstract class AbstractPart {
/**
* Enumeration used when the parts are synchronized.
+ * <ul>
+ * <li>UNVISITED - The part not yet visited. This is the initial state when synchronizing. The part
+ * can stay in this state after synchronization if one of its parent is ORPHANED.</li>
+ * <li>ORPHANED - The part is orphaned from its direct parent.</li>
+ * <li>REPARENTED - The part parent has changed</li>
+ * <li>CREATED - The part is newly created</li>
+ * <li>UNCHANGED - The part is visited, and its parent is unchanged.</li>
+ * </ul>
*/
public enum GarbageState {
- UNCHANGED, ORPHANED, REPARENTED, CREATED
+ UNVISITED, ORPHANED, REPARENTED, CREATED, UNCHANGED
}
+
/**
* The main container.
@@ -75,6 +84,15 @@ public abstract class AbstractPart {
}
/**
+ * Return true if the page state == {@link GarbageState#UNVISITED}.
+ * @return
+ */
+ public boolean isUnchecked() {
+
+ return garbageState == GarbageState.UNVISITED;
+ }
+
+ /**
* @return
*/
public GarbageState getGarbageState() {
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/ActiveEditorServicesSwitcher.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/ActiveEditorServicesSwitcher.java
index 18c21e9a561..87abd208f10 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/ActiveEditorServicesSwitcher.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/ActiveEditorServicesSwitcher.java
@@ -114,13 +114,13 @@ public class ActiveEditorServicesSwitcher implements IActiveEditorChangedListene
public void activeEditorChanged(PagePart oldEditor, PagePart newEditor)
{
- System.out.println(getClass().getSimpleName()+ ".activeEditorChange('"+ newEditor.getPartTitle()+"')");
+ System.out.println(getClass().getSimpleName()+ ".activeEditorChange('"+ (newEditor!=null?newEditor.getPartTitle():"null") +"')");
activeEditor = newEditor;
// Set focus
IPartService partService = (IPartService) getOuterEditorSite().getService(IPartService.class);
- if (partService.getActivePart() == getOuterEditorSite().getPart()) {
+ if (newEditor!=null && partService.getActivePart() == getOuterEditorSite().getPart()) {
newEditor.setFocus();
}
@@ -131,7 +131,8 @@ public class ActiveEditorServicesSwitcher implements IActiveEditorChangedListene
activateServices();
//
- newEditor.setFocus();
+ if (newEditor!=null )
+ newEditor.setFocus();
}
/**
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/ComponentPart.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/ComponentPart.java
index 818e37d776c..c35618ba0ca 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/ComponentPart.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/ComponentPart.java
@@ -269,23 +269,6 @@ public class ComponentPart extends PagePart {
return null;
}
- /**
- * Orphan this node. The parent is set to null, but control is left unchanged.
- * The node can be reattached with reparent(). Change garbage state to
- * {@link GarbageState.ORPHANED}.
- * This method as no effect if the Tile has already been reparented.
- *
- * @see
- * @return the parent
- */
- public void orphan() {
- // orphan only if we are in UNCHANGED state
- if (garbageState == GarbageState.UNCHANGED) {
- garbageState = GarbageState.ORPHANED;
- parent = null;
- }
- }
-
/**
* Change the parent of the Tile. The parent is changed, and the control is
@@ -303,7 +286,18 @@ public class ComponentPart extends PagePart {
this.parent = newParent;
// Change the SWT parent.
editorControl.setParent(newParent.getControl());
+
+ // Change state
+ if(garbageState == GarbageState.UNVISITED || garbageState == GarbageState.ORPHANED )
+ {
garbageState = GarbageState.REPARENTED;
+ }
+ else
+ {
+ // Bad state, this is an internal error
+ // TODO : log a warning ?
+ throw new IllegalStateException("Try to change state from "+ garbageState.toString() + " to REPARENTED. This is forbidden.");
+ }
}
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/EditorPart.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/EditorPart.java
index bd1bd39b5bb..0201706d85c 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/EditorPart.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/EditorPart.java
@@ -32,6 +32,7 @@ import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.internal.ErrorEditorPart;
import org.eclipse.ui.internal.dnd.IDropTarget;
import org.eclipse.ui.part.EditorActionBarContributor;
import org.eclipse.ui.part.IWorkbenchPartOrientation;
@@ -152,6 +153,8 @@ public class EditorPart extends PagePart {
} catch (PartInitException e) {
Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e));
// TODO Create a fake Error Page and initialize this part with.
+// editorPart = new ErrorEditorPart();
+// editorControl = createEditorPartControl(parent, editorPart);
editorControl = createErrorPartControl(parent, e);
}
catch (Exception e) {
@@ -446,24 +449,6 @@ public class EditorPart extends PagePart {
/**
- * Orphan this node. The parent is set to null, but control is left unchanged.
- * The node can be reattached with reparent(). Change garbage state to
- * {@link GarbageState.ORPHANED}.
- * This method as no effect if the Tile has already been reparented.
- *
- * @see
- * @return the parent
- */
- public void orphan() {
- // orphan only if we are in UNCHANGED state
- if (garbageState == GarbageState.UNCHANGED) {
- garbageState = GarbageState.ORPHANED;
- parent = null;
- }
- }
-
-
- /**
* Change the parent of the Tile. The parent is changed, and the control is
* attached to the parent control. Change garbage state to {@link GarbageState.REPARENTED}.
* Do not detach the Tile from its old parent.
@@ -479,7 +464,19 @@ public class EditorPart extends PagePart {
this.parent = newParent;
// Change the SWT parent.
editorControl.setParent(newParent.getControl());
+
+ // Change state
+ if(garbageState == GarbageState.UNVISITED || garbageState == GarbageState.ORPHANED )
+ {
garbageState = GarbageState.REPARENTED;
+ }
+ else
+ {
+ // Bad state, this is an internal error
+ // TODO : log a warning ?
+ throw new IllegalStateException("Try to change state from "+ garbageState.toString() + " to REPARENTED. This is forbidden.");
+ }
+
}
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/PagePart.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/PagePart.java
index febdab1da95..68ffa40b207 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/PagePart.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/PagePart.java
@@ -13,6 +13,7 @@
*****************************************************************************/
package org.eclipse.papyrus.sasheditor.internal;
+import org.eclipse.papyrus.sasheditor.internal.AbstractPart.GarbageState;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
@@ -52,9 +53,41 @@ public abstract class PagePart extends AbstractPart {
}
/**
- * Orphan this part.
+ * Orphan this node. The parent is set to null, but control is left unchanged.
+ * The node can be reattached with reparent(). Change garbage state to
+ * {@link GarbageState.ORPHANED}.
+ * This method as no effect if the Page has already been reparented.
+ *
+ * @see
+ * @return the parent
+ */
+ public void orphan() {
+ // orphan only if we are in COLLECTED state
+ if (garbageState == GarbageState.UNVISITED) {
+ garbageState = GarbageState.ORPHANED;
+ parent = null;
+ }
+ }
+
+ /**
+ * Mark this Page as UNCHANGED.
+ * The PAge should be in the COLLECTED state.
+ *
+ * @see
+ * @return the parent
*/
- abstract public void orphan() ;
+ public void unchanged() {
+ // orphan only if we are in COLLECTED state
+ if (garbageState == GarbageState.UNVISITED || garbageState == GarbageState.ORPHANED ) {
+ garbageState = GarbageState.UNCHANGED;
+ }
+ else
+ {
+ // Bad state, this is an internal error
+ // TODO : log a warning ?
+ throw new IllegalStateException("Try to change state from "+ garbageState.toString() + " to UNCHANGED. This is forbidden.");
+ }
+ }
/**
* Visit this part.
@@ -105,7 +138,7 @@ public abstract class PagePart extends AbstractPart {
*/
public void fillPartMap(PartLists partMap) {
partMap.addLeaf(this);
- garbageState = GarbageState.UNCHANGED;
+ garbageState = GarbageState.UNVISITED;
}
/**
@@ -158,4 +191,5 @@ public abstract class PagePart extends AbstractPart {
return this.rawModel == realModel;
}
+
}
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/PartLists.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/PartLists.java
index 7bcbfc7329f..480f9a4ca59 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/PartLists.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/PartLists.java
@@ -22,9 +22,9 @@ import org.eclipse.papyrus.sasheditor.sash.ITilePart;
/**
* This class contains lists of parts, regardless of the part parents.
- * There is two lists: one for the pane Parts and one for the Leaf Parts.
- * This class is used when refreshing the SashesContainer: a new instance is created
- * and filled with existing parts. Then the list is carried with each pane refresh methods.
+ * There are two lists: one for the pane Parts and one for the Page Parts (leafs).
+ * This class is used when refreshing the SashContainer: a new instance is created
+ * and filled with existing parts. Then the list is carried in each pane refresh method.
*
* @author cedric dumoulin
*/
@@ -32,6 +32,8 @@ public class PartLists {
private List<PagePart> pageParts = new ArrayList<PagePart>();
private List<AbstractPanelPart> panelParts = new ArrayList<AbstractPanelPart>();
+ /** List of created pages during synchronization */
+ private List<PagePart> createdPages /*= new ArrayList<PagePart>()*/;
/**
* Search for a Part associated to the specified newModel.
@@ -99,6 +101,51 @@ public class PartLists {
part.garbage();
}
}
+
+ /**
+ * Get the first non orphaned page, or null if none exists.
+ * @return a valid active page, or null if none exists.
+ */
+ public PagePart getFirstValidPage() {
+ // Remove orphaned part (no more used)
+ for (PagePart part : pageParts) {
+ if (! part.isOrphaned())
+ return part;
+ }
+
+ // No page
+ return null;
+ }
+
+ /**
+ * Get the first created page if any.
+ * @return a valid active page, or null if none exists.
+ */
+ public PagePart getFirstCreatedPage() {
+
+ if(createdPages == null)
+ return null;
+
+ if( createdPages.size()>0)
+ return createdPages.get(0);
+
+ // No page
+ return null;
+ }
+
+ /**
+ * Add a PagePart to the list of created Page.
+ * This is called from the TabFolder when a new page is created.
+ * @param modelPart
+ */
+ public void addCreatedPage(PagePart newPage) {
+
+ if(createdPages == null)
+ createdPages = new ArrayList<PagePart>();
+
+ createdPages.add(newPage);
+
+ }
}
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/RootPart.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/RootPart.java
index b0f98073ca8..4b337f67096 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/RootPart.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/RootPart.java
@@ -159,7 +159,10 @@ public class RootPart extends AbstractPart implements IPanelParent {
if (child != null) {
// If the tile is already for the model, there is nothing to do.
if (child.isPartFor(rawModel))
+ {
+ child.unchanged();
return;
+ }
// The current tile is not for the model: mark it as orphan
child.orphan();
}
@@ -270,7 +273,7 @@ public class RootPart extends AbstractPart implements IPanelParent {
* @see org.eclipse.papyrus.sasheditor.sash.ITilePart#getGarbageState()
*/
public GarbageState getGarbageState() {
- return GarbageState.UNCHANGED;
+ return GarbageState.UNVISITED;
}
/**
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/SashPanelPart.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/SashPanelPart.java
index 5a805201112..ee240f7a85b 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/SashPanelPart.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/SashPanelPart.java
@@ -88,7 +88,7 @@ public class SashPanelPart extends AbstractPanelPart implements IPanelParent {
for (AbstractPanelPart child : currentChildParts) {
child.fillPartMap(partMap);
}
- garbageState = GarbageState.UNCHANGED;
+ garbageState = GarbageState.UNVISITED;
}
/**
@@ -205,7 +205,7 @@ public class SashPanelPart extends AbstractPanelPart implements IPanelParent {
public void orphan() {
// orphan only if we are in UNCHANGED state
- if (garbageState == GarbageState.UNCHANGED) {
+ if (garbageState == GarbageState.UNVISITED) {
garbageState = GarbageState.ORPHANED;
parent = null;
}
@@ -397,7 +397,10 @@ public class SashPanelPart extends AbstractPanelPart implements IPanelParent {
if (currentChildPart != null) {
// If the tile is already for the model, there is nothing to do.
if (currentChildPart.isPartFor(newModel))
+ {
+ currentChildPart.unchanged();
return;
+ }
// The current tile is not for the model: mark it as orphan
currentChildPart.orphan();
}
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/SashWindowsContainer.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/SashWindowsContainer.java
index e4f41d72104..d9249171f59 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/SashWindowsContainer.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/SashWindowsContainer.java
@@ -183,7 +183,7 @@ public class SashWindowsContainer {
* @param childPart
*/
protected void setActivePage(PagePart childPart) {
- System.out.println("pageChangedEvent("+childPart+")");
+// System.out.println("setActivePage("+childPart+")");
pageChanged(childPart);
}
@@ -281,6 +281,10 @@ public class SashWindowsContainer {
System.out.println("start synchronize2() ------------------------");
showTilesStatus();
+ // Get the currently selected folder
+ PagePart oldActivePage = getActivePage();
+
+ // Do refresh
container.setRedraw(false);
// Create map of parts
// PartMap<T> partMap = new PartMap<T>();
@@ -294,6 +298,9 @@ public class SashWindowsContainer {
// Remove orphaned parts (no more used)
garbageMaps.garbage();
+ // set active page if needed
+ setActivePage( checkAndGetActivePage(oldActivePage, garbageMaps) );
+
// Reenable SWT and force layout
container.setRedraw(true);
container.layout(true, true);
@@ -302,6 +309,44 @@ public class SashWindowsContainer {
}
/**
+ * Check if the oldActivePage still alive, and set it if needed.
+ * If the oldActivePage is null, set an active page if one exist.
+ * If the oldActivePage still alive, let it as the active one. If it is
+ * disposed, get arbitrarily an active page if one exist.
+ *
+ * @param oldActivePage
+ * @param partLists
+ * @param garbageMaps
+ * @return A valid active page or null if none exists.
+ */
+ private PagePart checkAndGetActivePage(PagePart oldActivePage, PartLists partLists) {
+
+ // Check if there is a created page
+ PagePart activePage = partLists.getFirstCreatedPage();
+ if(activePage != null)
+ return activePage;
+
+ // Check oldActivePage validity (in case it has been deleted)
+ if( oldActivePage != null && ! (oldActivePage.isOrphaned() || oldActivePage.isUnchecked() ) )
+ return oldActivePage;
+
+ // Get an active page if any
+ return lookupFirstValidPage();
+ }
+
+ /**
+ * Lookup for a valid active Page. Return null if none is found.
+ * TODO Use a visitor to implements this method.
+ * @return
+ */
+ private PagePart lookupFirstValidPage() {
+ // First get a list of active editors
+ PartLists garbageMaps = new PartLists();
+ rootPart.fillPartMap(garbageMaps);
+ return garbageMaps.getFirstValidPage();
+ }
+
+ /**
* Show the status of the different Tiles composing the sash system.
* Used for debug purpose.
*/
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/TabFolderPart.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/TabFolderPart.java
index bbfe059029a..881f640c1a8 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/TabFolderPart.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/TabFolderPart.java
@@ -184,7 +184,7 @@ public class TabFolderPart extends AbstractTabFolderPart {
*/
public void fillPartMap(PartLists partMap) {
partMap.addPart(this);
- garbageState = GarbageState.UNCHANGED;
+ garbageState = GarbageState.UNVISITED;
for( TabItemPart child : currentTabItems)
{
@@ -214,11 +214,11 @@ public class TabFolderPart extends AbstractTabFolderPart {
* @param pageModel
* @param index
*/
- private void addPage(Object pageModel)
- {
- int index = currentTabItems.size();
- createTabItem(pageModel, index);
- }
+// private void addPage(Object pageModel)
+// {
+// int index = currentTabItems.size();
+// createTabItem(pageModel, index);
+// }
/**
* Create the control for this Part. Does not create children.
@@ -234,7 +234,7 @@ public class TabFolderPart extends AbstractTabFolderPart {
}
/**
- * The page has change. Propagate the event.
+ * The page has change. Propagate the event to the container.
* @param newPageIndex
*/
@Override
@@ -585,9 +585,10 @@ public class TabFolderPart extends AbstractTabFolderPart {
*/
public void orphan() {
// orphan only if we are in UNCHANGED state
- if (garbageState == GarbageState.UNCHANGED) {
+ if (garbageState == GarbageState.UNVISITED) {
garbageState = GarbageState.ORPHANED;
parent = null;
+
}
}
@@ -670,6 +671,11 @@ public class TabFolderPart extends AbstractTabFolderPart {
// end
activePageIndex = index;
}
+ else
+ {
+ // Change curTab state
+ curTab.getChildPart().unchanged();
+ }
}
// Check for extra tabs or extra models
@@ -723,7 +729,20 @@ public class TabFolderPart extends AbstractTabFolderPart {
setActivePage(activePageIndex);
}
else
- System.err.println("Active page not set while synchronizing !");
+ {
+ // Check if there is item in the CTabFolder.
+ // If true, we have a trouble
+ if(getTabFolder().getItemCount()>0)
+ {
+// System.err.println("Active page not set while synchronizing !");
+ // We have items, but none is selected.
+ // Select the first one.
+ if( getTabFolder().getSelectionIndex() <0 )
+ {
+ setActivePage(0);
+ }
+ }
+ }
// folder.update();
// folder.showSelection();
@@ -764,6 +783,7 @@ public class TabFolderPart extends AbstractTabFolderPart {
{
// No part found, create one
modelPart = createChildPart( newModel );
+ existingParts.addCreatedPage(modelPart);
// Attach it to the tabItem
newTab = new TabItemPart(this, modelPart, index);
}
@@ -773,26 +793,26 @@ public class TabFolderPart extends AbstractTabFolderPart {
}
- /**
- * Create a new TabItem and associated part corresponding to the specified newModel.
- * The TabItem is created at the specified index.
- * The associated parts is created.
- *
- * @param existingParts List of existing parts.
- * @param newModel
- * @param index
- * @param i
- */
- private void createTabItem(Object newModel, int index) {
- TabItemPart newTab;
-
- PagePart modelPart = createChildPart( newModel );
- // Attach it to the tabItem
- newTab = new TabItemPart(this, modelPart, index);
-
- // Add to the list of items.
- currentTabItems.add(index, newTab);
- }
+// /**
+// * Create a new TabItem and associated part corresponding to the specified newModel.
+// * The TabItem is created at the specified index.
+// * The associated parts is created.
+// *
+// * @param existingParts List of existing parts.
+// * @param newModel
+// * @param index
+// * @param i
+// */
+// private void createTabItem(Object newModel, int index) {
+// TabItemPart newTab;
+//
+// PagePart modelPart = createChildPart( newModel );
+// // Attach it to the tabItem
+// newTab = new TabItemPart(this, modelPart, index);
+//
+// // Add to the list of items.
+// currentTabItems.add(index, newTab);
+// }
/**
* Instruct the specified tabItem to use the new model. Check if a part already exist for the model
@@ -814,6 +834,7 @@ public class TabFolderPart extends AbstractTabFolderPart {
{
// No part found, create one
modelPart = createChildPart( newModel );
+ existingParts.addCreatedPage(modelPart);
// Attach it to the tabItem
tabItem.resetChild(modelPart);
}
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/TabItemPart.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/TabItemPart.java
index 61d9cbc4aee..2b6554f5a58 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/TabItemPart.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/TabItemPart.java
@@ -129,7 +129,7 @@ public class TabItemPart {
public void fillPartMap(PartLists partMap) {
childPart.fillPartMap(partMap);
- garbageState = GarbageState.UNCHANGED;
+ garbageState = GarbageState.UNVISITED;
}
/**
diff --git a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/eclipsecopy/AbstractTabFolderPart.java b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/eclipsecopy/AbstractTabFolderPart.java
index 49d1d6e1c3e..ca7b5c9a3c8 100644
--- a/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/eclipsecopy/AbstractTabFolderPart.java
+++ b/org.eclipse.papyrus.sasheditor/src2/org/eclipse/papyrus/sasheditor/internal/eclipsecopy/AbstractTabFolderPart.java
@@ -137,7 +137,7 @@ public abstract class AbstractTabFolderPart extends AbstractPanelPart {
// }
/**
- * Returns the index of the currently active page, or -1 if there is no active page.
+ * Returns the index of the currently active page of this folder, or -1 if there is no active page.
* <p>
* Subclasses should not override this method
* </p>
@@ -438,7 +438,7 @@ public abstract class AbstractTabFolderPart extends AbstractPanelPart {
// }
/**
- * Sets the currently active page.
+ * Sets the currently active page for this folder.
*
* @param pageIndex
* the index of the page to be activated; the index must be valid
diff --git a/org.eclipse.papyrus.sasheditor/test/org/eclipse/papyrus/sasheditor/internal/SashWindowsContainerTest.java b/org.eclipse.papyrus.sasheditor/test/org/eclipse/papyrus/sasheditor/internal/SashWindowsContainerTest.java
new file mode 100644
index 00000000000..070c24c4626
--- /dev/null
+++ b/org.eclipse.papyrus.sasheditor/test/org/eclipse/papyrus/sasheditor/internal/SashWindowsContainerTest.java
@@ -0,0 +1,119 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.sasheditor.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageModel;
+import org.eclipse.papyrus.sasheditor.contentprovider.ISashWindowsContentProvider;
+import org.eclipse.papyrus.sasheditor.contentprovider.simple.FakePageModel;
+import org.eclipse.papyrus.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider;
+import org.eclipse.papyrus.sasheditor.editor.ShellEditor;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+import junit.framework.TestCase;
+
+
+/**
+ * @author dumoulin
+ *
+ */
+public class SashWindowsContainerTest extends TestCase {
+
+
+ protected Display display;
+
+ /**
+ * Constructor.
+ * @param name
+ */
+ public SashWindowsContainerTest(String name) {
+ super(name);
+ }
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ * @throws java.lang.Exception
+ *
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ display = new Display();
+
+ }
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ * @throws java.lang.Exception
+ *
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ display.dispose();
+ }
+
+ /**
+ * 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);
+ contentProvider = new SimpleSashWindowsContentProvider();
+ SashWindowsContainer sashWindowContainer= new SashWindowsContainer();
+
+ sashWindowContainer.setContentProvider(contentProvider);
+
+ sashWindowContainer.createPartControl(shell);
+// shell.open();
+ return sashWindowContainer;
+ }
+
+ /**
+ * Create a contentProvider.
+ * @return
+ */
+ protected ISashWindowsContentProvider createContentProvider()
+ {
+ SimpleSashWindowsContentProvider contentProvider = new SimpleSashWindowsContentProvider();
+
+ // Create pages and add them to the default folder
+ List<IPageModel> models = new ArrayList<IPageModel>();
+ for(int i=0; i<8; i++)
+ {
+ IPageModel newModel = new FakePageModel("model"+i);
+ contentProvider.addPage(newModel);
+ models.add(newModel);
+ }
+
+ return contentProvider;
+ }
+ /**
+ * Test method for {@link org.eclipse.papyrus.sasheditor.internal.SashWindowsContainer#getActiveEditor()}.
+ */
+ public void testGetActiveEditor() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.sasheditor.internal.SashWindowsContainer#refreshTabs()}.
+ */
+ public void testRefreshTabs() {
+
+ ISashWindowsContentProvider contentProvider = createContentProvider();
+ SashWindowsContainer container = createSashWindowsContainer(contentProvider);
+
+ container.refreshTabs();
+ assertNotNull("container is set", container);
+ }
+
+}

Back to the top