Package de.innovationgate.eclipse.wgadesigner

Source Code of de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.wgadesigner;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.SynchronousBundleListener;
import org.osgi.util.tracker.ServiceTracker;

import de.innovationgate.eclipse.utils.BeanListPreferencesStore;
import de.innovationgate.eclipse.utils.BeanListStore;
import de.innovationgate.eclipse.utils.BeanMapPreferencesStore;
import de.innovationgate.eclipse.utils.DefaultHttpClient;
import de.innovationgate.eclipse.utils.InputStreamCanceledException;
import de.innovationgate.eclipse.utils.ProgressMonitorInputStream;
import de.innovationgate.eclipse.wgadesigner.classpath.DirectoryLibrarySet;
import de.innovationgate.eclipse.wgadesigner.classpath.LibraryClasspathEntryInformation;
import de.innovationgate.eclipse.wgadesigner.classpath.LibrarySet;
import de.innovationgate.eclipse.wgadesigner.editors.helpers.WGADeploymentManager;
import de.innovationgate.eclipse.wgadesigner.models.DesignTemplate;
import de.innovationgate.eclipse.wgadesigner.models.WGADistribution;
import de.innovationgate.eclipse.wgadesigner.models.WGARemoteServer;
import de.innovationgate.eclipse.wgadesigner.natures.WGADesign;
import de.innovationgate.eclipse.wgadesigner.natures.WGARuntime;
import de.innovationgate.eclipse.wgadesigner.preferences.PreferenceConstants;
import de.innovationgate.eclipse.wgadesigner.tomcat.TomcatUtils;
import de.innovationgate.utils.TemporaryFile;

/**
* The activator class controls the plug-in life cycle
*/
public class WGADesignerPlugin extends AbstractUIPlugin implements ResourceIDs, SynchronousBundleListener {   

  // The plug-in ID
  public static final String PLUGIN_ID = "de.innovationgate.eclipse.plugins.Core";
 
  public static final String JOB_FAMILY_WGA_DISTRIBUTION_DOWNLOAD = "JobFamilyWGADistributionDownload";
 
  private static final String SYSPROP_DEBUG = "de.innovationgate.eclipse.plugins.Core.debug";

  public static final String IMAGE_WGA_SERVER_START = "IMAGE_WGA_SERVER_START";
  public static final String IMAGE_WGA_SERVER_STOP = "IMAGE_WGA_SERVER_STOP";
  public static final String IMAGE_WGA_SERVER_RESTART = "IMAGE_WGA_SERVER_RESTART";
  public static final String IMAGE_INAKTIV_WGA_SERVER_START = "IMAGE_INAKTIV_WGA_SERVER_START";
  public static final String IMAGE_INAKTIV_WGA_SERVER_STOP = "IMAGE_INAKTIV_WGA_SERVER_STOP";

  public static final String IMAGE_WGA_RUNTIME = "IMAGE_WGA_RUNTIME";
  public static final String IMAGE_WGA_MULTIRUNTIME = "IMAGE_WGA_MULTIRUNTIME";
 
  public static final String IMAGE_WGA_RUNTIME_EDIT = "IMAGE_WGA_RUNTIME_EDIT";
  public static final String IMAGE_WGA_RUNTIME_ADD = "IMAGE_WGA_RUNTIME_ADD";
  public static final String IMAGE_REFRESH = "IMAGE_REFRESH";
 
  public static final String IMAGE_WGA_DESIGN = "IMAGE_WGA_DESIGN";
  public static final String IMAGE_WGA_DESIGN_LINK = "IMAGE_WGA_DESIGN_LINK";
  public static final String IMAGE_WGA_DESIGN_ADD = "IMAGE_WGA_DESIGN_ADD";
 
  public static final String IMAGE_WGA_PLUGIN = "IMAGE_WGA_PLUGIN";
  public static final String IMAGE_WGA_PLUGIN_LINK = "IMAGE_WGA_PLUGIN_LINK";
 
  public static final String IMAGE_WGA_DB = "IMAGE_WGA_DB";
  public static final String IMAGE_WGA_DB_DISABLED = "IMAGE_WGA_DB_DISABLED";
 
  public static final String IMAGE_EXPORT_WGA_DESIGN = "IMAGE_EXPORT_WGA_DESIGN";
  public static final String IMAGE_EXPORT_WGA_DESIGN_LOCAL = "IMAGE_EXPORT_WGA_DESIGN_LOCAL";
  public static final String IMAGE_EXPORT_WGA_DESIGN_REMOTE = "IMAGE_EXPORT_WGA_DESIGN_REMOTE";
 
  public static final String IMAGE_REMOTESERVER_REACHABLE= "IMAGE_REMOTESERVER_REACHABLE";
  public static final String IMAGE_REMOTESERVER_UNREACHABLE = "IMAGE_REMOTESERVER_UNREACHABLE";
 
  public static final String SYSPROP_WGA_DISTRIBUTION_DOWNLOAD = "de.innovationgate.eclipse.wgaDownloadURL";
  public static final String URL_WGA_DISTRIBUTION = "http://download.openwga.com/server/latest_" + de.innovationgate.eclipse.utils.Activator.SUPPORTED_WGA_VERSION_MAX.getMajor() + de.innovationgate.eclipse.utils.Activator.SUPPORTED_WGA_VERSION_MAX.getMinor() + ".war";
 
  public static final String DEFAULT_BROWSER_ID = WGADesignerPlugin.PLUGIN_ID + "browser.default";

 
  // The shared instance
  private static WGADesignerPlugin plugin;

  private WGADeploymentManager _wgaDeploymentManager;

  private BeanListPreferencesStore<WGADistribution> _wgaDistributionStore;

  private BeanListPreferencesStore<DesignTemplate> _desginTemplateStore;

  // store for additional library informations (source and javadoc attachments on wga library sets)
  private BeanMapPreferencesStore<IPath, LibraryClasspathEntryInformation> _libraryInformations;
 
  private ResourceManager _resourceManager;

  private File _wgaDefaultPluginsDir;

  private ServiceTracker _proxyServiceTracker;

  private BeanListStore<WGARemoteServer> _wgaRemoteServerStore;

  private Map<String, LibrarySet> _librarySets = new HashMap<String, LibrarySet>();

  // Storage keys
 
  private static final String STORAGE_KEY_WGA_REMOTESERVERS = "wgaRemoteServers";
 
  public static final String LIBRARY_SET_J2EE_1_4 = "j2ee14";
 
  public static final String LIBRARY_SET_J2EE_1_3 = "j2ee13";

  
  /**
   * The constructor
   *
   * @throws CoreException
   */
  public WGADesignerPlugin() throws CoreException {
  }

  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
   */
  public void start(BundleContext context) throws Exception {
    super.start(context);
   
    try {
      plugin = this;
     
      // #00000046 - try to init library sets as early as possible
      Bundle bundle = Platform.getBundle(PLUGIN_ID);      
      IPath path = new Path("resources/librarySets");
      URL librarySetURL = FileLocator.find(bundle, path, null);      
      File librarySetsDir = new File(FileLocator.toFileURL(librarySetURL).getPath());
 
      DirectoryLibrarySet j2ee13 = new DirectoryLibrarySet(LIBRARY_SET_J2EE_1_3);
      j2ee13.setName("Partial J2EE 1.3");
      j2ee13.setLocation(new File(librarySetsDir, "j2ee13"));
      _librarySets.put(j2ee13.getId(), j2ee13);
     
      DirectoryLibrarySet j2ee14 = new DirectoryLibrarySet(LIBRARY_SET_J2EE_1_4);
      j2ee14.setName("Partial J2EE 1.4");
      j2ee14.setLocation(new File(librarySetsDir, "j2ee14"));
      _librarySets.put(j2ee14.getId(), j2ee14);       
    } catch (Exception e) {
      logError("Unable to initialize plugin '" + PLUGIN_ID + "'.", e);
    }
   
    context.addBundleListener(this);
  }

  private void init() {
    try {
      _proxyServiceTracker = new ServiceTracker(getBundle().getBundleContext(), IProxyService.class.getName(), null);
      _proxyServiceTracker.open();

      setDebugging(Boolean.parseBoolean(System.getProperty(SYSPROP_DEBUG, "false")));
     
      // init resource manager
      _resourceManager = new ResourceManager();
      _resourceManager.init(getBundleFile(Platform.getBundle(PLUGIN_ID)), getStateLocation().toFile());
     
      // init BeanListStore for Remoteservers
      File settings = new File(getStateLocation().toFile(), "settings");
      if(!settings.exists()){
        settings.mkdir();
      }     
      _wgaRemoteServerStore = new BeanListStore<WGARemoteServer>(settings,STORAGE_KEY_WGA_REMOTESERVERS, WGARemoteServer.class.getClassLoader());

      Bundle bundle = Platform.getBundle(PLUGIN_ID);      
      Path path = new Path("resources/tomcat");
      URL tomcatURL = FileLocator.find(bundle, path, null);      
      File catalinaHome = new File(FileLocator.toFileURL(tomcatURL).getPath());
      TomcatUtils.getInstance().init(catalinaHome, new File(catalinaHome, "conf"));
     
      path = new Path("resources/wga/defaultPlugins");
      URL defaultPluginsURL = FileLocator.find(bundle, path, null);
      _wgaDefaultPluginsDir = new File (FileLocator.toFileURL(defaultPluginsURL).getPath());
     
      _wgaDeploymentManager = new WGADeploymentManager();     
      _wgaDeploymentManager.init(new File(getStateLocation().toFile(), "wgadeployments"));
     
      initWGADistributions();
    } catch (Exception e) {
      logError("Unable to initialize plugin '" + PLUGIN_ID + "'.", e);
    }
  }
 
  public String getWGADownloadURL() {
    return System.getProperty(SYSPROP_WGA_DISTRIBUTION_DOWNLOAD, URL_WGA_DISTRIBUTION);
  }

  public TemporaryFile downloadCurrentWGARelease(IProgressMonitor monitor) throws IllegalStateException, IOException, URISyntaxException {
      return downloadWGA(monitor, getWGADownloadURL());
  }
 
   public TemporaryFile downloadWGA(IProgressMonitor monitor, String url) throws IllegalStateException, IOException, URISyntaxException {
        monitor.setTaskName("Downloading OpenWGA from '" + url + "'");                    
        HttpClient client = new DefaultHttpClient((IProxyService)_proxyServiceTracker.getService(), new URI(url));
        GetMethod get = new GetMethod(url);
    int result = client.executeMethod(get);
    if (result == HttpURLConnection.HTTP_OK) {
      long size = get.getResponseContentLength();               
            TemporaryFile temp = new TemporaryFile("wga.war", new ProgressMonitorInputStream(monitor, "Downloading OpenWGA ", size, get.getResponseBodyAsStream()), getStateLocation().toFile());
      return temp;
    } else {
            throw new IOException("Download of OpenWGA failed. Server returned '" + result + "'.");
    }
   
  }
 
  public void initWGADistributions() {
    if (_wgaDeploymentManager.getDeployments().size() == 0) {
      final String fDownloadURL = getWGADownloadURL();
      Job createDefaultDeployment = new Job("Initializing WGA distributions") {
       
        @Override
        protected IStatus run(IProgressMonitor monitor) {
          try {     
            monitor.beginTask("Initializing WGA distributions", 100);             
            SubProgressMonitor downloadMonitor = new SubProgressMonitor(monitor, 90);             
            TemporaryFile temp = downloadCurrentWGARelease(downloadMonitor);
            SubProgressMonitor deployMonitor = new SubProgressMonitor(monitor, 10);
            getWGADeploymentManager().createOrUpdateDefaultDeployment(temp.getFile(), deployMonitor);
            temp.delete();
            return Status.OK_STATUS;
          } catch (InputStreamCanceledException e) {
            logWarning("WGA distribution download has been canceled by user.");
            return Status.CANCEL_STATUS;
          } catch (UnknownHostException e) {
            logError("Download of current OpenWGA release failed", e);
            return new Status(Status.ERROR, PLUGIN_ID, "Download of current OpenWGA release from '" + fDownloadURL + "' failed. Unknown host.");
          } catch (Exception e) {
            logError("Download of current WGA release failed.", e);
            return new Status(Status.ERROR, PLUGIN_ID, "Download of current OpenWGA release from '" + fDownloadURL + "' failed. See log for details.");         
          } finally {
            monitor.done();
          }
        }
 
        @Override
        public boolean belongsTo(Object family) {
          return JOB_FAMILY_WGA_DISTRIBUTION_DOWNLOAD.equals(family);
        }
       
       
      };       

      boolean startDownload = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Download current OpenWGA release", "You have currently no OpenWGA distribution installed in your workspace, which is necessary to use the OpenWGA Developer Studio. The latest release will be downloaded from '" + fDownloadURL + "' now.");
      if (startDownload) {
        createDefaultDeployment.setPriority(Job.LONG);
        createDefaultDeployment.setUser(true);
        createDefaultDeployment.schedule();
      }
    }
  }

  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
   */
  public void stop(BundleContext context) throws Exception {
    plugin = null;
    _proxyServiceTracker.close();
    super.stop(context);
  }

  /**
   * Returns the shared instance
   *
   * @return the shared instance
   */
  public static WGADesignerPlugin getDefault() {
    return plugin;
  }
 

  /*
   * public File getFileResource(String relativePath) throws IOException {
   * return _resourceManager.getResourceAsFile(relativePath); }
   */

  public InputStream getResourceAsStream(String relativePath) throws IOException {
    if (relativePath.startsWith("resources/")) {
      return FileLocator.toFileURL(FileLocator.find(Platform.getBundle(PLUGIN_ID), new Path(relativePath), null)).openStream();
    } else {
      return new FileInputStream(relativePath);
    }
  }

  public static Map<String, WGARuntime> getAllRuntimes() {

    Map<String, WGARuntime> allWGARuntimes = new HashMap<String, WGARuntime>();
    IProject tmp[] = null;
    tmp = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (int i = 0; i < tmp.length; i++) {
      try {
        if (tmp[i].isAccessible() && tmp[i].hasNature(NATURE_WGA_RUNTIME)) {
          allWGARuntimes.put(tmp[i].getName(), (WGARuntime) tmp[i].getNature(NATURE_WGA_RUNTIME));
        }
      } catch (CoreException e) {
        WGADesignerPlugin.getDefault().logWarning("Project " + tmp[i].getName() + " is not open", e);
      }
    }
    return allWGARuntimes;
 
 
    public static Map<String, WGARuntime> getAllRuntimes(ArrayList<IProject> projectsInWorkingSet) {
        Map<String, WGARuntime> allRuntimes= getAllRuntimes();
        Map<String, WGARuntime> allRuntimesInWorkingSets = new HashMap<String, WGARuntime>();
       
        if(projectsInWorkingSet !=null){
            for(IProject currentProject: projectsInWorkingSet){
                if(allRuntimes.containsKey(currentProject.getName())){
                    allRuntimesInWorkingSets.put(currentProject.getName(), allRuntimes.get(currentProject.getName()));
                }     
            }
        }       

       return allRuntimesInWorkingSets;
       
    }
 
 
  public static WGARuntime getRuntime(String name){
   
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
    try {
      if(project.isAccessible() && project.hasNature(NATURE_WGA_RUNTIME)){
        return (WGARuntime) project.getNature(NATURE_WGA_RUNTIME);
      }else {
        return null;
      }
    } catch (CoreException e) {
      return null;
    }
  }

  /**
   * retrieves all projects with NATURE_WGA_DESIGN in current workspace
   * @return
   */
  public static Map<String, WGADesign> getAllDesigns() {

    Map<String, WGADesign> allWGADesigns = new HashMap<String, WGADesign>();
    IProject tmp[] = null;
    tmp = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (int i = 0; i < tmp.length; i++) {
      try {
        if (tmp[i].hasNature(NATURE_WGA_DESIGN)) {
          allWGADesigns.put(tmp[i].getName(), (WGADesign) tmp[i].getNature(NATURE_WGA_DESIGN));
        }
      } catch (CoreException e) {
        WGADesignerPlugin.getDefault().logWarning("Project " + tmp[i].getName() + " is not open", e);
      }
    }
    return allWGADesigns;

  }
 
  /**
   * checks if workspace contains a wga design project (NATURE_WGA_DESIGN) of the given name
   * @param designName
   * @return
   */
  public static boolean hasWorkSpaceDesign(String designName) {
    if (designName == null || designName.equals(""))
      return false;

    Iterator<WGADesign> designsIter = getAllDesigns().values().iterator();
    while (designsIter.hasNext()) {
      if (designsIter.next().getName().equals(designName)) {
        return true;
      }
    }
    return false;
  }

  public void logError(String message, Throwable e) {
    if (e != null)
      getLog().log(new Status(Status.ERROR, PLUGIN_ID, message, e));
    else
      getLog().log(new Status(Status.ERROR, PLUGIN_ID, message));
  }

  public void logInfo(String message, Throwable e) {
    if (e != null)
      getLog().log(new Status(Status.INFO, PLUGIN_ID, message, e));
    else
      getLog().log(new Status(Status.INFO, PLUGIN_ID, message));
  }

  public void logWarning(String message, Throwable e) {
    if (e != null)
      getLog().log(new Status(Status.WARNING, PLUGIN_ID, message, e));
    else
      getLog().log(new Status(Status.WARNING, PLUGIN_ID, message));
  }

  public void logError(String message) {
    logError(message, null);
  }

  public void logInfo(String message) {
    logInfo(message, null);
  }

  public void logWarning(String message) {
    logWarning(message, null);
  }





  public WGADeploymentManager getWGADeploymentManager() {
    return _wgaDeploymentManager;
  }

  public BeanListPreferencesStore<WGADistribution> getWGADistributionStore() {
    if (_wgaDistributionStore == null) {
      _wgaDistributionStore = new BeanListPreferencesStore<WGADistribution>(getPreferenceStore(), PreferenceConstants.WGA_DISTRIBUTIONS, WGADistribution.class.getClassLoader());
    }
    return _wgaDistributionStore;
  }

  public BeanListPreferencesStore<DesignTemplate> getDesginTemplateStore() {
    if (_desginTemplateStore == null) {
      _desginTemplateStore = new BeanListPreferencesStore<DesignTemplate>(getPreferenceStore(), PreferenceConstants.DESIGN_TEMPLATES_CURRENT, DesignTemplate.class.getClassLoader());
    }
    return _desginTemplateStore;
  }
 
  public BeanMapPreferencesStore<IPath, LibraryClasspathEntryInformation> getLibraryClasspathEntryInformationStore() {
    if (_libraryInformations == null) {
      _libraryInformations = new BeanMapPreferencesStore<IPath, LibraryClasspathEntryInformation>(getPreferenceStore(), PreferenceConstants.LIBRARY_CLASSPATH_ENTRY_INFORMATIONS, LibraryClasspathEntryInformation.class.getClassLoader());
    }
    return _libraryInformations;
  }

  public File getWgaDefaultPluginsDir() {
    return _wgaDefaultPluginsDir;
  }

  /**
   * backport of {@link FileLocator.getBundleFile()} to be used in Eclipse 3.3
   *
   * @return
   * @throws IOException
   */
  private File getBundleFile(Bundle bundle) throws IOException {
    URL rootEntry = bundle.getEntry("/"); //$NON-NLS-1$
    rootEntry = FileLocator.resolve(rootEntry);
    if ("file".equals(rootEntry.getProtocol())) //$NON-NLS-1$
      return new File(rootEntry.getPath());
    if ("jar".equals(rootEntry.getProtocol())) { //$NON-NLS-1$
      String path = rootEntry.getPath();
      if (path.startsWith("file:")) {
        // strip off the file: and the !/
        path = path.substring(5, path.length() - 2);
        return new File(path);
      }
    }
    throw new IOException("Unknown protocol"); //$NON-NLS-1$   
  }

  public BeanListStore<WGARemoteServer> getWGARemoteServerStore() {
    return _wgaRemoteServerStore;
  }

  /**
   * creates a web browser with the given id
   * @param id
   * @return
   * @throws PartInitException
   */
  public IWebBrowser createBrowser(String id) throws PartInitException {
    return PlatformUI.getWorkbench().getBrowserSupport().createBrowser(SWT.MOZILLA | IWorkbenchBrowserSupport.NAVIGATION_BAR | IWorkbenchBrowserSupport.LOCATION_BAR, id, null, null);
  }

  public Map<String, LibrarySet> getLibrarySets() {   
    return _librarySets;
  }

  public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
   
    if (!bundle.equals(getBundle())) {
      return;
    }
   
    int type = event.getType();
    if (type == BundleEvent.STARTED) {
      init();
    }
  }

  @Override
  protected void initializeImageRegistry(ImageRegistry reg) {
    super.initializeImageRegistry(reg);
    try {
      reg.put(IMAGE_WGA_SERVER_START, createImage("resources/icons/server_go.png"));         
      reg.put(IMAGE_WGA_SERVER_STOP, createImage("resources/icons/server_delete.png"));
      reg.put(IMAGE_WGA_SERVER_RESTART, createImage("resources/icons/server_restart.png"));     
      reg.put(IMAGE_WGA_RUNTIME, createImage("resources/icons/wga_runtime.gif"));
      reg.put(IMAGE_WGA_MULTIRUNTIME, createImage("resources/icons/multi_server.png"));
      reg.put(IMAGE_WGA_RUNTIME_EDIT, createImage("resources/icons/server_edit.png"));
      reg.put(IMAGE_WGA_RUNTIME_ADD, createImage("resources/icons/server_add.png"));     
      reg.put(IMAGE_REFRESH, createImage("resources/icons/arrow_refresh.png"));
      reg.put(IMAGE_INAKTIV_WGA_SERVER_START, createImage("resources/icons/inaktiv_server_go.png"));
      reg.put(IMAGE_INAKTIV_WGA_SERVER_STOP, createImage("resources/icons/inaktiv_server_go.png"));
      reg.put(IMAGE_WGA_DESIGN, createImage("resources/icons/layout.png"));
      reg.put(IMAGE_WGA_DESIGN_ADD, createImage("resources/icons/layout_add.png"));
      reg.put(IMAGE_WGA_DESIGN_LINK, createImage("resources/icons/layout_link.png"));
      reg.put(IMAGE_WGA_PLUGIN, createImage("resources/icons/plugin.png"));
      reg.put(IMAGE_WGA_PLUGIN_LINK, createImage("resources/icons/plugin_link.png"));
      reg.put(IMAGE_WGA_DB, createImage("resources/icons/database.png"));
      reg.put(IMAGE_WGA_DB_DISABLED, createImage("resources/icons/database_delete.png"));
      reg.put(IMAGE_EXPORT_WGA_DESIGN, createImage("resources/icons/layout_go.png"));
      reg.put(IMAGE_EXPORT_WGA_DESIGN_LOCAL, createImage("resources/icons/layout_go.png"));
      reg.put(IMAGE_EXPORT_WGA_DESIGN_REMOTE, createImage("resources/icons/layout_go.png"));
      reg.put(IMAGE_REMOTESERVER_REACHABLE, createImage("resources/icons/flag_green.png"));
      reg.put(IMAGE_REMOTESERVER_UNREACHABLE, createImage("resources/icons/flag_red.png"));
    } catch (IOException e) {
      logError("Unable to initialize image registry for plugin '" + PLUGIN_ID + "'.");
   
  }
 
  private Image createImage(String resourcePath) throws IOException {
    InputStream in = null;
    try {
      in = getResourceAsStream(resourcePath);
      return new Image(Display.getCurrent(),in);
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException e) {         
        }
      }
    }   
  }
}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin

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.