Search in sources :

Example 1 with ISelectionStatusValidator

use of org.eclipse.ui.dialogs.ISelectionStatusValidator in project bndtools by bndtools.

the class AddFilesToRepositoryWizardPage method doAdd.

void doAdd() {
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setValidator(new ISelectionStatusValidator() {

        @Override
        public IStatus validate(Object[] selection) {
            if (selection.length > 0 && selection[0] instanceof IFile) {
                //$NON-NLS-1$
                return new Status(IStatus.OK, Plugin.PLUGIN_ID, IStatus.OK, "", null);
            }
            //$NON-NLS-1$
            return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, IStatus.ERROR, "", null);
        }
    });
    dialog.setAllowMultiple(true);
    dialog.setTitle("JAR File Selection");
    //$NON-NLS-1$
    dialog.addFilter(new FileExtensionFilter("jar"));
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    if (dialog.open() == Window.OK) {
        Object[] result = dialog.getResult();
        List<File> added = new ArrayList<File>(result.length);
        for (Object fileObj : result) {
            IFile ifile = (IFile) fileObj;
            File file = ifile.getLocation().toFile();
            analyseFile(file);
            files.add(file);
            added.add(file);
        }
        if (!added.isEmpty()) {
            viewer.add(added.toArray());
            validate();
        }
    }
}
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) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) FileExtensionFilter(bndtools.utils.FileExtensionFilter) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 2 with ISelectionStatusValidator

use of org.eclipse.ui.dialogs.ISelectionStatusValidator in project bndtools by bndtools.

the class ProjectLaunchTabPiece method doBrowseBndrun.

void doBrowseBndrun() {
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(launchTargetTxt.getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setValidator(new ISelectionStatusValidator() {

        @Override
        public IStatus validate(Object[] selection) {
            if (selection.length > 0 && selection[0] instanceof IFile) {
                //$NON-NLS-1$
                return new Status(IStatus.OK, Plugin.PLUGIN_ID, IStatus.OK, "", null);
            }
            //$NON-NLS-1$
            return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, IStatus.ERROR, "", null);
        }
    });
    dialog.setAllowMultiple(false);
    dialog.setTitle("Run File Selection");
    dialog.setMessage("Select the Run File to launch.");
    dialog.addFilter(new FileExtensionFilter(LaunchConstants.EXT_BNDRUN));
    dialog.setInput(ResourcesPlugin.getWorkspace());
    if (dialog.open() == Window.OK) {
        Object[] files = dialog.getResult();
        if (files != null && files.length == 1) {
            IPath path = ((IResource) files[0]).getFullPath().makeRelative();
            launchTargetTxt.setText(path.toString());
        } else {
            launchTargetTxt.setText("");
        }
    }
}
Also used : ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) FileExtensionFilter(bndtools.utils.FileExtensionFilter) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider)

Example 3 with ISelectionStatusValidator

use of org.eclipse.ui.dialogs.ISelectionStatusValidator 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)

Example 4 with ISelectionStatusValidator

use of org.eclipse.ui.dialogs.ISelectionStatusValidator in project bndtools by bndtools.

the class JarListWizardPage method createControl.

@Override
public void createControl(final Composite parent) {
    setTitle("Select JARs");
    final Composite composite = new Composite(parent, SWT.NONE);
    Label lblHint = new Label(composite, SWT.WRAP);
    lblHint.setText("Selected files (hint: drag files from an external application into this list):");
    final Table table = new Table(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer = new TableViewer(table);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ClassPathLabelProvider());
    btnAdd = new Button(composite, SWT.PUSH);
    btnAdd.setText("Add");
    btnAddExternal = new Button(composite, SWT.PUSH);
    btnAddExternal.setText("Add External");
    btnRemove = new Button(composite, SWT.PUSH);
    btnRemove.setText("Remove");
    viewer.setInput(paths);
    update();
    // Listeners
    ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {

        @Override
        public void dragEnter(DropTargetEvent event) {
            super.dragEnter(event);
            event.detail = DND.DROP_COPY;
        }

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            return true;
        }

        @Override
        public boolean performDrop(Object data) {
            if (data instanceof String[]) {
                String[] newPaths = (String[]) data;
                List<IPath> added = new ArrayList<IPath>(newPaths.length);
                for (String path : newPaths) {
                    added.add(new Path(path));
                }
                if (!added.isEmpty()) {
                    addToPaths(added);
                    viewer.add(added.toArray());
                    update();
                }
            }
            return true;
        }
    };
    dropAdapter.setFeedbackEnabled(false);
    dropAdapter.setSelectionFeedbackEnabled(false);
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { FileTransfer.getInstance() }, dropAdapter);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            update();
        }
    });
    btnAdd.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // IResource newFile = ResourcesPlugin.getWorkspace().getRoot();
            // if(newFile != null) {
            ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
            dialog.setValidator(new ISelectionStatusValidator() {

                @Override
                public IStatus validate(Object[] selection) {
                    if (selection.length > 0 && selection[0] instanceof IFile) {
                        //$NON-NLS-1$
                        return new Status(IStatus.OK, Plugin.PLUGIN_ID, IStatus.OK, "", null);
                    }
                    //$NON-NLS-1$
                    return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, IStatus.ERROR, "", null);
                }
            });
            dialog.setAllowMultiple(true);
            dialog.setTitle("JAR File Selection");
            dialog.setMessage("Select one or more JAR files.");
            //$NON-NLS-1$
            dialog.addFilter(new FileExtensionFilter("jar"));
            dialog.setInput(ResourcesPlugin.getWorkspace());
            if (dialog.open() == Window.OK) {
                Object[] files = dialog.getResult();
                List<IPath> added = new ArrayList<IPath>(files.length);
                for (Object file : files) {
                    added.add(((IResource) file).getFullPath().makeRelative());
                }
                if (!added.isEmpty()) {
                    addToPaths(added);
                    viewer.add(added.toArray());
                }
            }
            // }
            update();
        }
    });
    btnAddExternal.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN | SWT.MULTI);
            dialog.setFilterExtensions(new String[] { //$NON-NLS-1$
            "*.jar" });
            String res = dialog.open();
            if (res != null) {
                IPath filterPath = new Path(dialog.getFilterPath());
                String[] fileNames = dialog.getFileNames();
                List<IPath> added = new ArrayList<IPath>(fileNames.length);
                for (String fileName : fileNames) {
                    added.add(filterPath.append(fileName));
                }
                if (!added.isEmpty()) {
                    addToPaths(added);
                    viewer.add(added.toArray());
                }
            }
            update();
        }
    });
    btnRemove.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            removeFromPaths(((IStructuredSelection) viewer.getSelection()).toList());
            viewer.remove(((IStructuredSelection) viewer.getSelection()).toArray());
            update();
        }
    });
    // Layout
    composite.setLayout(new GridLayout(2, false));
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
    btnAdd.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    btnAddExternal.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    lblHint.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1));
    setControl(composite);
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ClassPathLabelProvider(bndtools.utils.ClassPathLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) TransferData(org.eclipse.swt.dnd.TransferData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileExtensionFilter(bndtools.utils.FileExtensionFilter) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) FileDialog(org.eclipse.swt.widgets.FileDialog)

Aggregations

IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)4 ISelectionStatusValidator (org.eclipse.ui.dialogs.ISelectionStatusValidator)4 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)4 FileExtensionFilter (bndtools.utils.FileExtensionFilter)3 IFile (org.eclipse.core.resources.IFile)3 ArrayList (java.util.ArrayList)2 IPath (org.eclipse.core.runtime.IPath)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)2 ClassPathLabelProvider (bndtools.utils.ClassPathLabelProvider)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)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