diff options
Diffstat (limited to 'plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/IReloadableEditor.java')
-rw-r--r-- | plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/IReloadableEditor.java | 103 |
1 files changed, 53 insertions, 50 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/IReloadableEditor.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/IReloadableEditor.java index d0ad1276c80..56f007f013b 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/IReloadableEditor.java +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/IReloadableEditor.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2014 CEA and others. - * + * * 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 @@ -54,16 +54,16 @@ public interface IReloadableEditor { /** * Reloads me in-place in the perspective layout. - * + * * @param triggeringResources - * the resources that have changed in some way, triggering re-load + * the resources that have changed in some way, triggering re-load * @param reason - * the reason why the re-load is being requested + * the reason why the re-load is being requested * @param dirtyPolicy - * how the client would like to handle the case of a dirty editor - * + * how the client would like to handle the case of a dirty editor + * * @throws CoreException - * on any failure to unload, reload, or whatever + * on any failure to unload, reload, or whatever */ void reloadEditor(Collection<? extends Resource> triggeringResources, ReloadReason reason, DirtyPolicy dirtyPolicy) throws CoreException; @@ -82,10 +82,10 @@ public interface IReloadableEditor { /** * Queries whether, under ordinary circumstances, the editor should attempt to re-load to pick up changes in its dependent resources. - * + * * @param triggeringResources - * the resources triggering re-load (or close) - * + * the resources triggering re-load (or close) + * * @return whether the editor should re-load */ public boolean shouldReload(Collection<? extends Resource> triggeringResources) { @@ -121,11 +121,11 @@ public interface IReloadableEditor { public DirtyPolicy resolve(IEditorPart editor, final Collection<? extends Resource> triggeringResources, final ReloadReason reason) throws CoreException { final boolean dirty = editor.isDirty(); - if(!dirty) { - if(reason.shouldReload(triggeringResources)) { + if (!dirty) { + if (reason.shouldReload(triggeringResources)) { // Just re-load it. Simple return DO_NOT_SAVE; - } else if(isPrincipalResourceAffected(editor, triggeringResources)) { + } else if (isPrincipalResourceAffected(editor, triggeringResources)) { // Just close it. Also simple return DO_NOT_SAVE; } @@ -140,7 +140,7 @@ public interface IReloadableEditor { final String dontSaveOption; final String ignoreOption = "Ignore"; - switch(reason) { + switch (reason) { case RESOURCES_DELETED: promptTitle = "Resources Deleted"; promptIntro = NLS.bind("Some resources used by \"{0}\" have been deleted.", editorName); @@ -157,8 +157,8 @@ public interface IReloadableEditor { Callable<DirtyPolicy> result; - if(allReadOnly) { - //Only read-only models have changed. We (most likely) won't save them within this current editor. As they are already loaded, we can just continue. + if (allReadOnly) { + // Only read-only models have changed. We (most likely) won't save them within this current editor. As they are already loaded, we can just continue. result = new Callable<DirtyPolicy>() { @Override @@ -167,16 +167,17 @@ public interface IReloadableEditor { final String message; final String[] options; - if(dirty) { + if (dirty) { message = promptIntro + " Note: all these resources are loaded in read-only mode and won't be overridden if you choose to save. Unsaved changes will be lost."; - options = new String[]{ saveOption, dontSaveOption, ignoreOption }; + options = new String[] { saveOption, dontSaveOption, ignoreOption }; } else { message = promptIntro; - options = new String[]{ dontSaveOption, ignoreOption }; + options = new String[] { dontSaveOption, ignoreOption }; } final MessageDialog dialog = new MessageDialog(parentShell, promptTitle, null, message, MessageDialog.WARNING, options, 0) { + @Override protected void setShellStyle(int newShellStyle) { super.setShellStyle(newShellStyle | SWT.SHEET); } @@ -185,10 +186,10 @@ public interface IReloadableEditor { DirtyPolicy result; - if(answer == SWT.DEFAULT) { + if (answer == SWT.DEFAULT) { // User hit Esc or dismissed the dialog with the window manager button. Ignore result = IGNORE; - } else if(dirty) { + } else if (dirty) { result = values()[answer]; } else { result = values()[answer + 1]; // Account for the missing "Save and Xxx" option @@ -198,7 +199,7 @@ public interface IReloadableEditor { } }; } else { - //At least one read-write resource has changed. Potential conflicts. + // At least one read-write resource has changed. Potential conflicts. result = new Callable<DirtyPolicy>() { @Override @@ -209,7 +210,7 @@ public interface IReloadableEditor { final String action = reason.shouldReload(triggeringResources) ? "re-open" : "close"; final String message; - if(dirty) { + if (dirty) { message = promptIntro + NLS.bind(" Do you wish to {0} the current editor? Unsaved changes will be lost.", action); } else { message = promptIntro + NLS.bind(" Do you wish to {0} the current editor?", action); @@ -218,11 +219,12 @@ public interface IReloadableEditor { final String[] options = { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }; final MessageDialog dialog = new MessageDialog(parentShell, promptTitle, null, message, MessageDialog.WARNING, options, 0) { + @Override protected void setShellStyle(int newShellStyle) { super.setShellStyle(newShellStyle | SWT.SHEET); } }; - if(dialog.open() == 0) { + if (dialog.open() == 0) { result = DO_NOT_SAVE; } @@ -243,7 +245,7 @@ public interface IReloadableEditor { /** * Queries the default dirty policy currently in effect. The default-default is {@link #PROMPT_TO_SAVE}. - * + * * @return the default policy */ public static DirtyPolicy getDefault() { @@ -252,18 +254,18 @@ public interface IReloadableEditor { /** * Resolves me to a specific actionable policy, based on the resources that are triggering re-load (or close) and the reason. - * + * * @param editor - * the editor to be re-loaded + * the editor to be re-loaded * @param triggeringResources - * the resources (possibly an empty collection) that have changed + * the resources (possibly an empty collection) that have changed * @param reloadReason - * the reason why re-load (or close) is triggered - * + * the reason why re-load (or close) is triggered + * * @return the specific policy to implement in re-loading the editor - * + * * @throws CoreException - * on failure to resolve the specific policy + * on failure to resolve the specific policy */ public DirtyPolicy resolve(IEditorPart editor, Collection<? extends Resource> triggeringResources, ReloadReason reason) throws CoreException { return this; @@ -277,11 +279,11 @@ public interface IReloadableEditor { private ModelSet getModelSet(IEditorPart editor) { ModelSet result = null; - if(editor instanceof IMultiDiagramEditor) { + if (editor instanceof IMultiDiagramEditor) { try { - result = ((IMultiDiagramEditor)editor).getServicesRegistry().getService(ModelSet.class); + result = ((IMultiDiagramEditor) editor).getServicesRegistry().getService(ModelSet.class); } catch (ServiceException e) { - // No problem. We have a fall-back + // No problem. We have a fall-back Activator.log.error(e); } } @@ -293,19 +295,19 @@ public interface IReloadableEditor { boolean result = false; ModelSet modelSet = getModelSet(editor); - if(modelSet != null) { + if (modelSet != null) { URI principalURI = modelSet.getURIWithoutExtension(); - for(Resource next : triggeringResources) { - if(next.getURI().trimFileExtension().equals(principalURI)) { + for (Resource next : triggeringResources) { + if (next.getURI().trimFileExtension().equals(principalURI)) { result = true; break; } } } else { URI principalURI = getURI(editor.getEditorInput()); - if(principalURI != null) { - for(Resource next : triggeringResources) { - if(next.getURI().equals(principalURI)) { + if (principalURI != null) { + for (Resource next : triggeringResources) { + if (next.getURI().equals(principalURI)) { result = true; break; } @@ -319,19 +321,19 @@ public interface IReloadableEditor { private URI getURI(IEditorInput input) { URI result = null; - if(input instanceof URIEditorInput) { - result = ((URIEditorInput)input).getURI(); - } else if(input instanceof IURIEditorInput) { - result = URI.createURI(((IURIEditorInput)input).getURI().toString()); + if (input instanceof URIEditorInput) { + result = ((URIEditorInput) input).getURI(); + } else if (input instanceof IURIEditorInput) { + result = URI.createURI(((IURIEditorInput) input).getURI().toString()); } return result; } protected boolean allReadOnly(Collection<? extends Resource> resources) { - for(Resource resource : resources) { + for (Resource resource : resources) { EditingDomain domain = TransactionUtil.getEditingDomain(resource); - if((domain == null) || !domain.isReadOnly(resource)) { + if ((domain == null) || !domain.isReadOnly(resource)) { return false; } } @@ -358,6 +360,7 @@ public interface IReloadableEditor { return AdapterUtils.adapt(editor, IReloadableEditor.class, new Adapter(editor)); } + @Override public void reloadEditor(Collection<? extends Resource> triggeringResources, ReloadReason reason, DirtyPolicy dirtyPolicy) throws CoreException { final IWorkbenchPage page = editor.getSite().getPage(); final IEditorInput currentInput = editor.getEditorInput(); @@ -369,15 +372,15 @@ public interface IReloadableEditor { final DirtyPolicy action = dirtyPolicy.resolve(editor, triggeringResources, reason); final boolean save = action == DirtyPolicy.SAVE; - if(save && editor.isDirty()) { + if (save && editor.isDirty()) { editor.doSave(new NullProgressMonitor()); } - if(action != DirtyPolicy.IGNORE) { + if (action != DirtyPolicy.IGNORE) { page.closeEditor(editor, save); // If resources were deleted, we close and don't re-open - if(reason.shouldReload(triggeringResources)) { + if (reason.shouldReload(triggeringResources)) { display.asyncExec(new Runnable() { @Override |