1 package org.simantics.spreadsheet.ui.editor;
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.IWorkbenchPage;
10 import org.eclipse.ui.IWorkbenchPart;
11 import org.eclipse.ui.IWorkbenchSite;
12 import org.eclipse.ui.part.IContributedContentsView;
13 import org.simantics.browsing.ui.swt.widgets.Button;
14 import org.simantics.browsing.ui.swt.widgets.Label;
15 import org.simantics.browsing.ui.swt.widgets.TrackedText;
16 import org.simantics.browsing.ui.swt.widgets.VariableStringPropertyFactory;
17 import org.simantics.browsing.ui.swt.widgets.VariableStringPropertyTextModifier;
18 import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;
19 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.layer0.variable.Variable;
23 import org.simantics.db.management.ISessionContext;
24 import org.simantics.selectionview.PropertyTabContributorImpl;
25 import org.simantics.spreadsheet.CommandCellExecutor;
26 import org.simantics.spreadsheet.Range;
27 import org.simantics.spreadsheet.graph.GraphUI;
28 import org.simantics.spreadsheet.util.SpreadsheetUtils;
30 public class CommandCellTab extends PropertyTabContributorImpl {
32 private IWorkbenchPart getContributor(IWorkbenchSite site) {
33 IWorkbenchPage page = site.getPage();
36 return page.getActivePart();
39 public void createControls(Composite body, final IWorkbenchSite site, final ISessionContext context, WidgetSupport support) {
41 Display display = body.getDisplay();
42 Font font = new Font(display, "Arial", 12, SWT.NONE);
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);
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);
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);
59 Label header = new Label(headerComposite2, support, 0);
60 //header.setTextFactory(new VariableStringPropertyFactory(" Variable - %1", "#URI"));
61 header.setText("Command");
63 header.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
64 GridDataFactory.fillDefaults().grab(true, false).span(2, 1).align(SWT.CENTER, SWT.CENTER).applyTo(header.getWidget());
66 Label label = new Label(composite, support, SWT.NONE);
67 label.setText("Expression: ");
68 label.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
69 GridDataFactory.fillDefaults().grab(false, false).applyTo(label.getWidget());
71 TrackedText name = new TrackedText(composite, support, SWT.BORDER);
72 name.setTextFactory(new VariableStringPropertyFactory("#Expression"));
73 name.addModifyListener(new VariableStringPropertyTextModifier("Expression"));
74 GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());
76 Button toggleCaseButton = new Button(composite, support, SWT.PUSH);
77 toggleCaseButton.setText("Execute");
78 toggleCaseButton.addSelectionListener(new SelectionListenerImpl<Variable>(context) {
81 public void apply(WriteGraph graph, Variable variable) throws DatabaseException {
83 final IWorkbenchPart spp = getContributor(site);
84 System.out.println("run command " + spp);
85 if(spp instanceof IContributedContentsView) {
86 IContributedContentsView ccw = (IContributedContentsView)spp;
87 IWorkbenchPart editorPart = ccw.getContributingPart();
88 GraphUI ui = (GraphUI)editorPart.getAdapter(GraphUI.class);
90 CommandCellExecutor executor = (CommandCellExecutor)ui.getAdapter(CommandCellExecutor.class);
91 String location = variable.getPossiblePropertyValue(graph, "HasName");
92 Range range = SpreadsheetUtils.decodeCellAbsolute(location);
93 executor.execute(range.startRow, range.startColumn);
94 System.out.println("uiui");