Przeglądaj źródła

Fixed scoping bug in property sections

Andreas Mülder 14 lat temu
rodzic
commit
1b159b134f

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

@@ -0,0 +1,53 @@
+package org.yakindu.sct.ui.editor.propertysheets;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.domain.IEditingDomainProvider;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+
+import de.itemis.gmf.runtime.commons.properties.GenericFormBasedPropertySection;
+import de.itemis.gmf.runtime.commons.properties.descriptors.XtextPropertyDescriptor;
+import de.itemis.xtext.utils.jface.viewers.util.ActiveEditorResolver;
+
+/**
+ * 
+ * @author andreas muelder
+ * 
+ */
+public abstract class AbstractEditorPropertySection extends
+		GenericFormBasedPropertySection {
+	/**
+	 * returns the resource that is active in the current editor, this is used
+	 * for the {@link XtextPropertyDescriptor}s context resource to enable
+	 * scoping to elements outside the text block
+	 */
+	protected Resource getActiveEditorResource() {
+		ActiveEditorResolver activeEditorResolver = new ActiveEditorResolver();
+		Display.getDefault().syncExec(activeEditorResolver);
+		IEditorPart editor = activeEditorResolver.getResult();
+
+		EditingDomain domain = null;
+		if (editor instanceof IEditingDomainProvider) {
+			domain = ((IEditingDomainProvider) editor).getEditingDomain();
+		} else if (editor.getAdapter(IEditingDomainProvider.class) != null) {
+			domain = ((IEditingDomainProvider) editor
+					.getAdapter(IEditingDomainProvider.class))
+					.getEditingDomain();
+		} else if (editor.getAdapter(EditingDomain.class) != null) {
+			domain = (EditingDomain) editor.getAdapter(EditingDomain.class);
+		}
+		if (domain == null) {
+			return null;
+		}
+
+		EList<Resource> resources = domain.getResourceSet().getResources();
+		if (resources.size() != 1) {
+			throw new IllegalStateException(
+					"Different resources in resource set , don't know which to use...");
+		}
+		return resources.get(0);
+
+	}
+}

+ 1 - 3
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/NamePropertySection.java

@@ -5,7 +5,6 @@ import java.util.List;
 import org.yakindu.sct.model.sgraph.NamedElement;
 import org.yakindu.sct.model.sgraph.SGraphPackage;
 
-import de.itemis.gmf.runtime.commons.properties.GenericFormBasedPropertySection;
 import de.itemis.gmf.runtime.commons.properties.descriptors.IFormPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.TextPropertyDescriptor;
 /**
@@ -13,12 +12,11 @@ import de.itemis.gmf.runtime.commons.properties.descriptors.TextPropertyDescript
  * @author andreas muelder
  *
  */
-public abstract class NamePropertySection extends GenericFormBasedPropertySection{
+public abstract class NamePropertySection extends AbstractEditorPropertySection{
 
 	@Override
 	protected void createPropertyDescriptors(
 			List<IFormPropertyDescriptor> descriptors) {
-		// Text Property Descriptor for the name
 		TextPropertyDescriptor nameDescriptor = new TextPropertyDescriptor(
 				SGraphPackage.Literals.NAMED_ELEMENT__NAME, "Name: ");
 		descriptors.add(nameDescriptor);

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

@@ -23,13 +23,14 @@ import com.google.inject.Injector;
 import de.itemis.gmf.runtime.commons.properties.descriptors.IFormPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.TextPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.XtextPropertyDescriptor;
+
 /**
  * Property Section for {@link StateEditPart}s. Consists of a
  * {@link TextPropertyDescriptor} for the name field and an
  * {@link XtextPropertyDescriptor} for the expression.
  * 
  * @author andreas muelder
- *
+ * 
  */
 public class StatePropertySection extends NamePropertySection {
 
@@ -40,7 +41,7 @@ public class StatePropertySection extends NamePropertySection {
 
 		XtextPropertyDescriptor expressionsDescriptor = new XtextPropertyDescriptor(
 				SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
-				"Expression: ", getInjector());
+				"Expression: ", getInjector(), getActiveEditorResource());
 		descriptors.add(expressionsDescriptor);
 	}
 
@@ -48,8 +49,7 @@ public class StatePropertySection extends NamePropertySection {
 		Extensions<IExpressionsProvider> extensions = new Extensions<IExpressionsProvider>(
 				IExpressionsProvider.EXPRESSIONS_EXTENSION);
 		IExpressionsProvider registeredProvider = extensions
-				.getRegisteredProvider(SGraphFactory.eINSTANCE
-						.createState());
+				.getRegisteredProvider(SGraphFactory.eINSTANCE.createState());
 		return registeredProvider.getInjector();
 	}
 }

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

@@ -20,7 +20,6 @@ import org.yakindu.sct.ui.editor.extensions.IExpressionsProvider;
 
 import com.google.inject.Injector;
 
-import de.itemis.gmf.runtime.commons.properties.GenericFormBasedPropertySection;
 import de.itemis.gmf.runtime.commons.properties.descriptors.IFormPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.TextPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.XtextPropertyDescriptor;
@@ -33,7 +32,7 @@ import de.itemis.gmf.runtime.commons.properties.descriptors.XtextPropertyDescrip
  * @author andreas muelder
  * 
  */
-public class StatechartPropertySection extends GenericFormBasedPropertySection {
+public class StatechartPropertySection extends AbstractEditorPropertySection {
 
 	@Override
 	protected void createPropertyDescriptors(

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

@@ -20,7 +20,6 @@ import org.yakindu.sct.ui.editor.extensions.IExpressionsProvider;
 
 import com.google.inject.Injector;
 
-import de.itemis.gmf.runtime.commons.properties.GenericFormBasedPropertySection;
 import de.itemis.gmf.runtime.commons.properties.descriptors.IFormPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.XtextPropertyDescriptor;
 
@@ -31,15 +30,16 @@ import de.itemis.gmf.runtime.commons.properties.descriptors.XtextPropertyDescrip
  * @author andreas muelder
  * 
  */
-public class TransitionPropertySection extends GenericFormBasedPropertySection {
+public class TransitionPropertySection extends AbstractEditorPropertySection {
 
 	@Override
 	protected void createPropertyDescriptors(
 			List<IFormPropertyDescriptor> descriptors) {
 		XtextPropertyDescriptor expressionsDescriptor = new XtextPropertyDescriptor(
 				SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
-				"Expression: ", getInjector());
+				"Expression: ", getInjector(), getActiveEditorResource());
 		descriptors.add(expressionsDescriptor);
+
 	}
 
 	protected Injector getInjector() {