1 /*******************************************************************************
\r
2 * Copyright (c) 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.ui.property.svg;
\r
14 import org.eclipse.jface.dialogs.IInputValidator;
\r
15 import org.eclipse.jface.layout.GridDataFactory;
\r
16 import org.eclipse.jface.resource.ColorDescriptor;
\r
17 import org.eclipse.swt.SWT;
\r
18 import org.eclipse.swt.graphics.Color;
\r
19 import org.eclipse.swt.graphics.RGB;
\r
20 import org.eclipse.swt.widgets.Composite;
\r
21 import org.eclipse.swt.widgets.Display;
\r
22 import org.eclipse.ui.IWorkbenchSite;
\r
23 import org.simantics.browsing.ui.swt.widgets.DefaultColorProvider;
\r
24 import org.simantics.browsing.ui.swt.widgets.Label;
\r
25 import org.simantics.browsing.ui.swt.widgets.TrackedText;
\r
26 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
27 import org.simantics.db.Resource;
\r
28 import org.simantics.db.management.ISessionContext;
\r
29 import org.simantics.selectionview.ComparableTabContributor;
\r
30 import org.simantics.selectionview.ConfigurationComposite;
\r
33 * @author Tuukka Lehtonen
\r
35 public class SVGElementComposite extends ConfigurationComposite {
\r
37 public static ComparableTabContributor make(Resource input, double priority, String tabLabel) {
\r
38 return make(new SVGInput(input), priority, tabLabel);
\r
41 public static ComparableTabContributor make(SVGInput input, double priority, String tabLabel) {
\r
42 return new ComparableTabContributor(new SVGElementComposite(), priority, input, tabLabel);
\r
45 public void create(final Composite body, IWorkbenchSite site, final ISessionContext context, final WidgetSupport support) {
\r
47 final Display display = body.getDisplay();
\r
49 body.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
\r
51 Label expressionHeader = new Label(body, support, 0);
\r
52 expressionHeader.setText("SVG markup");
\r
53 expressionHeader.setFont(smallFont);
\r
54 expressionHeader.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
\r
55 GridDataFactory.fillDefaults().grab(true, false).span(2, 1).align(SWT.CENTER, SWT.CENTER).applyTo(expressionHeader.getWidget());
\r
57 TrackedText expression = new TrackedText(body, support, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
\r
58 expression.setSelectAllOnStartEdit(false);
\r
59 expression.setColorProvider(new DefaultColorProvider(expression.getResourceManager()) {
\r
61 private final ColorDescriptor inactiveColor = ColorDescriptor.createFrom(new RGB(220, 220, 255));
\r
64 public Color getInactiveBackground() {
\r
65 return resourceManager.createColor(inactiveColor);
\r
69 expression.setTextFactory(new SVGTextFactory());
\r
70 expression.addModifyListener(new SVGModifier());
\r
71 expression.setInputValidator(new IInputValidator() {
\r
73 public String isValid(String document) {
\r
75 XMLPrettyPrinter.parseDocument(document);
\r
77 } catch (Exception e) {
\r
78 return e.getMessage();
\r
82 GridDataFactory.fillDefaults().grab(true, true).applyTo(expression.getWidget());
\r