浏览代码

changed XTextPropertyDescriptor to use XtextTextWidget

Andreas Mülder 14 年之前
父节点
当前提交
7d15e3ab52

+ 3 - 1
de.itemis.gmf.utils/plugins/de.itemis.gmf.runtime.commons/META-INF/MANIFEST.MF

@@ -6,7 +6,9 @@ Bundle-Version: 1.0.0.qualifier
 Bundle-Vendor: itemis AG
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Require-Bundle: org.eclipse.gmf.runtime.diagram.ui.properties;bundle-version="1.4.2",
- org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="1.4.1"
+ org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="1.4.1",
+ de.itemis.xtext.utils.jface;bundle-version="1.0.0",
+ com.google.inject;bundle-version="2.0.0"
 Export-Package: de.itemis.gmf.runtime.commons.commands,
  de.itemis.gmf.runtime.commons.editparts,
  de.itemis.gmf.runtime.commons.editpolicies,

+ 69 - 0
de.itemis.gmf.utils/plugins/de.itemis.gmf.runtime.commons/src/de/itemis/gmf/runtime/commons/properties/descriptors/XtextPropertyDescriptor.java

@@ -0,0 +1,69 @@
+/**
+ * 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 de.itemis.gmf.runtime.commons.properties.descriptors;
+
+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.xtext.utils.jface.viewers.XtextStyledText;
+
+/**
+ * 
+ * @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) {
+		XtextStyledText styledTextWrapper = new XtextStyledText(parent,
+				SWT.MULTI | SWT.BORDER, getInjector());
+		GridDataFactory.fillDefaults().grab(true, true)
+				.applyTo(styledTextWrapper.getStyledText());
+		return (StyledText) styledTextWrapper.getStyledText();
+	}
+
+	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();
+	}
+
+}