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) {
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);
80 values[i].setText(data[i]);
82 values[i].addModifyListener(new ModifyListener() {
83 public void modifyText(ModifyEvent e) {
88 whereValues[i] = new Button(container, SWT.CHECK);
89 whereValues[i].setText("Where clause");
90 whereValues[i].addSelectionListener(new SelectionListener() {
91 public void widgetDefaultSelected(SelectionEvent e) {
93 public void widgetSelected(SelectionEvent e) {
98 query = new Label(container, SWT.WRAP);
99 GridData gridData = new GridData();
100 gridData.horizontalSpan = layoutColumns;
101 gridData.horizontalAlignment = GridData.FILL;
102 gridData.verticalAlignment = GridData.FILL;
103 gridData.grabExcessHorizontalSpace = true;
104 gridData.grabExcessVerticalSpace = true;
105 query.setLayoutData(gridData);
107 setControl(container);
110 setPageComplete(true);
112 public void updateQuery() {
114 System.out.println("Updating query");
116 StringBuffer whereClause = new StringBuffer();
118 for (int i = 0; i < columnNames.length; i++) {
119 if (whereValues[i].getSelection()) {
121 whereClause.append(columnNames[i]);
122 whereClause.append(" = ");
123 whereClause.append(values[i].getText());
124 whereClause.append(", ");
127 if (whereClause.length() > 1) {
128 whereClause.deleteCharAt(whereClause.length() - 1);
129 whereClause.deleteCharAt(whereClause.length() - 1);
131 String query = "DELETE FROM " + row.getTable();
132 if (numSelected > 0) {
133 query += " WHERE " + whereClause.toString();
135 if (numSelected > 0) {
138 setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted");
140 this.getControl().pack();
141 this.query.setText(query);
143 public boolean performFinish() {
144 MultiSQLServer server = MultiSQLServer.getInstance();
145 server.execute(query.getText());