X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.common%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fcommon%2FTreeTableCell.java;h=299c7c7964955e4c47b2aa1beab214342ae35c39;hb=6f11a60dee43d620d500c0cf5af34a1d91c80a8b;hp=0ff973e9d233766042e6e8fbbe5b2302d387f333;hpb=6a4a43b278d6819c660182eb4954524d1757e077;p=simantics%2Fplatform.git 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 0ff973e9d..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 @@ -1,33 +1,89 @@ -/******************************************************************************* - * Copyright (c) 2013, 2014 Association for Decentralized - * Information Management in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the THTH Simantics - * Division Member Component License which accompanies this - * distribution, and is available at - * http://www.simantics.org/legal/sdmcl-v10.html - * - * Contributors: - * Semantum Oy - initial API and implementation - *******************************************************************************/ -package org.simantics.spreadsheet.common; - -import org.simantics.document.server.io.ITreeTableCell; - -public class TreeTableCell extends TableCell implements ITreeTableCell { - - private int parent = -1; - - public TreeTableCell() { - } - - public void setParent(int parent) { - this.parent = parent; - } - - @Override - public int getParent() { - return parent; - } - -} +/******************************************************************************* + * Copyright (c) 2013, 2014 Association for Decentralized + * Information Management in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the THTH Simantics + * Division Member Component License which accompanies this + * distribution, and is available at + * http://www.simantics.org/legal/sdmcl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +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; + } + + @Override + public int getParent() { + return parent; + } + + @Override + public Object getData() { + return data; + } + + @Override + public boolean isEditable() { + return editable; + } + +}