Search in sources :

Example 31 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project linuxtools by eclipse.

the class OpenGCDialog method handleBrowseWorkspace.

protected void handleBrowseWorkspace(String msg, Text text) {
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setTitle(msg);
    dialog.setMessage(msg);
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    dialog.setAllowMultiple(false);
    IContainer c = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(this.gcFile);
    if (c != null)
        dialog.setInitialSelection(c.getProject());
    dialog.setValidator(selection -> {
        if (selection.length != 1) {
            // $NON-NLS-1$
            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "", null);
        }
        if (!(selection[0] instanceof IFile)) {
            // $NON-NLS-1$
            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "", null);
        }
        // $NON-NLS-1$
        return new Status(IStatus.OK, Activator.PLUGIN_ID, 0, "", null);
    });
    if (dialog.open() == IDialogConstants.OK_ID) {
        IResource resource = (IResource) dialog.getFirstResult();
        // $NON-NLS-1$ //$NON-NLS-2$
        text.setText("${resource_loc:" + resource.getFullPath() + "}");
    }
}
Also used : ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 32 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project linuxtools by eclipse.

the class GprofNoGmonDialog method browseWorkspaceHandler.

/**
 * Handle the case when the user browses the Workspace.
 * @param parent
 * @return gmon.out location or null if bad.
 */
private static String browseWorkspaceHandler(Shell shell, IProject project) {
    // New tree Dialogue.
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    // Set dialogue settings.
    dialog.setTitle(GprofLaunchMessages.GprofNoGmonDialog_OpenGmon);
    dialog.setMessage(GprofLaunchMessages.GprofNoGmonDialog_OpenGmon);
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    dialog.setAllowMultiple(false);
    dialog.setInitialSelection(project);
    dialog.setValidator(selection -> {
        if (selection.length != 1) {
            // $NON-NLS-1$
            return new Status(IStatus.ERROR, GprofLaunch.PLUGIN_ID, 0, "", null);
        }
        if (!(selection[0] instanceof IFile)) {
            // $NON-NLS-1$
            return new Status(IStatus.ERROR, GprofLaunch.PLUGIN_ID, 0, "", null);
        }
        // $NON-NLS-1$
        return new Status(IStatus.OK, GprofLaunch.PLUGIN_ID, 0, "", null);
    });
    // Open dialogue.
    if (dialog.open() == IDialogConstants.OK_ID) {
        IResource resource = (IResource) dialog.getFirstResult();
        // If things were ok, return the gmon path.
        return resource.getLocation().toOSString();
    } else {
        return null;
    }
}
Also used : ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IResource(org.eclipse.core.resources.IResource)

Example 33 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project linuxtools by eclipse.

the class OpenGmonDialog method handleBrowseWorkspace.

private void handleBrowseWorkspace(String msg, Text text) {
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setTitle(msg);
    dialog.setMessage(msg);
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    dialog.setAllowMultiple(false);
    IContainer c = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(this.gmonFile);
    if (c != null) {
        dialog.setInitialSelection(c.getProject());
    }
    dialog.setValidator(selection -> {
        if (selection.length != 1) {
            // $NON-NLS-1$
            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "", null);
        }
        if (!(selection[0] instanceof IFile)) {
            // $NON-NLS-1$
            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "", null);
        }
        // $NON-NLS-1$
        return new Status(IStatus.OK, Activator.PLUGIN_ID, 0, "", null);
    });
    if (dialog.open() == IDialogConstants.OK_ID) {
        IResource resource = (IResource) dialog.getFirstResult();
        // $NON-NLS-1$//$NON-NLS-2$
        text.setText("${resource_loc:" + resource.getFullPath() + "}");
    }
}
Also used : ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 34 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project linuxtools by eclipse.

the class ValgrindOptionsTab method createSuppressionsOption.

private void createSuppressionsOption(Composite top) {
    Composite browseTop = new Composite(top, SWT.BORDER);
    browseTop.setLayout(new GridLayout(2, false));
    GridData browseData = new GridData(GridData.FILL_BOTH);
    browseTop.setLayoutData(browseData);
    Label suppFileLabel = new Label(browseTop, SWT.NONE);
    // $NON-NLS-1$
    suppFileLabel.setText(Messages.getString("ValgrindOptionsTab.suppressions_file"));
    createVerticalSpacer(browseTop, 1);
    suppFileList = new List(browseTop, SWT.BORDER);
    suppFileList.setLayoutData(new GridData(GridData.FILL_BOTH));
    Composite buttonTop = new Composite(browseTop, SWT.NONE);
    GridLayout buttonLayout = new GridLayout();
    buttonLayout.marginWidth = buttonLayout.marginHeight = 0;
    buttonTop.setLayout(buttonLayout);
    buttonTop.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, false));
    // $NON-NLS-1$
    Button workspaceBrowseButton = createPushButton(buttonTop, Messages.getString("ValgrindOptionsTab.Workspace"), null);
    workspaceBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
        // $NON-NLS-1$
        dialog.setTitle(Messages.getString("ValgrindOptionsTab.Select_a_Resource"));
        // $NON-NLS-1$
        dialog.setMessage(Messages.getString("ValgrindOptionsTab.Select_a_Suppressions_File"));
        dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
        dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
        if (dialog.open() == IDialogConstants.OK_ID) {
            IResource resource = (IResource) dialog.getFirstResult();
            String arg = resource.getFullPath().toString();
            String fileLoc = VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression("workspace_loc", // $NON-NLS-1$
            arg);
            suppFileList.add(fileLoc);
            updateLaunchConfigurationDialog();
        }
    }));
    // $NON-NLS-1$
    Button fileBrowseButton = createPushButton(buttonTop, Messages.getString("ValgrindOptionsTab.File_System"), null);
    fileBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        String filePath = null;
        FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
        filePath = dialog.open();
        if (filePath != null) {
            suppFileList.add(filePath);
            updateLaunchConfigurationDialog();
        }
    }));
    // $NON-NLS-1$
    Button removeButton = createPushButton(buttonTop, Messages.getString("ValgrindOptionsTab.Supp_remove"), null);
    removeButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        int[] selected = suppFileList.getSelectionIndices();
        if (selected.length > 0) {
            suppFileList.remove(selected);
            updateLaunchConfigurationDialog();
        }
    }));
}
Also used : WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) Arrays(java.util.Arrays) TabFolder(org.eclipse.swt.widgets.TabFolder) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) ConfigUtils(org.eclipse.linuxtools.profiling.launch.ConfigUtils) Image(org.eclipse.swt.graphics.Image) CoreException(org.eclipse.core.runtime.CoreException) Spinner(org.eclipse.swt.widgets.Spinner) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) Point(org.eclipse.swt.graphics.Point) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IStatus(org.eclipse.core.runtime.IStatus) IProject(org.eclipse.core.resources.IProject) IPath(org.eclipse.core.runtime.IPath) AbstractLaunchConfigurationTab(org.eclipse.debug.ui.AbstractLaunchConfigurationTab) VariablesPlugin(org.eclipse.core.variables.VariablesPlugin) Composite(org.eclipse.swt.widgets.Composite) AbstractUIPlugin(org.eclipse.ui.plugin.AbstractUIPlugin) GridData(org.eclipse.swt.layout.GridData) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) TabItem(org.eclipse.swt.widgets.TabItem) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Button(org.eclipse.swt.widgets.Button) NLS(org.eclipse.osgi.util.NLS) FileDialog(org.eclipse.swt.widgets.FileDialog) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) Status(org.eclipse.core.runtime.Status) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Version(org.osgi.framework.Version) Group(org.eclipse.swt.widgets.Group) ModifyListener(org.eclipse.swt.events.ModifyListener) IResource(org.eclipse.core.resources.IResource) SWT(org.eclipse.swt.SWT) List(org.eclipse.swt.widgets.List) IValgrindToolPage(org.eclipse.linuxtools.valgrind.launch.IValgrindToolPage) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Label(org.eclipse.swt.widgets.Label) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) List(org.eclipse.swt.widgets.List) FileDialog(org.eclipse.swt.widgets.FileDialog) IResource(org.eclipse.core.resources.IResource)

Example 35 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project webtools.sourceediting by eclipse.

the class ResourceSelectionBlock method openWorkspaceResourceDialog.

protected IPath openWorkspaceResourceDialog() {
    IResource currentResource = getResource();
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setTitle(getMessage(WORKSPACE_DIALOG_TITLE));
    dialog.setMessage(getMessage(WORKSPACE_DIALOG_MESSAGE));
    dialog.setValidator(validator);
    dialog.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof IContainer)
                return true;
            if (resourceType != IResource.FILE)
                return false;
            IFile file = (IFile) element;
            String[] extensions = getFileExtensions();
            if (extensions == null)
                return true;
            String fileExt = file.getFileExtension();
            if (fileExt != null) {
                for (String ext : extensions) {
                    if (fileExt.equalsIgnoreCase(ext))
                        return true;
                }
            }
            return false;
        }
    });
    ViewerFilter filter = getResourceFilter();
    if (filter != null)
        dialog.addFilter(filter);
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    dialog.setInitialSelection(currentResource);
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    dialog.setAllowMultiple(false);
    if (dialog.open() == Window.OK) {
        Object[] elements = dialog.getResult();
        if (elements.length > 0)
            return ((IResource) elements[0]).getFullPath();
    }
    return null;
}
Also used : ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Viewer(org.eclipse.jface.viewers.Viewer) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Aggregations

WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)53 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)42 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)32 IResource (org.eclipse.core.resources.IResource)27 IFile (org.eclipse.core.resources.IFile)18 ResourceComparator (org.eclipse.ui.views.navigator.ResourceComparator)18 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)16 IContainer (org.eclipse.core.resources.IContainer)15 IPath (org.eclipse.core.runtime.IPath)14 ArrayList (java.util.ArrayList)12 IStatus (org.eclipse.core.runtime.IStatus)12 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)12 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)11 ISelectionStatusValidator (org.eclipse.ui.dialogs.ISelectionStatusValidator)11 CoreException (org.eclipse.core.runtime.CoreException)10 Status (org.eclipse.core.runtime.Status)10 Composite (org.eclipse.swt.widgets.Composite)10 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)9 GridData (org.eclipse.swt.layout.GridData)9 Button (org.eclipse.swt.widgets.Button)9