*** empty log message ***
authorchoochter <choochter>
Wed, 23 Jul 2003 11:55:14 +0000 (11:55 +0000)
committerchoochter <choochter>
Wed, 23 Jul 2003 11:55:14 +0000 (11:55 +0000)
archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/GeneratePHPAction.java [new file with mode: 0644]

diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/GeneratePHPAction.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/GeneratePHPAction.java
new file mode 100644 (file)
index 0000000..067c315
--- /dev/null
@@ -0,0 +1,103 @@
+package net.sourceforge.phpdt.sql.actions;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.utils.PHPStringThing;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.LogProxy;
+import net.sourceforge.phpdt.sql.view.SQLLogView;
+import net.sourceforge.phpdt.sql.view.SQLQueryView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+
+public class GeneratePHPAction extends Action implements IViewActionDelegate {
+       SQLQueryView view;
+       FileDialog dialog;
+       /**
+        * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+        */
+       public void init(IViewPart view) {
+               this.view = (SQLQueryView) view;
+               dialog = new FileDialog(view.getSite().getShell(), SWT.SAVE);
+               dialog.setFilterExtensions(new String[] { "*.php", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+               dialog.setFilterNames(new String[] { Messages.getString("filedialog.phpFiles"), //$NON-NLS-1$
+                       Messages.getString("filedialog.allfiles")}); //$NON-NLS-1$ //$NON-NLS-2$
+       }
+
+       /**
+        * @see org.eclipse.ui.IActionDelegate#run(IAction)
+        */
+       public void run(IAction action) {
+               run();
+       }
+
+       public void run() {
+//TODO
+/*             String filename = dialog.open();
+               if (filename != null) {
+                       try {
+                               /*Check for the presence of a "." - either indicates an
+                               * extension has been provided or that a filename with a '.'
+                               * has been specified - if the latter, it is assumed the user
+                               * knows what they're doing - could be dangerous! :-)
+                               */
+/*                             if (filename.indexOf(".") == -1)
+                                       filename += ".php";
+                               File exportFile = new File(filename);
+                               FileWriter fileWriter = new FileWriter(exportFile);
+                               PrintWriter writer = new PrintWriter(fileWriter);
+                               String query = view.getQuery();
+                               Vector phpStrings = PHPStringThing.toPHP(query);
+
+                               while (!phpStrings.isEmpty()) {
+                                       String buffer = (String) phpStrings.remove(0);
+                                       BookmarkNode current =
+                                               BookmarkView.getInstance().getCurrentBookmark();
+
+                                       buffer.replaceAll(
+                                               "%%CONNLIST%%",
+                                               current.getConnect()
+                                                       + ", "
+                                                       + current.getUsername()
+                                                       + ", "
+                                                       + current.getPassword());
+                                       buffer.replaceAll("%%DBNAME%%", current.getName());
+
+                                       /*Find the %%NL%% templates and substitute in the correct
+                                        * newline character for the platform - println does this
+                                        * automagically!
+                                        */
+/*                                     StringTokenizer tokenizer =
+                                               new StringTokenizer(buffer, "%%NL%%");
+                                       while (tokenizer.hasMoreElements()) {
+                                               String line = (String) tokenizer.nextElement();
+                                               writer.println(line);
+                                       }
+                               }
+                               writer.close();
+                       } catch (IOException e) {
+                               LogProxy.getInstance().addText(SQLLogView.ERROR, e.toString());
+                               e.printStackTrace();
+                       }
+               }
+*/     }
+
+       /**
+        * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+        */
+       public void selectionChanged(IAction action, ISelection selection) {
+       }
+}