X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.ui%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fui%2Feditor%2FSpreadsheetEditor2.java;h=c8c17b223ee58b53ac2a61958edaf27e2e4e5688;hp=03a6727421dfa983a26fe37e9ac58503a35444f3;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/editor/SpreadsheetEditor2.java b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/editor/SpreadsheetEditor2.java index 03a672742..c8c17b223 100644 --- a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/editor/SpreadsheetEditor2.java +++ b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/editor/SpreadsheetEditor2.java @@ -1,171 +1,171 @@ -package org.simantics.spreadsheet.ui.editor; - -import java.util.Collection; -import java.util.Collections; -import java.util.TreeMap; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.contexts.IContextService; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.UnaryRead; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.request.VariableName; -import org.simantics.db.layer0.request.VariableRead; -import org.simantics.db.layer0.request.VariableRepresents; -import org.simantics.db.layer0.request.VariableURI; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; -import org.simantics.selectionview.StandardPropertyPage; -import org.simantics.spreadsheet.graph.GraphUI; -import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils; -import org.simantics.spreadsheet.resource.SpreadsheetResource; -import org.simantics.spreadsheet.ui.Spreadsheet; -import org.simantics.spreadsheet.util.SpreadsheetUtils; -import org.simantics.ui.workbench.IPropertyPage; -import org.simantics.ui.workbench.ResourceEditorPart2; -import org.simantics.utils.ui.LayoutUtils; -import org.simantics.utils.ui.jface.ActiveSelectionProvider; - -public class SpreadsheetEditor2 extends ResourceEditorPart2 { - - public static final boolean EXCEL = false; - public static final String EDITOR_ID = "org.simantics.spreadsheet.ui.editor2"; - - private Spreadsheet spreadsheet; - private final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider(); - private ExcelLink excelLink; - private GraphUI ui; - - public Spreadsheet getSpreadsheet() { - return spreadsheet; - } - - @Override - public void createPartControl(Composite parent) { - - // Create UI - parent.setLayout(LayoutUtils.createNoBorderGridLayout(1)); - parent.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); - - ui = new GraphUI(getSession()); - - try { - - Variable bookVariable = getSession().syncRequest(new Read() { - - @Override - public Variable perform(ReadGraph graph) throws DatabaseException { - - Resource book = getResourceInput2().getResource(); - Variable withContext = SpreadsheetUtils.getBookVariable(graph, book); - return withContext; - - } - - }); - -// getSession().syncRequest(new VariableRead(bookVariable) { -// -// @Override -// public Variable perform(ReadGraph graph) throws DatabaseException { -// SpreadsheetGraphUtils.fullSynchronization(graph, variable); -// return variable; -// } -// -// }); - - Variable sheetVariable = getSession().syncRequest(new VariableRead(bookVariable) { - - @Override - public Variable perform(ReadGraph graph) throws DatabaseException { - - SpreadsheetResource SR = SpreadsheetResource.getInstance(graph); - Collection children = variable.getChildren(graph); - if(children.isEmpty()) return null; - - TreeMap names = new TreeMap(); - for(Variable child : children) { - Resource type = child.getPossibleType(graph, SR.Spreadsheet); - if(type != null) - names.put(child.getName(graph), child); - } - - return names.firstEntry().getValue(); - - } - - }); - - String uri = getSession().syncRequest(new VariableURI(sheetVariable)); - - Resource book = getSession().syncRequest(new VariableRepresents(bookVariable)); - Resource sheet = getSession().syncRequest(new VariableRepresents(sheetVariable)); - String sheetName = getSession().syncRequest(new VariableName(sheetVariable)); - String bookName = getSession().syncRequest(new VariableName(bookVariable)); - - spreadsheet = new Spreadsheet(parent, SWT.NONE, ui, selectionProvider); - spreadsheet.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); - - excelLink = new ExcelLink(getSession(), sheet, spreadsheet.getClientModel(), book, bookName, sheetName, uri); - - if (GraphUI.DEBUG) - System.out.println("Opening SpreadsheetEditor2 with uri: " + uri); - ui.load(sheetVariable, spreadsheet.getClientInterface()); - - } catch (DatabaseException e) { - - e.printStackTrace(); - return; - - } - - spreadsheet.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - spreadsheet.defaultInitializeUI(); - - getSite().setSelectionProvider(selectionProvider); - - // Start tracking editor input validity. - activateValidation(); - - IContextService contexts = (IContextService)getSite().getService(IContextService.class); - contexts.activateContext("org.simantics.spreadsheet.ui.context"); - - } - - @Override - public void setFocus() { - if (spreadsheet != null) - spreadsheet.setFocus(); - } - - @Override - public Object getAdapter(Class adapter) { - if (adapter == IPropertyPage.class) - return new StandardPropertyPage(getSite(), Collections.singleton(SpreadsheetResource.URIs.BrowseContext)); - if (adapter == GraphUI.class) - return ui; - if (adapter == Spreadsheet.class) - return getSpreadsheet(); - return null; - } - - @Override - public void dispose() { - - if(EXCEL) - excelLink.dispose(); - -// backend.dispose(); - -// tableModel.dispose(); - ui.dispose(); - super.dispose(); - - } - +package org.simantics.spreadsheet.ui.editor; + +import java.util.Collection; +import java.util.Collections; +import java.util.TreeMap; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.contexts.IContextService; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.UnaryRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.VariableName; +import org.simantics.db.layer0.request.VariableRead; +import org.simantics.db.layer0.request.VariableRepresents; +import org.simantics.db.layer0.request.VariableURI; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.selectionview.StandardPropertyPage; +import org.simantics.spreadsheet.graph.GraphUI; +import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils; +import org.simantics.spreadsheet.resource.SpreadsheetResource; +import org.simantics.spreadsheet.ui.Spreadsheet; +import org.simantics.spreadsheet.util.SpreadsheetUtils; +import org.simantics.ui.workbench.IPropertyPage; +import org.simantics.ui.workbench.ResourceEditorPart2; +import org.simantics.utils.ui.LayoutUtils; +import org.simantics.utils.ui.jface.ActiveSelectionProvider; + +public class SpreadsheetEditor2 extends ResourceEditorPart2 { + + public static final boolean EXCEL = false; + public static final String EDITOR_ID = "org.simantics.spreadsheet.ui.editor2"; + + private Spreadsheet spreadsheet; + private final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider(); + private ExcelLink excelLink; + private GraphUI ui; + + public Spreadsheet getSpreadsheet() { + return spreadsheet; + } + + @Override + public void createPartControl(Composite parent) { + + // Create UI + parent.setLayout(LayoutUtils.createNoBorderGridLayout(1)); + parent.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); + + ui = new GraphUI(getSession()); + + try { + + Variable bookVariable = getSession().syncRequest(new Read() { + + @Override + public Variable perform(ReadGraph graph) throws DatabaseException { + + Resource book = getResourceInput2().getResource(); + Variable withContext = SpreadsheetUtils.getBookVariable(graph, book); + return withContext; + + } + + }); + +// getSession().syncRequest(new VariableRead(bookVariable) { +// +// @Override +// public Variable perform(ReadGraph graph) throws DatabaseException { +// SpreadsheetGraphUtils.fullSynchronization(graph, variable); +// return variable; +// } +// +// }); + + Variable sheetVariable = getSession().syncRequest(new VariableRead(bookVariable) { + + @Override + public Variable perform(ReadGraph graph) throws DatabaseException { + + SpreadsheetResource SR = SpreadsheetResource.getInstance(graph); + Collection children = variable.getChildren(graph); + if(children.isEmpty()) return null; + + TreeMap names = new TreeMap(); + for(Variable child : children) { + Resource type = child.getPossibleType(graph, SR.Spreadsheet); + if(type != null) + names.put(child.getName(graph), child); + } + + return names.firstEntry().getValue(); + + } + + }); + + String uri = getSession().syncRequest(new VariableURI(sheetVariable)); + + Resource book = getSession().syncRequest(new VariableRepresents(bookVariable)); + Resource sheet = getSession().syncRequest(new VariableRepresents(sheetVariable)); + String sheetName = getSession().syncRequest(new VariableName(sheetVariable)); + String bookName = getSession().syncRequest(new VariableName(bookVariable)); + + spreadsheet = new Spreadsheet(parent, SWT.NONE, ui, selectionProvider); + spreadsheet.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); + + excelLink = new ExcelLink(getSession(), sheet, spreadsheet.getClientModel(), book, bookName, sheetName, uri); + + if (GraphUI.DEBUG) + System.out.println("Opening SpreadsheetEditor2 with uri: " + uri); + ui.load(sheetVariable, spreadsheet.getClientInterface()); + + } catch (DatabaseException e) { + + e.printStackTrace(); + return; + + } + + spreadsheet.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + spreadsheet.defaultInitializeUI(); + + getSite().setSelectionProvider(selectionProvider); + + // Start tracking editor input validity. + activateValidation(); + + IContextService contexts = (IContextService)getSite().getService(IContextService.class); + contexts.activateContext("org.simantics.spreadsheet.ui.context"); + + } + + @Override + public void setFocus() { + if (spreadsheet != null) + spreadsheet.setFocus(); + } + + @Override + public Object getAdapter(Class adapter) { + if (adapter == IPropertyPage.class) + return new StandardPropertyPage(getSite(), Collections.singleton(SpreadsheetResource.URIs.BrowseContext)); + if (adapter == GraphUI.class) + return ui; + if (adapter == Spreadsheet.class) + return getSpreadsheet(); + return null; + } + + @Override + public void dispose() { + + if(EXCEL) + excelLink.dispose(); + +// backend.dispose(); + +// tableModel.dispose(); + ui.dispose(); + super.dispose(); + + } + } \ No newline at end of file