Search in sources :

Example 1 with BaseWorkbenchContentProvider

use of org.eclipse.ui.model.BaseWorkbenchContentProvider in project ow by vtst.

the class ResourceListControl method addResource.

private void addResource() {
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(null, new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
    dialog.setAllowMultiple(false);
    dialog.setTitle(messages.getString("FolderListControl_add"));
    dialog.setMessage("");
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    dialog.addFilter(this.addFilter);
    try {
        dialog.setInitialSelection(ResourcesPlugin.getWorkspace().getRoot());
    }// Raised by new Path(...)
     catch (IllegalArgumentException exn) {
    }
    dialog.setValidator(addValidator);
    dialog.open();
    T resource = getSelectedResource(dialog.getResult());
    if (resource != null) {
        addResource((T) resource);
    }
}
Also used : ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) SWT(org.eclipse.swt.SWT) BaseWorkbenchContentProvider(org.eclipse.ui.model.BaseWorkbenchContentProvider)

Example 2 with BaseWorkbenchContentProvider

use of org.eclipse.ui.model.BaseWorkbenchContentProvider in project sling by apache.

the class ConvertToContentProjectHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IProject project = (IProject) ((IStructuredSelection) selection).getFirstElement();
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getDisplay().getActiveShell(), new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
        dialog.setMessage("Select content sync root location (containing the jcr root)");
        dialog.setTitle("Content Sync Root");
        IContainer initialContainer = ProjectHelper.getInferredContentProjectContentRoot(project);
        if (initialContainer != null) {
            dialog.setInitialElementSelections(Arrays.asList(initialContainer));
        }
        dialog.addFilter(new ViewerFilter() {

            @Override
            public boolean select(Viewer viewer, Object parentElement, Object element) {
                if (element instanceof IProject) {
                    return ((IProject) element).equals(project);
                }
                // display folders only
                return element instanceof IContainer;
            }
        });
        dialog.setInput(new IWorkbenchAdapter() {

            @Override
            public Object getParent(Object o) {
                return null;
            }

            @Override
            public String getLabel(Object o) {
                return null;
            }

            @Override
            public ImageDescriptor getImageDescriptor(Object object) {
                return null;
            }

            @Override
            public Object[] getChildren(Object o) {
                return new Object[] { project };
            }
        });
        // this is the root element
        dialog.setAllowMultiple(false);
        dialog.setValidator(new ISelectionStatusValidator() {

            @Override
            public IStatus validate(Object[] selection) {
                if (selection.length > 0) {
                    final Object item = selection[0];
                    if (item instanceof IContainer) {
                        IContainer selectedContainer = (IContainer) item;
                        String errorMsg = ProjectHelper.validateContentPackageStructure(selectedContainer);
                        if (errorMsg != null) {
                            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMsg);
                        } else {
                            return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
                        }
                    }
                }
                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "");
            }
        });
        if (dialog.open() == ContainerSelectionDialog.OK) {
            Object[] result = dialog.getResult();
            if (result != null && result.length > 0) {
                final IContainer container = (IContainer) result[0];
                IRunnableWithProgress r = new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            IResource jcrRoot = container.findMember("jcr_root");
                            if (jcrRoot == null || !(jcrRoot instanceof IFolder)) {
                                MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", "jcr_root not found under " + container + " (or not a Folder)");
                                return;
                            }
                            ConfigurationHelper.convertToContentPackageProject(project, monitor, jcrRoot.getProjectRelativePath());
                        } catch (CoreException e) {
                            Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
                            MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
                        }
                    }
                };
                try {
                    PlatformUI.getWorkbench().getProgressService().busyCursorWhile(r);
                } catch (Exception e) {
                    Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
                    MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
                }
            }
        }
    }
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IStatus(org.eclipse.core.runtime.IStatus) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) BaseWorkbenchContentProvider(org.eclipse.ui.model.BaseWorkbenchContentProvider) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) ISelection(org.eclipse.jface.viewers.ISelection) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)2 BaseWorkbenchContentProvider (org.eclipse.ui.model.BaseWorkbenchContentProvider)2 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IContainer (org.eclipse.core.resources.IContainer)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 SWT (org.eclipse.swt.SWT)1