]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/DeleteHandler.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.spreadsheet.ui / src / org / simantics / spreadsheet / ui / DeleteHandler.java
1 package org.simantics.spreadsheet.ui;\r
2 /*******************************************************************************\r
3  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
4  * in Industry THTH ry.\r
5  * All rights reserved. This program and the accompanying materials\r
6  * are made available under the terms of the Eclipse Public License v1.0\r
7  * which accompanies this distribution, and is available at\r
8  * http://www.eclipse.org/legal/epl-v10.html\r
9  *\r
10  * Contributors:\r
11  *     VTT Technical Research Centre of Finland - initial API and implementation\r
12  *******************************************************************************/\r
13 import org.eclipse.core.commands.AbstractHandler;\r
14 import org.eclipse.core.commands.ExecutionEvent;\r
15 import org.eclipse.core.commands.ExecutionException;\r
16 import org.eclipse.core.runtime.IAdaptable;\r
17 import org.eclipse.ui.handlers.HandlerUtil;\r
18 import org.simantics.spreadsheet.CellEditor;\r
19 import org.simantics.spreadsheet.graph.GraphUI;\r
20 import org.simantics.spreadsheet.util.SpreadsheetUtils;\r
21 \r
22 \r
23 public class DeleteHandler extends AbstractHandler {\r
24 \r
25     @Override\r
26     public Object execute(ExecutionEvent event) throws ExecutionException {\r
27         \r
28         IAdaptable editor = (IAdaptable)HandlerUtil.getActiveEditor(event);\r
29         if(editor == null) return null;\r
30         \r
31         Spreadsheet sheet = (Spreadsheet)editor.getAdapter(Spreadsheet.class);\r
32         if(sheet == null) return null;\r
33         \r
34         int[] cols = sheet.getModel().getTable().getSelectedColumns();\r
35         int[] rows = sheet.getModel().getTable().getSelectedRows();\r
36         \r
37         GraphUI ui = (GraphUI)editor.getAdapter(GraphUI.class);\r
38         CellEditor ce = (CellEditor)ui.getAdapter(CellEditor.class);\r
39         \r
40         for(int row : rows) {\r
41                 for(int col : cols) {\r
42                         ce.edit(null, SpreadsheetUtils.cellName(row, col), null, null);\r
43                 }\r
44         }\r
45         \r
46         return null;\r
47         \r
48     }\r
49 \r
50 \r
51 }\r