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