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.events.ModifyEvent;
9 import org.eclipse.swt.events.ModifyListener;
10 import org.eclipse.swt.events.SelectionEvent;
11 import org.eclipse.swt.events.SelectionListener;
12 import org.eclipse.swt.layout.GridData;
13 import org.eclipse.swt.layout.GridLayout;
14 import org.eclipse.swt.widgets.Button;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Label;
17 import org.eclipse.swt.widgets.Text;
19 import com.quantum.QuantumPlugin;
20 import com.quantum.sql.TableRow;
21 import com.quantum.view.PHPSourceConsole;
22 import com.quantum.view.tableview.TableAdapter;
24 public class PHPDeleteRowPage extends WizardPage implements SQLPage {
30 IPreferenceStore fStore;
31 private final static boolean DEBUG = false;
33 public PHPDeleteRowPage(String pageName) {
37 public void init(TableRow row, TableAdapter adapter) {
41 public void createControl(Composite parent) {
42 System.out.println("page create control");
43 fStore = QuantumPlugin.getDefault().getPreferenceStore();
44 Composite container = new Composite(parent, SWT.NULL);
45 GridLayout layout = new GridLayout();
46 container.setLayout(layout);
47 int layoutColumns = 3;
48 layout.numColumns = layoutColumns;
52 System.out.println("Row is null");
54 if (row.getColumnNames() == null) {
55 System.out.println("Columns are null");
57 if (row.getTableData() == null) {
58 System.out.println("Data is null");
61 columnNames = row.getColumnNames();
62 String[] data = row.getTableData();
64 for (int i = 0; i < row.getColumnCount(); i++) {
65 System.out.println("data = " + i + "=" + data[i]);
66 System.out.println("column = " + i + "=" + columnNames[i]);
69 values = new Text[row.getColumnCount()];
70 whereValues = new Button[row.getColumnCount()];
71 Label temp = new Label(container, SWT.NULL);
72 temp.setText("Column Name");
73 temp = new Label(container, SWT.NULL);
74 temp.setText("Value");
75 temp = new Label(container, SWT.NULL);
76 temp.setText("Include in?");
77 for (int i = 0; i < row.getColumnCount(); i++) {
78 Label label = new Label(container, SWT.NULL);
79 label.setText(columnNames[i]);
80 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
81 GridData fullHorizontal = new GridData();
82 fullHorizontal.horizontalAlignment = GridData.FILL;
83 values[i].setLayoutData(fullHorizontal);
85 if (data[i] == null || data[i].equals("")) {
86 values[i].setText('$' + columnNames[i]);
88 values[i].setText(data[i]);
91 values[i].addModifyListener(new ModifyListener() {
92 public void modifyText(ModifyEvent e) {
97 whereValues[i] = new Button(container, SWT.CHECK);
98 whereValues[i].setText("Where clause");
99 whereValues[i].addSelectionListener(new SelectionListener() {
100 public void widgetDefaultSelected(SelectionEvent e) {
102 public void widgetSelected(SelectionEvent e) {
107 query = new Label(container, SWT.WRAP);
108 GridData gridData = new GridData();
109 gridData.horizontalSpan = layoutColumns;
110 gridData.horizontalAlignment = GridData.FILL;
111 gridData.verticalAlignment = GridData.FILL;
112 gridData.grabExcessHorizontalSpace = true;
113 gridData.grabExcessVerticalSpace = true;
114 query.setLayoutData(gridData);
116 setControl(container);
119 setPageComplete(true);
121 public void updateQuery() {
123 System.out.println("Updating delete query");
125 StringBuffer whereClause = new StringBuffer();
127 boolean first = false;
128 for (int i = 0; i < columnNames.length; i++) {
129 if (whereValues[i].getSelection()) {
132 whereClause.append(", ");
135 whereClause.append(columnNames[i]);
136 whereClause.append(" = ");
137 whereClause.append("'" + values[i].getText() + "'");
142 // if (whereClause.length() > 1) {
143 // whereClause.deleteCharAt(whereClause.length() - 1);
144 // whereClause.deleteCharAt(whereClause.length() - 1);
147 String[] arguments = { row.getTable(), whereClause.toString()};
148 MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.delete.template"));
150 String query = form.format(arguments);
152 // String query = "$results = mysql_query(\"DELETE FROM " + row.getTable();
153 // if (numSelected > 0) {
154 // query += " WHERE " + whereClause.toString() + "\");";
159 if (numSelected > 0) {
162 setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted");
165 this.getControl().pack();
166 this.query.setText(query);
168 public boolean performFinish() {
169 PHPSourceConsole console = PHPSourceConsole.getInstance();
171 console.print(query.getText());