Package com.onpositive.gae.tools.deploy

Source Code of com.onpositive.gae.tools.deploy.BrowserViewer

package com.onpositive.gae.tools.deploy;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.EditorPart;

import com.onpositive.gae.tools.Activator;
import com.onpositive.gae.tools.IBrowserConfigurationPart;
import com.onpositive.gae.tools.core.CheckLaunchJob;

public class BrowserViewer extends EditorPart {

  private Browser browser;
  private Action forward;
  private Action back;
  private ArrayList<IBrowserConfigurationPart> parts = new ArrayList<IBrowserConfigurationPart>();

  public BrowserViewer() {
  }

 
  public void doSave(IProgressMonitor monitor) {

  }

 
  public void doSaveAs() {

  }

 
  public void init(IEditorSite site, IEditorInput input)
      throws PartInitException {
    super.setSite(site);
    super.setInput(input);
  }

  public void dispose() {
    for (IBrowserConfigurationPart p : parts) {
      p.dispose();
    }
    super.dispose();
  }

  public IJavaProject getProject() {
    return ((BroswserEditorInput) getEditorInput()).project;
  }

 
  public boolean isDirty() {
    return false;
  }

 
  public boolean isSaveAsAllowed() {
    return false;
  }

 
  public void createPartControl(Composite parent) {
    GridLayout layout = new GridLayout(1, false);
    layout.marginWidth = 0;
    layout.marginWidth = 0;
    parent.setLayout(layout);
    Composite toolComposite = new Composite(parent, SWT.NONE);
    toolComposite.setLayout(new GridLayout(4, false));
    // toolComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    IConfigurationElement[] configurationElementsFor = Platform
        .getExtensionRegistry()
        .getConfigurationElementsFor(
            "com.onpositive.gae.tools.core.browserConfigurationPart");
    for (IConfigurationElement e : configurationElementsFor) {
      try {
        IBrowserConfigurationPart ps = (IBrowserConfigurationPart) e
            .createExecutableExtension("class");
        parts.add(ps);
      } catch (CoreException e1) {
        Activator.log(e1);
      }
    }
    ToolBarManager man = new ToolBarManager();
    Action action = new Action() {
      public void run() {
        browser.back();
      }
    };
    back = action;
    toolComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true,
        false).create());
    action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
        .getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
    action.setText("Backward");
    man.add(action);
    action = new Action() {
      public void run() {
        browser.refresh();
      }
    };
    action.setImageDescriptor(Activator.imageDescriptorFromPlugin(
        Activator.PLUGIN_ID, "/icons/refresh.gif"));
    action.setText("Refresh");
    man.add(action);
    action = new Action() {
      public void run() {
        browser.forward();
      }
    };
    forward = action;
    action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
        .getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
    action.setText("Forward");
    man.add(action);
    man.createControl(toolComposite);
    Label l = new Label(toolComposite, SWT.NONE);
    l.setText("Url:");
    final Text ts = new Text(toolComposite, SWT.BORDER);
    ts.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
        .create());
    ToolBarManager tman = new ToolBarManager();
    Collections.sort(parts, new Comparator<IBrowserConfigurationPart>() {

      public int compare(IBrowserConfigurationPart o1,
          IBrowserConfigurationPart o2) {
        return o1.getPriority() - o2.getPriority();
      }
    });
    for (IBrowserConfigurationPart p : parts) {
      p.createPartControl(tman, this);
    }
    tman.createControl(toolComposite);
    browser = new Browser(parent, SWT.NONE);
    browser.setLayoutData(GridDataFactory.fillDefaults().grab(true, true)
        .create());
    BroswserEditorInput br = (BroswserEditorInput) getEditorInput();
    browser.setUrl(br.uri);
    ts.addSelectionListener(new SelectionListener() {

      public void widgetSelected(SelectionEvent e) {
        browser.setUrl(ts.getText());
      }

      public void widgetDefaultSelected(SelectionEvent e) {
        browser.setUrl(ts.getText());
      }
    });
    ts.setText(br.uri);
    browser.addLocationListener(new LocationListener() {

      public void changing(LocationEvent event) {

      }

      public void changed(LocationEvent event) {
        back.setEnabled(browser.isBackEnabled());
        forward.setEnabled(browser.isForwardEnabled());
        ts.setText(browser.getUrl());
      }
    });
  }

 
  public void setFocus() {

  }
}
TOP

Related Classes of com.onpositive.gae.tools.deploy.BrowserViewer

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.