Search in sources :

Example 1 with RepositoryTreeLabelProvider

use of bndtools.model.repo.RepositoryTreeLabelProvider 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 RepositoryTreeLabelProvider

use of bndtools.model.repo.RepositoryTreeLabelProvider 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)

Example 3 with RepositoryTreeLabelProvider

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

the class RepositoriesView method createPartControl.

@Override
public void createPartControl(final Composite parent) {
    // CREATE CONTROLS
    final StackLayout stackLayout = new StackLayout();
    parent.setLayout(stackLayout);
    FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    Composite defaultParent = toolkit.createComposite(parent, SWT.NONE);
    FillLayout fill = new FillLayout();
    fill.marginHeight = 5;
    fill.marginWidth = 5;
    defaultParent.setLayout(fill);
    if (!Central.hasWorkspaceDirectory()) {
        FormText form = toolkit.createFormText(defaultParent, true);
        form.setText("<form><p>No workspace configuration found. <a>Create a new Bnd workspace...</a></p></form>", true, false);
        form.addHyperlinkListener(new HyperlinkAdapter() {

            @Override
            public void linkActivated(HyperlinkEvent e) {
                IWorkbench workbench = PlatformUI.getWorkbench();
                IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
                WorkspaceSetupWizard wizard = new WorkspaceSetupWizard();
                wizard.init(workbench, StructuredSelection.EMPTY);
                WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
                dialog.open();
            }
        });
    } else {
        toolkit.createLabel(defaultParent, "Repositories are loading, please wait...");
    }
    stackLayout.topControl = defaultParent;
    parent.layout();
    final Composite mainPanel = new Composite(parent, SWT.NONE);
    filterPanel = filterPart.createControl(mainPanel, 5, 5);
    Tree tree = new Tree(mainPanel, SWT.FULL_SELECTION | SWT.MULTI);
    filterPanel.setBackground(tree.getBackground());
    viewer = new TreeViewer(tree);
    contentProvider = new SearchableRepositoryTreeContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            super.inputChanged(viewer, oldInput, newInput);
            if (newInput != null) {
                stackLayout.topControl = mainPanel;
                advancedSearchAction.setEnabled(true);
                refreshAction.setEnabled(true);
                collapseAllAction.setEnabled(true);
                configureOfflineAction();
                parent.layout();
            }
        }
    };
    viewer.setContentProvider(contentProvider);
    ColumnViewerToolTipSupport.enableFor(viewer);
    viewer.setLabelProvider(new RepositoryTreeLabelProvider(false));
    getViewSite().setSelectionProvider(viewer);
    Central.addRepositoriesViewer(viewer, RepositoriesView.this);
    JpmPreferences jpmPrefs = new JpmPreferences();
    final boolean showJpmOnClick = jpmPrefs.getBrowserSelection() != JpmPreferences.PREF_BROWSER_EXTERNAL;
    // LISTENERS
    filterPart.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            String filter = (String) event.getNewValue();
            updatedFilter(filter);
        }
    });
    ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            if (target == null)
                return false;
            if (canDrop(target, transferType))
                return true;
            boolean valid = false;
            if (target instanceof RepositoryPlugin) {
                if (((RepositoryPlugin) target).canWrite()) {
                    if (URLTransfer.getInstance().isSupportedType(transferType))
                        return true;
                    if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
                        ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
                        if (selection instanceof IStructuredSelection) {
                            for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
                                Object element = iter.next();
                                if (element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion) {
                                    valid = true;
                                    break;
                                }
                                if (element instanceof IFile) {
                                    valid = true;
                                    break;
                                }
                                if (element instanceof IAdaptable) {
                                    IFile file = (IFile) ((IAdaptable) element).getAdapter(IFile.class);
                                    if (file != null) {
                                        valid = true;
                                        break;
                                    }
                                }
                            }
                        }
                    } else {
                        valid = true;
                    }
                }
            }
            return valid;
        }

        @Override
        public void dragEnter(DropTargetEvent event) {
            super.dragEnter(event);
            event.detail = DND.DROP_COPY;
        }

        @Override
        public boolean performDrop(Object data) {
            if (RepositoriesView.this.performDrop(getCurrentTarget(), getCurrentEvent().currentDataType, data)) {
                viewer.refresh(getCurrentTarget(), true);
                return true;
            }
            boolean copied = false;
            if (URLTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) {
                try {
                    URL url = new URL((String) URLTransfer.getInstance().nativeToJava(getCurrentEvent().currentDataType));
                    if (!url.getPath().endsWith(".jar")) {
                        String uris = url.toString();
                        if (uris.contains("#!/p/sha/")) {
                            MessageDialog.openWarning(null, "Dropped URL is a JPM Revision Identifier, not a JAR", "The dropped URL is a JPM identifier, can only be dropped on a JPM repository. You can also select the revision on JPM and drag the 'jar' link of the revision to any of the other repositories.");
                            return false;
                        }
                    }
                    File tmp = File.createTempFile("dwnl", ".jar");
                    try (HttpClient client = new HttpClient()) {
                        IO.copy(client.connect(url), tmp);
                    }
                    if (isJarFile(tmp)) {
                        copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), new File[] { tmp });
                    } else {
                        tmp.delete();
                        MessageDialog.openWarning(null, "Unrecognized Artifact", "The dropped URL is not recognized as a remote JAR file: " + url.toString());
                    }
                } catch (Exception e) {
                    return false;
                }
            } else if (data instanceof String[]) {
                String[] paths = (String[]) data;
                File[] files = new File[paths.length];
                for (int i = 0; i < paths.length; i++) {
                    files[i] = new File(paths[i]);
                }
                copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
            } else if (data instanceof IResource[]) {
                IResource[] resources = (IResource[]) data;
                File[] files = new File[resources.length];
                for (int i = 0; i < resources.length; i++) {
                    files[i] = resources[i].getLocation().toFile();
                }
                copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
            } else if (data instanceof IStructuredSelection) {
                File[] files = convertSelectionToFiles((IStructuredSelection) data);
                if (files != null && files.length > 0)
                    copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
            }
            return copied;
        }
    };
    dropAdapter.setFeedbackEnabled(false);
    dropAdapter.setExpandEnabled(false);
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { URLTransfer.getInstance(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), LocalSelectionTransfer.getTransfer() }, dropAdapter);
    viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new SelectionDragAdapter(viewer));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            boolean writableRepoSelected = false;
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object element = selection.getFirstElement();
            if (element instanceof RepositoryPlugin) {
                RepositoryPlugin repo = (RepositoryPlugin) element;
                writableRepoSelected = repo.canWrite();
            }
            addBundlesAction.setEnabled(writableRepoSelected);
        }
    });
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent ev) {
            Object element = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (element instanceof ContinueSearchElement) {
                try {
                    getViewSite().getPage().showView(Plugin.JPM_BROWSER_VIEW_ID, null, showJpmOnClick ? IWorkbenchPage.VIEW_ACTIVATE : IWorkbenchPage.VIEW_CREATE);
                } catch (PartInitException e) {
                    Plugin.getDefault().getLog().log(e.getStatus());
                }
            }
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (!event.getSelection().isEmpty()) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                final Object element = selection.getFirstElement();
                if (element instanceof IAdaptable) {
                    final URI uri = (URI) ((IAdaptable) element).getAdapter(URI.class);
                    if (uri == null && element instanceof RepositoryEntry) {
                        boolean download = MessageDialog.openQuestion(getSite().getShell(), "Repositories", "This repository entry is unable to be opened because it has not been downloaded. Download and open it now?");
                        if (download) {
                            final RepositoryEntry entry = (RepositoryEntry) element;
                            Job downloadJob = new Job("Downloading repository entry " + entry.getBsn()) {

                                @Override
                                protected IStatus run(IProgressMonitor monitor) {
                                    final File repoFile = entry.getFile(true);
                                    if (repoFile != null && repoFile.exists()) {
                                        getSite().getShell().getDisplay().asyncExec(new Runnable() {

                                            @Override
                                            public void run() {
                                                openURI(repoFile.toURI());
                                            }
                                        });
                                    }
                                    return Status.OK_STATUS;
                                }
                            };
                            downloadJob.setUser(true);
                            downloadJob.schedule();
                        }
                    } else if (uri != null) {
                        openURI(uri);
                    }
                } else if (element instanceof ContinueSearchElement) {
                    ContinueSearchElement searchElement = (ContinueSearchElement) element;
                    try {
                        JpmPreferences jpmPrefs = new JpmPreferences();
                        if (jpmPrefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_EXTERNAL) {
                            URI browseUrl = searchElement.browse();
                            getViewSite().getWorkbenchWindow().getWorkbench().getBrowserSupport().getExternalBrowser().openURL(browseUrl.toURL());
                        } else
                            getViewSite().getPage().showView(Plugin.JPM_BROWSER_VIEW_ID, null, IWorkbenchPage.VIEW_VISIBLE);
                    } catch (PartInitException e) {
                        Plugin.getDefault().getLog().log(e.getStatus());
                    } catch (Exception e) {
                        Plugin.getDefault().getLog().log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Failed to load repository browser view", e));
                    }
                } else if (element instanceof RepositoryPlugin) {
                    viewer.setExpandedState(element, !viewer.getExpandedState(element));
                }
            }
        }
    });
    createContextMenu();
    // LAYOUT
    GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    mainPanel.setLayout(layout);
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    filterPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    // Toolbar
    createActions();
    fillToolBar(getViewSite().getActionBars().getToolBarManager());
    prefs.addPropertyChangeListener(workspaceOfflineListener);
    // synthenic call to "refresh" so that we can get the repositories to show up in the UI
    new WorkspaceJob("Load repositories") {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            try {
                Central.refreshPlugins();
            } catch (Exception e) {
            // ignore errors there may be no workspace yet
            }
            return Status.OK_STATUS;
        }
    }.schedule();
    IActionBars actionBars = getViewSite().getActionBars();
    actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction);
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) IAdaptable(org.eclipse.core.runtime.IAdaptable) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryEntry(bndtools.model.repo.RepositoryEntry) ContinueSearchElement(bndtools.model.repo.ContinueSearchElement) Tree(org.eclipse.swt.widgets.Tree) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Job(org.eclipse.core.runtime.jobs.Job) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) PropertyChangeEvent(java.beans.PropertyChangeEvent) JpmPreferences(bndtools.preferences.JpmPreferences) FormText(org.eclipse.ui.forms.widgets.FormText) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) FillLayout(org.eclipse.swt.layout.FillLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) JarFile(java.util.jar.JarFile) SelectionDragAdapter(bndtools.utils.SelectionDragAdapter) IStatus(org.eclipse.core.runtime.IStatus) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) IFile(org.eclipse.core.resources.IFile) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) PropertyChangeListener(java.beans.PropertyChangeListener) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) URI(java.net.URI) URL(java.net.URL) SearchableRepositoryTreeContentProvider(bndtools.model.repo.SearchableRepositoryTreeContentProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TransferData(org.eclipse.swt.dnd.TransferData) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) StackLayout(org.eclipse.swt.custom.StackLayout) ISelection(org.eclipse.jface.viewers.ISelection) PartInitException(org.eclipse.ui.PartInitException) IActionBars(org.eclipse.ui.IActionBars) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) MouseAdapter(org.eclipse.swt.events.MouseAdapter) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) IWorkbench(org.eclipse.ui.IWorkbench) WorkspaceSetupWizard(bndtools.wizards.workspace.WorkspaceSetupWizard) RepositoryTreeLabelProvider(bndtools.model.repo.RepositoryTreeLabelProvider) HttpClient(aQute.bnd.http.HttpClient) GridData(org.eclipse.swt.layout.GridData) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IResource(org.eclipse.core.resources.IResource) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 4 with RepositoryTreeLabelProvider

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

the class AvailableBundlesPart method createClient.

private void createClient(Section section, FormToolkit toolkit) {
    section.setText("Browse Repos");
    // Create contents
    Composite container = toolkit.createComposite(section);
    section.setClient(container);
    GridLayout layout = new GridLayout(1, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    container.setLayout(layout);
    txtSearch = toolkit.createText(container, "", SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL | SWT.BORDER);
    txtSearch.setMessage("Enter search string");
    txtSearch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Tree tree = toolkit.createTree(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL);
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    viewer = new TreeViewer(tree);
    contentProvider.setShowRepos(false);
    viewer.setContentProvider(contentProvider);
    viewer.setLabelProvider(new RepositoryTreeLabelProvider(true));
    viewer.setFilters(new ViewerFilter[] { includedRepoFilter });
    txtSearch.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (scheduledFilterUpdate != null)
                scheduledFilterUpdate.cancel(true);
            searchStr = txtSearch.getText();
            scheduledFilterUpdate = Plugin.getDefault().getScheduler().schedule(updateFilterTask, SEARCH_DELAY, TimeUnit.MILLISECONDS);
        }
    });
    txtSearch.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            if (scheduledFilterUpdate != null)
                scheduledFilterUpdate.cancel(true);
            scheduledFilterUpdate = null;
            searchStr = txtSearch.getText();
            updateFilterTask.run();
        }
    });
    viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new SelectionDragAdapter(viewer) {

        @Override
        public void dragStart(DragSourceEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            if (!selection.isEmpty()) {
                LocalSelectionTransfer.getTransfer().setSelection(selection);
                LocalSelectionTransfer.getTransfer().setSelectionSetTime(event.time & 0xFFFFFFFFL);
            } else {
                event.doit = false;
            }
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) GridLayout(org.eclipse.swt.layout.GridLayout) RepositoryTreeLabelProvider(bndtools.model.repo.RepositoryTreeLabelProvider) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) SelectionDragAdapter(bndtools.utils.SelectionDragAdapter)

Aggregations

RepositoryTreeLabelProvider (bndtools.model.repo.RepositoryTreeLabelProvider)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 Tree (org.eclipse.swt.widgets.Tree)3 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)2 RepositoryBundle (bndtools.model.repo.RepositoryBundle)2 RepositoryBundleVersion (bndtools.model.repo.RepositoryBundleVersion)2 RepositoryTreeContentProvider (bndtools.model.repo.RepositoryTreeContentProvider)2 SelectionDragAdapter (bndtools.utils.SelectionDragAdapter)2 IOpenListener (org.eclipse.jface.viewers.IOpenListener)2 OpenEvent (org.eclipse.jface.viewers.OpenEvent)2 Viewer (org.eclipse.jface.viewers.Viewer)2 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)2 Workspace (aQute.bnd.build.Workspace)1 HttpClient (aQute.bnd.http.HttpClient)1