]> gerrit.simantics Code Review - simantics/platform.git/blob
c73efe63f1b3df5a549bd5f6ab183d922db24b81
[simantics/platform.git] /
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.profile.view;
13
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.SCLEditor;
22 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;
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;
31
32
33 public class SCLEditorComposite extends ConfigurationComposite {
34     
35         private SCLEditor editor;
36         
37     public void create(Composite body, IWorkbenchSite site, ISessionContext context, final WidgetSupport support) {
38         
39         GridLayoutFactory.fillDefaults().spacing(0, 0).equalWidth(false).numColumns(2).applyTo(body);
40         body.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
41         
42         Button button = new Button(body, support, SWT.NONE);
43         button.setText("&Apply changes");
44         button.addSelectionListener(new SelectionListenerImpl<Resource>(context) {
45
46                 private String content;
47                 
48                 @Override
49                 public void beforeApply() {
50                         content = editor.getContent();
51                         editor.getWidget().storeSelectedRange();
52                         editor.getControl().setFocus();
53                         editor.getWidget().restoreSelectedRange();
54                 }
55                 
56                         @Override
57                         public void apply(WriteGraph graph, Resource group) throws DatabaseException {
58                             Layer0X L0X = Layer0X.getInstance(graph);
59                                 graph.claimLiteral(group, L0X.HasExpression, content);
60                         }
61                         
62                 });
63         
64         editor = new SCLEditor(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());
68         
69     }
70     
71 }