Search in sources :

Example 66 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project jbosstools-hibernate by jbosstools.

the class LaunchHelper method findLaunchConfigurationByName.

public static ILaunchConfiguration findLaunchConfigurationByName(String launchConfigurationTypeId, String name) throws CoreException {
    Assert.isNotNull(launchConfigurationTypeId, HibernateConsoleMessages.LaunchHelper_launch_cfg_type_cannot_be_null);
    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType launchConfigurationType = launchManager.getLaunchConfigurationType(launchConfigurationTypeId);
    ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(launchConfigurationType);
    for (int i = 0; i < launchConfigurations.length; i++) {
        // can't believe
        // there is no
        // look up by
        // name API
        ILaunchConfiguration launchConfiguration = launchConfigurations[i];
        if (launchConfiguration.getName().equals(name)) {
            return launchConfiguration;
        }
    }
    return null;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager)

Example 67 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project jbosstools-hibernate by jbosstools.

the class LaunchHelper method findProjectRelatedHibernateLaunchConfigs.

public static ILaunchConfiguration[] findProjectRelatedHibernateLaunchConfigs(String projectName) throws CoreException {
    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfiguration[] configs = launchManager.getLaunchConfigurations(getHibernateLaunchConfigsType());
    List<ILaunchConfiguration> list = new ArrayList<ILaunchConfiguration>();
    for (int i = 0; i < configs.length && configs[i].exists(); i++) {
        String project = configs[i].getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
        if (projectName.equals(project))
            list.add(configs[i]);
    }
    return list.toArray(new ILaunchConfiguration[list.size()]);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ArrayList(java.util.ArrayList) ILaunchManager(org.eclipse.debug.core.ILaunchManager)

Example 68 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project jbosstools-hibernate by jbosstools.

the class ConsoleConfigurationPropertySource method createProjectDescriptor.

private IPropertyDescriptor createProjectDescriptor() {
    ComboBoxPropertyDescriptor projectDescriptor = new ComboBoxPropertyDescriptor(// $NON-NLS-1$
    "project", HibernateConsoleMessages.ConsoleConfigurationPropertySource_project, getSortedProjectNames());
    projectDescriptor.setValidator(new ICellEditorValidator() {

        public String isValid(Object value) {
            if (value instanceof Integer) {
                if (((Integer) value).intValue() < 0) {
                    try {
                        ILaunchConfiguration lc = HibernateConsolePlugin.getDefault().findLaunchConfig(cfg.getName());
                        if (lc != null) {
                            String projectName = lc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
                            if (projectName != null) {
                                return NLS.bind(HibernateConsoleMessages.ConsoleConfigurationMainTab_the_java_project_does_not_exist, projectName);
                            }
                        } else {
                            // $NON-NLS-1$//$NON-NLS-2$
                            HibernateConsolePlugin.getDefault().log("Can't find Console Configuration \"" + cfg.getName() + "\"");
                        }
                    } catch (CoreException e) {
                        HibernateConsolePlugin.getDefault().log(e);
                    }
                }
            }
            return null;
        }
    });
    return projectDescriptor;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ICellEditorValidator(org.eclipse.jface.viewers.ICellEditorValidator) ComboBoxPropertyDescriptor(org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor)

Example 69 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project jbosstools-hibernate by jbosstools.

the class ConsoleConfigurationPropertySource method getPropertyValue.

public Object getPropertyValue(Object id) {
    try {
        if ("name".equals(id)) {
            // $NON-NLS-1$
            return cfg.getName();
        }
        // TODO: bring back more eclipse friendly file names
        ConsoleConfigurationPreferences preferences = cfg.getPreferences();
        if ("project".equals(id)) {
            // $NON-NLS-1$
            try {
                ILaunchConfiguration lc = HibernateConsolePlugin.getDefault().findLaunchConfig(cfg.getName());
                if (lc != null) {
                    // $NON-NLS-1$
                    String projectName = lc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
                    return Arrays.binarySearch(getSortedProjectNames(), projectName);
                } else {
                    // $NON-NLS-1$//$NON-NLS-2$
                    HibernateConsolePlugin.getDefault().log("Can't find Console Configuration \"" + cfg.getName() + "\"");
                }
            } catch (CoreException e) {
                HibernateConsolePlugin.getDefault().log(e);
            }
        }
        if ("mode".equals(id)) {
            // $NON-NLS-1$
            String[] values = ConfigurationMode.values();
            String value = preferences.getConfigurationMode().toString();
            for (int i = 0; i < values.length; i++) {
                if (value.equals(values[i])) {
                    return i;
                }
            }
            // $NON-NLS-1$
            return new RuntimeException("Unknown ConsoleConfiguration mode: " + value);
        }
        if ("connection".equals(id)) {
            // $NON-NLS-1$
            try {
                ILaunchConfiguration lc = HibernateConsolePlugin.getDefault().findLaunchConfig(cfg.getName());
                if (lc != null) {
                    String connectionName = lc.getAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME, (String) null);
                    if (connectionName == null) {
                        connectionName = lc.getAttribute(IConsoleConfigurationLaunchConstants.USE_JPA_PROJECT_PROFILE, Boolean.FALSE.toString());
                        if (Boolean.TRUE.toString().equalsIgnoreCase(connectionName)) {
                            connectionName = HibernateConsoleMessages.ConnectionProfileCtrl_JPAConfiguredConnection;
                        } else {
                            connectionName = HibernateConsoleMessages.ConnectionProfileCtrl_HibernateConfiguredConnection;
                        }
                    }
                    String[] values = getConnectionNames();
                    for (int i = 0; i < values.length; i++) {
                        if (values[i].equals(connectionName)) {
                            return i;
                        }
                    }
                } else {
                    // $NON-NLS-1$//$NON-NLS-2$
                    HibernateConsolePlugin.getDefault().log("Can't find Console Configuration \"" + cfg.getName() + "\"");
                }
            } catch (CoreException e) {
                HibernateConsolePlugin.getDefault().log(e);
            }
        }
        if ("hibernate.cfg.xml".equals(id)) {
            // $NON-NLS-1$
            return preferences.getConfigXMLFile();
        }
        if ("hibernate.properties".equals(id)) {
            // $NON-NLS-1$
            return preferences.getPropertyFile();
        }
        if ("mapping.files".equals(id)) {
            // $NON-NLS-1$
            return Integer.valueOf(preferences.getMappingFiles().length);
        }
        return null;
    } catch (RuntimeException e) {
        return HibernateConsoleMessages.ConsoleConfigurationPropertySource_error + e.getMessage();
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences)

Example 70 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project jbosstools-hibernate by jbosstools.

the class ConsoleConfigurationPropertySource method setPropertyValue.

public void setPropertyValue(Object id, Object value) {
    if ("name".equals(id) && value instanceof String) {
        // $NON-NLS-1$
        String newName = (String) value;
        if (LaunchHelper.verifyConfigurationName(newName) != null) {
            // just do not change name
            return;
        }
        String oldName = cfg.getName();
        try {
            ILaunchConfiguration lc = HibernateConsolePlugin.getDefault().findLaunchConfig(oldName);
            if (lc != null) {
                ILaunchConfigurationWorkingCopy wc = lc.getWorkingCopy();
                wc.rename(newName);
                wc.doSave();
                // find newly created console configuration
                cfg = KnownConfigurations.getInstance().find(newName);
            } else {
                // $NON-NLS-1$//$NON-NLS-2$
                HibernateConsolePlugin.getDefault().log("Can't find Console Configuration \"" + oldName + "\"");
            }
        } catch (CoreException e) {
            HibernateConsolePlugin.getDefault().log(e);
        }
    } else if ("mode".equals(id) && value instanceof Integer) {
        // $NON-NLS-1$
        int index = (Integer) value;
        try {
            ILaunchConfiguration lc = HibernateConsolePlugin.getDefault().findLaunchConfig(cfg.getName());
            if (lc != null) {
                ILaunchConfigurationWorkingCopy wc = lc.getWorkingCopy();
                // //$NON-NLS-1$
                wc.setAttribute("org.hibernate.eclipse.launch.CONFIGURATION_FACTORY", ConfigurationMode.values()[index]);
                wc.doSave();
            } else {
                // $NON-NLS-1$//$NON-NLS-2$
                HibernateConsolePlugin.getDefault().log("Can't find Console Configuration \"" + cfg.getName() + "\"");
            }
        } catch (CoreException e) {
            // $NON-NLS-1$//$NON-NLS-2$
            HibernateConsolePlugin.getDefault().log("Can't find Console Configuration \"" + cfg.getName() + "\"");
        }
    } else if ("project".equals(id) && value instanceof Integer) {
        // $NON-NLS-1$
        int index = (Integer) value;
        try {
            ILaunchConfiguration lc = HibernateConsolePlugin.getDefault().findLaunchConfig(cfg.getName());
            if (lc != null) {
                ILaunchConfigurationWorkingCopy wc = lc.getWorkingCopy();
                String projectName = getSortedProjectNames()[index];
                wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
                if (projectName != null) {
                    wc.setAttribute(LaunchConfiguration.ATTR_MAPPED_RESOURCE_PATHS, Collections.singletonList(projectName));
                    wc.setAttribute(LaunchConfiguration.ATTR_MAPPED_RESOURCE_TYPES, Collections.singletonList(Integer.toString(IResource.PROJECT)));
                } else {
                    wc.removeAttribute(LaunchConfiguration.ATTR_MAPPED_RESOURCE_PATHS);
                    wc.removeAttribute(LaunchConfiguration.ATTR_MAPPED_RESOURCE_TYPES);
                }
                wc.doSave();
            } else {
                // $NON-NLS-1$//$NON-NLS-2$
                HibernateConsolePlugin.getDefault().log("Can't find Console Configuration \"" + cfg.getName() + "\"");
            }
        } catch (CoreException e) {
            // $NON-NLS-1$//$NON-NLS-2$
            HibernateConsolePlugin.getDefault().log("Can't find Console Configuration \"" + cfg.getName() + "\"");
        }
    } else if ("connection".equals(id) && value instanceof Integer) {
        // $NON-NLS-1$
        int index = (Integer) value;
        try {
            ILaunchConfiguration lc = HibernateConsolePlugin.getDefault().findLaunchConfig(cfg.getName());
            if (lc != null) {
                ILaunchConfigurationWorkingCopy wc = lc.getWorkingCopy();
                if (index == 0) {
                    // jpa
                    wc.setAttribute(IConsoleConfigurationLaunchConstants.USE_JPA_PROJECT_PROFILE, Boolean.TRUE.toString());
                    wc.removeAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME);
                } else if (index == 1) {
                    // hibernate
                    wc.removeAttribute(IConsoleConfigurationLaunchConstants.USE_JPA_PROJECT_PROFILE);
                    wc.removeAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME);
                } else {
                    // connection profile
                    String[] values = getConnectionNames();
                    wc.setAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME, values[index]);
                    wc.removeAttribute(IConsoleConfigurationLaunchConstants.USE_JPA_PROJECT_PROFILE);
                }
                wc.doSave();
            } else {
                // $NON-NLS-1$//$NON-NLS-2$
                HibernateConsolePlugin.getDefault().log("Can't find Console Configuration \"" + cfg.getName() + "\"");
            }
        } catch (CoreException e) {
            // $NON-NLS-1$//$NON-NLS-2$
            HibernateConsolePlugin.getDefault().log("Can't find Console Configuration \"" + cfg.getName() + "\"");
        }
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Aggregations

ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)275 CoreException (org.eclipse.core.runtime.CoreException)100 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)79 Test (org.junit.Test)72 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)51 ILaunchManager (org.eclipse.debug.core.ILaunchManager)41 ArrayList (java.util.ArrayList)37 ILaunch (org.eclipse.debug.core.ILaunch)37 IPath (org.eclipse.core.runtime.IPath)20 IProject (org.eclipse.core.resources.IProject)19 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)17 IStatus (org.eclipse.core.runtime.IStatus)16 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)16 IEditorPart (org.eclipse.ui.IEditorPart)15 IProcess (org.eclipse.debug.core.model.IProcess)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 IFile (org.eclipse.core.resources.IFile)13 Status (org.eclipse.core.runtime.Status)13 CachegrindViewPart (org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11