X-Git-Url: http://git.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/SQLQueryView.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/SQLQueryView.java index 24ae30d..81a97d7 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/SQLQueryView.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/SQLQueryView.java @@ -4,15 +4,6 @@ import java.util.LinkedList; import java.util.NoSuchElementException; import java.util.Vector; -import net.sourceforge.phpdt.sql.IConstants; -import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin; -import net.sourceforge.phpdt.sql.actions.ExecuteAction; -import net.sourceforge.phpdt.sql.actions.ExportQueryAction; -import net.sourceforge.phpdt.sql.actions.ImportQueryAction; -import net.sourceforge.phpdt.sql.parser.SQLLexx; -import net.sourceforge.phpdt.sql.parser.Token; -import net.sourceforge.phpdt.sql.sql.MultiSQLServer; - import org.eclipse.jface.action.Action; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ExtendedModifyEvent; @@ -35,10 +26,23 @@ import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.part.ViewPart; +import net.sourceforge.phpdt.sql.IConstants; +import net.sourceforge.phpdt.sql.Messages; +import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin; +import net.sourceforge.phpdt.sql.actions.ExecuteAction; +import net.sourceforge.phpdt.sql.actions.ExportQueryAction; +import net.sourceforge.phpdt.sql.actions.GeneratePHPAction; +import net.sourceforge.phpdt.sql.actions.ImportQueryAction; +import net.sourceforge.phpdt.sql.sql.MultiSQLServer; +import net.sourceforge.phpdt.sql.sql.parser.SQLLexx; +import net.sourceforge.phpdt.sql.sql.parser.Token; +import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode; + public class SQLQueryView extends ViewPart implements IConstants { - private ExecuteAction executeAction; - private ImportQueryAction importQueryAction; - private ExportQueryAction exportQueryAction; + ExecuteAction executeAction; + ImportQueryAction importQueryAction; + ExportQueryAction exportQueryAction; + GeneratePHPAction generatePHPAction; private Clipboard clip; private Label statusImage; private Label status; @@ -109,13 +113,23 @@ public class SQLQueryView extends ViewPart implements IConstants { } }); item = new ToolItem(toolbar, SWT.PUSH); + item.setImage(PHPEclipseSQLPlugin.getImage("php.gif")); //$NON-NLS-1$ + item.setToolTipText(Messages.getString("sqlqueryview.generatePHP")); //$NON-NLS-1$ + item.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + generatePHPAction.run(); + } + }); + item = new ToolItem(toolbar, SWT.PUSH); item.setImage(PHPEclipseSQLPlugin.getImage("clear.gif")); //$NON-NLS-1$ item.setToolTipText(Messages.getString("sqlqueryview.clear")); //$NON-NLS-1$ item.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { - setQuery(""); + setQuery(""); //$NON-NLS-1$ } }); @@ -124,12 +138,13 @@ public class SQLQueryView extends ViewPart implements IConstants { item = new ToolItem(toolbar, SWT.PUSH); final ToolItem commit = item; item.setImage(PHPEclipseSQLPlugin.getImage("commit.gif")); //$NON-NLS-1$ - item.setToolTipText("Commit"); + item.setToolTipText(Messages.getString("SQLQueryView.Commit")); //$NON-NLS-1$ item.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { - MultiSQLServer.getInstance().commit(); + BookmarkNode node = BookmarkView.getInstance().getCurrentBookmark(); + MultiSQLServer.getInstance().commit(node.getConnection()); } }); item.setEnabled(false); @@ -137,12 +152,13 @@ public class SQLQueryView extends ViewPart implements IConstants { item = new ToolItem(toolbar, SWT.PUSH); final ToolItem rollback = item; item.setImage(PHPEclipseSQLPlugin.getImage("rollback.gif")); //$NON-NLS-1$ - item.setToolTipText("RollBack"); + item.setToolTipText(Messages.getString("SQLQueryView.RollBack")); //$NON-NLS-1$ item.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { - MultiSQLServer.getInstance().rollback(); + BookmarkNode node = BookmarkView.getInstance().getCurrentBookmark(); + MultiSQLServer.getInstance().rollback(node.getConnection()); } }); item.setEnabled(false); @@ -150,12 +166,14 @@ public class SQLQueryView extends ViewPart implements IConstants { item = new ToolItem(toolbar, SWT.CHECK); final ToolItem autocommit = item; item.setImage(PHPEclipseSQLPlugin.getImage("autocommit.gif")); //$NON-NLS-1$ - item.setToolTipText("AutoCommit"); + item.setToolTipText(Messages.getString("SQLQueryView.AutoCommit")); //$NON-NLS-1$ item.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { - MultiSQLServer.getInstance().setAutoCommit(autocommit.getSelection()); + BookmarkNode node = BookmarkView.getInstance().getCurrentBookmark(); + + MultiSQLServer.getInstance().setAutoCommit(node.getConnection(), autocommit.getSelection()); if (autocommit.getSelection()) { commit.setEnabled(false); rollback.setEnabled(false); @@ -207,8 +225,8 @@ public class SQLQueryView extends ViewPart implements IConstants { progress = new ProgressBar(bottomStatus, SWT.HORIZONTAL); - status.setText(Messages.getString("sqlqueryview.done")); - statusImage.setImage(PHPEclipseSQLPlugin.getImage("success.gif")); + status.setText(Messages.getString("sqlqueryview.done")); //$NON-NLS-1$ + statusImage.setImage(PHPEclipseSQLPlugin.getImage("success.gif")); //$NON-NLS-1$ progress.setMinimum(0); } @@ -224,6 +242,8 @@ public class SQLQueryView extends ViewPart implements IConstants { importQueryAction.init(this); exportQueryAction = new ExportQueryAction(); exportQueryAction.init(this); + generatePHPAction = new GeneratePHPAction(); + generatePHPAction.init(this); } public void setStatus(String text) { @@ -244,10 +264,10 @@ public class SQLQueryView extends ViewPart implements IConstants { widget.setText(text); } - private String[] keywords = {"SELECT", "DROP", "FROM", - "INSERT", "INTO", "VALUES", - "CREATE", "TABLE", "VIEW", "SEQUENCE", - "UPDATE", "SET", "WHERE"}; + private String[] keywords = {"SELECT", "DROP", "FROM", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + "INSERT", "INTO", "VALUES", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + "CREATE", "TABLE", "VIEW", "SEQUENCE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + "UPDATE", "SET", "WHERE"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ SyntaxHighlighter textUpdater = new SyntaxHighlighter(); @@ -315,7 +335,7 @@ public class SQLQueryView extends ViewPart implements IConstants { if (upper || lower || both) { min = Math.min(start, min); max = Math.max(max, start + length); - if (t.getType() == t.IDENTIFIER) { + if (t.getType() == Token.IDENTIFIER) { boolean keyword = false; for (int index = 0; index < keywords.length; index++) { if (value.equals(keywords[index])) { @@ -329,13 +349,13 @@ public class SQLQueryView extends ViewPart implements IConstants { styleRange.foreground = DEFAULT; } styles.addElement(styleRange); - } else if (t.getType() == t.COMMENT) { + } else if (t.getType() == Token.COMMENT) { styleRange.foreground = COMMENT; styles.addElement(styleRange); - } else if (t.getType() == t.LITERAL) { + } else if (t.getType() == Token.LITERAL) { styleRange.foreground = STRING_LITERAL; styles.addElement(styleRange); - } else if (t.getType() == t.NUMERIC) { + } else if (t.getType() == Token.NUMERIC) { styleRange.foreground = NUMERIC; styles.addElement(styleRange); } else { @@ -369,10 +389,8 @@ public class SQLQueryView extends ViewPart implements IConstants { widget.setStyleRange(styles[i]); } } catch (Throwable t) { - if (DEBUG) { - System.out.println("Error with styles: " + t.getClass().toString()); + System.out.println("Error with styles: " + t.getClass().toString()); //$NON-NLS-1$ // ignore any errors - } } } });