1 package net.sourceforge.phpdt.sql.wizards;
3 import net.sourceforge.phpdt.sql.sql.TableRow;
4 import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
5 import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
7 import org.eclipse.jface.wizard.WizardPage;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.events.ModifyEvent;
10 import org.eclipse.swt.events.ModifyListener;
11 import org.eclipse.swt.events.SelectionEvent;
12 import org.eclipse.swt.events.SelectionListener;
13 import org.eclipse.swt.layout.GridData;
14 import org.eclipse.swt.layout.GridLayout;
15 import org.eclipse.swt.widgets.Button;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Label;
18 import org.eclipse.swt.widgets.Text;
20 public class PHPDeleteRowPage extends WizardPage implements SQLPage {
27 public PHPDeleteRowPage(String pageName) {
31 public void init(TableRow row, TableAdapter adapter) {
35 public void createControl(Composite parent) {
37 System.out.println("page create control");
39 Composite container = new Composite(parent, SWT.NULL);
40 GridLayout layout = new GridLayout();
41 container.setLayout(layout);
42 int layoutColumns = 3;
43 layout.numColumns = layoutColumns;
47 System.out.println("Row is null");
50 if (row.getColumnNames() == null) {
51 System.out.println("Columns are null");
53 if (row.getTableData() == null) {
54 System.out.println("Data is null");
57 columnNames = row.getColumnNames();
58 String[] data = row.getTableData();
60 for (int i = 0; i < row.getColumnCount(); i++) {
61 System.out.println("data = " + i + "=" + data[i]);
62 System.out.println("column = " + i + "=" + columnNames[i]);
65 values = new Text[row.getColumnCount()];
66 whereValues = new Button[row.getColumnCount()];
67 Label temp = new Label(container, SWT.NULL);
68 temp.setText("Column Name");
69 temp = new Label(container, SWT.NULL);
70 temp.setText("Value");
71 temp = new Label(container, SWT.NULL);
72 temp.setText("Include in?");
73 for (int i = 0; i < row.getColumnCount(); i++) {
74 Label label = new Label(container, SWT.NULL);
75 label.setText(columnNames[i]);
76 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
77 GridData fullHorizontal = new GridData();
78 fullHorizontal.horizontalAlignment = GridData.FILL;
79 values[i].setLayoutData(fullHorizontal);
81 if (data[i] == null || data[i].equals("")) {
82 values[i].setText('$' + columnNames[i]);
84 values[i].setText(data[i]);
87 values[i].addModifyListener(new ModifyListener() {
88 public void modifyText(ModifyEvent e) {
93 whereValues[i] = new Button(container, SWT.CHECK);
94 whereValues[i].setText("Where clause");
95 whereValues[i].addSelectionListener(new SelectionListener() {
96 public void widgetDefaultSelected(SelectionEvent e) {
98 public void widgetSelected(SelectionEvent e) {
103 query = new Label(container, SWT.WRAP);
104 GridData gridData = new GridData();
105 gridData.horizontalSpan = layoutColumns;
106 gridData.horizontalAlignment = GridData.FILL;
107 gridData.verticalAlignment = GridData.FILL;
108 gridData.grabExcessHorizontalSpace = true;
109 gridData.grabExcessVerticalSpace = true;
110 query.setLayoutData(gridData);
112 setControl(container);
115 setPageComplete(true);
117 public void updateQuery() {
119 System.out.println("Updating delete query");
121 StringBuffer whereClause = new StringBuffer();
123 boolean first = false;
124 for (int i = 0; i < columnNames.length; i++) {
125 if (whereValues[i].getSelection()) {
128 whereClause.append(", ");
131 whereClause.append(columnNames[i]);
132 whereClause.append(" = ");
133 whereClause.append("'" + values[i].getText() + "'");
138 // if (whereClause.length() > 1) {
139 // whereClause.deleteCharAt(whereClause.length() - 1);
140 // whereClause.deleteCharAt(whereClause.length() - 1);
142 String query = "$results = mysql_query(\"DELETE FROM " + row.getTable();
143 if (numSelected > 0) {
144 query += " WHERE " + whereClause.toString() + "\");";
149 if (numSelected > 0) {
152 setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted");
155 this.getControl().pack();
156 this.query.setText(query);
158 public boolean performFinish() {
159 PHPSourceConsole console = PHPSourceConsole.getInstance();
161 console.print(query.getText());