]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
e579df6c53abc74bdea0a181daf5ec604017ee5c
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
3  * 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.sysdyn.ui.browser.actions.newActions;\r
13 \r
14 import org.simantics.db.Resource;\r
15 import org.simantics.db.WriteGraph;\r
16 import org.simantics.db.common.request.WriteRequest;\r
17 import org.simantics.db.exception.DatabaseException;\r
18 import org.simantics.db.layer0.adapter.ActionFactory;\r
19 import org.simantics.sysdyn.utils.SheetUtils;\r
20 import org.simantics.ui.SimanticsUI;\r
21 \r
22 /**\r
23  * Creates a new spreadsheet to a book\r
24  * @author Teemu Lempinen\r
25  *\r
26  */\r
27 public class NewSheetAction implements ActionFactory{\r
28 \r
29     @Override\r
30     public Runnable create(Object target) {\r
31         if(!(target instanceof Resource))\r
32             return null;\r
33         final Resource book = (Resource)target;\r
34 \r
35         return new Runnable() {\r
36             @Override\r
37             public void run() {\r
38 \r
39                 SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
40 \r
41                     @Override\r
42                     public void perform(WriteGraph graph) throws DatabaseException {\r
43                         SheetUtils.createSheet(graph, book, null, new String[] {}, new int[] {50});\r
44                     }\r
45                     \r
46                 });\r
47             }\r
48         };\r
49     }\r
50 \r
51 }\r