1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\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.modeling.ui.modelBrowser.handlers;
\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.jface.viewers.ISelection;
\r
18 import org.eclipse.ui.handlers.HandlerUtil;
\r
19 import org.simantics.db.Resource;
\r
20 import org.simantics.db.WriteGraph;
\r
21 import org.simantics.db.common.request.WriteRequest;
\r
22 import org.simantics.db.exception.DatabaseException;
\r
23 import org.simantics.db.layer0.SelectionHints;
\r
24 import org.simantics.db.layer0.adapter.InstanceFactory;
\r
25 import org.simantics.simulation.ontology.SimulationResource;
\r
26 import org.simantics.spreadsheet.resource.SpreadsheetResource;
\r
27 import org.simantics.ui.SimanticsUI;
\r
28 import org.simantics.utils.datastructures.ArrayMap;
\r
29 import org.simantics.utils.ui.ISelectionUtils;
\r
31 public class NewSpreadsheetHandler extends AbstractHandler {
\r
34 public Object execute(ExecutionEvent event) throws ExecutionException {
\r
35 ISelection selection = HandlerUtil.getCurrentSelection(event);
\r
36 final Resource container = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, Resource.class);
\r
37 if (container == null)
\r
40 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
\r
42 public void perform(WriteGraph graph) throws DatabaseException {
\r
43 SimulationResource SIMU = SimulationResource.getInstance(graph);
\r
44 SpreadsheetResource ssr = SpreadsheetResource.getInstance(graph);
\r
45 Resource configuration = graph.getPossibleObject(container, SIMU.HasConfiguration);
\r
46 if (configuration == null)
\r
48 InstanceFactory sheetFactory = graph.adapt(ssr.Spreadsheet, InstanceFactory.class);
\r
49 graph.syncRequest(sheetFactory.create(graph, ArrayMap.keys("composite").values(configuration), ssr.ForCompositeTemplate));
\r