Search in sources :

Example 11 with ILaunchConfiguration

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

the class PerfOpenData method createDefaultConfiguration.

/**
 * Create an ILaunchConfiguration instance given the project's name.
 *
 * @param projectName
 * @return ILaunchConfiguration based on String projectName
 */
private ILaunchConfiguration createDefaultConfiguration(String projectName) {
    ILaunchConfiguration config = null;
    try {
        ILaunchConfigurationType configType = getLaunchConfigType();
        ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(projectName));
        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
        config = wc;
    } catch (CoreException e) {
        PerfCore.logException(e);
    }
    return config;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 12 with ILaunchConfiguration

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

the class PerfOpenData method open.

@Override
public void open(IPath file) {
    // get project name of where the file resides.
    String projectName = null;
    IFile location = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(file);
    // If unable to get location from workspace, try getting from current file selection
    if (location == null) {
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        ISelection selection = page.getSelection();
        if (selection instanceof ITreeSelection) {
            Object element = ((ITreeSelection) selection).getFirstElement();
            if (element instanceof IFile) {
                IFile eFile = (IFile) element;
                IProject project = eFile.getProject();
                projectName = project.getName();
                URI fileURI = ((IFile) element).getLocationURI();
                ILaunchConfiguration config = createDefaultConfiguration(projectName);
                PerfCore.report(config, null, null, fileURI.getPath(), null);
                String timestamp = DateFormat.getInstance().format(new Date(eFile.getLocalTimeStamp()));
                // $NON-NLS-1$ //$NON-NLS-2$
                PerfCore.refreshView(fileURI.toString() + " (" + timestamp + ")");
            }
        }
    } else {
        projectName = location.getProject().getName();
        ILaunchConfiguration config = createDefaultConfiguration(projectName);
        PerfCore.report(config, null, null, file.toOSString(), null);
        String timestamp = DateFormat.getInstance().format(new Date(location.getLocalTimeStamp()));
        // $NON-NLS-1$ //$NON-NLS-2$
        PerfCore.refreshView(file.toOSString() + " (" + timestamp + ")");
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IFile(org.eclipse.core.resources.IFile) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) Date(java.sql.Date)

Example 13 with ILaunchConfiguration

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

the class AbstractEventConfigTab method initializeFrom.

@Override
public void initializeFrom(ILaunchConfiguration config) {
    IProject previousProject = getOprofileProject();
    IProject project = getProject(config);
    setOprofileProject(project);
    updateOprofileInfo();
    String previousHost = null;
    if (previousProject != null) {
        if (previousProject.getLocationURI() != null) {
            previousHost = previousProject.getLocationURI().getHost();
        }
    }
    String host;
    if (project != null) {
        host = project.getLocationURI().getHost();
    } else {
        host = null;
    }
    // Any calculation based on project doesn't work as the very first time for local project they are both null.
    if (previousProject == null || previousHost != host || host == null || counters == null) {
        Control[] children = top.getChildren();
        for (Control control : children) {
            control.dispose();
        }
        OprofileCounter[] ctrs = getOprofileCounters(null);
        if (getOprofileTimerMode() || (ctrs.length > 0 && ctrs[0].getValidEvents() == null)) {
            Label timerModeLabel = new Label(top, SWT.LEFT);
            // $NON-NLS-1$
            timerModeLabel.setText(OprofileLaunchMessages.getString("tab.event.timermode.no.options"));
        } else {
            createVerticalSpacer(top, 1);
            // default event checkbox
            defaultEventCheck = new Button(top, SWT.CHECK);
            // $NON-NLS-1$
            defaultEventCheck.setText(OprofileLaunchMessages.getString("tab.event.defaultevent.button.text"));
            defaultEventCheck.setLayoutData(new GridData());
            defaultEventCheck.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> handleEnabledToggle()));
            createVerticalSpacer(top, 1);
            createCounterTabs(top);
        }
    }
    if (!getOprofileTimerMode()) {
        if (counters == null) {
            // $NON-NLS-1$
            OprofileCorePlugin.showErrorDialog("countersNotFound", null);
            return;
        }
        for (int i = 0; i < counters.length; i++) {
            counters[i].loadConfiguration(config);
        }
        for (CounterSubTab tab : counterSubTabs) {
            tab.initializeTab(config);
            tab.createEventsFilter();
        }
        try {
            boolean enabledState = config.getAttribute(OprofileLaunchPlugin.ATTR_USE_DEFAULT_EVENT, true);
            defaultEventCheck.setSelection(enabledState);
            setEnabledState(!enabledState);
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
}
Also used : IShellProvider(org.eclipse.jface.window.IShellProvider) Arrays(java.util.Arrays) TabFolder(org.eclipse.swt.widgets.TabFolder) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Image(org.eclipse.swt.graphics.Image) CoreException(org.eclipse.core.runtime.CoreException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Event(org.eclipse.swt.widgets.Event) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ListViewer(org.eclipse.jface.viewers.ListViewer) IProject(org.eclipse.core.resources.IProject) AbstractLaunchConfigurationTab(org.eclipse.debug.ui.AbstractLaunchConfigurationTab) Composite(org.eclipse.swt.widgets.Composite) Listener(org.eclipse.swt.widgets.Listener) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) OprofileLaunchPlugin(org.eclipse.linuxtools.internal.oprofile.launch.OprofileLaunchPlugin) GridData(org.eclipse.swt.layout.GridData) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TabItem(org.eclipse.swt.widgets.TabItem) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) Viewer(org.eclipse.jface.viewers.Viewer) Button(org.eclipse.swt.widgets.Button) Display(org.eclipse.swt.widgets.Display) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) OpUnitMask(org.eclipse.linuxtools.internal.oprofile.core.daemon.OpUnitMask) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) List(java.util.List) OpEvent(org.eclipse.linuxtools.internal.oprofile.core.daemon.OpEvent) ICDTLaunchConfigurationConstants(org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) OprofileLaunchMessages(org.eclipse.linuxtools.internal.oprofile.launch.OprofileLaunchMessages) Dialog(org.eclipse.jface.dialogs.Dialog) SWT(org.eclipse.swt.SWT) OprofileProject(org.eclipse.linuxtools.internal.oprofile.core.Oprofile.OprofileProject) OprofileCorePlugin(org.eclipse.linuxtools.internal.oprofile.core.OprofileCorePlugin) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Label(org.eclipse.swt.widgets.Label) LabelProvider(org.eclipse.jface.viewers.LabelProvider) OprofileDaemonEvent(org.eclipse.linuxtools.internal.oprofile.core.daemon.OprofileDaemonEvent) Control(org.eclipse.swt.widgets.Control) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Label(org.eclipse.swt.widgets.Label) IProject(org.eclipse.core.resources.IProject) Control(org.eclipse.swt.widgets.Control) CoreException(org.eclipse.core.runtime.CoreException) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData)

Example 14 with ILaunchConfiguration

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

the class ProfileLaunchShortcut method createConfiguration.

/**
 * Create a launch configuration based on a binary, and optionally
 * save it to the underlying resource.
 *
 * @param bin a representation of a binary
 * @param save true if the configuration should be saved to the
 * underlying resource, and false if it should not be saved.
 * @return a launch configuration generated for the binary.
 * @since 1.2
 */
protected ILaunchConfiguration createConfiguration(IBinary bin, boolean save) {
    ILaunchConfiguration config = null;
    try {
        String projectName = bin.getResource().getProjectRelativePath().toString();
        ILaunchConfigurationType configType = getLaunchConfigType();
        ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(bin.getElementName()));
        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, projectName);
        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, bin.getCProject().getElementName());
        wc.setMappedResources(new IResource[] { bin.getResource(), bin.getResource().getProject() });
        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
        setDefaultProfileAttributes(wc);
        if (save) {
            config = wc.doSave();
        } else {
            config = wc;
        }
    } catch (CoreException e) {
        e.printStackTrace();
    }
    return config;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 15 with ILaunchConfiguration

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

the class ProfileLaunchShortcut method chooseConfiguration.

/**
 * Show a selection dialog that allows the user to choose one of the specified
 * launch configurations.
 * @param configList The list of launch configurations to choose from.
 * @param mode Currently unused.
 * @return The chosen config, or <code>null</code> if the user cancelled the dialog.
 */
// TODO remove not used mode parameter for 4.0.
protected ILaunchConfiguration chooseConfiguration(List<ILaunchConfiguration> configList, String mode) {
    IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
    ElementListSelectionDialog dialog = new ElementListSelectionDialog(getActiveWorkbenchShell(), labelProvider);
    dialog.setElements(configList.toArray());
    dialog.setTitle(Messages.ProfileLaunchShortcut_Launch_Configuration_Selection);
    dialog.setMessage(Messages.ProfileLaunchShortcut_Choose_a_launch_configuration);
    dialog.setMultipleSelection(false);
    int result = dialog.open();
    labelProvider.dispose();
    if (result == Window.OK) {
        return (ILaunchConfiguration) dialog.getFirstResult();
    }
    return null;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) IDebugModelPresentation(org.eclipse.debug.ui.IDebugModelPresentation)

Aggregations

ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)266 CoreException (org.eclipse.core.runtime.CoreException)96 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)76 Test (org.junit.Test)72 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)50 ILaunchManager (org.eclipse.debug.core.ILaunchManager)40 ArrayList (java.util.ArrayList)37 ILaunch (org.eclipse.debug.core.ILaunch)35 IProject (org.eclipse.core.resources.IProject)20 IPath (org.eclipse.core.runtime.IPath)20 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)16 IEditorPart (org.eclipse.ui.IEditorPart)15 IStatus (org.eclipse.core.runtime.IStatus)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 IFile (org.eclipse.core.resources.IFile)13 IProcess (org.eclipse.debug.core.model.IProcess)13 CachegrindViewPart (org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart)13 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)11 Shell (org.eclipse.swt.widgets.Shell)10 ElementListSelectionDialog (org.eclipse.ui.dialogs.ElementListSelectionDialog)10