27fe9571f6d20b84c1de3d538a383cd810557a3b
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / view / CopyAction.java
1 /*
2  * Created on 28-jul-2003
3  *
4  */
5 package com.quantum.view;
6
7 import com.quantum.QuantumPlugin;
8 import com.quantum.view.tableview.TableView;
9
10 import org.eclipse.jface.action.Action;
11 import org.eclipse.swt.dnd.TextTransfer;
12 import org.eclipse.swt.dnd.Transfer;
13 import org.eclipse.swt.widgets.Table;
14 import org.eclipse.swt.widgets.TableItem;
15
16
17 public final class CopyAction extends Action {
18         private final TableView view;
19         private final Table table;
20         public CopyAction(TableView view, Table table) {
21                 super();
22                 this.view = view;
23                 this.table = table;
24         }
25         public void run() {
26                 TableItem items[] = table.getSelection();
27                 StringBuffer text = new StringBuffer();
28                 for (int i = 0; i < items.length; i++) {
29                         int columns = table.getColumnCount();
30                         for (int col = 0; col < columns; col++) {
31                                 text.append(items[i].getText(col));
32                                 text.append('\t');
33                         }
34                         text.append('\n');
35                 }
36                 QuantumPlugin.getDefault().getSysClip().setContents(
37                         new Object[] { text.toString()},
38                         new Transfer[] { TextTransfer.getInstance()});
39         }
40 }