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.eclipse.osgi.util.NLS;
22 import org.simantics.DatabaseJob;
23 import org.simantics.Simantics;
24 import org.simantics.db.Resource;
25 import org.simantics.db.WriteGraph;
26 import org.simantics.db.common.request.WriteRequest;
27 import org.simantics.db.exception.DatabaseException;
28 import org.simantics.db.layer0.request.Configuration;
29 import org.simantics.modeling.ModelingUtils;
30 import org.simantics.platform.ui.PlatformUIResource;
31 import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
32 import org.simantics.spreadsheet.util.SpreadsheetUtils;
34 public class NewModel extends AbstractHandler {
36 public static Resource execute(WriteGraph graph) throws DatabaseException {
37 PlatformUIResource PLATFORM = PlatformUIResource.getInstance(graph);
38 return execute(graph, PLATFORM.Model, null);
42 public Object execute(ExecutionEvent event) throws ExecutionException {
43 Job job = new DatabaseJob(Messages.NewModel_NewModel) {
45 protected IStatus run(IProgressMonitor monitor) {
47 Simantics.sync(new WriteRequest() {
49 public void perform(WriteGraph graph) throws DatabaseException {
53 return Status.OK_STATUS;
54 } catch (DatabaseException e) {
55 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(Messages.NewModel_0_Failed, getName()), e);
64 public static Resource execute(WriteGraph graph, Resource type, String name) throws DatabaseException {
65 Resource model = ModelingUtils.createModel(graph, type, name);
66 Resource conf = graph.syncRequest(new Configuration(model));
68 ModelingUtils.addSCLMainToModel(graph, model, "SCLMain", ""); //$NON-NLS-1$ //$NON-NLS-2$
69 ModelingUtils.createLocalLibrary(graph, model, Messages.NewModel_Library);
71 Resource book = SpreadsheetGraphUtils.createBook(graph, conf, Messages.NewModel_Book1);
72 SpreadsheetUtils.createSheet(graph, book, Messages.NewModel_Sheet1, new String[] { }, new int[] { 50 });
73 SpreadsheetUtils.createSheet(graph, book, Messages.NewModel_Sheet2, new String[] { }, new int[] { 50 });
74 SpreadsheetUtils.createSheet(graph, book, Messages.NewModel_Sheet3, new String[] { }, new int[] { 50 });