]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/Spreadsheet.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.spreadsheet.ui / src / org / simantics / spreadsheet / ui / Spreadsheet.java
diff --git a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/Spreadsheet.java b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/Spreadsheet.java
new file mode 100644 (file)
index 0000000..9b87ac0
--- /dev/null
@@ -0,0 +1,110 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.spreadsheet.ui;\r
+\r
+import javax.swing.JComponent;\r
+import javax.swing.JTable;\r
+import javax.swing.UIManager;\r
+import javax.swing.UnsupportedLookAndFeelException;\r
+\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.DisposeEvent;\r
+import org.eclipse.swt.events.DisposeListener;\r
+import org.eclipse.swt.layout.FillLayout;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.g2d.chassis.SWTChassis;\r
+import org.simantics.spreadsheet.Adaptable;\r
+import org.simantics.spreadsheet.ClientModel;\r
+import org.simantics.utils.ui.jface.ActiveSelectionProvider;\r
+\r
+public class Spreadsheet extends Composite {\r
+\r
+       public static boolean DEBUG = false;\r
+\r
+       final private SpreadsheetModel sm;\r
+\r
+       public SpreadsheetModel getModel() {\r
+               return sm;\r
+       }\r
+\r
+       public Spreadsheet(Composite parent, int style, Adaptable serverInterface, ActiveSelectionProvider selectionProvider) {\r
+\r
+               super(parent, style);\r
+\r
+               sm = new SpreadsheetModel(serverInterface, selectionProvider);\r
+\r
+               addDisposeListener(new DisposeListener() {\r
+                       @Override\r
+                       public void widgetDisposed(DisposeEvent e) {\r
+                       }\r
+               });\r
+\r
+       }\r
+\r
+       public ClientModel getClientModel() {\r
+\r
+               return sm.getClientModel();\r
+\r
+       }\r
+\r
+       public ClientModel getClientInterface() {\r
+\r
+               return sm.getClientInterface();\r
+\r
+       }\r
+\r
+       public void defaultInitializeUI() {\r
+\r
+               try {\r
+                       // Set System L&F\r
+                       UIManager.setLookAndFeel(\r
+                                       UIManager.getSystemLookAndFeelClassName());\r
+               }\r
+               catch (UnsupportedLookAndFeelException e) {\r
+                       // handle exception\r
+               }\r
+               catch (ClassNotFoundException e) {\r
+                       // handle exception\r
+               }\r
+               catch (InstantiationException e) {\r
+                       // handle exception\r
+               }\r
+               catch (IllegalAccessException e) {\r
+                       // handle exception\r
+               }\r
+\r
+               setLayout(new FillLayout(SWT.NONE));\r
+\r
+               createTable(this);\r
+\r
+               // Makes sure that the UI is up-to-date now that\r
+               // ClientTableModel is in play.\r
+               sm.getClientInterface().flush();\r
+\r
+       }\r
+\r
+       public JTable createTable(Composite parent) {\r
+\r
+               SWTChassis c = new SWTChassis(parent, 0){\r
+\r
+                       @Override\r
+                       protected JComponent createSwingComponent() {\r
+                               return sm.createComponent(null);\r
+                       }\r
+               };\r
+               c.syncPopulate();\r
+\r
+               return null;\r
+\r
+       }\r
+\r
+}\r