use of bndtools.model.repo.ProjectBundle 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;
}
use of bndtools.model.repo.ProjectBundle 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);
}
use of bndtools.model.repo.ProjectBundle in project bndtools by bndtools.
the class AbstractRequirementListPart method createRequirement.
private Requirement createRequirement(Object elem) throws Exception {
final String bsn;
String versionRange = null;
if (elem instanceof RepositoryBundle) {
bsn = ((RepositoryBundle) elem).getBsn();
} else if (elem instanceof RepositoryBundleVersion) {
RepositoryBundleVersion rbv = (RepositoryBundleVersion) elem;
bsn = rbv.getBsn();
versionRange = rbv.getVersion().toString();
} else if (elem instanceof ProjectBundle) {
bsn = ((ProjectBundle) elem).getBsn();
} else if (elem instanceof VersionedClause) {
VersionedClause clause = (VersionedClause) elem;
bsn = clause.getName();
versionRange = clause.getVersionRange();
} else {
throw new IllegalArgumentException("Unable to derive identity from an object of type " + elem.getClass().getSimpleName());
}
final CapReqBuilder reqBuilder;
if (preferences.getUseAliasRequirements()) {
reqBuilder = new CapReqBuilder("bnd.identity").addAttribute("id", bsn);
if (versionRange != null)
reqBuilder.addAttribute("version", versionRange);
} else {
Filter filter = new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, bsn);
if (versionRange != null)
filter = new AndFilter().addChild(filter).addChild(new SimpleFilter("version", Operator.GreaterThanOrEqual, versionRange));
reqBuilder = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString());
}
return reqBuilder.buildSyntheticRequirement();
}
use of bndtools.model.repo.ProjectBundle 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;
}
use of bndtools.model.repo.ProjectBundle in project bndtools by bndtools.
the class RunRequirementsPart 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;
}
Aggregations