added button to start tests.
[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.util.Iterator;
8
9 import com.quantum.QuantumPlugin;
10 import com.quantum.model.Column;
11 import com.quantum.model.EntityHolder;
12 import com.quantum.util.NthLevelConverter;
13 import com.quantum.util.QuantumUtil;
14 import com.quantum.util.StringUtil;
15 import com.quantum.view.bookmark.ColumnNode;
16
17 import org.eclipse.jface.preference.IPreferenceStore;
18 import org.eclipse.swt.dnd.TextTransfer;
19 import org.eclipse.swt.dnd.Transfer;
20 import org.eclipse.ui.IViewPart;
21 import org.eclipse.ui.actions.SelectionListenerAction;
22
23
24 public class CustomCopyAction extends SelectionListenerAction {
25         private final IViewPart view;
26         private final int ind;
27         /**
28          * @param BookmarkView
29          */
30         public CustomCopyAction(IViewPart view, int ind) {
31         super(null);
32                 this.view = view;
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().getCondQualifiedName(), 0);
47                                 }
48                         } else if (current instanceof EntityHolder) {
49                 EntityHolder currentSelec = (EntityHolder) current;
50                                 converter.add(currentSelec.getEntity().getCondQualifiedName(), null, 1);
51                                 Column[] columns = currentSelec.getEntity().getColumns();
52                                 for (int i = 0, length = (columns == null) ? 0 : columns.length;
53                     i < length;
54                     i++) {
55                                         converter.add(columns[i].getName(), 
56                         currentSelec.getEntity().getCondQualifiedName(), 0);
57                                 }                                       
58                         }
59                 }
60                 IPreferenceStore store = QuantumPlugin.getDefault().getPreferenceStore();
61         
62                 
63                 converter.convert(Integer.toString(ind));
64                 
65                 String template = QuantumUtil.trasposeEscape(store.getString("customCopyTemplate" + Integer.toString(ind)));
66                 copyText = StringUtil.substituteString(template, "${table_list}", converter.getTableList());
67                 
68                 
69                 QuantumPlugin.getDefault().getSysClip().setContents(
70                         new Object[] { copyText },
71                         new Transfer[] { TextTransfer.getInstance()});
72         }
73 }