3c0491bb0fc57bc509f4a53efd3eb46abdde4e53
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / CustomCopyAction.java
1 /*
2  * Created on 11/08/2003
3  *
4  */
5 package com.quantum.actions;
6
7 import java.sql.SQLException;
8 import java.util.Iterator;
9
10 import com.quantum.QuantumPlugin;
11 import com.quantum.model.Column;
12 import com.quantum.model.EntityHolder;
13 import com.quantum.model.NotConnectedException;
14 import com.quantum.util.NthLevelConverter;
15 import com.quantum.util.QuantumUtil;
16 import com.quantum.util.StringUtil;
17 import com.quantum.view.bookmark.ColumnNode;
18
19 import org.eclipse.jface.preference.IPreferenceStore;
20 import org.eclipse.swt.dnd.TextTransfer;
21 import org.eclipse.swt.dnd.Transfer;
22 import org.eclipse.ui.IViewPart;
23 import org.eclipse.ui.actions.SelectionListenerAction;
24
25
26 public class CustomCopyAction extends SelectionListenerAction {
27         private final int ind;
28         /**
29          * @param BookmarkView
30          */
31         public CustomCopyAction(IViewPart view, int ind) {
32         super(null);
33                 this.ind = ind;
34         }
35         public void run() {
36                 String copyText = "";
37                 Iterator iter = getSelectedNonResources().iterator();
38                 NthLevelConverter converter = new NthLevelConverter();
39                 // Fill up the converter. We iterate the selection items
40                 while (iter.hasNext()) {
41                         Object current = iter.next();
42                         if (current instanceof ColumnNode) {
43                                 ColumnNode column = (ColumnNode) current;
44                                 if (column != null) {
45                                         converter.add(column.getColumn().getName(), 
46                         column.getColumn().getParentEntity().getQualifiedName(), 0);
47                                 }
48                         } else if (current instanceof EntityHolder) {
49                 EntityHolder currentSelec = (EntityHolder) current;
50                                 converter.add(currentSelec.getEntity().getQualifiedName(), null, 1);
51                                 try {
52                                         Column[] columns = currentSelec.getEntity().getColumns();
53                                         for (int i = 0, length = (columns == null) ? 0 : columns.length;
54                             i < length;
55                             i++) {
56                                                 converter.add(columns[i].getName(), 
57                                 currentSelec.getEntity().getQualifiedName(), 0);
58                                         }                                       
59                                 } catch (NotConnectedException e) {
60                                 } catch (SQLException e) {
61                                 }
62                         }
63                 }
64                 IPreferenceStore store = QuantumPlugin.getDefault().getPreferenceStore();
65         
66                 
67                 converter.convert(Integer.toString(ind));
68                 
69                 String template = QuantumUtil.trasposeEscape(store.getString("customCopyTemplate" + Integer.toString(ind)));
70                 copyText = StringUtil.substituteString(template, "${table_list}", converter.getTableList());
71                 
72                 
73                 QuantumPlugin.getDefault().getSysClip().setContents(
74                         new Object[] { copyText },
75                         new Transfer[] { TextTransfer.getInstance()});
76         }
77 }