Parcourir la source

Bugfix: Caret Position changed after selection proposal via mouse in Property Sheet

Andreas Mülder il y a 12 ans
Parent
commit
740d018077

+ 12 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/AbstractEditorPropertySection.java

@@ -17,6 +17,7 @@ import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.edit.domain.EditingDomain;
 import org.eclipse.emf.edit.domain.IEditingDomainProvider;
 import org.eclipse.gmf.runtime.diagram.ui.properties.sections.AbstractModelerPropertySection;
+import org.eclipse.jface.bindings.keys.KeyStroke;
 import org.eclipse.jface.dialogs.IDialogLabelKeys;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.resource.JFaceResources;
@@ -43,6 +44,7 @@ import org.yakindu.sct.ui.editor.extensions.IExpressionLanguageProvider;
 
 import com.google.inject.Injector;
 
+import de.itemis.xtext.utils.jface.fieldassist.CompletionProposalAdapter;
 import de.itemis.xtext.utils.jface.viewers.ContextElementAdapter;
 import de.itemis.xtext.utils.jface.viewers.ContextElementAdapter.IContextElementProvider;
 import de.itemis.xtext.utils.jface.viewers.StyledTextXtextAdapter;
@@ -66,6 +68,8 @@ public abstract class AbstractEditorPropertySection extends
 
 	private Form form;
 
+	private CompletionProposalAdapter completionProposalAdapter;
+
 	@Override
 	public void refresh() {
 		super.refresh();
@@ -140,6 +144,14 @@ public abstract class AbstractEditorPropertySection extends
 		xtextAdapter.getFakeResourceContext().getFakeResource().eAdapters()
 				.add(new ContextElementAdapter(this));
 		xtextAdapter.adapt((StyledText) styledText);
+
+		completionProposalAdapter = new CompletionProposalAdapter(
+				styledText, xtextAdapter.getContentAssistant(),
+				KeyStroke.getInstance(SWT.CTRL, SWT.SPACE), null);
+	}
+	
+	public CompletionProposalAdapter getCompletionProposalAdapter() {
+		return completionProposalAdapter;
 	}
 
 	protected Injector getInjector(SemanticTarget semanticTarget) {

+ 16 - 2
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/StatePropertySection.java

@@ -12,7 +12,11 @@ package org.yakindu.sct.ui.editor.propertysheets;
 
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.operations.OperationHistoryFactory;
+import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.draw2d.ColorConstants;
 import org.eclipse.emf.common.notify.Notification;
 import org.eclipse.emf.common.notify.impl.AdapterImpl;
@@ -91,7 +95,7 @@ public class StatePropertySection extends
 		if (injector != null) {
 			txtSpecification = new StyledText(parent, SWT.MULTI | SWT.BORDER
 					| SWT.V_SCROLL | SWT.WRAP);
-			((StyledText)txtSpecification).setAlwaysShowScrollBars(false);
+			((StyledText) txtSpecification).setAlwaysShowScrollBars(false);
 			enableXtext(txtSpecification, injector);
 			createHelpWidget(parent, txtSpecification,
 					HelpContextIds.SC_PROPERTIES_STATE_EXPRESSION);
@@ -149,7 +153,17 @@ public class StatePropertySection extends
 		ISWTObservableValue specificationTextProperty = WidgetProperties.text(
 				SWT.FocusOut).observe(txtSpecification);
 		context.bindValue(specificationTextProperty,
-				specificationProperty.observe(eObject));
+				specificationProperty.observe(eObject), null,
+				new UpdateValueStrategy() {
+					@Override
+					protected IStatus doSet(IObservableValue observableValue,
+							Object value) {
+						if (!getCompletionProposalAdapter()
+								.isProposalPopupOpen())
+							return super.doSet(observableValue, value);
+						return Status.OK_STATUS;
+					}
+				});
 	}
 
 	private void bindNameControl(EMFDataBindingContext context) {

+ 16 - 1
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/StatechartPropertySection.java

@@ -10,6 +10,10 @@
  */
 package org.yakindu.sct.ui.editor.propertysheets;
 
+import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.emf.databinding.EMFDataBindingContext;
 import org.eclipse.emf.databinding.IEMFValueProperty;
 import org.eclipse.emf.databinding.edit.EMFEditProperties;
@@ -108,7 +112,18 @@ public class StatechartPropertySection extends
 				SGraphPackage.Literals.SPECIFICATION_ELEMENT__SPECIFICATION);
 		ISWTObservableValue uiProperty = WidgetProperties.text(SWT.FocusOut)
 				.observe(textControl);
-		context.bindValue(uiProperty, modelProperty.observe(eObject));
+		context.bindValue(uiProperty, modelProperty.observe(eObject), null,
+				new UpdateValueStrategy() {
+					@Override
+					protected IStatus doSet(IObservableValue observableValue,
+							Object value) {
+						if (!getCompletionProposalAdapter()
+								.isProposalPopupOpen())
+							return super.doSet(observableValue, value);
+						return Status.OK_STATUS;
+					}
+				});
+
 	}
 
 	private void bindNameControl(EMFDataBindingContext context) {

+ 20 - 4
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/TransitionPropertySection.java

@@ -10,6 +10,10 @@
  */
 package org.yakindu.sct.ui.editor.propertysheets;
 
+import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.emf.databinding.EMFDataBindingContext;
 import org.eclipse.emf.databinding.IEMFValueProperty;
 import org.eclipse.emf.databinding.edit.EMFEditProperties;
@@ -49,13 +53,15 @@ public class TransitionPropertySection extends AbstractEditorPropertySection {
 		if (injector != null) {
 			textControl = new StyledText(parent, SWT.MULTI | SWT.BORDER
 					| SWT.V_SCROLL | SWT.WRAP);
-			((StyledText)textControl).setAlwaysShowScrollBars(false);
+			((StyledText) textControl).setAlwaysShowScrollBars(false);
 			enableXtext(textControl, injector);
-			createHelpWidget(parent, textControl,HelpContextIds.SC_PROPERTIES_TRANSITION_EXPRESSION);
+			createHelpWidget(parent, textControl,
+					HelpContextIds.SC_PROPERTIES_TRANSITION_EXPRESSION);
 		} else {
 			textControl = getToolkit().createText(parent, "", SWT.MULTI);
 		}
-		GridDataFactory.fillDefaults().grab(true, true).hint(parent.getSize()).applyTo(textControl);
+		GridDataFactory.fillDefaults().grab(true, true).hint(parent.getSize())
+				.applyTo(textControl);
 
 	}
 
@@ -66,7 +72,17 @@ public class TransitionPropertySection extends AbstractEditorPropertySection {
 				SGraphPackage.Literals.SPECIFICATION_ELEMENT__SPECIFICATION);
 		ISWTObservableValue uiProperty = WidgetProperties.text(SWT.FocusOut)
 				.observe(textControl);
-		context.bindValue(uiProperty, modelProperty.observe(eObject));
+		context.bindValue(uiProperty, modelProperty.observe(eObject), null,
+				new UpdateValueStrategy() {
+					@Override
+					protected IStatus doSet(IObservableValue observableValue,
+							Object value) {
+						if (!getCompletionProposalAdapter()
+								.isProposalPopupOpen())
+							return super.doSet(observableValue, value);
+						return Status.OK_STATUS;
+					}
+				});
 	}
 
 }