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;
51 System.out.println("Row is null");
53 if (row.getColumnNames() == null) {
54 System.out.println("Columns are null");
56 if (row.getTableData() == null) {
57 System.out.println("Data is null");
60 columnNames = row.getColumnNames();
61 String[] data = row.getTableData();
63 for (int i = 0; i < row.getColumnCount(); i++) {
64 System.out.println("data = " + i + "=" + data[i]);
65 System.out.println("column = " + i + "=" + columnNames[i]);
68 values = new Text[row.getColumnCount()];
69 whereValues = new Button[row.getColumnCount()];
70 Label temp = new Label(container, SWT.NULL);
71 temp.setText("Column Name");
72 temp = new Label(container, SWT.NULL);
73 temp.setText("Value");
74 temp = new Label(container, SWT.NULL);
75 temp.setText("Include in?");
76 for (int i = 0; i < row.getColumnCount(); i++) {
77 Label label = new Label(container, SWT.NULL);
78 label.setText(columnNames[i]);
79 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
80 GridData fullHorizontal = new GridData();
81 fullHorizontal.horizontalAlignment = GridData.FILL;
82 values[i].setLayoutData(fullHorizontal);
84 if (data[i] == null || data[i].equals("")) {
85 values[i].setText('$' + columnNames[i]);
87 values[i].setText(data[i]);
90 values[i].addModifyListener(new ModifyListener() {
91 public void modifyText(ModifyEvent e) {
96 whereValues[i] = new Button(container, SWT.CHECK);
97 whereValues[i].setText("Where clause");
98 whereValues[i].addSelectionListener(new SelectionListener() {
99 public void widgetDefaultSelected(SelectionEvent e) {
101 public void widgetSelected(SelectionEvent e) {
106 query = new Label(container, SWT.WRAP);
107 GridData gridData = new GridData();
108 gridData.horizontalSpan = layoutColumns;
109 gridData.horizontalAlignment = GridData.FILL;
110 gridData.verticalAlignment = GridData.FILL;
111 gridData.grabExcessHorizontalSpace = true;
112 gridData.grabExcessVerticalSpace = true;
113 query.setLayoutData(gridData);
115 setControl(container);
118 setPageComplete(true);
120 public void updateQuery() {
122 System.out.println("Updating delete query");
124 StringBuffer whereClause = new StringBuffer();
126 boolean first = false;
127 for (int i = 0; i < columnNames.length; i++) {
128 if (whereValues[i].getSelection()) {
131 whereClause.append(", ");
134 whereClause.append(columnNames[i]);
135 whereClause.append(" = ");
136 whereClause.append("'" + values[i].getText() + "'");
141 // if (whereClause.length() > 1) {
142 // whereClause.deleteCharAt(whereClause.length() - 1);
143 // whereClause.deleteCharAt(whereClause.length() - 1);
146 String[] arguments = { row.getTable(), whereClause.toString()};
147 MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.delete.template"));
149 String query = form.format(arguments);
151 // String query = "$results = mysql_query(\"DELETE FROM " + row.getTable();
152 // if (numSelected > 0) {
153 // query += " WHERE " + whereClause.toString() + "\");";
158 if (numSelected > 0) {
161 setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted");
164 this.getControl().pack();
165 this.query.setText(query);
167 public boolean performFinish() {
168 PHPSourceConsole console = PHPSourceConsole.getInstance();
170 console.print(query.getText());