Fixed: 1775382 - Cannot change value in Expressions View
[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.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;
19
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;
24
25
26 public class CustomCopyAction extends SelectionListenerAction {
27         private final int ind;
28         public CustomCopyAction( int ind ) {
29         super(Messages.getString(CustomCopyAction.class.getName() + ".text"));
30                 this.ind = ind;
31         }
32         public void run() {
33                 String copyText = "";
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;
41                                 if (column != null) {
42                                         converter.add(column.getColumn().getName(), 
43                         column.getColumn().getParentEntity().getQualifiedName(), 0);
44                                 }
45                         } else if (current instanceof EntityHolder) {
46                 EntityHolder currentSelec = (EntityHolder) current;
47                                 converter.add(currentSelec.getEntity().getQualifiedName(), null, 1);
48                                 try {
49                                         Column[] columns = currentSelec.getEntity().getColumns();
50                                         for (int i = 0, length = (columns == null) ? 0 : columns.length;
51                             i < length;
52                             i++) {
53                                                 converter.add(columns[i].getName(), 
54                                 currentSelec.getEntity().getQualifiedName(), 0);
55                                         }                                       
56                                 } catch (NotConnectedException e) {
57                                 } catch (SQLException e) {
58                                 }
59                         }
60                 }
61                 IPreferenceStore store = QuantumPlugin.getDefault().getPreferenceStore();
62         
63                 
64                 converter.convert(Integer.toString(ind));
65                 
66                 String template = QuantumUtil.trasposeEscape(store.getString("customCopyTemplate" + Integer.toString(ind)));
67                 copyText = StringUtil.substituteString(template, "${table_list}", converter.getTableList());
68                 
69                 
70                 QuantumPlugin.getDefault().getSysClip().setContents(
71                         new Object[] { copyText },
72                         new Transfer[] { TextTransfer.getInstance()});
73         }
74
75 }