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 PHPSelectRowPage extends WizardPage implements SQLPage {
32 IPreferenceStore fStore;
34 public PHPSelectRowPage(String pageName) {
38 public void init(TableRow row, TableAdapter adapter) {
42 public void createControl(Composite parent) {
43 System.out.println("page create control");
44 Composite container = new Composite(parent, SWT.NULL);
45 fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
47 GridLayout layout = new GridLayout();
48 container.setLayout(layout);
49 int layoutColumns = 4;
50 layout.numColumns = layoutColumns;
53 System.out.println("Row is null");
55 if (row.getColumnNames() == null) {
56 System.out.println("Columns are null");
58 if (row.getTableData() == null) {
59 System.out.println("Data is null");
61 columnNames = row.getColumnNames();
62 String[] data = row.getTableData();
64 for (int i = 0; i < row.getColumnCount(); i++) {
65 System.out.println("data = " + i + "=" + data[i]);
66 System.out.println("column = " + i + "=" + columnNames[i]);
69 whereValues = new Text[row.getColumnCount()];
70 // newValues = new Text[row.getColumnCount()];
71 primaryKeys = new Button[row.getColumnCount()];
72 setValues = 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("Where");
79 // temp = new Label(container, SWT.NULL);
80 // temp.setText("New Value");
81 temp = new Label(container, SWT.NULL);
82 temp.setText("Select");
83 for (int i = 0; i < row.getColumnCount(); i++) {
84 Label label = new Label(container, SWT.NULL);
85 label.setText(columnNames[i]);
86 whereValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
87 if (data[i] == null || data[i].equals("")) {
88 whereValues[i].setText('$' + columnNames[i]);
90 whereValues[i].setText(data[i]);
93 whereValues[i].addModifyListener(new ModifyListener() {
94 public void modifyText(ModifyEvent e) {
99 primaryKeys[i] = new Button(container, SWT.CHECK);
100 //primaryKeys[i].setText("Where Clause");
101 primaryKeys[i].addSelectionListener(new SelectionListener() {
102 public void widgetDefaultSelected(SelectionEvent e) {
104 public void widgetSelected(SelectionEvent e) {
108 // newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
109 // newValues[i].setText(data[i]);
110 // newValues[i].addModifyListener(new ModifyListener() {
111 // public void modifyText(ModifyEvent e) {
115 setValues[i] = new Button(container, SWT.CHECK);
116 //setValues[i].setText("Select Value");
117 setValues[i].addSelectionListener(new SelectionListener() {
118 public void widgetDefaultSelected(SelectionEvent e) {
120 public void widgetSelected(SelectionEvent e) {
125 query = new Label(container, SWT.WRAP);
126 GridData gridData = new GridData();
127 gridData.horizontalSpan = layoutColumns;
128 gridData.horizontalAlignment = GridData.FILL;
129 gridData.verticalAlignment = GridData.FILL;
130 gridData.grabExcessHorizontalSpace = true;
131 gridData.grabExcessVerticalSpace = true;
132 query.setLayoutData(gridData);
134 setControl(container);
137 setPageComplete(true);
140 public void updateQuery() {
141 System.out.println("PHP SELECT");
142 StringBuffer setClause = new StringBuffer();
143 StringBuffer whereClause = new StringBuffer();
145 boolean firstClause = false;
146 for (int i = 0; i < columnNames.length; i++) {
147 if (primaryKeys[i].getSelection()) {
149 whereClause.append(" AND ");
152 whereClause.append(columnNames[i]);
153 whereClause.append(" = ");
154 temp = whereValues[i].getText();
155 // if (temp.charAt(0) == '$') {
156 // whereClause.append(temp);
158 whereClause.append("'" + temp + "'");
162 if (setValues[i].getSelection()) {
163 setClause.append(columnNames[i]);
164 // setClause.append(" = ");
165 // setClause.append(newValues[i].getText());
166 setClause.append(", ");
169 // if (whereClause.length() > 1) {
170 // whereClause.deleteCharAt(whereClause.length() - 1);
171 // whereClause.deleteCharAt(whereClause.length() - 1);
173 if (setClause.length() > 1) {
174 setClause.deleteCharAt(setClause.length() - 1);
175 setClause.deleteCharAt(setClause.length() - 1);
179 { setClause.toString(), row.getTable(), whereClause.toString()};
182 fStore.getString("phpeclipse.sql.select.template"));
184 String query = form.format(arguments);
185 // String query = "$results = mysql_query(\"SELECT " + setClause.toString();
186 // query += " FROM " + row.getTable();
187 // query += " WHERE " + whereClause.toString() + "\");";
188 this.query.setText(query);
191 public boolean performFinish() {
192 PHPSourceConsole console = PHPSourceConsole.getInstance();
194 console.print(query.getText());