]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/editor/NoCellTab.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.spreadsheet.ui / src / org / simantics / spreadsheet / ui / editor / NoCellTab.java
1 package org.simantics.spreadsheet.ui.editor;
2
3 import org.eclipse.jface.layout.GridDataFactory;
4 import org.eclipse.jface.layout.GridLayoutFactory;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.graphics.Font;
7 import org.eclipse.swt.widgets.Composite;
8 import org.eclipse.swt.widgets.Display;
9 import org.eclipse.ui.IWorkbenchSite;
10 import org.simantics.browsing.ui.swt.widgets.Label;
11 import org.simantics.browsing.ui.swt.widgets.TrackedText;
12 import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl;
13 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
14 import org.simantics.db.WriteGraph;
15 import org.simantics.db.exception.DatabaseException;
16 import org.simantics.db.layer0.variable.Variable;
17 import org.simantics.db.layer0.variable.VariableSpaceManipulator;
18 import org.simantics.db.layer0.variable.VariableSpaceManipulator.ChildCreationData;
19 import org.simantics.db.layer0.variable.Variables;
20 import org.simantics.db.layer0.variable.VariableSpaceManipulator.Modification;
21 import org.simantics.db.layer0.variable.VariableSpaceManipulator.PropertyCreationData;
22 import org.simantics.db.management.ISessionContext;
23 import org.simantics.selectionview.PropertyTabContributorImpl;
24
25 public class NoCellTab extends PropertyTabContributorImpl {
26
27         static class NoCellInput {
28                 
29                 public Variable sheet;
30                 public String location;
31                 
32                 public NoCellInput(Variable sheet, String location) {
33                         this.sheet = sheet;
34                         this.location = location;
35                 }
36                 
37         }
38         
39     public void createControls(Composite body, IWorkbenchSite site, final ISessionContext context, WidgetSupport support) {
40
41         Display display = body.getDisplay();
42         Font font = new Font(display, "Arial", 12, SWT.NONE); 
43
44         Composite composite = new Composite(body, SWT.NONE);
45         composite.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
46         GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
47         GridLayoutFactory.fillDefaults().equalWidth(false).numColumns(2).applyTo(composite);
48         
49         Composite headerComposite = new Composite(composite, 0);
50         headerComposite.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
51         GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(headerComposite);
52         GridLayoutFactory.fillDefaults().equalWidth(false).numColumns(1).extendedMargins(2,2,2,2).applyTo(headerComposite);
53
54         Composite headerComposite2 = new Composite(headerComposite, 0);
55         headerComposite2.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
56         GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(headerComposite2);
57         GridLayoutFactory.fillDefaults().equalWidth(false).numColumns(1).extendedMargins(3,3,3,3).applyTo(headerComposite2);
58
59         Label header = new Label(headerComposite2, support, 0);
60         header.setText("Create new cell");
61         header.setFont(font);
62         header.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
63         GridDataFactory.fillDefaults().grab(true, false).span(2, 1).align(SWT.CENTER, SWT.CENTER).applyTo(header.getWidget());
64         
65         Label label = new Label(composite, support, SWT.NONE);
66         label.setText("Expression: ");
67         label.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
68         GridDataFactory.fillDefaults().grab(false, false).applyTo(label.getWidget());
69         
70         TrackedText name = new TrackedText(composite, support, SWT.BORDER);
71         name.setText("");
72         GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());
73         name.addModifyListener(new TextModifyListenerImpl<NoCellInput>() {
74
75                         @Override
76                         public void applyText(WriteGraph graph, NoCellInput input, String text) throws DatabaseException {
77 //                              System.out.println("create variable for " + input);
78                                 VariableSpaceManipulator manipulator = input.sheet.adapt(graph, VariableSpaceManipulator.class);
79                                 manipulator.apply(graph, Modification.addChild(ChildCreationData.build(input.location, "", PropertyCreationData.build(Variables.NAME, text))));
80                         }
81                 
82         });
83         
84     }
85    
86 }