Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeremie.tatibouet2015-06-09 12:03:12 +0000
committerArnaud Cuccuru2015-06-09 12:55:10 +0000
commit9e55f58f5eb9631b1674320245edeb746e993bca (patch)
tree72234e6255a27241ded26d63a170e018881d4897
parent38257a57d2229d0b9706207341da307b6ce4c770 (diff)
downloadorg.eclipse.papyrus-9e55f58f5eb9631b1674320245edeb746e993bca.tar.gz
org.eclipse.papyrus-9e55f58f5eb9631b1674320245edeb746e993bca.tar.xz
org.eclipse.papyrus-9e55f58f5eb9631b1674320245edeb746e993bca.zip
Avoid freeze of the ALF editor when editing an activity (bug 466458)
Remove unecessary old undo redo code (will be replaced in future commits) Change-Id: Ieb255cb625d48af00fe7566b9802a056ad3daef3 Signed-off-by: jeremie.tatibouet <jeremie.tatibouet@cea.fr> Reviewed-on: https://git.eclipse.org/r/49766 Reviewed-by: Arnaud Cuccuru <arnaud.cuccuru@cea.fr> Tested-by: Arnaud Cuccuru <arnaud.cuccuru@cea.fr>
-rw-r--r--extraplugins/alf/ui/org.eclipse.papyrus.uml.alf.properties.xtext/src/org/eclipse/papyrus/uml/alf/properties/xtext/sheet/AlfEditionPropertySection.java76
-rw-r--r--extraplugins/alf/ui/org.eclipse.papyrus.uml.alf.properties.xtext/src/org/eclipse/papyrus/uml/alf/properties/xtext/sheet/tooling/StyledTextWithUndoRedo.java64
2 files changed, 68 insertions, 72 deletions
diff --git a/extraplugins/alf/ui/org.eclipse.papyrus.uml.alf.properties.xtext/src/org/eclipse/papyrus/uml/alf/properties/xtext/sheet/AlfEditionPropertySection.java b/extraplugins/alf/ui/org.eclipse.papyrus.uml.alf.properties.xtext/src/org/eclipse/papyrus/uml/alf/properties/xtext/sheet/AlfEditionPropertySection.java
index 3fc986eff17..e7e1695c59b 100644
--- a/extraplugins/alf/ui/org.eclipse.papyrus.uml.alf.properties.xtext/src/org/eclipse/papyrus/uml/alf/properties/xtext/sheet/AlfEditionPropertySection.java
+++ b/extraplugins/alf/ui/org.eclipse.papyrus.uml.alf.properties.xtext/src/org/eclipse/papyrus/uml/alf/properties/xtext/sheet/AlfEditionPropertySection.java
@@ -20,7 +20,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.diagram.ui.properties.sections.AbstractModelerPropertySection;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.uml.alf.properties.xtext.UndoRedoStack;
+import org.eclipse.papyrus.uml.alf.properties.xtext.sheet.tooling.StyledTextWithUndoRedo;
import org.eclipse.papyrus.uml.alf.properties.xtext.sheet.ui.listeners.CommitButtonSelectionListener;
import org.eclipse.papyrus.uml.alf.properties.xtext.sheet.ui.listeners.EditorFocusListener;
import org.eclipse.papyrus.uml.alf.text.generation.DefaultEditStringRetrievalStrategy;
@@ -31,13 +31,9 @@ import org.eclipse.papyrus.uml.xtext.integration.StyledTextXtextAdapter;
import org.eclipse.papyrus.uml.xtext.integration.core.ContextElementAdapter;
import org.eclipse.papyrus.uml.xtext.integration.core.ContextElementAdapter.IContextElementProvider;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.ExtendedModifyEvent;
-import org.eclipse.swt.custom.ExtendedModifyListener;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -65,7 +61,7 @@ public class AlfEditionPropertySection extends
private Form form;
- private StyledText textControl;
+ private StyledTextWithUndoRedo textControl;
private Button commitButton;
@@ -73,8 +69,6 @@ public class AlfEditionPropertySection extends
final private ContextElementAdapter contextElementAdapter = new ContextElementAdapter(this);
- private UndoRedoStack<ExtendedModifyEvent> undoRedoStack;
-
protected boolean isUndo;
protected boolean isRedo;
@@ -87,7 +81,6 @@ public class AlfEditionPropertySection extends
public AlfEditionPropertySection() {
this.previousEObject = null;
- this.undoRedoStack = new UndoRedoStack<ExtendedModifyEvent>();
this.alfSerialization = new DefaultEditStringRetrievalStrategy();
this.alfToolingInjector = AlfActivator.getInstance().getInjector(AlfActivator.ORG_ECLIPSE_PAPYRUS_UML_ALF_ALF);
}
@@ -219,77 +212,16 @@ public class AlfEditionPropertySection extends
protected void createTextControl(final Composite parent) {
- textControl = new StyledText(parent, SWT.MULTI | SWT.BORDER
+ textControl = new StyledTextWithUndoRedo(parent, SWT.MULTI | SWT.BORDER
| SWT.V_SCROLL | SWT.WRAP);
textControl.setAlwaysShowScrollBars(false);
GridDataFactory.fillDefaults().grab(true, true).hint(parent.getSize())
.applyTo(textControl);
- textControl.addExtendedModifyListener(new ExtendedModifyListener() {
-
- public void modifyText(ExtendedModifyEvent event) {
- if (isUndo) {
- undoRedoStack.pushRedo(event);
- } else { // is Redo or a normal user action
- undoRedoStack.pushUndo(event);
- if (!isRedo) {
- undoRedoStack.clearRedo();
- // TODO Switch to treat consecutive characters as one event?
- }
- }
- }
- });
-
- textControl.addKeyListener(new KeyAdapter() {
- @Override
- public void keyPressed(KeyEvent e) {
- boolean isCtrl = (e.stateMask & SWT.CTRL) > 0;
- boolean isAlt = (e.stateMask & SWT.ALT) > 0;
- if (isCtrl && !isAlt) {
- boolean isShift = (e.stateMask & SWT.SHIFT) > 0;
- if (e.keyCode == 'z') {
- if (isShift) {
- redo();
- } else {
- undo();
- }
- }
- }
- }
- });
-
+
textControl.addFocusListener(new EditorFocusListener(this));
}
- protected void undo() {
- if (undoRedoStack.hasUndo()) {
- isUndo = true;
- revertEvent(undoRedoStack.popUndo());
- isUndo = false;
- }
- }
-
- protected void redo() {
- if (undoRedoStack.hasRedo()) {
- isRedo = true;
- revertEvent(undoRedoStack.popRedo());
- isRedo = false;
- }
- }
-
- /**
- * Reverts the given modify event, in the way as the Eclipse text editor
- * does it.
- *
- * @param event
- */
- private void revertEvent(ExtendedModifyEvent event) {
- textControl.replaceTextRange(event.start, event.length, event.replacedText);
- // (causes the modifyText() listener method to be called)
-
- textControl.setSelectionRange(event.start, event.replacedText.length());
- }
-
protected void updateXtextAdapters(Control styledText) {
if (styledTextAdapter != null) {
styledTextAdapter.getFakeResourceContext().getFakeResource().eAdapters().remove(contextElementAdapter);
diff --git a/extraplugins/alf/ui/org.eclipse.papyrus.uml.alf.properties.xtext/src/org/eclipse/papyrus/uml/alf/properties/xtext/sheet/tooling/StyledTextWithUndoRedo.java b/extraplugins/alf/ui/org.eclipse.papyrus.uml.alf.properties.xtext/src/org/eclipse/papyrus/uml/alf/properties/xtext/sheet/tooling/StyledTextWithUndoRedo.java
new file mode 100644
index 00000000000..84b76e282af
--- /dev/null
+++ b/extraplugins/alf/ui/org.eclipse.papyrus.uml.alf.properties.xtext/src/org/eclipse/papyrus/uml/alf/properties/xtext/sheet/tooling/StyledTextWithUndoRedo.java
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Jérémie Tatibouet (CEA LIST)
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.alf.properties.xtext.sheet.tooling;
+
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+
+public class StyledTextWithUndoRedo extends StyledText {
+
+ public StyledTextWithUndoRedo(Composite parent, int style) {
+ super(parent, style);
+ }
+
+ @Override
+ public void replaceTextRange(int start, int length, String text) {
+ int contentLength = getCharCount();
+ int end = start + length;
+ if (start > end || start < 0 || end > contentLength) {
+ return;
+ }
+ super.replaceTextRange(start, length, text);
+ }
+
+ @Override
+ public void redrawRange(int start, int length, boolean clearBackground) {
+ int end = start + length;
+ int contentLength = getContent().getCharCount();
+ if (start > end || start < 0 || end > contentLength) {
+ return;
+ }else{
+ super.redrawRange(start, length, clearBackground);
+ }
+ }
+
+ @Override
+ public Rectangle getTextBounds(int start, int end) {
+ int contentLength = getCharCount();
+ if (start < 0 || start >= contentLength || end < 0 || end >= contentLength || start > end) {
+ return new Rectangle(0, 0, 0, 0);
+ }else{
+ return super.getTextBounds(start, end);
+ }
+ }
+
+ @Override
+ public void replaceStyleRanges(int start, int length, StyleRange[] ranges) {
+ try{
+ super.replaceStyleRanges(start, length, ranges);
+ }catch(IllegalArgumentException e){}
+ }
+}

Back to the top