Package com.onpositive.gae.console

Source Code of com.onpositive.gae.console.ShowConsoleAction

package com.onpositive.gae.console;
import java.io.ByteArrayInputStream;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.FileEditorInput;

import com.onpositive.gae.tools.Constants;
import com.onpositive.gae.tools.GaeToolsViewerAction;
import com.onpositive.gae.tools.UIUtils;
import com.onpositive.gae.tools.deploy.CheckTools;
import com.onpositive.gae.tools.deploy.ConfigureTools;
import com.onpositive.gae.tools.deploy.PrepareGaeProject;
import com.onpositive.google.scrapbook.Activator;
import com.onpositive.google.scrapbook.ConsoleEditor;


public class ShowConsoleAction  extends GaeToolsViewerAction implements IWorkbenchWindowActionDelegate {

  public ShowConsoleAction(String text, boolean debug2) {
    super(text, debug2);
   
  }
 
  public ShowConsoleAction(){
    this("Open Java Console",true);
  }

  private IJavaProject fJavaProject;
 
  public void dispose() {
    // TODO Auto-generated method stub

  }

  public void init(IWorkbenchWindow window) {
    // TODO Auto-generated method stub

  }

  public static  void openConsole(IJavaProject fJavaProject2,boolean isDebug) {
    IFolder folder = fJavaProject2.getProject().getFolder(
        Constants.TOOLS_FILES_FOLDER);

    try {
      if (!folder.exists()) {
        folder.create(true, true, new NullProgressMonitor());
      }
      IFile file = folder.getFile("console.snippet");
      if (!file.exists()) {
        file.create(new ByteArrayInputStream(("import com.google.appengine.api.datastore.*;\r\n" +
            "import com.google.appengine.api.images.*;\r\n" +
            "import com.google.appengine.api.xmpp.*;\r\n" +
            "import com.google.appengine.api.mail.*;\r\n" +
            "import com.google.appengine.api.urlfetch.*;\r\n" +
            "import com.google.appengine.api.memcache.*;\r\n" +
            "import com.google.appengine.api.labs.taskqueue.*;\r\n" +
            "//Say Hello\r\n" +
            "out.print(\"Hello world\");").getBytes()),
            true, new NullProgressMonitor());
      }
      IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
          .getActivePage();
     
      ConsoleEditor openEditor = (ConsoleEditor) activePage.openEditor(new FileEditorInput(file),
              "com.onpositive.google.scrapbook.javaeditor");
    } catch (CoreException e) {
      Activator.getDefault().log(e);
      MessageDialog.openError(Display.getCurrent().getActiveShell(),
          "Error", e.getMessage());
    }
  }
 
  public void run(IAction action) {
    final IJavaProject javaGaeProject = UIUtils.getJavaGaeProject();
    if (javaGaeProject == null) {
      return;
    }
    fJavaProject = javaGaeProject;
    CheckTools check = new CheckTools("Check tools", fJavaProject,
        Activator.getDefault().getBundle());
    if (!check.doCheck()) {
      boolean openConfirm = MessageDialog
          .openConfirm(
              Display.getCurrent().getActiveShell(),
              "Project should be configured to add OnPositive Concole Support",
              "Do you want to configure project to add OnPositive Console Support now?");
      if (openConfirm) {
        PrepareGaeProject prepareGaeProject = new ConfigureTools(
            "Preparing Google Web Application Project",
            fJavaProject, Activator.getDefault().getBundle(),true);
        PlatformUI.getWorkbench().getProgressService().showInDialog(
            null, prepareGaeProject);
        prepareGaeProject.schedule();
        prepareGaeProject.addJobChangeListener(new JobChangeAdapter(){

         
          public void done(IJobChangeEvent event) {
            if (event.getResult().isOK()){
              Display.getDefault().asyncExec(new Runnable(){

               
                public void run() {
                  internalRun();
                }
               
              });
            }
            super.done(event);
          }
         
        });
      }
    } else {
      internalRun();
    }
  }

  public void selectionChanged(IAction action, ISelection selection) {
    // TODO Auto-generated method stub

  }
 
  private void internalRun() {
    IJavaProject fJavaProject2 = fJavaProject;
    openConsole(fJavaProject2,this.debug);

  }

 
  protected void openViewer(IJavaProject project, String url)
      throws PartInitException {
    // TODO Auto-generated method stub
   
  }


}
TOP

Related Classes of com.onpositive.gae.console.ShowConsoleAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.