import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
public class PHPInsertRowPage extends WizardPage implements SQLPage {
- TableRow row;
- String[] columnNames;
- Text[] values;
- Label query;
- private IPreferenceStore fStore;
+ TableRow row;
+ String[] columnNames;
+ Text[] values;
+ Label query;
+ private IPreferenceStore fStore;
- public PHPInsertRowPage(String pageName) {
- super(pageName);
- }
+ public PHPInsertRowPage(String pageName) {
+ super(pageName);
+ }
- public void init(TableRow row, TableAdapter adapter) {
- this.row = row;
- }
+ public void init(TableRow row, TableAdapter adapter) {
+ this.row = row;
+ }
- public void createControl(Composite parent) {
- System.out.println("page create control");
- fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- int layoutColumns = 2;
- layout.numColumns = layoutColumns;
+ public void createControl(Composite parent) {
+ if (DEBUG) {
+ System.out.println("page create control");
+ }
+ fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ int layoutColumns = 2;
+ layout.numColumns = layoutColumns;
- if (row == null) {
- System.out.println("Row is null");
- }
- if (row.getColumnNames() == null) {
- System.out.println("Columns are null");
- }
- if (row.getTableData() == null) {
- System.out.println("Data is null");
- }
- columnNames = row.getColumnNames();
- String[] data = row.getTableData();
- for (int i = 0; i < row.getColumnCount(); i++) {
- System.out.println("data = " + i + "=" + data[i]);
- System.out.println("column = " + i + "=" + columnNames[i]);
- }
- values = new Text[row.getColumnCount()];
- Label temp = new Label(container, SWT.NULL);
- temp.setText("Column Name");
- temp = new Label(container, SWT.NULL);
- temp.setText("Value");
- for (int i = 0; i < row.getColumnCount(); i++) {
- Label label = new Label(container, SWT.NULL);
- label.setText(columnNames[i]);
- values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
- GridData fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- values[i].setLayoutData(fullHorizontal);
+ if (DEBUG) {
+ if (row == null) {
+ System.out.println("Row is null");
+ }
+ if (row.getColumnNames() == null) {
+ System.out.println("Columns are null");
+ }
+ if (row.getTableData() == null) {
+ System.out.println("Data is null");
+ }
+ }
- //values[i].setText(data[i]);
- values[i].addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- updateQuery();
- }
- });
- }
- query = new Label(container, SWT.WRAP);
- GridData gridData = new GridData();
- gridData.horizontalSpan = layoutColumns;
- gridData.horizontalAlignment = GridData.FILL;
- gridData.verticalAlignment = GridData.FILL;
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- query.setLayoutData(gridData);
+ columnNames = row.getColumnNames();
+ String[] data = row.getTableData();
+ if (DEBUG) {
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ System.out.println("data = " + i + "=" + data[i]);
+ System.out.println("column = " + i + "=" + columnNames[i]);
+ }
+ }
+ values = new Text[row.getColumnCount()];
+ Label temp = new Label(container, SWT.NULL);
+ temp.setText("Column Name");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("Value");
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ Label label = new Label(container, SWT.NULL);
+ label.setText(columnNames[i]);
+ values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
+ GridData fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ values[i].setLayoutData(fullHorizontal);
- setControl(container);
- updateQuery();
+ //values[i].setText(data[i]);
+ values[i].addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateQuery();
+ }
+ });
+ }
+ query = new Label(container, SWT.WRAP);
+ GridData gridData = new GridData();
+ gridData.horizontalSpan = layoutColumns;
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ query.setLayoutData(gridData);
- setPageComplete(true);
- }
- public void updateQuery() {
- System.out.println("Updating insert query");
- StringBuffer fieldClause = new StringBuffer();
+ setControl(container);
+ updateQuery();
- StringBuffer valuesClause = new StringBuffer();
- String text;
- boolean first = false;
- for (int i = 0; i < columnNames.length; i++) {
- text = values[i].getText();
- if (!text.equals("")) {
- if (first) {
- valuesClause.append(", ");
- fieldClause.append(", ");
- }
- valuesClause.append("'" + values[i].getText() + "'");
- fieldClause.append(columnNames[i]);
- first = true;
- }
- }
- // if (valuesClause.length() > 1) {
- // valuesClause.deleteCharAt(valuesClause.length() - 1);
- // valuesClause.deleteCharAt(valuesClause.length() - 1);
- // }
- String[] arguments =
- { row.getTable(), fieldClause.toString(), valuesClause.toString()};
- MessageFormat form =
- new MessageFormat(
- fStore.getString("phpeclipse.sql.insert.template"));
+ setPageComplete(true);
+ }
+ public void updateQuery() {
+ if (DEBUG) {
+ System.out.println("Updating insert query");
+ }
+ StringBuffer fieldClause = new StringBuffer();
- String query = form.format(arguments);
+ StringBuffer valuesClause = new StringBuffer();
+ String text;
+ boolean first = false;
+ for (int i = 0; i < columnNames.length; i++) {
+ text = values[i].getText();
+ if (!text.equals("")) {
+ if (first) {
+ valuesClause.append(", ");
+ fieldClause.append(", ");
+ }
+ valuesClause.append("'" + values[i].getText() + "'");
+ fieldClause.append(columnNames[i]);
+ first = true;
+ }
+ }
+ // if (valuesClause.length() > 1) {
+ // valuesClause.deleteCharAt(valuesClause.length() - 1);
+ // valuesClause.deleteCharAt(valuesClause.length() - 1);
+ // }
+ String[] arguments = { row.getTable(), fieldClause.toString(), valuesClause.toString()};
+ MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.insert.template"));
- // String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " (";
- // query += fieldClause.toString() + ") ";
- // query += " VALUES (" + valuesClause.toString();
- // query += ")\");";
- this.query.setText(query);
- }
- public boolean performFinish() {
- PHPSourceConsole console = PHPSourceConsole.getInstance();
- console.clear();
- console.print(query.getText());
- return true;
- }
+ String query = form.format(arguments);
+
+ // String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " (";
+ // query += fieldClause.toString() + ") ";
+ // query += " VALUES (" + valuesClause.toString();
+ // query += ")\");";
+ this.query.setText(query);
+ }
+ public boolean performFinish() {
+ PHPSourceConsole console = PHPSourceConsole.getInstance();
+ console.clear();
+ console.print(query.getText());
+ return true;
+ }
}
\ No newline at end of file