org.eclipse.ui.cheatsheets_3.4.100.v20110425

16:48:04.010 INFO  jd.cli.Main - Decompiling org.eclipse.ui.cheatsheets_3.4.100.v20110425.jar
package org.eclipse.ui.cheatsheets;

import org.eclipse.swt.widgets.Composite;

public abstract class AbstractItemExtensionElement
{
  private String attributeName;
  
  public AbstractItemExtensionElement(String attributeName)
  {
    if (attributeName == null) {
      throw new IllegalArgumentException();
    }
    this.attributeName = attributeName;
  }
  
  public final String getAttributeName()
  {
    return attributeName;
  }
  
  public abstract void handleAttribute(String paramString);
  
  public abstract void createControl(Composite paramComposite);
  
  public abstract void dispose();
}

/* Location:
 * Qualified Name:     org.eclipse.ui.cheatsheets.AbstractItemExtensionElement
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.cheatsheets;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.core.runtime.IExecutableExtensionFactory;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.internal.cheatsheets.actions.CheatSheetHelpMenuAction;

public class CheatSheetExtensionFactory
  implements IExecutableExtensionFactory, IExecutableExtension
{
  public static final String HELP_MENU_ACTION = "helpMenuAction";
  private IConfigurationElement config;
  private String id;
  private String propertyName;
  
  public Object create()
    throws CoreException
  {
    if ("helpMenuAction".equals(id)) {
      return configure(new CheatSheetHelpMenuAction());
    }
    throw new CoreException(new Status(4, 
      "org.eclipse.ui.cheatsheets", 
      0, "Unknown id in data argument for " + getClass(), null));
  }
  
  public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
    throws CoreException
  {
    if ((data instanceof String)) {
      id = ((String)data);
    } else {
      throw new CoreException(new Status(4, 
        "org.eclipse.ui", 0, 
        "Data argument must be a String for " + getClass(), null));
    }
    this.config = config;
    this.propertyName = propertyName;
  }
  
  private Object configure(Object obj)
    throws CoreException
  {
    if ((obj instanceof IExecutableExtension)) {
      ((IExecutableExtension)obj).setInitializationData(config, 
        propertyName, null);
    }
    return obj;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.cheatsheets.CheatSheetExtensionFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.cheatsheets;

public abstract class CheatSheetListener
{
  public abstract void cheatSheetEvent(ICheatSheetEvent paramICheatSheetEvent);
}

/* Location:
 * Qualified Name:     org.eclipse.ui.cheatsheets.CheatSheetListener
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.cheatsheets;

import org.eclipse.ui.internal.cheatsheets.views.CheatSheetViewer;

public final class CheatSheetViewerFactory
{
  public static ICheatSheetViewer createCheatSheetView()
  {
    return new CheatSheetViewer(false);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.cheatsheets.CheatSheetViewerFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.cheatsheets;

public abstract interface ICheatSheetAction
{
  public abstract void run(String[] paramArrayOfString, ICheatSheetManager paramICheatSheetManager);
}

/* Location:
 * Qualified Name:     org.eclipse.ui.cheatsheets.ICheatSheetAction
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.cheatsheets;

public abstract interface ICheatSheetEvent
{
  public static final int CHEATSHEET_OPENED = 0;
  public static final int CHEATSHEET_CLOSED = 1;
  public static final int CHEATSHEET_STARTED = 2;
  public static final int CHEATSHEET_RESTARTED = 3;
  public static final int CHEATSHEET_COMPLETED = 4;
  public static final int CHEATSHEET_RESTORED = 5;
  
  public abstract int getEventType();
  
  public abstract String getCheatSheetID();
  
  public abstract ICheatSheetManager getCheatSheetManager();
}

/* Location:
 * Qualified Name:     org.eclipse.ui.cheatsheets.ICheatSheetEvent
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.cheatsheets;

import java.util.Set;

public abstract interface ICheatSheetManager
{
  public abstract String getCheatSheetID();
  
  public abstract String getData(String paramString);
  
  public abstract void setData(String paramString1, String paramString2);
  
  public abstract ICheatSheetManager getParent();
  
  public abstract Set getKeySet();
}

/* Location:
 * Qualified Name:     org.eclipse.ui.cheatsheets.ICheatSheetManager
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.cheatsheets;

import java.net.URL;
import java.util.Map;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

public abstract interface ICheatSheetViewer
{
  public abstract void createPartControl(Composite paramComposite);
  
  public abstract Control getControl();
  
  public abstract String getCheatSheetID();
  
  public abstract void setFocus();
  
  public abstract void setInput(String paramString);
  
  public abstract void setInput(String paramString1, String paramString2, URL paramURL);
  
  public abstract void reset(Map paramMap);
}

/* Location:
 * Qualified Name:     org.eclipse.ui.cheatsheets.ICheatSheetViewer
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.cheatsheets;

import java.net.URL;
import org.eclipse.help.ui.internal.views.HelpTray;
import org.eclipse.help.ui.internal.views.IHelpPartPage;
import org.eclipse.help.ui.internal.views.ReusableHelpPart;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.TrayDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.forms.ManagedForm;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetRegistryReader;
import org.eclipse.ui.internal.cheatsheets.state.DefaultStateManager;
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetHelpPart;
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetView;
import org.eclipse.ui.internal.cheatsheets.views.ViewUtilities;

public final class OpenCheatSheetAction
  extends Action
{
  private String id;
  private String name;
  private URL url;
  private String xml;
  private String basePath;
  
  public OpenCheatSheetAction(String id)
  {
    if (id == null) {
      throw new IllegalArgumentException();
    }
    this.id = id;
  }
  
  public OpenCheatSheetAction(String id, String name, URL url)
  {
    if ((id == null) || (name == null) || (url == null)) {
      throw new IllegalArgumentException();
    }
    this.id = id;
    this.name = name;
    this.url = url;
  }
  
  public OpenCheatSheetAction(String id, String name, String xml, URL baseURL)
  {
    if ((id == null) || (name == null) || (xml == null)) {
      throw new IllegalArgumentException();
    }
    this.id = id;
    this.name = name;
    this.xml = xml;
    if (baseURL != null) {
      basePath = baseURL.toExternalForm();
    }
  }
  
  public void run()
  {
    Shell shell = Display.getDefault().getActiveShell();
    if ((shell != null) && (!shell.isFocusControl()) && ((shell.getData() instanceof TrayDialog)))
    {
      TrayDialog dialog = (TrayDialog)shell.getData();
      HelpTray tray = (HelpTray)dialog.getTray();
      if (tray == null)
      {
        tray = new HelpTray();
        dialog.openTray(tray);
      }
      ReusableHelpPart helpPart = tray.getHelpPart();
      IHelpPartPage page = helpPart.createPage("cheatsheet-page", null, null);
      page.setVerticalSpacing(0);
      page.setHorizontalMargin(0);
      CheatSheetElement contentElement = CheatSheetRegistryReader.getInstance().findCheatSheet(id);
      helpPart.addPart("cheatsheet-page", new CheatSheetHelpPart(helpPart.getForm().getForm().getBody(), helpPart.getForm().getToolkit(), page.getToolBarManager(), contentElement, new DefaultStateManager()));
      page.addPart("cheatsheet-page", true);
      helpPart.addPage(page);
      helpPart.showPage("cheatsheet-page");
    }
    else
    {
      CheatSheetView view = ViewUtilities.showCheatSheetView();
      if (view == null) {
        return;
      }
      if (url != null) {
        view.setInput(id, name, url);
      } else if (xml != null) {
        view.setInputFromXml(id, name, xml, basePath);
      } else {
        view.setInput(id);
      }
      IWorkbenchPage page = view.getSite().getWorkbenchWindow().getActivePage();
      page.bringToTop(view);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.cheatsheets.OpenCheatSheetAction
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.cheatsheets;

class OpenCheatSheetFromHelpAction$1
  implements Runnable
{
  final OpenCheatSheetFromHelpAction this$0;
  
  OpenCheatSheetFromHelpAction$1(OpenCheatSheetFromHelpAction paramOpenCheatSheetFromHelpAction)
  {
    this$0 = paramOpenCheatSheetFromHelpAction;
  }
  
  public void run()
  {
    new OpenCheatSheetAction(OpenCheatSheetFromHelpAction.access$0(this$0)).run();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.cheatsheets.OpenCheatSheetFromHelpAction.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.cheatsheets;

import org.eclipse.help.ILiveHelpAction;
import org.eclipse.swt.widgets.Display;

public final class OpenCheatSheetFromHelpAction
  implements ILiveHelpAction
{
  private String cheatsheetID = null;
  
  public void setInitializationString(String data)
  {
    cheatsheetID = data;
  }
  
  public void run()
  {
    Display.getDefault().syncExec(new Runnable()
    {
      public void run()
      {
        new OpenCheatSheetAction(cheatsheetID).run();
      }
    });
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.cheatsheets.OpenCheatSheetFromHelpAction
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.internal.cheatsheets;

import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

class ActionRunner$1
  implements IPropertyChangeListener
{
  final ActionRunner this$0;
  private final boolean[] val$listenerFired;
  private final boolean[] val$listenerResult;
  
  ActionRunner$1(ActionRunner paramActionRunner, boolean[] paramArrayOfBoolean1, boolean[] paramArrayOfBoolean2)
  {
    this$0 = paramActionRunner;val$listenerFired = paramArrayOfBoolean1;val$listenerResult = paramArrayOfBoolean2;
  }
  
  public void propertyChange(PropertyChangeEvent event)
  {
    if ((event.getProperty().equals("result")) && ((event.getNewValue() instanceof Boolean)))
    {
      val$listenerFired[0] = true;
      val$listenerResult[0] = ((Boolean)event.getNewValue()).booleanValue();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.internal.cheatsheets.ActionRunner.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.internal.cheatsheets;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.cheatsheets.ICheatSheetAction;
import org.eclipse.ui.internal.cheatsheets.data.Action;
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
import org.osgi.framework.Bundle;

public class ActionRunner
{
  public IStatus runAction(Action cheatSheetAction, CheatSheetManager csm)
  {
    IStatus status = Status.OK_STATUS;
    String pluginId = cheatSheetAction.getPluginID();
    String className = cheatSheetAction.getActionClass();
    String[] params = cheatSheetAction.getParams();
    Bundle bundle = Platform.getBundle(pluginId);
    if (bundle == null)
    {
      String message = NLS.bind(Messages.ERROR_FINDING_PLUGIN_FOR_ACTION, new Object[] { pluginId });
      return new Status(4, "org.eclipse.ui.cheatsheets", 0, message, null);
    }
    try
    {
      actionClass = bundle.loadClass(className);
    }
    catch (Exception e)
    {
      Class actionClass;
      String message = NLS.bind(Messages.ERROR_LOADING_CLASS_FOR_ACTION, new Object[] { className });
      return new Status(4, "org.eclipse.ui.cheatsheets", 0, message, e);
    }
    try
    {
      Class actionClass;
      action = (IAction)actionClass.newInstance();
    }
    catch (Exception e)
    {
      IAction action;
      String message = NLS.bind(Messages.ERROR_CREATING_CLASS_FOR_ACTION, new Object[] { className });
      return new Status(4, "org.eclipse.ui.cheatsheets", 0, message, e);
    }
    IAction action;
    boolean[] listenerFired = new boolean[1];
    boolean[] listenerResult = new boolean[1];
    IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener()
    {
      private final boolean[] val$listenerFired;
      private final boolean[] val$listenerResult;
      
      public void propertyChange(PropertyChangeEvent event)
      {
        if ((event.getProperty().equals("result")) && ((event.getNewValue() instanceof Boolean)))
        {
          val$listenerFired[0] = true;
          val$listenerResult[0] = ((Boolean)event.getNewValue()).booleanValue();
        }
      }
    };
    action.addPropertyChangeListener(propertyChangeListener);
    if ((action instanceof ICheatSheetAction))
    {
      String[] clonedParams = (String[])null;
      if ((params != null) && (params.length > 0))
      {
        clonedParams = new String[params.length];
        System.arraycopy(params, 0, clonedParams, 0, params.length);
        for (int i = 0; i < clonedParams.length; i++)
        {
          String param = clonedParams[i];
          if ((param != null) && (param.startsWith("${")) && (param.endsWith("}")))
          {
            param = param.substring(2, param.length() - 1);
            String value = csm.getDataQualified(param);
            clonedParams[i] = (value == null ? "" : value);
          }
        }
      }
      ((ICheatSheetAction)action).run(clonedParams, csm);
    }
    else
    {
      try
      {
        action.run();
      }
      catch (Throwable e)
      {
        status = new Status(4, "org.eclipse.ui.cheatsheets", 0, Messages.EXCEPTION_RUNNING_ACTION, e);
      }
    }
    action.removePropertyChangeListener(propertyChangeListener);
    if ((status.isOK()) && (listenerFired[0] != 0) && 
      (listenerResult[0] == 0)) {
      status = new Status(2, "org.eclipse.ui.cheatsheets", 0, Messages.ACTION_FAILED, null);
    }
    return status;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.internal.cheatsheets.ActionRunner
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.internal.cheatsheets;

import org.eclipse.core.expressions.EvaluationContext;
import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.PlatformUI;

public final class CheatSheetEvaluationContext
{
  private static final String VARIABLE_PLATFORM = "platform";
  private static final String VARIABLE_WORKBENCH = "workbench";
  private static EvaluationContext context;
  
  public static EvaluationContext getContext()
  {
    if (context == null)
    {
      context = new EvaluationContext(null, Platform.class);
      context.addVariable("platform", Platform.class);
      context.addVariable("workbench", PlatformUI.getWorkbench());
    }
    return context;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.internal.cheatsheets.CheatSheetEvaluationContext
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.internal.cheatsheets;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetRegistryReader;

public class CheatSheetHistory
{
  private static final int DEFAULT_DEPTH = 5;
  private ArrayList history;
  private CheatSheetRegistryReader reg;
  private ListenerList listeners = new ListenerList();
  
  public CheatSheetHistory(CheatSheetRegistryReader reg)
  {
    history = new ArrayList(5);
    this.reg = reg;
  }
  
  public void addListener(IPropertyListener l)
  {
    listeners.add(l);
  }
  
  public void removeListener(IPropertyListener l)
  {
    listeners.remove(l);
  }
  
  private void fireChange()
  {
    Object[] array = listeners.getListeners();
    for (int i = 0; i < array.length; i++)
    {
      IPropertyListener element = (IPropertyListener)array[i];
      element.propertyChanged(this, 0);
    }
  }
  
  public IStatus restoreState(IMemento memento)
  {
    IMemento[] children = memento.getChildren("element");
    for (int i = 0; (i < children.length) && (i < 5); i++)
    {
      CheatSheetElement element = 
        reg.findCheatSheet(children[i].getID());
      if (element != null) {
        history.add(element);
      }
    }
    return new Status(0, "org.eclipse.ui.cheatsheets", 0, "", null);
  }
  
  public IStatus saveState(IMemento memento)
  {
    Iterator iter = history.iterator();
    while (iter.hasNext())
    {
      CheatSheetElement element = (CheatSheetElement)iter.next();
      if (element != null) {
        memento.createChild("element", element.getID());
      }
    }
    return new Status(0, "org.eclipse.ui.cheatsheets", 0, "", null);
  }
  
  public void add(String id)
  {
    CheatSheetElement element = reg.findCheatSheet(id);
    if (element != null) {
      add(element);
    }
  }
  
  public void add(CheatSheetElement element)
  {
    if (history.contains(element)) {
      return;
    }
    int size = history.size();
    int preferredSize = 5;
    while (size >= preferredSize)
    {
      size--;
      history.remove(size);
    }
    history.add(0, element);
    fireChange();
  }
  
  public void refreshFromRegistry()
  {
    boolean change = false;
    
    Iterator iter = history.iterator();
    while (iter.hasNext())
    {
      CheatSheetElement element = (CheatSheetElement)iter.next();
      if (reg.findCheatSheet(element.getID()) == null)
      {
        iter.remove();
        change = true;
      }
    }
    if (change) {
      fireChange();
    }
  }
  
  public int copyItems(List dest, int destStart, int count)
  {
    int itemCount = count;
    if (itemCount > history.size()) {
      itemCount = history.size();
    }
    for (int i = 0; i < itemCount; i++) {
      dest.add(destStart + i, history.get(i));
    }
    return itemCount;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.internal.cheatsheets.CheatSheetHistory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.internal.cheatsheets;

import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.util.SafeRunnable;
import org.eclipse.ui.IMemento;

class CheatSheetPlugin$1
  extends SafeRunnable
{
  final CheatSheetPlugin this$0;
  
  CheatSheetPlugin$1(CheatSheetPlugin paramCheatSheetPlugin)
  {
    this$0 = paramCheatSheetPlugin;
  }
  
  public void run()
  {
    IMemento memento = this$0.readMemento("history.xml");
    if (memento != null)
    {
      IMemento childMem = memento.getChild("cheatsheetHistory");
      if (childMem != null) {
        CheatSheetPlugin.access$0(this$0).restoreState(childMem);
      }
    }
  }
  
  public void handleException(Throwable e)
  {
    String message = Messages.ERROR_READING_STATE_FILE;
    IStatus status = new Status(4, "org.eclipse.ui.cheatsheets", 0, message, e);
    CheatSheetPlugin.getPlugin().getLog().log(status);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.internal.cheatsheets;

import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.util.SafeRunnable;
import org.eclipse.ui.XMLMemento;

class CheatSheetPlugin$2
  extends SafeRunnable
{
  final CheatSheetPlugin this$0;
  
  CheatSheetPlugin$2(CheatSheetPlugin paramCheatSheetPlugin)
  {
    this$0 = paramCheatSheetPlugin;
  }
  
  public void run()
  {
    XMLMemento memento = XMLMemento.createWriteRoot("cheatsheet");
    
    memento.putString("version", CheatSheetPlugin.access$1()[1]);
    
    this$0.getCheatSheetHistory().saveState(memento.createChild("cheatsheetHistory"));
    
    IStatus status = this$0.saveMemento(memento, "history.xml");
    if (!status.isOK()) {
      CheatSheetPlugin.getPlugin().getLog().log(status);
    }
  }
  
  public void handleException(Throwable e)
  {
    String message = Messages.ERROR_WRITING_STATE_FILE;
    IStatus status = new Status(4, "org.eclipse.ui.cheatsheets", 0, message, e);
    CheatSheetPlugin.getPlugin().getLog().log(status);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin.2
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.internal.cheatsheets;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
import org.eclipse.help.internal.entityresolver.LocalEntityResolver;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.util.SafeRunnable;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.XMLMemento;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetRegistryReader;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

public class CheatSheetPlugin
  extends AbstractUIPlugin
{
  public static final String PLUGIN_ID = "org.eclipse.help.base";
  static CheatSheetPlugin plugin;
  private CheatSheetHistory history = null;
  private DocumentBuilder documentBuilder = null;
  private static final String HISTORY_FILENAME = "history.xml";
  private static final String MEMENTO_TAG_CHEATSHEET = "cheatsheet";
  private static final String MEMENTO_TAG_VERSION = "version";
  private static final String[] VERSION_STRING = { "0.0", "3.0.0" };
  private static final String MEMENTO_TAG_CHEATSHEET_HISTORY = "cheatsheetHistory";
  public static final IPath ICONS_PATH = new Path("$nl$/icons/");
  public static final String T_OBJ = "obj16/";
  public static final String T_ELCL = "elcl16/";
  public static final String T_DLCL = "dlcl16/";
  public static final String T_VIEW = "view16/";
  
  public static CheatSheetPlugin getPlugin()
  {
    return plugin;
  }
  
  public Image getImage(String key)
  {
    Image image = getImageRegistry().get(key);
    return image;
  }
  
  public CheatSheetHistory getCheatSheetHistory()
  {
    if (history == null)
    {
      history = new CheatSheetHistory(CheatSheetRegistryReader.getInstance());
      restoreCheatSheetHistory();
    }
    return history;
  }
  
  private File getCheatSheetStateFile(String filename)
  {
    IPath path = getPlugin().getStateLocation();
    path = path.append(filename);
    return path.toFile();
  }
  
  public DocumentBuilder getDocumentBuilder()
  {
    if (documentBuilder == null) {
      try
      {
        documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        documentBuilder.setEntityResolver(new LocalEntityResolver());
      }
      catch (Exception e)
      {
        IStatus status = new Status(4, "org.eclipse.ui.cheatsheets", 0, Messages.ERROR_CREATING_DOCUMENT_BUILDER, e);
        getPlugin().getLog().log(status);
      }
    }
    return documentBuilder;
  }
  
  public static synchronized void logError(String message, Throwable ex)
  {
    if (message == null) {
      message = "";
    }
    Status errorStatus = new Status(4, "org.eclipse.help.base", 0, 
      message, ex);
    getPlugin().getLog().log(errorStatus);
  }
  
  protected void initializeImageRegistry(ImageRegistry reg)
  {
    IPath path = ICONS_PATH.append("obj16/").append("cheatsheet_obj.gif");
    ImageDescriptor imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("CHEATSHEET_OBJ", imageDescriptor);
    
    path = ICONS_PATH.append("obj16/").append("skip_status.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("CHEATSHEET_ITEM_SKIP", imageDescriptor);
    
    path = ICONS_PATH.append("obj16/").append("complete_status.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("CHEATSHEET_ITEM_COMPLETE", imageDescriptor);
    
    path = ICONS_PATH.append("elcl16/").append("linkto_help.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("CHEATSHEET_ITEM_HELP", imageDescriptor);
    
    path = ICONS_PATH.append("elcl16/").append("start_cheatsheet.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("CHEATSHEET_START", imageDescriptor);
    
    path = ICONS_PATH.append("elcl16/").append("restart_cheatsheet.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("CHEATSHEET_RESTART", imageDescriptor);
    
    path = ICONS_PATH.append("elcl16/").append("start_task.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("CHEATSHEET_ITEM_BUTTON_START", imageDescriptor);
    
    path = ICONS_PATH.append("elcl16/").append("skip_task.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("CHEATSHEET_ITEM_BUTTON_SKIP", imageDescriptor);
    
    path = ICONS_PATH.append("elcl16/").append("complete_task.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("CHEATSHEET_ITEM_BUTTON_COMPLETE", imageDescriptor);
    
    path = ICONS_PATH.append("elcl16/").append("restart_task.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("CHEATSHEET_ITEM_BUTTON_RESTART", imageDescriptor);
    
    path = ICONS_PATH.append("elcl16/").append("return_to_start.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("CHEATSHEET_RETURN", imageDescriptor);
    
    path = ICONS_PATH.append("obj16/").append("error.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("ERROR", imageDescriptor);
    
    path = ICONS_PATH.append("obj16/").append("composite_obj.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("COMPOSITE_OBJ", imageDescriptor);
    
    path = ICONS_PATH.append("obj16/").append("information.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("INFORMATION", imageDescriptor);
    
    path = ICONS_PATH.append("obj16/").append("warning.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("WARNING", imageDescriptor);
    
    path = ICONS_PATH.append("elcl16/").append("start_ccs_task.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("COMPOSITE_TASK_START", imageDescriptor);
    
    path = ICONS_PATH.append("elcl16/").append("skip_ccs_task.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("COMPOSITE_TASK_SKIP", imageDescriptor);
    
    path = ICONS_PATH.append("elcl16/").append("review_ccs_task.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("COMPOSITE_TASK_REVIEW", imageDescriptor);
    
    path = ICONS_PATH.append("elcl16/").append("goto_ccs_task.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("COMPOSITE_GOTO_TASK", imageDescriptor);
    
    path = ICONS_PATH.append("elcl16/").append("restart_all.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("COMPOSITE_RESTART_ALL", imageDescriptor);
    
    path = ICONS_PATH.append("view16/").append("cheatsheet_view.gif");
    imageDescriptor = createImageDescriptor(getPlugin().getBundle(), path);
    reg.put("CHEATSHEET_VIEW", imageDescriptor);
  }
  
  private void restoreCheatSheetHistory()
  {
    SafeRunner.run(new SafeRunnable()
    {
      public void run()
      {
        IMemento memento = readMemento("history.xml");
        if (memento != null)
        {
          IMemento childMem = memento.getChild("cheatsheetHistory");
          if (childMem != null) {
            history.restoreState(childMem);
          }
        }
      }
      
      public void handleException(Throwable e)
      {
        String message = Messages.ERROR_READING_STATE_FILE;
        IStatus status = new Status(4, "org.eclipse.ui.cheatsheets", 0, message, e);
        CheatSheetPlugin.getPlugin().getLog().log(status);
      }
    });
  }
  
  /* Error */
  public XMLMemento readMemento(String filename)
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore_3
    //   2: aload_0
    //   3: aload_1
    //   4: invokespecial 392	org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin:getCheatSheetStateFile	(Ljava/lang/String;)Ljava/io/File;
    //   7: astore 4
    //   9: new 225	java/io/FileInputStream
    //   12: dup
    //   13: aload 4
    //   15: invokespecial 365	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   18: astore 5
    //   20: new 229	java/io/InputStreamReader
    //   23: dup
    //   24: aload 5
    //   26: ldc_w 222
    //   29: invokespecial 368	java/io/InputStreamReader:<init>	(Ljava/io/InputStream;Ljava/lang/String;)V
    //   32: astore_3
    //   33: aload_3
    //   34: invokestatic 383	org/eclipse/ui/XMLMemento:createReadRoot	(Ljava/io/Reader;)Lorg/eclipse/ui/XMLMemento;
    //   37: astore_2
    //   38: goto +200 -> 238
    //   41: pop
    //   42: aconst_null
    //   43: astore_2
    //   44: aload_3
    //   45: ifnull +241 -> 286
    //   48: aload_3
    //   49: invokevirtual 367	java/io/InputStreamReader:close	()V
    //   52: goto +234 -> 286
    //   55: astore 8
    //   57: getstatic 362	org/eclipse/ui/internal/cheatsheets/Messages:ERROR_READING_STATE_FILE	Ljava/lang/String;
    //   60: astore 9
    //   62: new 240	org/eclipse/core/runtime/Status
    //   65: dup
    //   66: iconst_4
    //   67: ldc 29
    //   69: iconst_0
    //   70: aload 9
    //   72: aload 8
    //   74: invokespecial 377	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
    //   77: astore 10
    //   79: invokestatic 390	org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin:getPlugin	()Lorg/eclipse/ui/internal/cheatsheets/CheatSheetPlugin;
    //   82: invokevirtual 387	org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin:getLog	()Lorg/eclipse/core/runtime/ILog;
    //   85: aload 10
    //   87: invokeinterface 401 2 0
    //   92: goto +194 -> 286
    //   95: astore 4
    //   97: getstatic 362	org/eclipse/ui/internal/cheatsheets/Messages:ERROR_READING_STATE_FILE	Ljava/lang/String;
    //   100: astore 5
    //   102: new 240	org/eclipse/core/runtime/Status
    //   105: dup
    //   106: iconst_4
    //   107: ldc 29
    //   109: iconst_0
    //   110: aload 5
    //   112: aload 4
    //   114: invokespecial 377	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
    //   117: astore 6
    //   119: invokestatic 390	org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin:getPlugin	()Lorg/eclipse/ui/internal/cheatsheets/CheatSheetPlugin;
    //   122: invokevirtual 387	org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin:getLog	()Lorg/eclipse/core/runtime/ILog;
    //   125: aload 6
    //   127: invokeinterface 401 2 0
    //   132: aconst_null
    //   133: astore_2
    //   134: aload_3
    //   135: ifnull +151 -> 286
    //   138: aload_3
    //   139: invokevirtual 367	java/io/InputStreamReader:close	()V
    //   142: goto +144 -> 286
    //   145: astore 8
    //   147: getstatic 362	org/eclipse/ui/internal/cheatsheets/Messages:ERROR_READING_STATE_FILE	Ljava/lang/String;
    //   150: astore 9
    //   152: new 240	org/eclipse/core/runtime/Status
    //   155: dup
    //   156: iconst_4
    //   157: ldc 29
    //   159: iconst_0
    //   160: aload 9
    //   162: aload 8
    //   164: invokespecial 377	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
    //   167: astore 10
    //   169: invokestatic 390	org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin:getPlugin	()Lorg/eclipse/ui/internal/cheatsheets/CheatSheetPlugin;
    //   172: invokevirtual 387	org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin:getLog	()Lorg/eclipse/core/runtime/ILog;
    //   175: aload 10
    //   177: invokeinterface 401 2 0
    //   182: goto +104 -> 286
    //   185: astore 7
    //   187: aload_3
    //   188: ifnull +47 -> 235
    //   191: aload_3
    //   192: invokevirtual 367	java/io/InputStreamReader:close	()V
    //   195: goto +40 -> 235
    //   198: astore 8
    //   200: getstatic 362	org/eclipse/ui/internal/cheatsheets/Messages:ERROR_READING_STATE_FILE	Ljava/lang/String;
    //   203: astore 9
    //   205: new 240	org/eclipse/core/runtime/Status
    //   208: dup
    //   209: iconst_4
    //   210: ldc 29
    //   212: iconst_0
    //   213: aload 9
    //   215: aload 8
    //   217: invokespecial 377	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
    //   220: astore 10
    //   222: invokestatic 390	org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin:getPlugin	()Lorg/eclipse/ui/internal/cheatsheets/CheatSheetPlugin;
    //   225: invokevirtual 387	org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin:getLog	()Lorg/eclipse/core/runtime/ILog;
    //   228: aload 10
    //   230: invokeinterface 401 2 0
    //   235: aload 7
    //   237: athrow
    //   238: aload_3
    //   239: ifnull +47 -> 286
    //   242: aload_3
    //   243: invokevirtual 367	java/io/InputStreamReader:close	()V
    //   246: goto +40 -> 286
    //   249: astore 8
    //   251: getstatic 362	org/eclipse/ui/internal/cheatsheets/Messages:ERROR_READING_STATE_FILE	Ljava/lang/String;
    //   254: astore 9
    //   256: new 240	org/eclipse/core/runtime/Status
    //   259: dup
    //   260: iconst_4
    //   261: ldc 29
    //   263: iconst_0
    //   264: aload 9
    //   266: aload 8
    //   268: invokespecial 377	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
    //   271: astore 10
    //   273: invokestatic 390	org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin:getPlugin	()Lorg/eclipse/ui/internal/cheatsheets/CheatSheetPlugin;
    //   276: invokevirtual 387	org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin:getLog	()Lorg/eclipse/core/runtime/ILog;
    //   279: aload 10
    //   281: invokeinterface 401 2 0
    //   286: aload_2
    //   287: areturn
    // Line number table:
    //   Java source line #267	-> byte code offset #0
    //   Java source line #271	-> byte code offset #2
    //   Java source line #273	-> byte code offset #9
    //   Java source line #274	-> byte code offset #20
    //   Java source line #275	-> byte code offset #33
    //   Java source line #278	-> byte code offset #41
    //   Java source line #279	-> byte code offset #42
    //   Java source line #288	-> byte code offset #44
    //   Java source line #289	-> byte code offset #48
    //   Java source line #290	-> byte code offset #55
    //   Java source line #292	-> byte code offset #57
    //   Java source line #293	-> byte code offset #62
    //   Java source line #294	-> byte code offset #79
    //   Java source line #281	-> byte code offset #95
    //   Java source line #282	-> byte code offset #97
    //   Java source line #283	-> byte code offset #102
    //   Java source line #284	-> byte code offset #119
    //   Java source line #285	-> byte code offset #132
    //   Java source line #288	-> byte code offset #134
    //   Java source line #289	-> byte code offset #138
    //   Java source line #290	-> byte code offset #145
    //   Java source line #292	-> byte code offset #147
    //   Java source line #293	-> byte code offset #152
    //   Java source line #294	-> byte code offset #169
    //   Java source line #286	-> byte code offset #185
    //   Java source line #288	-> byte code offset #187
    //   Java source line #289	-> byte code offset #191
    //   Java source line #290	-> byte code offset #198
    //   Java source line #292	-> byte code offset #200
    //   Java source line #293	-> byte code offset #205
    //   Java source line #294	-> byte code offset #222
    //   Java source line #296	-> byte code offset #235
    //   Java source line #288	-> byte code offset #238
    //   Java source line #289	-> byte code offset #242
    //   Java source line #290	-> byte code offset #249
    //   Java source line #292	-> byte code offset #251
    //   Java source line #293	-> byte code offset #256
    //   Java source line #294	-> byte code offset #273
    //   Java source line #297	-> byte code offset #286
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	288	0	this	CheatSheetPlugin
    //   0	288	1	filename	String
    //   37	2	2	memento	XMLMemento
    //   43	2	2	memento	XMLMemento
    //   133	2	2	memento	XMLMemento
    //   238	1	2	memento	XMLMemento
    //   286	1	2	memento	XMLMemento
    //   1	242	3	reader	java.io.InputStreamReader
    //   7	7	4	stateFile	File
    //   95	18	4	e	Exception
    //   18	7	5	input	java.io.FileInputStream
    //   100	11	5	message	String
    //   117	9	6	status	IStatus
    //   185	51	7	localObject	Object
    //   55	18	8	e	IOException
    //   145	18	8	e	IOException
    //   198	18	8	e	IOException
    //   249	18	8	e	IOException
    //   60	11	9	message	String
    //   150	11	9	message	String
    //   203	11	9	message	String
    //   254	11	9	message	String
    //   77	9	10	status	IStatus
    //   167	9	10	status	IStatus
    //   220	9	10	status	IStatus
    //   271	9	10	status	IStatus
    //   41	1	26	localFileNotFoundException	java.io.FileNotFoundException
    // Exception table:
    //   from	to	target	type
    //   2	38	41	java/io/FileNotFoundException
    //   44	52	55	java/io/IOException
    //   2	38	95	java/lang/Exception
    //   134	142	145	java/io/IOException
    //   2	44	185	finally
    //   95	134	185	finally
    //   187	195	198	java/io/IOException
    //   238	246	249	java/io/IOException
  }
  
  private void saveCheatSheetHistory()
  {
    SafeRunner.run(new SafeRunnable()
    {
      public 
1 2 3 4 5 6 7 8 9 10 11 12 13 14

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd