1 package net.sourceforge.phpdt.sql.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 net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
20 import net.sourceforge.phpdt.sql.sql.TableRow;
21 import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
22 import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
24 public class PHPDeleteRowPage extends WizardPage implements SQLPage {
30 IPreferenceStore fStore;
32 public PHPDeleteRowPage(String pageName) {
36 public void init(TableRow row, TableAdapter adapter) {
40 public void createControl(Composite parent) {
41 System.out.println("page create control");
42 fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
43 Composite container = new Composite(parent, SWT.NULL);
44 GridLayout layout = new GridLayout();
45 container.setLayout(layout);
46 int layoutColumns = 3;
47 layout.numColumns = layoutColumns;
50 System.out.println("Row is null");
52 if (row.getColumnNames() == null) {
53 System.out.println("Columns are null");
55 if (row.getTableData() == null) {
56 System.out.println("Data is null");
59 columnNames = row.getColumnNames();
60 String[] data = row.getTableData();
61 for (int i = 0; i < row.getColumnCount(); i++) {
62 System.out.println("data = " + i + "=" + data[i]);
63 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() {
118 System.out.println("Updating delete query");
119 StringBuffer whereClause = new StringBuffer();
121 boolean first = false;
122 for (int i = 0; i < columnNames.length; i++) {
123 if (whereValues[i].getSelection()) {
126 whereClause.append(", ");
129 whereClause.append(columnNames[i]);
130 whereClause.append(" = ");
131 whereClause.append("'" + values[i].getText() + "'");
136 // if (whereClause.length() > 1) {
137 // whereClause.deleteCharAt(whereClause.length() - 1);
138 // whereClause.deleteCharAt(whereClause.length() - 1);
141 String[] arguments = { row.getTable(), whereClause.toString()};
144 fStore.getString("phpeclipse.sql.delete.template"));
146 String query = form.format(arguments);
148 // String query = "$results = mysql_query(\"DELETE FROM " + row.getTable();
149 // if (numSelected > 0) {
150 // query += " WHERE " + whereClause.toString() + "\");";
155 if (numSelected > 0) {
158 setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted");
161 this.getControl().pack();
162 this.query.setText(query);
164 public boolean performFinish() {
165 PHPSourceConsole console = PHPSourceConsole.getInstance();
167 console.print(query.getText());