--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * 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.desktop.ui.internal;\r
+\r
+ import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.core.runtime.jobs.Job;\r
+import org.simantics.DatabaseJob;\r
+import org.simantics.Simantics;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.request.Configuration;\r
+import org.simantics.modeling.ModelingUtils;\r
+import org.simantics.platform.ui.PlatformUIResource;\r
+import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;\r
+import org.simantics.spreadsheet.util.SpreadsheetUtils;\r
+\r
+public class NewModel extends AbstractHandler {\r
+\r
+ public static Resource execute(WriteGraph graph) throws DatabaseException {\r
+ PlatformUIResource PLATFORM = PlatformUIResource.getInstance(graph);\r
+ return execute(graph, PLATFORM.Model, null);\r
+ }\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ Job job = new DatabaseJob("Creating Model") {\r
+ @Override\r
+ protected IStatus run(IProgressMonitor monitor) {\r
+ try {\r
+ Simantics.sync(new WriteRequest() {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ execute(graph);\r
+ }\r
+ });\r
+ return Status.OK_STATUS;\r
+ } catch (DatabaseException e) {\r
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e);\r
+ }\r
+ }\r
+ };\r
+ job.setUser(true);\r
+ job.schedule();\r
+ return null;\r
+ }\r
+\r
+ public static Resource execute(WriteGraph graph, Resource type, String name) throws DatabaseException {\r
+ Resource model = ModelingUtils.createModel(graph, type, name);\r
+ Resource conf = graph.syncRequest(new Configuration(model));\r
+\r
+ ModelingUtils.addSCLMainToModel(graph, model, "SCLMain", "");\r
+ ModelingUtils.createLocalLibrary(graph, model, "Library");\r
+\r
+ Resource book = SpreadsheetGraphUtils.createBook(graph, conf, "Book1");\r
+ SpreadsheetUtils.createSheet(graph, book, "Sheet1", new String[] { }, new int[] { 50 });\r
+ SpreadsheetUtils.createSheet(graph, book, "Sheet2", new String[] { }, new int[] { 50 });\r
+ SpreadsheetUtils.createSheet(graph, book, "Sheet3", new String[] { }, new int[] { 50 });\r
+\r
+ return model;\r
+ }\r
+\r
+}\r