diff options
28 files changed, 666 insertions, 317 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java index 17e386cd6a..c6d7569ff3 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java @@ -89,6 +89,7 @@ import org.eclipse.sirius.diagram.provider.DiagramItemProviderAdapterFactory; import org.eclipse.sirius.diagram.ui.business.api.view.SiriusGMFHelper; import org.eclipse.sirius.diagram.ui.business.internal.command.CreateAndStoreGMFDiagramCommand; import org.eclipse.sirius.diagram.ui.edit.api.part.IDDiagramEditPart; +import org.eclipse.sirius.diagram.ui.internal.refresh.DiagramRefresherHelper; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; import org.eclipse.sirius.diagram.ui.provider.Messages; import org.eclipse.sirius.diagram.ui.tools.api.editor.DDiagramEditor; @@ -156,8 +157,7 @@ public class DiagramDialectUIServices implements DialectUIServices { if (gmfDiags.isEmpty()) { /* - * we have our diagrams but not the gmf ones => old aird - * version or corrupted file + * we have our diagrams but not the gmf ones => old aird version or corrupted file */ TransactionalEditingDomain domain = session.getTransactionalEditingDomain(); domain.getCommandStack().execute(new CreateAndStoreGMFDiagramCommand(session, diag)); @@ -262,8 +262,7 @@ public class DiagramDialectUIServices implements DialectUIServices { } /** - * Synchronizes the GMF diagram model according to the viewpoint - * DSemanticDiagram model. + * Synchronizes the GMF diagram model according to the viewpoint DSemanticDiagram model. * * @param diagram * the GMF diagram model to synchronize. @@ -505,10 +504,8 @@ public class DiagramDialectUIServices implements DialectUIServices { /* validate to have all nodes in the right position */ diagramEditPart.getFigure().validate(); /* - * In the case of connection on EditParts created during - * first Refresh they will not appear until we refresh a - * second time Example of such cases are exchanges on - * DFI (mch) + * In the case of connection on EditParts created during first Refresh they will not appear + * until we refresh a second time Example of such cases are exchanges on DFI (mch) */ diagramEditPart.getRoot().refresh(); /* @@ -527,7 +524,7 @@ public class DiagramDialectUIServices implements DialectUIServices { if (exception instanceof SizeTooLargeException) { throw (SizeTooLargeException) exception; } else if (exception.getStatus() != null && exception.getStatus().getException() instanceof SWTException) { - /* Case that can occurs on Windows.*/ + /* Case that can occurs on Windows. */ throw new SizeTooLargeException(new Status(IStatus.ERROR, SiriusPlugin.ID, representation.getName())); } SiriusPlugin.getDefault().error(MessageFormat.format(Messages.DiagramDialectUIServices_exportedDiagramImageCreationError, correctPath), exception); @@ -735,8 +732,7 @@ public class DiagramDialectUIServices implements DialectUIServices { * @param session * the current session * - * @return the editPart corresponding to the diagram element given as - * parameter or null if any + * @return the editPart corresponding to the diagram element given as parameter or null if any */ protected IGraphicalEditPart getEditPart(final DDiagramElement diagramElement, final EditPartViewer graphicalViewer, Session session) { IGraphicalEditPart result = null; @@ -764,8 +760,8 @@ public class DiagramDialectUIServices implements DialectUIServices { /** * {@inheritDoc} * - * @see org.eclipse.sirius.ui.business.api.dialect.DialectUIServices#completeToolTipText(String, - * EObject, EStructuralFeature) + * @see org.eclipse.sirius.ui.business.api.dialect.DialectUIServices#completeToolTipText(String, EObject, + * EStructuralFeature) */ @Override public String completeToolTipText(String toolTipText, EObject eObject, EStructuralFeature feature) { @@ -807,13 +803,10 @@ public class DiagramDialectUIServices implements DialectUIServices { /** * {@inheritDoc} * - * @see org.eclipse.sirius.ui.business.api.dialect.DialectUIServices#completeToolTipText(String, - * EObject) - * @deprecated this method has not access to the feature of eObject. This is - * supported in + * @see org.eclipse.sirius.ui.business.api.dialect.DialectUIServices#completeToolTipText(String, EObject) + * @deprecated this method has not access to the feature of eObject. This is supported in * org.eclipse.sirius.diagram.ui.business.internal.dialect - * .DiagramDialectUIServices.completeToolTipText(String, - * EObject, EStructuralFeature) + * .DiagramDialectUIServices.completeToolTipText(String, EObject, EStructuralFeature) */ @Deprecated @Override @@ -821,4 +814,15 @@ public class DiagramDialectUIServices implements DialectUIServices { return completeToolTipText(toolTipText, eObject, null); } + @Override + public void refreshEditor(DialectEditor dialectEditor, IProgressMonitor monitor) { + if (dialectEditor.getRepresentation() instanceof DSemanticDiagram && dialectEditor instanceof DiagramEditor) { + DSemanticDiagram diagram = (DSemanticDiagram) dialectEditor.getRepresentation(); + + Set<EditPart> editPartsToRefresh = new HashSet<EditPart>(1); + editPartsToRefresh.add(((DiagramEditor) dialectEditor).getDiagramEditPart()); + DiagramRefresherHelper.refreshEditParts(diagram, editPartsToRefresh); + } + } + } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/DiagramRefresherHelper.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/DiagramRefresherHelper.java new file mode 100644 index 0000000000..f43b5aaff1 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/DiagramRefresherHelper.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * 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.diagram.ui.internal.refresh; + +import java.lang.reflect.InvocationTargetException; +import java.util.Collection; + +import org.eclipse.gef.EditPart; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.ui.provider.Messages; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.refresh.RefreshRunnableWithProgress; +import org.eclipse.sirius.ui.business.api.action.RefreshActionListenerRegistry; +import org.eclipse.sirius.viewpoint.SiriusPlugin; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; + +/** + * This class contains utility methods used to refresh table editors. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public final class DiagramRefresherHelper { + + /** + * Private constructor for utility class. + */ + private DiagramRefresherHelper() { + super(); + } + + /** + * Refreshes the tree item of the given selection if such element exists. If not refreshes the all editor. Should be + * call in an EMF {@link Command} because some semantics modifications can happen in this context. + * + * @param diagram + * the diagram from which edit parts will be refreshed. + * @param editParts + * the edit parts to refresh. + */ + public static void refreshEditParts(DDiagram diagram, final Collection<EditPart> editParts) { + if (diagram != null) { + RefreshActionListenerRegistry.INSTANCE.notifyRepresentationIsAboutToBeRefreshed(diagram); + } + + final Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + final ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(activeShell); + try { + monitorDialog.run(true, false, new RefreshRunnableWithProgress(editParts)); + } catch (final InvocationTargetException e) { + MessageDialog.openError(activeShell, Messages.RefreshDiagramAction_error, e.getTargetException().getMessage()); + SiriusPlugin.getDefault().error(Messages.RefreshDiagramAction_refreshDiagramError, e); + } catch (final InterruptedException e) { + MessageDialog.openInformation(activeShell, Messages.RefreshDiagramAction_cancelled, e.getMessage()); + } + } +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/refresh/RefreshDiagramAction.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/refresh/RefreshDiagramAction.java index cfe1c9afb5..e6859eaa4f 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/refresh/RefreshDiagramAction.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/refresh/RefreshDiagramAction.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.ui.tools.internal.actions.refresh; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -20,19 +19,14 @@ import java.util.List; import org.eclipse.gef.EditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.sirius.diagram.DDiagram; import org.eclipse.sirius.diagram.ui.business.internal.dialect.DiagramDialectUIServices; -import org.eclipse.sirius.diagram.ui.provider.Messages; +import org.eclipse.sirius.diagram.ui.internal.refresh.DiagramRefresherHelper; import org.eclipse.sirius.diagram.ui.tools.internal.graphical.edit.part.DDiagramHelper; -import org.eclipse.sirius.ui.business.api.action.RefreshActionListenerRegistry; -import org.eclipse.sirius.viewpoint.SiriusPlugin; import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.RetargetAction; @@ -83,24 +77,12 @@ public class RefreshDiagramAction extends RetargetAction { if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; final Collection<EditPart> minimizedSelection = RefreshDiagramAction.minimizeSelection(Arrays.asList(structuredSelection.toArray())); - + DDiagram diagram = null; if (!minimizedSelection.isEmpty()) { - DDiagram diagram = DDiagramHelper.findParentDDiagram(Iterables.filter(minimizedSelection, IGraphicalEditPart.class).iterator().next()); - if (diagram != null) { - RefreshActionListenerRegistry.INSTANCE.notifyRepresentationIsAboutToBeRefreshed(diagram); - } + diagram = DDiagramHelper.findParentDDiagram(Iterables.filter(minimizedSelection, IGraphicalEditPart.class).iterator().next()); } - final Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - final ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(activeShell); - try { - monitorDialog.run(true, false, new RefreshRunnableWithProgress(minimizedSelection)); - } catch (final InvocationTargetException e) { - MessageDialog.openError(activeShell, Messages.RefreshDiagramAction_error, e.getTargetException().getMessage()); - SiriusPlugin.getDefault().error(Messages.RefreshDiagramAction_refreshDiagramError, e); - } catch (final InterruptedException e) { - MessageDialog.openInformation(activeShell, Messages.RefreshDiagramAction_cancelled, e.getMessage()); - } + DiagramRefresherHelper.refreshEditParts(diagram, minimizedSelection); } } diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index 0dda38480f..5bef444b1a 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -238,6 +238,9 @@ </h4> <ul> <li><span class="label label-success">Added</span> The method + <code>org.eclipse.sirius.ui.business.api.dialect.DialectUIServices.refreshEditor(DialectEditor, IProgressMonitor)</code> has been added to allow specifiers to do a full refresh of its dialect editor easily. + </li> + <li><span class="label label-success">Added</span> The method <code>org.eclipse.sirius.ui.tools.api.color.VisualBindingManager.getDefaultFontWithRuntimeSizeAndFromLabelFormat(List<FontFormat>)</code> has been added to allow to retrieve a font using the given format and the default Sirius font (arial) and the runtime height. </li> <li><span class="label label-success">Added</span> The method diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index 1dffac4779..9c1433d4ce 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -54,6 +54,7 @@ h4. Changes in @org.eclipse.sirius@ h4. Changes in @org.eclipse.sirius.ui@ +* <span class="label label-success">Added</span> The method @org.eclipse.sirius.ui.business.api.dialect.DialectUIServices.refreshEditor(DialectEditor, IProgressMonitor)@ has been added to allow specifiers to do a full refresh of its dialect editor easily. * <span class="label label-success">Added</span> The method @org.eclipse.sirius.ui.tools.api.color.VisualBindingManager.getDefaultFontWithRuntimeSizeAndFromLabelFormat(List<FontFormat>)@ has been added to allow to retrieve a font using the given format and the default Sirius font (arial) and the runtime height. * <span class="label label-success">Added</span> The method @org.eclipse.sirius.ui.tools.api.color.VisualBindingManager.getFontFromNameAndLabelFormatAndWithDefaultSize(List<FontFormat>, String)@ has been added to allow to retrieve a font using the given format and the given font name and the runtime height. * <span class="label label-info">Modified</span> The method @org.eclipse.sirius.ui.tools.api.project.ModelingProjectManager.createLocalRepresentationsFile(IProject, IProgressMonitor)@ has its return type changed from @void@ to @Session@ to allow callers to have access to the newly created session directly. diff --git a/plugins/org.eclipse.sirius.table.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.table.ui/META-INF/MANIFEST.MF index 544b5640d1..7e7db0cf7b 100644 --- a/plugins/org.eclipse.sirius.table.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.table.ui/META-INF/MANIFEST.MF @@ -12,6 +12,7 @@ Export-Package: org.eclipse.sirius.table.metamodel.table.description.provider;ve org.eclipse.sirius.table.metamodel.table.provider;version="3.2.0", org.eclipse.sirius.table.ui.business.api.helper;version="2.0.2", org.eclipse.sirius.table.ui.business.internal.dialect;version="2.2.0";x-internal:=true, + org.eclipse.sirius.table.ui.business.internal.refresh;version="5.0.0";x-internal:=true, org.eclipse.sirius.table.ui.tools.api.editor;version="3.0.0", org.eclipse.sirius.table.ui.tools.internal.commands;version="2.0.2";x-internal:=true, org.eclipse.sirius.table.ui.tools.internal.editor;version="3.0.0";x-internal:=true, diff --git a/plugins/org.eclipse.sirius.table.ui/plugin.properties b/plugins/org.eclipse.sirius.table.ui/plugin.properties index f8df8b6f53..d73d8a2b17 100644 --- a/plugins/org.eclipse.sirius.table.ui/plugin.properties +++ b/plugins/org.eclipse.sirius.table.ui/plugin.properties @@ -1,5 +1,5 @@ # ==================================================================== -# Copyright (c) 2007, 2015 THALES GLOBAL SERVICES +# Copyright (c) 2007, 2017 THALES GLOBAL SERVICES # 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 @@ -280,8 +280,6 @@ _UI_DTableElementStyle_defaultBackgroundStyle_feature = Default Background Style AbstractDTableEditor_editorToBeClosedAndReopenedSinceContentIsNotAccessible={0}\nContent access has failed at editor opening, you can try to reopen this editor. AbstractDTableEditor_tableNotSaved = This table was not saved. You can close the editor -Action_cancelled = Cancelled -Action_error = Error Action_setValue = Set {0} value Action_setValues = Set {0} values DeleteLinesAction_label = Delete line @@ -327,8 +325,10 @@ HierarchyLabelTableProvider_elementWithoutName = Element without name PrintAction_errorDuringPrinting = An error occurs during printing: {0} PrintAction_tableWithoutName = table without name PrintAsImageCallback_pageFooter = page {0}/{1} -RefreshAction_errorDuringRefresh = Error while refreshing table +Refresh_errorDuringRefresh = Error while refreshing table RefreshAction_label = Refresh table +Refresh_cancelled = Cancelled +Refresh_error = Error RefreshAtOpeningActivator_refreshTableCmdName = refresh table model at opening ShowAllColumnsAction_label = Show hidden columns ShowAllLinesAction_label = Show hidden lines diff --git a/plugins/org.eclipse.sirius.table.ui/src-gen/org/eclipse/sirius/table/metamodel/table/provider/Messages.java b/plugins/org.eclipse.sirius.table.ui/src-gen/org/eclipse/sirius/table/metamodel/table/provider/Messages.java index 892633a9e9..4bdcfa5641 100644 --- a/plugins/org.eclipse.sirius.table.ui/src-gen/org/eclipse/sirius/table/metamodel/table/provider/Messages.java +++ b/plugins/org.eclipse.sirius.table.ui/src-gen/org/eclipse/sirius/table/metamodel/table/provider/Messages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Obeo. + * Copyright (c) 2015, 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 @@ -31,10 +31,10 @@ public final class Messages { public static String AbstractDTableEditor_editorToBeClosedAndReopenedSinceContentIsNotAccessible; @TranslatableMessage - public static String Action_cancelled; + public static String Refresh_cancelled; @TranslatableMessage - public static String Action_error; + public static String Refresh_error; @TranslatableMessage public static String Action_setValue; @@ -172,7 +172,7 @@ public final class Messages { public static String PrintAsImageCallback_pageFooter; @TranslatableMessage - public static String RefreshAction_errorDuringRefresh; + public static String Refresh_errorDuringRefresh; @TranslatableMessage public static String RefreshAction_label; diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/business/internal/dialect/TableDialectUIServices.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/business/internal/dialect/TableDialectUIServices.java index 3c7fb5a858..e2c6eb79ae 100644 --- a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/business/internal/dialect/TableDialectUIServices.java +++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/business/internal/dialect/TableDialectUIServices.java @@ -51,6 +51,7 @@ import org.eclipse.sirius.table.metamodel.table.provider.Messages; import org.eclipse.sirius.table.metamodel.table.provider.TableItemProviderAdapterFactory; import org.eclipse.sirius.table.metamodel.table.provider.TableUIPlugin; import org.eclipse.sirius.table.tools.api.export.TableExportHelper; +import org.eclipse.sirius.table.ui.business.internal.refresh.TableRefresherHelper; import org.eclipse.sirius.table.ui.tools.api.editor.DTableEditor; import org.eclipse.sirius.table.ui.tools.internal.editor.AbstractDTableEditor; import org.eclipse.sirius.table.ui.tools.internal.editor.DTableCrossEditor; @@ -314,17 +315,22 @@ public class TableDialectUIServices implements DialectUIServices { /** * {@inheritDoc} * - * @see org.eclipse.sirius.ui.business.api.dialect.DialectUIServices#completeToolTipText(String, - * EObject) - * @deprecated this method has not access to the feature of eObject. This is - * supported in + * @see org.eclipse.sirius.ui.business.api.dialect.DialectUIServices#completeToolTipText(String, EObject) + * @deprecated this method has not access to the feature of eObject. This is supported in * org.eclipse.sirius.table.ui.business.internal.dialect - * .TableDialectUIServices.completeToolTipText(String, EObject, - * EStructuralFeature) + * .TableDialectUIServices.completeToolTipText(String, EObject, EStructuralFeature) */ @Deprecated @Override public String completeToolTipText(String toolTipText, EObject eObject) { return toolTipText; } + + @Override + public void refreshEditor(DialectEditor dialectEditor, IProgressMonitor monitor) { + if (dialectEditor instanceof AbstractDTableEditor) { + final AbstractDTableEditor tableEditor = (AbstractDTableEditor) dialectEditor; + TableRefresherHelper.refreshEditor(tableEditor, monitor); + } + } } diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/business/internal/refresh/TableRefresherHelper.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/business/internal/refresh/TableRefresherHelper.java new file mode 100644 index 0000000000..c01b0343b0 --- /dev/null +++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/business/internal/refresh/TableRefresherHelper.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * 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.table.ui.business.internal.refresh; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.sirius.business.api.dialect.command.RefreshRepresentationsCommand; +import org.eclipse.sirius.table.metamodel.table.provider.Messages; +import org.eclipse.sirius.table.ui.tools.internal.editor.AbstractDTableEditor; +import org.eclipse.sirius.ui.business.api.action.RefreshActionListenerRegistry; +import org.eclipse.sirius.viewpoint.SiriusPlugin; +import org.eclipse.swt.widgets.Shell; + +/** + * This class contains utility methods used to refresh table editors. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public final class TableRefresherHelper { + + /** + * Private constructor for utility class. + */ + private TableRefresherHelper() { + super(); + } + + /** + * Refreshes the given table editor and uses the given monitor for task monitoring. Should be call in an EMF Command + * because some semantics modifications can happen in this context. + * + * @param tableEditor + * the table editor to refresh. + * @param theMonitor + * the monitor to use for monitoring the task. + */ + public static void refreshEditor(AbstractDTableEditor tableEditor, IProgressMonitor theMonitor) { + SubMonitor subMonitor = SubMonitor.convert(theMonitor, 1); + final IRunnableWithProgress op = new IRunnableWithProgress() { + @Override + public void run(final IProgressMonitor monitor) { + TransactionalEditingDomain domain = tableEditor.getEditingDomain(); + domain.getCommandStack().execute(new RefreshRepresentationsCommand(domain, monitor, tableEditor.getTableModel())); + } + }; + final Shell activeShell = tableEditor.getSite().getShell(); + final ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(activeShell); + try { + tableEditor.enablePropertiesUpdate(false); + RefreshActionListenerRegistry.INSTANCE.notifyRepresentationIsAboutToBeRefreshed(tableEditor.getTableModel()); + monitorDialog.run(true, false, op); + subMonitor.split(1); + } catch (final InvocationTargetException e) { + MessageDialog.openError(activeShell, Messages.Refresh_error, e.getTargetException().getMessage()); + SiriusPlugin.getDefault().error(Messages.Refresh_errorDuringRefresh, e); + } catch (final InterruptedException e) { + MessageDialog.openInformation(activeShell, Messages.Refresh_cancelled, e.getMessage()); + } finally { + tableEditor.enablePropertiesUpdate(true); + } + } +} diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/EditorRefreshAction.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/EditorRefreshAction.java index 4c04eead7a..92dc717f3f 100644 --- a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/EditorRefreshAction.java +++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/EditorRefreshAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2015 THALES GLOBAL SERVICES. + * Copyright (c) 2008, 2017 THALES GLOBAL SERVICES. * 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 @@ -10,20 +10,11 @@ *******************************************************************************/ package org.eclipse.sirius.table.ui.tools.internal.editor.action; -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.sirius.business.api.dialect.command.RefreshRepresentationsCommand; -import org.eclipse.sirius.table.metamodel.table.provider.Messages; +import org.eclipse.sirius.table.ui.business.internal.refresh.TableRefresherHelper; import org.eclipse.sirius.table.ui.tools.internal.editor.AbstractDTableEditor; -import org.eclipse.sirius.ui.business.api.action.RefreshActionListenerRegistry; -import org.eclipse.sirius.viewpoint.SiriusPlugin; -import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorActionDelegate; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPart; @@ -35,8 +26,7 @@ import org.eclipse.ui.IWorkbenchPart; */ public class EditorRefreshAction implements IEditorActionDelegate { /** - * This records the editor or view with which the action is currently - * associated. + * This records the editor or view with which the action is currently associated. */ protected IWorkbenchPart workbenchPart; @@ -59,26 +49,7 @@ public class EditorRefreshAction implements IEditorActionDelegate { @Override public void run(final IAction action) { if (workbenchPart instanceof AbstractDTableEditor) { - final IRunnableWithProgress op = new IRunnableWithProgress() { - @Override - public void run(final IProgressMonitor monitor) { - final AbstractDTableEditor tableEditor = (AbstractDTableEditor) workbenchPart; - tableEditor.enablePropertiesUpdate(false); - RefreshActionListenerRegistry.INSTANCE.notifyRepresentationIsAboutToBeRefreshed(tableEditor.getTableModel()); - tableEditor.getEditingDomain().getCommandStack().execute(new RefreshRepresentationsCommand(tableEditor.getEditingDomain(), monitor, tableEditor.getTableModel())); - tableEditor.enablePropertiesUpdate(true); - } - }; - final Shell activeShell = workbenchPart.getSite().getShell(); - final ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(activeShell); - try { - monitorDialog.run(false, false, op); - } catch (final InvocationTargetException e) { - MessageDialog.openError(activeShell, Messages.Action_error, e.getTargetException().getMessage()); - SiriusPlugin.getDefault().error(Messages.RefreshAction_errorDuringRefresh, e); - } catch (final InterruptedException e) { - MessageDialog.openInformation(activeShell, Messages.Action_cancelled, e.getMessage()); - } + TableRefresherHelper.refreshEditor((AbstractDTableEditor) workbenchPart, new NullProgressMonitor()); } } diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/RefreshAction.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/RefreshAction.java index bb4ac90a94..e1ca2038a3 100644 --- a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/RefreshAction.java +++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/RefreshAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2015 THALES GLOBAL SERVICES. + * Copyright (c) 2008, 2017 THALES GLOBAL SERVICES. * 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 @@ -10,23 +10,14 @@ *******************************************************************************/ package org.eclipse.sirius.table.ui.tools.internal.editor.action; -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.sirius.business.api.dialect.command.RefreshRepresentationsCommand; import org.eclipse.sirius.table.metamodel.table.provider.Messages; +import org.eclipse.sirius.table.ui.business.internal.refresh.TableRefresherHelper; import org.eclipse.sirius.table.ui.tools.internal.editor.AbstractDTableEditor; import org.eclipse.sirius.table.ui.tools.internal.editor.DTableViewerManager; -import org.eclipse.sirius.ui.business.api.action.RefreshActionListenerRegistry; -import org.eclipse.sirius.viewpoint.SiriusPlugin; -import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPage; @@ -60,27 +51,7 @@ public class RefreshAction extends Action implements IObjectActionDelegate { IEditorPart activeEditor = activePage.getActiveEditor(); if (activeEditor instanceof AbstractDTableEditor) { tableEditor = (AbstractDTableEditor) activeEditor; - final IRunnableWithProgress op = new IRunnableWithProgress() { - @Override - public void run(final IProgressMonitor monitor) { - TransactionalEditingDomain domain = tableEditor.getEditingDomain(); - domain.getCommandStack().execute(new RefreshRepresentationsCommand(domain, monitor, tableEditor.getTableModel())); - } - }; - final Shell activeShell = tableEditor.getSite().getShell(); - final ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(activeShell); - try { - tableEditor.enablePropertiesUpdate(false); - RefreshActionListenerRegistry.INSTANCE.notifyRepresentationIsAboutToBeRefreshed(tableEditor.getTableModel()); - monitorDialog.run(true, false, op); - } catch (final InvocationTargetException e) { - MessageDialog.openError(activeShell, Messages.Action_error, e.getTargetException().getMessage()); - SiriusPlugin.getDefault().error(Messages.RefreshAction_errorDuringRefresh, e); - } catch (final InterruptedException e) { - MessageDialog.openInformation(activeShell, Messages.Action_cancelled, e.getMessage()); - } finally { - tableEditor.enablePropertiesUpdate(true); - } + TableRefresherHelper.refreshEditor(tableEditor, new NullProgressMonitor()); } } } diff --git a/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF index 96d80118ce..c50cf73857 100644 --- a/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF @@ -76,7 +76,8 @@ Require-Bundle: org.eclipse.sirius.tests.sample.benchmark, org.eclipse.ui.navigator;bundle-version="3.5.200", org.eclipse.sirius.diagram.formatdata;bundle-version="4.1.0", org.eclipse.sirius.ext.emf.edit;bundle-version="4.1.0", - org.eclipse.ui.editors + org.eclipse.ui.editors, + org.eclipse.emf.ecore Bundle-Activator: org.eclipse.sirius.tests.SiriusTestsPlugin Eclipse-LazyStart: true Bundle-Localization: plugin diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/diagram/AllDiagramPluginsTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/diagram/AllDiagramPluginsTests.java index 89b5075c4f..62041eebcf 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/diagram/AllDiagramPluginsTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/diagram/AllDiagramPluginsTests.java @@ -103,6 +103,7 @@ import org.eclipse.sirius.tests.unit.diagram.copier.RepresentationCopierTest; import org.eclipse.sirius.tests.unit.diagram.decorators.DecoratorsTest; import org.eclipse.sirius.tests.unit.diagram.decorators.TransientLayerAndDecoratorTest; import org.eclipse.sirius.tests.unit.diagram.dialect.DiagramDialectServicesTests; +import org.eclipse.sirius.tests.unit.diagram.dialect.DiagramUIDialectServicesTests; import org.eclipse.sirius.tests.unit.diagram.dragndrop.DraggedObjectTesterTests; import org.eclipse.sirius.tests.unit.diagram.dragndrop.LabelVisibilityOnCreationTest; import org.eclipse.sirius.tests.unit.diagram.dragndrop.LabelVisibilityOnDragAndDropTests; @@ -284,6 +285,7 @@ public class AllDiagramPluginsTests { suite.addTestSuite(DynamicInstanceTests.class); suite.addTestSuite(CanonicalDBorderItemLocatorTest.class); suite.addTestSuite(DiagramDialectServicesTests.class); + suite.addTestSuite(DiagramUIDialectServicesTests.class); suite.addTestSuite(TypeContentProposalTests.class); suite.addTestSuite(TypeNameTest.class); diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/dialect/DiagramUIDialectServicesTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/dialect/DiagramUIDialectServicesTests.java new file mode 100644 index 0000000000..e639a316f7 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/dialect/DiagramUIDialectServicesTests.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2016, 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.tests.unit.diagram.dialect; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.sirius.business.api.preferences.SiriusPreferencesKeys; +import org.eclipse.sirius.diagram.ui.business.internal.dialect.DiagramDialectUIServices; +import org.eclipse.sirius.diagram.ui.tools.api.editor.DDiagramEditor; +import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; +import org.eclipse.sirius.tests.support.api.TestsUtil; +import org.eclipse.sirius.ui.business.api.dialect.DialectEditor; +import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; +import org.eclipse.sirius.ui.business.api.preferences.SiriusUIPreferencesKeys; +import org.eclipse.sirius.viewpoint.DRepresentation; + +/** + * This class tests the services of {@link DiagramDialectUIServices}. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public class DiagramUIDialectServicesTests extends SiriusDiagramTestCase { + + private static final String MODELER_PATH = "/org.eclipse.sirius.tests.junit/data/unit/dialect/aqlDomainClassDef.odesign"; + + private static final String SEMANTIC_MODEL_PATH = "/org.eclipse.sirius.tests.junit/data/unit/dialect/aqlDomainClassDef.ecore"; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + changeSiriusUIPreference(SiriusUIPreferencesKeys.PREF_RELOAD_ON_LAST_EDITOR_CLOSE.name(), false); + changeSiriusUIPreference(SiriusUIPreferencesKeys.PREF_SAVE_WHEN_NO_EDITOR.name(), false); + changeSiriusPreference(SiriusPreferencesKeys.PREF_AUTO_REFRESH.name(), false); + + genericSetUp(SEMANTIC_MODEL_PATH, MODELER_PATH); + initViewpoint("aqlDomainClassDef"); + } + + /** + * Tests that refresh is done with + * {@link DialectUIManager#refreshEditor(DialectEditor, org.eclipse.core.runtime.IProgressMonitor)} + * for a {@link DDiagramEditor}. + * + */ + public void testDiagramDialectUIManagerRefresh() { + DRepresentation newRepresentation = createRepresentation("EcoreDiag"); + final DialectEditor editor = (DialectEditor) DialectUIManager.INSTANCE.openEditor(session, newRepresentation, new NullProgressMonitor()); + TestsUtil.synchronizationWithUIThread(); + try { + assertEquals("Test setup is wrong.", 2, newRepresentation.getRepresentationElements().size()); + + EPackage ePackage = (EPackage) semanticModel; + Command changeNameCommand = new RecordingCommand(session.getTransactionalEditingDomain()) { + @Override + protected void doExecute() { + ePackage.getEClassifiers().clear(); + + } + }; + session.getTransactionalEditingDomain().getCommandStack().execute(changeNameCommand); + TestsUtil.synchronizationWithUIThread(); + DialectUIManager.INSTANCE.refreshEditor(editor, new NullProgressMonitor()); + TestsUtil.synchronizationWithUIThread(); + assertEquals("Refresh has failed.", 0, editor.getRepresentation().getRepresentationElements().size()); + } finally + + { + DialectUIManager.INSTANCE.closeEditor(editor, false); + } + + } + +} diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/refresh/TableManuelRefreshTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/refresh/TableManuelRefreshTests.java index 7a523aa761..965b3e5256 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/refresh/TableManuelRefreshTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/refresh/TableManuelRefreshTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES. * 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 @@ -13,17 +13,22 @@ package org.eclipse.sirius.tests.unit.table.unit.refresh; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EcoreFactory; import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.emf.edit.command.AddCommand; import org.eclipse.emf.edit.command.SetCommand; import org.eclipse.sirius.business.api.dialect.DialectManager; import org.eclipse.sirius.business.api.preferences.SiriusPreferencesKeys; import org.eclipse.sirius.table.metamodel.table.DLine; import org.eclipse.sirius.table.metamodel.table.DTable; +import org.eclipse.sirius.table.ui.tools.internal.editor.DTableEditionEditor; import org.eclipse.sirius.tests.SiriusTestsPlugin; import org.eclipse.sirius.tests.support.api.EclipseTestsSupportHelper; import org.eclipse.sirius.tests.support.api.SiriusTestCase; import org.eclipse.sirius.tests.support.api.TestsUtil; import org.eclipse.sirius.tools.api.command.ICommandFactory; +import org.eclipse.sirius.ui.business.api.dialect.DialectEditor; import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; /** @@ -44,6 +49,8 @@ public class TableManuelRefreshTests extends SiriusTestCase { private DTable dTable; + private DialectEditor tableEditor; + @Override protected void setUp() throws Exception { super.setUp(); @@ -56,7 +63,7 @@ public class TableManuelRefreshTests extends SiriusTestCase { dTable = (DTable) DialectManager.INSTANCE.getAllRepresentations(session).iterator().next(); - DialectUIManager.INSTANCE.openEditor(session, dTable, new NullProgressMonitor()); + tableEditor = (DialectEditor) DialectUIManager.INSTANCE.openEditor(session, dTable, new NullProgressMonitor()); TestsUtil.synchronizationWithUIThread(); changeSiriusPreference(SiriusPreferencesKeys.PREF_AUTO_REFRESH.name(), false); @@ -72,6 +79,28 @@ public class TableManuelRefreshTests extends SiriusTestCase { assertEquals("in manual refresh the DCell.label should be refreshed", newEClass.getName(), dLineOfNewEClass.getLabel()); } + /** + * Tests that refresh is done with + * {@link DialectUIManager#refreshEditor(DialectEditor, org.eclipse.core.runtime.IProgressMonitor)} + * for a {@link DTableEditionEditor}. + * + */ + public void testTableDialectUIManagerRefresh() { + EPackage ePackage = (EPackage) semanticModel; + EClass newEClass = EcoreFactory.eINSTANCE.createEClass(); + newEClass.setName("NewEClass"); + assertEquals("Test setup is wrong.", 1, dTable.getLines().size()); + + Command changeNewEClassNameCmd = AddCommand.create(session.getTransactionalEditingDomain(), ePackage, EcorePackage.Literals.EPACKAGE__ECLASSIFIERS, newEClass); + session.getTransactionalEditingDomain().getCommandStack().execute(changeNewEClassNameCmd); + TestsUtil.synchronizationWithUIThread(); + + assertEquals("Test setup is wrong.", 1, dTable.getLines().size()); + + DialectUIManager.INSTANCE.refreshEditor(tableEditor, new NullProgressMonitor()); + assertEquals("The refresh has not work. The new element has not been inserted in the table.", 2, dTable.getLines().size()); + } + @Override protected ICommandFactory getCommandFactory() { return null; @@ -80,6 +109,8 @@ public class TableManuelRefreshTests extends SiriusTestCase { @Override protected void tearDown() throws Exception { dTable = null; + DialectUIManager.INSTANCE.closeEditor(tableEditor, false); + tableEditor = null; super.tearDown(); } diff --git a/plugins/org.eclipse.sirius.tests.tree/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.tests.tree/META-INF/MANIFEST.MF index 808827dd2e..0e63e2934f 100644 --- a/plugins/org.eclipse.sirius.tests.tree/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.tests.tree/META-INF/MANIFEST.MF @@ -47,6 +47,7 @@ Export-Package: org.eclipse.sirius.tests, org.eclipse.sirius.tests.suite.tree, org.eclipse.sirius.tests.support.api, org.eclipse.sirius.tests.unit.common, + org.eclipse.sirius.tests.unit.dialect, org.eclipse.sirius.tests.unit.tree, org.eclipse.sirius.tests.unit.tree.tools, org.eclipse.sirius.tests.unit.tree.vsm.edit diff --git a/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/suite/tree/AllTreePluginTests.java b/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/suite/tree/AllTreePluginTests.java index 9eb23ed207..11c2720ae4 100644 --- a/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/suite/tree/AllTreePluginTests.java +++ b/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/suite/tree/AllTreePluginTests.java @@ -10,11 +10,6 @@ *******************************************************************************/ package org.eclipse.sirius.tests.suite.tree; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import junit.textui.TestRunner; - import org.eclipse.sirius.tests.api.tools.RefreshWhenSeveralEditorsOpenTest; import org.eclipse.sirius.tests.api.tools.TreeItemCreationToolsTest; import org.eclipse.sirius.tests.api.tools.TreeItemDeletionToolsTest; @@ -22,6 +17,7 @@ import org.eclipse.sirius.tests.api.tools.TreeItemDragAndDropToolTest; import org.eclipse.sirius.tests.api.tools.TreeItemDragAndDropToolUsingRecordingCommandCompositionTest; import org.eclipse.sirius.tests.api.tools.TreeItemEditionToolTest; import org.eclipse.sirius.tests.api.tools.TreeItemRefreshWithToolsTest; +import org.eclipse.sirius.tests.unit.dialect.TreeUIDialectServicesTests; import org.eclipse.sirius.tests.unit.migration.InitializeElementsToSelectExpressionForTreeMigrationTest; import org.eclipse.sirius.tests.unit.tree.MappingHierarchyTableTest; import org.eclipse.sirius.tests.unit.tree.TreeItemOrderTests; @@ -29,6 +25,11 @@ import org.eclipse.sirius.tests.unit.tree.TreeRefreshTests; import org.eclipse.sirius.tests.unit.tree.TreeVariablesTest; import org.eclipse.sirius.tests.unit.tree.tools.SelectionInTreeAfterToolExecutionTest; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import junit.textui.TestRunner; + /** * The designer main test suite for the tree component. * @@ -47,8 +48,7 @@ public class AllTreePluginTests extends TestCase { } /** - * Creates the {@link junit.framework.TestSuite TestSuite} for all the tests - * of the table component. + * Creates the {@link junit.framework.TestSuite TestSuite} for all the tests of the table component. * * @return The testsuite containing all the tests of the tree component */ @@ -71,6 +71,7 @@ public class AllTreePluginTests extends TestCase { suite.addTestSuite(TreeItemRefreshWithToolsTest.class); suite.addTestSuite(SelectionInTreeAfterToolExecutionTest.class); suite.addTestSuite(InitializeElementsToSelectExpressionForTreeMigrationTest.class); + suite.addTestSuite(TreeUIDialectServicesTests.class); return suite; } diff --git a/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/unit/dialect/TreeUIDialectServicesTests.java b/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/unit/dialect/TreeUIDialectServicesTests.java new file mode 100644 index 0000000000..c67d90fa7c --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/unit/dialect/TreeUIDialectServicesTests.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2011, 2017 THALES GLOBAL SERVICES. + * 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.tests.unit.dialect; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.sirius.business.api.preferences.SiriusPreferencesKeys; +import org.eclipse.sirius.tests.SiriusTestsPlugin; +import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; +import org.eclipse.sirius.tests.support.api.TestsUtil; +import org.eclipse.sirius.tree.DTree; +import org.eclipse.sirius.tree.ui.tools.api.editor.DTreeEditor; +import org.eclipse.sirius.ui.business.api.dialect.DialectEditor; +import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; +import org.junit.Assert; + +/** + * Test Multiple refresh required when several editors are open and AutoRefresh is on. Test also undo and redo with + * several editors are open. Test VP-815 and DOREMI-2443 + * + * @author jdupont + */ +/** + * Test the services provided by TreeUIDialectServices + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public class TreeUIDialectServicesTests extends SiriusDiagramTestCase { + + private static final String SEMANTIC_MODEL_PATH = "/" + SiriusTestsPlugin.PLUGIN_ID + "/data/unit/refresh/refreshWhenSeveralEdiorsOpen/My.ecore"; + + private static final String MODELER_PATH = "/" + SiriusTestsPlugin.PLUGIN_ID + "/data/unit/refresh/refreshWhenSeveralEdiorsOpen/EcoreExtension.odesign"; + + private static final String SESSION_PATH = "/" + SiriusTestsPlugin.PLUGIN_ID + "/data/unit/refresh/refreshWhenSeveralEdiorsOpen/My.aird"; + + private static final String VIEWPOINT_NAME = "Design"; + + private static final String VIEWPOINT_NAME_EXTENSION = "EcoreForResfreshTest"; + + private static final String REPRESENTATION_DESC_NAME_TREE = "Tree"; + + private DTree tree; + + private DialectEditor editorRootTree; + + @Override + protected void setUp() throws Exception { + super.setUp(); + genericSetUp(SEMANTIC_MODEL_PATH, MODELER_PATH, SESSION_PATH); + initViewpoint(VIEWPOINT_NAME); + initViewpoint(VIEWPOINT_NAME_EXTENSION); + tree = (DTree) getRepresentations(REPRESENTATION_DESC_NAME_TREE).toArray()[0]; + } + + /** + * Tests that refresh is done with + * {@link DialectUIManager#refreshEditor(DialectEditor, org.eclipse.core.runtime.IProgressMonitor)} for a + * {@link DTreeEditor}. + * + */ + public void testDiagramDialectUIManagerRefresh() { + changeSiriusPreference(SiriusPreferencesKeys.PREF_AUTO_REFRESH.name(), false); + EPackage ePackage = (EPackage) semanticModel; + editorRootTree = (DialectEditor) DialectUIManager.INSTANCE.openEditor(session, tree, new NullProgressMonitor()); + TestsUtil.synchronizationWithUIThread(); + + Assert.assertEquals("Test setup is wrong.", 12, tree.getRepresentationElements().size()); + + Command changeNameCommand = new RecordingCommand(session.getTransactionalEditingDomain()) { + @Override + protected void doExecute() { + ePackage.getESubpackages().clear(); + } + }; + session.getTransactionalEditingDomain().getCommandStack().execute(changeNameCommand); + + DialectUIManager.INSTANCE.refreshEditor(editorRootTree, new NullProgressMonitor()); + TestsUtil.synchronizationWithUIThread(); + + Assert.assertEquals("Refresh was not applied.", 0, tree.getRepresentationElements().size()); + + } + + @Override + protected void tearDown() throws Exception { + TestsUtil.synchronizationWithUIThread(); + DialectUIManager.INSTANCE.closeEditor(editorRootTree, false); + tree = null; + editorRootTree = null; + super.tearDown(); + } +} diff --git a/plugins/org.eclipse.sirius.tree.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.tree.ui/META-INF/MANIFEST.MF index b0425cb831..cfa182daf1 100644 --- a/plugins/org.eclipse.sirius.tree.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.tree.ui/META-INF/MANIFEST.MF @@ -12,6 +12,7 @@ Export-Package: org.eclipse.sirius.tree.description.provider;version="3.0.0", org.eclipse.sirius.tree.provider;version="3.0.0", org.eclipse.sirius.tree.ui.business.api.helper;version="2.0.4", org.eclipse.sirius.tree.ui.business.internal.dialect;version="2.2.0";x-internal:=true, + org.eclipse.sirius.tree.ui.business.internal.refresh;version="5.0.0";x-internal:=true, org.eclipse.sirius.tree.ui.internal.preferences;version="5.0.0";x-internal:=true, org.eclipse.sirius.tree.ui.properties.propertysource;version="2.0.4", org.eclipse.sirius.tree.ui.properties.section.common;version="3.0.0", diff --git a/plugins/org.eclipse.sirius.tree.ui/plugin.properties b/plugins/org.eclipse.sirius.tree.ui/plugin.properties index 9b1900e48b..2453259ffa 100644 --- a/plugins/org.eclipse.sirius.tree.ui/plugin.properties +++ b/plugins/org.eclipse.sirius.tree.ui/plugin.properties @@ -1,5 +1,5 @@ # ==================================================================== -# Copyright (c) 2013, 2015 THALES GLOBAL SERVICES +# Copyright (c) 2013, 2017 THALES GLOBAL SERVICES # 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 @@ -27,9 +27,9 @@ DeleteTreeItemsAction_deleteTargetSemanticElements = Delete the target semantic DeleteTreeItemsAction_deleteTreeItem = Delete tree item DeleteTreeItemsAction_deleteTreeItems = Delete tree items EditorCreateTreeItemMenuAction_name = Create root tree items -EditorRefreshAction_error = Error -EditorRefreshAction_refreshCancelled = Cancelled -EditorRefreshAction_treeRefreshError = Error while refreshing tree +EditorRefresh_error = Error +EditorRefresh_refreshCancelled = Cancelled +EditorRefresh_treeRefreshError = Error while refreshing tree ExpandDTreeItemRunnableWithProgress_expandTreeItem = Expand {0} tree item ExpandDTreeItemRunnableWithProgress_treeItemCollapsing = Tree item collapsing ExpandDTreeItemRunnableWithProgress_treeItemExpanding = Tree item expanding diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/business/internal/dialect/TreeDialectUIServices.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/business/internal/dialect/TreeDialectUIServices.java index 788813fc35..ef38c10d41 100644 --- a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/business/internal/dialect/TreeDialectUIServices.java +++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/business/internal/dialect/TreeDialectUIServices.java @@ -45,6 +45,7 @@ import org.eclipse.sirius.tree.description.TreeDescription; import org.eclipse.sirius.tree.description.TreeNavigationDescription; import org.eclipse.sirius.tree.description.provider.DescriptionItemProviderAdapterFactory; import org.eclipse.sirius.tree.provider.TreeItemProviderAdapterFactory; +import org.eclipse.sirius.tree.ui.business.internal.refresh.TreeRefresherHelper; import org.eclipse.sirius.tree.ui.provider.Messages; import org.eclipse.sirius.tree.ui.provider.TreeUIPlugin; import org.eclipse.sirius.tree.ui.tools.internal.editor.DTreeEditor; @@ -282,13 +283,10 @@ public class TreeDialectUIServices implements DialectUIServices { /** * {@inheritDoc} * - * @see org.eclipse.sirius.ui.business.api.dialect.DialectUIServices#completeToolTipText(String, - * EObject) - * @deprecated this method has not access to the feature of eObject. This is - * supported in + * @see org.eclipse.sirius.ui.business.api.dialect.DialectUIServices#completeToolTipText(String, EObject) + * @deprecated this method has not access to the feature of eObject. This is supported in * org.eclipse.sirius.tree.ui.business.internal.dialect - * .TreeDialectUIServices.completeToolTipText(String, EObject, - * EStructuralFeature) + * .TreeDialectUIServices.completeToolTipText(String, EObject, EStructuralFeature) */ @Deprecated @Override @@ -296,4 +294,12 @@ public class TreeDialectUIServices implements DialectUIServices { return toolTipText; } + @Override + public void refreshEditor(DialectEditor dialectEditor, IProgressMonitor monitor) { + if (dialectEditor instanceof DTreeEditor) { + final DTreeEditor treeEditor = (DTreeEditor) dialectEditor; + TreeRefresherHelper.refreshEditor(treeEditor, new StructuredSelection(), monitor); + } + } + } diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/business/internal/refresh/TreeRefresherHelper.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/business/internal/refresh/TreeRefresherHelper.java new file mode 100644 index 0000000000..a335c0daaa --- /dev/null +++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/business/internal/refresh/TreeRefresherHelper.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * 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.tree.ui.business.internal.refresh; + +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedList; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.sirius.business.api.dialect.command.RefreshRepresentationsCommand; +import org.eclipse.sirius.business.api.query.EObjectQuery; +import org.eclipse.sirius.business.api.session.Session; +import org.eclipse.sirius.tree.DTreeItem; +import org.eclipse.sirius.tree.business.api.command.DTreeItemLocalRefreshCommand; +import org.eclipse.sirius.tree.business.internal.dialect.common.tree.TreeRefreshContext; +import org.eclipse.sirius.tree.business.internal.dialect.common.viewpoint.GlobalContext; +import org.eclipse.sirius.tree.ui.provider.Messages; +import org.eclipse.sirius.tree.ui.tools.internal.editor.DTreeEditor; +import org.eclipse.sirius.ui.business.api.action.RefreshActionListenerRegistry; +import org.eclipse.sirius.viewpoint.SiriusPlugin; +import org.eclipse.swt.widgets.Shell; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +/** + * This class contains utility methods used to refresh table editors. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public final class TreeRefresherHelper { + + /** + * Private constructor for utility class. + */ + private TreeRefresherHelper() { + super(); + } + + /** + * Refreshes the tree item of the given selection if such element exists. If not refreshes the all editor. Should be + * call in an EMF {@link Command} because some semantics modifications can happen in this context. + * + * @param treeEditor + * the tree editor to refresh. + * @param structuredSelection + * the current tree editor selection. + * @param theMonitor + * the monitor to use for monitoring the task. + */ + public static void refreshEditor(DTreeEditor treeEditor, IStructuredSelection structuredSelection, IProgressMonitor theMonitor) { + SubMonitor subMonitor = SubMonitor.convert(theMonitor, 1); + IRunnableWithProgress op = getRunnable(treeEditor, structuredSelection); + if (op != null) { + run(op, treeEditor); + } + subMonitor.split(1); + } + + /** + * Execute the given refresh runnable refreshing the given editor. + * + * @param op + * the refresh runnable to execute. + * @param treeEditor + * the tree editor to refresh. + */ + private static void run(final IRunnableWithProgress op, DTreeEditor treeEditor) { + final Shell activeShell = treeEditor.getSite().getShell(); + final ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(activeShell); + try { + treeEditor.enablePropertiesUpdate(false); + monitorDialog.run(true, false, op); + } catch (final InvocationTargetException e) { + MessageDialog.openError(activeShell, Messages.EditorRefresh_error, e.getTargetException().getMessage()); + SiriusPlugin.getDefault().error(Messages.EditorRefresh_treeRefreshError, e); + } catch (final InterruptedException e) { + MessageDialog.openInformation(activeShell, Messages.EditorRefresh_refreshCancelled, e.getMessage()); + } finally { + treeEditor.enablePropertiesUpdate(true); + } + } + + /** + * Constructs the runnable refreshing the given tree editor or the tree items in the given selection if such element + * exists. + * + * @param treeEditor + * the tree editor to refresh. + * @param structuredSelection + * the selection containing tree item to refresh. + * @return the runnable refreshing the given tree editor or the tree items in the given selection if such element + * exists. + */ + private static IRunnableWithProgress getRunnable(DTreeEditor treeEditor, IStructuredSelection structuredSelection) { + IRunnableWithProgress op = null; + LinkedList<Object> minimizedSelection = new LinkedList<Object>(Arrays.asList(structuredSelection.toArray())); + if (minimizedSelection.isEmpty()) { + op = new IRunnableWithProgress() { + @Override + public void run(final IProgressMonitor monitor) { + TransactionalEditingDomain domain = treeEditor.getEditingDomain(); + domain.getCommandStack().execute(new RefreshRepresentationsCommand(domain, monitor, treeEditor.getTreeModel())); + } + }; + RefreshActionListenerRegistry.INSTANCE.notifyRepresentationIsAboutToBeRefreshed(treeEditor.getTreeModel()); + } else { + Iterable<DTreeItem> elements = Iterables.filter(minimizedSelection, DTreeItem.class); + final Collection<DTreeItem> dTreeItems = Lists.newArrayList(elements); + if (!dTreeItems.isEmpty()) { + op = new IRunnableWithProgress() { + @Override + public void run(final IProgressMonitor monitor) { + Session session = new EObjectQuery(treeEditor.getRepresentation()).getSession(); + if (session != null) { + GlobalContext globalContext = new TreeRefreshContext(session.getModelAccessor(), session.getInterpreter(), session.getSemanticResources(), + session.getTransactionalEditingDomain()); + TransactionalEditingDomain domain = treeEditor.getEditingDomain(); + Command localRefreshCmd = new DTreeItemLocalRefreshCommand(domain, globalContext, dTreeItems, false); + domain.getCommandStack().execute(localRefreshCmd); + } + } + }; + } + } + return op; + } +} diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/provider/Messages.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/provider/Messages.java index 634b8c7a09..40062b4894 100644 --- a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/provider/Messages.java +++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/provider/Messages.java @@ -66,13 +66,13 @@ public final class Messages { public static String EditorCreateTreeItemMenuAction_name; @TranslatableMessage - public static String EditorRefreshAction_error; + public static String EditorRefresh_error; @TranslatableMessage - public static String EditorRefreshAction_refreshCancelled; + public static String EditorRefresh_refreshCancelled; @TranslatableMessage - public static String EditorRefreshAction_treeRefreshError; + public static String EditorRefresh_treeRefreshError; @TranslatableMessage public static String ExpandDTreeItemRunnableWithProgress_expandTreeItem; diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/EditorRefreshAction.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/EditorRefreshAction.java index b79b0aea3a..2372ad2cf0 100644 --- a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/EditorRefreshAction.java +++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/EditorRefreshAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES. * 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 @@ -10,20 +10,12 @@ *******************************************************************************/ package org.eclipse.sirius.tree.ui.tools.internal.editor.actions; -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.sirius.business.api.dialect.command.RefreshRepresentationsCommand; -import org.eclipse.sirius.tree.ui.provider.Messages; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.sirius.tree.ui.business.internal.refresh.TreeRefresherHelper; import org.eclipse.sirius.tree.ui.tools.internal.editor.DTreeEditor; -import org.eclipse.sirius.ui.business.api.action.RefreshActionListenerRegistry; -import org.eclipse.sirius.viewpoint.SiriusPlugin; -import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorActionDelegate; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPart; @@ -35,8 +27,7 @@ import org.eclipse.ui.IWorkbenchPart; */ public class EditorRefreshAction implements IEditorActionDelegate { /** - * This records the editor or view with which the action is currently - * associated. + * This records the editor or view with which the action is currently associated. */ protected IWorkbenchPart workbenchPart; @@ -48,26 +39,7 @@ public class EditorRefreshAction implements IEditorActionDelegate { @Override public void run(final IAction action) { if (workbenchPart instanceof DTreeEditor) { - final IRunnableWithProgress op = new IRunnableWithProgress() { - @Override - public void run(final IProgressMonitor monitor) { - final DTreeEditor treeEditor = (DTreeEditor) workbenchPart; - treeEditor.enablePropertiesUpdate(false); - RefreshActionListenerRegistry.INSTANCE.notifyRepresentationIsAboutToBeRefreshed(treeEditor.getTreeModel()); - treeEditor.getEditingDomain().getCommandStack().execute(new RefreshRepresentationsCommand(treeEditor.getEditingDomain(), monitor, treeEditor.getTreeModel())); - treeEditor.enablePropertiesUpdate(true); - } - }; - final Shell activeShell = workbenchPart.getSite().getShell(); - final ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(activeShell); - try { - monitorDialog.run(false, false, op); - } catch (final InvocationTargetException e) { - MessageDialog.openError(activeShell, Messages.EditorRefreshAction_error, e.getTargetException().getMessage()); - SiriusPlugin.getDefault().error(Messages.EditorRefreshAction_treeRefreshError, e); - } catch (final InterruptedException e) { - MessageDialog.openInformation(activeShell, Messages.EditorRefreshAction_refreshCancelled, e.getMessage()); - } + TreeRefresherHelper.refreshEditor((DTreeEditor) workbenchPart, new StructuredSelection(), new NullProgressMonitor()); } } diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/RefreshAction.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/RefreshAction.java index ab7c1e882f..3883d910b1 100644 --- a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/RefreshAction.java +++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/RefreshAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES. * 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 @@ -10,43 +10,21 @@ *******************************************************************************/ package org.eclipse.sirius.tree.ui.tools.internal.editor.actions; -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedList; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.sirius.business.api.dialect.command.RefreshRepresentationsCommand; -import org.eclipse.sirius.business.api.query.EObjectQuery; -import org.eclipse.sirius.business.api.session.Session; -import org.eclipse.sirius.tree.DTreeItem; -import org.eclipse.sirius.tree.business.api.command.DTreeItemLocalRefreshCommand; -import org.eclipse.sirius.tree.business.internal.dialect.common.tree.TreeRefreshContext; -import org.eclipse.sirius.tree.business.internal.dialect.common.viewpoint.GlobalContext; +import org.eclipse.sirius.tree.ui.business.internal.refresh.TreeRefresherHelper; import org.eclipse.sirius.tree.ui.provider.Messages; import org.eclipse.sirius.tree.ui.tools.internal.editor.DTreeEditor; import org.eclipse.sirius.tree.ui.tools.internal.editor.DTreeViewerManager; -import org.eclipse.sirius.ui.business.api.action.RefreshActionListenerRegistry; -import org.eclipse.sirius.viewpoint.SiriusPlugin; -import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.PlatformUI; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - /** * This action refresh the entire tree or the tree items elements selected. * @@ -58,8 +36,6 @@ public class RefreshAction extends Action implements IObjectActionDelegate { private ISelection selection; - private LinkedList<Object> minimizedSelection; - /** * Default constructor. * @@ -69,7 +45,6 @@ public class RefreshAction extends Action implements IObjectActionDelegate { public RefreshAction(final DTreeEditor treeEditor) { super(Messages.RefreshAction_refreshTreeElement, DTreeViewerManager.getImageRegistry().getDescriptor(DTreeViewerManager.REFRESH_IMG)); this.treeEditor = treeEditor; - minimizedSelection = new LinkedList<Object>(); } @Override @@ -82,46 +57,10 @@ public class RefreshAction extends Action implements IObjectActionDelegate { this.selection = activePage.getSelection(); if (this.selection instanceof IStructuredSelection) { final IStructuredSelection structuredSelection = (IStructuredSelection) this.selection; - minimizedSelection = new LinkedList<Object>(Arrays.asList(structuredSelection.toArray())); - } - IRunnableWithProgress op = getRunnable(); - if (op != null) { - run(op); - } - } - } - } - - private IRunnableWithProgress getRunnable() { - IRunnableWithProgress op = null; - if (minimizedSelection.isEmpty()) { - op = new IRunnableWithProgress() { - @Override - public void run(final IProgressMonitor monitor) { - TransactionalEditingDomain domain = treeEditor.getEditingDomain(); - domain.getCommandStack().execute(new RefreshRepresentationsCommand(domain, monitor, treeEditor.getTreeModel())); + TreeRefresherHelper.refreshEditor(treeEditor, structuredSelection, new NullProgressMonitor()); } - }; - RefreshActionListenerRegistry.INSTANCE.notifyRepresentationIsAboutToBeRefreshed(treeEditor.getTreeModel()); - } else { - Iterable<DTreeItem> elements = Iterables.filter(minimizedSelection, DTreeItem.class); - final Collection<DTreeItem> dTreeItems = Lists.newArrayList(elements); - if (!dTreeItems.isEmpty()) { - op = new IRunnableWithProgress() { - @Override - public void run(final IProgressMonitor monitor) { - Session session = new EObjectQuery(treeEditor.getRepresentation()).getSession(); - if (session != null) { - GlobalContext globalContext = new TreeRefreshContext(session.getModelAccessor(), session.getInterpreter(), session.getSemanticResources(), session.getTransactionalEditingDomain()); - TransactionalEditingDomain domain = treeEditor.getEditingDomain(); - Command localRefreshCmd = new DTreeItemLocalRefreshCommand(domain, globalContext, dTreeItems, false); - domain.getCommandStack().execute(localRefreshCmd); - } - } - }; } } - return op; } @Override @@ -133,22 +72,6 @@ public class RefreshAction extends Action implements IObjectActionDelegate { run(); } - private void run(final IRunnableWithProgress op) { - final Shell activeShell = treeEditor.getSite().getShell(); - final ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(activeShell); - try { - treeEditor.enablePropertiesUpdate(false); - monitorDialog.run(true, false, op); - } catch (final InvocationTargetException e) { - MessageDialog.openError(activeShell, Messages.EditorRefreshAction_error, e.getTargetException().getMessage()); - SiriusPlugin.getDefault().error(Messages.EditorRefreshAction_treeRefreshError, e); - } catch (final InterruptedException e) { - MessageDialog.openInformation(activeShell, Messages.EditorRefreshAction_refreshCancelled, e.getMessage()); - } finally { - treeEditor.enablePropertiesUpdate(true); - } - } - @Override public void selectionChanged(IAction action, ISelection sel) { this.selection = sel; diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/dialect/DialectUIServices.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/dialect/DialectUIServices.java index 3c3a36f526..d60c3411f4 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/dialect/DialectUIServices.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/dialect/DialectUIServices.java @@ -46,24 +46,20 @@ public interface DialectUIServices { Collection<CommandParameter> provideNewChildDescriptors(); /** - * Return the list of creation tool descriptors provided for a given parent - * feature. + * Return the list of creation tool descriptors provided for a given parent feature. * * @param feature * the feature containing the creation tools. - * @return the list of creation tool descriptors provided on creation tool - * container. + * @return the list of creation tool descriptors provided on creation tool container. */ Collection<CommandParameter> provideRepresentationCreationToolDescriptors(Object feature); /** - * Return the list of navigation tool descriptors provided for a given - * parent feature. + * Return the list of navigation tool descriptors provided for a given parent feature. * * @param feature * the feature containing the navigation tools. - * @return the list of navigation tool descriptors provided on navigation - * tool container. + * @return the list of navigation tool descriptors provided on navigation tool container. */ Collection<CommandParameter> provideRepresentationNavigationToolDescriptors(Object feature); @@ -78,8 +74,8 @@ public interface DialectUIServices { Collection<CommandParameter> provideTools(EObject object); /** - * Return the list of additional mapping descriptors to appear inside a - * layer, which can depend on the representation type. + * Return the list of additional mapping descriptors to appear inside a layer, which can depend on the + * representation type. * * @param object * the context of the child creation. @@ -89,8 +85,7 @@ public interface DialectUIServices { Collection<CommandParameter> provideAdditionalMappings(EObject object); /** - * Open an editor for the given representation (if only you know about this - * kind of representation). + * Open an editor for the given representation (if only you know about this kind of representation). * * @param dRepresentation * {@link DRepresentation} to open. @@ -103,8 +98,17 @@ public interface DialectUIServices { IEditorPart openEditor(Session session, DRepresentation dRepresentation, IProgressMonitor monitor); /** - * Sets the given {@link DRepresentationElement}s as current selection for - * the editor. + * Execute a full refresh of the given editor. + * + * @param dialectEditor + * the editor to refresh. + * @param monitor + * the monitor to use for refreshing. + */ + void refreshEditor(DialectEditor dialectEditor, IProgressMonitor monitor); + + /** + * Sets the given {@link DRepresentationElement}s as current selection for the editor. * * @param dialectEditor * the editor which needs a selection update. @@ -114,8 +118,8 @@ public interface DialectUIServices { void setSelection(DialectEditor dialectEditor, List<DRepresentationElement> selection); /** - * Sets the given {@link DRepresentationElement}s as current selection for - * the editor and reveal the selection if needed. + * Sets the given {@link DRepresentationElement}s as current selection for the editor and reveal the selection if + * needed. * * @param dialectEditor * the editor which needs a selection update. @@ -143,11 +147,9 @@ public interface DialectUIServices { String getEditorName(DRepresentation representation); /** - * Creates a new {@link AdapterFactory} used in the description editor for - * the provided types. + * Creates a new {@link AdapterFactory} used in the description editor for the provided types. * - * @return a new {@link AdapterFactory} used in the description editor for - * the provided types. + * @return a new {@link AdapterFactory} used in the description editor for the provided types. */ AdapterFactory createAdapterFactory(); @@ -156,23 +158,21 @@ public interface DialectUIServices { * * @param editorPart * the editor to close. - * @return true if the dialect manage such {@link IEditorPart}, false - * otherwise. + * @return true if the dialect manage such {@link IEditorPart}, false otherwise. */ boolean canHandleEditor(IEditorPart editorPart); /** - * Close an editor (if only you know about this kind of {@link IEditorPart}) - * and execute the specification operations. + * Close an editor (if only you know about this kind of {@link IEditorPart}) and execute the specification + * operations. * * @param editor * the editor to close * @param save - * <code>true</code> to save the editor contents if required - * (recommended), and <code>false</code> to discard any unsaved - * changes - * @return <code>true</code> if the editor was successfully closed, and - * <code>false</code> if the editor is still open + * <code>true</code> to save the editor contents if required (recommended), and <code>false</code> to + * discard any unsaved changes + * @return <code>true</code> if the editor was successfully closed, and <code>false</code> if the editor is still + * open */ boolean closeEditor(IEditorPart editor, boolean save); @@ -234,42 +234,35 @@ public interface DialectUIServices { * * @param representation * representation to test. - * @return true if the dialect can handle the representation, false - * otherwise. + * @return true if the dialect can handle the representation, false otherwise. */ boolean canHandle(DRepresentation representation); /** - * Tell whether the dialect is able to handle the representationDescriptor - * associated representation. + * Tell whether the dialect is able to handle the representationDescriptor associated representation. * * @param representationDescriptor * Represents the representation to test. - * @return true if the dialect can handle the representation, false - * otherwise. + * @return true if the dialect can handle the representation, false otherwise. */ boolean canHandle(DRepresentationDescriptor representationDescriptor); /** - * Tell whether the dialect is able to handle the given representation - * description. + * Tell whether the dialect is able to handle the given representation description. * * @param description * the representation description to test. - * @return true if the dialect can handle the representation description, - * false otherwise. + * @return true if the dialect can handle the representation description, false otherwise. * @since 1.0.0 M6 */ boolean canHandle(RepresentationDescription description); /** - * Tell whether the dialect is able to handle the given representation - * extension description. + * Tell whether the dialect is able to handle the given representation extension description. * * @param description * the representation extension description to test. - * @return true if the dialect can handle the representation extension - * description, false otherwise. + * @return true if the dialect can handle the representation extension description, false otherwise. * @since 1.0.0 M6 */ boolean canHandle(RepresentationExtensionDescription description); @@ -278,8 +271,7 @@ public interface DialectUIServices { * Return Hierachical LabelProvider. * * @param currentLabelProvider - * the current label provider. If the current label is null, the - * result can be null + * the current label provider. If the current label is null, the result can be null * @return a LabelProvider * @deprecated use directly a {@link HierarchyLabelProvider}. */ @@ -287,8 +279,7 @@ public interface DialectUIServices { ILabelProvider getHierarchyLabelProvider(ILabelProvider currentLabelProvider); /** - * Allows the {@link DialectUIServices} to customize the tooltip displayed - * in the VSM editor. + * Allows the {@link DialectUIServices} to customize the tooltip displayed in the VSM editor. * * @param toolTipText * the initial tool tip @@ -303,8 +294,7 @@ public interface DialectUIServices { String completeToolTipText(String toolTipText, EObject eObject, EStructuralFeature feature); /** - * Allows the {@link DialectUIServices} to customize the tooltip displayed - * in the VSM editor. + * Allows the {@link DialectUIServices} to customize the tooltip displayed in the VSM editor. * * @param toolTipText * the initial tool tip @@ -313,9 +303,8 @@ public interface DialectUIServices { * * @return a customized tooltip if needed, the initial tooltip otherwise. * @since 1.0.0 M6 - * @deprecated this method has not access to the feature of eObject. This is - * supported in org.eclipse.sirius.ui.business.api.dialect. - * DialectUIServices.completeToolTipText(String, EObject, + * @deprecated this method has not access to the feature of eObject. This is supported in + * org.eclipse.sirius.ui.business.api.dialect. DialectUIServices.completeToolTipText(String, EObject, * EStructuralFeature) */ @Deprecated diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/dialect/DialectUIManagerImpl.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/dialect/DialectUIManagerImpl.java index f6e0ccf647..5d9a58768d 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/dialect/DialectUIManagerImpl.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/dialect/DialectUIManagerImpl.java @@ -54,8 +54,7 @@ import org.eclipse.sirius.viewpoint.provider.ViewpointItemProviderAdapterFactory import org.eclipse.ui.IEditorPart; /** - * Class able to manage a set of dialects to provides the usual dialect services - * using the Eclipse environment. + * Class able to manage a set of dialects to provides the usual dialect services using the Eclipse environment. * * @author cbrun */ @@ -306,9 +305,7 @@ public class DialectUIManagerImpl implements DialectUIManager { /** * {@inheritDoc} * - * @deprecated use directly a - * {@link org.eclipse.sirius.ui.business.api.dialect.HierarchyLabelProvider} - * . + * @deprecated use directly a {@link org.eclipse.sirius.ui.business.api.dialect.HierarchyLabelProvider} . */ @Deprecated @Override @@ -376,4 +373,13 @@ public class DialectUIManagerImpl implements DialectUIManager { return SiriusEditPlugin.getPlugin().getPreferenceStore().getBoolean(SiriusUIPreferencesKeys.PREF_REFRESH_ON_REPRESENTATION_OPENING.name()); } + @Override + public void refreshEditor(DialectEditor dialectEditor, IProgressMonitor monitor) { + for (final DialectUI dialect : dialects.values()) { + if (dialect.getServices().canHandleEditor(dialectEditor)) { + dialect.getServices().refreshEditor(dialectEditor, monitor); + } + } + } + } |