package net.sf.aftrace.e4.application;

import java.net.URL;

import org.eclipse.ui.application.IWorkbenchConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.osgi.framework.Bundle;

public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {

	private static final String PERSPECTIVE_ID = "test.rcp.perspective"; //$NON-NLS-1$

	public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
			IWorkbenchWindowConfigurer configurer) {
		return new ApplicationWorkbenchWindowAdvisor(configurer);
	}

	public String getInitialWindowPerspectiveId() {
		return PERSPECTIVE_ID;
	}

	@Override
	public void initialize(IWorkbenchConfigurer configurer) {
//		super.initialize(configurer);
//		// inserted: register workbench adapters
//		IDE.registerAdapters();
//
//		// inserted: register images for rendering explorer view
//		final String ICONS_PATH = "icons/full/";
//		final String PATH_OBJECT = ICONS_PATH + "obj16/";
//		Bundle ideBundle = Platform.getBundle(IDEWorkbenchPlugin.IDE_WORKBENCH);
//		declareWorkbenchImage(configurer, ideBundle,
//				IDE.SharedImages.IMG_OBJ_PROJECT, PATH_OBJECT + "prj_obj.gif",
//				true);
//		declareWorkbenchImage(configurer, ideBundle,
//				IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED, PATH_OBJECT
//						+ "cprj_obj.gif", true);
		
		 IDE.registerAdapters();
         final String ICONS_PATH = "icons/full/";
         final String PATH_OBJECT = ICONS_PATH + "obj16/";
         Bundle ideBundle = Platform.getBundle(IDEWorkbenchPlugin.IDE_WORKBENCH);
         declareWorkbenchImage(configurer, ideBundle,
                         IDE.SharedImages.IMG_OBJ_PROJECT, PATH_OBJECT + "prj_obj.gif",
                         true);
         declareWorkbenchImage(configurer, ideBundle,
                         IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED, PATH_OBJECT
                                         + "cprj_obj.gif", true);

         super.initialize(configurer);
         configurer.setSaveAndRestore(true);
	}

	private void declareWorkbenchImage(IWorkbenchConfigurer configurer_p,
			Bundle ideBundle, String symbolicName, String path, boolean shared) {
		URL url = ideBundle.getEntry(path);
		ImageDescriptor desc = ImageDescriptor.createFromURL(url);
		configurer_p.declareImage(symbolicName, desc, shared);
	}

}

@@ -969,18 +969,16 @@
 urer) %7B%0A
-//
 %09%09super.
@@ -1001,18 +1001,16 @@
 gurer);%0A
-//
 %09%09// ins
@@ -1044,18 +1044,16 @@
 dapters%0A
-//
 %09%09IDE.re
@@ -1074,13 +1074,9 @@
 ();%0A
-//%0A//
+%0A
 %09%09//
@@ -1130,18 +1130,16 @@
 er view%0A
-//
 %09%09final 
@@ -1173,18 +1173,16 @@
 full/%22;%0A
-//
 %09%09final 
@@ -1225,18 +1225,16 @@
 bj16/%22;%0A
-//
 %09%09Bundle
@@ -1300,18 +1300,16 @@
 BENCH);%0A
-//
 %09%09declar
@@ -1339,34 +1339,32 @@
 rer, ideBundle,%0A
-//
 %09%09%09%09IDE.SharedIm
@@ -1414,18 +1414,16 @@
 j.gif%22,%0A
-//
 %09%09%09%09true
@@ -1425,18 +1425,16 @@
 %09true);%0A
-//
 %09%09declar
@@ -1472,18 +1472,16 @@
 Bundle,%0A
-//
 %09%09%09%09IDE.
@@ -1529,18 +1529,16 @@
 _OBJECT%0A
-//
 %09%09%09%09%09%09+ 
@@ -1564,686 +1564,8 @@
 e);%0A
-%09%09%0A%09%09 IDE.registerAdapters();%0A         final String ICONS_PATH = %22icons/full/%22;%0A         final String PATH_OBJECT = ICONS_PATH + %22obj16/%22;%0A         Bundle ideBundle = Platform.getBundle(IDEWorkbenchPlugin.IDE_WORKBENCH);%0A         declareWorkbenchImage(configurer, ideBundle,%0A                         IDE.SharedImages.IMG_OBJ_PROJECT, PATH_OBJECT + %22prj_obj.gif%22,%0A                         true);%0A         declareWorkbenchImage(configurer, ideBundle,%0A                         IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED, PATH_OBJECT%0A                                         + %22cprj_obj.gif%22, true);%0A%0A         super.initialize(configurer);%0A         configurer.setSaveAndRestore(true);%0A
 %09%7D%0A%0A

Fix app init