X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.common%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fcommon%2FTreeTableCell.java;h=299c7c7964955e4c47b2aa1beab214342ae35c39;hp=2face448f40973faf7135e6575e99776ead55a4e;hb=8360fe5756f40b0f43f673394f1fef098d31627e;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 diff --git a/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/TreeTableCell.java b/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/TreeTableCell.java index 2face448f..299c7c796 100644 --- a/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/TreeTableCell.java +++ b/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/TreeTableCell.java @@ -12,15 +12,61 @@ *******************************************************************************/ package org.simantics.spreadsheet.common; +import org.eclipse.jface.resource.FontDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.FontData; +import org.simantics.document.server.io.IFont; import org.simantics.document.server.io.ITreeTableCell; +import org.simantics.document.server.io.SimpleFont; public class TreeTableCell extends TableCell implements ITreeTableCell { private int parent = -1; + + private boolean editable = true; + private Object data; public TreeTableCell() { } + public TreeTableCell(String text, Object data, Object font, int parent, int row, int column, boolean editable) { + super(column, row, 0, 0, text, (IFont)font, null, null, false, 1, 1); + this.editable = editable; + this.parent = parent; + this.data = data; + } + + @Override + public int getRowSpan() { + throw new IllegalStateException("Row span is not supported in TreeTableCell"); + } + + @Override + public int getColumnSpan() { + throw new IllegalStateException("Column span is not supported in TreeTableCell"); + } + + public static TreeTableCell createTreeTableCell(String text, Object data, Object font, int parent, int row, int column, boolean editable) { + return new TreeTableCell(text, data, extractIFont(font), parent, row, column, editable); + } + + private static IFont extractIFont(Object font) { + if(font instanceof FontDescriptor) { + FontDescriptor descriptor = (FontDescriptor)font; + String family = ""; + String style = ""; + int size = 12; + for(FontData d : descriptor.getFontData()) { + family = d.getName(); + if((d.getStyle() & SWT.ITALIC) != 0) style += "Italic"; + if((d.getStyle() & SWT.BOLD) != 0) style += "Bold"; + size = d.getHeight(); + } + return new SimpleFont(family, style, size); + } + return null; + } + public void setParent(int parent) { this.parent = parent; } @@ -30,4 +76,14 @@ public class TreeTableCell extends TableCell implements ITreeTableCell { return parent; } + @Override + public Object getData() { + return data; + } + + @Override + public boolean isEditable() { + return editable; + } + }