Search in sources :

Example 86 with WorkbenchLabelProvider

use of org.eclipse.ui.model.WorkbenchLabelProvider in project jbosstools-hibernate by jbosstools.

the class DialogSelectionHelper method chooseFolderEntries.

public static IPath[] chooseFolderEntries(Shell shell, IPath initialSelection, String title, String description, boolean allowMultiple) {
    List<Class<?>> clazzes = new ArrayList<Class<?>>();
    clazzes.add(IFolder.class);
    clazzes.add(IProject.class);
    Class<?>[] acceptedClasses = clazzes.toArray(new Class[clazzes.size()]);
    TypedElementSelectionValidator validator = new TypedElementSelectionValidator(acceptedClasses, true);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IResource focus = initialSelection != null ? root.findMember(initialSelection) : null;
    ElementTreeSelectionDialog dialog = null;
    dialog = new FolderSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setValidator(validator);
    dialog.setAllowMultiple(allowMultiple);
    dialog.setTitle(title);
    dialog.setMessage(description);
    dialog.setInput(root);
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    dialog.setInitialSelection(focus);
    if (dialog.open() == Window.OK) {
        Object[] elements = dialog.getResult();
        IPath[] res = new IPath[elements.length];
        for (int i = 0; i < res.length; i++) {
            IResource elem = (IResource) elements[i];
            res[i] = elem.getFullPath();
        }
        return res;
    }
    return null;
}
Also used : ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IResource(org.eclipse.core.resources.IResource)

Example 87 with WorkbenchLabelProvider

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

the class MergeResultDialog method createDialogArea.

@Override
public Control createDialogArea(final Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    composite.setLayout(gridLayout);
    // result
    Label resultLabel = new Label(composite, SWT.NONE);
    resultLabel.setText(UIText.MergeResultDialog_result);
    resultLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    Text resultText = new Text(composite, SWT.READ_ONLY);
    MergeStatus status = mergeResult.getMergeStatus();
    resultText.setText(status.toString());
    resultText.setSelection(resultText.getCaretPosition());
    resultText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    if (status == MergeStatus.FAILED) {
        resultText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
        StringBuilder paths = new StringBuilder();
        Label pathsLabel = new Label(composite, SWT.NONE);
        pathsLabel.setText(UIText.MergeResultDialog_failed);
        pathsLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
        Text pathsText = new Text(composite, SWT.READ_ONLY);
        pathsText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
        Set<Entry<String, MergeFailureReason>> failedPaths = mergeResult.getFailingPaths().entrySet();
        int n = 0;
        for (Map.Entry<String, MergeFailureReason> e : failedPaths) {
            if (n > 0)
                paths.append(Text.DELIMITER);
            paths.append(e.getValue());
            // $NON-NLS-1$
            paths.append("\t");
            paths.append(e.getKey());
            n++;
            if (n > 10 && failedPaths.size() > 15)
                break;
        }
        if (n < failedPaths.size()) {
            paths.append(Text.DELIMITER);
            paths.append(MessageFormat.format(UIText.MergeResultDialog_nMore, Integer.valueOf(n - failedPaths.size())));
        }
        pathsText.setText(paths.toString());
    }
    if (status == MergeStatus.FAST_FORWARD || status == MergeStatus.FAST_FORWARD_SQUASHED || status == MergeStatus.MERGED) {
        // new head
        Label newHeadLabel = new Label(composite, SWT.NONE);
        newHeadLabel.setText(UIText.MergeResultDialog_newHead);
        newHeadLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
        Text newHeadText = new Text(composite, SWT.READ_ONLY);
        ObjectId newHead = mergeResult.getNewHead();
        if (newHead != null)
            newHeadText.setText(getCommitMessage(newHead) + SPACE + abbreviate(mergeResult.getNewHead(), true));
        newHeadText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    }
    // Merge Input
    Label mergeInputLabel = new Label(composite, SWT.NONE);
    mergeInputLabel.setText(UIText.MergeResultDialog_mergeInput);
    GridDataFactory.fillDefaults().align(SWT.LEAD, SWT.CENTER).span(2, 1).applyTo(mergeInputLabel);
    TableViewer viewer = new TableViewer(composite);
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void dispose() {
        // empty
        }

        @Override
        public void inputChanged(Viewer theViewer, Object oldInput, Object newInput) {
        // empty
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return getCommits(mergeResult.getMergedCommits());
        }
    });
    final IStyledLabelProvider styleProvider = new IStyledLabelProvider() {

        private final WorkbenchLabelProvider wrapped = new WorkbenchLabelProvider();

        @Override
        public void removeListener(ILabelProviderListener listener) {
        // Empty
        }

        @Override
        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        @Override
        public void dispose() {
            wrapped.dispose();
        }

        @Override
        public void addListener(ILabelProviderListener listener) {
        // Empty
        }

        @Override
        public StyledString getStyledText(Object element) {
            // supported
            if (element instanceof RepositoryCommit)
                return ((RepositoryCommit) element).getStyledText(element);
            return new StyledString(wrapped.getText(element));
        }

        @Override
        public Image getImage(Object element) {
            return wrapped.getImage(element);
        }
    };
    viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(styleProvider));
    applyDialogFont(composite);
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(viewer.getControl());
    viewer.setInput(mergeResult);
    new OpenAndLinkWithEditorHelper(viewer) {

        @Override
        protected void linkToEditor(ISelection selection) {
        // Not supported
        }

        @Override
        protected void open(ISelection selection, boolean activate) {
            handleOpen(selection, OpenStrategy.activateOnOpen());
        }

        @Override
        protected void activate(ISelection selection) {
            handleOpen(selection, true);
        }

        private void handleOpen(ISelection selection, boolean activateOnOpen) {
            if (selection instanceof IStructuredSelection)
                for (Object element : ((IStructuredSelection) selection).toArray()) if (element instanceof RepositoryCommit)
                    CommitEditor.openQuiet((RepositoryCommit) element, activateOnOpen);
        }
    };
    return composite;
}
Also used : OpenAndLinkWithEditorHelper(org.eclipse.ui.OpenAndLinkWithEditorHelper) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) StyledString(org.eclipse.jface.viewers.StyledString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) ISelection(org.eclipse.jface.viewers.ISelection) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ObjectId(org.eclipse.jgit.lib.ObjectId) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) StyledString(org.eclipse.jface.viewers.StyledString) MergeFailureReason(org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) MergeStatus(org.eclipse.jgit.api.MergeResult.MergeStatus) IStyledLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Map(java.util.Map) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 88 with WorkbenchLabelProvider

use of org.eclipse.ui.model.WorkbenchLabelProvider in project eclipse-cs by checkstyle.

the class CheckConfigurationWorkingSetEditor method createCheckConfigContents.

/**
 * Creates the content regarding the management of check configurations.
 *
 * @param parent
 *          the parent composite
 * @return the configuration area
 */
private Composite createCheckConfigContents(Composite parent) {
    Composite configComposite = new Composite(parent, SWT.NULL);
    configComposite.setLayout(new FormLayout());
    final Control rightButtons = createButtonBar(configComposite);
    FormData fd = new FormData();
    fd.top = new FormAttachment(0);
    fd.right = new FormAttachment(100);
    fd.bottom = new FormAttachment(100);
    rightButtons.setLayoutData(fd);
    Composite tableAndDesc = new Composite(configComposite, SWT.NULL);
    tableAndDesc.setLayout(new FormLayout());
    fd = new FormData();
    fd.left = new FormAttachment(0);
    fd.top = new FormAttachment(0);
    fd.right = new FormAttachment(rightButtons, -3, SWT.LEFT);
    fd.bottom = new FormAttachment(100, 0);
    tableAndDesc.setLayoutData(fd);
    final Control table = createConfigTable(tableAndDesc);
    fd = new FormData();
    fd.left = new FormAttachment(0);
    fd.top = new FormAttachment(0);
    fd.right = new FormAttachment(100);
    fd.bottom = new FormAttachment(70);
    table.setLayoutData(fd);
    Composite descArea = new Composite(tableAndDesc, SWT.NULL);
    descArea.setLayout(new FormLayout());
    fd = new FormData();
    fd.left = new FormAttachment(0);
    fd.top = new FormAttachment(table, 0);
    fd.right = new FormAttachment(mIsShowUsage ? 60 : 100);
    fd.bottom = new FormAttachment(100);
    descArea.setLayoutData(fd);
    Label lblDescription = new Label(descArea, SWT.NULL);
    lblDescription.setText(Messages.CheckstylePreferencePage_lblDescription);
    fd = new FormData();
    fd.left = new FormAttachment(0);
    fd.top = new FormAttachment(3);
    fd.right = new FormAttachment(100);
    lblDescription.setLayoutData(fd);
    mConfigurationDescription = new Text(descArea, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.VERTICAL);
    fd = new FormData();
    fd.left = new FormAttachment(0);
    fd.top = new FormAttachment(lblDescription);
    fd.right = new FormAttachment(100);
    fd.bottom = new FormAttachment(100);
    mConfigurationDescription.setLayoutData(fd);
    if (mIsShowUsage) {
        Composite usageArea = new Composite(tableAndDesc, SWT.NULL);
        usageArea.setLayout(new FormLayout());
        fd = new FormData();
        fd.left = new FormAttachment(60, 0);
        fd.top = new FormAttachment(table, 3);
        fd.right = new FormAttachment(100);
        fd.bottom = new FormAttachment(100);
        usageArea.setLayoutData(fd);
        Label lblUsage = new Label(usageArea, SWT.NULL);
        lblUsage.setText(Messages.CheckstylePreferencePage_lblProjectUsage);
        fd = new FormData();
        fd.left = new FormAttachment(0);
        fd.top = new FormAttachment(0);
        fd.right = new FormAttachment(100);
        lblUsage.setLayoutData(fd);
        mUsageView = new TableViewer(usageArea);
        mUsageView.getControl().setBackground(usageArea.getBackground());
        mUsageView.setContentProvider(new ArrayContentProvider());
        mUsageView.setLabelProvider(new WorkbenchLabelProvider());
        fd = new FormData();
        fd.left = new FormAttachment(0);
        fd.top = new FormAttachment(lblUsage);
        fd.right = new FormAttachment(100);
        fd.bottom = new FormAttachment(100);
        mUsageView.getControl().setLayoutData(fd);
    }
    // enforce update of button enabled state
    mController.selectionChanged(new SelectionChangedEvent(mViewer, new StructuredSelection()));
    return configComposite;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Control(org.eclipse.swt.widgets.Control) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Text(org.eclipse.swt.widgets.Text) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) EnhancedTableViewer(net.sf.eclipsecs.ui.util.table.EnhancedTableViewer) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 89 with WorkbenchLabelProvider

use of org.eclipse.ui.model.WorkbenchLabelProvider in project InformationSystem by ObeoNetwork.

the class DocumentationLinkDialog method createWorkspaceValueEditor.

private void createWorkspaceValueEditor(Group grpDocumentationSettings) {
    btnWorkspace = new Button(grpDocumentationSettings, SWT.RADIO);
    btnWorkspace.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    btnWorkspace.addSelectionListener(new SelectionAdapter() {

        /**
         * {@inheritDoc}
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            valueText.setEnabled(false);
            treeViewer.getControl().setEnabled(true);
        }
    });
    // $NON-NLS-1$
    btnWorkspace.setText(DocBridgeUI.getInstance().getString("DocumentationLinkDialog_WorkspaceEditor_title"));
    treeViewer = new TreeViewer(grpDocumentationSettings, SWT.BORDER);
    Tree tree = treeViewer.getTree();
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    tree.setEnabled(false);
    treeViewer.setContentProvider(new WorkbenchContentProvider());
    treeViewer.setLabelProvider(new WorkbenchLabelProvider());
    treeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
    treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection() instanceof StructuredSelection) {
                Object selection = ((StructuredSelection) event.getSelection()).getFirstElement();
                if (selection instanceof IFile) {
                    value = DocumentationLink.WORKSPACE_PREFIX + ((IFile) selection).getFullPath().toString();
                } else {
                    value = null;
                }
                updateButtons();
            }
        }
    });
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree)

Example 90 with WorkbenchLabelProvider

use of org.eclipse.ui.model.WorkbenchLabelProvider in project InformationSystem by ObeoNetwork.

the class SpecificWorkspaceResourceDialog method openFolderOrFileSelection.

public static IResource openFolderOrFileSelection(Shell parent, String title, String message, IPath suggestedPath, List<ViewerFilter> viewerFilters) {
    final SpecificWorkspaceResourceDialog dialog = new SpecificWorkspaceResourceDialog(parent, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setAllowMultiple(false);
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.setShowNewFolderControl(true);
    dialog.setShowFileControl(false);
    dialog.addFilter(dialog.createDefaultViewerFilter(false));
    if (viewerFilters != null) {
        for (ViewerFilter viewerFilter : viewerFilters) {
            dialog.addFilter(viewerFilter);
        }
    }
    if (suggestedPath != null) {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IResource resource = root.findMember(suggestedPath);
        if (resource != null && resource.isAccessible()) {
            if (resource instanceof IContainer) {
                dialog.setInitialSelection(resource);
            } else {
                dialog.setInitialSelection(resource.getParent());
                dialog.setFileText(resource.getName());
            }
        } else {
            if (suggestedPath.segmentCount() > 1) {
                if (resource == null) {
                    resource = root.getFile(suggestedPath);
                }
                if (resource.getProject().isAccessible()) {
                    IContainer container = resource.getParent();
                    for (; !container.isAccessible() && container != resource.getProject(); container = container.getParent()) {
                    // Do nothing
                    }
                    dialog.setInitialSelection(container);
                    suggestedPath = suggestedPath.removeFirstSegments(container.getFullPath().segmentCount());
                    dialog.setFileText(suggestedPath.toString());
                    suggestedPath = null;
                }
            }
            if (suggestedPath != null) {
                String fileText = suggestedPath.isAbsolute() ? suggestedPath.removeFirstSegments(1).toString() : suggestedPath.toString();
                dialog.setFileText(fileText);
            }
        }
    }
    dialog.loadContents();
    return dialog.open() == Window.OK ? dialog.getSelectedContainers()[0] : null;
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) 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)93 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)44 GridData (org.eclipse.swt.layout.GridData)36 Composite (org.eclipse.swt.widgets.Composite)36 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)36 GridLayout (org.eclipse.swt.layout.GridLayout)30 IResource (org.eclipse.core.resources.IResource)24 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)22 Button (org.eclipse.swt.widgets.Button)22 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)20 IFile (org.eclipse.core.resources.IFile)19 TableViewer (org.eclipse.jface.viewers.TableViewer)19 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)19 ResourceComparator (org.eclipse.ui.views.navigator.ResourceComparator)19 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)17 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)17 SelectionEvent (org.eclipse.swt.events.SelectionEvent)16 SelectionListener (org.eclipse.swt.events.SelectionListener)16 Label (org.eclipse.swt.widgets.Label)16 ArrayList (java.util.ArrayList)14