1 package net.sourceforge.phpdt.sql.wizards;
3 import java.text.MessageFormat;
5 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
6 import net.sourceforge.phpdt.sql.sql.TableRow;
7 import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
8 import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
10 import org.eclipse.jface.preference.IPreferenceStore;
11 import org.eclipse.jface.wizard.WizardPage;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.events.ModifyEvent;
14 import org.eclipse.swt.events.ModifyListener;
15 import org.eclipse.swt.events.SelectionEvent;
16 import org.eclipse.swt.events.SelectionListener;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Text;
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) {
42 System.out.println("page create control");
44 fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
45 Composite container = new Composite(parent, SWT.NULL);
46 GridLayout layout = new GridLayout();
47 container.setLayout(layout);
48 int layoutColumns = 3;
49 layout.numColumns = layoutColumns;
53 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);
150 String[] arguments = { row.getTable(), whereClause.toString() };
151 MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.delete.template"));
153 String query = form.format(arguments);
155 // String query = "$results = mysql_query(\"DELETE FROM " + row.getTable();
156 // if (numSelected > 0) {
157 // query += " WHERE " + whereClause.toString() + "\");";
162 if (numSelected > 0) {
165 setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted");
168 this.getControl().pack();
169 this.query.setText(query);
171 public boolean performFinish() {
172 PHPSourceConsole console = PHPSourceConsole.getInstance();
174 console.print(query.getText());