Search in sources :

Example 1 with RepositoryTreeContentProvider

use of bndtools.model.repo.RepositoryTreeContentProvider 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 2 with RepositoryTreeContentProvider

use of bndtools.model.repo.RepositoryTreeContentProvider in project bndtools by bndtools.

the class MapValuesContentProvider method createAvailableBundlesPanel.

Control createAvailableBundlesPanel(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    new Label(panel, SWT.NONE).setText("Available Bundles:");
    selectionSearchTxt = new Text(panel, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
    selectionSearchTxt.setMessage("filter bundle name");
    final Tree availableTree = new Tree(panel, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    availableViewer = new TreeViewer(availableTree);
    availableViewer.setLabelProvider(new RepositoryTreeLabelProvider(false));
    availableViewer.setContentProvider(new RepositoryTreeContentProvider());
    availableViewer.setAutoExpandLevel(2);
    availableViewer.setFilters(new ViewerFilter[] { alreadySelectedFilter });
    // Load data
    try {
        refreshBundleList();
    } catch (Exception e) {
        setErrorMessage("Error querying repositories: " + e.getMessage());
        logger.logError("Error querying repository configuration.", e);
    }
    // Listeners
    selectionSearchTxt.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_DOWN)
                availableTree.setFocus();
        }
    });
    selectionSearchTxt.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            availableViewer.setFilters(new ViewerFilter[] { alreadySelectedFilter });
        }
    });
    availableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        // Enable add button when a bundle or bundle version is selected on
        // the left
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) availableViewer.getSelection();
            for (Iterator<?> iter = sel.iterator(); iter.hasNext(); ) {
                Object element = iter.next();
                if (element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion || element instanceof ProjectBundle) {
                    addButton.setEnabled(true);
                    return;
                }
            }
            addButton.setEnabled(false);
        }
    });
    availableViewer.addOpenListener(new IOpenListener() {

        @Override
        public void open(OpenEvent event) {
            doAdd();
        }
    });
    GridLayout layout;
    GridData gd;
    layout = new GridLayout(1, false);
    panel.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    selectionSearchTxt.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.heightHint = 300;
    gd.widthHint = 250;
    availableTree.setLayoutData(gd);
    return panel;
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) ModifyListener(org.eclipse.swt.events.ModifyListener) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) RepositoryTreeContentProvider(bndtools.model.repo.RepositoryTreeContentProvider) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) KeyEvent(org.eclipse.swt.events.KeyEvent) ProjectBundle(bndtools.model.repo.ProjectBundle) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Iterator(java.util.Iterator) Tree(org.eclipse.swt.widgets.Tree) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Text(org.eclipse.swt.widgets.Text) RepositoryTreeLabelProvider(bndtools.model.repo.RepositoryTreeLabelProvider) IOpenListener(org.eclipse.jface.viewers.IOpenListener) GridData(org.eclipse.swt.layout.GridData) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Aggregations

RepositoryTreeContentProvider (bndtools.model.repo.RepositoryTreeContentProvider)2 RepositoryTreeLabelProvider (bndtools.model.repo.RepositoryTreeLabelProvider)2 IOpenListener (org.eclipse.jface.viewers.IOpenListener)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 OpenEvent (org.eclipse.jface.viewers.OpenEvent)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)2 Workspace (aQute.bnd.build.Workspace)1 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)1 ProjectBundle (bndtools.model.repo.ProjectBundle)1 RepositoryBundle (bndtools.model.repo.RepositoryBundle)1 RepositoryBundleVersion (bndtools.model.repo.RepositoryBundleVersion)1 Iterator (java.util.Iterator)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 IWizardPage (org.eclipse.jface.wizard.IWizardPage)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1