Search in sources :

Example 21 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project webtools.sourceediting by eclipse.

the class ProcessorLibraryBlock method addWorkspace.

private void addWorkspace(IStructuredSelection selection) {
    IDialogSettings dialogSettings = XSLDebugUIPlugin.getDefault().getDialogSettings();
    String lastUsedPath = dialogSettings.get(LAST_WORKSPACE_PATH_SETTING);
    IPath lastPath = null;
    if (lastUsedPath != null) {
        lastPath = Path.fromPortableString(lastUsedPath);
    }
    // IResource currentResource = getResource();
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(tableViewer.getControl().getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setTitle(Messages.ProcessorLibraryBlock_WorkspaceFileDialog_Title);
    dialog.setMessage(Messages.ProcessorLibraryBlock_WorkspaceFileDialog_Message);
    dialog.setValidator(validator);
    dialog.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof IContainer)
                return true;
            else if (element instanceof IFile) {
                IFile file = (IFile) element;
                String extension = file.getFileExtension();
                if (extension == null)
                    return false;
                // $NON-NLS-1$
                return extension.equals("jar");
            }
            return false;
        }
    });
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    if (lastPath != null)
        dialog.setInitialSelection(lastPath);
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    dialog.setAllowMultiple(true);
    if (dialog.open() == Window.OK) {
        Object[] elements = dialog.getResult();
        if (elements.length > 0) {
            IProcessorJar[] libs = new IProcessorJar[elements.length];
            for (int i = 0; i < elements.length; i++) {
                IFile jar = (IFile) elements[i];
                libs[i] = JAXPRuntime.createProcessorJar(jar.getFullPath());
            }
            IProcessorJar[] currentJars = install.getProcessorJars();
            IProcessorJar[] newJars = new IProcessorJar[currentJars.length + libs.length];
            System.arraycopy(currentJars, 0, newJars, 0, currentJars.length);
            System.arraycopy(libs, 0, newJars, currentJars.length, libs.length);
            install.setProcessorJars(newJars);
            tableViewer.add(libs);
            lastPath = libs[0].getPath();
            lastPath = lastPath.uptoSegment(lastPath.segmentCount());
            dialogSettings.put(LAST_WORKSPACE_PATH_SETTING, lastPath.toPortableString());
        }
    }
}
Also used : ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IProcessorJar(org.eclipse.wst.xsl.jaxp.launching.IProcessorJar) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) IContainer(org.eclipse.core.resources.IContainer)

Example 22 with WorkbenchContentProvider

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

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

the class RunDescriptorTargetLocationPage method createRunDescriptorSelectionArea.

private TreeViewer createRunDescriptorSelectionArea(Composite composite) {
    final TreeViewer projectTree = new TreeViewer(new Tree(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER));
    projectTree.getTree().setLayoutData(fillGridData(1));
    projectTree.setContentProvider(new WorkbenchContentProvider());
    projectTree.setLabelProvider(new WorkbenchLabelProvider());
    projectTree.setInput(ResourcesPlugin.getWorkspace());
    projectTree.setFilters(getProjectTreeFilters());
    projectTree.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Object selection = ((ITreeSelection) event.getSelection()).getFirstElement();
            if (selection != null && selection instanceof IFile) {
                runDescriptorFile = (IFile) selection;
            } else {
                runDescriptorFile = null;
            }
            updateTarget();
        }
    });
    projectTree.expandAll();
    return projectTree;
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Tree(org.eclipse.swt.widgets.Tree) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider)

Example 24 with WorkbenchContentProvider

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

use of org.eclipse.ui.model.WorkbenchContentProvider in project mechanoid by robotoworks.

the class PackageBrowserField method onBrowseButtonPressed.

@Override
protected void onBrowseButtonPressed() {
    Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
    ListDialog dialog = new ListDialog(shell);
    dialog.setContentProvider(new WorkbenchContentProvider());
    dialog.setInput("hi");
    dialog.setLabelProvider(new WorkbenchLabelProvider());
    dialog.setBlockOnOpen(true);
    if (dialog.open() == Window.OK) {
    // TODO
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ListDialog(org.eclipse.ui.dialogs.ListDialog)

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