<commit_before>package org.lamport.tla.toolbox;

import java.net.URL;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
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.ui.ide.IDE;
import org.lamport.tla.toolbox.tool.ToolboxHandle;
import org.lamport.tla.toolbox.util.UIHelper;
import org.osgi.framework.Bundle;

/**
 * This workbench advisor creates the window advisor, and specifies
 * the perspective id for the initial window.
 * @author <NAME>
 * @version $Id$ 
 */
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor
{

    // TODO MOVE!
    public static final String PERSPECTIVE_ID = "org.lamport.tla.toolbox.ui.perspective.initial";
    public static final String IDE_PLUGIN = "org.eclipse.ui.ide";
    public static final String PATH_OBJECT = "icons/full/obj16/";
    public static final String PATH_WIZBAN = "icons/full/wizban/";
    
    public static final String PRJ_OBJ = PATH_OBJECT + "prj_obj.gif"; 
    public static final String PRJ_OBJ_C = PATH_OBJECT + "cprj_obj.gif";
    public static final String SAVEAS_DLG = PATH_WIZBAN + "saveas_wiz.png";
    
    /**
     * Image definition from org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages#IMG_DLGBAN_SAVEAS_DLG
     */
    public static final String IMG_DLGBAN_SAVEAS_DLG = "IMG_DLGBAN_SAVEAS_DLG";

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

    public String getInitialWindowPerspectiveId()
    {
        return PERSPECTIVE_ID;
    }

    /*
     * @see org.eclipse.ui.application.WorkbenchAdvisor#initialize(org.eclipse.ui.application.IWorkbenchConfigurer)
     */
    public void initialize(IWorkbenchConfigurer configurer)
    {
        // save the positions of windows etc...
        configurer.setSaveAndRestore(true);

        super.initialize(configurer);
        
        Bundle ideBundle = Platform.getBundle(IDE_PLUGIN);
        declareWorkbenchImage(configurer, ideBundle, IDE.SharedImages.IMG_OBJ_PROJECT, PRJ_OBJ,
                true);
        declareWorkbenchImage(configurer, ideBundle, IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED, PRJ_OBJ_C, true);
        
        declareWorkbenchImage(configurer, ideBundle, IMG_DLGBAN_SAVEAS_DLG, SAVEAS_DLG, true);
        
        // register adapter
        IDE.registerAdapters();
    }

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

    public boolean preShutdown()
    {
        if (!ToolboxHandle.getInstanceStore().getBoolean(ToolboxHandle.I_RESTORE_LAST_SPEC))
        {
            UIHelper.getActivePage().closeAllEditors(true);
            UIHelper.switchPerspective(getInitialWindowPerspectiveId());
        }
        return super.preShutdown();
    }
}<commit_msg>life cycle notifications added<commit_after>package org.lamport.tla.toolbox;

import java.net.URL;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
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.ui.ide.IDE;
import org.lamport.tla.toolbox.tool.ToolboxHandle;
import org.lamport.tla.toolbox.tool.ToolboxLifecycleException;
import org.lamport.tla.toolbox.tool.ToolboxLifecycleParticipant;
import org.lamport.tla.toolbox.util.ToolboxParticipantManger;
import org.lamport.tla.toolbox.util.UIHelper;
import org.osgi.framework.Bundle;

/**
 * This workbench advisor creates the window advisor, and specifies
 * the perspective id for the initial window.
 * @author <NAME>
 * @version $Id$ 
 */
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor
{

    // TODO MOVE!
    public static final String PERSPECTIVE_ID = "org.lamport.tla.toolbox.ui.perspective.initial";
    public static final String IDE_PLUGIN = "org.eclipse.ui.ide";
    public static final String PATH_OBJECT = "icons/full/obj16/";
    public static final String PATH_WIZBAN = "icons/full/wizban/";
    
    public static final String PRJ_OBJ = PATH_OBJECT + "prj_obj.gif"; 
    public static final String PRJ_OBJ_C = PATH_OBJECT + "cprj_obj.gif";
    public static final String SAVEAS_DLG = PATH_WIZBAN + "saveas_wiz.png";
    
    /**
     * Image definition from org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages#IMG_DLGBAN_SAVEAS_DLG
     */
    public static final String IMG_DLGBAN_SAVEAS_DLG = "IMG_DLGBAN_SAVEAS_DLG";
    private ToolboxLifecycleParticipant[] registeredTools;

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

    public String getInitialWindowPerspectiveId()
    {
        return PERSPECTIVE_ID;
    }

    /*
     * @see org.eclipse.ui.application.WorkbenchAdvisor#initialize(org.eclipse.ui.application.IWorkbenchConfigurer)
     */
    public void initialize(IWorkbenchConfigurer configurer)
    {
        // save the positions of windows etc...
        configurer.setSaveAndRestore(true);

        super.initialize(configurer);
        
        Bundle ideBundle = Platform.getBundle(IDE_PLUGIN);
        declareWorkbenchImage(configurer, ideBundle, IDE.SharedImages.IMG_OBJ_PROJECT, PRJ_OBJ,
                true);
        declareWorkbenchImage(configurer, ideBundle, IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED, PRJ_OBJ_C, true);
        
        declareWorkbenchImage(configurer, ideBundle, IMG_DLGBAN_SAVEAS_DLG, SAVEAS_DLG, true);
        
        // register adapter
        IDE.registerAdapters();
    }

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

    public boolean preShutdown()
    {
        if (!ToolboxHandle.getInstanceStore().getBoolean(ToolboxHandle.I_RESTORE_LAST_SPEC))
        {
            UIHelper.getActivePage().closeAllEditors(true);
            UIHelper.switchPerspective(getInitialWindowPerspectiveId());
        }
        
        try 
        {
            ToolboxParticipantManger.terminate(registeredTools);
        } catch (ToolboxLifecycleException e)
        {
            // TODO
            e.printStackTrace();
        }
        
        return super.preShutdown();
    }

    public void postStartup()
    {
        super.postStartup();
        
        try 
        {
            registeredTools = ToolboxParticipantManger.getRegisteredTools();
            ToolboxParticipantManger.initialize(registeredTools);
        } catch (ToolboxLifecycleException e)
        {
            // TODO
            e.printStackTrace();
        }
        
    }
    
    
}
{'fraction_non_alphanumeric': 0.08585994097129059, 'fraction_numerical': 0.0005366246310705661, 'mean_word_length': 3.314236111111111, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7595439', 'n_tokens_mistral': 2270, 'n_tokens_neox': 2188, 'n_words': 398}