2 * Created on 11/08/2003
5 package com.quantum.actions;
7 import java.sql.SQLException;
8 import java.util.Iterator;
10 import com.quantum.Messages;
11 import com.quantum.QuantumPlugin;
12 import com.quantum.model.Column;
13 import com.quantum.model.EntityHolder;
14 import com.quantum.model.NotConnectedException;
15 import com.quantum.util.NthLevelConverter;
16 import com.quantum.util.QuantumUtil;
17 import com.quantum.util.StringUtil;
18 import com.quantum.view.bookmark.ColumnNode;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.swt.dnd.TextTransfer;
22 import org.eclipse.swt.dnd.Transfer;
23 import org.eclipse.ui.actions.SelectionListenerAction;
26 public class CustomCopyAction extends SelectionListenerAction {
27 private final int ind;
28 public CustomCopyAction( int ind ) {
29 super(Messages.getString(CustomCopyAction.class.getName() + ".text"));
34 Iterator iter = getSelectedNonResources().iterator();
35 NthLevelConverter converter = new NthLevelConverter();
36 // Fill up the converter. We iterate the selection items
37 while (iter.hasNext()) {
38 Object current = iter.next();
39 if (current instanceof ColumnNode) {
40 ColumnNode column = (ColumnNode) current;
42 converter.add(column.getColumn().getName(),
43 column.getColumn().getParentEntity().getQualifiedName(), 0);
45 } else if (current instanceof EntityHolder) {
46 EntityHolder currentSelec = (EntityHolder) current;
47 converter.add(currentSelec.getEntity().getQualifiedName(), null, 1);
49 Column[] columns = currentSelec.getEntity().getColumns();
50 for (int i = 0, length = (columns == null) ? 0 : columns.length;
53 converter.add(columns[i].getName(),
54 currentSelec.getEntity().getQualifiedName(), 0);
56 } catch (NotConnectedException e) {
57 } catch (SQLException e) {
61 IPreferenceStore store = QuantumPlugin.getDefault().getPreferenceStore();
64 converter.convert(Integer.toString(ind));
66 String template = QuantumUtil.trasposeEscape(store.getString("customCopyTemplate" + Integer.toString(ind)));
67 copyText = StringUtil.substituteString(template, "${table_list}", converter.getTableList());
70 QuantumPlugin.getDefault().getSysClip().setContents(
71 new Object[] { copyText },
72 new Transfer[] { TextTransfer.getInstance()});