diff options
| author | pguilet | 2017-07-17 13:27:03 +0000 |
|---|---|---|
| committer | Pierre Guilet | 2017-07-26 11:51:46 +0000 |
| commit | be0a34ef16906ab4f0e725d814223a229992751a (patch) | |
| tree | baf3b919911c99b1b426a6e664d292e425073702 | |
| parent | 149bc6d7f89a04e924e4038f949a4338c74a4a17 (diff) | |
| download | org.eclipse.sirius-be0a34ef16906ab4f0e725d814223a229992751a.tar.gz org.eclipse.sirius-be0a34ef16906ab4f0e725d814223a229992751a.tar.xz org.eclipse.sirius-be0a34ef16906ab4f0e725d814223a229992751a.zip | |
[518524] Adds command API to update pages dynamically
A new API allows custom page providers to tell aird editors owning their
pages to either refresh the page's tab, to remove it or to reorder it to
a new location when a resource set event of the session behind the
editor occurs.
Bug: 518524
Change-Id: Id681ac5c3ede24faffa80896ce6376f24e03bf5e
Signed-off-by: pguilet <pierre.guilet@obeo.fr>
14 files changed, 596 insertions, 49 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 d30b575623..4bbf77462e 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,12 +10,14 @@ *******************************************************************************/ package org.eclipse.sirius.ui.debug.pages; +import org.eclipse.emf.transaction.ResourceSetChangeEvent; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.ui.editor.SessionEditor; import org.eclipse.sirius.ui.editor.api.pages.AbstractSessionEditorPage; import org.eclipse.sirius.ui.editor.api.pages.DefaultSessionEditorPage; import org.eclipse.sirius.ui.editor.api.pages.PageProviderRegistry.PositioningKind; +import org.eclipse.sirius.ui.editor.api.pages.PageUpdateCommandBuilder.PageUpdateCommand; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; @@ -43,16 +45,6 @@ public class DebugPage extends AbstractSessionEditorPage { this.session = editor.getSession(); } - /* - * (non-Javadoc) - * @see org.eclipse.ui.forms.editor.FormPage#dispose() - */ - @Override - public void dispose() { - // TODO Auto-generated method stub - super.dispose(); - } - @Override protected void createFormContent(IManagedForm managedForm) { super.createFormContent(managedForm); @@ -81,4 +73,9 @@ public class DebugPage extends AbstractSessionEditorPage { return PositioningKind.AFTER; } + @Override + public PageUpdateCommand notifyAndGetUpdateCommands(ResourceSetChangeEvent resourceSetChangeEvent) { + return null; + } + } 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 9b5e0feb64..d0575a665f 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 @@ -17,7 +17,6 @@ import java.util.function.Supplier; import org.eclipse.sirius.ui.editor.SessionEditor; import org.eclipse.sirius.ui.editor.api.pages.AbstractSessionEditorPage; -import org.eclipse.sirius.ui.editor.api.pages.DefaultSessionEditorPage; import org.eclipse.sirius.ui.editor.api.pages.PageProvider; /** @@ -33,7 +32,7 @@ public class DebugPageProvider extends PageProvider { @Override public Map<String, Supplier<AbstractSessionEditorPage>> getPages(SessionEditor editor) { Map<String, Supplier<AbstractSessionEditorPage>> resultMap = new HashMap<>(); - resultMap.put(DefaultSessionEditorPage.PAGE_ID, () -> { + resultMap.put(DebugPage.PAGE_ID, () -> { return new DebugPage(editor, DebugPage.PAGE_ID, DEBUG_PAGE_TITLE); }); return resultMap; diff --git a/plugins/org.eclipse.sirius.ui.editor/plugin.properties b/plugins/org.eclipse.sirius.ui.editor/plugin.properties index 9bb46ce4e2..456fadea1c 100644 --- a/plugins/org.eclipse.sirius.ui.editor/plugin.properties +++ b/plugins/org.eclipse.sirius.ui.editor/plugin.properties @@ -38,4 +38,5 @@ GraphicalSemanticModelsHandler_addModelButton_tooltip=Add model DefaultSessionEditorPage_closeSession_action_label=Unload models DefaultSessionEditorPage_closeSession_action_tooltip=Unload models and close all associated editors DefaultSessionEditorPage_selectFilterAction_tooltip=Customize view... -DefaultSessionEditorPage_collapseAllAction_tooltip=Collapse all
\ No newline at end of file +DefaultSessionEditorPage_collapseAllAction_tooltip=Collapse all +SessionEditor_PageCommand_Integrity_Error=Some page update commands from page {0} were ignored because a remove command was executed first and thus no update can be done anymore. diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/Messages.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/Messages.java index 1669295f31..974866d73c 100644 --- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/Messages.java +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/Messages.java @@ -97,6 +97,9 @@ public final class Messages { @TranslatableMessage public static String GraphicalSemanticModelsHandler_addModelButton_tooltip; + @TranslatableMessage + public static String SessionEditor_PageCommand_Integrity_Error; + // CHECKSTYLE:ON private Messages() { 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 b54fc2e5e3..8f507c360d 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 @@ -14,6 +14,7 @@ import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.EventObject; import java.util.List; +import java.util.Vector; import java.util.stream.Collectors; import org.eclipse.core.resources.IFile; @@ -28,6 +29,8 @@ 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.ResourceSetChangeEvent; +import org.eclipse.emf.transaction.ResourceSetListenerImpl; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.sirius.business.api.modelingproject.ModelingProject; import org.eclipse.sirius.business.api.session.Session; @@ -38,12 +41,18 @@ import org.eclipse.sirius.ui.business.api.session.IEditingSession; import org.eclipse.sirius.ui.business.api.session.SessionUIManager; import org.eclipse.sirius.ui.editor.api.pages.AbstractSessionEditorPage; import org.eclipse.sirius.ui.editor.api.pages.PageProviderRegistry; +import org.eclipse.sirius.ui.editor.api.pages.PageUpdateCommandBuilder.PageUpdateCommand; import org.eclipse.sirius.ui.editor.internal.pages.PageProviderListener; +import org.eclipse.sirius.ui.editor.internal.pages.RemovePageCommand; +import org.eclipse.sirius.ui.editor.internal.pages.RenameTabLabelCommand; +import org.eclipse.sirius.ui.editor.internal.pages.ReorderPageCommand; import org.eclipse.sirius.ui.tools.api.views.modelexplorerview.IModelExplorerView; import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.TabItem; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorSite; @@ -74,6 +83,33 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; */ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedPropertySheetPageContributor, IModelExplorerView, SessionListener, ISiriusEditor, PageProviderListener { /** + * This listener listens to any change in the session's resource set and + * notifies all pages when such change happens. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ + private final class SessionResourceSetListener extends ResourceSetListenerImpl { + @Override + public void resourceSetChanged(ResourceSetChangeEvent event) { + int pageCount = SessionEditor.this.getPageCount(); + 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); + } + } + } + + @Override + public boolean isPostcommitOnly() { + return true; + } + } + + /** * The editor's id. */ public static final String EDITOR_ID = "org.eclipse.sirius.ui.editor.session"; //$NON-NLS-1$ @@ -101,6 +137,12 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp */ private PageProviderRegistry pageRegistry; + /** + * This listener listens to any change in the session's resource set and + * notifies all pages when such change happens. + */ + private SessionResourceSetListener resourceSetListener; + @Override protected void addPages() { updatePages(); @@ -122,16 +164,7 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp int pageIndex = pages.indexOf(page); if (pageIndex != -1) { if (pageIndex != i) { - // page already exists so we reuse its control in a new - // tab to avoid loosing states like expanded items. - cTabF.getItem(pageIndex).dispose(); - pages.remove(pageIndex); - page.setIndex(i); - - CTabItem item = new CTabItem(cTabF, SWT.NONE, i); - item.setText(page.getTitle()); - item.setControl(page.getPartControl()); - pages.add(i, page); + updatePageTabPosition(cTabF, page, pageIndex, i); } } else { try { @@ -152,6 +185,61 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp } cTabF.getParent().layout(); + setActivePage(activePage); + } + + /** + * Update the page tab position at the given original index to the new + * target index. + * + * @param cTabF + * the {@link CTabFolder} containing the {@link TabItem}. + * @param page + * the page associated to the tab item to update. + * @param originalPositionIndex + * the position index of the tab item to update. + * @param targetPositionIndex + * the target index the tab item should have. the + * + * + */ + private void updatePageTabPosition(CTabFolder cTabF, AbstractSessionEditorPage page, int originalPositionIndex, int targetPositionIndex) { + // page already exists so we reuse its control in a new + // tab to avoid loosing states like expanded items. + cTabF.getItem(originalPositionIndex).dispose(); + pages.remove(originalPositionIndex); + + CTabItem item = new CTabItem(cTabF, SWT.NONE, targetPositionIndex); + item.setText(page.getTitle()); + item.setControl(page.getPartControl()); + pages.add(targetPositionIndex, page); + + updatePageIndices(0); + } + + /** + * Update page indices. + * + * @param start + * start index from which index updating is done. + */ + private void updatePageIndices(int start) { + for (int i = start; i < pages.size(); i++) { + Object page = pages.get(i); + if (page instanceof IFormPage) { + IFormPage fpage = (IFormPage) page; + fpage.setIndex(i); + } + } + } + + /** + * Set the given page as this editor active page if such page exists. + * + * @param activePage + * the page to set as the active page of this editor. + */ + public void setActivePage(IFormPage activePage) { if (activePage != null) { int activePageIndex = pages.indexOf(activePage); if (activePageIndex != -1) { @@ -183,11 +271,9 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp ErrorDialog.openError(getSite().getShell(), MessageFormat.format(Messages.UI_SessionEditor_session_loading_error_message, new Object[0]), MessageFormat.format(Messages.UI_SessionEditor_inputNotHandled_error_message, editorInput.getClass().getSimpleName()), Status.CANCEL_STATUS); } - try { if (sessionResourceURI != null) { final URI sessionResourceURIFinal = sessionResourceURI; - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(sessionResourceURIFinal.toPlatformString(true))); IProject project = file.getProject(); if (ModelingProject.hasModelingProjectNature(project)) { @@ -199,12 +285,10 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp setPartName(sessionResourceURIFinal.lastSegment()); setContentDescription(sessionResourceURIFinal.toPlatformString(true)); } - // until we find a way to load session independently from the // editor, session loading blocks the editor opening with a // progress monitor. PlatformUI.getWorkbench().getProgressService().busyCursorWhile((monitor) -> { - SubMonitor subMonitor = SubMonitor.convert(monitor, 1); subMonitor.beginTask(MessageFormat.format(Messages.UI_SessionEditor_session_loading_task_title, new Object[0]), 1); session = SessionManager.INSTANCE.getSession(sessionResourceURIFinal, subMonitor); @@ -216,6 +300,9 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp editingSession.open(); editingSession.attachEditor(this); + resourceSetListener = new SessionResourceSetListener(); + session.getTransactionalEditingDomain().addResourceSetListener(resourceSetListener); + subMonitor.worked(1); subMonitor.done(); }); @@ -254,6 +341,10 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp pageRegistry.removeRegistryListener(this); pageRegistry = null; } + if (resourceSetListener != null && session != null && session.getTransactionalEditingDomain() != null) { + session.getTransactionalEditingDomain().removeResourceSetListener(resourceSetListener); + resourceSetListener = null; + } if (session != null) { final IEditingSession editingSession = SessionUIManager.INSTANCE.getUISession(session); if (editingSession != null) { @@ -374,4 +465,133 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp public Session getSession() { return session; } + + /** + * Execute 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) { + boolean removeCommandExecuted = false; + if (updateCommand.getRemoveCommand() != null) { + executeRemoveCommand(updateCommand.getRemoveCommand(), SessionEditor.this, customPage); + removeCommandExecuted = true; + } + if (!removeCommandExecuted && updateCommand.getReorderCommand() != null) { + executeReorderCommand(updateCommand.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); + } else { + SessionEditorPlugin.getPlugin().error(MessageFormat.format(Messages.SessionEditor_PageCommand_Integrity_Error, customPage.getClass().getName()), null); + } + } + } + + /** + * Execute the reorder command. + * + * @param pageUpdateCommand + * the command to execute containing execution information. + * @param editor + * the editor calling for a page reordering. + * @param page + * the page reordered. + */ + private void executeReorderCommand(ReorderPageCommand pageUpdateCommand, SessionEditor editor, AbstractSessionEditorPage page) { + PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { + 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) { + if (object instanceof AbstractSessionEditorPage && targetPageId.equals(((AbstractSessionEditorPage) object).getId())) { + targetPageIndex = ((AbstractSessionEditorPage) object).getIndex(); + break; + } + } + + int commandingPageIndex = pages.indexOf(page); + if (commandingPageIndex != -1 && targetPageIndex != -1) { + switch (pageUpdateCommand.getPositioningKind()) { + case AFTER: + if (targetPageIndex + 1 != commandingPageIndex) { + updatePageTabPosition(tabFolder, page, commandingPageIndex, targetPageIndex); + } + break; + case BEFORE: + if (commandingPageIndex + 1 != targetPageIndex) { + updatePageTabPosition(tabFolder, page, commandingPageIndex, targetPageIndex); + } + break; + case REPLACE: + editor.removePage(targetPageIndex); + commandingPageIndex = pages.indexOf(page); + int targetPageIndexAfterRemoval = targetPageIndex > 0 && targetPageIndex >= pages.size() ? targetPageIndex - 1 : targetPageIndex; + updatePageTabPosition(tabFolder, page, commandingPageIndex, targetPageIndexAfterRemoval); + break; + default: + break; + } + } + tabFolder.getParent().redraw(); + tabFolder.getParent().layout(); + editor.setFocus(); + editor.setActivePage(activePage); + } + }); + + } + + /** + * Execute the page removal command for the given page. + * + * @param pageUpdateCommand + * the command containing removal information. + * @param editor + * the editor calling for a page removal.. + * @param page + * the page that will be removed from editor. + */ + private void executeRemoveCommand(RemovePageCommand pageUpdateCommand, SessionEditor editor, AbstractSessionEditorPage page) { + PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { + editor.removePage(editor.pages.indexOf(page)); + }); + } + + /** + * Execute the tab renaming command for the given page. + * + * @param pageUpdateCommand + * the command containing rename information. + * @param editor + * the editor calling for a page tab renaming. + * @param page + * the page that will have its tab renamed. + */ + private void executeRenameCommand(RenameTabLabelCommand pageUpdateCommand, SessionEditor editor, AbstractSessionEditorPage page) { + PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { + Composite container = editor.getContainer(); + if (container instanceof CTabFolder) { + Vector<Object> pages = editor.pages; + int index = pages.indexOf(page); + if (index != -1) { + CTabFolder tabFolder = (CTabFolder) container; + CTabItem tabItem = tabFolder.getItem(index); + tabItem.setText(pageUpdateCommand.getNewLabel()); + 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 9fb62a7af6..63a6b9e422 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,12 +11,14 @@ package org.eclipse.sirius.ui.editor.api.pages; +import org.eclipse.emf.transaction.ResourceSetChangeEvent; 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; import org.eclipse.ui.forms.editor.FormPage; /** - * Custom page provided to aird editor must extends this class. + * Custom page provided to session editor must extends this class. * * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> * @@ -68,4 +70,18 @@ public abstract class AbstractSessionEditorPage extends FormPage { */ public abstract 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 }.** + * + * @param resourceSetChangeEvent + * the event that occurred.*@return an optional + * {@link PageUpdateCommand} the editor should execute.* It can + * be null. + */ + public abstract PageUpdateCommand notifyAndGetUpdateCommands(ResourceSetChangeEvent resourceSetChangeEvent); + } 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 bc1f20a1b0..18785e6691 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 @@ -20,6 +20,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.ResourceSetChangeEvent; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ToolBarManager; import org.eclipse.jface.layout.GridLayoutFactory; @@ -33,6 +34,7 @@ import org.eclipse.sirius.ui.editor.Messages; import org.eclipse.sirius.ui.editor.SessionEditor; import org.eclipse.sirius.ui.editor.SessionEditorPlugin; import org.eclipse.sirius.ui.editor.api.pages.PageProviderRegistry.PositioningKind; +import org.eclipse.sirius.ui.editor.api.pages.PageUpdateCommandBuilder.PageUpdateCommand; import org.eclipse.sirius.ui.editor.internal.graphicalcomponents.GraphicalSemanticModelsHandler; import org.eclipse.sirius.ui.tools.internal.actions.session.CloseSessionsAction; import org.eclipse.sirius.ui.tools.internal.graphicalcomponents.GraphicalRepresentationHandler; @@ -304,7 +306,6 @@ public class DefaultSessionEditorPage extends AbstractSessionEditorPage implemen representationSectionClient.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create()); representationSectionClient.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); representationSection.setClient(representationSectionClient); - GraphicalRepresentationHandlerBuilder graphicalRepresentationHandlerBuilder = new GraphicalRepresentationHandler.GraphicalRepresentationHandlerBuilder(session); graphicalRepresentationHandler = graphicalRepresentationHandlerBuilder.activateBrowserWithViewpointAndRepresentationDescriptionInformation().activateGroupingByCheckbox() .activateRepresentationAndViewpointControls().useToolkitToCreateGraphicComponents(toolkit).activateShowDisabledViewpointsCheckbox().build(); @@ -389,4 +390,9 @@ public class DefaultSessionEditorPage extends AbstractSessionEditorPage implemen public PositioningKind getPositioning() { return null; } + + @Override + public PageUpdateCommand notifyAndGetUpdateCommands(ResourceSetChangeEvent resourceSetChangeEvent) { + return null; + } } 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 c56f6369da..7f6b827122 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 @@ -39,7 +39,10 @@ public class PageProviderRegistry { */ private final List<PageProvider> pageProviders; - private final PageOrderer pageOrderer; + /** + * Components ordering pages regarding positioning information. + */ + private PageOrderer pageOrderer; /** * This enum specifies positioning type to apply when initializing an @@ -144,7 +147,6 @@ public class PageProviderRegistry { public List<AbstractSessionEditorPage> getPagesOrdered(SessionEditor editor, Session session, List<AbstractSessionEditorPage> displayedPages) { List<AbstractSessionEditorPage> pagesOrdered = pageOrderer.getOrderedPages(pageProviders, editor, displayedPages); 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 new file mode 100644 index 0000000000..f2646c6d66 --- /dev/null +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/PageUpdateCommandBuilder.java @@ -0,0 +1,168 @@ +/******************************************************************************* + * Copyright (c) 2017 Obeo + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.ui.editor.api.pages; + +import org.eclipse.sirius.ui.editor.SessionEditor; +import org.eclipse.sirius.ui.editor.api.pages.PageProviderRegistry.PositioningKind; +import org.eclipse.sirius.ui.editor.internal.pages.RemovePageCommand; +import org.eclipse.sirius.ui.editor.internal.pages.RenameTabLabelCommand; +import org.eclipse.sirius.ui.editor.internal.pages.ReorderPageCommand; + +/** + * Provides commands for {@link AbstractSessionEditorPage} pages to tell owner + * editor to update it. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public class PageUpdateCommandBuilder { + /** + * Component providing commands to execute from a {@link SessionEditor}. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ + public class PageUpdateCommand { + /** + * This command remove the page providing it from its editor. + */ + RemovePageCommand removeCommand; + + /** + * This command rename the page's tab of its editor. + */ + RenameTabLabelCommand renameCommand; + + /** + * This command reorder the page in its editor to a new location. + */ + ReorderPageCommand reorderCommand; + + /** + * Returns the command to remove the page providing it from its editor. + * + * @return the command to remove the page providing it from its editor. + */ + public RemovePageCommand getRemoveCommand() { + return removeCommand; + } + + /** + * Returns the command to rename the page's tab of its editor. + * + * @return the command to rename the page's tab of its editor. + */ + public RenameTabLabelCommand getRenameCommand() { + return renameCommand; + } + + /** + * Returns the command to reorder the page in its editor to a new + * location. + * + * @return the command to reorder the page in its editor to a new + * location. + */ + public ReorderPageCommand getReorderCommand() { + return reorderCommand; + } + + /** + * Sets the command to rename the page's tab of its editor. + * + * @param renameCommand + * the command to rename the page's tab of its editor. + */ + public void setRenameCommand(RenameTabLabelCommand renameCommand) { + this.renameCommand = renameCommand; + } + + /** + * Sets the command to remove the page providing it from its editor. + * + * @param removePageCommand + * the command to remove the page providing it from its + * editor. + */ + public void setRemoveCommand(RemovePageCommand removePageCommand) { + this.removeCommand = removePageCommand; + } + + /** + * Sets the command to reorder the page in its editor to a new location. + * + * @param reorderCommand + * the command to reorder the page in its editor to a new + * location. + */ + public void setReorderCommand(ReorderPageCommand reorderCommand) { + this.reorderCommand = reorderCommand; + } + } + + /** + * Component providing commands to execute from a {@link SessionEditor}. + */ + PageUpdateCommand pageUpdateCommand; + + /** + * Initialize the commands builder. + */ + public PageUpdateCommandBuilder() { + pageUpdateCommand = new PageUpdateCommand(); + } + + /** + * Creates a command to rename the page's tab with the given label. + * + * @param newLabel + * the new tab label. + * @return the command builder. + */ + public PageUpdateCommandBuilder renameTab(String newLabel) { + pageUpdateCommand.setRenameCommand(new RenameTabLabelCommand(newLabel)); + return this; + } + + /** + * Creates a command to remove the page from its editor. + * + * @return the command builder. + */ + public PageUpdateCommandBuilder removePage() { + pageUpdateCommand.setRemoveCommand(new RemovePageCommand()); + return this; + } + + /** + * Creates a command to reorder the page regarding the given location + * information. + * + * @param positioningKind + * the kind of positioning to achieve. + * @param targetPageId + * the target page id to place this page relatively to. + * @return the command builder. + */ + public PageUpdateCommandBuilder reorderPage(PositioningKind positioningKind, String targetPageId) { + pageUpdateCommand.setReorderCommand(new ReorderPageCommand(positioningKind, targetPageId)); + return this; + } + + /** + * Build the command containing all commands to execute. + * + * @return the command containing all commands to execute. + */ + public PageUpdateCommand build() { + return pageUpdateCommand; + } +} diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java index 3fb7b83590..e3ba55d876 100644 --- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java @@ -409,22 +409,23 @@ public class GraphicalSemanticModelsHandler implements SessionListener, SessionM site.getShell().getDisplay().asyncExec(new Runnable() { @Override public void run() { - - // Try to select the last affected objects. - Command mostRecentCommand = ((CommandStack) event.getSource()).getMostRecentCommand(); - if (mostRecentCommand != null) { - Collection<?> affectedObjects = mostRecentCommand.getAffectedObjects(); - if (!affectedObjects.isEmpty()) { - setSelectionToViewer(affectedObjects); - } else { - Tree tree = treeViewer.getTree(); - if (!tree.isDisposed() && tree.getItems().length > 0 && !tree.getItem(0).isDisposed()) { - List<Object> selectionCollection = new ArrayList<Object>(); - selectionCollection.add(tree.getItem(0).getData()); - setSelectionToViewer(selectionCollection); + if (treeViewer != null && !treeViewer.getTree().isDisposed()) { + // Try to select the last affected objects. + Command mostRecentCommand = ((CommandStack) event.getSource()).getMostRecentCommand(); + if (mostRecentCommand != null) { + Collection<?> affectedObjects = mostRecentCommand.getAffectedObjects(); + if (!affectedObjects.isEmpty()) { + setSelectionToViewer(affectedObjects); + } else { + Tree tree = treeViewer.getTree(); + if (!tree.isDisposed() && tree.getItems().length > 0 && !tree.getItem(0).isDisposed()) { + List<Object> selectionCollection = new ArrayList<Object>(); + selectionCollection.add(tree.getItem(0).getData()); + setSelectionToViewer(selectionCollection); + } } + actionBars.updateActionBars(); } - actionBars.updateActionBars(); } } }); diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/RemovePageCommand.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/RemovePageCommand.java new file mode 100644 index 0000000000..559fc54b7c --- /dev/null +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/RemovePageCommand.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2017 Obeo + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.ui.editor.internal.pages; + +import org.eclipse.sirius.ui.editor.api.pages.AbstractSessionEditorPage; + +/** + * A command to remove an {@link AbstractSessionEditorPage} from its editor. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public class RemovePageCommand { + +} diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/RenameTabLabelCommand.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/RenameTabLabelCommand.java new file mode 100644 index 0000000000..1f61345964 --- /dev/null +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/RenameTabLabelCommand.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2017 Obeo + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.ui.editor.internal.pages; + +/** + * A command refreshing the tab label of a multi-page editor's page. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public class RenameTabLabelCommand { + + /** + * The label to use when renaming the tab. + */ + private String newLabel; + + /** + * Initialize the command with required information. + * + * @param newLabel + * the label to use when renaming the tab. + */ + public RenameTabLabelCommand(String newLabel) { + this.newLabel = newLabel; + } + + /** + * Returns the label to use when renaming the tab. + * + * @return the label to use when renaming the tab. + */ + public String getNewLabel() { + return newLabel; + } +} diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/ReorderPageCommand.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/ReorderPageCommand.java new file mode 100644 index 0000000000..ec2101e493 --- /dev/null +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/ReorderPageCommand.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2017 Obeo + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.ui.editor.internal.pages; + +import org.eclipse.sirius.ui.editor.api.pages.PageProviderRegistry.PositioningKind; + +/** + * A command to reorder a page to another location identified by a page id among + * its parent editor pages. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public class ReorderPageCommand { + + /** + * The kind of positioning to achieve. + */ + PositioningKind positioningKind; + + /** + * The id of the page to be placed relatively to. + */ + String targetPageId; + + /** + * Initialize the command with required information. + * + * @param positioningKind + * the kind of positioning to achieve. + * @param targetPageId + * the id of the page to be placed relatively to. + */ + public ReorderPageCommand(PositioningKind positioningKind, String targetPageId) { + super(); + this.positioningKind = positioningKind; + this.targetPageId = targetPageId; + } + + /** + * Returns the id of the page to be placed relatively to. + * + * @return the id of the page to be placed relatively to. + */ + public String getTargetPageId() { + return targetPageId; + } + + /** + * Returns the kind of positioning to achieve. + * + * @return the kind of positioning to achieve. + */ + public PositioningKind getPositioningKind() { + return positioningKind; + } +} diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/graphicalcomponents/GraphicalRepresentationHandler.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/graphicalcomponents/GraphicalRepresentationHandler.java index 51fac9452b..897fe0d854 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/graphicalcomponents/GraphicalRepresentationHandler.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/graphicalcomponents/GraphicalRepresentationHandler.java @@ -159,7 +159,7 @@ public class GraphicalRepresentationHandler implements SessionManagerListener { // a model may have been added/removed from the model so we have to update content that is // relative to loaded models. PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { - if (!treeViewer.getTree().isDisposed()) { + if (treeViewer != null && !treeViewer.getTree().isDisposed()) { initInput(); } }); @@ -944,9 +944,11 @@ public class GraphicalRepresentationHandler implements SessionManagerListener { return viewpointItemImpl.getViewpoint(); }); ViewpointHelper.handleViewpointActivation(session, viewpoints.collect(Collectors.toSet()), enable, true); - treeViewer.getTree().setRedraw(true); - treeViewer.refresh(); - treeViewer.setSelection(new StructuredSelection(viewpointsToActivate.stream().collect(Collectors.toList()))); + if (treeViewer != null && !treeViewer.getTree().isDisposed()) { + treeViewer.getTree().setRedraw(true); + treeViewer.refresh(); + treeViewer.setSelection(new StructuredSelection(viewpointsToActivate.stream().collect(Collectors.toList()))); + } } /** |
