FileDocCategorySizeDatePackage
PostActivityCreationAction.javaAPI DocAndroid 1.5 API3283Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.manifest.descriptors

PostActivityCreationAction

public class PostActivityCreationAction extends Object implements com.android.ide.eclipse.editors.manifest.model.UiClassAttributeNode.IPostTypeCreationAction
Action to be executed after an Activity class is created.

Fields Summary
private static final PostActivityCreationAction
sAction
Constructors Summary
private PostActivityCreationAction()

    
      
        // private constructor to enforce singleton.
    
Methods Summary
public static com.android.ide.eclipse.editors.manifest.model.UiClassAttributeNode.IPostTypeCreationActiongetAction()
Returns the action.

        return sAction;
    
public voidprocessNewType(org.eclipse.jdt.core.IType newType)
Processes a newly created Activity.

        try {
            String methodContent = 
                "    /** Called when the activity is first created. */\n" +
                "    @Override\n" +
                "    public void onCreate(Bundle savedInstanceState) {\n" +
                "        super.onCreate(savedInstanceState);\n" +
                "\n" +
                "        // TODO Auto-generated method stub\n" +
                "    }";
            newType.createMethod(methodContent, null /* sibling*/, false /* force */,
                    new NullProgressMonitor());

            // we need to add the import for Bundle, so we need the compilation unit.
            // Since the type could be enclosed in other types, we loop till we find it.
            ICompilationUnit compilationUnit = null;
            IJavaElement element = newType;
            do {
                IJavaElement parentElement = element.getParent();
                if (parentElement !=  null) {
                    if (parentElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
                        compilationUnit = (ICompilationUnit)parentElement;
                    }
                    
                    element = parentElement;
                } else {
                    break;
                }
            } while (compilationUnit == null);
            
            if (compilationUnit != null) {
                compilationUnit.createImport(AndroidConstants.CLASS_BUNDLE,
                        null /* sibling */, new NullProgressMonitor());
            }
        } catch (JavaModelException e) {
        }