]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/Spreadsheet.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.spreadsheet.ui / src / org / simantics / spreadsheet / ui / Spreadsheet.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.spreadsheet.ui;
13
14 import javax.swing.JComponent;
15 import javax.swing.JTable;
16 import javax.swing.UIManager;
17 import javax.swing.UnsupportedLookAndFeelException;
18
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.events.DisposeEvent;
21 import org.eclipse.swt.events.DisposeListener;
22 import org.eclipse.swt.layout.FillLayout;
23 import org.eclipse.swt.widgets.Composite;
24 import org.simantics.g2d.chassis.SWTChassis;
25 import org.simantics.spreadsheet.Adaptable;
26 import org.simantics.spreadsheet.ClientModel;
27 import org.simantics.utils.ui.jface.ActiveSelectionProvider;
28
29 public class Spreadsheet extends Composite {
30
31         public static boolean DEBUG = false;
32
33         final private SpreadsheetModel sm;
34
35         public SpreadsheetModel getModel() {
36                 return sm;
37         }
38
39         public Spreadsheet(Composite parent, int style, Adaptable serverInterface, ActiveSelectionProvider selectionProvider) {
40
41                 super(parent, style);
42
43                 sm = new SpreadsheetModel(serverInterface, selectionProvider);
44
45                 addDisposeListener(new DisposeListener() {
46                         @Override
47                         public void widgetDisposed(DisposeEvent e) {
48                         }
49                 });
50
51         }
52
53         public ClientModel getClientModel() {
54
55                 return sm.getClientModel();
56
57         }
58
59         public ClientModel getClientInterface() {
60
61                 return sm.getClientInterface();
62
63         }
64
65         public void defaultInitializeUI() {
66
67                 try {
68                         // Set System L&F
69                         UIManager.setLookAndFeel(
70                                         UIManager.getSystemLookAndFeelClassName());
71                 }
72                 catch (UnsupportedLookAndFeelException e) {
73                         // handle exception
74                 }
75                 catch (ClassNotFoundException e) {
76                         // handle exception
77                 }
78                 catch (InstantiationException e) {
79                         // handle exception
80                 }
81                 catch (IllegalAccessException e) {
82                         // handle exception
83                 }
84
85                 setLayout(new FillLayout(SWT.NONE));
86
87                 createTable(this);
88
89                 // Makes sure that the UI is up-to-date now that
90                 // ClientTableModel is in play.
91                 sm.getClientInterface().flush();
92
93         }
94
95         public JTable createTable(Composite parent) {
96
97                 SWTChassis c = new SWTChassis(parent, 0){
98
99                         @Override
100                         protected JComponent createSwingComponent() {
101                                 return sm.createComponent(null);
102                         }
103                 };
104                 c.syncPopulate();
105
106                 return null;
107
108         }
109
110 }