]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/TreeTableCell.java
TreeGridWidget improvements
[simantics/platform.git] / bundles / org.simantics.spreadsheet.common / src / org / simantics / spreadsheet / common / TreeTableCell.java
index 0ff973e9d233766042e6e8fbbe5b2302d387f333..299c7c7964955e4c47b2aa1beab214342ae35c39 100644 (file)
@@ -1,33 +1,89 @@
-/*******************************************************************************\r
- * Copyright (c) 2013, 2014 Association for Decentralized \r
- * Information Management in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the THTH Simantics \r
- * Division Member Component License which accompanies this \r
- * distribution, and is available at\r
- * http://www.simantics.org/legal/sdmcl-v10.html\r
- *\r
- * Contributors:\r
- *     Semantum Oy - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.spreadsheet.common;\r
-\r
-import org.simantics.document.server.io.ITreeTableCell;\r
-\r
-public class TreeTableCell extends TableCell implements ITreeTableCell {       \r
-       \r
-       private int parent = -1;\r
-\r
-       public TreeTableCell() {\r
-       }\r
-       \r
-       public void setParent(int parent) {\r
-               this.parent = parent;\r
-       }\r
-       \r
-       @Override\r
-       public int getParent() {\r
-               return parent;\r
-       }\r
-\r
-}\r
+/*******************************************************************************
+ * 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;
+       }
+
+}