diff options
| author | Esteban Dugueperoux | 2015-02-10 15:06:03 +0000 |
|---|---|---|
| committer | Esteban DUGUEPEROUX | 2015-02-10 15:26:03 +0000 |
| commit | f0b9dc110ca0369d2ea464aa31994ae6bda2fae4 (patch) | |
| tree | 60a49e5320a5bb8d459a692ede1b207e50c2eb62 | |
| parent | ce0da355f74a7dc26d043df3af9f06ba10bf4e4e (diff) | |
| download | org.eclipse.sirius-f0b9dc110ca0369d2ea464aa31994ae6bda2fae4.tar.gz org.eclipse.sirius-f0b9dc110ca0369d2ea464aa31994ae6bda2fae4.tar.xz org.eclipse.sirius-f0b9dc110ca0369d2ea464aa31994ae6bda2fae4.zip | |
[458977] Have F5 shortcut for refresh in tree/table dialect
Add F5 binding for local/global refresh in tree/table dialect.
Only global refresh is possible for table.
Bug: 458977
Change-Id: I660b1916ccbe6d016ae56dd2d90f417815cbc869
Signed-off-by: Esteban Dugueperoux <esteban.dugueperoux@obeo.fr>
14 files changed, 344 insertions, 190 deletions
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html index b620d7997f..44dca054e2 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html @@ -140,7 +140,20 @@ <code>org.eclipse.sirius.ecore.extender.business.api.accessor.CompositeMetamodelExtender.eRemoveInverseCrossReferences()</code> has been changed to return the list of changed objects by the inverse cross references removal. </li> <li>The exception - <code>org.eclipse.sirius.ecore.extender.IllegalURIException</code> has beed removed. It was not actually thrown anywhere in the code. + <code>org.eclipse.sirius.ecore.extender.IllegalURIException</code> has been removed. It was not actually thrown anywhere in the code. + </li> + </ul> + <h4 id="Changesinorg.eclipse.sirius.tree">Changes in + <code>org.eclipse.sirius.tree</code> + </h4> + <ul> + <li>The method + <code>org.eclipse.sirius.tree.business.api.interaction.DTreeItemUserInteraction.refreshContent(boolean fullRefresh)</code> has been added to allow full refresh from a specified + <code>DTreeItem</code>. + </li> + <li>The EMF Command + <code>org.eclipse.sirius.tree.business.api.command.DTreeItemLocalRefreshCommand</code> has been added to call + <code>DTreeItemUserInteraction.refreshContent(boolean fullRefresh)</code> in an EMF Command. </li> </ul> <h4 id="Changesinorg.eclipse.sirius.diagram">Changes in @@ -570,7 +583,7 @@ <code>TreeUIHelper.toContentHTMl()</code> </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.tree">Changes in + <h4 id="Changesinorg.eclipse.sirius.tree2">Changes in <code>org.eclipse.sirius.tree</code> </h4> <ul> @@ -1460,7 +1473,7 @@ if (rootPackage != null && rootPackage.getNsURI().equals(DiagramPackage. <code>org.eclipse.sirius.table.tools.api.command.ITableCommandFactory.setAutoRefreshDTable()</code> method was removed. It had no effect, any code which called it can simply be removed. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.tree2">Changes in + <h4 id="Changesinorg.eclipse.sirius.tree3">Changes in <code>org.eclipse.sirius.tree</code> </h4> <ul> @@ -1896,7 +1909,7 @@ if (rootPackage != null && rootPackage.getNsURI().equals(DiagramPackage. <code>TableHelper.getCell(DLine, String)</code> has been removed. Use the variant which take a DLine and a DColumn as parameters. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.tree3">Changes in + <h4 id="Changesinorg.eclipse.sirius.tree4">Changes in <code>org.eclipse.sirius.tree</code> </h4> <ul> diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile index 3cb60af163..a920fd4801 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile @@ -42,7 +42,12 @@ h4. Changes in @org.eclipse.sirius.ecore.extender@ * The method @org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor.eRemoveInverseCrossReferences()@ has been changed to return the list of changed objects by the inverse cross references removal. * The method @org.eclipse.sirius.ecore.extender.business.api.accessor.IMetamodelExtender.eRemoveInverseCrossReferences()@ has been changed to return the list of changed objects by the inverse cross references removal. * The method @org.eclipse.sirius.ecore.extender.business.api.accessor.CompositeMetamodelExtender.eRemoveInverseCrossReferences()@ has been changed to return the list of changed objects by the inverse cross references removal. -* The exception @org.eclipse.sirius.ecore.extender.IllegalURIException@ has beed removed. It was not actually thrown anywhere in the code. +* The exception @org.eclipse.sirius.ecore.extender.IllegalURIException@ has been removed. It was not actually thrown anywhere in the code. + +h4. Changes in @org.eclipse.sirius.tree@ + +* The method @org.eclipse.sirius.tree.business.api.interaction.DTreeItemUserInteraction.refreshContent(boolean fullRefresh)@ has been added to allow full refresh from a specified @DTreeItem@. +* The EMF Command @org.eclipse.sirius.tree.business.api.command.DTreeItemLocalRefreshCommand@ has been added to call @DTreeItemUserInteraction.refreshContent(boolean fullRefresh)@ in an EMF Command. h4. Changes in @org.eclipse.sirius.diagram@ diff --git a/plugins/org.eclipse.sirius.table.ui/plugin.xml b/plugins/org.eclipse.sirius.table.ui/plugin.xml index fc20a370a5..1860a58072 100644 --- a/plugins/org.eclipse.sirius.table.ui/plugin.xml +++ b/plugins/org.eclipse.sirius.table.ui/plugin.xml @@ -225,4 +225,28 @@ name="Export to CSV"> </command> </extension> + + <extension point="org.eclipse.ui.bindings"> + <key + commandId="org.eclipse.sirius.table.ui.command.refreshElement" + contextId="org.eclipse.sirius.table.ui.EditorID.tableContext" + schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" + sequence="F5"/> + </extension> + + <extension + point="org.eclipse.ui.handlers"> + <handler + class="org.eclipse.sirius.table.ui.tools.internal.commands.RefreshElementCommand" + commandId="org.eclipse.sirius.table.ui.command.refreshElement"> + </handler> + </extension> + + <extension point="org.eclipse.ui.commands"> + <command + id="org.eclipse.sirius.table.ui.command.refreshElement" + name="Refresh element"> + </command> + </extension> + </plugin> diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/commands/RefreshElementCommand.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/commands/RefreshElementCommand.java new file mode 100644 index 0000000000..8a413ec351 --- /dev/null +++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/commands/RefreshElementCommand.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2015 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.tools.internal.commands; + +import org.eclipse.sirius.table.ui.tools.internal.editor.action.RefreshAction; +import org.eclipse.sirius.ui.tools.internal.commands.AbstractActionWrapperHandler; + +/** + * A {@link AbstractActionWrapperHandler} to launch refresh. + * + * @author <a href="mailto:esteban.dugueperoux@obeo.fr">Esteban Dugueperoux</a> + */ +public class RefreshElementCommand extends AbstractActionWrapperHandler { + + /** + * Construct a new instance. + */ + public RefreshElementCommand() { + super(new RefreshAction(null)); + } + +} 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 0e8e854bf3..1bc4e7bc4d 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 @@ -15,25 +15,33 @@ import java.lang.reflect.InvocationTargetException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.transaction.TransactionalEditingDomain; 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.swt.widgets.Shell; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.sirius.business.api.dialect.command.RefreshRepresentationsCommand; 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; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; /** * This action refresh the content of the table. * * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a> */ -public class RefreshAction extends Action { +public class RefreshAction extends Action implements IObjectActionDelegate { + private static final String DEFAULT_NAME = "Refresh table"; - AbstractDTableEditor tableEditor; + private AbstractDTableEditor tableEditor; /** * Default constructor. @@ -46,33 +54,49 @@ public class RefreshAction extends Action { this.tableEditor = tableEditor; } - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.action.Action#run() - */ @Override public void run() { - final IRunnableWithProgress op = new IRunnableWithProgress() { - public void run(final IProgressMonitor monitor) { - TransactionalEditingDomain domain = tableEditor.getEditingDomain(); - domain.getCommandStack().execute(new RefreshRepresentationsCommand(domain, monitor, tableEditor.getTableModel())); + IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + if (activePage != null) { + IEditorPart activeEditor = activePage.getActiveEditor(); + if (activeEditor instanceof AbstractDTableEditor) { + tableEditor = (AbstractDTableEditor) activeEditor; + final IRunnableWithProgress op = new IRunnableWithProgress() { + 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, "Error", e.getTargetException().getMessage()); + SiriusPlugin.getDefault().error("Error while refreshing table", e); + } catch (final InterruptedException e) { + MessageDialog.openInformation(activeShell, "Cancelled", e.getMessage()); + } finally { + tableEditor.enablePropertiesUpdate(true); + } } - }; - 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, "Error", e.getTargetException().getMessage()); - SiriusPlugin.getDefault().error("Error while refreshing table", e); - } catch (final InterruptedException e) { - MessageDialog.openInformation(activeShell, "Cancelled", e.getMessage()); - } finally { - tableEditor.enablePropertiesUpdate(true); } + } + + @Override + public void run(IAction action) { + run(); + } + + @Override + public void selectionChanged(IAction action, ISelection selection) { + + } + + @Override + public void setActivePart(IAction action, IWorkbenchPart targetPart) { } } diff --git a/plugins/org.eclipse.sirius.tree.ui/plugin.xml b/plugins/org.eclipse.sirius.tree.ui/plugin.xml index f4c06f9eb2..4857692992 100644 --- a/plugins/org.eclipse.sirius.tree.ui/plugin.xml +++ b/plugins/org.eclipse.sirius.tree.ui/plugin.xml @@ -185,4 +185,28 @@ </action> </editorContribution> </extension> + + <extension point="org.eclipse.ui.bindings"> + <key + commandId="org.eclipse.sirius.tree.ui.command.refreshElement" + contextId="org.eclipse.sirius.tree.ui.EditorID.treeContext" + schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" + sequence="F5"/> + </extension> + + <extension + point="org.eclipse.ui.handlers"> + <handler + class="org.eclipse.sirius.tree.ui.tools.internal.commands.RefreshElementCommand" + commandId="org.eclipse.sirius.tree.ui.command.refreshElement"> + </handler> + </extension> + + <extension point="org.eclipse.ui.commands"> + <command + id="org.eclipse.sirius.tree.ui.command.refreshElement" + name="Refresh element"> + </command> + </extension> + </plugin> diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/commands/RefreshElementCommand.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/commands/RefreshElementCommand.java new file mode 100644 index 0000000000..dda79a6d8a --- /dev/null +++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/commands/RefreshElementCommand.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2015 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.tools.internal.commands; + +import org.eclipse.sirius.tree.ui.tools.internal.editor.actions.RefreshAction; +import org.eclipse.sirius.ui.tools.internal.commands.AbstractActionWrapperHandler; + +/** + * A {@link AbstractActionWrapperHandler} to launch refresh. + * + * @author <a href="mailto:esteban.dugueperoux@obeo.fr">Esteban Dugueperoux</a> + */ +public class RefreshElementCommand extends AbstractActionWrapperHandler { + + /** + * Construct a new instance. + */ + public RefreshElementCommand() { + super(new RefreshAction(null)); + } + +} 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 86bcb40ed3..325e145c74 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 @@ -12,9 +12,11 @@ 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.jface.action.Action; import org.eclipse.jface.action.IAction; @@ -23,32 +25,36 @@ 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.viewpoint.GlobalContext; +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; -import org.eclipse.sirius.business.api.dialect.command.RefreshRepresentationsCommand; -import org.eclipse.sirius.tools.api.command.SiriusCommand; -import org.eclipse.sirius.tree.DTreeElement; -import org.eclipse.sirius.tree.business.internal.helper.RefreshTreeElementTask; -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; - /** * This action refresh the entire tree or the tree items elements selected. * * @author nlepine */ public class RefreshAction extends Action implements IObjectActionDelegate { + private static final String DEFAULT_NAME = "Refresh Tree Element"; - DTreeEditor treeEditor; + private DTreeEditor treeEditor; private ISelection selection; @@ -66,53 +72,63 @@ public class RefreshAction extends Action implements IObjectActionDelegate { minimizedSelection = new LinkedList<Object>(); } - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.action.Action#run() - */ @Override public void run() { - this.selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection(); - if (this.selection instanceof IStructuredSelection) { - final IStructuredSelection structuredSelection = (IStructuredSelection) this.selection; - minimizedSelection = new LinkedList<Object>(Arrays.asList(structuredSelection.toArray())); - + IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + if (activePage != null) { + IEditorPart activeEditor = activePage.getActiveEditor(); + if (activeEditor instanceof DTreeEditor) { + treeEditor = (DTreeEditor) activeEditor; + 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); + } + } } - final IRunnableWithProgress op = new IRunnableWithProgress() { - public void run(final IProgressMonitor monitor) { - final SiriusCommand result = new SiriusCommand(treeEditor.getEditingDomain()); - Iterable<DTreeElement> elements = Iterables.filter(minimizedSelection, DTreeElement.class); - result.getTasks().add(new RefreshTreeElementTask(Lists.newArrayList(elements), treeEditor.getEditingDomain(), monitor)); - treeEditor.getEditingDomain().getCommandStack().execute(result); + } + + private IRunnableWithProgress getRunnable() { + IRunnableWithProgress op = null; + if (minimizedSelection.isEmpty()) { + op = new IRunnableWithProgress() { + 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() { + public void run(final IProgressMonitor monitor) { + Session session = new EObjectQuery(treeEditor.getRepresentation()).getSession(); + if (session != null) { + GlobalContext globalContext = new GlobalContext(session.getModelAccessor(), session.getInterpreter(), session.getSemanticResources()); + TransactionalEditingDomain domain = treeEditor.getEditingDomain(); + Command localRefreshCmd = new DTreeItemLocalRefreshCommand(domain, globalContext, dTreeItems, false); + domain.getCommandStack().execute(localRefreshCmd); + } + } + }; } - }; - run(op); + } + return op; } - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, - * org.eclipse.ui.IWorkbenchPart) - */ + @Override public void setActivePart(IAction action, IWorkbenchPart targetPart) { } - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ + @Override public void run(IAction action) { - IRunnableWithProgress op = new IRunnableWithProgress() { - public void run(final IProgressMonitor monitor) { - TransactionalEditingDomain domain = treeEditor.getEditingDomain(); - domain.getCommandStack().execute(new RefreshRepresentationsCommand(domain, monitor, treeEditor.getTreeModel())); - } - }; - RefreshActionListenerRegistry.INSTANCE.notifyRepresentationIsAboutToBeRefreshed(treeEditor.getTreeModel()); - run(op); + run(); } private void run(final IRunnableWithProgress op) { @@ -131,9 +147,7 @@ public class RefreshAction extends Action implements IObjectActionDelegate { } } - /** - * {@inheritDoc} - */ + @Override public void selectionChanged(IAction action, ISelection sel) { this.selection = sel; } diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/listeners/DTreeViewerListener.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/listeners/DTreeViewerListener.java index 4b09585b5e..c91e7d2eb9 100644 --- a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/listeners/DTreeViewerListener.java +++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/listeners/DTreeViewerListener.java @@ -58,7 +58,7 @@ public class DTreeViewerListener implements ITreeViewerListener { expandDTreeItemCmd.append(new DTreeItemExpansionChangeCommand(globalContext, domain, dTreeItem, true)); if (!Platform.getPreferencesService().getBoolean(SiriusPlugin.ID, SiriusPreferencesKeys.PREF_AUTO_REFRESH.name(), false, null)) { SiriusCommand result = new SiriusCommand(domain); - result.getTasks().add(new RefreshTreeElementTask((DTreeItem) event.getElement(), domain)); + result.getTasks().add(new RefreshTreeElementTask((DTreeItem) event.getElement())); expandDTreeItemCmd.append(result); } commandStack.execute(expandDTreeItemCmd); diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/api/command/DTreeItemLocalRefreshCommand.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/api/command/DTreeItemLocalRefreshCommand.java new file mode 100644 index 0000000000..34172802ae --- /dev/null +++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/api/command/DTreeItemLocalRefreshCommand.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2015 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.business.api.command; + +import java.util.Collection; + +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.sirius.tree.DTreeItem; +import org.eclipse.sirius.tree.business.api.interaction.DTreeItemUserInteraction; +import org.eclipse.sirius.tree.business.internal.dialect.common.viewpoint.GlobalContext; + +/** + * EMF Command to do a local refresh of a set of {@link DTreeItem}. + * + * @author <a href="mailto:esteban.dugueperoux@obeo.fr">Esteban Dugueperoux</a> + */ +public class DTreeItemLocalRefreshCommand extends RecordingCommand { + + private GlobalContext globalContext; + + private Collection<DTreeItem> dTreeItems; + + private boolean fullRefresh; + + /** + * Default constructor. + * + * @param domain + * the {@link TransactionalEditingDomain} on which do changes + * @param globalContext + * the {@link GlobalContext} to do refresh + * @param dTreeItems + * the {@link DTreeItem} to refresh + * @param fullRefresh + * true to do a full refresh of the {@link DTreeItem} and its + * children recursively + */ + public DTreeItemLocalRefreshCommand(TransactionalEditingDomain domain, GlobalContext globalContext, Collection<DTreeItem> dTreeItems, boolean fullRefresh) { + super(domain, "Refresh locally tree"); + this.globalContext = globalContext; + this.dTreeItems = dTreeItems; + this.fullRefresh = fullRefresh; + } + + @Override + protected void doExecute() { + for (DTreeItem dTreeItem : dTreeItems) { + new DTreeItemUserInteraction(dTreeItem, globalContext).refreshContent(fullRefresh); + } + } + +} diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/api/interaction/DTreeItemUserInteraction.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/api/interaction/DTreeItemUserInteraction.java index d2a9df220f..fccf2789b4 100644 --- a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/api/interaction/DTreeItemUserInteraction.java +++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/api/interaction/DTreeItemUserInteraction.java @@ -67,11 +67,22 @@ public class DTreeItemUserInteraction { * Refresh the content of the TreeItem. */ public void refreshContent() { + refreshContent(false); + } + + /** + * Refresh the content of the TreeItem. + * + * @param fullRefresh + * true to do a full refresh of the {@link DTreeItem} and its + * children recursively + */ + public void refreshContent(boolean fullRefresh) { SemanticPartitionInvalidator invalidator = new SemanticPartitionInvalidator(); Option<DTree> parentTree = new DTreeItemQuery(item).getParentTree(); if (parentTree.some()) { DTreeRefresh refresher = new DTreeRefresh(item, new TreeDescriptionQuery(parentTree.get().getDescription()).getAllDescendantMappings(), invalidator, ctx); - refresher.refresh(false, new NullProgressMonitor()); + refresher.refresh(fullRefresh, new NullProgressMonitor()); } } diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/helper/RefreshTreeElementTask.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/helper/RefreshTreeElementTask.java index 844139f491..bcdd773c55 100644 --- a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/helper/RefreshTreeElementTask.java +++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/helper/RefreshTreeElementTask.java @@ -16,27 +16,25 @@ import java.util.Iterator; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.TransactionalEditingDomain; - -import org.eclipse.sirius.business.api.dialect.command.RefreshRepresentationsCommand; +import org.eclipse.sirius.business.api.dialect.DialectManager; import org.eclipse.sirius.business.api.helper.task.AbstractCommandTask; +import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter; +import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor; import org.eclipse.sirius.tree.DTree; import org.eclipse.sirius.tree.DTreeElement; import org.eclipse.sirius.tree.DTreeItem; -import org.eclipse.sirius.tree.tools.internal.command.RefreshTreeElementCommand; +import org.eclipse.sirius.tree.business.internal.refresh.DTreeElementSynchronizerSpec; +import org.eclipse.sirius.viewpoint.SiriusPlugin; /** * Task for refresh tree item elements. * * @author nlepine - * */ public class RefreshTreeElementTask extends AbstractCommandTask { private EObject uniqueRefreshable; - private final TransactionalEditingDomain editingDomain; - private Collection<DTreeElement> refreshablesList; /** The monitor for the execution of this task */ @@ -47,11 +45,9 @@ public class RefreshTreeElementTask extends AbstractCommandTask { * * @param objectToRefresh * the object to refresh - * @param editingDomain - * the transactional editing domain */ - public RefreshTreeElementTask(final EObject objectToRefresh, final TransactionalEditingDomain editingDomain) { - this(objectToRefresh, editingDomain, new NullProgressMonitor()); + public RefreshTreeElementTask(final EObject objectToRefresh) { + this(objectToRefresh, new NullProgressMonitor()); } /** @@ -59,14 +55,11 @@ public class RefreshTreeElementTask extends AbstractCommandTask { * * @param objectToRefresh * the object to refresh - * @param editingDomain - * the transactional editing domain * @param monitor * The monitor for the execution of this task */ - public RefreshTreeElementTask(final EObject objectToRefresh, final TransactionalEditingDomain editingDomain, final IProgressMonitor monitor) { + public RefreshTreeElementTask(final EObject objectToRefresh, final IProgressMonitor monitor) { this.uniqueRefreshable = objectToRefresh; - this.editingDomain = editingDomain; this.monitor = monitor; } @@ -75,11 +68,9 @@ public class RefreshTreeElementTask extends AbstractCommandTask { * * @param objectsToRefresh * the object to refresh - * @param editingDomain - * the transactional editing domain */ - public RefreshTreeElementTask(Collection<DTreeElement> objectsToRefresh, TransactionalEditingDomain editingDomain) { - this(objectsToRefresh, editingDomain, new NullProgressMonitor()); + public RefreshTreeElementTask(Collection<DTreeElement> objectsToRefresh) { + this(objectsToRefresh, new NullProgressMonitor()); } /** @@ -87,45 +78,44 @@ public class RefreshTreeElementTask extends AbstractCommandTask { * * @param objectsToRefresh * the object to refresh - * @param editingDomain - * the transactional editing domain * @param monitor * The monitor for the execution of this task */ - public RefreshTreeElementTask(Collection<DTreeElement> objectsToRefresh, TransactionalEditingDomain editingDomain, IProgressMonitor monitor) { + public RefreshTreeElementTask(Collection<DTreeElement> objectsToRefresh, IProgressMonitor monitor) { this.refreshablesList = objectsToRefresh; - this.editingDomain = editingDomain; this.monitor = monitor; } - /** - * {@inheritDoc} - * - * @see org.eclipse.sirius.business.api.helper.task.ICommandTask#execute() - */ + @Override public void execute() { if (uniqueRefreshable instanceof DTree) { - editingDomain.getCommandStack().execute(new RefreshRepresentationsCommand(editingDomain, monitor, (DTree) uniqueRefreshable)); + DialectManager.INSTANCE.refresh((DTree) uniqueRefreshable, monitor); } if (uniqueRefreshable instanceof DTreeElement) { - editingDomain.getCommandStack().execute(new RefreshTreeElementCommand(editingDomain, (DTreeItem) uniqueRefreshable, monitor)); + refreshTreeElement((DTreeItem) uniqueRefreshable); } if (refreshablesList != null) { final Iterator<DTreeElement> it = refreshablesList.iterator(); while (it.hasNext()) { final Object obj = it.next(); if (obj instanceof DTree) { - editingDomain.getCommandStack().execute(new RefreshRepresentationsCommand(editingDomain, monitor, (DTree) obj)); + DialectManager.INSTANCE.refresh((DTree) obj, monitor); } else if (obj instanceof DTreeElement) { - editingDomain.getCommandStack().execute(new RefreshTreeElementCommand(editingDomain, (DTreeItem) obj, monitor)); + refreshTreeElement((DTreeItem) obj); } } } } - /** - * {@inheritDoc} - */ + private void refreshTreeElement(DTreeItem treeElement) { + DTree tree = TreeHelper.getTree(treeElement); + IInterpreter interpreter = SiriusPlugin.getDefault().getInterpreterRegistry().getInterpreter(tree.getTarget()); + ModelAccessor accessor = SiriusPlugin.getDefault().getModelAccessorRegistry().getModelAccessor(tree); + DTreeElementSynchronizerSpec synchronizer = new DTreeElementSynchronizerSpec(interpreter, accessor); + synchronizer.refreshItemAndChildren(treeElement); + } + + @Override public String getLabel() { return "Refresh element task"; } diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/tools/internal/command/RefreshTreeElementCommand.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/tools/internal/command/RefreshTreeElementCommand.java deleted file mode 100644 index a023b31209..0000000000 --- a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/tools/internal/command/RefreshTreeElementCommand.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.tree.tools.internal.command; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter; -import org.eclipse.sirius.tree.DTree; -import org.eclipse.sirius.tree.DTreeItem; -import org.eclipse.sirius.tree.business.internal.helper.TreeHelper; -import org.eclipse.sirius.tree.business.internal.refresh.DTreeElementSynchronizerSpec; -import org.eclipse.sirius.viewpoint.SiriusPlugin; -import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor; - -/** - * Create tree item refresh command. - * - * @author nlepine - */ -public class RefreshTreeElementCommand extends RecordingCommand { - - private DTreeItem treeElement; - - /** - * Construct a new instance. - * - * @param domain - * the editing domain. - * @param treeElement - * the treeElement to refresh. - * @param monitor - * a progress monitor. - */ - public RefreshTreeElementCommand(TransactionalEditingDomain domain, DTreeItem treeElement, IProgressMonitor monitor) { - super(domain, "Refresh representation"); - this.treeElement = treeElement; - } - - /** - * Construct a new instance. - * - * @param domain - * the editing domain. - * @param treeElement - * the treeElement to refresh. - */ - public RefreshTreeElementCommand(TransactionalEditingDomain domain, DTreeItem treeElement) { - this(domain, treeElement, null); - } - - /** - * {@inheritDoc} - */ - @Override - protected void doExecute() { - DTree tree = TreeHelper.getTree(treeElement); - IInterpreter interpreter = SiriusPlugin.getDefault().getInterpreterRegistry().getInterpreter(tree.getTarget()); - ModelAccessor accessor = SiriusPlugin.getDefault().getModelAccessorRegistry().getModelAccessor(tree); - DTreeElementSynchronizerSpec synchronizer = new DTreeElementSynchronizerSpec(interpreter, accessor); - synchronizer.refreshItemAndChildren(treeElement); - } -} diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/tools/internal/command/TreeCommandFactory.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/tools/internal/command/TreeCommandFactory.java index 6939128ab4..4d2fe6fcc9 100644 --- a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/tools/internal/command/TreeCommandFactory.java +++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/tools/internal/command/TreeCommandFactory.java @@ -348,7 +348,7 @@ public class TreeCommandFactory extends AbstractCommandFactory implements ITreeC // Add a RefreshTreeElementTask to have DTreeItem refreshed // on direct edit even in REFRESH_AUTO mode at false - ICommandTask refreshTreeElementTask = new RefreshTreeElementTask(editedTreeItem, domain); + ICommandTask refreshTreeElementTask = new RefreshTreeElementTask(editedTreeItem); result.getTasks().add(refreshTreeElementTask); } } |
