2015-11-24 16:22:17 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.user.statisticalalgorithmsimporter.client;
|
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
import com.google.gwt.dom.client.Element;
|
|
|
|
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
|
|
|
import com.google.gwt.user.client.Window;
|
|
|
|
import com.sencha.gxt.core.client.dom.XDOM;
|
|
|
|
import com.sencha.gxt.core.client.dom.XElement;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.SimpleContainer;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.Viewport.ViewportAppearance;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2017-05-12 18:26:05 +02:00
|
|
|
* @author Giancarlo Panichi
|
|
|
|
*
|
2015-11-24 16:22:17 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class PortalViewport extends SimpleContainer {
|
|
|
|
|
|
|
|
protected int rightScrollBarSize = 17;
|
|
|
|
|
|
|
|
protected boolean enableScroll;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a viewport layout container with the default appearance.
|
|
|
|
*/
|
|
|
|
public PortalViewport() {
|
2017-05-12 18:26:05 +02:00
|
|
|
this(GWT.<ViewportAppearance>create(ViewportAppearance.class));
|
2015-11-24 16:22:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a viewport layout container with the specified appearance.
|
|
|
|
*
|
|
|
|
* @param appearance
|
|
|
|
* the appearance of the viewport layout container
|
|
|
|
*/
|
|
|
|
public PortalViewport(ViewportAppearance appearance) {
|
|
|
|
super(true);
|
|
|
|
try {
|
|
|
|
|
|
|
|
SafeHtmlBuilder sb = new SafeHtmlBuilder();
|
|
|
|
appearance.render(sb);
|
2017-05-12 18:26:05 +02:00
|
|
|
XElement element = XDOM.create(sb.toSafeHtml());
|
|
|
|
setElement((Element) element);
|
2015-11-24 16:22:17 +01:00
|
|
|
monitorWindowResize = true;
|
|
|
|
forceLayoutOnResize = true;
|
|
|
|
getFocusSupport().setIgnore(false);
|
|
|
|
resize();
|
|
|
|
} catch (Exception e) {
|
2017-05-12 18:26:05 +02:00
|
|
|
Log.error("PortalViewport: constructor error " + e.getLocalizedMessage());
|
2015-11-24 16:22:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if window scrolling is enabled.
|
|
|
|
*
|
|
|
|
* @return true if window scrolling is enabled
|
|
|
|
*/
|
|
|
|
public boolean isEnableScroll() {
|
|
|
|
return enableScroll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether window scrolling is enabled.
|
|
|
|
*
|
|
|
|
* @param enableScroll
|
|
|
|
* true to enable window scrolling
|
|
|
|
*/
|
|
|
|
public void setEnableScroll(boolean enableScroll) {
|
|
|
|
this.enableScroll = enableScroll;
|
|
|
|
Window.enableScrolling(enableScroll);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the rightScrollBarSize
|
|
|
|
*/
|
|
|
|
public int getRightScrollBarSize() {
|
|
|
|
return rightScrollBarSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param rightScrollBarSize
|
|
|
|
* the rightScrollBarSize to set
|
|
|
|
*/
|
|
|
|
public void setRightScrollBarSize(int rightScrollBarSize) {
|
|
|
|
this.rightScrollBarSize = rightScrollBarSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onAttach() {
|
|
|
|
super.onAttach();
|
|
|
|
setEnableScroll(enableScroll);
|
|
|
|
resize();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void resize() {
|
|
|
|
int viewWidth;
|
2017-05-12 18:26:05 +02:00
|
|
|
if (enableScroll) {
|
|
|
|
viewWidth = calculateWidth() - rightScrollBarSize;
|
2015-11-24 16:22:17 +01:00
|
|
|
} else {
|
|
|
|
viewWidth = calculateWidth();
|
|
|
|
}
|
2017-05-12 18:26:05 +02:00
|
|
|
|
2015-11-24 16:22:17 +01:00
|
|
|
int viewHeight = calculateHeight();
|
2017-05-12 18:26:05 +02:00
|
|
|
Log.info("AM resize viewWidth: " + viewWidth + " viewHeight: " + viewHeight + " clientWidth: "
|
|
|
|
+ Window.getClientWidth() + " clientHeight: " + Window.getClientHeight());
|
2015-11-24 16:22:17 +01:00
|
|
|
try {
|
|
|
|
setPixelSize(viewWidth, viewHeight);
|
|
|
|
} catch (Exception e) {
|
2017-05-12 18:26:05 +02:00
|
|
|
Log.error("PortalViewport: error in resize() at setPixelSize " + e.getLocalizedMessage());
|
2015-11-24 16:22:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onWindowResize(int width, int height) {
|
|
|
|
int viewWidth = calculateWidth();
|
|
|
|
int viewHeight = calculateHeight();
|
2017-05-12 18:26:05 +02:00
|
|
|
Log.trace("AM onWindowResize viewWidth: " + viewWidth + " viewHeight: " + viewHeight + " clientWidth: "
|
|
|
|
+ Window.getClientWidth() + " clientHeight: " + Window.getClientHeight());
|
2015-11-24 16:22:17 +01:00
|
|
|
setPixelSize(viewWidth, viewHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int calculateWidth() {
|
|
|
|
int leftBorder = getAbsoluteLeft();
|
2017-05-12 18:26:05 +02:00
|
|
|
Log.info("AM width: " + String.valueOf(Window.getClientWidth() - 2 * leftBorder));
|
2015-11-24 16:22:17 +01:00
|
|
|
return Window.getClientWidth() - 2 * leftBorder;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int calculateHeight() {
|
|
|
|
int topBorder = getAbsoluteTop();
|
2017-05-12 18:26:05 +02:00
|
|
|
Log.info("AM height: " + String.valueOf(Window.getClientHeight() - topBorder - 34));
|
2015-11-24 16:22:17 +01:00
|
|
|
return Window.getClientHeight() - topBorder - 34;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|