diff options
| author | pguilet | 2017-07-18 09:54:13 +0000 |
|---|---|---|
| committer | Pierre Guilet | 2017-07-31 12:26:15 +0000 |
| commit | e420bc0104bcefa6835828b055a6dae23623792c (patch) | |
| tree | 1ce6b6db5ff59349ca170bd4befa9417c4b98cc4 | |
| parent | 3b0f264c64d712c03581302271cddbea0e393c16 (diff) | |
| download | org.eclipse.sirius-e420bc0104bcefa6835828b055a6dae23623792c.tar.gz org.eclipse.sirius-e420bc0104bcefa6835828b055a6dae23623792c.tar.xz org.eclipse.sirius-e420bc0104bcefa6835828b055a6dae23623792c.zip | |
[518524] Add deferred refresh and command execution
Aird editor custom pages now can tell the editor to be called for
refresh and page update only when it has focus.
Bug: 518524
Change-Id: Ic141540d1cab6e1fcf8dc83f6cfcbdd5ed09cd5e
Signed-off-by: pguilet <pierre.guilet@obeo.fr>
10 files changed, 252 insertions, 82 deletions
diff --git a/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/pages/DebugPage.java b/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/pages/DebugPage.java index 4bbf77462e..eada1587d0 100644 --- a/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/pages/DebugPage.java +++ b/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/pages/DebugPage.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.sirius.ui.debug.pages; +import java.util.Optional; + import org.eclipse.emf.transaction.ResourceSetChangeEvent; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.sirius.business.api.session.Session; @@ -64,18 +66,23 @@ public class DebugPage extends AbstractSessionEditorPage { } @Override - public String getLocationId() { - return DefaultSessionEditorPage.PAGE_ID; + public Optional<String> getLocationId() { + return Optional.of(DefaultSessionEditorPage.PAGE_ID); + } + + @Override + public Optional<PositioningKind> getPositioning() { + return Optional.of(PositioningKind.AFTER); } @Override - public PositioningKind getPositioning() { - return PositioningKind.AFTER; + public Optional<PageUpdateCommand> resourceSetChanged(ResourceSetChangeEvent resourceSetChangeEvent) { + return Optional.empty(); } @Override - public PageUpdateCommand notifyAndGetUpdateCommands(ResourceSetChangeEvent resourceSetChangeEvent) { - return null; + public Optional<PageUpdateCommand> pageChanged(boolean isVisible) { + return Optional.empty(); } } diff --git a/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/pages/DebugPageProvider.java b/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/pages/DebugPageProvider.java index d0575a665f..dcb26df6ee 100644 --- a/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/pages/DebugPageProvider.java +++ b/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/pages/DebugPageProvider.java @@ -38,4 +38,8 @@ public class DebugPageProvider extends PageProvider { return resultMap; } + @Override + public boolean provides(String pageId) { + return DebugPage.PAGE_ID.equals(pageId); + } } diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditor.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditor.java index 8f507c360d..85c797fbc6 100644 --- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditor.java +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditor.java @@ -12,8 +12,10 @@ package org.eclipse.sirius.ui.editor; import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.EventObject; import java.util.List; +import java.util.Optional; import java.util.Vector; import java.util.stream.Collectors; @@ -29,6 +31,7 @@ import org.eclipse.emf.common.command.CommandStackListener; import org.eclipse.emf.common.ui.URIEditorInput; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.transaction.NotificationFilter; import org.eclipse.emf.transaction.ResourceSetChangeEvent; import org.eclipse.emf.transaction.ResourceSetListenerImpl; import org.eclipse.jface.dialogs.ErrorDialog; @@ -93,14 +96,21 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp @Override public void resourceSetChanged(ResourceSetChangeEvent event) { int pageCount = SessionEditor.this.getPageCount(); + List<Runnable> commandsToExecute = new ArrayList<>(); for (int i = 0; i < pageCount; i++) { Object page = SessionEditor.this.pages.get(i); if (page instanceof AbstractSessionEditorPage) { AbstractSessionEditorPage customPage = (AbstractSessionEditorPage) page; - PageUpdateCommand updateCommand = customPage.notifyAndGetUpdateCommands(event); - executeUpdateCommands(customPage, updateCommand); + Optional<NotificationFilter> notificationFilter = customPage.getFilterForPageRequesting(); + boolean providePages = event.getNotifications().stream().anyMatch(notification -> notificationFilter.isPresent() ? true : notificationFilter.get().matches(notification)); + if (providePages) { + Optional<PageUpdateCommand> updateCommand = customPage.resourceSetChanged(event); + commandsToExecute.addAll(prepareUpdateCommands(customPage, updateCommand)); + } } } + executeCommands(commandsToExecute); + updatePages(event); } @Override @@ -145,17 +155,31 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp @Override protected void addPages() { - updatePages(); + updatePages(null); + } + + /** + * Execute the given command in UI thread. + * + * @param commandsToExecute + * the commands to execute. + */ + private void executeCommands(List<Runnable> commandsToExecute) { + PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { + commandsToExecute.stream().forEach(Runnable::run); + }); } /** * Remove obsolete page, add new pages and reorder all pages currently * displayed like the new list. * + * @param event + * */ - private void updatePages() { + private void updatePages(ResourceSetChangeEvent event) { List<AbstractSessionEditorPage> newOrderedPages = pageRegistry.getPagesOrdered(this, session, - pages.stream().filter(AbstractSessionEditorPage.class::isInstance).map(AbstractSessionEditorPage.class::cast).collect(Collectors.toList())); + pages.stream().filter(AbstractSessionEditorPage.class::isInstance).map(AbstractSessionEditorPage.class::cast).collect(Collectors.toList()), event); CTabFolder cTabF = (CTabFolder) this.getContainer(); IFormPage activePage = getActivePageInstance(); @@ -252,12 +276,31 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp @Override public void pageProviderChanged() { - updatePages(); + updatePages(null); } @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { super.init(site, input); + this.addPageChangedListener(event -> { + Object selectedPage = event.getSelectedPage(); + if (selectedPage instanceof AbstractSessionEditorPage) { + AbstractSessionEditorPage theSelectedPage = (AbstractSessionEditorPage) selectedPage; + Optional<PageUpdateCommand> selectedPageCommand = theSelectedPage.pageChanged(true); + List<Runnable> commandsToExecute = new ArrayList<>(); + commandsToExecute.addAll(prepareUpdateCommands(theSelectedPage, selectedPageCommand)); + for (Object page : pages) { + if (page instanceof AbstractSessionEditorPage) { + AbstractSessionEditorPage sessionEditorPage = (AbstractSessionEditorPage) page; + if (sessionEditorPage.getIndex() != theSelectedPage.getIndex()) { + Optional<PageUpdateCommand> pageCommand = sessionEditorPage.pageChanged(false); + commandsToExecute.addAll(prepareUpdateCommands(sessionEditorPage, pageCommand)); + } + } + } + executeCommands(commandsToExecute); + } + }); IEditorInput editorInput = this.getEditorInput(); URI sessionResourceURI = null; if (editorInput instanceof FileEditorInput) { @@ -467,36 +510,39 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp } /** - * Execute the given {@link PageUpdateCommand}. If a remove command is - * present, other update command will be ignored. + * Prepare all commands as {@link Runnable} from the given + * {@link PageUpdateCommand}. If a remove command is present, other update + * command will be ignored. * * @param customPage * the page updated. * @param updateCommand * the commands this editor must execute to update the page. */ - private void executeUpdateCommands(AbstractSessionEditorPage customPage, PageUpdateCommand updateCommand) { - if (updateCommand != null) { + private List<Runnable> prepareUpdateCommands(AbstractSessionEditorPage customPage, Optional<PageUpdateCommand> updateCommand) { + List<Runnable> runnables = new ArrayList<>(2); + updateCommand.ifPresent(updateCommandTemp -> { boolean removeCommandExecuted = false; - if (updateCommand.getRemoveCommand() != null) { - executeRemoveCommand(updateCommand.getRemoveCommand(), SessionEditor.this, customPage); + if (updateCommandTemp.getRemoveCommand() != null) { + runnables.add(prepareRemoveCommand(updateCommandTemp.getRemoveCommand(), SessionEditor.this, customPage)); removeCommandExecuted = true; } - if (!removeCommandExecuted && updateCommand.getReorderCommand() != null) { - executeReorderCommand(updateCommand.getReorderCommand(), SessionEditor.this, customPage); + if (!removeCommandExecuted && updateCommandTemp.getReorderCommand() != null) { + runnables.add(prepareReorderCommand(updateCommandTemp.getReorderCommand(), SessionEditor.this, customPage)); } else { SessionEditorPlugin.getPlugin().error(MessageFormat.format(Messages.SessionEditor_PageCommand_Integrity_Error, customPage.getClass().getName()), null); } - if (!removeCommandExecuted && updateCommand.getRenameCommand() != null) { - executeRenameCommand(updateCommand.getRenameCommand(), SessionEditor.this, customPage); + if (!removeCommandExecuted && updateCommandTemp.getRenameCommand() != null) { + runnables.add(prepareRenameCommand(updateCommandTemp.getRenameCommand(), SessionEditor.this, customPage)); } else { SessionEditorPlugin.getPlugin().error(MessageFormat.format(Messages.SessionEditor_PageCommand_Integrity_Error, customPage.getClass().getName()), null); } - } + }); + return runnables; } /** - * Execute the reorder command. + * Prepare the reorder command by returning a {@link Runnable}. * * @param pageUpdateCommand * the command to execute containing execution information. @@ -505,13 +551,12 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp * @param page * the page reordered. */ - private void executeReorderCommand(ReorderPageCommand pageUpdateCommand, SessionEditor editor, AbstractSessionEditorPage page) { - PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { + private Runnable prepareReorderCommand(ReorderPageCommand pageUpdateCommand, SessionEditor editor, AbstractSessionEditorPage page) { + return () -> { Composite container = editor.getContainer(); if (container instanceof CTabFolder) { CTabFolder tabFolder = (CTabFolder) editor.getContainer(); IFormPage activePage = editor.getActivePageInstance(); - int targetPageIndex = -1; String targetPageId = pageUpdateCommand.getTargetPageId(); for (Object object : pages) { @@ -520,7 +565,6 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp break; } } - int commandingPageIndex = pages.indexOf(page); if (commandingPageIndex != -1 && targetPageIndex != -1) { switch (pageUpdateCommand.getPositioningKind()) { @@ -549,12 +593,12 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp editor.setFocus(); editor.setActivePage(activePage); } - }); - + }; } /** - * Execute the page removal command for the given page. + * Prepare the page removal command for the given page by returning a + * {@link Runnable}. * * @param pageUpdateCommand * the command containing removal information. @@ -563,14 +607,15 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp * @param page * the page that will be removed from editor. */ - private void executeRemoveCommand(RemovePageCommand pageUpdateCommand, SessionEditor editor, AbstractSessionEditorPage page) { - PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { + private Runnable prepareRemoveCommand(RemovePageCommand pageUpdateCommand, SessionEditor editor, AbstractSessionEditorPage page) { + return () -> { editor.removePage(editor.pages.indexOf(page)); - }); + }; } /** - * Execute the tab renaming command for the given page. + * Prepare the tab renaming command for the given page by returning a + * {@link Runnable}. * * @param pageUpdateCommand * the command containing rename information. @@ -579,8 +624,8 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp * @param page * the page that will have its tab renamed. */ - private void executeRenameCommand(RenameTabLabelCommand pageUpdateCommand, SessionEditor editor, AbstractSessionEditorPage page) { - PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { + private Runnable prepareRenameCommand(RenameTabLabelCommand pageUpdateCommand, SessionEditor editor, AbstractSessionEditorPage page) { + return () -> { Composite container = editor.getContainer(); if (container instanceof CTabFolder) { Vector<Object> pages = editor.pages; @@ -592,6 +637,6 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp tabFolder.getParent().layout(); } } - }); + }; } } diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/AbstractSessionEditorPage.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/AbstractSessionEditorPage.java index 63a6b9e422..e7876e4457 100644 --- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/AbstractSessionEditorPage.java +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/AbstractSessionEditorPage.java @@ -11,7 +11,11 @@ package org.eclipse.sirius.ui.editor.api.pages; +import java.util.Optional; + +import org.eclipse.emf.transaction.NotificationFilter; import org.eclipse.emf.transaction.ResourceSetChangeEvent; +import org.eclipse.sirius.ui.editor.SessionEditor; import org.eclipse.sirius.ui.editor.api.pages.PageProviderRegistry.PositioningKind; import org.eclipse.sirius.ui.editor.api.pages.PageUpdateCommandBuilder.PageUpdateCommand; import org.eclipse.ui.forms.editor.FormEditor; @@ -57,31 +61,73 @@ public abstract class AbstractSessionEditorPage extends FormPage { * page. * * @return the id of the page to take in consideration when positioning this - * page. + * page. {@link Optional#empty()} if no positioning is provided. */ - public abstract String getLocationId(); + public abstract Optional<String> getLocationId(); /** * Returns the kind of positioning to apply regarding the target page * returned by {@link AbstractSessionEditorPage#getLocationId()}. * * @return the kind of positioning to apply regarding the target page - * returned by {@link AbstractSessionEditorPage#getLocationId()}. + * returned by + * {@link AbstractSessionEditorPage#getLocationId()}.{@link Optional#empty()} + * if no positioning is provided. */ - public abstract PositioningKind getPositioning(); + public abstract Optional<PositioningKind> getPositioning(); /** - * This method notifies when a {@link ResourceSetChangeEvent} occurs on - * the*session's resource set of the session editor containing your page. If - * some* change must be done to the page at editor'slevel, you can return a - * list*of {@link PageUpdateCommand}to do so. The command must be provided - * by* using the factory {@link PageUpdateCommand }.** + * This method notifies you when a {@link ResourceSetChangeEvent} occurs on + * the session's resource set of the session editor containing your page. If + * some changes must be done to the page at editor's level, you can return a + * {@link PageUpdateCommand} built with {@link PageUpdateCommandBuilder} to + * do so. * * @param resourceSetChangeEvent - * the event that occurred.*@return an optional - * {@link PageUpdateCommand} the editor should execute.* It can - * be null. + * the event that occurred. + * @return an {@link PageUpdateCommand} the editor should execute. + * {@link Optional#empty()} if no update should be done. + */ + public abstract Optional<PageUpdateCommand> resourceSetChanged(ResourceSetChangeEvent resourceSetChangeEvent); + + /** + * Notifies the page that its visibility status has changed. You can return + * a {@link PageUpdateCommand} built with {@link PageUpdateCommandBuilder} + * if a page update must be done from session editor owning this page. + * + * The method is call with the parameter isVisible to true when the page tab + * is selected. + * + * The method is call with the parameter isVisible to false when any page + * tab except the one of this page is selected. + * + * + * @param isVisible + * true if the page has just been made visible. I.e page tab has + * been clicked. False if the page has just been made invisible. + * I.e another page tab has been clicked. + * @return a {@link PageUpdateCommand} built with + * {@link PageUpdateCommandBuilder} if a page update must be done + * from session editor owning this page. {@link Optional#empty()} if + * no update must be done. */ - public abstract PageUpdateCommand notifyAndGetUpdateCommands(ResourceSetChangeEvent resourceSetChangeEvent); + public abstract Optional<PageUpdateCommand> pageChanged(boolean isVisible); + + /** + * Returns a filter that will reduce the call to the method + * {@link PageProvider#getPages(SessionEditor)} for better performances. + * Without the filter, the method is called when any resource set event + * occurs on the editor's session. + * + * By default, the {@link NotificationFilter#NOT_TOUCH} filter is provided. + * + * @return a filter that will reduce the call to the method + * {@link PageProvider#getPages(SessionEditor)} for better + * performances. {@link Optional#empty()} if no filtering should be + * done. + */ + public Optional<NotificationFilter> getFilterForPageRequesting() { + return Optional.of(NotificationFilter.NOT_TOUCH); + } } diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/DefaultSessionEditorPage.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/DefaultSessionEditorPage.java index 18785e6691..eac346ead5 100644 --- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/DefaultSessionEditorPage.java +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/DefaultSessionEditorPage.java @@ -13,6 +13,7 @@ package org.eclipse.sirius.ui.editor.api.pages; import java.net.MalformedURLException; import java.net.URL; import java.text.MessageFormat; +import java.util.Optional; import java.util.stream.Collectors; import org.eclipse.core.resources.IProject; @@ -382,17 +383,23 @@ public class DefaultSessionEditorPage extends AbstractSessionEditorPage implemen } @Override - public String getLocationId() { - return null; + public Optional<String> getLocationId() { + return Optional.empty(); } @Override - public PositioningKind getPositioning() { - return null; + public Optional<PositioningKind> getPositioning() { + return Optional.empty(); } @Override - public PageUpdateCommand notifyAndGetUpdateCommands(ResourceSetChangeEvent resourceSetChangeEvent) { - return null; + public Optional<PageUpdateCommand> resourceSetChanged(ResourceSetChangeEvent resourceSetChangeEvent) { + return Optional.empty(); } + + @Override + public Optional<PageUpdateCommand> pageChanged(boolean isVisible) { + return Optional.empty(); + } + } diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/PageProvider.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/PageProvider.java index 9860d85e75..7f1997f9d4 100644 --- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/PageProvider.java +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/PageProvider.java @@ -13,6 +13,7 @@ package org.eclipse.sirius.ui.editor.api.pages; import java.util.Map; import java.util.function.Supplier; +import org.eclipse.emf.transaction.NotificationFilter; import org.eclipse.sirius.ui.editor.SessionEditor; import org.eclipse.ui.part.MultiPageEditorPart; @@ -39,4 +40,31 @@ public abstract class PageProvider { * in a multi-page editor. */ public abstract Map<String, Supplier<AbstractSessionEditorPage>> getPages(SessionEditor editor); + + /** + * Returns a filter that will reduce the call to the method + * {@link PageProvider#getPages(SessionEditor)} for better performances. + * Without the filter, the method is called when any resource set event + * occurs on the editor's session. + * + * By default, the {@link NotificationFilter#NOT_TOUCH} filter is provided. + * + * @return a filter that will reduce the call to the method + * {@link PageProvider#getPages(SessionEditor)} for better + * performances. + */ + public NotificationFilter getFilterForPageRequesting() { + return NotificationFilter.NOT_TOUCH; + } + + /** + * Returns true if this provider provides pages with the given id. + * + * @param pageId + * the page's id from which we want to know if this provider + * provides pages with this id. + * @return true if this provider provides pages with the given id. False + * otherwise. + */ + public abstract boolean provides(String pageId); } diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/PageProviderRegistry.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/PageProviderRegistry.java index 7f6b827122..a52d512742 100644 --- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/PageProviderRegistry.java +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/PageProviderRegistry.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; +import org.eclipse.emf.transaction.ResourceSetChangeEvent; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.ui.editor.SessionEditor; import org.eclipse.sirius.ui.editor.internal.pages.PageOrderer; @@ -139,13 +140,15 @@ public class PageProviderRegistry { * the aird editor's session from which page request is done. * @param displayedPages * pages already dysplayed by the editor. + * @param event + * the event triggering the call to this method. Can be null. * @return a list of {@link AbstractSessionEditorPage} in the order computed * from all their location information retrieved from their parent * creators {@link PageProvider}. Obsolete pages are not returned. * New available pages fitting current context are returned. */ - public List<AbstractSessionEditorPage> getPagesOrdered(SessionEditor editor, Session session, List<AbstractSessionEditorPage> displayedPages) { - List<AbstractSessionEditorPage> pagesOrdered = pageOrderer.getOrderedPages(pageProviders, editor, displayedPages); + public List<AbstractSessionEditorPage> getPagesOrdered(SessionEditor editor, Session session, List<AbstractSessionEditorPage> displayedPages, ResourceSetChangeEvent event) { + List<AbstractSessionEditorPage> pagesOrdered = pageOrderer.getOrderedPages(pageProviders, editor, displayedPages, event); return pagesOrdered; } diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/PageUpdateCommandBuilder.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/PageUpdateCommandBuilder.java index f2646c6d66..69f4af52b9 100644 --- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/PageUpdateCommandBuilder.java +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/PageUpdateCommandBuilder.java @@ -30,7 +30,7 @@ public class PageUpdateCommandBuilder { * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> * */ - public class PageUpdateCommand { + public final class PageUpdateCommand { /** * This command remove the page providing it from its editor. */ @@ -46,6 +46,9 @@ public class PageUpdateCommandBuilder { */ ReorderPageCommand reorderCommand; + private PageUpdateCommand() { + } + /** * Returns the command to remove the page providing it from its editor. * diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/DefaultPageProvider.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/DefaultPageProvider.java index 912b1264f2..faa712a3ac 100644 --- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/DefaultPageProvider.java +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/DefaultPageProvider.java @@ -36,4 +36,9 @@ public class DefaultPageProvider extends PageProvider { }); return resultMap; } + + @Override + public boolean provides(String pageId) { + return DefaultSessionEditorPage.PAGE_ID.equals(pageId); + } } diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/PageOrderer.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/PageOrderer.java index bc2f07121c..4a081184dd 100644 --- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/PageOrderer.java +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/PageOrderer.java @@ -11,16 +11,21 @@ package org.eclipse.sirius.ui.editor.internal.pages; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.Set; import java.util.function.Supplier; import java.util.stream.Collectors; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.transaction.NotificationFilter; +import org.eclipse.emf.transaction.ResourceSetChangeEvent; import org.eclipse.sirius.ui.editor.SessionEditor; import org.eclipse.sirius.ui.editor.api.pages.AbstractSessionEditorPage; import org.eclipse.sirius.ui.editor.api.pages.PageProvider; @@ -99,14 +104,17 @@ public class PageOrderer { * * @param alreadyInitializedPages * the pages the editor currently contains. + * @param event + * the event triggering the call to this method. Can be null. * @return all pages the caller should display in the order defined by all * their positioning information. */ - public List<AbstractSessionEditorPage> getOrderedPages(List<PageProvider> pageProviders, SessionEditor editor, List<AbstractSessionEditorPage> alreadyInitializedPages) { + public List<AbstractSessionEditorPage> getOrderedPages(List<PageProvider> pageProviders, SessionEditor editor, List<AbstractSessionEditorPage> alreadyInitializedPages, + ResourceSetChangeEvent event) { List<AbstractSessionEditorPage> pagesToKeep = new ArrayList<>(); List<PagePositioning> pagePositioningElements = new ArrayList<>(); Map<String, PagePositioning> pageIdToPageMap = new HashMap<>(); - initializePagePositioning(pageProviders, editor, alreadyInitializedPages, pagesToKeep, pagePositioningElements, pageIdToPageMap); + initializePagePositioning(pageProviders, editor, alreadyInitializedPages, pagesToKeep, pagePositioningElements, pageIdToPageMap, event); positionPagesRegardingOthers(pagePositioningElements, pageIdToPageMap); Set<PagePositioning> replacedPages = new HashSet<>(); replacePages(pagePositioningElements, pageIdToPageMap, replacedPages); @@ -262,26 +270,38 @@ public class PageOrderer { * @param pageIdToPageMap * a map of page id to the corresponding {@link PagePositioning} * containing a page to display in the given editor. + * @param event + * the event triggering the call to this method. Can be null. */ private void initializePagePositioning(List<PageProvider> pageProviders, SessionEditor editor, List<AbstractSessionEditorPage> alreadyInitializedPages, List<AbstractSessionEditorPage> pagesToKeep, - List<PagePositioning> pagePositioningElements, Map<String, PagePositioning> pageIdToPageMap) { + List<PagePositioning> pagePositioningElements, Map<String, PagePositioning> pageIdToPageMap, ResourceSetChangeEvent event) { Set<String> alreadyInitializedPagesId = alreadyInitializedPages.stream().map(page -> page.getId()).collect(Collectors.toSet()); for (PageProvider pageProvider : pageProviders) { - Map<String, Supplier<AbstractSessionEditorPage>> pagesToAdd = pageProvider.getPages(editor); - if (pagesToAdd != null) { - // For each page provided by the provider we initialize a - // PagePositionning defining the page and the location it - // should have regarding other page. - for (Entry<String, Supplier<AbstractSessionEditorPage>> pageEntry : pagesToAdd.entrySet()) { - if (!alreadyInitializedPagesId.contains(pageEntry.getKey())) { - AbstractSessionEditorPage page = pageEntry.getValue().get(); - PositioningKind positioningKind = page.getPositioning(); - String locationId = page.getLocationId(); - PagePositioning pagePositioning = new PagePositioning(); - pageIdToPageMap.put(page.getId(), pagePositioning); - pagePositioningElements.add(pagePositioning); - setPortsId(positioningKind, locationId, pagePositioning); - pagePositioning.page = page; + List<Notification> notifications = event != null ? event.getNotifications() : Collections.emptyList(); + NotificationFilter filterForInitialCondition = pageProvider.getFilterForPageRequesting(); + boolean providePages = notifications.isEmpty() + || notifications.stream().anyMatch(notification -> filterForInitialCondition == null ? true : filterForInitialCondition.matches(notification)); + if (providePages) { + Map<String, Supplier<AbstractSessionEditorPage>> pagesToAdd = pageProvider.getPages(editor); + if (pagesToAdd != null) { + // For each page provided by the provider we initialize a + // PagePositionning defining the page and the location it + // should have regarding other page. + for (Entry<String, Supplier<AbstractSessionEditorPage>> pageEntry : pagesToAdd.entrySet()) { + if (!alreadyInitializedPagesId.contains(pageEntry.getKey())) { + AbstractSessionEditorPage page = pageEntry.getValue().get(); + + PagePositioning pagePositioning = new PagePositioning(); + pageIdToPageMap.put(page.getId(), pagePositioning); + pagePositioningElements.add(pagePositioning); + Optional<PositioningKind> positioningKind = page.getPositioning(); + Optional<String> locationId = page.getLocationId(); + if (positioningKind.isPresent() && locationId.isPresent()) { + setPortsId(positioningKind.get(), locationId.get(), pagePositioning); + } + pagePositioning.page = page; + + } } } } @@ -290,13 +310,15 @@ public class PageOrderer { // should be kept, we ask this provider to know if some // additional already initialized pages should be kept. for (AbstractSessionEditorPage page : alreadyInitializedPages) { - if (pagesToAdd.get(page.getId()) != null) { + if (pageProvider.provides(page.getId())) { pagesToKeep.add(page); - PositioningKind positioningKind = page.getPositioning(); - String locationId = page.getLocationId(); PagePositioning pagePositioning = new PagePositioning(); pageIdToPageMap.put(page.getId(), pagePositioning); - setPortsId(positioningKind, locationId, pagePositioning); + Optional<PositioningKind> positioningKind = page.getPositioning(); + Optional<String> locationId = page.getLocationId(); + if (positioningKind.isPresent() && locationId.isPresent()) { + setPortsId(positioningKind.get(), locationId.get(), pagePositioning); + } pagePositioning.page = page; pagePositioningElements.add(pagePositioning); } |
