ScrolledComposite showing two scrollbars each for vertical & horizontal scroll - eclipse

My current application is a RCP application using eclipse framework. There is a view whose composite is given to a Scrolled Composite and then all the relevant composites are made with the ScrolledComposite as the parent.
protected void createContent(Composite parent)
{
ScrolledComposite form = new ScrolledForm(parent,SWT.H_SCROLL|SWT.V_SCROLL);
GridLayout layout = new GridLayout(1, false);
form.getBody().setLayout(layout);
......................
.........................
}
The issue is that at times there are two vertical and two horizontal scrollbars visible. One is of the main view and the second is for the ScrolledComposite.
I have implemented a ResizeListener that will change the MinSize of the SCrolledLayout dynamically.
Rectangle rect = form.getClientArea();
form.setMinSize(SWT.DEFAULT,SWT.DEFAULT);
However Still at times there are two Scrollbars visible but they are of no use and they look annoying. So Since the scrollbars are of no use I am disabling them in the ResizeListener itself.
Rectangle rect = form.getClientArea();
form.getHorizontalBar().setVisible(false);
form.getVerticalBar().setVisible(false);
form.setMinSize(SWT.DEFAULT,SWT.DEFAULT);
Is there a better way to do this or am I goofing up somewhere.

Related

GWT drag and drop animation

I have a flow panel with many photo-widgets inside (gallery with random number of rows and columns, depends on screen size) for which I want to implement drag and drop behavior to change their order. I am using gwt-dnd library. Its FlowPanelDropController allows you to define your own positioner (delimiter) which shows the candidate location for dropping the dragged widget.
I want this positioner to be the empty space with defined width, and the challenging thing is to implement sliding animation effect for the when positioner is added and removed.
If you are a desktop Picasa app user you know what I mean: the target row slides both sides (little to the left, little to the right) extending the space between the items where you are going to drop a photo.
The whole thing is complex enough, but any help related to how to apply the animation for positioner attach/detach is appreciated. Maybe I need to use a different approach (e.g., use GWT native dnd instead of gwt-dnd lib and no "positioners" at all) if you have any ideas how this could be helpful.
Thanks.
Well, I ended up overriding AbstractPositioningDropController (parent of FlowPanelDropController) and adding some extra features.
1) newPositioner() method now builds the Label, which is vertical space with some small width, height and decoration. This widget's element has constant id (say, "POSITIONER"), which helps to distinguish between multiple positioners if you plan to have several of them while navigating with a drag object over multiple drop targets. Also some transition CSS effects were applied to the Label, which will be responsible for handling animated extension of Label's width.
2) in onEnter() I do the following
...
removePositioner(getPositionerElement());
Widget positioner = newPositioner();
dropTarget.insert(positioner, targetIndex);
animatePositionerExtension();
where getPositionerElement() returns DOM.getElementById(POSITIONER)
At the same time removePositioner(..) resets the id of this element to something abstract and ideally should provide some animation before calling .removeFromParent(). But I didn't have enough time to properly debug this so ended up just removing the old positioner with no animation.
Method animatePositionerExtension() contains the code that changes the width of the positioner widget, so that CSS transition will catch that and provides animation.
All access to positioner widget in the class should be provided through updated methods.
3) onLeave() contains line removePositioner(getPositionerElement());
4) In the end of onMove() I added a couple of lines:
galleryWidget.extendHoveredRow(targetIndex - 1);
animatePositionerExtension();
where extendHoveredRow(hoveredWidgetOrdinal) implemented the logic to "limit" the sliding effect in the single line:
int rowHovered = -1;
public void extendHoveredRow(int hoveredWidgetOrdinal) {
int newRowHovered = getRowByOrdinalHovered(hoveredWidgetOrdinal);
if (rowHovered != newRowHovered) {
// adjust position of items in the previously hovered row
int firstInPreviouslyHoveredRow = (rowHovered - 1) * itemsInARow;
shiftFirstItemLeft(firstInPreviouslyHoveredRow, false);
rowHovered = newRowHovered;
// extend this row
int firstInThisRow = getOrdinalFirstInThisRowByOrdinal(hoveredWidgetOrdinal);
shiftFirstItemLeft(firstInThisRow, true);
}
}
This is in short how I did the thing. And still there's some room for improvements, like adding animated removal.
Again, it's all about overriding DropController and manipulations with elements inside the "gallery" widget. The benefit of this approach is that I remain in the gwt-dnd operations framework, and also reused a bunch of existent code.
Some notes:
CSS transition is not supported in IE pre-9, but this is unrelated to
this topic.
Put a transparent "glass" div on top of the Image widget if you use it
as a face of dragProxy. This will save you tons of time trying to
understand why either setting element's draggable to false, or
calling event.preventDefault() somewhere else, or other workarounds don't work in one or several browsers and the image itself is being dragged instead of the whole dragProxy widget.

GXT ScrollBar overlapping content

I'm using setScrollMode(ScrollMode.AUTOY) to enable vertical scrolling when necessary on a VerticalLayoutContainer. However, the scrollbar overlaps the content of the container. The only way around this that I've seen is to call setAdjustForScroll(true). The problem with this is that The panel will then always reserve space for a scrollbar even when one is not present.
Is there a way to tell GXT to only adjust for a scrollbar when one is present? Or perhaps use an event handler (eg ResizeHandler) and check if the scrollbar is currently visible?
Instead of trying to check in a handler if the scrollbar is visible, isn't it just easier to not have the content in the VerticalLayoutContainer?
For example I have:
VerticalLayoutContainer vp = new VerticalLayoutContainer();
vp.setScrollMode(ScrollMode.AUTO);
vp.add(layer1, new VerticalLayoutData(1, -1));
vp.add(layer2, new VerticalLayoutData(1, -1));
vp.add(layer3, new VerticalLayoutData(1, -1));
the layers(1-3) contain the actual content and are different types Ex. VBoxLayoutContainer, Container, VerticalLayoutContainer.
It works for me. I don't think it is relevant but I am adding the vp to a CenterLayoutContainer that is added to the root panel.

Display SimplePager Pagination menu both at the top and bottom of the data

I have some data that I'm displaying in a CellTable which is inside a SimplePager. The pagination navigation options are shown in the bottom, I was wondering if it would be possible to show these on the top as well as the bottom of the data.
I want to do this because depending on the browser size, the user may not be able to see the controls.
I want the navigation controls to show both before and after the table data.
Yes, just add two pagers:
final AbstractPager pager = new SimplePager();
pager.setDisplay(cellTable);
contentPanel.add(pager);
contentPanel.add(cellTable);
final AbstractPager pager2 = new SimplePager();
pager2.setDisplay(cellTable);
contentPanel.add(pager2);
The pager shows on top if you add pager before adding celltable in layout.
CellTable table=new CellTable();
VerticalPanel containerPanel = new VerticalPanel();
SimplePager pager1 = new SimplePager(TextLocation.CENTER);
containerPanel.add(pager);
containerPanel.add(table);
SimplePager pager2 = new SimplePager(TextLocation.CENTER)
containerPanel.add(pager2)
Thus, you have to create two pager and add celltable in between of those.

automatic resize of the tab panel based on contents

Hello I have implemented something like
private VerticalPanel resultPanel;
private TabLayoutPanel tabPanel = new TabLayoutPanel(2.5, Unit.EM);
ResizeLayoutPanel resizePanel = new ResizeLayoutPanel();
myMethod(){
resizePanel.setWidth("100%");
resizePanel.setHeight("415px");
resizePanel.setWidget(tabPanel);
resultPanel = new VerticalPanel();
resultPanel.setWidth("100%");
resultPanel.add(resizePanel);
tabPanel.add(myVerticalPanel, tabHeader);
}
so the myVerticalPanel is the actual contents which is little large in height. As resizePanel height is set to 415px so rest of the contents are hidden.
I am looking for two things to achieve:
1. If there is a larger screen available then increase the tabPanel area to show more contents automatically
2. If screen is small then a scroll to appear to see rest of the contents
Please advise
You can try to replace the TabLayoutPanel with a HeaderPanel:
A panel that includes a header (top), footer (bottom), and content
(middle) area. The header and footer areas resize naturally. The
content area is allocated all of the remaining space between the
header and footer area.
Alternatively you can override the onResize() method your ResizeLayoutPanel calculate the height of your embedded content and set the appropriate height.
If you want scrolling functionality you have to embed your VerticalPanel in a ScrollPanel or use CSS to set the oferflow property.

Error in GWT MapWidget

I am trying to add MapWidget to VerticalPanel but the map added on the
left corner:
And I added marker and the marker should be centered on the image
I can't see the marker when I load the map. I should navigate to this
location to show map.
The code for this
private FormPanel form = new FormPanel();
private VerticalPanel main = new VerticalPanel();
public Map(){
ScrollPanel container = new ScrollPanel();
initWidget(container);
container.setStyleName("FuoEgForm");
form.setWidget(main);
main.setSpacing(6);
container.add(main);
}
public MapWidget addMapWidget(){
MapWidget map = new MapWidget();
//map.setSize("100%", "100%");
map.setStyleName("gwt-map");
map.removeMapType(MapType.getNormalMap());
map.removeMapType(MapType.getSatelliteMap());
map.addMapType(MapType.getPhysicalMap());
map.addMapType(MapType.getHybridMap());
map.setCurrentMapType(MapType.getHybridMap());
//map.setSize("100%", "100%");
map.setWidth("500px");
map.setHeight("500px");
main.add(map);
}
How can I solve this issue? The map should fill the gray
boundary?
As of gwt-maps-1.1, the MapWidget implements the RequiresResize interface. When added to a panel that supports this interface (such as DockLayoutPanel), the widget automatically calls map.checkResizeAndCenter() whenever the panel containing the widget is resized. This new feature makes it possible to set your map size to 100% in both directions and fill up the available space on the screen. To use LayoutPanel subclasses properly, make sure your html page is set to use standards mode by adding as the first line in the document.
In gwt-maps 1.0, it may be necessary to force the map to resize its layout after the map is initially added. you can use the MapWidget.checkResizeAndCenter() method to clean this up. You may need to delay calling this function using a DeferredCommand or other mechanism to wait until after the DOM layout pass that resizes the map is called.
or you can find unexpected another unexpected reason that happened with me
i made the map invisible #constructor
and then set it visible if clicked on a button
the solution
make the map always visible :)
I insert these line below the add(map) :
LatLng c = mapWidget.getCenter();
resizeMap(mapWidget.getMVCObject());
mapWidget.setCenter(c);