Search in sources :

Example 41 with WorkbenchContentProvider

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

the class LiferayDataModelWizardPage method handleFileBrowseButton.

protected void handleFileBrowseButton(final Text text, String title, String message) {
    ISelectionStatusValidator validator = getContainerDialogSelectionValidator();
    ViewerFilter filter = getContainerDialogViewerFilter();
    ITreeContentProvider contentProvider = new WorkbenchContentProvider();
    IDecoratorManager decoratorManager = PlatformUI.getWorkbench().getDecoratorManager();
    ILabelProvider labelProvider = new DecoratingLabelProvider(new WorkbenchLabelProvider(), decoratorManager.getLabelDecorator());
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), labelProvider, contentProvider);
    dialog.setValidator(validator);
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.addFilter(filter);
    final IWebProject lrproject = LiferayCore.create(IWebProject.class, CoreUtil.getProject(getDataModel().getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME)));
    if (lrproject != null) {
        final IFolder defaultDocroot = lrproject.getDefaultDocrootFolder();
        if (defaultDocroot != null) {
            dialog.setInput(defaultDocroot);
            if (dialog.open() == Window.OK) {
                Object element = dialog.getFirstResult();
                try {
                    if (element instanceof IFile) {
                        IFile file = (IFile) element;
                        final IPath relativePath = file.getFullPath().makeRelativeTo(defaultDocroot.getFullPath());
                        text.setText("/" + relativePath.toPortableString());
                    // dealWithSelectedContainerResource(container);
                    }
                } catch (Exception ex) {
                // Do nothing
                }
            }
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) IDecoratorManager(org.eclipse.ui.IDecoratorManager) DecoratingLabelProvider(org.eclipse.jface.viewers.DecoratingLabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) EObject(org.eclipse.emf.ecore.EObject) IFolder(org.eclipse.core.resources.IFolder)

Example 42 with WorkbenchContentProvider

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

the class UIUtils method createFileDialog.

/**
 * Create a file selection dialog.
 *
 * @param selectedFile the initial selected file. May be null
 * @param title the title of the dialog
 * @param message the message of the dialog
 * @param extension the extension to filter. If null or empty, all files are accepted
 * @param initialSelection the initial selection resource (used if selectedFile is null)
 * @return the dialog
 */
public static ElementTreeSelectionDialog createFileDialog(String selectedFile, String title, String message, String extension, IResource initialSelection) {
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    dialog.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return element instanceof IContainer || (element instanceof IFile && (StringUtils.isEmpty(extension) || extension.equals(((IFile) element).getFileExtension())));
        }
    });
    dialog.setAllowMultiple(false);
    if (StringUtils.isNotBlank(selectedFile)) {
        String prefix = "${workspace_loc:";
        String path = selectedFile;
        if (selectedFile.startsWith(prefix) && selectedFile.endsWith("}")) {
            path = path.substring(prefix.length(), path.length() - 1);
        }
        initialSelection = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
    }
    if (initialSelection != null) {
        dialog.setInitialSelection(initialSelection);
    }
    return dialog;
}
Also used : ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) 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) IContainer(org.eclipse.core.resources.IContainer)

Example 43 with WorkbenchContentProvider

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

the class ServerSettingsWizardPage method createWorkspaceFolderDialog.

private ElementTreeSelectionDialog createWorkspaceFolderDialog(Shell shell, String selectedFile) {
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setTitle("Select a workspace folder");
    dialog.setMessage("Select a workspace folder to deploy");
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    dialog.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (!(element instanceof IContainer)) {
                return false;
            }
            IContainer container = (IContainer) element;
            return container.isAccessible() && !ProjectUtils.isInternalPde(container.getName()) && !ProjectUtils.isInternalRSE(container.getName());
        }
    });
    dialog.setAllowMultiple(false);
    org.eclipse.core.resources.IResource res = model.getDeployProject();
    if (org.apache.commons.lang.StringUtils.isNotBlank(selectedFile)) {
        String path = VariablesHelper.getWorkspacePath(selectedFile);
        org.eclipse.core.resources.IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
        if (member != null) {
            res = member;
        }
    }
    if (res != null) {
        dialog.setInitialSelection(res);
    }
    return dialog;
}
Also used : ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ComboViewer(org.eclipse.jface.viewers.ComboViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IContainer(org.eclipse.core.resources.IContainer)

Example 44 with WorkbenchContentProvider

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

the class DQRuleSelectPage method createControl.

public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    FillLayout layout = new FillLayout();
    container.setLayout(layout);
    cViewer = new ContainerCheckedTreeViewer(container, SWT.NONE);
    cViewer.setLabelProvider(new DQRuleLabelProvider());
    cViewer.setContentProvider(new WorkbenchContentProvider());
    cViewer.setInput(ResourceManager.getLibrariesFolder());
    // ADD mzhao bug TDQ-4188 hide the .svn folders.
    cViewer.addFilter(new DQFolderFilter(true));
    cViewer.addFilter(new RuleFolderFliter(true));
    cViewer.addFilter(AnalysisUtils.createRuleFilter());
    setControl(container);
}
Also used : RuleFolderFliter(org.talend.dataprofiler.core.ui.filters.RuleFolderFliter) Composite(org.eclipse.swt.widgets.Composite) ContainerCheckedTreeViewer(org.eclipse.ui.dialogs.ContainerCheckedTreeViewer) FillLayout(org.eclipse.swt.layout.FillLayout) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) DQFolderFilter(org.talend.dataprofiler.core.ui.filters.DQFolderFilter)

Example 45 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project whole by wholeplatform.

the class OperationLauncherRegistry method openJavaSourceFoldersDialog.

public static IContainer[] openJavaSourceFoldersDialog(Shell shell, boolean allowMultipleSelection) {
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setValidator(new JavaSourceFolderValidator());
    dialog.setTitle("Java Source Folder Selection");
    dialog.setMessage("Choose a destination folder for generated code");
    dialog.addFilter(new JavaSourceFolderFilter());
    dialog.setInput(JDTUtils.getWorkspaceRoot());
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    dialog.setAllowMultiple(allowMultipleSelection);
    if (dialog.open() == Window.OK) {
        Object[] elements = dialog.getResult();
        IContainer[] containers = new IContainer[elements.length];
        for (int i = 0; i < containers.length; i++) containers[i] = (IContainer) elements[i];
        return containers;
    }
    return new IContainer[0];
}
Also used : ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) JavaSourceFolderValidator(org.whole.lang.ui.controls.JavaSourceFolderValidator) IContainer(org.eclipse.core.resources.IContainer) JavaSourceFolderFilter(org.whole.lang.ui.controls.JavaSourceFolderFilter)

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