Search in sources :

Example 1 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project generator by mybatis.

the class AbstractGeneratorComposite method chooseFileFromWorkspace.

protected IResource chooseFileFromWorkspace() {
    ElementTreeSelectionDialog esd = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    esd.setTitle(getDialogTitle());
    esd.setMessage(getDialogMessage());
    esd.setAllowMultiple(false);
    esd.setValidator(selectionStatusVerifier);
    esd.addFilter(getViewerFilter());
    esd.setInput(ResourcesPlugin.getWorkspace().getRoot());
    esd.setInitialSelection(getWorkspaceResource());
    int rc = esd.open();
    if (rc == 0) {
        Object[] elements = esd.getResult();
        if (elements.length > 0) {
            return (IResource) elements[0];
        }
    }
    return null;
}
Also used : ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IResource(org.eclipse.core.resources.IResource)

Example 2 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project translationstudio8 by heartsome.

the class WizardExportResourcesPage2 method getResourceProvider.

/**
	 * Returns a content provider for <code>IResource</code>s that returns only children of the given resource type.
	 */
private ITreeContentProvider getResourceProvider(final int resourceType) {
    return new WorkbenchContentProvider() {

        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 (int i = 0; i < members.length; i++) {
                    if (members[i].getName().equals(".config") || members[i].getName().equals(".project") || members[i].getName().equalsIgnoreCase(".temp")) {
                        defaultExportItems.add(members[i]);
                        continue;
                    }
                    // And the test bits with the resource types to see if they are what we want
                    if ((members[i].getType() & resourceType) > 0) {
                        results.add(members[i]);
                    }
                }
                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 3 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project xtext-eclipse by eclipse.

the class ProjectSelectionDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    Font font = parent.getFont();
    composite.setFont(font);
    createMessageArea(composite);
    tableViewer = new TableViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            doSelectionChanged(((IStructuredSelection) event.getSelection()).toArray());
        }
    });
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            okPressed();
        }
    });
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.heightHint = SIZING_SELECTION_WIDGET_HEIGHT;
    data.widthHint = SIZING_SELECTION_WIDGET_WIDTH;
    tableViewer.getTable().setLayoutData(data);
    tableViewer.setContentProvider(new WorkbenchContentProvider());
    tableViewer.setLabelProvider(new WorkbenchLabelProvider());
    tableViewer.setComparator(new ResourceComparator(ResourceComparator.NAME));
    tableViewer.getControl().setFont(font);
    Button checkbox = new Button(composite, SWT.CHECK);
    checkbox.setText(Messages.ProjectSelectionDialog_filter);
    checkbox.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
    checkbox.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateFilter(((Button) e.widget).getSelection());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            updateFilter(((Button) e.widget).getSelection());
        }
    });
    boolean doFilter = !dialogSettings.getBoolean(DIALOG_SETTINGS_SHOW_ALL) && !projectsWithSpecifics.isEmpty();
    checkbox.setSelection(doFilter);
    updateFilter(doFilter);
    tableViewer.setInput(ResourcesPlugin.getWorkspace());
    doSelectionChanged(new Object[0]);
    Dialog.applyDialogFont(composite);
    return composite;
}
Also used : ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) Font(org.eclipse.swt.graphics.Font) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 4 with WorkbenchContentProvider

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

the class BuildDockerImageLaunchConfigurationMainTab method onBrowseWorkspace.

/**
 * Opens a dialog to browse the workspace
 *
 * @return
 */
private SelectionListener onBrowseWorkspace(final Text pathText, final Class<?> expectedType) {
    return SelectionListener.widgetSelectedAdapter(e -> {
        final ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
        dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
        dialog.setTitle(LaunchMessages.getString(BROWSE_WORKSPACE_DIALOG_TITLE));
        dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
        dialog.setAllowMultiple(false);
        dialog.setValidator(selection -> {
            if (selection.length == 1 && expectedType.isAssignableFrom(selection[0].getClass())) {
                return new Status(IStatus.OK, Activator.PLUGIN_ID, null);
            }
            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, null);
        });
        if (dialog.open() == IDialogConstants.OK_ID) {
            final IResource selection = (IResource) dialog.getFirstResult();
            pathText.setText(selection.getFullPath().toOSString());
            buildContextPathWorkspaceRelative = true;
        }
    });
}
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) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IResource(org.eclipse.core.resources.IResource)

Example 5 with WorkbenchContentProvider

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

the class DockerComposeUpLaunchConfigurationMainTab method onBrowseWorkspace.

/**
 * Opens a dialog to browse the workspace
 *
 * @return
 */
private SelectionListener onBrowseWorkspace(final Text pathText, final Class<?> expectedType) {
    return SelectionListener.widgetSelectedAdapter(e -> {
        final ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
        dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
        dialog.setTitle(LaunchMessages.getString(// $NON-NLS-1$
        "DockerComposeUpLaunchConfigurationMainTab.dockerComposePath.browseworkspace.dialog.title"));
        dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
        dialog.setAllowMultiple(false);
        dialog.setValidator(selection -> {
            if (selection.length == 1 && expectedType.isAssignableFrom(selection[0].getClass())) {
                return new Status(IStatus.OK, Activator.PLUGIN_ID, null);
            }
            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, null);
        });
        if (dialog.open() == IDialogConstants.OK_ID) {
            final IResource selection = (IResource) dialog.getFirstResult();
            pathText.setText(selection.getFullPath().toOSString());
            dockerComposeFilePathWorkspaceRelative = true;
        }
    });
}
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) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) 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