Search in sources :

Example 36 with WorkbenchContentProvider

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

Example 37 with WorkbenchContentProvider

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

the class CustomElementSelectionDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    CustomElementSelectionForm form = new CustomElementSelectionForm(parent, SWT.FILL);
    form.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    TreeViewer v = form.getTreeViewer();
    for (ViewerFilter filter : filters) {
        v.addFilter(filter);
    }
    this.treeViewer = v;
    WorkbenchContentProvider contentProvider = new WorkbenchContentProvider();
    ILabelProvider labelProvider = new WorkbenchLabelProvider();
    this.treeViewer.setContentProvider(contentProvider);
    this.treeViewer.setLabelProvider(labelProvider);
    this.treeViewer.setComparator(new ViewerComparator());
    this.treeViewer.setAutoExpandLevel(this.getAutoExpandLevel());
    form.setElementLabel(this.elementLabel);
    this.elementNameInput = form.getElementInput();
    form.getElementInput().addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals(SuffixText.TEXT_PROPERTY) || evt.getPropertyName().equals(SuffixText.SUFFIX_PROPERTY)) {
                validateElementInput();
                elementInputChanged();
            }
        }
    });
    return form;
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) PropertyChangeEvent(java.beans.PropertyChangeEvent) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) PropertyChangeListener(java.beans.PropertyChangeListener) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider)

Example 38 with WorkbenchContentProvider

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

the class AbstractExportToSingleFileWizardPage method getContentProvider.

/**
 * Returns a content provider for the list dialog. It will return all projects in the workspace except the given
 * project, plus any projects referenced by the given project which do no exist in the workspace.
 *
 * @return the content provider that shows the project content
 */
private IStructuredContentProvider getContentProvider() {
    return new WorkbenchContentProvider() {

        @Override
        public Object[] getChildren(Object o) {
            if (!(o instanceof IWorkspace)) {
                return new Object[0];
            }
            // Collect all the projects in the workspace except the given project
            IProject[] projects = ((IWorkspace) o).getRoot().getProjects();
            List<IProject> applicableProjects = Lists.newArrayList();
            Optional<? extends IN4JSEclipseProject> projectOpt = null;
            for (IProject candidate : projects) {
                projectOpt = n4jsCore.create(candidate);
                if (projectOpt.isPresent() && projectOpt.get().exists()) {
                    applicableProjects.add(candidate);
                }
            }
            return applicableProjects.toArray(new IProject[applicableProjects.size()]);
        }
    };
}
Also used : IWorkspace(org.eclipse.core.resources.IWorkspace) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IProject(org.eclipse.core.resources.IProject)

Example 39 with WorkbenchContentProvider

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

the class UploadNewWorkflowDefinitionAction method promptForWorkspaceFile.

protected IFile promptForWorkspaceFile() {
    ISelectionStatusValidator validator = getContainerDialogSelectionValidator();
    ViewerFilter filter = getContainerDialogViewerFilter();
    ITreeContentProvider contentProvider = new WorkbenchContentProvider();
    IWorkbench workBench = PlatformUI.getWorkbench();
    ILabelProvider labelProvider = new DecoratingLabelProvider(new WorkbenchLabelProvider(), workBench.getDecoratorManager().getLabelDecorator());
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), labelProvider, contentProvider);
    dialog.setValidator(validator);
    dialog.setTitle("workspace file");
    dialog.setMessage("workspace file");
    dialog.addFilter(filter);
    dialog.setInput(ResourcesPlugin.getWorkspace());
    if (dialog.open() == Window.OK) {
        Object element = dialog.getFirstResult();
        try {
            if (element instanceof IFile) {
                IFile file = (IFile) element;
                return file;
            }
        } catch (Exception ex) {
        // Do nothing
        }
    }
    return null;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) DecoratingLabelProvider(org.eclipse.jface.viewers.DecoratingLabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider)

Example 40 with WorkbenchContentProvider

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

the class NewPortletClassWizardPage method handleFolderButtonPressed.

/**
 * Browse for a new Destination Folder
 */
protected void handleFolderButtonPressed() {
    ISelectionStatusValidator validator = getContainerDialogSelectionValidator();
    ViewerFilter filter = getContainerDialogViewerFilter();
    ITreeContentProvider contentProvider = new WorkbenchContentProvider();
    IWorkbench workbench = PlatformUI.getWorkbench();
    ILabelProvider labelProvider = new DecoratingLabelProvider(new WorkbenchLabelProvider(), workbench.getDecoratorManager().getLabelDecorator());
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), labelProvider, contentProvider);
    dialog.setValidator(validator);
    dialog.setTitle(J2EEUIMessages.CONTAINER_SELECTION_DIALOG_TITLE);
    dialog.setMessage(J2EEUIMessages.CONTAINER_SELECTION_DIALOG_DESC);
    dialog.addFilter(filter);
    String projectName = model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME);
    if ((projectName == null) || (projectName.length() == 0)) {
        return;
    }
    IProject project = ProjectUtilities.getProject(projectName);
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    if (project != null) {
        dialog.setInitialSelection(project);
    }
    if (dialog.open() == Window.OK) {
        Object element = dialog.getFirstResult();
        try {
            if (element instanceof IContainer) {
                IContainer container = (IContainer) element;
                folderText.setText(container.getFullPath().toString());
            // dealWithSelectedContainerResource(container);
            }
        } catch (Exception ex) {
        // Do nothing
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) DecoratingLabelProvider(org.eclipse.jface.viewers.DecoratingLabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) IWorkbench(org.eclipse.ui.IWorkbench) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) EObject(org.eclipse.emf.ecore.EObject) IContainer(org.eclipse.core.resources.IContainer)

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