--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.modeling.ui.property.svg;\r
+\r
+import org.eclipse.jface.dialogs.IInputValidator;\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.resource.ColorDescriptor;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.graphics.Color;\r
+import org.eclipse.swt.graphics.RGB;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.widgets.DefaultColorProvider;\r
+import org.simantics.browsing.ui.swt.widgets.Label;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.selectionview.ComparableTabContributor;\r
+import org.simantics.selectionview.ConfigurationComposite;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class SVGElementComposite extends ConfigurationComposite {\r
+\r
+ public static ComparableTabContributor make(Resource input, double priority, String tabLabel) {\r
+ return make(new SVGInput(input), priority, tabLabel);\r
+ }\r
+\r
+ public static ComparableTabContributor make(SVGInput input, double priority, String tabLabel) {\r
+ return new ComparableTabContributor(new SVGElementComposite(), priority, input, tabLabel);\r
+ }\r
+\r
+ public void create(final Composite body, IWorkbenchSite site, final ISessionContext context, final WidgetSupport support) {\r
+\r
+ final Display display = body.getDisplay();\r
+\r
+ body.setBackground(display.getSystemColor(SWT.COLOR_WHITE));\r
+\r
+ Label expressionHeader = new Label(body, support, 0);\r
+ expressionHeader.setText("SVG markup");\r
+ expressionHeader.setFont(smallFont);\r
+ expressionHeader.setBackground(display.getSystemColor(SWT.COLOR_WHITE));\r
+ GridDataFactory.fillDefaults().grab(true, false).span(2, 1).align(SWT.CENTER, SWT.CENTER).applyTo(expressionHeader.getWidget());\r
+\r
+ TrackedText expression = new TrackedText(body, support, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);\r
+ expression.setSelectAllOnStartEdit(false);\r
+ expression.setColorProvider(new DefaultColorProvider(expression.getResourceManager()) {\r
+\r
+ private final ColorDescriptor inactiveColor = ColorDescriptor.createFrom(new RGB(220, 220, 255));\r
+\r
+ @Override\r
+ public Color getInactiveBackground() {\r
+ return resourceManager.createColor(inactiveColor);\r
+ }\r
+\r
+ });\r
+ expression.setTextFactory(new SVGTextFactory());\r
+ expression.addModifyListener(new SVGModifier());\r
+ expression.setInputValidator(new IInputValidator() {\r
+ @Override\r
+ public String isValid(String document) {\r
+ try {\r
+ XMLPrettyPrinter.parseDocument(document);\r
+ return null;\r
+ } catch (Exception e) {\r
+ return e.getMessage();\r
+ }\r
+ }\r
+ });\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(expression.getWidget());\r
+\r
+ }\r
+\r
+}\r