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.charts.ui;
14 import java.util.List;
16 import org.eclipse.core.commands.AbstractHandler;
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.swt.widgets.Shell;
21 import org.eclipse.ui.handlers.HandlerUtil;
22 import org.simantics.Simantics;
23 import org.simantics.charts.ontology.ChartResource;
24 import org.simantics.db.ReadGraph;
25 import org.simantics.db.Resource;
26 import org.simantics.db.Session;
27 import org.simantics.db.exception.DatabaseException;
28 import org.simantics.db.layer0.SelectionHints;
29 import org.simantics.db.request.Read;
30 import org.simantics.utils.ui.ISelectionUtils;
32 public class PropertiesHandler extends AbstractHandler {
35 public Object execute(ExecutionEvent event) throws ExecutionException {
36 ISelection selection = HandlerUtil.getCurrentSelection(event);
37 List<Resource> list = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
38 final Shell shell = HandlerUtil.getActiveShell(event);
39 Session session = Simantics.getSession();
40 for ( final Resource item : list ) {
41 session.asyncRequest(new Read<Object>() {
43 public Object perform(ReadGraph graph) throws DatabaseException {
44 ChartResource CHART = ChartResource.getInstance(graph);
45 if ( graph.isInstanceOf(item, CHART.Chart_Item) ) {
46 ChartDoubleClickHandler.openChartItemPropertiesDialog(graph, item, shell.getDisplay());
48 if ( graph.isInstanceOf(item, CHART.TimeSeriesChart) ) {
49 ChartDoubleClickHandler.openChartPropertiesDialog(graph, item, shell.getDisplay());