Search in sources :

Example 6 with ResourceComparator

use of org.eclipse.ui.views.navigator.ResourceComparator in project jbosstools-hibernate by jbosstools.

the class HibernatePropertiesComposite method createSetupAction.

private Runnable createSetupAction() {
    return new Runnable() {

        @Override
        public void run() {
            IPath initialPath = getConfigurationFilePath();
            int defaultChoice = 0;
            if (initialPath != null) {
                defaultChoice = 1;
            }
            MessageDialog dialog = createSetupDialog(HibernateConsoleMessages.ConsoleConfigurationMainTab_setup_configuration_file, HibernateConsoleMessages.ConsoleConfigurationMainTab_do_you_want_to_create_new_cfgxml, defaultChoice);
            int answer = dialog.open();
            IPath cfgFile = null;
            if (answer == 0) {
                // create new
                cfgFile = handleConfigurationFileCreate();
            } else if (answer == 1) {
                // use existing
                cfgFile = handleConfigurationFileBrowse();
            }
            if (cfgFile != null) {
                HibernatePropertiesComposite.this.cfgFile.setText(makeClassPathRelative(cfgFile).toString());
            }
        }

        protected IPath makeClassPathRelative(IPath cfgFile) {
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IResource res = root.findMember(cfgFile);
            if (res != null && res.exists() && res.getType() == IResource.FILE) {
                IPackageFragmentRoot[] allPackageFragmentRoots = getSourcePackageFragmentRoots();
                for (IPackageFragmentRoot iPackageFragmentRoot : allPackageFragmentRoots) {
                    if (iPackageFragmentRoot.getResource().getFullPath().isPrefixOf(cfgFile)) {
                        cfgFile = cfgFile.removeFirstSegments(iPackageFragmentRoot.getResource().getFullPath().segmentCount());
                        return cfgFile;
                    }
                }
            }
            return res.getLocation();
        }

        private MessageDialog createSetupDialog(String title, String question, int defaultChoice) {
            return new MessageDialog(getShell(), title, null, question, MessageDialog.QUESTION, new String[] { HibernateConsoleMessages.ConsoleConfigurationMainTab_create_new, HibernateConsoleMessages.ConsoleConfigurationMainTab_use_existing, IDialogConstants.CANCEL_LABEL }, defaultChoice);
        }

        private IPath handleConfigurationFileBrowse() {
            IPath[] paths = chooseFileEntries();
            if (paths != null && paths.length == 1) {
                return paths[0];
            }
            return null;
        }

        public IPath[] chooseFileEntries() {
            TypedElementSelectionValidator validator = new TypedElementSelectionValidator(new Class[] { IFile.class }, false);
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IResource focus = getConfigurationFilePath() != null ? root.findMember(getConfigurationFilePath()) : null;
            ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider() {

                public Object[] getElements(Object element) {
                    IPackageFragmentRoot[] sourcePackageFragmentRoots = getSourcePackageFragmentRoots();
                    IResource[] ress = new IResource[sourcePackageFragmentRoots.length];
                    for (int i = 0; i < sourcePackageFragmentRoots.length; i++) {
                        ress[i] = sourcePackageFragmentRoots[i].getResource();
                    }
                    return ress;
                }
            });
            dialog.setValidator(validator);
            dialog.setAllowMultiple(false);
            dialog.setTitle(HibernateConsoleMessages.ConsoleConfigurationMainTab_select_hibernate_cfg_xml_file);
            dialog.setMessage(HibernateConsoleMessages.ConsoleConfigurationMainTab_choose_file_to_use_as_hibernate_cfg_xml);
            dialog.addFilter(new FileFilter(new String[] { HibernateConsoleMessages.ConsoleConfigurationMainTab_cfg_xml }, null, true, false));
            dialog.setInput(root);
            dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
            dialog.setInitialSelection(focus);
            if (dialog.open() == Window.OK) {
                Object[] elements = dialog.getResult();
                IPath[] res = new IPath[elements.length];
                for (int i = 0; i < res.length; i++) {
                    IResource elem = (IResource) elements[i];
                    res[i] = elem.getFullPath();
                }
                return res;
            }
            return null;
        }

        private IPath handleConfigurationFileCreate() {
            NewConfigurationWizard wizard = new NewConfigurationWizard();
            wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
            IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            WizardDialog wdialog = new WizardDialog(win.getShell(), wizard);
            wdialog.create();
            IWizardPage configPage = wizard.getPage(HibernateConsoleMessages.ConsoleConfigurationMainTab_wizard_page);
            if (configPage != null && configPage instanceof NewConfigurationWizardPage) {
                ((NewConfigurationWizardPage) configPage).setCreateConsoleConfigurationVisible(false);
            }
            // This opens a dialog
            if (wdialog.open() == Window.OK) {
                WizardNewFileCreationPage createdFilePath = ((WizardNewFileCreationPage) wizard.getStartingPage());
                if (createdFilePath != null) {
                    // createNewFile() does not creates new file if it was created by wizard (OK was pressed)
                    return createdFilePath.createNewFile().getFullPath();
                }
            }
            return null;
        }
    };
}
Also used : ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IPath(org.eclipse.core.runtime.IPath) NewConfigurationWizard(org.hibernate.eclipse.console.wizards.NewConfigurationWizard) WizardNewFileCreationPage(org.eclipse.ui.dialogs.WizardNewFileCreationPage) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) TypedElementSelectionValidator(org.eclipse.jdt.internal.ui.wizards.TypedElementSelectionValidator) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) NewConfigurationWizardPage(org.hibernate.eclipse.console.wizards.NewConfigurationWizardPage) IWizardPage(org.eclipse.jface.wizard.IWizardPage) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) FileFilter(org.hibernate.eclipse.console.FileFilter) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IResource(org.eclipse.core.resources.IResource)

Example 7 with ResourceComparator

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

the class ProcessorLibraryBlock method addWorkspace.

private void addWorkspace(IStructuredSelection selection) {
    IDialogSettings dialogSettings = XSLDebugUIPlugin.getDefault().getDialogSettings();
    String lastUsedPath = dialogSettings.get(LAST_WORKSPACE_PATH_SETTING);
    IPath lastPath = null;
    if (lastUsedPath != null) {
        lastPath = Path.fromPortableString(lastUsedPath);
    }
    // IResource currentResource = getResource();
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(tableViewer.getControl().getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setTitle(Messages.ProcessorLibraryBlock_WorkspaceFileDialog_Title);
    dialog.setMessage(Messages.ProcessorLibraryBlock_WorkspaceFileDialog_Message);
    dialog.setValidator(validator);
    dialog.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof IContainer)
                return true;
            else if (element instanceof IFile) {
                IFile file = (IFile) element;
                String extension = file.getFileExtension();
                if (extension == null)
                    return false;
                // $NON-NLS-1$
                return extension.equals("jar");
            }
            return false;
        }
    });
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    if (lastPath != null)
        dialog.setInitialSelection(lastPath);
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    dialog.setAllowMultiple(true);
    if (dialog.open() == Window.OK) {
        Object[] elements = dialog.getResult();
        if (elements.length > 0) {
            IProcessorJar[] libs = new IProcessorJar[elements.length];
            for (int i = 0; i < elements.length; i++) {
                IFile jar = (IFile) elements[i];
                libs[i] = JAXPRuntime.createProcessorJar(jar.getFullPath());
            }
            IProcessorJar[] currentJars = install.getProcessorJars();
            IProcessorJar[] newJars = new IProcessorJar[currentJars.length + libs.length];
            System.arraycopy(currentJars, 0, newJars, 0, currentJars.length);
            System.arraycopy(libs, 0, newJars, currentJars.length, libs.length);
            install.setProcessorJars(newJars);
            tableViewer.add(libs);
            lastPath = libs[0].getPath();
            lastPath = lastPath.uptoSegment(lastPath.segmentCount());
            dialogSettings.put(LAST_WORKSPACE_PATH_SETTING, lastPath.toPortableString());
        }
    }
}
Also used : ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IProcessorJar(org.eclipse.wst.xsl.jaxp.launching.IProcessorJar) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) IContainer(org.eclipse.core.resources.IContainer)

Example 8 with ResourceComparator

use of org.eclipse.ui.views.navigator.ResourceComparator in project tdi-studio-se by Talend.

the class AddResourceAction method run.

/**
     * Prompts for a jar to add.
     * 
     * @see IAction#run()
     */
@Override
public void run() {
    // ViewerFilter filter = new ArchiveFilter(getSelectedJars());
    ILabelProvider lp = new WorkbenchLabelProvider();
    ITreeContentProvider cp = new WorkbenchContentProvider();
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), lp, cp);
    dialog.setValidator(validator);
    //$NON-NLS-1$
    dialog.setTitle(Messages.getString("AddResourceAction.JARSecection"));
    //$NON-NLS-1$
    dialog.setMessage(Messages.getString("AddResourceAction.ChooseResource"));
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot().getProject(PluginConstant.COMPONENT_PROJECT));
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    if (dialog.open() == Window.OK) {
        Object[] elements = dialog.getResult();
        List<ILibEntry> res = new ArrayList<ILibEntry>();
        for (int i = 0; i < elements.length; i++) {
            IResource elem = (IResource) elements[i];
            String name = elem.getName();
            if (name.matches("(?i).*\\.(jar)\\b")) {
                //$NON-NLS-1$
                res.add(new JarLibEntry(elem));
            }
            if (name.matches("(?i).*\\.(pm)\\b")) {
                //$NON-NLS-1$
                res.add(new PmLibEntry(elem));
            }
        }
        if (res.size() > 0) {
            ILibEntry[] entries = new ILibEntry[res.size()];
            getViewer().addEntries(res.toArray(entries));
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) JarLibEntry(org.talend.componentdesigner.model.libentry.JarLibEntry) ArrayList(java.util.ArrayList) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ILibEntry(org.talend.componentdesigner.model.ILibEntry) PmLibEntry(org.talend.componentdesigner.model.libentry.PmLibEntry) IResource(org.eclipse.core.resources.IResource)

Example 9 with ResourceComparator

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

the class SystemTapOptionsTab method createFileOption.

private void createFileOption(Composite top) {
    Composite browseTop = new Composite(top, SWT.NONE);
    browseTop.setLayout(new GridLayout(4, false));
    browseTop.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Label suppFileLabel = new Label(browseTop, SWT.NONE);
    // $NON-NLS-1$
    suppFileLabel.setText(Messages.getString("SystemTapOptionsTab.ScriptSelector"));
    scriptFile = new Text(browseTop, SWT.BORDER);
    scriptFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    scriptFile.addModifyListener(modifyListener);
    // $NON-NLS-1$
    workspaceBrowseButton = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton"), null);
    workspaceBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
        // $NON-NLS-1$
        dialog.setTitle(Messages.getString("SystemTapOptionsTab.ResourceButton"));
        // $NON-NLS-1$
        dialog.setMessage(Messages.getString("SystemTapOptionsTab.SuppresionsFile"));
        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();
            scriptFile.setText(workspacePath + arg);
        }
    }));
    // $NON-NLS-1$
    fileBrowseButton = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.FileSystem"), null);
    fileBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        String filePath = scriptFile.getText();
        FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
        filePath = dialog.open();
        if (filePath != null) {
            scriptFile.setText(filePath);
        }
    }));
    Label binaryFileLabel = new Label(browseTop, SWT.NONE);
    // $NON-NLS-1$
    binaryFileLabel.setText(Messages.getString("SystemTapOptionsTab.SelectBinary"));
    binaryFile = new Text(browseTop, SWT.BORDER);
    binaryFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    binaryFile.addModifyListener(modifyListener);
    // $NON-NLS-1$
    Button workspaceBrowseButton2 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton2"), null);
    workspaceBrowseButton2.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
        // $NON-NLS-1$
        dialog.setTitle(Messages.getString("SystemTapOptionsTab.SelectResource"));
        // $NON-NLS-1$
        dialog.setMessage(Messages.getString("SystemTapOptionsTab.SelectSuppressions"));
        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();
            binaryFile.setText(workspacePath + arg);
        }
    }));
    // $NON-NLS-1$
    Button fileBrowseButton2 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.BrowseFiles"), null);
    fileBrowseButton2.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        String filePath = binaryFile.getText();
        FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
        filePath = dialog.open();
        if (filePath != null) {
            File file = new File(filePath);
            if (file.exists())
                binaryFile.setText(filePath);
        }
    }));
    Label outputFileLabel = new Label(browseTop, SWT.NONE);
    // $NON-NLS-1$
    outputFileLabel.setText(Messages.getString("SystemTapOptionsTab.SelectOutput"));
    outputFile = new Text(browseTop, SWT.BORDER);
    outputFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    outputFile.addModifyListener(modifyListenerOutput);
    outputFile.addFocusListener(focusListener);
    // $NON-NLS-1$
    Button workspaceBrowseButton3 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton2"), null);
    workspaceBrowseButton3.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
        // $NON-NLS-1$
        dialog.setTitle(Messages.getString("SystemTapOptionsTab.SelectResource"));
        // $NON-NLS-1$
        dialog.setMessage(Messages.getString("SystemTapOptionsTab.SelectSuppressions"));
        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();
            outputFile.setText(workspacePath + arg);
            checkOverwrite();
            updateLaunchConfigurationDialog();
        }
    }));
    // $NON-NLS-1$
    Button fileBrowseButton3 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.BrowseFiles"), null);
    fileBrowseButton3.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        String filePath = outputFile.getText();
        FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
        filePath = dialog.open();
        if (filePath != null) {
            outputFile.setText(filePath);
            checkOverwrite();
            updateLaunchConfigurationDialog();
        }
    }));
    useColourButton = new Button(browseTop, SWT.CHECK);
    // $NON-NLS-1$
    useColourButton.setText(Messages.getString("SystemTapOptionsTab.ColourCodes"));
    useColourButton.addSelectionListener(selectListener);
    useColourButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
Also used : CLaunchConfigurationTab(org.eclipse.cdt.launch.ui.CLaunchConfigurationTab) LaunchConfigurationConstants(org.eclipse.linuxtools.internal.callgraph.core.LaunchConfigurationConstants) CoreException(org.eclipse.core.runtime.CoreException) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IPath(org.eclipse.core.runtime.IPath) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) Composite(org.eclipse.swt.widgets.Composite) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IExtension(org.eclipse.core.runtime.IExtension) SystemTapView(org.eclipse.linuxtools.internal.callgraph.core.SystemTapView) CDebugUtils(org.eclipse.cdt.debug.core.CDebugUtils) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) PlatformUI(org.eclipse.ui.PlatformUI) ICElement(org.eclipse.cdt.core.model.ICElement) IBinary(org.eclipse.cdt.core.model.IBinary) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Window(org.eclipse.jface.window.Window) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) PluginConstants(org.eclipse.linuxtools.internal.callgraph.core.PluginConstants) SelectionListener(org.eclipse.swt.events.SelectionListener) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) TabFolder(org.eclipse.swt.widgets.TabFolder) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Image(org.eclipse.swt.graphics.Image) Spinner(org.eclipse.swt.widgets.Spinner) FocusListener(org.eclipse.swt.events.FocusListener) ArrayList(java.util.ArrayList) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) TwoPaneElementSelector(org.eclipse.ui.dialogs.TwoPaneElementSelector) IWorkspace(org.eclipse.core.resources.IWorkspace) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) GridData(org.eclipse.swt.layout.GridData) ICProject(org.eclipse.cdt.core.model.ICProject) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) TabItem(org.eclipse.swt.widgets.TabItem) Shell(org.eclipse.swt.widgets.Shell) FileDialog(org.eclipse.swt.widgets.FileDialog) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) File(java.io.File) CElementLabelProvider(org.eclipse.cdt.ui.CElementLabelProvider) ICDTLaunchConfigurationConstants(org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants) ModifyListener(org.eclipse.swt.events.ModifyListener) IResource(org.eclipse.core.resources.IResource) Platform(org.eclipse.core.runtime.Platform) LabelProvider(org.eclipse.jface.viewers.LabelProvider) 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) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) 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) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Example 10 with ResourceComparator

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

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