]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/impl/WidgetSupportFactory.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / widgets / impl / WidgetSupportFactory.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.browsing.ui.swt.widgets.impl;\r
13 \r
14 import java.util.concurrent.CopyOnWriteArrayList;\r
15 \r
16 import org.eclipse.jface.viewers.ISelection;\r
17 import org.eclipse.jface.viewers.StructuredSelection;\r
18 import org.simantics.Simantics;\r
19 import org.simantics.db.ReadGraph;\r
20 import org.simantics.db.Resource;\r
21 import org.simantics.db.management.ISessionContext;\r
22 \r
23 public class WidgetSupportFactory {\r
24 \r
25         public static WidgetSupport projectSupport() {\r
26                 \r
27                 return new WidgetSupport() {\r
28 \r
29                         final private CopyOnWriteArrayList<Widget> widgets = new CopyOnWriteArrayList<Widget>();\r
30 \r
31                         @Override\r
32                         public synchronized void register(Widget widget) {\r
33                                 widgets.add(widget);\r
34                         }\r
35                         \r
36                         @Override\r
37                         public void update(Widget widget) {\r
38                                 throw new Error("Not implemented.");\r
39                         }\r
40 \r
41                         @Override\r
42                         public void update() {\r
43                                 throw new Error("Not implemented.");\r
44                         }\r
45                         \r
46                         @Override\r
47                         public <T> T getInput() {\r
48                                 throw new Error("Not implemented.");\r
49                         }\r
50                         \r
51                         @Override\r
52                         public void finish() {\r
53                             Resource project = Simantics.peekProjectResource();\r
54                             if(project == null) return;\r
55                                 ISelection input = new StructuredSelection(project);\r
56                                 fireInput(Simantics.getSessionContext(), input);\r
57                         }\r
58                         \r
59                         public void fireInput(ISessionContext context, Object input) {\r
60                                 for(Widget widget : widgets) widget.setInput(context, input);\r
61                         }\r
62                         \r
63                         @Override\r
64                         public <T> T getParameter(String key) {\r
65                                 throw new Error("Not implemented.");\r
66                         }\r
67                         \r
68                         @Override\r
69                         public void setParameter(String key, Object value) {\r
70                                 throw new Error("Not implemented.");\r
71                         }\r
72 \r
73                         @Override\r
74                         public <T> T getInput(ReadGraph graph) {\r
75                                 throw new Error("Not implemented.");\r
76                         }\r
77                         \r
78                 };\r
79                 \r
80         }\r
81         \r
82 }\r