Java Code Examples for org.eclipse.jface.viewers.TableViewer#addDropSupport()

The following examples show how to use org.eclipse.jface.viewers.TableViewer#addDropSupport() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexEditionControl.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private void createAvailableAttributesTableViewer(Composite parent) {
    Section section = formPage.getToolkit().createSection(parent, Section.EXPANDED);
    section.setLayout(GridLayoutFactory.fillDefaults().create());
    section.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    section.setText(Messages.availableAttributes);

    Composite client = formPage.getToolkit().createComposite(section);
    client.setLayout(GridLayoutFactory.fillDefaults().create());
    client.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    availableAttributesTableViewer = new TableViewer(client,
            SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    availableAttributesTableViewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    availableAttributesTableViewer.getTable().setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, AVAILABLE_FIELDS_VIEWER_ID);
    formPage.getToolkit().adapt(availableAttributesTableViewer.getTable());
    ColumnViewerToolTipSupport.enableFor(availableAttributesTableViewer);
    availableAttributesTableViewer.setUseHashlookup(true);
    availableAttributesTableViewer.getTable().setLinesVisible(true);
    availableAttributesTableViewer.setFilters(indexableFieldFilter, indexedFieldsFilter());

    TableLayout layout = new TableLayout();
    layout.addColumnData(new ColumnWeightData(1, true));
    availableAttributesTableViewer.getTable().setLayout(layout);

    createAttributesColumn(availableAttributesTableViewer);

    availableAttributesTableViewer.setContentProvider(new ObservableListContentProvider());
    availableAttributesTableViewer.setInput(actualsFieldsObservable);
    selectedAvailableAttributeObservable = ViewersObservables.observeMultiSelection(availableAttributesTableViewer);

    availableAttributesTableViewer.getTable().addMouseMoveListener(e -> updateCursor(e, availableAttributesTableViewer));
    availableAttributesTableViewer.addDragSupport(DND.DROP_MOVE, new Transfer[] { FieldTransfer.getInstance() },
            dragSourceAdapter(selectedAvailableAttributeObservable));
    availableAttributesTableViewer.addDropSupport(DND.DROP_MOVE,
            new Transfer[] { FieldTransfer.getInstance() },
            new DropTargetAdapter() {

                @Override
                public void drop(DropTargetEvent event) {
                    dragLeave(event);
                    indexedFieldsObservable.removeAll((Collection<?>) event.data);
                }
            });

    section.setClient(client);
}
 
Example 2
Source File: ContactSelectorView.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void createPartControl(Composite parent){
	Composite composite = new Composite(parent, SWT.NONE);
	composite.setLayout(new GridLayout(1, false));
	
	Composite compositeSearch = new Composite(composite, SWT.NONE);
	compositeSearch.setLayout(new GridLayout(1, false));
	compositeSearch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
	
	txtFilter = new Text(compositeSearch, SWT.BORDER | SWT.SEARCH | SWT.CANCEL);
	txtFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
	
	tableViewerContacts = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);
	Table table = tableViewerContacts.getTable();
	table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	
	Composite compositeStatus = new Composite(composite, SWT.NONE);
	compositeStatus.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
	compositeStatus.setLayout(new GridLayout(1, false));
	
	lblStatus = new Label(compositeStatus, SWT.NONE);
	lblStatus.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
	
	tableViewerContacts.setComparator(new ContactSelectorViewerComparator(tableViewerContacts));
	filterAnzeigeTyp = new KontaktAnzeigeTypViewerFilter(tableViewerContacts);
	ViewerFilter[] filters = new ViewerFilter[] {
		filterAnzeigeTyp, filterPositionTitle
	};
	tableViewerContacts.setFilters(filters);
	
	int operations = DND.DROP_COPY | DND.DROP_MOVE;
	Transfer[] transferTypes = new Transfer[] {
		TextTransfer.getInstance()
	};
	tableViewerContacts.addDragSupport(operations, transferTypes,
		new ContactSelectorDragListener(tableViewerContacts));
	tableViewerContacts.addDropSupport(operations, transferTypes,
		new ContactSelectorDropListener(tableViewerContacts));
	
	txtFilter.addKeyListener(new FilterKeyListener(txtFilter, tableViewerContacts));
	txtFilter.addSelectionListener(new SelectionAdapter() {
		public void widgetDefaultSelected(SelectionEvent e){
			if (e.detail == SWT.CANCEL) {
				filterPositionTitle.setSearchText(null);
				tableViewerContacts.getControl().setRedraw(false);
				tableViewerContacts.refresh();
				tableViewerContacts.getControl().setRedraw(true);
			}
		}
	});
	
	initDataBindings();
	
	MenuManager menuManager = new MenuManager();
	menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
	tableViewerContacts.getTable().setMenu(
		menuManager.createContextMenu(tableViewerContacts.getTable()));
	
	getSite().registerContextMenu(menuManager, tableViewerContacts);
	getSite().setSelectionProvider(tableViewerContacts);
	
	contactList.getRealm().asyncExec(loadContactsRunnable);
	
	tableViewerContacts
		.addSelectionChangedListener(new ContactSelectionChangedToEventDispatcher());
	tableViewerContacts.addSelectionChangedListener(new ISelectionChangedListener() {
		
		@Override
		public void selectionChanged(SelectionChangedEvent event){
			StructuredSelection ss = (StructuredSelection) event.getSelection();
			tableViewerContacts.refresh(ss.getFirstElement());
		}
	});
}