1 package net.sourceforge.phpdt.sql.wizards;
3 import org.eclipse.jface.wizard.WizardPage;
4 import org.eclipse.swt.SWT;
5 import org.eclipse.swt.events.ModifyEvent;
6 import org.eclipse.swt.events.ModifyListener;
7 import org.eclipse.swt.events.SelectionEvent;
8 import org.eclipse.swt.events.SelectionListener;
9 import org.eclipse.swt.layout.GridData;
10 import org.eclipse.swt.layout.GridLayout;
11 import org.eclipse.swt.widgets.Button;
12 import org.eclipse.swt.widgets.Composite;
13 import org.eclipse.swt.widgets.Label;
14 import org.eclipse.swt.widgets.Text;
16 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
17 import net.sourceforge.phpdt.sql.sql.TableRow;
18 import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
20 public class DeleteRowPage extends WizardPage implements SQLPage {
27 public DeleteRowPage(String pageName) {
31 public void init(TableRow row, TableAdapter adapter) {
35 public void createControl(Composite parent) {
36 System.out.println("page create control");
37 Composite container = new Composite(parent, SWT.NULL);
38 GridLayout layout = new GridLayout();
39 container.setLayout(layout);
40 int layoutColumns = 3;
41 layout.numColumns = layoutColumns;
44 System.out.println("Row is null");
46 if (row.getColumnNames() == null) {
47 System.out.println("Columns are null");
49 if (row.getTableData() == null) {
50 System.out.println("Data is null");
52 columnNames = row.getColumnNames();
53 String[] data = row.getTableData();
54 for (int i = 0; i < row.getColumnCount(); i++) {
55 System.out.println("data = " + i + "=" + data[i]);
56 System.out.println("column = " + i + "=" + columnNames[i]);
58 values = new Text[row.getColumnCount()];
59 whereValues = new Button[row.getColumnCount()];
60 Label temp = new Label(container, SWT.NULL);
61 temp.setText("Column Name");
62 temp = new Label(container, SWT.NULL);
63 temp.setText("Value");
64 temp = new Label(container, SWT.NULL);
65 temp.setText("Include in?");
66 for (int i = 0; i < row.getColumnCount(); i++) {
67 Label label = new Label(container, SWT.NULL);
68 label.setText(columnNames[i]);
69 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
70 GridData fullHorizontal = new GridData();
71 fullHorizontal.horizontalAlignment = GridData.FILL;
72 values[i].setLayoutData(fullHorizontal);
73 values[i].setText(data[i]);
75 values[i].addModifyListener(new ModifyListener() {
76 public void modifyText(ModifyEvent e) {
81 whereValues[i] = new Button(container, SWT.CHECK);
82 whereValues[i].setText("Where clause");
83 whereValues[i].addSelectionListener(new SelectionListener() {
84 public void widgetDefaultSelected(SelectionEvent e) {
86 public void widgetSelected(SelectionEvent e) {
91 query = new Label(container, SWT.WRAP);
92 GridData gridData = new GridData();
93 gridData.horizontalSpan = layoutColumns;
94 gridData.horizontalAlignment = GridData.FILL;
95 gridData.verticalAlignment = GridData.FILL;
96 gridData.grabExcessHorizontalSpace = true;
97 gridData.grabExcessVerticalSpace = true;
98 query.setLayoutData(gridData);
100 setControl(container);
103 setPageComplete(true);
105 public void updateQuery() {
106 System.out.println("Updating query");
107 StringBuffer whereClause = new StringBuffer();
109 for (int i = 0; i < columnNames.length; i++) {
110 if (whereValues[i].getSelection()) {
112 whereClause.append(columnNames[i]);
113 whereClause.append(" = ");
114 whereClause.append(values[i].getText());
115 whereClause.append(", ");
118 if (whereClause.length() > 1) {
119 whereClause.deleteCharAt(whereClause.length() - 1);
120 whereClause.deleteCharAt(whereClause.length() - 1);
122 String query = "DELETE FROM " + row.getTable();
123 if (numSelected > 0) {
124 query += " WHERE " + whereClause.toString();
126 if (numSelected > 0) {
129 setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted");
131 this.getControl().pack();
132 this.query.setText(query);
134 public boolean performFinish() {
135 MultiSQLServer server = MultiSQLServer.getInstance();
136 server.execute(query.getText());