Search in sources :

Example 1 with RepositoryBundle

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

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

the class RunBlacklistPart method createRequirement.

private static Requirement createRequirement(Object elem) {
    String bsn = null;
    Version version = null;
    if (elem instanceof RepositoryBundle) {
        bsn = ((RepositoryBundle) elem).getBsn();
    } else if (elem instanceof RepositoryBundleVersion) {
        RepositoryBundleVersion rbv = (RepositoryBundleVersion) elem;
        bsn = rbv.getBsn();
        version = rbv.getVersion();
    } else if (elem instanceof ProjectBundle) {
        bsn = ((ProjectBundle) elem).getBsn();
    }
    if (bsn != null) {
        Filter filter = new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, bsn);
        if (version != null) {
            filter = new AndFilter().addChild(filter).addChild(new SimpleFilter("version", Operator.GreaterThanOrEqual, version.toString()));
        }
        Requirement req = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()).buildSyntheticRequirement();
        return req;
    }
    return null;
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) ProjectBundle(bndtools.model.repo.ProjectBundle) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) AndFilter(aQute.libg.filters.AndFilter) Requirement(org.osgi.resource.Requirement) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) Version(aQute.bnd.version.Version) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) SimpleFilter(aQute.libg.filters.SimpleFilter) AndFilter(aQute.libg.filters.AndFilter) Filter(aQute.libg.filters.Filter) LiteralFilter(aQute.libg.filters.LiteralFilter) SimpleFilter(aQute.libg.filters.SimpleFilter)

Example 3 with RepositoryBundle

use of bndtools.model.repo.RepositoryBundle 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 4 with RepositoryBundle

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

the class RepoDownloadJob method expandContentsInto.

private void expandContentsInto(RemoteRepositoryPlugin repo, List<RepositoryBundleVersion> rbvs) throws Exception {
    List<String> bsns = repo.list(null);
    if (bsns != null) {
        for (String bsn : bsns) {
            RepositoryBundle bundle = new RepositoryBundle(repo, bsn);
            expandContentsInto(bundle, rbvs);
        }
    }
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle)

Example 5 with RepositoryBundle

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

the class RepositoriesView method createActions.

void createActions() {
    collapseAllAction = new Action() {

        @Override
        public void run() {
            viewer.collapseAll();
        }
    };
    collapseAllAction.setEnabled(false);
    collapseAllAction.setText("Collapse All");
    collapseAllAction.setToolTipText("Collapse All");
    collapseAllAction.setImageDescriptor(Icons.desc("collapse"));
    collapseAllAction.setDisabledImageDescriptor(Icons.desc("collapse.disabled"));
    refreshAction = new Action() {

        @Override
        public void run() {
            new WorkspaceJob("Refresh repositories") {

                @Override
                public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                    if (monitor == null)
                        monitor = new NullProgressMonitor();
                    monitor.subTask("Refresh all repositories");
                    try {
                        refreshAction.setEnabled(false);
                        Central.refreshPlugins();
                    } catch (Exception e) {
                        return new Status(Status.ERROR, Plugin.PLUGIN_ID, "Failed to refresh plugins", e);
                    } finally {
                        refreshAction.setEnabled(true);
                    }
                    return Status.OK_STATUS;
                }
            }.schedule();
        }
    };
    refreshAction.setEnabled(false);
    refreshAction.setText("Refresh");
    refreshAction.setToolTipText("Refresh Repositories Tree");
    refreshAction.setImageDescriptor(Icons.desc("refresh"));
    refreshAction.setDisabledImageDescriptor(Icons.desc("refresh.disabled"));
    addBundlesAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object element = selection.getFirstElement();
            if (element != null && element instanceof RepositoryPlugin) {
                RepositoryPlugin repo = (RepositoryPlugin) element;
                if (repo.canWrite()) {
                    AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(repo, new File[0]);
                    WizardDialog dialog = new WizardDialog(getViewSite().getShell(), wizard);
                    dialog.open();
                    viewer.refresh(repo);
                }
            }
        }
    };
    addBundlesAction.setEnabled(false);
    addBundlesAction.setText("Add");
    addBundlesAction.setToolTipText("Add Bundles to Repository");
    addBundlesAction.setImageDescriptor(Icons.desc("add"));
    addBundlesAction.setDisabledImageDescriptor(Icons.desc("add.disabled"));
    advancedSearchAction = new Action("Advanced Search", Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            if (advancedSearchAction.isChecked()) {
                AdvancedSearchDialog dialog = new AdvancedSearchDialog(getSite().getShell());
                if (advancedSearchState != null) {
                    try {
                        XMLMemento memento = XMLMemento.createReadRoot(new StringReader(advancedSearchState));
                        dialog.restoreState(memento);
                    } catch (Exception e) {
                        logger.logError("Failed to load dialog state", e);
                    }
                }
                if (Window.OK == dialog.open()) {
                    Requirement req = dialog.getRequirement();
                    contentProvider.setRequirementFilter(req);
                    SWTUtil.recurseEnable(false, filterPanel);
                    viewer.refresh();
                    viewer.expandToLevel(2);
                } else {
                    advancedSearchAction.setChecked(false);
                }
                try {
                    XMLMemento memento = XMLMemento.createWriteRoot("search");
                    dialog.saveState(memento);
                    StringWriter writer = new StringWriter();
                    memento.save(writer);
                    advancedSearchState = writer.toString();
                } catch (Exception e) {
                    logger.logError("Failed to save dialog state", e);
                }
            } else {
                contentProvider.setRequirementFilter(null);
                SWTUtil.recurseEnable(true, filterPanel);
                viewer.refresh();
            }
        }
    };
    advancedSearchAction.setEnabled(false);
    advancedSearchAction.setText("Advanced Search");
    advancedSearchAction.setToolTipText("Toggle Advanced Search");
    advancedSearchAction.setImageDescriptor(Icons.desc("search"));
    advancedSearchAction.setDisabledImageDescriptor(Icons.desc("search.disabled"));
    downloadAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            // The set of Repos included in the selection; they will be completely downloaded.
            Set<RemoteRepositoryPlugin> repos = new IdentityHashSet<>(selectionByType(selection, RemoteRepositoryPlugin.class));
            // The set of Bundles included in the selection.
            Set<RepositoryBundle> bundles = new IdentityHashSet<RepositoryBundle>();
            for (RepositoryBundle bundle : selectionByType(selection, RepositoryBundle.class)) {
                // filter out bundles that come from already-selected repos.
                if (!repos.contains(bundle.getRepo()))
                    bundles.add(bundle);
            }
            // The set of Bundle Versions included in the selection
            Set<RepositoryBundleVersion> bundleVersions = new IdentityHashSet<RepositoryBundleVersion>();
            for (RepositoryBundleVersion bundleVersion : selectionByType(selection, RepositoryBundleVersion.class)) {
                // filter out bundles that come from already-selected repos.
                if (!repos.contains(bundleVersion.getRepo()))
                    bundleVersions.add(bundleVersion);
            }
            RepoDownloadJob downloadJob = new RepoDownloadJob(repos, bundles, bundleVersions);
            downloadJob.schedule();
        }

        private <T> List<T> selectionByType(IStructuredSelection selection, Class<T> type) {
            List<T> result = new ArrayList<T>(selection.size());
            @SuppressWarnings("unchecked") Iterator<Object> iterator = selection.iterator();
            while (iterator.hasNext()) {
                Object item = iterator.next();
                if (type.isInstance(item)) {
                    @SuppressWarnings("unchecked") T cast = (T) item;
                    result.add(cast);
                }
            }
            return result;
        }
    };
    downloadAction.setEnabled(false);
    downloadAction.setText("Download Repository Content");
    downloadAction.setImageDescriptor(Icons.desc("download"));
    downloadAction.setDisabledImageDescriptor(Icons.desc("download.disabled"));
    offlineAction = new Action("Online/Offline Mode", Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            Workspace workspace = Central.getWorkspaceIfPresent();
            if (workspace != null) {
                prefs.setWorkspaceOffline(offlineAction.isChecked());
            }
        }
    };
    offlineAction.setEnabled(false);
    offlineAction.setToolTipText("Go Offline");
    offlineAction.setImageDescriptor(Icons.desc("connected"));
    offlineAction.setDisabledImageDescriptor(Icons.desc("connected.disabled"));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            boolean enable = false;
            @SuppressWarnings("unchecked") List<Object> list = selection.toList();
            for (Object item : list) {
                if (item instanceof RemoteRepositoryPlugin) {
                    enable = true;
                    break;
                } else if (item instanceof RepositoryEntry) {
                    if (!((RepositoryEntry) item).isLocal()) {
                        enable = true;
                        break;
                    }
                }
            }
            downloadAction.setEnabled(enable);
        }
    });
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Action(org.eclipse.jface.action.Action) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) Set(java.util.Set) IdentityHashSet(org.bndtools.utils.collections.IdentityHashSet) AddFilesToRepositoryWizard(bndtools.wizards.workspace.AddFilesToRepositoryWizard) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryEntry(bndtools.model.repo.RepositoryEntry) StringWriter(java.io.StringWriter) SWT(org.eclipse.swt.SWT) StringReader(java.io.StringReader) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) Requirement(org.osgi.resource.Requirement) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) XMLMemento(org.eclipse.ui.XMLMemento) IFile(org.eclipse.core.resources.IFile) File(java.io.File) JarFile(java.util.jar.JarFile) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Workspace(aQute.bnd.build.Workspace)

Aggregations

RepositoryBundle (bndtools.model.repo.RepositoryBundle)9 RepositoryBundleVersion (bndtools.model.repo.RepositoryBundleVersion)8 ProjectBundle (bndtools.model.repo.ProjectBundle)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)4 RemoteRepositoryPlugin (aQute.bnd.service.RemoteRepositoryPlugin)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 WizardDialog (org.eclipse.jface.wizard.WizardDialog)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 Requirement (org.osgi.resource.Requirement)3 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)2 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)2 RepositoryEntry (bndtools.model.repo.RepositoryEntry)2 RepositoryTreeLabelProvider (bndtools.model.repo.RepositoryTreeLabelProvider)2