Search in sources :

Example 1 with ElementTreeSelectionDialog

use of org.eclipse.ui.dialogs.ElementTreeSelectionDialog in project generator by mybatis.

the class AbstractGeneratorComposite method chooseFileFromWorkspace.

protected IResource chooseFileFromWorkspace() {
    ElementTreeSelectionDialog esd = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    esd.setTitle(getDialogTitle());
    esd.setMessage(getDialogMessage());
    esd.setAllowMultiple(false);
    esd.setValidator(selectionStatusVerifier);
    esd.addFilter(getViewerFilter());
    esd.setInput(ResourcesPlugin.getWorkspace().getRoot());
    esd.setInitialSelection(getWorkspaceResource());
    int rc = esd.open();
    if (rc == 0) {
        Object[] elements = esd.getResult();
        if (elements.length > 0) {
            return (IResource) elements[0];
        }
    }
    return null;
}
Also used : ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IResource(org.eclipse.core.resources.IResource)

Example 2 with ElementTreeSelectionDialog

use of org.eclipse.ui.dialogs.ElementTreeSelectionDialog 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 3 with ElementTreeSelectionDialog

use of org.eclipse.ui.dialogs.ElementTreeSelectionDialog 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 4 with ElementTreeSelectionDialog

use of org.eclipse.ui.dialogs.ElementTreeSelectionDialog 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 5 with ElementTreeSelectionDialog

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

Aggregations

ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)7 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)7 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)5 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 ISelectionStatusValidator (org.eclipse.ui.dialogs.ISelectionStatusValidator)4 FileExtensionFilter (bndtools.utils.FileExtensionFilter)3 ArrayList (java.util.ArrayList)3 IFile (org.eclipse.core.resources.IFile)3 IResource (org.eclipse.core.resources.IResource)3 IPath (org.eclipse.core.runtime.IPath)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)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