From fca686a82ae6f3f173e1782b4885f2e49eeb2276 Mon Sep 17 00:00:00 2001 From: adaussy Date: Tue, 14 Jan 2014 15:05:24 +0100 Subject: Bug 425567 - Renaming operations and properties is possible even if model in readOnly https://bugs.eclipse.org/bugs/show_bug.cgi?id=425567 --- .../documentation/view/RichTextEditorDialog.java | 327 ++++++++++----------- .../clazz/custom/parsers/OperationParser.java | 20 +- .../clazz/custom/parsers/PropertyParser.java | 20 +- 3 files changed, 196 insertions(+), 171 deletions(-) diff --git a/plugins/core/org.eclipse.papyrus.documentation.view/src/org/eclipse/papyrus/documentation/view/RichTextEditorDialog.java b/plugins/core/org.eclipse.papyrus.documentation.view/src/org/eclipse/papyrus/documentation/view/RichTextEditorDialog.java index fa791cc1dc8..6a978db57ea 100644 --- a/plugins/core/org.eclipse.papyrus.documentation.view/src/org/eclipse/papyrus/documentation/view/RichTextEditorDialog.java +++ b/plugins/core/org.eclipse.papyrus.documentation.view/src/org/eclipse/papyrus/documentation/view/RichTextEditorDialog.java @@ -51,176 +51,166 @@ import org.eclipse.papyrus.documentation.view.actions.InsertTableRowAction; import org.eclipse.papyrus.documentation.view.actions.TextColorAction; import org.eclipse.papyrus.documentation.view.actions.TextHighlightAction; import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.ToolBar; -import org.eclipse.swt.widgets.ToolItem; /** * A dialog using a RichText and its Toolbar to change a documentation * * @author Jacques Lescot */ -public class RichTextEditorDialog extends Dialog -{ - /** The minimum width of the dialog */ - private static final int MINIMUM_DIALOG_WIDTH = 50; - - /** The minimum height of the dialog */ - private static final int MINIMUM_DIALOG_HEIGHT = 300; - - /** The minimum height of the dialog */ - private static final int MARGIN = 80; - - private RichText commentsText; - - private String initialValue; - - private String newValue; - - /** - * Constructor - * - * @param parentShell the parent Shell - * @param initialValue initial documentation value - */ - public RichTextEditorDialog(Shell parentShell, String initialValue) - { - super(parentShell); - - setBlockOnOpen(true); - setShellStyle(getShellStyle() | SWT.RESIZE); - - this.initialValue = initialValue; - } - - /** - * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) - */ - protected void configureShell(Shell newShell) - { - newShell.setText(Messages.RichTextEditorDialog_useRichText); -// newShell.setMinimumSize(MINIMUM_DIALOG_WIDTH, MINIMUM_DIALOG_HEIGHT); - - super.configureShell(newShell); - } - - /** - * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) - */ - @Override - protected Control createDialogArea(Composite parent) - { - Composite dialogComposite = (Composite) super.createDialogArea(parent); - dialogComposite.setLayout(new GridLayout()); - - Composite toolbarComposite = new Composite(dialogComposite, SWT.NONE); - toolbarComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); - toolbarComposite.setLayout(new GridLayout()); - final RichTextToolBar toolBar = new RichTextToolBar(toolbarComposite, SWT.WRAP, commentsText); - - Composite container = new Composite(dialogComposite, SWT.BORDER); - container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - container.setLayout(new GridLayout()); - getShell(); - commentsText = new RichText(container, SWT.NONE); - commentsText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - commentsText.setText(initialValue); - commentsText.setFocus(); - fillToolBar(toolBar, commentsText); - getShell().setMinimumSize(toolBar.getToolbarMgr().getControl().getBounds().width + MARGIN, MINIMUM_DIALOG_HEIGHT); - return dialogComposite; - } - - /** - * Populate actions in the Toolbar to link with the RichText - * - * @param toolBar The IRichTextToolBar - * @param richText The IRichText - */ - private void fillToolBar(IRichTextToolBar toolBar, IRichText richText) - { - toolBar.addAction(new FontStyleAction(richText)); - toolBar.addAction(new FontNameAction(richText)); - toolBar.addAction(new FontSizeAction(richText)); - toolBar.addSeparator(); - toolBar.addAction(new CutAction(richText)); - toolBar.addAction(new CopyAction(richText)); - toolBar.addAction(new PasteAction(richText)); - toolBar.addSeparator(); - toolBar.addAction(new ClearContentAction(richText)); - toolBar.addSeparator(); - toolBar.addAction(new BoldAction(richText)); - toolBar.addAction(new ItalicAction(richText)); - toolBar.addAction(new UnderlineAction(richText)); - toolBar.addSeparator(); - toolBar.addAction(new TextColorAction(richText)); - toolBar.addAction(new TextHighlightAction(richText)); - toolBar.addSeparator(); - toolBar.addAction(new SubscriptAction(richText)); - toolBar.addAction(new SuperscriptAction(richText)); - toolBar.addSeparator(); - toolBar.addAction(new TidyActionGroup(richText)); - toolBar.addSeparator(); - toolBar.addAction(new AddOrderedListAction(richText)); - toolBar.addAction(new AddUnorderedListAction(richText)); - toolBar.addSeparator(); - toolBar.addAction(new OutdentAction(richText)); - toolBar.addAction(new IndentAction(richText)); - toolBar.addSeparator(); - toolBar.addAction(new JustifyLeftAction(richText)); - toolBar.addAction(new JustifyCenterAction(richText)); - toolBar.addAction(new JustifyRightAction(richText)); - toolBar.addAction(new JustifyFullAction(richText)); - toolBar.addSeparator(); - toolBar.addAction(new FindReplaceAction(richText) - { - /** - * @see org.eclipse.epf.richtext.actions.FindReplaceAction#execute(org.eclipse.epf.richtext.IRichText) - */ - @Override - public void execute(IRichText rText) - { - rText.getFindReplaceAction().execute(rText); - } - }); - toolBar.addSeparator(); - toolBar.addAction(new AddLinkAction(richText)); - toolBar.addAction(new AddElementLinkAction(richText)); - toolBar.addAction(new AddImageAction(richText)); - toolBar.addSeparator(); - toolBar.addAction(new AddTableAction(richText)); - - // Only add these actions when IE is used to render the Browser - if (Platform.getOS().equals("win32")) { //$NON-NLS-1$ - toolBar.addAction(new InsertTableColumnAction(richText)); - toolBar.addAction(new DeleteTableColumnAction(richText)); - toolBar.addAction(new InsertTableRowAction(richText)); - toolBar.addAction(new DeleteTableRowAction(richText)); - } - } - - /** - * @see org.eclipse.jface.dialogs.Dialog#okPressed() - */ - @Override - protected void okPressed() - { - newValue = commentsText.getText(); - - super.okPressed(); - } - - /* +public class RichTextEditorDialog extends Dialog { + + /** The minimum width of the dialog */ + private static final int MINIMUM_DIALOG_WIDTH = 50; + + /** The minimum height of the dialog */ + private static final int MINIMUM_DIALOG_HEIGHT = 600; + + /** The minimum height of the dialog */ + private static final int MARGIN = 80; + + private RichText commentsText; + + private String initialValue; + + private String newValue; + + /** + * Constructor + * + * @param parentShell + * the parent Shell + * @param initialValue + * initial documentation value + */ + public RichTextEditorDialog(Shell parentShell, String initialValue) { + super(parentShell); + + setBlockOnOpen(true); + setShellStyle(getShellStyle() | SWT.RESIZE); + + this.initialValue = initialValue; + } + + /** + * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + */ + protected void configureShell(Shell newShell) { + newShell.setText(Messages.RichTextEditorDialog_useRichText); + // newShell.setMinimumSize(MINIMUM_DIALOG_WIDTH, MINIMUM_DIALOG_HEIGHT); + + super.configureShell(newShell); + } + + /** + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createDialogArea(Composite parent) { + Composite dialogComposite = (Composite)super.createDialogArea(parent); + dialogComposite.setLayout(new GridLayout()); + + Composite toolbarComposite = new Composite(dialogComposite, SWT.NONE); + toolbarComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + toolbarComposite.setLayout(new GridLayout()); + final RichTextToolBar toolBar = new RichTextToolBar(toolbarComposite, SWT.WRAP, commentsText); + + Composite container = new Composite(dialogComposite, SWT.BORDER); + container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + container.setLayout(new GridLayout()); + getShell(); + commentsText = new RichText(container, SWT.NONE); + commentsText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + commentsText.setText(initialValue); + commentsText.setFocus(); + fillToolBar(toolBar, commentsText); + getShell().setMinimumSize(toolBar.getToolbarMgr().getControl().getBounds().width + MARGIN, MINIMUM_DIALOG_HEIGHT); + return dialogComposite; + } + + /** + * Populate actions in the Toolbar to link with the RichText + * + * @param toolBar + * The IRichTextToolBar + * @param richText + * The IRichText + */ + private void fillToolBar(IRichTextToolBar toolBar, IRichText richText) { + toolBar.addAction(new FontStyleAction(richText)); + toolBar.addAction(new FontNameAction(richText)); + toolBar.addAction(new FontSizeAction(richText)); + toolBar.addSeparator(); + toolBar.addAction(new CutAction(richText)); + toolBar.addAction(new CopyAction(richText)); + toolBar.addAction(new PasteAction(richText)); + toolBar.addSeparator(); + toolBar.addAction(new ClearContentAction(richText)); + toolBar.addSeparator(); + toolBar.addAction(new BoldAction(richText)); + toolBar.addAction(new ItalicAction(richText)); + toolBar.addAction(new UnderlineAction(richText)); + toolBar.addSeparator(); + toolBar.addAction(new TextColorAction(richText)); + toolBar.addAction(new TextHighlightAction(richText)); + toolBar.addSeparator(); + toolBar.addAction(new SubscriptAction(richText)); + toolBar.addAction(new SuperscriptAction(richText)); + toolBar.addSeparator(); + toolBar.addAction(new TidyActionGroup(richText)); + toolBar.addSeparator(); + toolBar.addAction(new AddOrderedListAction(richText)); + toolBar.addAction(new AddUnorderedListAction(richText)); + toolBar.addSeparator(); + toolBar.addAction(new OutdentAction(richText)); + toolBar.addAction(new IndentAction(richText)); + toolBar.addSeparator(); + toolBar.addAction(new JustifyLeftAction(richText)); + toolBar.addAction(new JustifyCenterAction(richText)); + toolBar.addAction(new JustifyRightAction(richText)); + toolBar.addAction(new JustifyFullAction(richText)); + toolBar.addSeparator(); + toolBar.addAction(new FindReplaceAction(richText) { + + /** + * @see org.eclipse.epf.richtext.actions.FindReplaceAction#execute(org.eclipse.epf.richtext.IRichText) + */ + @Override + public void execute(IRichText rText) { + rText.getFindReplaceAction().execute(rText); + } + }); + toolBar.addSeparator(); + toolBar.addAction(new AddLinkAction(richText)); + toolBar.addAction(new AddElementLinkAction(richText)); + toolBar.addAction(new AddImageAction(richText)); + toolBar.addSeparator(); + toolBar.addAction(new AddTableAction(richText)); + + // Only add these actions when IE is used to render the Browser + if(Platform.getOS().equals("win32")) { //$NON-NLS-1$ + toolBar.addAction(new InsertTableColumnAction(richText)); + toolBar.addAction(new DeleteTableColumnAction(richText)); + toolBar.addAction(new InsertTableRowAction(richText)); + toolBar.addAction(new DeleteTableRowAction(richText)); + } + } + + /** + * @see org.eclipse.jface.dialogs.Dialog#okPressed() + */ + @Override + protected void okPressed() { + newValue = commentsText.getText(); + + super.okPressed(); + } + + /* * (non-Javadoc) * * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) @@ -231,14 +221,13 @@ public class RichTextEditorDialog extends Dialog createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false); createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); } - - /** - * This method returns the text contained in the RichTextCommentsComposite - * - * @return the text contained in the RichTextCommentsComposite - */ - public String getDocumentationValue() - { - return newValue; - } + + /** + * This method returns the text contained in the RichTextCommentsComposite + * + * @return the text contained in the RichTextCommentsComposite + */ + public String getDocumentationValue() { + return newValue; + } } diff --git a/plugins/uml/org.eclipse.papyrus.diagram.clazz/custom-src/org/eclipse/papyrus/diagram/clazz/custom/parsers/OperationParser.java b/plugins/uml/org.eclipse.papyrus.diagram.clazz/custom-src/org/eclipse/papyrus/diagram/clazz/custom/parsers/OperationParser.java index 5ad14cb68c1..230a6efc556 100644 --- a/plugins/uml/org.eclipse.papyrus.diagram.clazz/custom-src/org/eclipse/papyrus/diagram/clazz/custom/parsers/OperationParser.java +++ b/plugins/uml/org.eclipse.papyrus.diagram.clazz/custom-src/org/eclipse/papyrus/diagram/clazz/custom/parsers/OperationParser.java @@ -14,12 +14,17 @@ *****************************************************************************/ package org.eclipse.papyrus.diagram.clazz.custom.parsers; +import java.util.Collections; import java.util.List; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.workspace.util.WorkspaceSynchronizer; import org.eclipse.gmf.runtime.common.core.command.CommandResult; import org.eclipse.gmf.runtime.common.core.command.ICommand; import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; @@ -68,7 +73,7 @@ public class OperationParser implements IParser { final Operation operation = ((Operation)((EObjectAdapter)element).getRealObject()); final String result = newString; - AbstractTransactionalCommand tc = new AbstractTransactionalCommand(EditorUtils.getTransactionalEditingDomain(), "Edit Operation", (List)null) { + AbstractTransactionalCommand tc = new AbstractTransactionalCommand(EditorUtils.getTransactionalEditingDomain(), "Edit Operation", getModifiedFiles(operation)) { @Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { @@ -91,6 +96,19 @@ public class OperationParser implements IParser { return tc; } + protected List getModifiedFiles(EObject target) { + List modifiedFiles = null; + Resource resource = target.eResource(); + if(resource != null) { + IFile file = WorkspaceSynchronizer.getFile(resource); + if(file != null) { + modifiedFiles = Collections.singletonList(file); + } + } + return modifiedFiles; + } + + /** * * {@inheritDoc} diff --git a/plugins/uml/org.eclipse.papyrus.diagram.clazz/custom-src/org/eclipse/papyrus/diagram/clazz/custom/parsers/PropertyParser.java b/plugins/uml/org.eclipse.papyrus.diagram.clazz/custom-src/org/eclipse/papyrus/diagram/clazz/custom/parsers/PropertyParser.java index 436183c605e..fdba8486cc4 100644 --- a/plugins/uml/org.eclipse.papyrus.diagram.clazz/custom-src/org/eclipse/papyrus/diagram/clazz/custom/parsers/PropertyParser.java +++ b/plugins/uml/org.eclipse.papyrus.diagram.clazz/custom-src/org/eclipse/papyrus/diagram/clazz/custom/parsers/PropertyParser.java @@ -14,12 +14,17 @@ *****************************************************************************/ package org.eclipse.papyrus.diagram.clazz.custom.parsers; +import java.util.Collections; import java.util.List; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.workspace.util.WorkspaceSynchronizer; import org.eclipse.gmf.runtime.common.core.command.CommandResult; import org.eclipse.gmf.runtime.common.core.command.ICommand; import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; @@ -71,7 +76,7 @@ public class PropertyParser implements IParser { final Property property = ((Property)((EObjectAdapter)element).getRealObject()); final String result = newString; - AbstractTransactionalCommand tc = new AbstractTransactionalCommand(EditorUtils.getTransactionalEditingDomain(), "Edit Property", (List)null) { + AbstractTransactionalCommand tc = new AbstractTransactionalCommand(EditorUtils.getTransactionalEditingDomain(), "Edit Property", getModifiedFiles(property)) { @Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { @@ -94,6 +99,19 @@ public class PropertyParser implements IParser { return tc; } + protected List getModifiedFiles(EObject target) { + List modifiedFiles = null; + Resource resource = target.eResource(); + if(resource != null) { + IFile file = WorkspaceSynchronizer.getFile(resource); + if(file != null) { + modifiedFiles = Collections.singletonList(file); + } + } + return modifiedFiles; + } + + /** * * {@inheritDoc} -- cgit v1.2.3