Search in sources :

Example 6 with DragSourceEvent

use of org.eclipse.swt.dnd.DragSourceEvent in project bndtools by bndtools.

the class AvailableBundlesPart method createClient.

private void createClient(Section section, FormToolkit toolkit) {
    section.setText("Browse Repos");
    // Create contents
    Composite container = toolkit.createComposite(section);
    section.setClient(container);
    GridLayout layout = new GridLayout(1, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    container.setLayout(layout);
    txtSearch = toolkit.createText(container, "", SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL | SWT.BORDER);
    txtSearch.setMessage("Enter search string");
    txtSearch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Tree tree = toolkit.createTree(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL);
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    viewer = new TreeViewer(tree);
    contentProvider.setShowRepos(false);
    viewer.setContentProvider(contentProvider);
    viewer.setLabelProvider(new RepositoryTreeLabelProvider(true));
    viewer.setFilters(new ViewerFilter[] { includedRepoFilter });
    txtSearch.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (scheduledFilterUpdate != null)
                scheduledFilterUpdate.cancel(true);
            searchStr = txtSearch.getText();
            scheduledFilterUpdate = Plugin.getDefault().getScheduler().schedule(updateFilterTask, SEARCH_DELAY, TimeUnit.MILLISECONDS);
        }
    });
    txtSearch.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            if (scheduledFilterUpdate != null)
                scheduledFilterUpdate.cancel(true);
            scheduledFilterUpdate = null;
            searchStr = txtSearch.getText();
            updateFilterTask.run();
        }
    });
    viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new SelectionDragAdapter(viewer) {

        @Override
        public void dragStart(DragSourceEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            if (!selection.isEmpty()) {
                LocalSelectionTransfer.getTransfer().setSelection(selection);
                LocalSelectionTransfer.getTransfer().setSelectionSetTime(event.time & 0xFFFFFFFFL);
            } else {
                event.doit = false;
            }
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) GridLayout(org.eclipse.swt.layout.GridLayout) RepositoryTreeLabelProvider(bndtools.model.repo.RepositoryTreeLabelProvider) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) SelectionDragAdapter(bndtools.utils.SelectionDragAdapter)

Example 7 with DragSourceEvent

use of org.eclipse.swt.dnd.DragSourceEvent in project bndtools by bndtools.

the class BundleCalculatedImportsPart method createSection.

private void createSection(Section section, FormToolkit toolkit) {
    // CREATE COMPONENTS
    section.setText(Messages.BundleCalculatedImportsPart_title);
    ToolBar toolbar = new ToolBar(section, SWT.FLAT);
    section.setTextClient(toolbar);
    final ToolItem showSelfImportsItem = new ToolItem(toolbar, SWT.CHECK);
    showSelfImportsItem.setImage(imgShowSelfImports);
    showSelfImportsItem.setToolTipText(Messages.BundleCalculatedImportsPart_tooltipShowSelfImports);
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    // toolkit.createLabel(composite,
    // Messages.BundleCalculatedImportsPart_description, SWT.WRAP);
    tree = toolkit.createTree(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
    viewer = new TreeViewer(tree);
    viewer.setContentProvider(new CapReqMapContentProvider());
    viewer.setLabelProvider(new RequirementWrapperLabelProvider(true));
    ColumnViewerToolTipSupport.enableFor(viewer);
    nonPkgFilter = new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parent, Object element) {
            if (element instanceof RequirementWrapper)
                return PackageNamespace.PACKAGE_NAMESPACE.equals(((RequirementWrapper) element).requirement.getNamespace());
            return true;
        }
    };
    hideSelfImportsFilter = new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof RequirementWrapper)
                return !((RequirementWrapper) element).resolved;
            return true;
        }
    };
    viewer.setFilters(new ViewerFilter[] { nonPkgFilter, hideSelfImportsFilter });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            getManagedForm().fireSelectionChanged(BundleCalculatedImportsPart.this, event.getSelection());
        }
    });
    viewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new DragSourceAdapter() {

        @Override
        public void dragSetData(DragSourceEvent event) {
            LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
            if (transfer.isSupportedType(event.dataType))
                transfer.setSelection(viewer.getSelection());
        }
    });
    viewer.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 importUsedBy = (Clazz) item;
                    String className = importUsedBy.getFQN();
                    IType type = null;
                    IFile file = getEditorFile();
                    if (file != null) {
                        IJavaProject javaProject = JavaCore.create(file.getProject());
                        try {
                            type = javaProject.findType(className);
                        } catch (JavaModelException e) {
                            ErrorDialog.openError(tree.getShell(), Messages.BundleCalculatedImportsPart_error, Messages.BundleCalculatedImportsPart_errorFindingType, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format(Messages.BundleCalculatedImportsPart_errorOpeningClass, className), e));
                        }
                    }
                    try {
                        if (type != null)
                            JavaUI.openInEditor(type, true, true);
                    } catch (PartInitException e) {
                        ErrorDialog.openError(tree.getShell(), Messages.BundleCalculatedImportsPart_error, null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format(Messages.BundleCalculatedImportsPart_errorOpeningJavaEditor, className), e));
                    } catch (JavaModelException e) {
                        ErrorDialog.openError(tree.getShell(), Messages.BundleCalculatedImportsPart_error, null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format(Messages.BundleCalculatedImportsPart_errorOpeningClass, className), e));
                    }
                }
            }
        }
    });
    // LISTENERS
    showSelfImportsItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean showSelfImports = showSelfImportsItem.getSelection();
            ViewerFilter[] filters = showSelfImports ? new ViewerFilter[] { nonPkgFilter } : new ViewerFilter[] { nonPkgFilter, hideSelfImportsFilter };
            viewer.setFilters(filters);
        }
    });
    // LAYOUT
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 2;
    composite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.heightHint = 75;
    gd.widthHint = 75;
    tree.setLayoutData(gd);
}
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) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IType(org.eclipse.jdt.core.IType) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Iterator(java.util.Iterator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Clazz(aQute.bnd.osgi.Clazz) PartInitException(org.eclipse.ui.PartInitException) RequirementWrapper(bndtools.model.resolution.RequirementWrapper) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) ToolItem(org.eclipse.swt.widgets.ToolItem) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) RequirementWrapperLabelProvider(bndtools.model.resolution.RequirementWrapperLabelProvider) IOpenListener(org.eclipse.jface.viewers.IOpenListener) IJavaProject(org.eclipse.jdt.core.IJavaProject) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Aggregations

DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)7 DragSource (org.eclipse.swt.dnd.DragSource)4 DragSourceListener (org.eclipse.swt.dnd.DragSourceListener)3 TextTransfer (org.eclipse.swt.dnd.TextTransfer)3 Transfer (org.eclipse.swt.dnd.Transfer)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 DragSourceAdapter (org.eclipse.swt.dnd.DragSourceAdapter)2 DropTarget (org.eclipse.swt.dnd.DropTarget)2 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Clazz (aQute.bnd.osgi.Clazz)1 RepositoryTreeLabelProvider (bndtools.model.repo.RepositoryTreeLabelProvider)1 CapReqMapContentProvider (bndtools.model.resolution.CapReqMapContentProvider)1 RequirementWrapper (bndtools.model.resolution.RequirementWrapper)1 RequirementWrapperLabelProvider (bndtools.model.resolution.RequirementWrapperLabelProvider)1