1 package com.quantum.wizards;
3 import java.text.MessageFormat;
5 import org.eclipse.jface.preference.IPreferenceStore;
6 import org.eclipse.jface.wizard.WizardPage;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.dnd.TextTransfer;
9 import org.eclipse.swt.dnd.Transfer;
10 import org.eclipse.swt.events.ModifyEvent;
11 import org.eclipse.swt.events.ModifyListener;
12 import org.eclipse.swt.events.SelectionEvent;
13 import org.eclipse.swt.events.SelectionListener;
14 import org.eclipse.swt.layout.GridData;
15 import org.eclipse.swt.layout.GridLayout;
16 import org.eclipse.swt.widgets.Button;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Label;
19 import org.eclipse.swt.widgets.Text;
21 import com.quantum.QuantumPlugin;
22 import com.quantum.sql.TableRow;
23 //import com.quantum.view.PHPSourceConsole;
24 import com.quantum.view.tableview.TableAdapter;
26 public class PHPDeleteRowPage extends WizardPage implements SQLPage {
32 IPreferenceStore fStore;
33 private final static boolean DEBUG = false;
35 public PHPDeleteRowPage(String pageName) {
39 public void init(TableRow row, TableAdapter adapter) {
43 public void createControl(Composite parent) {
44 System.out.println("page create control");
45 fStore = QuantumPlugin.getDefault().getPreferenceStore();
46 Composite container = new Composite(parent, SWT.NULL);
47 GridLayout layout = new GridLayout();
48 container.setLayout(layout);
49 int layoutColumns = 3;
50 layout.numColumns = layoutColumns;
54 System.out.println("Row is null");
56 if (row.getColumnNames() == null) {
57 System.out.println("Columns are null");
59 if (row.getTableData() == null) {
60 System.out.println("Data is null");
63 columnNames = row.getColumnNames();
64 String[] data = row.getTableData();
66 for (int i = 0; i < row.getColumnCount(); i++) {
67 System.out.println("data = " + i + "=" + data[i]);
68 System.out.println("column = " + i + "=" + columnNames[i]);
71 values = new Text[row.getColumnCount()];
72 whereValues = new Button[row.getColumnCount()];
73 Label temp = new Label(container, SWT.NULL);
74 temp.setText("Column Name");
75 temp = new Label(container, SWT.NULL);
76 temp.setText("Value");
77 temp = new Label(container, SWT.NULL);
78 temp.setText("Include in?");
79 for (int i = 0; i < row.getColumnCount(); i++) {
80 Label label = new Label(container, SWT.NULL);
81 label.setText(columnNames[i]);
82 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
83 GridData fullHorizontal = new GridData();
84 fullHorizontal.horizontalAlignment = GridData.FILL;
85 values[i].setLayoutData(fullHorizontal);
87 if (data[i] == null || data[i].equals("")) {
88 values[i].setText('$' + columnNames[i]);
90 values[i].setText(data[i]);
93 values[i].addModifyListener(new ModifyListener() {
94 public void modifyText(ModifyEvent e) {
99 whereValues[i] = new Button(container, SWT.CHECK);
100 whereValues[i].setText("Where clause");
101 whereValues[i].addSelectionListener(new SelectionListener() {
102 public void widgetDefaultSelected(SelectionEvent e) {
104 public void widgetSelected(SelectionEvent e) {
109 query = new Label(container, SWT.WRAP);
110 GridData gridData = new GridData();
111 gridData.horizontalSpan = layoutColumns;
112 gridData.horizontalAlignment = GridData.FILL;
113 gridData.verticalAlignment = GridData.FILL;
114 gridData.grabExcessHorizontalSpace = true;
115 gridData.grabExcessVerticalSpace = true;
116 query.setLayoutData(gridData);
118 setControl(container);
121 setPageComplete(true);
123 public void updateQuery() {
125 System.out.println("Updating delete query");
127 StringBuffer whereClause = new StringBuffer();
129 boolean first = false;
130 for (int i = 0; i < columnNames.length; i++) {
131 if (whereValues[i].getSelection()) {
134 whereClause.append(", ");
137 whereClause.append(columnNames[i]);
138 whereClause.append(" = ");
139 whereClause.append("'" + values[i].getText() + "'");
144 // if (whereClause.length() > 1) {
145 // whereClause.deleteCharAt(whereClause.length() - 1);
146 // whereClause.deleteCharAt(whereClause.length() - 1);
149 String[] arguments = { row.getTable(), whereClause.toString()};
150 MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.delete.template"));
152 String query = form.format(arguments);
154 // String query = "$results = mysql_query(\"DELETE FROM " + row.getTable();
155 // if (numSelected > 0) {
156 // query += " WHERE " + whereClause.toString() + "\");";
161 if (numSelected > 0) {
164 setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted");
167 this.getControl().pack();
168 this.query.setText(query);
170 public boolean performFinish() {
171 // PHPSourceConsole console = PHPSourceConsole.getInstance();
173 // console.print(query.getText());
174 QuantumPlugin.getDefault().getSysClip().setContents(
175 new Object[] { query.getText() },
176 new Transfer[] { TextTransfer.getInstance()});