Package tool.editors.method

Source Code of tool.editors.method.MethodElementFactory

package tool.editors.method;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.IRegion;
import org.eclipse.ui.IElementFactory;
import org.eclipse.ui.IMemento;

import tool.model.ToolClass;
import tool.model.ToolMethod;

public class MethodElementFactory implements  IElementFactory{
  private static final String ID_FACTORY = "tool.editors.method.methodElementFactory"; //$NON-NLS-1$
  private static final String TAG_METHOD_NAME = "methodName";
  private static final String TAG_CLASS_FILE = "fileName";
 
  public MethodElementFactory(){
    super();
  }
  @Override
  public IAdaptable createElement(IMemento memento) {
        String methodName = memento.getString(TAG_METHOD_NAME);
        if (methodName == null) {
            return null;
        }
        String classFileName = memento.getString(TAG_CLASS_FILE);
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(
                new Path(classFileName));
        if (file != null) {
          ToolClass cls = ToolClass.fetch(file);
          ToolMethod method = cls.findMethod(methodName);
            return new MethodEditorInput(method);
        }
        return null;
  }
  public static void saveState(IMemento memento, MethodEditorInput input) {
        ToolMethod method = input.getMethod();
        ToolClass cls = ((ToolClass)method.getParent());
        memento.putString(TAG_METHOD_NAME, method.getLabelText());
        memento.putString(TAG_CLASS_FILE, cls.getFile().getFullPath().toString());
    }
  public static String getFactoryId() {
        return ID_FACTORY;
    }
}
TOP

Related Classes of tool.editors.method.MethodElementFactory

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.