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