|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.s60tools.crashanalyser.ui.editors; |
|
19 |
|
20 import org.eclipse.swt.custom.TableCursor; |
|
21 import org.eclipse.swt.dnd.Clipboard; |
|
22 import org.eclipse.swt.dnd.TextTransfer; |
|
23 import org.eclipse.swt.dnd.Transfer; |
|
24 import org.eclipse.swt.events.KeyEvent; |
|
25 import org.eclipse.swt.events.KeyListener; |
|
26 import org.eclipse.swt.widgets.Display; |
|
27 import org.eclipse.swt.widgets.Table; |
|
28 import org.eclipse.swt.widgets.TableItem; |
|
29 |
|
30 public class TableKeyListener implements KeyListener{ |
|
31 |
|
32 private static final int CTRL_C = 3; |
|
33 private Table table = null; |
|
34 private TableCursor cursor = null; |
|
35 |
|
36 /** |
|
37 * Create new TableKeyListener. |
|
38 * |
|
39 * @param table Table |
|
40 * @param cursor Cursor |
|
41 */ |
|
42 public TableKeyListener(Table table, TableCursor cursor) { |
|
43 this.table = table; |
|
44 this.cursor = cursor; |
|
45 } |
|
46 |
|
47 |
|
48 /* |
|
49 * (non-Javadoc) |
|
50 * |
|
51 * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent) |
|
52 */ |
|
53 public void keyPressed(KeyEvent e) { |
|
54 |
|
55 switch (e.character) { |
|
56 |
|
57 case CTRL_C: |
|
58 // Copy the cell content to clipboard |
|
59 |
|
60 try { |
|
61 Clipboard clipBoard = new Clipboard(Display.getCurrent()); |
|
62 TextTransfer textTransfer = TextTransfer.getInstance(); |
|
63 |
|
64 TableItem[] items = table.getSelection(); |
|
65 |
|
66 if (items == null || items.length == 0) { |
|
67 return; |
|
68 } |
|
69 |
|
70 int columnIndex = cursor.getColumn(); |
|
71 clipBoard.setContents(new Object[] { items[0].getText(columnIndex) }, new Transfer[] { textTransfer }); |
|
72 |
|
73 } catch (Exception ex) { |
|
74 // ignore |
|
75 } |
|
76 break; |
|
77 |
|
78 default: |
|
79 return; |
|
80 |
|
81 } |
|
82 } |
|
83 |
|
84 /* |
|
85 * (non-Javadoc) |
|
86 * |
|
87 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent) |
|
88 */ |
|
89 public void keyReleased(KeyEvent e) { |
|
90 // Do nothing. |
|
91 } |
|
92 |
|
93 } |