2 * Created on 28-jul-2003
5 package com.quantum.view.tableview;
7 import com.quantum.ImageStore;
8 import com.quantum.Messages;
9 import com.quantum.QuantumPlugin;
11 import org.eclipse.jface.action.Action;
12 import org.eclipse.swt.dnd.TextTransfer;
13 import org.eclipse.swt.dnd.Transfer;
14 import org.eclipse.swt.widgets.Table;
15 import org.eclipse.swt.widgets.TableItem;
18 public final class CopyAction extends Action {
20 private static final String LINE_SEPARATOR = System.getProperty("line.separator");
22 private final TableView view;
24 public CopyAction(TableView view) {
27 setText(Messages.getString(getClass(), "text"));
28 setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.COPY));
32 Table table = getTable();
34 TableItem items[] = table.getSelection();
35 StringBuffer text = new StringBuffer();
36 for (int i = 0; i < items.length; i++) {
37 int columns = table.getColumnCount();
38 for (int col = 0; col < columns; col++) {
39 text.append(items[i].getText(col));
42 text.append(LINE_SEPARATOR);
44 QuantumPlugin.getDefault().getSysClip().setContents(
45 new Object[] { text.toString()},
46 new Transfer[] { TextTransfer.getInstance()});
50 private Table getTable() {
51 ResultSetViewer viewer = this.view.getSelectedResultSetViewer();
52 return viewer == null ? null : viewer.getTable();