1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.diagram.profile.view;
14 import org.eclipse.jface.layout.GridDataFactory;
15 import org.eclipse.jface.layout.GridLayoutFactory;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Display;
19 import org.eclipse.ui.IWorkbenchSite;
20 import org.simantics.browsing.ui.swt.widgets.Button;
21 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;
22 import org.simantics.browsing.ui.swt.widgets.Text;
23 import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;
24 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
25 import org.simantics.db.Resource;
26 import org.simantics.db.WriteGraph;
27 import org.simantics.db.exception.DatabaseException;
28 import org.simantics.db.management.ISessionContext;
29 import org.simantics.operation.Layer0X;
30 import org.simantics.selectionview.ConfigurationComposite;
33 public class SCLEditorComposite extends ConfigurationComposite {
37 public void create(Composite body, IWorkbenchSite site, ISessionContext context, final WidgetSupport support) {
39 GridLayoutFactory.fillDefaults().spacing(0, 0).equalWidth(false).numColumns(2).applyTo(body);
40 body.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
42 Button button = new Button(body, support, SWT.NONE);
43 button.setText("&Apply changes");
44 button.addSelectionListener(new SelectionListenerImpl<Resource>(context) {
46 private String content;
49 public void beforeApply() {
50 content = editor.getWidget().getText();
51 //editor.getWidget().storeSelectedRange();
52 editor.getControl().setFocus();
53 //editor.getWidget().restoreSelectedRange();
57 public void apply(WriteGraph graph, Resource group) throws DatabaseException {
58 Layer0X L0X = Layer0X.getInstance(graph);
59 graph.claimLiteral(group, L0X.HasExpression, content);
64 editor = new Text(body, support, SWT.BORDER | SWT.FLAT);
65 editor.setTextFactory(new StringPropertyFactory(Layer0X.URIs.HasExpression));
66 //editor.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasExpression));
67 GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(editor.getControl());