Search in sources :

Example 11 with ResourceComparator

use of org.eclipse.ui.views.navigator.ResourceComparator 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 12 with ResourceComparator

use of org.eclipse.ui.views.navigator.ResourceComparator 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 13 with ResourceComparator

use of org.eclipse.ui.views.navigator.ResourceComparator 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 14 with ResourceComparator

use of org.eclipse.ui.views.navigator.ResourceComparator 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)

Example 15 with ResourceComparator

use of org.eclipse.ui.views.navigator.ResourceComparator in project webtools.sourceediting by eclipse.

the class AddWorkspaceFileAction method run.

@Override
public void run() {
    // ViewerFilter filter= new StylesheetFilter(getSelectedJars());
    ILabelProvider lp = new WorkbenchLabelProvider();
    ITreeContentProvider cp = new WorkbenchContentProvider();
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), lp, cp);
    dialog.setValidator(validator);
    dialog.setTitle(Messages.AddWorkspaceFileAction_DialogTitle);
    dialog.setMessage(Messages.AddWorkspaceFileAction_DialogMessage);
    dialog.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (!(element instanceof IResource))
                return false;
            IResource resource = (IResource) element;
            if (resource.getType() == IResource.FILE) {
                if (!XSLCore.isXSLFile((IFile) resource))
                    return false;
            }
            return true;
        }
    });
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    if (dialog.open() == Window.OK) {
        Object[] elements = dialog.getResult();
        LaunchTransform[] res = new LaunchTransform[elements.length];
        for (int i = 0; i < res.length; i++) {
            IResource elem = (IResource) elements[i];
            res[i] = new LaunchTransform(elem.getFullPath().toPortableString(), LaunchTransform.RESOURCE_TYPE);
        }
        addTransforms(res);
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Viewer(org.eclipse.jface.viewers.Viewer) StylesheetViewer(org.eclipse.wst.xsl.internal.debug.ui.tabs.main.StylesheetViewer) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IResource(org.eclipse.core.resources.IResource)

Aggregations

ResourceComparator (org.eclipse.ui.views.navigator.ResourceComparator)20 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)19 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)18 IResource (org.eclipse.core.resources.IResource)17 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)17 IPath (org.eclipse.core.runtime.IPath)7 IStatus (org.eclipse.core.runtime.IStatus)7 IContainer (org.eclipse.core.resources.IContainer)6 IFile (org.eclipse.core.resources.IFile)6 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)6 Status (org.eclipse.core.runtime.Status)6 ArrayList (java.util.ArrayList)5 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)4 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)4 SelectionListener (org.eclipse.swt.events.SelectionListener)4 GridData (org.eclipse.swt.layout.GridData)4 Button (org.eclipse.swt.widgets.Button)4 Composite (org.eclipse.swt.widgets.Composite)4 ResourcesPlugin (org.eclipse.core.resources.ResourcesPlugin)3 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)3