Search in sources :

Example 91 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project bndtools by bndtools.

the class LocalRepositorySelectionPage method createControl.

public void createControl(Composite parent) {
    setTitle("Select Local Repository");
    setMessage("Bundle will be imported into the selected repository.");
    Table table = new Table(parent, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    final TableViewer viewer = new TableViewer(table);
    viewer.setContentProvider(new RepositoryTreeContentProvider());
    viewer.setLabelProvider(new RepositoryTreeLabelProvider(false));
    viewer.setFilters(new ViewerFilter[] { new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return (element instanceof RepositoryPlugin) && ((RepositoryPlugin) element).canWrite();
        }
    } });
    try {
        Workspace workspace = Central.getWorkspace();
        viewer.setInput(workspace);
        if (selectedRepository != null)
            viewer.setSelection(new StructuredSelection(selectedRepository));
        validate(workspace);
    } catch (Exception e) {
        logger.logError("Error querying local repositories", e);
        setErrorMessage("Error querying local repositories, see log for details.");
    }
    // LISTENERS
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            setSelectedRepository((RepositoryPlugin) selection.getFirstElement());
        }
    });
    viewer.addOpenListener(new IOpenListener() {

        public void open(OpenEvent evt) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            setSelectedRepository((RepositoryPlugin) selection.getFirstElement());
            IWizardPage nextPage = getNextPage();
            if (nextPage != null)
                getContainer().showPage(nextPage);
        }
    });
    setControl(table);
}
Also used : Table(org.eclipse.swt.widgets.Table) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) RepositoryTreeContentProvider(bndtools.model.repo.RepositoryTreeContentProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryTreeLabelProvider(bndtools.model.repo.RepositoryTreeLabelProvider) IOpenListener(org.eclipse.jface.viewers.IOpenListener) IWizardPage(org.eclipse.jface.wizard.IWizardPage) TableViewer(org.eclipse.jface.viewers.TableViewer) Workspace(aQute.bnd.build.Workspace) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Example 92 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project bndtools by bndtools.

the class WorkspaceReleaseAction method selectionChanged.

/**
     * @see IActionDelegate#selectionChanged(IAction, ISelection)
     */
public void selectionChanged(IAction action, ISelection selection) {
    projects = Collections.emptySet();
    if (selection != null && (selection instanceof StructuredSelection)) {
        StructuredSelection ss = (StructuredSelection) selection;
        projects = new HashSet<IProject>();
        for (Iterator<?> itr = ss.iterator(); itr.hasNext(); ) {
            Object selected = itr.next();
            if (selected instanceof IProject) {
                projects.add((IProject) selected);
            } else if (selected instanceof IWorkingSet) {
                IWorkingSet workingSet = (IWorkingSet) selected;
                for (IAdaptable adaptable : workingSet.getElements()) {
                    IProject project = (IProject) adaptable.getAdapter(IProject.class);
                    if (project != null && !projects.contains(project)) {
                        projects.add(project);
                    }
                }
            } else if (selected instanceof IFile) {
                IFile bndFile = (IFile) selected;
                if (bndFile.getName().endsWith(Constants.DEFAULT_BND_EXTENSION)) {
                    if (!projects.contains(bndFile.getProject()))
                        projects.add(bndFile.getProject());
                }
            }
        }
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IProject(org.eclipse.core.resources.IProject) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 93 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project bndtools by bndtools.

the class ReleaseAction method getLocations.

static IFile[] getLocations(ISelection selection) {
    if (selection != null && (selection instanceof StructuredSelection)) {
        StructuredSelection ss = (StructuredSelection) selection;
        IFile[] result = new IFile[ss.size()];
        int n = 0;
        for (@SuppressWarnings("unchecked") Iterator<IFile> i = ss.iterator(); i.hasNext(); ) {
            result[n++] = i.next();
        }
        return result;
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 94 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project eclipse.platform.text by eclipse.

the class AnnotationsConfigurationBlock method applyData.

/**
 * Applies the given data.
 *
 * @param data the annotation type to select in the list or <code>null</code>
 * @see org.eclipse.ui.internal.editors.text.IPreferenceConfigurationBlock#applyData(java.lang.Object)
 * @since 3.4
 */
@Override
public void applyData(Object data) {
    if (!(data instanceof String))
        return;
    for (int i = 0; i < fListModel.length; i++) {
        final ListItem element = fListModel[i];
        if (data.equals(element.label)) {
            final Control control = fAnnotationTypeViewer.getControl();
            control.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    control.setFocus();
                    fAnnotationTypeViewer.setSelection(new StructuredSelection(element), true);
                }
            });
            return;
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 95 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project eclipse.platform.text by eclipse.

the class LinkedModeConfigurationBlock method updateDecorationViewer.

private void updateDecorationViewer(ListItem item, boolean changed) {
    // decoration selection: if the checkbox is enabled, there is
    // only one case where the combo is not enabled: if both the highlight and textStyle keys are null
    final boolean enabled = fShowInTextCheckBox.getSelection() && !(item.highlightKey == null && item.textStyleKey == null);
    fDecorationViewer.getControl().setEnabled(enabled);
    if (changed) {
        String[] selection = null;
        ArrayList<String[]> list = new ArrayList<>();
        list.addAll(item.validStyles);
        if (getPreferenceStore().getBoolean(item.highlightKey))
            selection = HIGHLIGHT;
        // set selection
        if (selection == null) {
            String val = getPreferenceStore().getString(item.textStyleKey);
            for (Iterator<String[]> iter = list.iterator(); iter.hasNext(); ) {
                String[] elem = iter.next();
                if (elem[1].equals(val)) {
                    selection = elem;
                    break;
                }
            }
        }
        fDecorationViewer.setInput(list.toArray(new Object[list.size()]));
        if (selection == null)
            selection = list.get(0);
        fDecorationViewer.setSelection(new StructuredSelection((Object) selection), true);
    }
}
Also used : ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)256 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)133 ArrayList (java.util.ArrayList)59 ISelection (org.eclipse.jface.viewers.ISelection)43 List (java.util.List)35 GridData (org.eclipse.swt.layout.GridData)28 TreeViewer (org.eclipse.jface.viewers.TreeViewer)25 Composite (org.eclipse.swt.widgets.Composite)24 SelectionEvent (org.eclipse.swt.events.SelectionEvent)21 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)20 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)20 IFile (org.eclipse.core.resources.IFile)19 Label (org.eclipse.swt.widgets.Label)19 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)18 GridLayout (org.eclipse.swt.layout.GridLayout)18 Shell (org.eclipse.swt.widgets.Shell)17 IViewPart (org.eclipse.ui.IViewPart)15 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)15 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)14 Button (org.eclipse.swt.widgets.Button)14