1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.desktop.ui.internal;
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.core.runtime.Status;
20 import org.eclipse.core.runtime.jobs.Job;
21 import org.simantics.DatabaseJob;
22 import org.simantics.Simantics;
23 import org.simantics.db.Resource;
24 import org.simantics.db.WriteGraph;
25 import org.simantics.db.common.request.WriteRequest;
26 import org.simantics.db.exception.DatabaseException;
27 import org.simantics.db.layer0.request.Configuration;
28 import org.simantics.modeling.ModelingUtils;
29 import org.simantics.platform.ui.PlatformUIResource;
30 import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
31 import org.simantics.spreadsheet.util.SpreadsheetUtils;
33 public class NewModel extends AbstractHandler {
35 public static Resource execute(WriteGraph graph) throws DatabaseException {
36 PlatformUIResource PLATFORM = PlatformUIResource.getInstance(graph);
37 return execute(graph, PLATFORM.Model, null);
41 public Object execute(ExecutionEvent event) throws ExecutionException {
42 Job job = new DatabaseJob("Creating Model") {
44 protected IStatus run(IProgressMonitor monitor) {
46 Simantics.sync(new WriteRequest() {
48 public void perform(WriteGraph graph) throws DatabaseException {
52 return Status.OK_STATUS;
53 } catch (DatabaseException e) {
54 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e);
63 public static Resource execute(WriteGraph graph, Resource type, String name) throws DatabaseException {
64 Resource model = ModelingUtils.createModel(graph, type, name);
65 Resource conf = graph.syncRequest(new Configuration(model));
67 ModelingUtils.addSCLMainToModel(graph, model, "SCLMain", "");
68 ModelingUtils.createLocalLibrary(graph, model, "Library");
70 Resource book = SpreadsheetGraphUtils.createBook(graph, conf, "Book1");
71 SpreadsheetUtils.createSheet(graph, book, "Sheet1", new String[] { }, new int[] { 50 });
72 SpreadsheetUtils.createSheet(graph, book, "Sheet2", new String[] { }, new int[] { 50 });
73 SpreadsheetUtils.createSheet(graph, book, "Sheet3", new String[] { }, new int[] { 50 });