Browse Source

If not grammar is specified, use a TextdirectEditManager as a fallback

Andreas Mülder 13 years ago
parent
commit
8e51568ed4

+ 50 - 8
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/PlugableExternalXtextLabelEditPart.java

@@ -11,10 +11,21 @@
 package org.yakindu.sct.ui.editor.editparts;
 
 import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EAttribute;
 import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.editpolicies.DirectEditPolicy;
+import org.eclipse.gef.tools.DirectEditManager;
+import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
+import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
 import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.viewers.ICellEditorValidator;
 import org.yakindu.sct.model.sgraph.ExpressionElement;
 import org.yakindu.sct.model.sgraph.SGraphPackage;
+import org.yakindu.sct.ui.editor.DiagramActivator;
 import org.yakindu.sct.ui.editor.extensions.ExpressionLanguageProviderExtensions;
 import org.yakindu.sct.ui.editor.extensions.ExpressionLanguageProviderExtensions.SemanticTarget;
 import org.yakindu.sct.ui.editor.extensions.IExpressionLanguageProvider;
@@ -22,6 +33,7 @@ import org.yakindu.sct.ui.editor.policies.ExpressionDirectEditPolicy;
 
 import com.google.inject.Injector;
 
+import de.itemis.gmf.runtime.commons.parsers.AttributeParser;
 import de.itemis.xtext.utils.gmf.directedit.ExternalXtextLabelEditPart;
 import de.itemis.xtext.utils.gmf.directedit.XtextDirectEditManager;
 
@@ -31,7 +43,7 @@ import de.itemis.xtext.utils.gmf.directedit.XtextDirectEditManager;
  * 
  */
 public abstract class PlugableExternalXtextLabelEditPart extends
-		ExternalXtextLabelEditPart {
+		ExternalXtextLabelEditPart implements ITextAwareEditPart {
 
 	private Injector injector;
 
@@ -52,15 +64,25 @@ public abstract class PlugableExternalXtextLabelEditPart extends
 	@Override
 	protected void createDefaultEditPolicies() {
 		super.createDefaultEditPolicies();
-		ExpressionDirectEditPolicy expressionDirectEditPolicy = new ExpressionDirectEditPolicy();
-		injector.injectMembers(expressionDirectEditPolicy);
-		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE,
-				expressionDirectEditPolicy);
+		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, createDirectEditPolicy());
+	}
+
+	protected DirectEditPolicy createDirectEditPolicy() {
+		if (injector != null) {
+			ExpressionDirectEditPolicy expressionDirectEditPolicy = new ExpressionDirectEditPolicy();
+			injector.injectMembers(expressionDirectEditPolicy);
+			return expressionDirectEditPolicy;
+		} else
+			return new LabelDirectEditPolicy();
 	}
 
 	@Override
-	protected XtextDirectEditManager createXTextDirectEditManager() {
-		return new XtextDirectEditManager(this, injector, getEditorStyles());
+	protected DirectEditManager createDirectEditManager() {
+		if (injector != null) {
+			return new XtextDirectEditManager(this, injector, getEditorStyles());
+		} else {
+			return new TextDirectEditManager(this);
+		}
 	}
 
 	@Override
@@ -70,13 +92,17 @@ public abstract class PlugableExternalXtextLabelEditPart extends
 
 	@Override
 	protected void handleNotificationEvent(Notification notification) {
-		if (notification.getFeature() == SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION) {
+		if (notification.getFeature() == getFeature()) {
 			refreshVisuals();
 		} else {
 			super.handleNotificationEvent(notification);
 		}
 	}
 
+	private EAttribute getFeature() {
+		return SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION;
+	}
+
 	public String getEditText() {
 		String exp = resolveSemanticElement().getExpression();
 		return exp != null ? exp : "";
@@ -86,4 +112,20 @@ public abstract class PlugableExternalXtextLabelEditPart extends
 		return injector;
 	}
 
+	public ICellEditorValidator getEditTextValidator() {
+		return null;
+	}
+
+	public ParserOptions getParserOptions() {
+		return ParserOptions.NONE;
+	}
+
+	public IParser getParser() {
+		return new AttributeParser(getFeature(), DiagramActivator.PLUGIN_ID);
+	}
+
+	public IContentAssistProcessor getCompletionProcessor() {
+		return null;
+	}
+
 }

+ 53 - 10
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/PlugableXtextLabelEditPart.java

@@ -11,10 +11,21 @@
 package org.yakindu.sct.ui.editor.editparts;
 
 import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EAttribute;
 import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.editpolicies.DirectEditPolicy;
+import org.eclipse.gef.tools.DirectEditManager;
+import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
+import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
 import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.viewers.ICellEditorValidator;
 import org.yakindu.sct.model.sgraph.ExpressionElement;
 import org.yakindu.sct.model.sgraph.SGraphPackage;
+import org.yakindu.sct.ui.editor.DiagramActivator;
 import org.yakindu.sct.ui.editor.extensions.ExpressionLanguageProviderExtensions;
 import org.yakindu.sct.ui.editor.extensions.ExpressionLanguageProviderExtensions.SemanticTarget;
 import org.yakindu.sct.ui.editor.extensions.IExpressionLanguageProvider;
@@ -22,6 +33,7 @@ import org.yakindu.sct.ui.editor.policies.ExpressionDirectEditPolicy;
 
 import com.google.inject.Injector;
 
+import de.itemis.gmf.runtime.commons.parsers.AttributeParser;
 import de.itemis.xtext.utils.gmf.directedit.XtextDirectEditManager;
 import de.itemis.xtext.utils.gmf.directedit.XtextLabelEditPart;
 
@@ -30,7 +42,8 @@ import de.itemis.xtext.utils.gmf.directedit.XtextLabelEditPart;
  * @author andreas muelder - Initial contribution and API
  * 
  */
-public abstract class PlugableXtextLabelEditPart extends XtextLabelEditPart {
+public abstract class PlugableXtextLabelEditPart extends XtextLabelEditPart
+		implements ITextAwareEditPart {
 
 	private Injector injector;
 
@@ -51,15 +64,25 @@ public abstract class PlugableXtextLabelEditPart extends XtextLabelEditPart {
 	@Override
 	protected void createDefaultEditPolicies() {
 		super.createDefaultEditPolicies();
-		ExpressionDirectEditPolicy expressionDirectEditPolicy = new ExpressionDirectEditPolicy();
-		injector.injectMembers(expressionDirectEditPolicy);
-		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE,
-				expressionDirectEditPolicy);
+		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, createDirectEditPolicy());
+	}
+
+	protected DirectEditPolicy createDirectEditPolicy() {
+		if (injector != null) {
+			ExpressionDirectEditPolicy expressionDirectEditPolicy = new ExpressionDirectEditPolicy();
+			injector.injectMembers(expressionDirectEditPolicy);
+			return expressionDirectEditPolicy;
+		} else
+			return new LabelDirectEditPolicy();
 	}
 
 	@Override
-	protected XtextDirectEditManager createXTextDirectEditManager() {
-		return new XtextDirectEditManager(this, injector, getEditorStyles());
+	protected DirectEditManager createDirectEditManager() {
+		if (injector != null) {
+			return new XtextDirectEditManager(this, injector, getEditorStyles());
+		} else {
+			return new TextDirectEditManager(this);
+		}
 	}
 
 	@Override
@@ -69,20 +92,40 @@ public abstract class PlugableXtextLabelEditPart extends XtextLabelEditPart {
 
 	@Override
 	protected void handleNotificationEvent(Notification notification) {
-		if (notification.getFeature() == SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION) {
+		if (notification.getFeature() == getFeature()) {
 			refreshVisuals();
 		} else {
 			super.handleNotificationEvent(notification);
 		}
 	}
 
+	private EAttribute getFeature() {
+		return SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION;
+	}
+
+	public Injector getInjector() {
+		return injector;
+	}
+
 	public String getEditText() {
 		String exp = resolveSemanticElement().getExpression();
 		return exp != null ? exp : "";
 	}
 
-	public Injector getInjector() {
-		return injector;
+	public ICellEditorValidator getEditTextValidator() {
+		return null;
+	}
+
+	public ParserOptions getParserOptions() {
+		return ParserOptions.NONE;
+	}
+
+	public IParser getParser() {
+		return new AttributeParser(getFeature(), DiagramActivator.PLUGIN_ID);
+	}
+
+	public IContentAssistProcessor getCompletionProcessor() {
+		return null;
 	}
 
 }

+ 1 - 2
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/extensions/ExpressionLanguageProviderExtensions.java

@@ -61,7 +61,6 @@ public class ExpressionLanguageProviderExtensions {
 				e.printStackTrace();
 			}
 		}
-		throw new IllegalStateException("No Expression Provider found for "
-				+ target);
+		return new IExpressionLanguageProvider.NullLanguageProvider();
 	}
 }

+ 8 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/extensions/IExpressionLanguageProvider.java

@@ -21,4 +21,12 @@ public interface IExpressionLanguageProvider {
 
 	public Injector getInjector();
 
+	public static class NullLanguageProvider implements IExpressionLanguageProvider {
+		public Injector getInjector() {
+			return null;
+		}
+	}
 }
+
+
+

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

@@ -18,7 +18,10 @@ import org.yakindu.sct.ui.editor.editparts.StateEditPart;
 import org.yakindu.sct.ui.editor.extensions.ExpressionLanguageProviderExtensions.SemanticTarget;
 import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
 
+import com.google.inject.Injector;
+
 import de.itemis.gmf.runtime.commons.properties.descriptors.IFormPropertyDescriptor;
+import de.itemis.gmf.runtime.commons.properties.descriptors.TextAreaPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.TextPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.XtextPropertyDescriptor;
 import de.itemis.xtext.utils.jface.viewers.context.CloningBasedFakeContextResourcesProvider;
@@ -38,14 +41,22 @@ public class StatePropertySection extends NamePropertySection {
 			List<IFormPropertyDescriptor> descriptors) {
 		super.createPropertyDescriptors(descriptors);
 
-		XtextPropertyDescriptor expressionsDescriptor = new XtextPropertyDescriptor(
-				SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
-				"Expression: ",
-				IYakinduSctHelpContextIds.SC_PROPERTIES_STATE_EXPRESSION,
-				getInjector(SemanticTarget.StateDeclaration),
-				new CloningBasedFakeContextResourcesProvider(
-						Collections.singletonList(getActiveEditorResource())));
-		descriptors.add(expressionsDescriptor);
+		Injector injector = getInjector(SemanticTarget.StateDeclaration);
+		if (injector != null) {
+			XtextPropertyDescriptor descriptor = new XtextPropertyDescriptor(
+					SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
+					"Expression: ",
+					IYakinduSctHelpContextIds.SC_PROPERTIES_STATE_EXPRESSION,
+					injector, new CloningBasedFakeContextResourcesProvider(
+							Collections
+									.singletonList(getActiveEditorResource())));
+			descriptors.add(descriptor);
+		} else {
+			TextAreaPropertyDescriptor descriptor = new TextAreaPropertyDescriptor(
+					SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
+					"Expression: ");
+			descriptors.add(descriptor);
+		}
 
 		// Submachine reference
 		SubmachineSelectionDialogPropertyDescriptor submachineDescriptor = new SubmachineSelectionDialogPropertyDescriptor();

+ 22 - 7
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/StatechartPropertySection.java

@@ -10,6 +10,7 @@
  */
 package org.yakindu.sct.ui.editor.propertysheets;
 
+import java.util.Collections;
 import java.util.List;
 
 import org.yakindu.sct.model.sgraph.SGraphPackage;
@@ -17,9 +18,13 @@ import org.yakindu.sct.ui.editor.editparts.StatechartTextEditPart;
 import org.yakindu.sct.ui.editor.extensions.ExpressionLanguageProviderExtensions.SemanticTarget;
 import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
 
+import com.google.inject.Injector;
+
 import de.itemis.gmf.runtime.commons.properties.descriptors.IFormPropertyDescriptor;
+import de.itemis.gmf.runtime.commons.properties.descriptors.TextAreaPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.TextPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.XtextPropertyDescriptor;
+import de.itemis.xtext.utils.jface.viewers.context.CloningBasedFakeContextResourcesProvider;
 
 /**
  * Property Section for {@link StatechartTextEditPart}s. Consists of a
@@ -39,13 +44,23 @@ public class StatechartPropertySection extends AbstractEditorPropertySection {
 				SGraphPackage.Literals.NAMED_ELEMENT__NAME, "Name: ");
 		descriptors.add(nameDescriptor);
 		
-		// Xtext property descriptor for the expression
-		XtextPropertyDescriptor expressionsDescriptor = new XtextPropertyDescriptor(
-				SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
-				"Expression: ",
-				IYakinduSctHelpContextIds.SC_PROPERTIES_STATECHART_EXPRESSION,
-				getInjector(SemanticTarget.StatechartInterface));
-		descriptors.add(expressionsDescriptor);
+		Injector injector = getInjector(SemanticTarget.StatechartInterface);
+		
+		if (injector != null) {
+			XtextPropertyDescriptor descriptor = new XtextPropertyDescriptor(
+					SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
+					"Expression: ",
+					IYakinduSctHelpContextIds.SC_PROPERTIES_STATECHART_EXPRESSION,
+					injector, new CloningBasedFakeContextResourcesProvider(
+							Collections
+									.singletonList(getActiveEditorResource())));
+			descriptors.add(descriptor);
+		} else {
+			TextAreaPropertyDescriptor descriptor = new TextAreaPropertyDescriptor(
+					SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
+					"Expression: ");
+			descriptors.add(descriptor);
+		}
 	}
 
 }

+ 7 - 34
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/SubmachineSelectionDialogPropertyDescriptor.java

@@ -18,7 +18,7 @@ import org.eclipse.draw2d.ColorConstants;
 import org.eclipse.emf.common.notify.Notification;
 import org.eclipse.emf.common.notify.impl.AdapterImpl;
 import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
 import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
 import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
 import org.eclipse.jface.dialogs.Dialog;
@@ -31,20 +31,11 @@ import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.xtext.naming.IQualifiedNameConverter;
-import org.eclipse.xtext.naming.IQualifiedNameProvider;
-import org.eclipse.xtext.naming.QualifiedName;
 import org.yakindu.sct.model.sgraph.SGraphPackage;
 import org.yakindu.sct.model.sgraph.State;
 import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.model.sgraph.provider.SGraphItemProviderAdapterFactory;
 import org.yakindu.sct.ui.editor.dialogs.SelectSubmachineDialog;
-import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
-import org.yakindu.sct.ui.editor.extensions.ExpressionLanguageProviderExtensions;
-import org.yakindu.sct.ui.editor.extensions.ExpressionLanguageProviderExtensions.SemanticTarget;
-import org.yakindu.sct.ui.editor.extensions.IExpressionLanguageProvider;
-
-import com.google.inject.Inject;
-import com.google.inject.Injector;
 
 import de.itemis.gmf.runtime.commons.properties.descriptors.IFormPropertyDescriptor;
 
@@ -65,26 +56,13 @@ public class SubmachineSelectionDialogPropertyDescriptor implements
 		}
 	}
 
-	@Inject
-	IQualifiedNameProvider nameProvider;
-	@Inject
-	IQualifiedNameConverter nameConverter;
 	private State state;
 	private Label label;
 	private UpdateLabelAdapter updateLabelAdapter;
 	private EObject context;
 
-	private void injectMembers(Resource resource) {
-		IExpressionLanguageProvider provider = ExpressionLanguageProviderExtensions
-				.getRegisteredProvider(SemanticTarget.StatechartInterface,
-						resource.getURI().lastSegment());
-		Injector injector = provider.getInjector();
-		injector.injectMembers(this);
-	}
-
 	public void updateModelBinding(EObject eObject) {
 		this.state = (State) eObject;
-		injectMembers(state.eResource());
 		updateLabel(state);
 		context = eObject;
 		if (updateLabelAdapter == null) {
@@ -95,18 +73,13 @@ public class SubmachineSelectionDialogPropertyDescriptor implements
 
 	private void updateLabel(State state) {
 		Statechart substatechart = state.getSubstatechart();
-		String labelText = "";
 		if (substatechart != null) {
-			QualifiedName qualifiedName = nameProvider
-					.getFullyQualifiedName(substatechart);
-			if (qualifiedName != null) {
-				String text = nameConverter.toString(qualifiedName);
-				labelText = text;
-			} else {
-				labelText = "<UNRESOLVED>";
-			}
+			AdapterFactoryLabelProvider provider = new AdapterFactoryLabelProvider(
+					new SGraphItemProviderAdapterFactory());
+			label.setText(provider.getText(substatechart));
+		} else {
+			label.setText("");
 		}
-		label.setText(labelText);
 	}
 
 	public void createLabelColumn(Composite parent) {

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

@@ -18,7 +18,10 @@ import org.yakindu.sct.ui.editor.editparts.TransitionEditPart;
 import org.yakindu.sct.ui.editor.extensions.ExpressionLanguageProviderExtensions.SemanticTarget;
 import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
 
+import com.google.inject.Injector;
+
 import de.itemis.gmf.runtime.commons.properties.descriptors.IFormPropertyDescriptor;
+import de.itemis.gmf.runtime.commons.properties.descriptors.TextAreaPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.XtextPropertyDescriptor;
 import de.itemis.xtext.utils.jface.viewers.context.CloningBasedFakeContextResourcesProvider;
 
@@ -34,13 +37,21 @@ public class TransitionPropertySection extends AbstractEditorPropertySection {
 	@Override
 	protected void createPropertyDescriptors(
 			List<IFormPropertyDescriptor> descriptors) {
-		XtextPropertyDescriptor expressionsDescriptor = new XtextPropertyDescriptor(
-				SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
-				"Expression: ",
-				IYakinduSctHelpContextIds.SC_PROPERTIES_TRANSITION_EXPRESSION,
-				getInjector(SemanticTarget.TransitionExpression),
-				new CloningBasedFakeContextResourcesProvider(
-						Collections.singletonList(getActiveEditorResource())));
-		descriptors.add(expressionsDescriptor);
+		Injector injector = getInjector(SemanticTarget.TransitionExpression);
+		if (injector != null) {
+			XtextPropertyDescriptor descriptor = new XtextPropertyDescriptor(
+					SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
+					"Expression: ",
+					IYakinduSctHelpContextIds.SC_PROPERTIES_STATECHART_EXPRESSION,
+					injector, new CloningBasedFakeContextResourcesProvider(
+							Collections
+									.singletonList(getActiveEditorResource())));
+			descriptors.add(descriptor);
+		} else {
+			TextAreaPropertyDescriptor descriptor = new TextAreaPropertyDescriptor(
+					SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
+					"Expression: ");
+			descriptors.add(descriptor);
+		}
 	}
 }