Search in sources :

Example 1 with CapabilityLabelProvider

use of bndtools.model.resolution.CapabilityLabelProvider 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);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) CapReqMapContentProvider(bndtools.model.resolution.CapReqMapContentProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IType(org.eclipse.jdt.core.IType) GridLayout(org.eclipse.swt.layout.GridLayout) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Iterator(java.util.Iterator) ISelection(org.eclipse.jface.viewers.ISelection) Tree(org.eclipse.swt.widgets.Tree) Clazz(aQute.bnd.osgi.Clazz) BndFileCapReqLoader(bndtools.tasks.BndFileCapReqLoader) BndBuilderCapReqLoader(bndtools.tasks.BndBuilderCapReqLoader) JarFileCapReqLoader(bndtools.tasks.JarFileCapReqLoader) ResourceCapReqLoader(bndtools.tasks.ResourceCapReqLoader) CapReqLoader(bndtools.tasks.CapReqLoader) PartInitException(org.eclipse.ui.PartInitException) RequirementWrapper(bndtools.model.resolution.RequirementWrapper) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) CapabilityLabelProvider(bndtools.model.resolution.CapabilityLabelProvider) FillLayout(org.eclipse.swt.layout.FillLayout) BndBuilderCapReqLoader(bndtools.tasks.BndBuilderCapReqLoader) SashForm(org.eclipse.swt.custom.SashForm) RequirementWrapperLabelProvider(bndtools.model.resolution.RequirementWrapperLabelProvider) IOpenListener(org.eclipse.jface.viewers.IOpenListener) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) IFile(org.eclipse.core.resources.IFile) File(java.io.File) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Example 2 with CapabilityLabelProvider

use of bndtools.model.resolution.CapabilityLabelProvider in project bndtools by bndtools.

the class ResolutionChoiceSelectionDialog method createDialogArea.

@SuppressWarnings("unused")
@Override
protected Control createDialogArea(Composite parent) {
    setTitle("Multiple Provider Candidates");
    setMessage("Use the candidate list to specify your preferences. Candidates at the top of the list will be preferred by the resolver.");
    // Create controls
    Composite outer = (Composite) super.createDialogArea(parent);
    Composite contents = new Composite(outer, SWT.NONE);
    Label lblRequirement = new Label(contents, SWT.NONE);
    lblRequirement.setText("Requirement Info");
    lblRequirement.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
    StyledText txtRequirement = new StyledText(contents, SWT.WRAP | SWT.BORDER);
    txtRequirement.setEditable(false);
    txtRequirement.setCaret(null);
    // txtRequirement.setBackground(contents.getBackground());
    txtRequirement.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
    new Label(contents, SWT.NONE);
    Label lblCandidates = new Label(contents, SWT.NONE);
    lblCandidates.setText("Candidates");
    lblCandidates.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
    Composite lowerPanel = new Composite(contents, SWT.NONE);
    Table tbl = new Table(lowerPanel, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    viewer = new CheckboxTableViewer(tbl);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setLabelProvider(new CapabilityLabelProvider());
    btnUp = new Button(lowerPanel, SWT.PUSH);
    btnUp.setText("Move Up");
    btnUp.setEnabled(false);
    btnDown = new Button(lowerPanel, SWT.PUSH);
    btnDown.setText("Move Down");
    btnDown.setEnabled(false);
    Composite cmpPreferences = new Composite(contents, SWT.NONE);
    btnSavePreference = new Button(cmpPreferences, SWT.CHECK | SWT.WRAP);
    txtSavePreference = new StyledText(cmpPreferences, SWT.WRAP);
    txtSavePreference.setEditable(false);
    txtSavePreference.setCaret(null);
    txtSavePreference.setBackground(contents.getBackground());
    txtSavePreference.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
    // Events
    txtSavePreference.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            btnSavePreference.setSelection(!btnSavePreference.getSelection());
        }
    });
    // Load data
    StyledString label = createRequirementText();
    txtRequirement.setText(label.getString());
    txtRequirement.setStyleRanges(label.getStyleRanges());
    viewer.setInput(candidates);
    updateSavePreferenceText();
    // Layout
    GridLayout layout;
    GridData gd;
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    contents.setLayoutData(gd);
    layout = new GridLayout(1, false);
    contents.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.NONE, true, false);
    gd.horizontalIndent = 5;
    txtRequirement.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.NONE, true, false);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    lowerPanel.setLayoutData(gd);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    lowerPanel.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3);
    gd.widthHint = 450;
    gd.heightHint = 250;
    tbl.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.NONE, false, false);
    btnUp.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.NONE, false, false);
    btnDown.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.NONE, true, false);
    cmpPreferences.setLayoutData(gd);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    cmpPreferences.setLayout(layout);
    gd = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    btnSavePreference.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    txtSavePreference.setLayoutData(gd);
    return contents;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) CapabilityLabelProvider(bndtools.model.resolution.CapabilityLabelProvider) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) StyledString(org.eclipse.jface.viewers.StyledString) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData)

Aggregations

CapabilityLabelProvider (bndtools.model.resolution.CapabilityLabelProvider)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 Table (org.eclipse.swt.widgets.Table)2 Clazz (aQute.bnd.osgi.Clazz)1 CapReqMapContentProvider (bndtools.model.resolution.CapReqMapContentProvider)1 RequirementWrapper (bndtools.model.resolution.RequirementWrapper)1 RequirementWrapperLabelProvider (bndtools.model.resolution.RequirementWrapperLabelProvider)1 BndBuilderCapReqLoader (bndtools.tasks.BndBuilderCapReqLoader)1 BndFileCapReqLoader (bndtools.tasks.BndFileCapReqLoader)1 CapReqLoader (bndtools.tasks.CapReqLoader)1 JarFileCapReqLoader (bndtools.tasks.JarFileCapReqLoader)1 ResourceCapReqLoader (bndtools.tasks.ResourceCapReqLoader)1 File (java.io.File)1 Iterator (java.util.Iterator)1 IFile (org.eclipse.core.resources.IFile)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 IStatus (org.eclipse.core.runtime.IStatus)1