Search in sources :

Example 6 with ResourceDescriptor

use of aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor in project bnd by bndtools.

the class RepoCommand method _copy.

public void _copy(CopyOptions options) throws Exception {
    List<String> args = options._arguments();
    String srcName = args.remove(0);
    String dstName = args.remove(0);
    RepositoryPlugin source = workspace.getRepository(srcName);
    RepositoryPlugin dest = workspace.getRepository(dstName);
    if (source == null) {
        bnd.error("No such source repository: %s, available repos %s", srcName, workspace.getRepositories());
    }
    if (dest == null) {
        bnd.error("No such destination repository: %s, available repos %s", dstName, workspace.getRepositories());
    } else if (!dest.canWrite())
        bnd.error("Destination repository cannot write: %s", dest);
    if (!bnd.isOk() || source == null || dest == null) {
        return;
    }
    logger.debug("src = {} -> {}", srcName, source);
    logger.debug("dst = {} -> {}", dstName, dest);
    @SuppressWarnings("unused")
    class Spec {

        DownloadBlocker src;

        DownloadBlocker dst;

        String bsn;

        Version version;

        public byte[] digest;
    }
    List<Spec> sources = new ArrayList<Spec>();
    for (String bsn : source.list(null)) {
        for (Version version : source.versions(bsn)) {
            logger.debug("src: {} {}", bsn, version);
            Spec spec = new Spec();
            spec.bsn = bsn;
            spec.version = version;
            spec.src = new DownloadBlocker(bnd);
            File src = source.get(bsn, version, null, spec.src);
            if (src == null) {
                bnd.error("No such entry: %s-%s", bsn, version);
            } else {
                spec.dst = findMatchingVersion(dest, bsn, version);
                sources.add(spec);
            }
        }
    }
    for (Spec spec : sources) {
        String reason = spec.src.getReason();
        if (reason != null) {
            bnd.error("Failed to find %s because: %s", spec.src.getFile(), reason);
        }
        File src = spec.src.getFile();
        if (!src.isFile()) {
            bnd.error("Not a valid file %s", spec.src.getFile());
        }
        spec.digest = SHA1.digest(src).digest();
    }
    //
    // See if we can prune the list by diffing
    //
    ResourceRepository resources = null;
    if (dest instanceof ResourceRepository)
        resources = (ResourceRepository) dest;
    nextFile: for (Iterator<Spec> i = sources.iterator(); i.hasNext(); ) {
        Spec spec = i.next();
        if (resources != null) {
            ResourceDescriptor rd = resources.getResourceDescriptor(spec.digest);
            if (rd != null)
                // Already exists
                continue nextFile;
        }
    // TODO Diff
    }
    if (!bnd.isOk())
        return;
    for (Spec spec : sources) {
        File src = spec.src.getFile();
        if (!options.dry()) {
            try (InputStream fin = IO.stream(src)) {
                PutResult put = dest.put(fin, null);
                if (put.digest != null) {
                    if (!Arrays.equals(spec.digest, put.digest)) {
                        bnd.error("Digest error in upload %s", src);
                    }
                }
            } catch (Exception e) {
                bnd.exception(e, "Exception %s in upload %s", e, src);
            }
        }
    }
    for (String bsn : source.list(null)) {
        for (Version version : source.versions(bsn)) {
            System.out.println(bsn + ";version=" + version);
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) DownloadBlocker(aQute.bnd.build.DownloadBlocker) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Version(aQute.bnd.version.Version) Iterator(java.util.Iterator) ResourceRepository(aQute.bnd.service.repository.ResourceRepository) File(java.io.File) PutResult(aQute.bnd.service.RepositoryPlugin.PutResult) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 7 with ResourceDescriptor

use of aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor in project bnd by bndtools.

the class InfoRepositoryWrapper method init.

boolean init() {
    try {
        if (System.currentTimeMillis() < lastTime + 10000)
            return true;
    } finally {
        lastTime = System.currentTimeMillis();
    }
    Set<String> errors = new LinkedHashSet<String>();
    try {
        //
        // Get the current repo contents
        //
        Set<String> toBeDeleted = new HashSet<String>(persistent.keySet());
        Map<String, DownloadBlocker> blockers = new HashMap<String, DownloadBlocker>();
        for (InfoRepository repo : repos) {
            Map<String, ResourceDescriptor> map = collectKeys(repo);
            for (final Map.Entry<String, ResourceDescriptor> entry : map.entrySet()) {
                final String id = entry.getKey();
                toBeDeleted.remove(id);
                if (persistent.containsKey(id))
                    continue;
                final ResourceDescriptor rd = entry.getValue();
                DownloadBlocker blocker = new DownloadBlocker(null) {

                    //
                    // We steal the thread of the downloader to index
                    //
                    @Override
                    public void success(File file) throws Exception {
                        IndexResult index = null;
                        try {
                            index = repoIndexer.indexFile(file);
                            ResourceBuilder rb = new ResourceBuilder();
                            for (org.osgi.service.indexer.Capability capability : index.capabilities) {
                                CapReqBuilder cb = new CapReqBuilder(capability.getNamespace());
                                cb.addAttributes(capability.getAttributes());
                                cb.addDirectives(capability.getDirectives());
                                rb.addCapability(cb.buildSyntheticCapability());
                            }
                            for (org.osgi.service.indexer.Requirement requirement : index.requirements) {
                                CapReqBuilder cb = new CapReqBuilder(requirement.getNamespace());
                                cb.addAttributes(requirement.getAttributes());
                                cb.addDirectives(requirement.getDirectives());
                                rb.addRequirement(cb.buildSyntheticRequirement());
                            }
                            Resource resource = rb.build();
                            PersistentResource pr = new PersistentResource(resource);
                            persistent.put(id, pr);
                        } finally {
                            super.success(file);
                            if (index != null) {
                                index.resource.close();
                            }
                        }
                    }
                };
                blockers.put(entry.getKey(), blocker);
                repo.get(rd.bsn, rd.version, null, blocker);
            }
        }
        for (Entry<String, DownloadBlocker> entry : blockers.entrySet()) {
            String key = entry.getKey();
            DownloadBlocker blocker = entry.getValue();
            String reason = blocker.getReason();
            if (reason != null) {
                errors.add(key + ": " + reason);
            }
        }
        persistent.keySet().removeAll(toBeDeleted);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (!errors.isEmpty())
        throw new IllegalStateException("Cannot index " + repos + " due to " + errors);
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) IndexResult(org.osgi.service.indexer.ResourceIndexer.IndexResult) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) PersistentResource(aQute.bnd.osgi.resource.PersistentResource) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) PersistentResource(aQute.bnd.osgi.resource.PersistentResource) Resource(org.osgi.resource.Resource) DownloadBlocker(aQute.bnd.build.DownloadBlocker) InfoRepository(aQute.bnd.service.repository.InfoRepository) IOException(java.io.IOException) HashMap(java.util.HashMap) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) PersistentMap(aQute.lib.persistentmap.PersistentMap) File(java.io.File) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 8 with ResourceDescriptor

use of aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor in project bndtools by bndtools.

the class RepositoryBundleSelectionPart method createSection.

void createSection(Section section, FormToolkit toolkit) {
    // Toolbar buttons
    ToolBar toolbar = new ToolBar(section, SWT.FLAT);
    section.setTextClient(toolbar);
    fillToolBar(toolbar);
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
    viewer = new TableViewer(table);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(getLabelProvider());
    // Listeners
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ToolItem remove = getRemoveItemTool();
            if (remove != null)
                remove.setEnabled(isRemovable(event.getSelection()));
        }
    });
    ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {

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

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            if (FileTransfer.getInstance().isSupportedType(transferType))
                return true;
            if (ResourceTransfer.getInstance().isSupportedType(transferType))
                return true;
            if (URLTransfer.getInstance().isSupportedType(transferType))
                return true;
            ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
            if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
                return false;
            }
            Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
            while (iterator.hasNext()) {
                if (!selectionIsDroppable(iterator.next())) {
                    return false;
                }
            }
            return true;
        }

        private boolean selectionIsDroppable(Object element) {
            return element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion || element instanceof ProjectBundle || element instanceof RepositoryResourceElement;
        }

        @Override
        public boolean performDrop(Object data) {
            TransferData transfer = getCurrentEvent().currentDataType;
            if (URLTransfer.getInstance().isSupportedType(transfer)) {
                String urlStr = (String) URLTransfer.getInstance().nativeToJava(transfer);
                return handleURLDrop(urlStr);
            } else if (data instanceof String[]) {
                return handleFileNameDrop((String[]) data);
            } else if (data instanceof IResource[]) {
                return handleResourceDrop((IResource[]) data);
            } else {
                return handleSelectionDrop();
            }
        }

        private boolean handleResourceDrop(IResource[] resources) {
            File[] files = new File[resources.length];
            for (int i = 0; i < resources.length; i++) {
                files[i] = resources[i].getLocation().toFile();
            }
            return handleFileDrop(files);
        }

        private boolean handleFileNameDrop(String[] paths) {
            File[] files = new File[paths.length];
            for (int i = 0; i < paths.length; i++) {
                files[i] = new File(paths[i]);
            }
            return handleFileDrop(files);
        }

        private boolean handleFileDrop(File[] files) {
            if (files.length > 0) {
                BndPreferences prefs = new BndPreferences();
                boolean hideWarning = prefs.getHideWarningExternalFile();
                if (!hideWarning) {
                    MessageDialogWithToggle dialog = MessageDialogWithToggle.openWarning(getSection().getShell(), "Add External Files", "External files cannot be directly added to a project, they must be added to a local repository first.", "Do not show this warning again.", false, null, null);
                    if (Window.CANCEL == dialog.getReturnCode())
                        return false;
                    if (dialog.getToggleState()) {
                        prefs.setHideWarningExternalFile(true);
                    }
                }
                AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(null, files);
                WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
                if (Window.OK == dialog.open()) {
                    List<Pair<String, String>> addingBundles = wizard.getSelectedBundles();
                    List<VersionedClause> addingClauses = new ArrayList<VersionedClause>(addingBundles.size());
                    for (Pair<String, String> addingBundle : addingBundles) {
                        Attrs attribs = new Attrs();
                        attribs.put(Constants.VERSION_ATTRIBUTE, addingBundle.getSecond());
                        addingClauses.add(new VersionedClause(addingBundle.getFirst(), attribs));
                    }
                    handleAdd(addingClauses);
                }
                return true;
            }
            return false;
        }

        private boolean handleSelectionDrop() {
            ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
            if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
                return false;
            }
            List<VersionedClause> adding = new LinkedList<VersionedClause>();
            Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
            while (iterator.hasNext()) {
                Object item = iterator.next();
                if (item instanceof RepositoryBundle) {
                    VersionedClause newClause = RepositoryBundleUtils.convertRepoBundle((RepositoryBundle) item);
                    adding.add(newClause);
                } else if (item instanceof RepositoryBundleVersion) {
                    RepositoryBundleVersion bundleVersion = (RepositoryBundleVersion) item;
                    VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(bundleVersion, phase);
                    adding.add(newClause);
                } else if (item instanceof RepositoryResourceElement) {
                    RepositoryResourceElement elt = (RepositoryResourceElement) item;
                    VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(elt.getRepositoryBundleVersion(), phase);
                    adding.add(newClause);
                }
            }
            handleAdd(adding);
            return true;
        }

        private boolean handleURLDrop(String urlStr) {
            try {
                URI uri = new URI(sanitizeUrl(urlStr));
                AddJpmDependenciesWizard wizard = new AddJpmDependenciesWizard(uri);
                WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
                if (dialog.open() == Window.OK) {
                    Set<ResourceDescriptor> resources = wizard.getResult();
                    List<VersionedClause> newBundles = new ArrayList<VersionedClause>(resources.size());
                    for (ResourceDescriptor resource : resources) {
                        Attrs attrs = new Attrs();
                        attrs.put(Constants.VERSION_ATTRIBUTE, resource.version != null ? resource.version.toString() : Version.emptyVersion.toString());
                        VersionedClause clause = new VersionedClause(resource.bsn, attrs);
                        newBundles.add(clause);
                    }
                    handleAdd(newBundles);
                    return true;
                }
                return false;
            } catch (URISyntaxException e) {
                MessageDialog.openError(getSection().getShell(), "Error", "The dropped URL was invalid: " + urlStr);
                return false;
            }
        }

        private String sanitizeUrl(String urlStr) {
            int newline = urlStr.indexOf('\n');
            if (newline > -1)
                return urlStr.substring(0, newline).trim();
            return urlStr;
        }

        private void handleAdd(Collection<VersionedClause> newClauses) {
            if (newClauses == null || newClauses.isEmpty())
                return;
            List<VersionedClause> toAdd = new LinkedList<VersionedClause>();
            for (VersionedClause newClause : newClauses) {
                boolean found = false;
                for (ListIterator<VersionedClause> iter = bundles.listIterator(); iter.hasNext(); ) {
                    VersionedClause existing = iter.next();
                    if (newClause.getName().equals(existing.getName())) {
                        int index = iter.previousIndex();
                        iter.set(newClause);
                        viewer.replace(newClause, index);
                        found = true;
                        break;
                    }
                }
                if (!found)
                    toAdd.add(newClause);
            }
            bundles.addAll(toAdd);
            viewer.add(toAdd.toArray());
            markDirty();
        }
    };
    dropAdapter.setFeedbackEnabled(false);
    dropAdapter.setExpandEnabled(false);
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), URLTransfer.getInstance() }, dropAdapter);
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.DEL) {
                doRemove();
            } else if (e.character == '+') {
                doAdd();
            }
        }
    });
    // Layout
    GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 50;
    gd.heightHint = getTableHeightHint();
    table.setLayoutData(gd);
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) BndPreferences(bndtools.preferences.BndPreferences) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ArrayList(java.util.ArrayList) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ProjectBundle(bndtools.model.repo.ProjectBundle) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) LinkedList(java.util.LinkedList) Collection(java.util.Collection) File(java.io.File) AddFilesToRepositoryWizard(bndtools.wizards.workspace.AddFilesToRepositoryWizard) Attrs(aQute.bnd.header.Attrs) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) TransferData(org.eclipse.swt.dnd.TransferData) ISelection(org.eclipse.jface.viewers.ISelection) ToolItem(org.eclipse.swt.widgets.ToolItem) Pair(bndtools.types.Pair) Composite(org.eclipse.swt.widgets.Composite) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) RepositoryResourceElement(bndtools.model.repo.RepositoryResourceElement) ToolBar(org.eclipse.swt.widgets.ToolBar) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) AddJpmDependenciesWizard(org.bndtools.core.ui.wizards.jpm.AddJpmDependenciesWizard) TableViewer(org.eclipse.jface.viewers.TableViewer) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IResource(org.eclipse.core.resources.IResource) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 9 with ResourceDescriptor

use of aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor in project bnd by bndtools.

the class FileRepoTest method testIndex.

/**
	 * Test a repo with an index
	 */
public void testIndex() throws Exception {
    //
    // Check if the index property works
    // by verifying the diff between the
    // testRepo and the indexed Repo
    //
    assertNull(testRepo.getResources());
    assertNotNull(indexedRepo.getResources());
    //
    // Check that we can actually put a resource
    //
    PutResult put = indexedRepo.put(IO.getFile("jar/osgi.jar").toURI().toURL().openStream(), null);
    assertNotNull(put);
    // Can we get it?
    ResourceDescriptor desc = indexedRepo.getDescriptor("osgi", new Version("4.0"));
    assertNotNull(desc);
    // Got the same file?
    assertTrue(Arrays.equals(put.digest, desc.id));
    //
    // Check if the description was copied
    //
    assertEquals("OSGi Service Platform Release 4 Interfaces and Classes for use in compiling bundles.", desc.description);
    //
    // We must be able to access by its sha1
    //
    ResourceDescriptor resource = indexedRepo.getResource(put.digest);
    assertTrue(Arrays.equals(resource.id, desc.id));
    //
    // Check if we now have a set of resources
    //
    SortedSet<ResourceDescriptor> resources = indexedRepo.getResources();
    assertEquals(1, resources.size());
    ResourceDescriptor rd = resources.iterator().next();
    assertTrue(Arrays.equals(rd.id, put.digest));
    //
    // Check if the bsn brings us back
    //
    File file = indexedRepo.get(desc.bsn, desc.version, null);
    assertNotNull(file);
    assertTrue(Arrays.equals(put.digest, SHA1.digest(file).digest()));
    byte[] digest = SHA256.digest(file).digest();
    assertTrue(Arrays.equals(rd.sha256, digest));
    //
    // Delete and see if it is really gone
    //
    indexedRepo.delete(desc.bsn, desc.version);
    resources = indexedRepo.getResources();
    assertEquals(0, resources.size());
    file = indexedRepo.get(desc.bsn, desc.version, null);
    assertNull(file);
    resource = indexedRepo.getResource(put.digest);
    assertNull(resource);
}
Also used : Version(aQute.bnd.version.Version) PutResult(aQute.bnd.service.RepositoryPlugin.PutResult) IO.getFile(aQute.lib.io.IO.getFile) File(java.io.File) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 10 with ResourceDescriptor

use of aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor in project bndtools by bndtools.

the class JpmDependencyWizardPage method createControl.

@Override
@SuppressWarnings("unused")
public void createControl(Composite parent) {
    // CREATE CONTROLS
    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);
    Label lblDirect = new Label(container, SWT.NONE);
    lblDirect.setFont(JFaceResources.getBannerFont());
    lblDirect.setText("Direct Dependencies:");
    Table tblDirect = new Table(container, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL);
    viewerDirect = new TableViewer(tblDirect);
    viewerDirect.setContentProvider(ArrayContentProvider.getInstance());
    viewerDirect.setLabelProvider(new ResourceDescriptorLabelProvider());
    createHelpLabel(container, "The above dependencies will be added to the project and, if necessary, to the JPM4J local index.");
    Label separator = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
    Label lblIndirect = new Label(container, SWT.NONE);
    lblIndirect.setFont(JFaceResources.getBannerFont());
    lblIndirect.setText("Transitive Dependencies:");
    Composite cmpIndirect = new Composite(container, SWT.NONE);
    Table tblIndirect = new Table(cmpIndirect, SWT.CHECK | SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL);
    viewerIndirect = new CheckboxTableViewer(tblIndirect);
    viewerIndirect.setContentProvider(ArrayContentProvider.getInstance());
    viewerIndirect.setLabelProvider(new ResourceDescriptorLabelProvider());
    Button btnSelectAll = new Button(cmpIndirect, SWT.PUSH);
    btnSelectAll.setText("All");
    Button btnSelectNone = new Button(cmpIndirect, SWT.PUSH);
    btnSelectNone.setText("None");
    new Label(cmpIndirect, SWT.NONE);
    createHelpLabel(container, "The above dependencies will be added to the JPM4J local index. Checked dependencies will also be added directly to the project.");
    // LISTENERS
    // Query JPM and show results *after* dialog is shown. This ensures progress is visible in the dialog's
    // progress bar
    getContainer().getShell().addShellListener(new ShellAdapter() {

        @Override
        public void shellActivated(ShellEvent e) {
            runQuery();
        }
    });
    viewerIndirect.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent ev) {
            if (selectedIndirectResources == null)
                selectedIndirectResources = new HashSet<ResourceDescriptor>();
            ResourceDescriptor resource = (ResourceDescriptor) ev.getElement();
            if (ev.getChecked())
                selectedIndirectResources.add(resource);
            else
                selectedIndirectResources.remove(resource);
        }
    });
    btnSelectAll.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedIndirectResources.addAll(indirectResources);
            updateSelectedCheckboxes();
        }
    });
    btnSelectNone.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedIndirectResources.clear();
            updateSelectedCheckboxes();
        }
    });
    viewerDirect.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection sel = event.getSelection();
            if (sel.isEmpty())
                selection = (ResourceDescriptor) ((IStructuredSelection) viewerIndirect.getSelection()).getFirstElement();
            else
                selection = (ResourceDescriptor) ((IStructuredSelection) sel).getFirstElement();
            getContainer().updateMessage();
        }
    });
    viewerIndirect.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection sel = event.getSelection();
            if (sel.isEmpty())
                selection = (ResourceDescriptor) ((IStructuredSelection) viewerDirect.getSelection()).getFirstElement();
            else
                selection = (ResourceDescriptor) ((IStructuredSelection) sel).getFirstElement();
            getContainer().updateMessage();
        }
    });
    // LAYOUT
    GridLayout layout;
    GridData gd;
    layout = new GridLayout(1, true);
    container.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    gd.heightHint = 30;
    tblDirect.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    separator.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    cmpIndirect.setLayoutData(gd);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = 2;
    layout.verticalSpacing = 2;
    cmpIndirect.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3);
    gd.heightHint = 100;
    tblIndirect.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    btnSelectAll.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    btnSelectNone.setLayoutData(gd);
}
Also used : ShellAdapter(org.eclipse.swt.events.ShellAdapter) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) GridData(org.eclipse.swt.layout.GridData) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Aggregations

ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)19 File (java.io.File)10 Version (aQute.bnd.version.Version)7 IOException (java.io.IOException)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Workspace (aQute.bnd.build.Workspace)3 Parameters (aQute.bnd.header.Parameters)3 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)3 DownloadListener (aQute.bnd.service.RepositoryPlugin.DownloadListener)3 InfoRepository (aQute.bnd.service.repository.InfoRepository)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 DownloadBlocker (aQute.bnd.build.DownloadBlocker)2 Attrs (aQute.bnd.header.Attrs)2 Repository (aQute.bnd.jpm.Repository)2 Jar (aQute.bnd.osgi.Jar)2 PutResult (aQute.bnd.service.RepositoryPlugin.PutResult)2 Listener (aQute.bnd.service.repository.ResourceRepository.Listener)2 ResourceRepositoryEvent (aQute.bnd.service.repository.ResourceRepository.ResourceRepositoryEvent)2