use of bndtools.tasks.CapReqLoader in project bndtools by bndtools.
the class ResolutionView method setLoaders.
private boolean setLoaders(Set<CapReqLoader> newLoaders) {
Set<CapReqLoader> oldLoaders = loaders;
boolean swap = !oldLoaders.equals(newLoaders);
if (swap) {
loaders = newLoaders;
}
for (CapReqLoader l : swap ? oldLoaders : newLoaders) {
IO.close(l);
}
return swap;
}
use of bndtools.tasks.CapReqLoader in project bndtools by bndtools.
the class ResolutionView method setInput.
public void setInput(Set<CapReqLoader> sourceLoaders, Map<String, List<Capability>> capabilities, Map<String, List<RequirementWrapper>> requirements) {
setLoaders(sourceLoaders);
sourceLoaders = loaders;
if (reqsTree != null && !reqsTree.isDisposed() && capsTable != null && !capsTable.isDisposed()) {
reqsViewer.setInput(requirements);
capsViewer.setInput(capabilities);
String label;
if (!sourceLoaders.isEmpty()) {
StringBuilder builder = new StringBuilder();
String delim = "";
boolean shortLabel = sourceLoaders.size() > 1;
for (CapReqLoader l : sourceLoaders) {
builder.append(delim);
builder.append(shortLabel ? l.getShortLabel() : l.getLongLabel());
delim = ", ";
}
label = builder.toString();
} else {
label = "<no input>";
}
setContentDescription(label);
}
}
use of bndtools.tasks.CapReqLoader in project bndtools by bndtools.
the class ResolutionView method createPartControl.
@Override
public void createPartControl(Composite parent) {
this.display = parent.getDisplay();
SashForm splitPanel = new SashForm(parent, SWT.HORIZONTAL);
splitPanel.setLayout(new FillLayout());
Composite reqsPanel = new Composite(splitPanel, SWT.NONE);
reqsPanel.setBackground(parent.getBackground());
GridLayout reqsLayout = new GridLayout(1, false);
reqsLayout.marginWidth = 0;
reqsLayout.marginHeight = 0;
reqsLayout.verticalSpacing = 2;
reqsPanel.setLayout(reqsLayout);
new Label(reqsPanel, SWT.NONE).setText("Requirements:");
reqsTree = new Tree(reqsPanel, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
reqsTree.setHeaderVisible(false);
reqsTree.setLinesVisible(false);
reqsTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
reqsViewer = new TreeViewer(reqsTree);
ColumnViewerToolTipSupport.enableFor(reqsViewer);
reqsViewer.setLabelProvider(new RequirementWrapperLabelProvider(true));
reqsViewer.setContentProvider(new CapReqMapContentProvider());
Composite capsPanel = new Composite(splitPanel, SWT.NONE);
capsPanel.setBackground(parent.getBackground());
GridLayout capsLayout = new GridLayout(1, false);
capsLayout.marginWidth = 0;
capsLayout.marginHeight = 0;
capsLayout.verticalSpacing = 2;
capsPanel.setLayout(capsLayout);
new Label(capsPanel, SWT.NONE).setText("Capabilities:");
capsTable = new Table(capsPanel, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
capsTable.setHeaderVisible(false);
capsTable.setLinesVisible(false);
capsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
capsViewer = new TableViewer(capsTable);
ColumnViewerToolTipSupport.enableFor(capsViewer);
capsViewer.setLabelProvider(new CapabilityLabelProvider(true));
capsViewer.setContentProvider(new CapReqMapContentProvider());
capsViewer.setFilters(new ViewerFilter[] { new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
return !filteredCapabilityNamespaces.contains(((Capability) element).getNamespace());
}
} });
hideSelfImportsFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof RequirementWrapper) {
RequirementWrapper rw = (RequirementWrapper) element;
return !rw.resolved;
}
return true;
}
};
reqsViewer.setFilters(new ViewerFilter[] { hideSelfImportsFilter });
reqsViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new LocalTransferDragListener(reqsViewer));
capsViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new LocalTransferDragListener(capsViewer));
reqsViewer.addOpenListener(new IOpenListener() {
@Override
public void open(OpenEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
Object item = iter.next();
if (item instanceof Clazz) {
Clazz clazz = (Clazz) item;
String className = clazz.getFQN();
IType type = null;
if (!loaders.isEmpty()) {
IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
for (CapReqLoader loader : loaders) {
if (loader instanceof BndBuilderCapReqLoader) {
File loaderFile = ((BndBuilderCapReqLoader) loader).getFile();
IFile[] wsfiles = wsroot.findFilesForLocationURI(loaderFile.toURI());
for (IFile wsfile : wsfiles) {
IJavaProject javaProject = JavaCore.create(wsfile.getProject());
try {
type = javaProject.findType(className);
if (type != null)
break;
} catch (JavaModelException e) {
ErrorDialog.openError(getSite().getShell(), "Error", "", new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening Java class '{0}'.", className), e));
}
}
}
}
}
try {
if (type != null)
JavaUI.openInEditor(type, true, true);
} catch (PartInitException e) {
ErrorDialog.openError(getSite().getShell(), "Error", "", new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening Java editor for class '{0}'.", className), e));
} catch (JavaModelException e) {
ErrorDialog.openError(getSite().getShell(), "Error", "", new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening Java class '{0}'.", className), e));
}
}
}
}
});
fillActionBars();
getSite().getPage().addPostSelectionListener(this);
getSite().getPage().addPartListener(partAdapter);
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
// Current selection & part
IWorkbenchPart activePart = getSite().getPage().getActivePart();
ISelection activeSelection = getSite().getWorkbenchWindow().getSelectionService().getSelection();
selectionChanged(activePart, activeSelection);
}
use of bndtools.tasks.CapReqLoader in project bndtools by bndtools.
the class ResolutionView method resourceChanged.
@Override
public void resourceChanged(IResourceChangeEvent event) {
if (!loaders.isEmpty()) {
IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
for (CapReqLoader loader : loaders) {
if (loader instanceof BndBuilderCapReqLoader) {
File file = ((BndBuilderCapReqLoader) loader).getFile();
IFile[] wsfiles = wsroot.findFilesForLocationURI(file.toURI());
for (IFile wsfile : wsfiles) {
if (event.getDelta().findMember(wsfile.getFullPath()) != null) {
executeAnalysis();
break;
}
}
}
}
}
}
use of bndtools.tasks.CapReqLoader in project bndtools by bndtools.
the class ResolutionView method getLoadersFromSelection.
private Set<CapReqLoader> getLoadersFromSelection(IStructuredSelection structSel) {
Set<CapReqLoader> result = new LinkedHashSet<CapReqLoader>();
Iterator<?> iter = structSel.iterator();
while (iter.hasNext()) {
Object element = iter.next();
CapReqLoader loader = null;
File file = SelectionUtils.adaptObject(element, File.class);
if (file != null) {
loader = getLoaderForFile(file);
} else {
IResource eresource = SelectionUtils.adaptObject(element, IResource.class);
if (eresource != null) {
IPath location = eresource.getLocation();
if (location != null) {
loader = getLoaderForFile(location.toFile());
}
} else if (element instanceof RepositoryResourceElement) {
Resource resource = ((RepositoryResourceElement) element).getResource();
loader = new ResourceCapReqLoader(resource);
}
}
if (loader != null)
result.add(loader);
}
return result;
}
Aggregations