Browse Source

Added Form based Property API

Andreas Mülder 14 years ago
parent
commit
973079d09a

+ 19 - 4
plugins/org.yakindu.sct.statechart.diagram/plugin.xml

@@ -358,13 +358,28 @@
    
    <extension point="org.eclipse.ui.views.properties.tabbed.propertySections" id="propsections">
       <propertySections contributorId="org.yakindu.sct.statechart.diagram.StatechartDiagramEditor">
+		<!-- State model section -->         
          <propertySection
-            id="property.section.domain" 
+            id="property.section.domain.state" 
             tab="property.tab.domain"
-            class="org.yakindu.sct.statechart.diagram.propertysheets.DiagramPropertySection">
-            <input type="org.eclipse.gmf.runtime.notation.View"/>
-            <input type="org.eclipse.gef.EditPart"/>
+            class="org.yakindu.sct.statechart.diagram.propertysheets.StatePropertySection">
+            <input type="org.yakindu.sct.statechart.diagram.editparts.StateEditPart"/>
          </propertySection>
+        <!-- Statechart model section -->         
+         <propertySection
+            id="property.section.domain.statechart" 
+            tab="property.tab.domain"
+            class="org.yakindu.sct.statechart.diagram.propertysheets.StatechartPropertySection">
+            <input type="org.yakindu.sct.statechart.diagram.editparts.StatechartTextEditPart"/>
+         </propertySection>
+        <!-- Transition model section -->         
+         <propertySection
+            id="property.section.domain.transition" 
+            tab="property.tab.domain"
+            class="org.yakindu.sct.statechart.diagram.propertysheets.TransitionPropertySection">
+            <input type="org.yakindu.sct.statechart.diagram.editparts.TransitionEditPart"/>
+         </propertySection>
+         
          <propertySection id="property.section.ConnectorAppearancePropertySection" 
             filter="org.eclipse.gmf.runtime.diagram.ui.properties.filters.ConnectionEditPartPropertySectionFilter" 
             class="org.eclipse.gmf.runtime.diagram.ui.properties.sections.appearance.ConnectionAppearancePropertySection" 

+ 4 - 1
plugins/org.yakindu.sct.statechart.diagram/src/org/yakindu/sct/statechart/diagram/extensions/IExpressionsProvider.java

@@ -5,10 +5,13 @@ import org.eclipse.swt.SWT;
 import com.google.inject.Injector;
 
 /**
- * @author muelder
+ * @author andreas muelder
  * 
  */
 public interface IExpressionsProvider extends ISCTProvider {
+
+	String EXPRESSIONS_EXTENSION = "org.yakindu.sct.statechart.diagram.expressions";
+
 	/**
 	 * 
 	 * @return the Injector

+ 0 - 55
plugins/org.yakindu.sct.statechart.diagram/src/org/yakindu/sct/statechart/diagram/propertysheets/DiagramPropertySection.java

@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2011 committers of YAKINDU 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:
- * 	committers of YAKINDU - initial API and implementation
- * 
- */
-package org.yakindu.sct.statechart.diagram.propertysheets;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.edit.provider.IItemPropertySource;
-import org.eclipse.emf.edit.ui.provider.PropertySource;
-import org.eclipse.ui.views.properties.IPropertySource;
-import org.eclipse.ui.views.properties.IPropertySourceProvider;
-import org.yakindu.model.sct.statechart.ExpressionElement;
-
-import de.itemis.gmf.runtime.commons.properties.SemanticPropertySection;
-
-/**
- * Custom SemanticPropertySection that creates ExpressionelementPropertySources
- * for ExpressionElements.
- * 
- * @author andreas muelder
- * 
- */
-public class DiagramPropertySection extends SemanticPropertySection implements
-		IPropertySourceProvider {
-
-	@Override
-	public IPropertySource getPropertySource(Object object) {
-		if (object instanceof IPropertySource) {
-			return (IPropertySource) object;
-		}
-		AdapterFactory af = getAdapterFactory(object);
-		if (af != null) {
-			IItemPropertySource ips = (IItemPropertySource) af.adapt(object,
-					IItemPropertySource.class);
-			if (ips != null) {
-				if (object instanceof ExpressionElement) {
-					return new ExpressionElementPropertySource(object, ips);
-				}
-				return new PropertySource(object, ips);
-			}
-		}
-		if (object instanceof IAdaptable) {
-			return (IPropertySource) ((IAdaptable) object)
-					.getAdapter(IPropertySource.class);
-		}
-		return null;
-	}
-}

+ 0 - 86
plugins/org.yakindu.sct.statechart.diagram/src/org/yakindu/sct/statechart/diagram/propertysheets/ExpressionElementPropertySource.java

@@ -1,86 +0,0 @@
-/**
- * Copyright (c) 2011 committers of YAKINDU 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:
- * 	committers of YAKINDU - initial API and implementation
- * 
- */
-package org.yakindu.sct.statechart.diagram.propertysheets;
-
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
-import org.eclipse.emf.edit.provider.IItemPropertySource;
-import org.eclipse.emf.edit.ui.provider.PropertyDescriptor;
-import org.eclipse.emf.edit.ui.provider.PropertySource;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.views.properties.IPropertyDescriptor;
-import org.yakindu.model.sct.statechart.ExpressionElement;
-import org.yakindu.model.sct.statechart.StatechartPackage;
-import org.yakindu.sct.statechart.diagram.extensions.Extensions;
-import org.yakindu.sct.statechart.diagram.extensions.IExpressionsProvider;
-
-import de.itemis.xtext.utils.jface.viewers.XtextCellEditor;
-
-/**
- * Creates an {@link XtextCellEditor} for all {@link ExpressionElement}s for the
- * Property Page. The Language provider is loaded via
- * org.yakindu.sct.statechart.diagram.expressions extension point.
- * 
- * 
- * 
- * @author muelder
- * 
- */
-public class ExpressionElementPropertySource extends PropertySource {
-
-	private static final String EXPRESSIONS_EXTENSION = "org.yakindu.sct.statechart.diagram.expressions";
-
-	private final ExpressionElement element;
-
-	public ExpressionElementPropertySource(Object object,
-			IItemPropertySource itemPropertySource) {
-		super(object, itemPropertySource);
-		element = (ExpressionElement) object;
-	}
-
-	@Override
-	protected IPropertyDescriptor createPropertyDescriptor(
-			IItemPropertyDescriptor itemPropertyDescriptor) {
-		if (itemPropertyDescriptor.getFeature(object) instanceof EAttribute) {
-			EAttribute attribute = (EAttribute) itemPropertyDescriptor
-					.getFeature(object);
-			if (StatechartPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION
-					.equals(attribute)) {
-				return new PropertyDescriptor(object, itemPropertyDescriptor) {
-					@Override
-					public CellEditor createPropertyEditor(Composite composite) {
-						final XtextCellEditor xTextEditor = new XtextCellEditor(
-								getExpressionsProvider().getStyle());
-						getExpressionsProvider().getInjector().injectMembers(
-								xTextEditor);
-						xTextEditor.setContext(((EObject)object).eResource());
-						xTextEditor.create(composite);
-						return xTextEditor;
-
-					}
-				};
-			}
-		}
-		;
-		return super.createPropertyDescriptor(itemPropertyDescriptor);
-	}
-
-	protected IExpressionsProvider getExpressionsProvider() {
-		Extensions<IExpressionsProvider> extensions = new Extensions<IExpressionsProvider>(
-				EXPRESSIONS_EXTENSION);
-		IExpressionsProvider registeredProvider = extensions
-				.getRegisteredProvider(element);
-		return registeredProvider;
-	}
-
-}

+ 1 - 1
plugins/org.yakindu.sct.statechart.diagram/src/org/yakindu/sct/statechart/diagram/propertysheets/SheetLabelProvider.java

@@ -24,7 +24,7 @@ import org.yakindu.sct.statechart.diagram.DiagramActivator;
 
 /**
  * 
- * @author muelder
+ * @author andreas muelder
  * 
  */
 public class SheetLabelProvider extends BaseLabelProvider implements

+ 58 - 0
plugins/org.yakindu.sct.statechart.diagram/src/org/yakindu/sct/statechart/diagram/propertysheets/StatePropertySection.java

@@ -0,0 +1,58 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.statechart.diagram.propertysheets;
+
+import java.util.List;
+
+import org.yakindu.model.sct.statechart.StatechartFactory;
+import org.yakindu.model.sct.statechart.StatechartPackage;
+import org.yakindu.sct.statechart.diagram.editparts.StateEditPart;
+import org.yakindu.sct.statechart.diagram.extensions.Extensions;
+import org.yakindu.sct.statechart.diagram.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;
+/**
+ * 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 GenericFormBasedPropertySection {
+
+	@Override
+	protected void createPropertyDescriptors(
+			List<IFormPropertyDescriptor> descriptors) {
+		
+		TextPropertyDescriptor nameDescriptor = new TextPropertyDescriptor(
+				StatechartPackage.Literals.NAMED_ELEMENT__NAME, "Name: ");
+		descriptors.add(nameDescriptor);
+
+		XtextPropertyDescriptor expressionsDescriptor = new XtextPropertyDescriptor(
+				StatechartPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
+				"Expression: ", getInjector());
+		descriptors.add(expressionsDescriptor);
+	}
+
+	protected Injector getInjector() {
+		Extensions<IExpressionsProvider> extensions = new Extensions<IExpressionsProvider>(
+				IExpressionsProvider.EXPRESSIONS_EXTENSION);
+		IExpressionsProvider registeredProvider = extensions
+				.getRegisteredProvider(StatechartFactory.eINSTANCE
+						.createState());
+		return registeredProvider.getInjector();
+	}
+}

+ 59 - 0
plugins/org.yakindu.sct.statechart.diagram/src/org/yakindu/sct/statechart/diagram/propertysheets/StatechartPropertySection.java

@@ -0,0 +1,59 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.statechart.diagram.propertysheets;
+
+import java.util.List;
+
+import org.yakindu.model.sct.statechart.StatechartFactory;
+import org.yakindu.model.sct.statechart.StatechartPackage;
+import org.yakindu.sct.statechart.diagram.editparts.StatechartTextEditPart;
+import org.yakindu.sct.statechart.diagram.extensions.Extensions;
+import org.yakindu.sct.statechart.diagram.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;
+
+/**
+ * Property Section for {@link StatechartTextEditPart}s. Consists of a
+ * {@link TextPropertyDescriptor} for the name field and an
+ * {@link XtextPropertyDescriptor} for the expression.
+ * 
+ * @author andreas muelder
+ * 
+ */
+public class StatechartPropertySection extends GenericFormBasedPropertySection {
+
+	@Override
+	protected void createPropertyDescriptors(
+			List<IFormPropertyDescriptor> descriptors) {
+		//Text Property Descriptor for the name
+		TextPropertyDescriptor nameDescriptor = new TextPropertyDescriptor(
+				StatechartPackage.Literals.NAMED_ELEMENT__NAME, "Name: ");
+		descriptors.add(nameDescriptor);
+		//Text property descriptor for the expression
+		XtextPropertyDescriptor expressionsDescriptor = new XtextPropertyDescriptor(
+				StatechartPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
+				"Expression: ", getInjector());
+		descriptors.add(expressionsDescriptor);
+	}
+
+	protected Injector getInjector() {
+		Extensions<IExpressionsProvider> extensions = new Extensions<IExpressionsProvider>(
+				IExpressionsProvider.EXPRESSIONS_EXTENSION);
+		IExpressionsProvider registeredProvider = extensions
+				.getRegisteredProvider(StatechartFactory.eINSTANCE
+						.createStatechart());
+		return registeredProvider.getInjector();
+	}
+}

+ 53 - 0
plugins/org.yakindu.sct.statechart.diagram/src/org/yakindu/sct/statechart/diagram/propertysheets/TransitionPropertySection.java

@@ -0,0 +1,53 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.statechart.diagram.propertysheets;
+
+import java.util.List;
+
+import org.yakindu.model.sct.statechart.StatechartFactory;
+import org.yakindu.model.sct.statechart.StatechartPackage;
+import org.yakindu.sct.statechart.diagram.editparts.TransitionEditPart;
+import org.yakindu.sct.statechart.diagram.extensions.Extensions;
+import org.yakindu.sct.statechart.diagram.extensions.IExpressionsProvider;
+
+import com.google.inject.Injector;
+
+import de.itemis.gmf.runtime.commons.properties.GenericFormBasedPropertySection;
+import de.itemis.gmf.runtime.commons.properties.descriptors.IFormPropertyDescriptor;
+
+/**
+ * Property Section for {@link TransitionEditPart}s. Consists of a
+ * {@link XtextPropertyDescriptor} for the expression.
+ * 
+ * @author andreas muelder
+ * 
+ */
+public class TransitionPropertySection extends GenericFormBasedPropertySection {
+
+	@Override
+	protected void createPropertyDescriptors(
+			List<IFormPropertyDescriptor> descriptors) {
+		XtextPropertyDescriptor expressionsDescriptor = new XtextPropertyDescriptor(
+				StatechartPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
+				"Expression: ", getInjector());
+		descriptors.add(expressionsDescriptor);
+	}
+
+	protected Injector getInjector() {
+		Extensions<IExpressionsProvider> extensions = new Extensions<IExpressionsProvider>(
+				IExpressionsProvider.EXPRESSIONS_EXTENSION);
+		IExpressionsProvider registeredProvider = extensions
+				.getRegisteredProvider(StatechartFactory.eINSTANCE
+						.createTransition());
+		return registeredProvider.getInjector();
+	}
+
+}

+ 79 - 0
plugins/org.yakindu.sct.statechart.diagram/src/org/yakindu/sct/statechart/diagram/propertysheets/XtextPropertyDescriptor.java

@@ -0,0 +1,79 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.statechart.diagram.propertysheets;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Composite;
+
+import com.google.inject.Injector;
+
+import de.itemis.gmf.runtime.commons.properties.descriptors.AbstractPropertyDescriptor;
+import de.itemis.xtext.utils.jface.viewers.XtextCellEditor;
+
+/**
+ * 
+ * @author andreas muelder
+ * 
+ */
+public class XtextPropertyDescriptor extends AbstractPropertyDescriptor {
+
+	private final Injector injector;
+
+	public XtextPropertyDescriptor(EAttribute feature, String labelName,
+			Injector injector) {
+		super(feature, labelName);
+		this.injector = injector;
+	}
+
+	public StyledText createControl(Composite parent) {
+		XtextCellEditor editor = new XtextCellEditor(SWT.MULTI | SWT.BORDER
+				| SWT.V_SCROLL) {
+			@Override
+			protected void focusLost() {
+				// super.focusLost();
+			}
+		};
+		getInjector().injectMembers(editor);
+		editor.create(parent);
+		editor.activate();
+		editor.getControl().setVisible(true);
+		GridDataFactory.fillDefaults().grab(true, true)
+				.applyTo(editor.getControl());
+		return (StyledText) editor.getControl();
+	}
+
+	public Object getControlValue() {
+		StyledText styledText = getControl();
+		return (styledText.getText() != null && styledText.getText().trim()
+				.length() != 0) ? styledText.getText().trim() : null;
+	}
+
+	public void setControlValue(Object value) {
+		if (value != null) {
+			Assert.isTrue(value instanceof String, "Illegal value " + value);
+			getControl().setText((String) value);
+		}
+	}
+
+	public Injector getInjector() {
+		return injector;
+	}
+
+	@Override
+	public StyledText getControl() {
+		return (StyledText) super.getControl();
+	}
+
+}