Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » Textfield-GridEditor not usable when heigher than grid
Textfield-GridEditor not usable when heigher than grid [message #539613] Fri, 11 June 2010 13:58 Go to next message
Johannes Michler is currently offline Johannes MichlerFriend
Messages: 21
Registered: July 2009
Junior Member
Hi,

I'm trying to build a little application using a nebula grid with setAutoHeigth(true) and a GridEditor. I Registered a MouseAdapter on the Grid and when clicking in a cell of my Grid a new SWT Text widget gets created and filled with the text of my cell. This is fine so far. But when having large amounts of Text in the cell, so that the Entire Cell cannot be shown, I'm getting to problems: When scrolling down in my grid, I can see the next row. But I can not see the remainder text of the previous row. Furthermore, I cannot activate an GridEditor on such cells: I see no cursor of my newly created editor, and I cannot type anything. Visually, everything seems like before clicking the editor.


Have I done something wrong? Or is this a Nebula-Bug?


package edu.karlsruhe.horus.editors.petrinets.properties;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.nebula.widgets.grid.Grid;
import org.eclipse.nebula.widgets.grid.GridColumn;
import org.eclipse.nebula.widgets.grid.GridEditor;
import org.eclipse.nebula.widgets.grid.GridItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class test1 extends TitleAreaDialog {

    /**
     * Create the dialog.
     * 
     * @param parentShell
     */
    public test1( Shell parentShell) {
        super( parentShell);
    }

    /**
     * Create contents of the dialog.
     * 
     * @param parent
     */
    @Override
    protected Control createDialogArea( Composite parent) {
        Composite area = ( Composite) super.createDialogArea( parent);
        Composite container = new Composite( area, SWT.NONE);
        container.setLayout( new GridLayout( 1, false));
        container.setLayoutData( new GridData( GridData.FILL_BOTH));

        final Grid grid = new Grid( container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
        grid.setCellSelectionEnabled( true);
        grid.setHeaderVisible( true);
        grid.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true, 1, 1));
        grid.setAutoHeight( true);

        GridColumn gridColumn = new GridColumn( grid, SWT.NONE);
        gridColumn.setText( "New Column");
        gridColumn.setWidth( 150);
        gridColumn.setWordWrap( true);

        GridItem gridItem = new GridItem( grid, SWT.NONE);
        gridItem
                .setText(
                        0,
                        "Very long Text! Very long Text! Very long Text! Very long Text! Very long Text!Very long Text!Very long Text!Very long Text!Very long Text!Very long Text! Very long Text! Very long Text!");


        final GridEditor editor = new GridEditor( grid);
        grid.addMouseListener( new MouseAdapter() {

            public void mouseDown( MouseEvent e) {

                Control oldEditor = editor.getEditor();
                if ( oldEditor != null)
                    oldEditor.dispose();

                Point pt = new Point( e.x, e.y);

                final GridItem item = grid.getItem( pt);
                final Point cell = grid.getCell( pt);
                if ( item == null || cell == null)
                    return;

                // The control that will be the editor must be a child of the Table
                Text newEditor = new Text( grid, SWT.MULTI | SWT.BORDER | SWT.WRAP);
                newEditor.setText( item.getText( cell.x));
                editor.setEditor( newEditor, item, cell.x);
                editor.grabHorizontal = true;
                editor.grabVertical = true;

            }
        });
        return area;
    }

    /**
     * Create contents of the button bar.
     * 
     * @param parent
     */
    @Override
    protected void createButtonsForButtonBar( Composite parent) {
        createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
        createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
    }

    /**
     * Return the initial size of the dialog.
     */
    @Override
    protected Point getInitialSize() {
        return new Point( 589, 456);
    }

    @Override
    protected boolean isResizable() {
        return true;
    }
}

Re: Textfield-GridEditor not usable when heigher than grid [message #1033831 is a reply to message #539613] Thu, 04 April 2013 17:45 Go to previous messageGo to next message
K S is currently offline K SFriend
Messages: 4
Registered: February 2013
Junior Member
I am having the same problem as above. Can anyone help or provide more information about this? It seems the editor is not activated and text that go beyond the height of the grid are not displayed.

Is there a solution to get around this. Thank you.
Re: Textfield-GridEditor not usable when heigher than grid [message #1234594 is a reply to message #1033831] Wed, 22 January 2014 10:28 Go to previous message
Marko Herchet is currently offline Marko HerchetFriend
Messages: 13
Registered: May 2012
Junior Member
I have the same problem as well. I think it might have to do with the following code I found
	public Rectangle getBounds(int columnIndex) {
		checkWidget();

		// HACK: The -1000,-1000 xy coordinates below are a hack to deal with
		// GridEditor issues. In
		// normal SWT Table, when an editor is created on Table and its
		// positioned in the header area
		// the header overlays the editor. Because Grid (header and everything)
		// is drawn on one
		// composite, when an editor is positioned in the header area the editor
		// overlays the header.
		// So to fix this, when the editor is anywhere its not supposed to be
		// seen (the editor
		// coordinates are determined by this getBounds) we position it out in
		// timbuktu.
		if (!isVisible())
			return new Rectangle(-1000, -1000, 0, 0);

		if (!parent.isShown(this))
			return new Rectangle(-1000, -1000, 0, 0);

		Point origin = parent.getOrigin(parent.getColumn(columnIndex), this);

		if (origin.x < 0 && parent.isRowHeaderVisible())
			return new Rectangle(-1000, -1000, 0, 0);

		Point cellSize = this.getCellSize(columnIndex);

		return new Rectangle(origin.x, origin.y, cellSize.x, cellSize.y);
	}

[Updated on: Wed, 22 January 2014 10:28]

Report message to a moderator

Previous Topic:[SOLVED] Expanded tree toggles in Grid
Next Topic:Not display any groups in Gallery?
Goto Forum:
  


Current Time: Wed Apr 24 15:23:55 GMT 2024

Powered by FUDForum. Page generated in 0.03328 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top