You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Pierre-Arnaud Marcelot <pa...@marcelot.net> on 2007/10/17 15:04:07 UTC

[Studio] Customizable size for ConnectionWidget

Hi Dev,

I'm using the ConnectionWidget class (
org.apache.directory.studio.connection.ui.widgets.ConnectionWidget) in the
Schema Editor plugin to let the user select the connection he wants to
associate with a Schema Project. The widget performs well but is
unfortunately defined with a height value of 250 which causes the window to
be a little too high.

I was wondering if was possible to modify the interface of the methods:

   - public void createWidget( Composite parent )
   - protected Control createContent( Composite parent )

to be able to give them a GridData for specifying the size of the widget
instead of using a default size of width = 450 & height = 250.

WDYT ?

Regards,
P-A

Re: [Studio] Customizable size for ConnectionWidget

Posted by Pierre-Arnaud Marcelot <pa...@marcelot.net>.
Ok, cool. Thanks.

I going to modify the ConnectionWidget GridData then, and see where it is
used in the LDAP Browser plugins to add an override of the GridData.

Regards,
P-A

On 10/22/07, Stefan Seelmann <se...@apache.org> wrote:
>
>
> > Maybe what we could do, is set the default GridData with no height and
> > width hints and when we use the ConnectionWidget and need to change its
> > size, use the following code (which overrides the default definition):
> >     GridData myGridData = new GridData( GridData.FILL_BOTH );
> >     myGridData.widthHint = 450;
> >     myGridData.heightHint = 250;
> >     connectionWidget.getViewer.getTree.setLayoutData( myGridData );
> >
> > It should be working...
> > WDYT ?
> >
>
> Yes, sounds good.
>
> > Regards,
> > P-A
> >
> >
>
> Stefan
>
>

Re: [Studio] Customizable size for ConnectionWidget

Posted by Stefan Seelmann <se...@apache.org>.
> Maybe what we could do, is set the default GridData with no height and
> width hints and when we use the ConnectionWidget and need to change its
> size, use the following code (which overrides the default definition):
>     GridData myGridData = new GridData( GridData.FILL_BOTH );
>     myGridData.widthHint = 450;
>     myGridData.heightHint = 250;
>     connectionWidget.getViewer.getTree.setLayoutData( myGridData );
>  
> It should be working...
> WDYT ?
>

Yes, sounds good.

> Regards,
> P-A
> 
>  

Stefan


Re: [Studio] Customizable size for ConnectionWidget

Posted by Pierre-Arnaud Marcelot <pa...@marcelot.net>.
Hi Stefan,

you are totally right. Hardcoding the width and height in that way is
> not a good idea, my fault. On Linux/GTK the height of the widget is
> good. But on other platforms it may be too high.


Well, the problem is actually on Linux/GTK (and on the other platforms too).

Instead the width and heigt of widgets should be calculated depending on
> the platform dependent font metrics. Here is a code snippet:
>
> ------------------------------------------------
> GC gc = new GC( control );
> gc.setFont( JFaceResources.getDialogFont() );
> FontMetrics fontMetrics = gc.getFontMetrics();
> gc.dispose();
>
> int width = Dialog.convertHorizontalDLUsToPixels( fontMetrics,
> IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
> int height = Dialog.convertVerticalDLUsToPixels( fontMetrics,
> IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 );
> ------------------------------------------------


I tried this code but it does not solves the problem. We only win 6 pixels
on the height.

I tried with the following code (without height and width hints):
    tree = new Tree( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL |
SWT.BORDER );
    GridData data = new GridData( GridData.FILL_BOTH );
    tree.setLayoutData( data );
And here, I win 101 pixels on the height. And the size of the dialog is no
longer changed (it's the default minimum size I think).

Here are a few screenshots:
the dialog, as it is right now ->
http://people.apache.org/~pamarcelot/ConnectionWidget/Window_ATM.png
the dialog with your fix ->
http://people.apache.org/~pamarcelot/ConnectionWidget/Window_Stefan_fix.png
the dialog with no height and width hints ->
http://people.apache.org/~pamarcelot/ConnectionWidget/Window_good.png

I don't think we need to pass a GridData to the createContent() method
> when we use that calculation.


I had a second (closer) look at the ConnectionWidget and I saw I could get
the TreeViewer with the method "public TreeViewer getViewer()".

Maybe what we could do, is set the default GridData with no height and width
hints and when we use the ConnectionWidget and need to change its size, use
the following code (which overrides the default definition):
    GridData myGridData = new GridData( GridData.FILL_BOTH );
    myGridData.widthHint = 450;
    myGridData.heightHint = 250;
    connectionWidget.getViewer.getTree.setLayoutData( myGridData );

It should be working...
WDYT ?

Regards,
P-A

Re: [Studio] Customizable size for ConnectionWidget

Posted by Stefan Seelmann <se...@apache.org>.
Hi Pierre-Arnaud,

you are totally right. Hardcoding the width and height in that way is
not a good idea, my fault. On Linux/GTK the height of the widget is
good. But on other platforms it may be too high.

Instead the width and heigt of widgets should be calculated depending on
the platform dependent font metrics. Here is a code snippet:

------------------------------------------------
GC gc = new GC( control );
gc.setFont( JFaceResources.getDialogFont() );
FontMetrics fontMetrics = gc.getFontMetrics();
gc.dispose();

int width = Dialog.convertHorizontalDLUsToPixels( fontMetrics,
IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
int height = Dialog.convertVerticalDLUsToPixels( fontMetrics,
IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 );
------------------------------------------------

I don't think we need to pass a GridData to the createContent() method
when we use that calculation.

WDYT?

Regards,
Stefan Seelmann


Pierre-Arnaud Marcelot schrieb:
> Hi Dev,
> 
> I'm using the ConnectionWidget class
> (org.apache.directory.studio.connection.ui.widgets.ConnectionWidget) in
> the Schema Editor plugin to let the user select the connection he wants
> to associate with a Schema Project. The widget performs well but is
> unfortunately defined with a height value of 250 which causes the window
> to be a little too high.
> 
> I was wondering if was possible to modify the interface of the methods:
> 
>     * public void createWidget( Composite parent )
>     * protected Control createContent( Composite parent )
> 
> to be able to give them a GridData for specifying the size of the widget
> instead of using a default size of width = 450 & height = 250.
> 
> WDYT ?
> 
> Regards,
> P-A
> 
>