1 package com.quantum.php.wizards;
3 import java.text.MessageFormat;
5 import org.eclipse.jface.preference.IPreferenceStore;
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.dnd.TextTransfer;
8 import org.eclipse.swt.dnd.Transfer;
9 import org.eclipse.swt.events.ModifyEvent;
10 import org.eclipse.swt.events.ModifyListener;
11 import org.eclipse.swt.layout.GridData;
12 import org.eclipse.swt.layout.GridLayout;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Label;
15 import org.eclipse.swt.widgets.Text;
17 import com.quantum.QuantumPlugin;
18 import com.quantum.adapters.DatabaseAdapter;
19 import com.quantum.model.Bookmark;
20 import com.quantum.model.Entity;
21 import com.quantum.php.PHPMessages;
22 import com.quantum.wizards.BaseSQLPage;
23 import com.quantum.wizards.SQLPage;
25 public class PHPInsertRowPage extends BaseSQLPage implements SQLPage {
30 private IPreferenceStore fStore;
32 public PHPInsertRowPage(String pageName) {
36 public void createControl(Composite parent) {
37 System.out.println("page create control"); //$NON-NLS-1$
38 fStore = QuantumPlugin.getDefault().getPreferenceStore();
39 Composite container = new Composite(parent, SWT.V_SCROLL);
40 GridLayout layout = new GridLayout();
41 container.setLayout(layout);
42 layout.numColumns = 2;
44 columnNames = this.results.getColumnNames();
45 values = new Text[columnNames.length];
46 new Label(container, SWT.NULL).setText(PHPMessages.getString("PHPInsertRowPage.ColumnName")); //$NON-NLS-1$
47 new Label(container, SWT.NULL).setText(PHPMessages.getString("PHPInsertRowPage.Value")); //$NON-NLS-1$
48 for (int i = 0; i < columnNames.length; i++) {
49 Label label = new Label(container, SWT.NULL);
50 label.setText(columnNames[i]);
51 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
52 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
53 gridData.widthHint = 150;
54 values[i].setLayoutData(gridData);
56 //values[i].setText(data[i]);
57 values[i].addModifyListener(new ModifyListener() {
58 public void modifyText(ModifyEvent e) {
63 query = new Label(container, SWT.WRAP);
64 GridData gridData = new GridData();
65 gridData.horizontalSpan = layout.numColumns;
66 gridData.horizontalAlignment = GridData.FILL;
67 gridData.verticalAlignment = GridData.FILL;
68 gridData.grabExcessHorizontalSpace = true;
69 gridData.grabExcessVerticalSpace = true;
70 query.setLayoutData(gridData);
72 setControl(container);
75 setPageComplete(true);
77 public void updateQuery() {
78 System.out.println("Updating query"); //$NON-NLS-1$
79 StringBuffer valuesClause = new StringBuffer();
80 StringBuffer namesClause = new StringBuffer();
81 Bookmark bookmark = this.results.getBookmark();
82 Entity entity = this.results.getEntity();
83 DatabaseAdapter adapter = bookmark.getAdapter();
86 for (int i = 0; i < columnNames.length; i++) {
87 String name = columnNames[i];
88 String value = values[i].getText();
89 if (value.length() > 0) {
91 valuesClause.append(", "); //$NON-NLS-1$
92 namesClause.append(", ");
94 appendColumn(valuesClause, entity, name, adapter, value);
95 namesClause.append(name);
100 // String query = "INSERT INTO " + this.results.getEntity().getQuotedTableName(); //$NON-NLS-1$
101 // if (numColumns > 0) {
102 // query += " (" + namesClause + ")";
103 // query += " VALUES " + "(" + valuesClause; //$NON-NLS-1$
104 // query += " )"; //$NON-NLS-1$
106 String[] arguments = { this.results.getEntity().getQuotedTableName(), namesClause.toString(), valuesClause.toString()};
107 MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.insert.template"));
109 String query = form.format(arguments);
111 // String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " (";
112 // query += fieldClause.toString() + ") ";
113 // query += " VALUES (" + valuesClause.toString();
115 this.query.setText(query);
118 * @see com.quantum.wizards.BaseSQLPage#getQueryText()
120 protected String getQueryText() {
121 return this.query.getText();
124 * @see com.quantum.wizards.SQLPage#performFinish()
126 public boolean performFinish() {
127 QuantumPlugin.getDefault().getSysClip().setContents(
128 new Object[] { query.getText() },
129 new Transfer[] { TextTransfer.getInstance()});
134 //package com.quantum.php.wizards;
136 //import java.text.MessageFormat;
138 //import org.eclipse.jface.preference.IPreferenceStore;
139 //import org.eclipse.jface.wizard.WizardPage;
140 //import org.eclipse.swt.SWT;
141 //import org.eclipse.swt.dnd.TextTransfer;
142 //import org.eclipse.swt.dnd.Transfer;
143 //import org.eclipse.swt.events.ModifyEvent;
144 //import org.eclipse.swt.events.ModifyListener;
145 //import org.eclipse.swt.layout.GridData;
146 //import org.eclipse.swt.layout.GridLayout;
147 //import org.eclipse.swt.widgets.Composite;
148 //import org.eclipse.swt.widgets.Label;
149 //import org.eclipse.swt.widgets.Text;
151 //import com.quantum.QuantumPlugin;
152 //import com.quantum.sql.TableRow;
153 //import com.quantum.wizards.BaseSQLPage;
154 //import com.quantum.wizards.SQLPage;
155 ////import com.quantum.view.PHPSourceConsole;
156 ////import com.quantum.view.tableview.TableAdapter;
158 //public class PHPInsertRowPage extends BaseSQLPage implements SQLPage {
160 // String[] columnNames;
163 // private final static boolean DEBUG = false;
164 // private IPreferenceStore fStore;
166 // public PHPInsertRowPage(String pageName) {
170 //// public void init(TableRow row, TableAdapter adapter) {
174 // public void createControl(Composite parent) {
176 // System.out.println("page create control");
178 // fStore = QuantumPlugin.getDefault().getPreferenceStore();
179 // Composite container = new Composite(parent, SWT.NULL);
180 // GridLayout layout = new GridLayout();
181 // container.setLayout(layout);
182 // int layoutColumns = 2;
183 // layout.numColumns = layoutColumns;
186 // if (row == null) {
187 // System.out.println("Row is null");
189 // if (row.getColumnNames() == null) {
190 // System.out.println("Columns are null");
192 // if (row.getTableData() == null) {
193 // System.out.println("Data is null");
197 // columnNames = row.getColumnNames();
198 // String[] data = row.getTableData();
200 // for (int i = 0; i < row.getColumnCount(); i++) {
201 // System.out.println("data = " + i + "=" + data[i]);
202 // System.out.println("column = " + i + "=" + columnNames[i]);
205 // values = new Text[row.getColumnCount()];
206 // Label temp = new Label(container, SWT.NULL);
207 // temp.setText("Column Name");
208 // temp = new Label(container, SWT.NULL);
209 // temp.setText("Value");
210 // for (int i = 0; i < row.getColumnCount(); i++) {
211 // Label label = new Label(container, SWT.NULL);
212 // label.setText(columnNames[i]);
213 // values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
214 // GridData fullHorizontal = new GridData();
215 // fullHorizontal.horizontalAlignment = GridData.FILL;
216 // values[i].setLayoutData(fullHorizontal);
218 // //values[i].setText(data[i]);
219 // values[i].addModifyListener(new ModifyListener() {
220 // public void modifyText(ModifyEvent e) {
225 // query = new Label(container, SWT.WRAP);
226 // GridData gridData = new GridData();
227 // gridData.horizontalSpan = layoutColumns;
228 // gridData.horizontalAlignment = GridData.FILL;
229 // gridData.verticalAlignment = GridData.FILL;
230 // gridData.grabExcessHorizontalSpace = true;
231 // gridData.grabExcessVerticalSpace = true;
232 // query.setLayoutData(gridData);
234 // setControl(container);
237 // setPageComplete(true);
239 // public void updateQuery() {
241 // System.out.println("Updating insert query");
243 // StringBuffer fieldClause = new StringBuffer();
245 // StringBuffer valuesClause = new StringBuffer();
247 // boolean first = false;
248 // for (int i = 0; i < columnNames.length; i++) {
249 // text = values[i].getText();
250 // if (!text.equals("")) {
252 // valuesClause.append(", ");
253 // fieldClause.append(", ");
255 // valuesClause.append("'" + values[i].getText() + "'");
256 // fieldClause.append(columnNames[i]);
260 // // if (valuesClause.length() > 1) {
261 // // valuesClause.deleteCharAt(valuesClause.length() - 1);
262 // // valuesClause.deleteCharAt(valuesClause.length() - 1);
264 // String[] arguments = { row.getTable(), fieldClause.toString(), valuesClause.toString()};
265 // MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.insert.template"));
267 // String query = form.format(arguments);
269 // // String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " (";
270 // // query += fieldClause.toString() + ") ";
271 // // query += " VALUES (" + valuesClause.toString();
272 // // query += ")\");";
273 // this.query.setText(query);
275 // public boolean performFinish() {
276 //// PHPSourceConsole console = PHPSourceConsole.getInstance();
277 //// console.clear();
278 //// console.print(query.getText());
279 // QuantumPlugin.getDefault().getSysClip().setContents(
280 // new Object[] { query.getText() },
281 // new Transfer[] { TextTransfer.getInstance()});
285 // * @see com.quantum.wizards.BaseSQLPage#getQueryText()
287 // protected String getQueryText() {
288 // return this.query.getText();