Java Code Examples for org.eclipse.swt.dnd.DND#DROP_MOVE

The following examples show how to use org.eclipse.swt.dnd.DND#DROP_MOVE . 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: ItemEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void createContextMenuFor ( StructuredViewer viewer )
{
    MenuManager contextMenu = new MenuManager ( "#PopUp" ); //$NON-NLS-1$
    contextMenu.add ( new Separator ( "additions" ) ); //$NON-NLS-1$
    contextMenu.setRemoveAllWhenShown ( true );
    contextMenu.addMenuListener ( this );
    Menu menu = contextMenu.createContextMenu ( viewer.getControl () );
    viewer.getControl ().setMenu ( menu );
    getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) );

    int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
    Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance (), LocalSelectionTransfer.getTransfer (), FileTransfer.getInstance () };
    viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) );
    viewer.addDropSupport ( dndOperations, transfers, new EditingDomainViewerDropAdapter ( editingDomain, viewer ) );
}
 
Example 2
Source File: PydevPackageExplorer.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void initDragAndDrop() {
    int operations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;

    CommonDragAdapter dragAdapter = createDragAdapter();
    addDragSupport(operations, dragAdapter.getSupportedDragTransfers(),
            dragAdapter);

    CommonDropAdapter dropAdapter = createDropAdapter();
    addDropSupport(operations, dropAdapter.getSupportedDropTransfers(),
            dropAdapter);

    // Set the drop adaptor of the PyDev content service instead of the standard one,
    // which shouldn't be used for drop policies.
    NavigatorDnDService dnd = (NavigatorDnDService) pyContentService.getDnDService();
    dnd.setDropAdaptor(dropAdapter);
}
 
Example 3
Source File: ProtocolEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void createContextMenuFor ( StructuredViewer viewer )
{
    MenuManager contextMenu = new MenuManager ( "#PopUp" ); //$NON-NLS-1$
    contextMenu.add ( new Separator ( "additions" ) ); //$NON-NLS-1$
    contextMenu.setRemoveAllWhenShown ( true );
    contextMenu.addMenuListener ( this );
    Menu menu = contextMenu.createContextMenu ( viewer.getControl () );
    viewer.getControl ().setMenu ( menu );
    getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) );

    int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
    Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance (), LocalSelectionTransfer.getTransfer (), FileTransfer.getInstance () };
    viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) );
    viewer.addDropSupport ( dndOperations, transfers, new EditingDomainViewerDropAdapter ( editingDomain, viewer ) );
}
 
Example 4
Source File: ChartEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This creates a context menu for the viewer and adds a listener as well
 * registering the menu for extension.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * 
 * @generated NOT
 */
protected void createContextMenuFor ( final StructuredViewer viewer )
{
    final MenuManager contextMenu = new MenuManager ( "#PopUp" ); //$NON-NLS-1$
    contextMenu.add ( new Separator ( "additions" ) ); //$NON-NLS-1$
    contextMenu.setRemoveAllWhenShown ( true );
    contextMenu.addMenuListener ( this );
    final Menu menu = contextMenu.createContextMenu ( viewer.getControl () );
    viewer.getControl ().setMenu ( menu );
    getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) );

    final int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
    final Transfer[] transfers = new Transfer[] {
            LocalTransfer.getInstance (),
            LocalSelectionTransfer.getTransfer (),
            FileTransfer.getInstance (),
            ItemTransfer.getInstance ()
    };
    viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) );
    viewer.addDropSupport ( dndOperations, transfers, new DropAdapterExtension ( this.editingDomain, viewer ) );
}
 
Example 5
Source File: ChartConfiguratorView.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This creates a context menu for the viewer and adds a listener as well
 * registering the menu for extension. <!-- begin-user-doc --> <!--
 * end-user-doc -->
 */
protected void createContextMenuFor ( final StructuredViewer viewer )
{
    final MenuManager contextMenu = new MenuManager ( "#PopUp" );
    contextMenu.add ( new Separator ( "additions" ) );
    contextMenu.setRemoveAllWhenShown ( true );
    contextMenu.addMenuListener ( this );
    final Menu menu = contextMenu.createContextMenu ( viewer.getControl () );
    viewer.getControl ().setMenu ( menu );
    getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) );

    final int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
    final Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance () };
    viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) );
    viewer.addDropSupport ( dndOperations, transfers, new EditingDomainViewerDropAdapter ( this.editingDomain, viewer ) );
}
 
Example 6
Source File: ScriptConsoleViewer.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void dragFinished(DragSourceEvent event) {
    try {
        if (event.detail == DND.DROP_MOVE && selectionIsEditable) {
            Point newSelection = getSelection();
            int length = selection.y - selection.x;
            int delta = 0;
            if (newSelection.x < selection.x) {
                delta = length;
            }
            replaceTextRange(selection.x + delta, length, "");
        }
    } finally {
        thisConsoleInitiatedDrag = false;
    }
}
 
Example 7
Source File: SecurityEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void createContextMenuFor ( StructuredViewer viewer )
{
    MenuManager contextMenu = new MenuManager ( "#PopUp" ); //$NON-NLS-1$
    contextMenu.add ( new Separator ( "additions" ) ); //$NON-NLS-1$
    contextMenu.setRemoveAllWhenShown ( true );
    contextMenu.addMenuListener ( this );
    Menu menu = contextMenu.createContextMenu ( viewer.getControl () );
    viewer.getControl ().setMenu ( menu );
    getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) );

    int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
    Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance (), LocalSelectionTransfer.getTransfer (), FileTransfer.getInstance () };
    viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) );
    viewer.addDropSupport ( dndOperations, transfers, new EditingDomainViewerDropAdapter ( editingDomain, viewer ) );
}
 
Example 8
Source File: ConfigurationEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void createContextMenuFor ( StructuredViewer viewer )
{
    MenuManager contextMenu = new MenuManager ( "#PopUp" ); //$NON-NLS-1$
    contextMenu.add ( new Separator ( "additions" ) ); //$NON-NLS-1$
    contextMenu.setRemoveAllWhenShown ( true );
    contextMenu.addMenuListener ( this );
    Menu menu = contextMenu.createContextMenu ( viewer.getControl () );
    viewer.getControl ().setMenu ( menu );
    getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) );

    int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
    Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance (), LocalSelectionTransfer.getTransfer (), FileTransfer.getInstance () };
    viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) );
    viewer.addDropSupport ( dndOperations, transfers, new EditingDomainViewerDropAdapter ( editingDomain, viewer ) );
}
 
Example 9
Source File: MemoryEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void createContextMenuFor ( StructuredViewer viewer )
{
    MenuManager contextMenu = new MenuManager ( "#PopUp" );
    contextMenu.add ( new Separator ( "additions" ) );
    contextMenu.setRemoveAllWhenShown ( true );
    contextMenu.addMenuListener ( this );
    Menu menu = contextMenu.createContextMenu ( viewer.getControl () );
    viewer.getControl ().setMenu ( menu );
    getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) );

    int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
    Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance (), LocalSelectionTransfer.getTransfer (), FileTransfer.getInstance () };
    viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) );
    viewer.addDropSupport ( dndOperations, transfers, new EditingDomainViewerDropAdapter ( editingDomain, viewer ) );
}
 
Example 10
Source File: WorldEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void createContextMenuFor ( StructuredViewer viewer )
{
    MenuManager contextMenu = new MenuManager ( "#PopUp" ); //$NON-NLS-1$
    contextMenu.add ( new Separator ( "additions" ) ); //$NON-NLS-1$
    contextMenu.setRemoveAllWhenShown ( true );
    contextMenu.addMenuListener ( this );
    Menu menu = contextMenu.createContextMenu ( viewer.getControl () );
    viewer.getControl ().setMenu ( menu );
    getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) );

    int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
    Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance (), LocalSelectionTransfer.getTransfer (), FileTransfer.getInstance () };
    viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) );
    viewer.addDropSupport ( dndOperations, transfers, new EditingDomainViewerDropAdapter ( editingDomain, viewer ) );
}
 
Example 11
Source File: XViewerCustDialogDragDrop.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Drag should only be from visible table
 */
public void performHiddenTableDragOver(DropTargetEvent event) {
   if (!TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
      event.detail = DND.DROP_NONE;
      return;
   }
   // Only allow drag from visibleColTable
   if (event.widget != xViewerCustomizeDialog.visibleColTable) {
      return;
   }

   event.detail = DND.DROP_MOVE;
}
 
Example 12
Source File: ScriptConsoleViewer.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private void initDragDrop() {
    DragSource dragSource = new DragSource(this, DND.DROP_COPY | DND.DROP_MOVE);
    dragSource.addDragListener(new DragSourceAdapter());
    dragSource.setTransfer(new Transfer[] { org.eclipse.swt.dnd.TextTransfer.getInstance() });

    DropTarget dropTarget = new DropTarget(this, DND.DROP_COPY | DND.DROP_MOVE);
    dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer(),
            org.eclipse.swt.dnd.TextTransfer.getInstance() });
    dropTarget.addDropListener(new DragTargetAdapter());
}
 
Example 13
Source File: BeansEditor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void createContextMenuFor(StructuredViewer viewer) {
	MenuManager contextMenu = new MenuManager("#PopUp");
	contextMenu.add(new Separator("additions"));
	contextMenu.setRemoveAllWhenShown(true);
	contextMenu.addMenuListener(this);
	Menu menu= contextMenu.createContextMenu(viewer.getControl());
	viewer.getControl().setMenu(menu);
	getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer));

	int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
	Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance(), LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance() };
	viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer));
	viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(editingDomain, viewer));
}
 
Example 14
Source File: EipEditor.java    From eip-designer with Apache License 2.0 5 votes vote down vote up
/**
   * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
   * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
   * @generated
   */
protected void createContextMenuFor(StructuredViewer viewer) {
     MenuManager contextMenu = new MenuManager("#PopUp");
     contextMenu.add(new Separator("additions"));
     contextMenu.setRemoveAllWhenShown(true);
     contextMenu.addMenuListener(this);
     Menu menu= contextMenu.createContextMenu(viewer.getControl());
     viewer.getControl().setMenu(menu);
     getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer));

     int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
     Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance(), LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance() };
     viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer));
     viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(editingDomain, viewer));
  }
 
Example 15
Source File: FileTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void dragFinished(DragSourceEvent event) {
	if (!event.doit)
		return;

	if (event.detail == DND.DROP_MOVE) {
		// http://bugs.eclipse.org/bugs/show_bug.cgi?id=30543
		// handleDropMove(event);
	} else if (event.detail == DND.DROP_TARGET_MOVE) {
		handleRefresh();
	}
}
 
Example 16
Source File: SelectionTransferDropAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int internalDetermineOperation(Object target, int operation, int operations) {

		initializeSelection();

		if (target == null)
			return DND.DROP_NONE;

		//Do not allow to drop on itself, bug 14228
		if (getCurrentLocation() == LOCATION_ON) {
			IJavaElement[] javaElements= ReorgUtils.getJavaElements(fElements);
			if (contains(javaElements, target))
				return DND.DROP_NONE;

			IResource[] resources= ReorgUtils.getResources(fElements);
			if (contains(resources, target))
				return DND.DROP_NONE;
		}

		try {
			switch(operation) {
				case DND.DROP_DEFAULT:
					return handleValidateDefault(target, operations);
				case DND.DROP_COPY:
					return handleValidateCopy(target);
				case DND.DROP_MOVE:
					return handleValidateMove(target);
			}
		} catch (JavaModelException e){
			ExceptionHandler.handle(e, PackagesMessages.SelectionTransferDropAdapter_error_title, PackagesMessages.SelectionTransferDropAdapter_error_message);
		}

		return DND.DROP_NONE;
	}
 
Example 17
Source File: DesignElementDropAdapter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see ViewerDropAdapter#performDrop(Object)
 */
public boolean performDrop( Object data )
{

	if ( DNDService.getInstance( ).performDrop( data,
			getCurrentTarget( ),
			getCurrentOperation( ),
			new DNDLocation( getCurrentLocation( ) ) ) )
	{
		return true;
	}

	if ( data instanceof Object[]
			&& ( (Object[]) data )[0] instanceof ThemeHandle )
	{
		if ( getCurrentTarget( ) instanceof ModuleHandle )
		{
			if ( Policy.TRACING_DND_DRAG )
			{
				System.out.println( "DND >> Dropped. Operation: Apply Theme, Target: " //$NON-NLS-1$
						+ getCurrentTarget( ) );
			}
			return applyTheme( (ThemeHandle) ( (Object[]) data )[0],
					(ModuleHandle) getCurrentTarget( ) );
		}
		else
		{
			return false;
		}
	}

	if ( getCurrentOperation( ) == DND.DROP_MOVE )
	{
		if ( Policy.TRACING_DND_DRAG )
		{
			System.out.println( "DND >> Dropped. Operation: Copy, Target: " //$NON-NLS-1$
					+ getCurrentTarget( ) );
		}
		return moveData( data, getCurrentTarget( ) );
	}
	else if ( getCurrentOperation( ) == DND.DROP_COPY
			|| getCurrentOperation( ) == DND.DROP_LINK )
	{
		if ( Policy.TRACING_DND_DRAG )
		{
			System.out.println( "DND >> Dropped. Operation: Move, Target: " //$NON-NLS-1$
					+ getCurrentTarget( ) );
		}
		return copyData( data, getCurrentTarget( ) );
	}
	return false;
}
 
Example 18
Source File: TexOutlinePage.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates the control ie. creates all the stuff that matters and
 * is visible in the outline. 
 * 
 * Actions must be created before menus and toolbars.
 * 
 * @param parent
 */
public void createControl(Composite parent) {
    super.createControl(parent);
    
    // create the context actions
    createActions();
    
    // initialize the tree viewer
    TreeViewer viewer = getTreeViewer();		
    filter = new TexOutlineFilter();
    viewer.setContentProvider(new TexContentProvider(filter));
    viewer.setLabelProvider(new TexLabelProvider());
    viewer.setComparer(new TexOutlineNodeComparer());
    
    // get and apply the preferences
    this.getOutlinePreferences();
    viewer.addFilter(filter);
    
    // set the selection listener
    viewer.addSelectionChangedListener(this);
    
    // enable drag'n'drop support
    TexOutlineDNDAdapter dndAdapter = new TexOutlineDNDAdapter(viewer, this);
    int ops = DND.DROP_COPY | DND.DROP_MOVE;
    Transfer[] transfers = new Transfer[] {TextTransfer.getInstance()};
    viewer.addDragSupport(ops, transfers, dndAdapter);
    viewer.addDropSupport(ops, transfers, dndAdapter);
    
    // enable copy-paste
    initCopyPaste(viewer);
    
    // create the menu bar and the context menu
    createToolbar();
    resetToolbarButtons();
    createContextMenu();
    
    
    // finally set the input
    if (this.input != null) {
        viewer.setInput(this.input.getRootNodes());
        
        // set update button status and also the context actions
        outlineActions.get(ACTION_UPDATE).setEnabled(false);
        outlineActions.get(ACTION_COPY).setEnabled(true);
        outlineActions.get(ACTION_CUT).setEnabled(true);
        outlineActions.get(ACTION_PASTE).setEnabled(true);
        outlineActions.get(ACTION_DELETE).setEnabled(true);

    }
}
 
Example 19
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());
		}
	});
}
 
Example 20
Source File: FilterViewer.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
public FilterViewer(Composite parent, int style, boolean isDialog) {
    super(parent, style);

    this.fIsDialog = isDialog;

    setLayout(new FillLayout());
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    setLayoutData(gd);

    final SashForm sash = new SashForm(this, SWT.HORIZONTAL);

    // Create the tree viewer to display the filter tree
    fViewer = new TreeViewer(sash, SWT.NONE);
    fViewer.setContentProvider(new FilterTreeContentProvider());
    fViewer.setLabelProvider(new FilterTreeLabelProvider());

    // Create the empty filter node properties panel
    fComposite = new Composite(sash, SWT.NONE);
    GridLayout gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    fComposite.setLayout(gl);

    createContextMenu();

    fViewer.addSelectionChangedListener(event -> {
        if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {
            // Update the filter node properties panel to the selection
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            ITmfFilterTreeNode node = (ITmfFilterTreeNode) selection.getFirstElement();
            updateFilterNodeComposite(node);
        } else {
            updateFilterNodeComposite(null);
        }
    });

    fViewer.getTree().addPaintListener(e -> {
        TmfFilterTreeNode root = (TmfFilterTreeNode) fViewer.getInput();
        if (root == null || root.getChildrenCount() == 0) {
            e.gc.setForeground(FOREGROUND_COLOR);
            e.gc.drawText(Messages.FilterViewer_EmptyTreeHintText, 5, 0);
        }
    });

    int operations = DND.DROP_MOVE | DND.DROP_COPY;
    DragSource dragSource = new org.eclipse.swt.dnd.DragSource(fViewer.getTree(), operations);
    dragSource.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
    dragSource.addDragListener(new FilterDragSourceAdapter(this));
    DropTarget dropTarget = new DropTarget(fViewer.getTree(), operations);
    dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
    dropTarget.addDropListener(new FilterDropTargetAdapter(this));
}