Search in sources :

Example 26 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project tdi-studio-se by Talend.

the class SelectDeleteProjectDialog method getResourceProvider.

private ITreeContentProvider getResourceProvider(final int resourceType) {
    return new WorkbenchContentProvider() {

        @Override
        public Object[] getChildren(Object o) {
            if (o instanceof IContainer) {
                IResource[] members = null;
                try {
                    members = ((IContainer) o).members();
                } catch (CoreException e) {
                    // just return an empty set of children
                    return new Object[0];
                }
                // filter out the desired resource types
                ArrayList results = new ArrayList();
                for (IResource member : members) {
                    // And the test bits with the resource types to see if they are what we want
                    if ((member.getType() & resourceType) > 0) {
                        results.add(member);
                    }
                }
                return results.toArray();
            }
            // input element case
            if (o instanceof ArrayList) {
                return ((ArrayList) o).toArray();
            }
            return new Object[0];
        }
    };
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 27 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project tdi-studio-se by Talend.

the class TalendWizardArchiveFileResourceExportPage1 method getResourceProvider.

private ITreeContentProvider getResourceProvider(final int resourceType) {
    return new WorkbenchContentProvider() {

        @Override
        public Object[] getChildren(Object o) {
            if (o instanceof IContainer) {
                IResource[] members = null;
                try {
                    members = ((IContainer) o).members();
                } catch (CoreException e) {
                    // just return an empty set of children
                    return new Object[0];
                }
                // filter out the desired resource types
                ArrayList results = new ArrayList();
                for (IResource member : members) {
                    // And the test bits with the resource types to see if they are what we want
                    if ((member.getType() & resourceType) > 0) {
                        results.add(member);
                    }
                }
                return results.toArray();
            }
            // input element case
            if (o instanceof ArrayList) {
                return ((ArrayList) o).toArray();
            }
            return new Object[0];
        }
    };
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 28 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider 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 29 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project eclipse.platform.text by eclipse.

the class SelectResourcesDialog method getResourceProvider.

private ITreeContentProvider getResourceProvider(final int resourceType) {
    return new WorkbenchContentProvider() {

        @Override
        public Object[] getChildren(Object o) {
            if (o instanceof IWorkspaceRoot) {
                HashSet<IResource> projects = new HashSet<>();
                for (int i = 0; i < fInput.length; i++) {
                    IResource project = fInput[i].getProject();
                    if ((project.getType() & resourceType) > 0)
                        projects.add(project);
                }
                return projects.toArray();
            }
            if (o instanceof IContainer) {
                IResource[] members = null;
                try {
                    members = ((IContainer) o).members();
                } catch (CoreException e) {
                    // just return an empty set of children
                    return new Object[0];
                }
                // filter out the desired resource types
                ArrayList<IResource> results = new ArrayList<>();
                for (int i = 0; i < members.length; i++) {
                    // And the test bits with the resource types to see if they are what we want
                    if ((members[i].getType() & resourceType) > 0 && (resourceType != IResource.FILE || fAcceptableLocationsFilter == null || fAcceptableLocationsFilter.accept(members[i]))) {
                        results.add(members[i]);
                    }
                }
                return results.toArray();
            }
            // input element case
            if (o instanceof ArrayList)
                return ((ArrayList<?>) o).toArray();
            return new Object[0];
        }
    };
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 30 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider 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)

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