Search in sources :

Example 81 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project egit by eclipse.

the class DiscardChangesActionHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // capture selection from active part as long as we have context
    mySelection = getSelection(event);
    try {
        IWorkbenchPart part = getPart(event);
        String question = UIText.DiscardChangesAction_confirmActionMessage;
        ILaunchConfiguration launch = LaunchFinder.getRunningLaunchConfiguration(Arrays.asList(getRepositories()), null);
        if (launch != null) {
            question = MessageFormat.format(question, "\n\n" + // $NON-NLS-1$
            MessageFormat.format(UIText.LaunchFinder_RunningLaunchMessage, launch.getName()));
        } else {
            // $NON-NLS-1$
            question = MessageFormat.format(question, "");
        }
        boolean performAction = openConfirmationDialog(event, question);
        if (!performAction) {
            return null;
        }
        final DiscardChangesOperation operation = createOperation(part, event);
        if (operation == null) {
            return null;
        }
        String jobname = UIText.DiscardChangesAction_discardChanges;
        Job job = new WorkspaceJob(jobname) {

            @Override
            public IStatus runInWorkspace(IProgressMonitor monitor) {
                try {
                    operation.execute(monitor);
                } catch (CoreException e) {
                    return Activator.createErrorStatus(e.getStatus().getMessage(), e);
                }
                return Status.OK_STATUS;
            }

            @Override
            public boolean belongsTo(Object family) {
                if (JobFamilies.DISCARD_CHANGES.equals(family)) {
                    return true;
                }
                return super.belongsTo(family);
            }
        };
        job.setUser(true);
        job.setRule(operation.getSchedulingRule());
        job.schedule();
        return null;
    } finally {
        // cleanup mySelection to avoid side effects later after execution
        mySelection = null;
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) DiscardChangesOperation(org.eclipse.egit.core.op.DiscardChangesOperation) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob)

Example 82 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project statecharts by Yakindu.

the class StatechartLaunchShortcut method launch.

protected void launch(IFile file, String mode) {
    showConsole();
    final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    final ILaunchConfigurationType configType = launchManager.getLaunchConfigurationType(getConfigType());
    ILaunchConfiguration launchConfig = findLaunchConfiguration(configType, file);
    if (launchConfig != null) {
        DebugUITools.launch(launchConfig, mode);
    } else {
        ILaunchConfiguration launchConfiguration = createNewLaunchConfiguration(file);
        DebugUITools.launch(launchConfiguration, mode);
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager)

Example 83 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project titan.EclipsePlug-ins by eclipse.

the class AstRunnerJava method run.

public void run(IAction action) {
    boolean projectfound = false;
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (IProject p : projects) {
        if (p.getName().equals("org.eclipse.titan.codegenerator.output"))
            projectfound = true;
    }
    if (projectfound) {
        ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
        ILaunchConfigurationType type = manager.getLaunchConfigurationType("org.eclipse.jdt.launching.localJavaApplication");
        try {
            ILaunchConfiguration[] lcs = manager.getLaunchConfigurations(type);
            for (ILaunchConfiguration l : lcs) {
                if (l.getName().equals("org.eclipse.titan.codegenerator.output.MC"))
                    l.delete();
                if (l.getName().equals("org.eclipse.titan.codegenerator.output.HC"))
                    l.delete();
            }
            ILaunchConfigurationWorkingCopy mcrc = type.newInstance(null, "org.eclipse.titan.codegenerator.output.MC");
            List<String> mcrespaths = new ArrayList<String>();
            mcrespaths.add("/org.eclipse.titan.codegenerator.output/src/org/eclipse/titan/codegenerator/TTCN3JavaAPI/MC.java");
            mcrc.setAttribute("org.eclipse.debug.core.MAPPED_RESOURCE_PATHS", mcrespaths);
            List<String> mcrestypes = new ArrayList<String>();
            mcrestypes.add("1");
            mcrc.setAttribute("org.eclipse.debug.core.MAPPED_RESOURCE_TYPES", mcrestypes);
            mcrc.setAttribute("org.eclipse.jdt.launching.MAIN_TYPE", "org.eclipse.titan.codegenerator.TTCN3JavaAPI.MC");
            mcrc.setAttribute("org.eclipse.jdt.launching.PROJECT_ATTR", "org.eclipse.titan.codegenerator.output");
            DebugUITools.launch(mcrc, ILaunchManager.RUN_MODE);
            ILaunchConfigurationWorkingCopy hcrc = type.newInstance(null, "org.eclipse.titan.codegenerator.output.HC");
            List<String> hcrespaths = new ArrayList<String>();
            hcrespaths.add("/org.eclipse.titan.codegenerator.output/src/org/eclipse/titan/codegenerator/javagen/HC.java");
            hcrc.setAttribute("org.eclipse.debug.core.MAPPED_RESOURCE_PATHS", hcrespaths);
            List<String> hcrestypes = new ArrayList<String>();
            hcrestypes.add("1");
            hcrc.setAttribute("org.eclipse.debug.core.MAPPED_RESOURCE_TYPES", hcrestypes);
            hcrc.setAttribute("org.eclipse.jdt.launching.MAIN_TYPE", "org.eclipse.titan.codegenerator.javagen.HC");
            hcrc.setAttribute("org.eclipse.jdt.launching.PROJECT_ATTR", "org.eclipse.titan.codegenerator.output");
            DebugUITools.launch(hcrc, ILaunchManager.RUN_MODE);
        } catch (Exception e) {
        }
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ArrayList(java.util.ArrayList) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IProject(org.eclipse.core.resources.IProject) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException)

Example 84 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project titan.EclipsePlug-ins by eclipse.

the class LaunchShortcut method launch.

@Override
public final void launch(final ISelection selection, final String mode) {
    if (!(selection instanceof IStructuredSelection)) {
        return;
    }
    final Object[] selections = ((IStructuredSelection) selection).toArray();
    if (1 != selections.length) {
        return;
    }
    IFile cfgFile = null;
    IProject project = null;
    if ((selections[0] instanceof IProject)) {
        // try to find the cfg file:
        project = (IProject) selections[0];
        List<IFile> cfgFiles = ProjectFileHandler.getCfgFiles(project);
        if (cfgFiles.size() == 1) {
            cfgFile = cfgFiles.get(0);
        } else if (cfgFiles.size() > 1) {
            final ILabelProvider labelProvider = DebugUITools.newDebugModelPresentation();
            final ElementListSelectionDialog dialog = new ElementListSelectionDialog(null, labelProvider);
            dialog.setTitle("Config File Selection");
            dialog.setMessage("Select existing cfg file:");
            dialog.setElements(cfgFiles.toArray(new IFile[cfgFiles.size()]));
            if (dialog.open() == Window.OK) {
                cfgFile = (IFile) dialog.getFirstResult();
            }
        } else {
            ErrorReporter.logError("Config file not found");
            ErrorReporter.parallelErrorDisplayInMessageDialog("An error was found while creating the default launch configuration for project " + project.getName(), "Config file not found in project " + project.getName());
            return;
        }
    } else {
        return;
    }
    if (project == null || cfgFile == null) {
        return;
    }
    final ILaunchConfigurationWorkingCopy wc = getWorkingCopy(project, cfgFile, mode);
    if (wc == null) {
        // successful launch happened
        return;
    }
    boolean result = initLaunchConfiguration(wc, project, cfgFile.getLocation().toOSString());
    if (result) {
        result = HostControllersTab.initLaunchConfiguration(wc);
    }
    try {
        if (result) {
            ILaunchConfiguration conf = wc.doSave();
            conf.launch(mode, null);
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IProject(org.eclipse.core.resources.IProject)

Example 85 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project titan.EclipsePlug-ins by eclipse.

the class LaunchShortcutConfig method launch.

@Override
public final void launch(final ISelection selection, final String mode) {
    if (!(selection instanceof IStructuredSelection)) {
        return;
    }
    final Object[] selections = ((IStructuredSelection) selection).toArray();
    if (1 != selections.length) {
        return;
    }
    if (!(selections[0] instanceof IFile)) {
        // Is it necessary???
        ErrorReporter.logError("Config file not found");
        return;
    }
    final IFile file = (IFile) selections[0];
    final IProject project = file.getProject();
    if (project == null) {
        ErrorReporter.logError("Project file not found");
        return;
    }
    try {
        final ILaunchConfigurationWorkingCopy wc = getWorkingCopy(project, file, mode);
        if (wc == null) {
            // successful launch
            return;
        }
        boolean result = initLaunchConfiguration(wc, project, file.getLocation().toOSString());
        if (result) {
            result = HostControllersTab.initLaunchConfiguration(wc);
        }
        if (result) {
            wc.setMappedResources(new IResource[] { project, file });
            wc.setAttribute(EXECUTECONFIGFILEONLAUNCH, true);
            final ILaunchConfiguration conf = wc.doSave();
            conf.launch(mode, null);
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IProject(org.eclipse.core.resources.IProject)

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