X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.desktop.ui%2Fsrc%2Forg%2Fsimantics%2Fdesktop%2Fui%2Finternal%2FNewModel.java;fp=bundles%2Forg.simantics.desktop.ui%2Fsrc%2Forg%2Fsimantics%2Fdesktop%2Fui%2Finternal%2FNewModel.java;h=ffa408e3cfaf2a7f9b561dbd34a6de8ad14edc69;hp=d6236ec7e38ec89bd0de5d7ef19d8c4293c734b9;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/NewModel.java b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/NewModel.java index d6236ec7e..ffa408e3c 100644 --- a/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/NewModel.java +++ b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/NewModel.java @@ -1,78 +1,78 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.desktop.ui.internal; - - import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.simantics.DatabaseJob; -import org.simantics.Simantics; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.request.Configuration; -import org.simantics.modeling.ModelingUtils; -import org.simantics.platform.ui.PlatformUIResource; -import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils; -import org.simantics.spreadsheet.util.SpreadsheetUtils; - -public class NewModel extends AbstractHandler { - - public static Resource execute(WriteGraph graph) throws DatabaseException { - PlatformUIResource PLATFORM = PlatformUIResource.getInstance(graph); - return execute(graph, PLATFORM.Model, null); - } - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - Job job = new DatabaseJob("Creating Model") { - @Override - protected IStatus run(IProgressMonitor monitor) { - try { - Simantics.sync(new WriteRequest() { - @Override - public void perform(WriteGraph graph) throws DatabaseException { - execute(graph); - } - }); - return Status.OK_STATUS; - } catch (DatabaseException e) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e); - } - } - }; - job.setUser(true); - job.schedule(); - return null; - } - - public static Resource execute(WriteGraph graph, Resource type, String name) throws DatabaseException { - Resource model = ModelingUtils.createModel(graph, type, name); - Resource conf = graph.syncRequest(new Configuration(model)); - - ModelingUtils.addSCLMainToModel(graph, model, "SCLMain", ""); - ModelingUtils.createLocalLibrary(graph, model, "Library"); - - Resource book = SpreadsheetGraphUtils.createBook(graph, conf, "Book1"); - SpreadsheetUtils.createSheet(graph, book, "Sheet1", new String[] { }, new int[] { 50 }); - SpreadsheetUtils.createSheet(graph, book, "Sheet2", new String[] { }, new int[] { 50 }); - SpreadsheetUtils.createSheet(graph, book, "Sheet3", new String[] { }, new int[] { 50 }); - - return model; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.desktop.ui.internal; + + import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.simantics.DatabaseJob; +import org.simantics.Simantics; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.Configuration; +import org.simantics.modeling.ModelingUtils; +import org.simantics.platform.ui.PlatformUIResource; +import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils; +import org.simantics.spreadsheet.util.SpreadsheetUtils; + +public class NewModel extends AbstractHandler { + + public static Resource execute(WriteGraph graph) throws DatabaseException { + PlatformUIResource PLATFORM = PlatformUIResource.getInstance(graph); + return execute(graph, PLATFORM.Model, null); + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + Job job = new DatabaseJob("Creating Model") { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + Simantics.sync(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + execute(graph); + } + }); + return Status.OK_STATUS; + } catch (DatabaseException e) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e); + } + } + }; + job.setUser(true); + job.schedule(); + return null; + } + + public static Resource execute(WriteGraph graph, Resource type, String name) throws DatabaseException { + Resource model = ModelingUtils.createModel(graph, type, name); + Resource conf = graph.syncRequest(new Configuration(model)); + + ModelingUtils.addSCLMainToModel(graph, model, "SCLMain", ""); + ModelingUtils.createLocalLibrary(graph, model, "Library"); + + Resource book = SpreadsheetGraphUtils.createBook(graph, conf, "Book1"); + SpreadsheetUtils.createSheet(graph, book, "Sheet1", new String[] { }, new int[] { 50 }); + SpreadsheetUtils.createSheet(graph, book, "Sheet2", new String[] { }, new int[] { 50 }); + SpreadsheetUtils.createSheet(graph, book, "Sheet3", new String[] { }, new int[] { 50 }); + + return model; + } + +}