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 PHPUpdateRowPage extends WizardPage implements SQLPage {
28 public PHPUpdateRowPage(String pageName) {
32 public void init(TableRow row, TableAdapter adapter) {
36 public void createControl(Composite parent) {
38 System.out.println("page create control");
40 Composite container = new Composite(parent, SWT.NULL);
41 GridLayout layout = new GridLayout();
42 container.setLayout(layout);
43 int layoutColumns = 5;
44 layout.numColumns = layoutColumns;
48 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");
58 columnNames = row.getColumnNames();
59 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]);
66 oldValues = new Text[row.getColumnCount()];
67 newValues = new Text[row.getColumnCount()];
68 primaryKeys = new Button[row.getColumnCount()];
69 setValues = 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("Old Value");
74 temp = new Label(container, SWT.NULL);
76 temp = new Label(container, SWT.NULL);
77 temp.setText("New Value");
78 temp = new Label(container, SWT.NULL);
80 for (int i = 0; i < row.getColumnCount(); i++) {
81 Label label = new Label(container, SWT.NULL);
82 label.setText(columnNames[i]);
83 oldValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
84 oldValues[i].setText(data[i]);
85 oldValues[i].addModifyListener(new ModifyListener() {
86 public void modifyText(ModifyEvent e) {
90 primaryKeys[i] = new Button(container, SWT.CHECK);
91 primaryKeys[i].setText("Primary Key");
92 primaryKeys[i].addSelectionListener(new SelectionListener() {
93 public void widgetDefaultSelected(SelectionEvent e) {
95 public void widgetSelected(SelectionEvent e) {
99 newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
100 newValues[i].setText(data[i]);
101 newValues[i].addModifyListener(new ModifyListener() {
102 public void modifyText(ModifyEvent e) {
106 setValues[i] = new Button(container, SWT.CHECK);
107 setValues[i].setText("Set Value");
108 setValues[i].addSelectionListener(new SelectionListener() {
109 public void widgetDefaultSelected(SelectionEvent e) {
111 public void widgetSelected(SelectionEvent e) {
116 query = new Label(container, SWT.WRAP);
117 GridData gridData = new GridData();
118 gridData.horizontalSpan = layoutColumns;
119 gridData.horizontalAlignment = GridData.FILL;
120 gridData.verticalAlignment = GridData.FILL;
121 gridData.grabExcessHorizontalSpace = true;
122 gridData.grabExcessVerticalSpace = true;
123 query.setLayoutData(gridData);
125 setControl(container);
128 setPageComplete(true);
130 public void updateQuery() {
132 System.out.println("Updating query");
134 StringBuffer setClause = new StringBuffer();
135 StringBuffer whereClause = new StringBuffer();
136 for (int i = 0; i < columnNames.length; i++) {
137 if (primaryKeys[i].getSelection()) {
138 whereClause.append(columnNames[i]);
139 whereClause.append(" = ");
140 whereClause.append(oldValues[i].getText());
141 whereClause.append(", ");
143 if (setValues[i].getSelection()) {
144 setClause.append(columnNames[i]);
145 setClause.append(" = ");
146 setClause.append(newValues[i].getText());
147 setClause.append(", ");
150 if (whereClause.length() > 1) {
151 whereClause.deleteCharAt(whereClause.length() - 1);
152 whereClause.deleteCharAt(whereClause.length() - 1);
154 if (setClause.length() > 1) {
155 setClause.deleteCharAt(setClause.length() - 1);
156 setClause.deleteCharAt(setClause.length() - 1);
158 String query = "UPDATE " + row.getTable();
159 query += " SET " + setClause.toString();
160 query += " WHERE " + whereClause.toString();
161 this.query.setText(query);
163 public boolean performFinish() {
164 MultiSQLServer server = MultiSQLServer.getInstance();
165 server.execute(query.getText());