Search in sources :

Example 11 with WorkbenchLabelProvider

use of org.eclipse.ui.model.WorkbenchLabelProvider in project translationstudio8 by heartsome.

the class LocationPageContentProvider method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    composite.setLayout(layout);
    final GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
    composite.setLayoutData(data);
    getShell().setText(Messages.getString("dialog.WorkspaceDialog.shell"));
    wsTreeViewer = new TreeViewer(composite, SWT.BORDER);
    final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 550;
    gd.heightHint = 250;
    wsTreeViewer.getTree().setLayoutData(gd);
    wsTreeViewer.setContentProvider(new LocationPageContentProvider());
    wsTreeViewer.setLabelProvider(new WorkbenchLabelProvider());
    wsTreeViewer.setInput(ResourcesPlugin.getWorkspace());
    final Composite group = new Composite(composite, SWT.NONE);
    layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    group.setLayout(layout);
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    final Label label = new Label(group, SWT.NONE);
    label.setLayoutData(new GridData());
    label.setText(Messages.getString("dialog.WorkspaceDialog.label"));
    wsFilenameText = new Text(group, SWT.BORDER);
    wsFilenameText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    setupListeners();
    return parent;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text)

Example 12 with WorkbenchLabelProvider

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

Example 13 with WorkbenchLabelProvider

use of org.eclipse.ui.model.WorkbenchLabelProvider in project tdi-studio-se by Talend.

the class AddResourceAction method run.

/**
     * Prompts for a jar to add.
     * 
     * @see IAction#run()
     */
@Override
public void run() {
    // ViewerFilter filter = new ArchiveFilter(getSelectedJars());
    ILabelProvider lp = new WorkbenchLabelProvider();
    ITreeContentProvider cp = new WorkbenchContentProvider();
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), lp, cp);
    dialog.setValidator(validator);
    //$NON-NLS-1$
    dialog.setTitle(Messages.getString("AddResourceAction.JARSecection"));
    //$NON-NLS-1$
    dialog.setMessage(Messages.getString("AddResourceAction.ChooseResource"));
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot().getProject(PluginConstant.COMPONENT_PROJECT));
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    if (dialog.open() == Window.OK) {
        Object[] elements = dialog.getResult();
        List<ILibEntry> res = new ArrayList<ILibEntry>();
        for (int i = 0; i < elements.length; i++) {
            IResource elem = (IResource) elements[i];
            String name = elem.getName();
            if (name.matches("(?i).*\\.(jar)\\b")) {
                //$NON-NLS-1$
                res.add(new JarLibEntry(elem));
            }
            if (name.matches("(?i).*\\.(pm)\\b")) {
                //$NON-NLS-1$
                res.add(new PmLibEntry(elem));
            }
        }
        if (res.size() > 0) {
            ILibEntry[] entries = new ILibEntry[res.size()];
            getViewer().addEntries(res.toArray(entries));
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) JarLibEntry(org.talend.componentdesigner.model.libentry.JarLibEntry) ArrayList(java.util.ArrayList) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ILibEntry(org.talend.componentdesigner.model.ILibEntry) PmLibEntry(org.talend.componentdesigner.model.libentry.PmLibEntry) IResource(org.eclipse.core.resources.IResource)

Example 14 with WorkbenchLabelProvider

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

the class ProjectLaunchTabPiece method doBrowseProject.

void doBrowseProject() {
    ElementListSelectionDialog dialog = new ElementListSelectionDialog(launchTargetTxt.getShell(), new WorkbenchLabelProvider());
    dialog.setTitle("Project Selection");
    dialog.setMessage("Select a project to constrain your search.");
    List<IProject> projects = loadProjects();
    dialog.setElements(projects.toArray());
    if (Window.OK == dialog.open()) {
        IProject selected = (IProject) dialog.getFirstResult();
        launchTargetTxt.setText(selected.getName());
    }
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) IProject(org.eclipse.core.resources.IProject)

Example 15 with WorkbenchLabelProvider

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

WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)26 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)16 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)15 IResource (org.eclipse.core.resources.IResource)11 IStatus (org.eclipse.core.runtime.IStatus)10 Status (org.eclipse.core.runtime.Status)10 GridData (org.eclipse.swt.layout.GridData)10 ArrayList (java.util.ArrayList)9 ResourceComparator (org.eclipse.ui.views.navigator.ResourceComparator)9 Composite (org.eclipse.swt.widgets.Composite)8 GridLayout (org.eclipse.swt.layout.GridLayout)7 Button (org.eclipse.swt.widgets.Button)7 IFile (org.eclipse.core.resources.IFile)6 SWT (org.eclipse.swt.SWT)6 List (java.util.List)5 IPath (org.eclipse.core.runtime.IPath)5 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)5 Label (org.eclipse.swt.widgets.Label)5 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)4 TableViewer (org.eclipse.jface.viewers.TableViewer)4