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