]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.charts/src/org/simantics/charts/ui/PropertiesHandler.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / ui / PropertiesHandler.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.charts.ui;
13
14 import java.util.List;
15
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.charts.ontology.ChartResource;
23 import org.simantics.db.ReadGraph;
24 import org.simantics.db.Resource;
25 import org.simantics.db.Session;
26 import org.simantics.db.exception.DatabaseException;
27 import org.simantics.db.layer0.SelectionHints;
28 import org.simantics.db.request.Read;
29 import org.simantics.ui.SimanticsUI;
30 import org.simantics.utils.ui.ISelectionUtils;
31
32 public class PropertiesHandler extends AbstractHandler {
33
34         @Override
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 = SimanticsUI.getSession();
40         for ( final Resource item : list ) {            
41             session.asyncRequest(new Read<Object>() {
42                         @Override
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());
47                                 } else
48                                 if ( graph.isInstanceOf(item, CHART.TimeSeriesChart) ) {
49                                         ChartDoubleClickHandler.openChartPropertiesDialog(graph, item, shell.getDisplay());
50                                 } 
51                                 return null;
52                         }});
53         }
54                 return null;
55         }
56
57 }