Search in sources :

Example 16 with WorkbenchLabelProvider

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

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

the class SystemTapLaunchShortcut method chooseUnit.

/**
 * Creates a dialog that prompts the user to select from the given list of
 * ICElements
 *
 * @param list
 *            : list of ICElements
 * @return
 */
private Object[] chooseUnit(List<ICContainer> list, int numberOfValidFiles) {
    ListTreeContentProvider prov = new ListTreeContentProvider();
    RuledTreeSelectionDialog dialog = new RuledTreeSelectionDialog(getActiveWorkbenchShell(), new WorkbenchLabelProvider(), prov);
    // $NON-NLS-1$
    dialog.setTitle(Messages.getString("SystemTapLaunchShortcut.SelectFiles"));
    // $NON-NLS-1$
    dialog.setMessage(Messages.getString("SystemTapLaunchShortcut.SelectFilesMsg"));
    dialog.setInput(list);
    dialog.setHelpAvailable(false);
    dialog.setStatusLineAboveButtons(false);
    dialog.setEmptyListMessage(Messages.getString(// $NON-NLS-1$
    "SystemTapLaunchShortcut.NoFiles"));
    dialog.setContainerMode(true);
    Object[] topLevel = prov.findElements(list);
    dialog.setInitialSelections(topLevel);
    dialog.setSize(cap(topLevel.length * 10, 30, 55), cap((int) (topLevel.length * 1.5), 3, 13));
    dialog.create();
    Button okButton = dialog.getOkButton();
    Object[] result = null;
    if (testMode) {
        okButton.setSelection(true);
        result = list.toArray();
        ArrayList<Object> output = new ArrayList<>();
        try {
            for (Object obj : result) {
                if (obj instanceof ICContainer) {
                    ICElement[] array = ((ICContainer) obj).getChildren();
                    for (ICElement c : array) {
                        if (!(validElement(c))) {
                            continue;
                        }
                        if (c.getElementName().contains(MAIN_FUNC_NAME) && !output.contains(c)) {
                            output.add(c);
                        }
                    }
                }
            }
            if (output.size() >= numberOfValidFiles) {
                output.clear();
                output.add(USER_SELECTED_ALL);
            }
        } catch (CModelException e) {
            e.printStackTrace();
        }
        result = output.toArray();
    } else {
        if (dialog.open() == Window.CANCEL) {
            return null;
        }
        result = dialog.getResult();
    }
    if (result == null) {
        return null;
    }
    ArrayList<Object> output = new ArrayList<>();
    try {
        for (Object obj : result) {
            if (obj instanceof ICContainer) {
                ICElement[] array = ((ICContainer) obj).getChildren();
                for (ICElement c : array) {
                    if (!(validElement(c))) {
                        continue;
                    }
                    if (!output.contains(c)) {
                        output.add(c);
                    }
                }
            } else if ((obj instanceof ICElement) && validElement((ICElement) obj) && !output.contains(obj)) {
                output.add(obj);
            }
        }
        if (output.size() >= numberOfValidFiles) {
            output.clear();
            output.add(USER_SELECTED_ALL);
        }
    } catch (CModelException e) {
        e.printStackTrace();
    }
    return output.toArray();
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ICContainer(org.eclipse.cdt.core.model.ICContainer) Button(org.eclipse.swt.widgets.Button) CModelException(org.eclipse.cdt.core.model.CModelException) ArrayList(java.util.ArrayList) ICElement(org.eclipse.cdt.core.model.ICElement)

Example 18 with WorkbenchLabelProvider

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

the class SystemTapOptionsTab method createFileOption.

private void createFileOption(Composite top) {
    Composite browseTop = new Composite(top, SWT.NONE);
    browseTop.setLayout(new GridLayout(4, false));
    browseTop.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Label suppFileLabel = new Label(browseTop, SWT.NONE);
    // $NON-NLS-1$
    suppFileLabel.setText(Messages.getString("SystemTapOptionsTab.ScriptSelector"));
    scriptFile = new Text(browseTop, SWT.BORDER);
    scriptFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    scriptFile.addModifyListener(modifyListener);
    // $NON-NLS-1$
    workspaceBrowseButton = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton"), null);
    workspaceBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
        // $NON-NLS-1$
        dialog.setTitle(Messages.getString("SystemTapOptionsTab.ResourceButton"));
        // $NON-NLS-1$
        dialog.setMessage(Messages.getString("SystemTapOptionsTab.SuppresionsFile"));
        dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
        dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
        if (dialog.open() == IDialogConstants.OK_ID) {
            IResource resource = (IResource) dialog.getFirstResult();
            String arg = resource.getFullPath().toString();
            scriptFile.setText(workspacePath + arg);
        }
    }));
    // $NON-NLS-1$
    fileBrowseButton = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.FileSystem"), null);
    fileBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        String filePath = scriptFile.getText();
        FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
        filePath = dialog.open();
        if (filePath != null) {
            scriptFile.setText(filePath);
        }
    }));
    Label binaryFileLabel = new Label(browseTop, SWT.NONE);
    // $NON-NLS-1$
    binaryFileLabel.setText(Messages.getString("SystemTapOptionsTab.SelectBinary"));
    binaryFile = new Text(browseTop, SWT.BORDER);
    binaryFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    binaryFile.addModifyListener(modifyListener);
    // $NON-NLS-1$
    Button workspaceBrowseButton2 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton2"), null);
    workspaceBrowseButton2.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
        // $NON-NLS-1$
        dialog.setTitle(Messages.getString("SystemTapOptionsTab.SelectResource"));
        // $NON-NLS-1$
        dialog.setMessage(Messages.getString("SystemTapOptionsTab.SelectSuppressions"));
        dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
        dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
        if (dialog.open() == IDialogConstants.OK_ID) {
            IResource resource = (IResource) dialog.getFirstResult();
            String arg = resource.getFullPath().toString();
            binaryFile.setText(workspacePath + arg);
        }
    }));
    // $NON-NLS-1$
    Button fileBrowseButton2 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.BrowseFiles"), null);
    fileBrowseButton2.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        String filePath = binaryFile.getText();
        FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
        filePath = dialog.open();
        if (filePath != null) {
            File file = new File(filePath);
            if (file.exists())
                binaryFile.setText(filePath);
        }
    }));
    Label outputFileLabel = new Label(browseTop, SWT.NONE);
    // $NON-NLS-1$
    outputFileLabel.setText(Messages.getString("SystemTapOptionsTab.SelectOutput"));
    outputFile = new Text(browseTop, SWT.BORDER);
    outputFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    outputFile.addModifyListener(modifyListenerOutput);
    outputFile.addFocusListener(focusListener);
    // $NON-NLS-1$
    Button workspaceBrowseButton3 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton2"), null);
    workspaceBrowseButton3.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
        // $NON-NLS-1$
        dialog.setTitle(Messages.getString("SystemTapOptionsTab.SelectResource"));
        // $NON-NLS-1$
        dialog.setMessage(Messages.getString("SystemTapOptionsTab.SelectSuppressions"));
        dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
        dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
        if (dialog.open() == IDialogConstants.OK_ID) {
            IResource resource = (IResource) dialog.getFirstResult();
            String arg = resource.getFullPath().toString();
            outputFile.setText(workspacePath + arg);
            checkOverwrite();
            updateLaunchConfigurationDialog();
        }
    }));
    // $NON-NLS-1$
    Button fileBrowseButton3 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.BrowseFiles"), null);
    fileBrowseButton3.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        String filePath = outputFile.getText();
        FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
        filePath = dialog.open();
        if (filePath != null) {
            outputFile.setText(filePath);
            checkOverwrite();
            updateLaunchConfigurationDialog();
        }
    }));
    useColourButton = new Button(browseTop, SWT.CHECK);
    // $NON-NLS-1$
    useColourButton.setText(Messages.getString("SystemTapOptionsTab.ColourCodes"));
    useColourButton.addSelectionListener(selectListener);
    useColourButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
Also used : CLaunchConfigurationTab(org.eclipse.cdt.launch.ui.CLaunchConfigurationTab) LaunchConfigurationConstants(org.eclipse.linuxtools.internal.callgraph.core.LaunchConfigurationConstants) CoreException(org.eclipse.core.runtime.CoreException) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IPath(org.eclipse.core.runtime.IPath) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) Composite(org.eclipse.swt.widgets.Composite) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IExtension(org.eclipse.core.runtime.IExtension) SystemTapView(org.eclipse.linuxtools.internal.callgraph.core.SystemTapView) CDebugUtils(org.eclipse.cdt.debug.core.CDebugUtils) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) PlatformUI(org.eclipse.ui.PlatformUI) ICElement(org.eclipse.cdt.core.model.ICElement) IBinary(org.eclipse.cdt.core.model.IBinary) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Window(org.eclipse.jface.window.Window) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) PluginConstants(org.eclipse.linuxtools.internal.callgraph.core.PluginConstants) SelectionListener(org.eclipse.swt.events.SelectionListener) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) TabFolder(org.eclipse.swt.widgets.TabFolder) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Image(org.eclipse.swt.graphics.Image) Spinner(org.eclipse.swt.widgets.Spinner) FocusListener(org.eclipse.swt.events.FocusListener) ArrayList(java.util.ArrayList) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) TwoPaneElementSelector(org.eclipse.ui.dialogs.TwoPaneElementSelector) IWorkspace(org.eclipse.core.resources.IWorkspace) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) GridData(org.eclipse.swt.layout.GridData) ICProject(org.eclipse.cdt.core.model.ICProject) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) TabItem(org.eclipse.swt.widgets.TabItem) Shell(org.eclipse.swt.widgets.Shell) FileDialog(org.eclipse.swt.widgets.FileDialog) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) File(java.io.File) CElementLabelProvider(org.eclipse.cdt.ui.CElementLabelProvider) ICDTLaunchConfigurationConstants(org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants) ModifyListener(org.eclipse.swt.events.ModifyListener) IResource(org.eclipse.core.resources.IResource) Platform(org.eclipse.core.runtime.Platform) LabelProvider(org.eclipse.jface.viewers.LabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Example 19 with WorkbenchLabelProvider

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

the class ContainerCopyFromPage method createControl.

@Override
public void createControl(Composite parent) {
    // page group
    Composite composite = new Composite(parent, SWT.NULL);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, false).applyTo(composite);
    GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(6, 6).applyTo(composite);
    Label targetLabel = new Label(composite, SWT.NULL);
    targetLabel.setText(WizardMessages.getString(TARGET_LABEL));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).grab(false, false).applyTo(targetLabel);
    targetText = new Text(composite, SWT.BORDER | SWT.SINGLE);
    targetText.addModifyListener(Listener);
    targetText.setToolTipText(WizardMessages.getString(TARGET_TOOLTIP));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, false).applyTo(targetText);
    browseButton = new Button(composite, SWT.NONE);
    browseButton.setText(WizardMessages.getString(BROWSE_LABEL));
    browseButton.addSelectionListener(onBrowseSelect());
    GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).span(1, 1).grab(false, false).applyTo(browseButton);
    // Create a fake parent of the root to be the dialog input element.
    // Use an empty label so that display of the element's full name
    // doesn't include a confusing label
    // $NON-NLS-1$
    FileSystemElement input = new FileSystemElement("", null, true);
    input.addChild(root);
    root.setParent(input);
    Composite selectionComposite = null;
    if (canBrowseContainer) {
        selectionComposite = new Composite(composite, SWT.NULL);
        GridLayout selectionLayout = new GridLayout();
        selectionComposite.setLayout(selectionLayout);
        selectionGroup = new CheckboxTreeAndListGroup(selectionComposite, input, getFolderProvider(), getDynamicFolderProvider(), new WorkbenchLabelProvider(), getFileProvider(), new WorkbenchLabelProvider(), SWT.NONE, // since this page has no
        SIZING_SELECTION_WIDGET_WIDTH, // other significantly-sized
        SIZING_SELECTION_WIDGET_HEIGHT);
        // hardcode the combined
        // widget's
        // size, otherwise it will open too small
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(3, 1).grab(true, false).applyTo(selectionComposite);
    } else {
        Label sourceLabel = new Label(composite, SWT.NONE);
        sourceLabel.setText(WizardMessages.getString(SOURCE_LABEL));
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).grab(false, false).applyTo(sourceLabel);
        sourceText = new Text(composite, SWT.BORDER | SWT.SINGLE);
        sourceText.addModifyListener(Listener);
        sourceText.setToolTipText(WizardMessages.getString(SOURCE_TOOLTIP));
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, false).applyTo(sourceText);
    }
    if (canBrowseContainer) {
        WorkbenchViewerComparator comparator = new WorkbenchViewerComparator();
        selectionGroup.setTreeComparator(comparator);
        selectionGroup.setListComparator(comparator);
        selectionGroup.addCheckStateListener(CheckListener);
    }
    setControl(composite);
    validate();
    setPageComplete(false);
    if (canBrowseContainer) {
        selectionGroup.aboutToOpen();
    }
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) MinimizedFileSystemElement(org.eclipse.linuxtools.internal.docker.ui.MinimizedFileSystemElement) FileSystemElement(org.eclipse.ui.dialogs.FileSystemElement) Text(org.eclipse.swt.widgets.Text) WorkbenchViewerComparator(org.eclipse.ui.model.WorkbenchViewerComparator) CheckboxTreeAndListGroup(org.eclipse.linuxtools.internal.docker.ui.CheckboxTreeAndListGroup)

Example 20 with WorkbenchLabelProvider

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

the class OpenGCDialog method handleBrowseWorkspace.

protected void handleBrowseWorkspace(String msg, Text text) {
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setTitle(msg);
    dialog.setMessage(msg);
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    dialog.setAllowMultiple(false);
    IContainer c = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(this.gcFile);
    if (c != null)
        dialog.setInitialSelection(c.getProject());
    dialog.setValidator(selection -> {
        if (selection.length != 1) {
            // $NON-NLS-1$
            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "", null);
        }
        if (!(selection[0] instanceof IFile)) {
            // $NON-NLS-1$
            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "", null);
        }
        // $NON-NLS-1$
        return new Status(IStatus.OK, Activator.PLUGIN_ID, 0, "", null);
    });
    if (dialog.open() == IDialogConstants.OK_ID) {
        IResource resource = (IResource) dialog.getFirstResult();
        // $NON-NLS-1$ //$NON-NLS-2$
        text.setText("${resource_loc:" + resource.getFullPath() + "}");
    }
}
Also used : ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

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