I want to use the CaptionPanel inside a Layout Panel (DockLayoutPanel) .
The problem is that there is no CaptionLayoutPanel(like SimpleLayoutPanel) implementation and therefore if I want to use
this panel inside a Layout Panel, all childs will loose the resize events because the "resize-chain" is broken through the CaptionPanel.
Is there any workaround?
Extend CaptionPanel and implement the ProvidesResize and RequiresResize interfaces
CustomCaptionPanel extends CaptionPanel implements RequiresResize,ProvidesResize {
public void onResize() {
if (getContentWidget() instanceof RequiresResize) {
((RequiresResize) getContentWidget()).onResize();
}
}
The easiest solution is not to use CaptionPanel.
If you want children to respond to resize events, add a layer to your LayoutPanel that will hold a caption (Label), and another layer that will contain a child widget that you want to respond to resize. You can style these widgets any way you like (e.g. a Label can look like a tab or a panel with some background and rounded corners, etc.)
An alternative solution is style your CaptionPanel as Roddy of the Frozen Peas suggested, and then add a ResizeHandler to your window. When triggered, you can set the size of a child widget to
myChildWidget.setSize(myCaptionPanel.getOffsetWidth() + "px", myCaptionPanel.getOffsetHeight() + "px");
Related
My Graphiti editor has shape that represents db table with it rows.. i am looking for a way to add scroll bar to my shape. any one know how to do that?
I've found an answer to this question.
This is the link to use: https://www.eclipse.org/forums/index.php/t/1071551/
I've created my own ScrollFigure, which extends draw2d ScrollPane and implements IGraphicsAlgorithmRenderer.
public class ScrollFigure extends ScrollPane implements IGraphicsAlgorithmRenderer {
#Override
public void setLayoutManager(LayoutManager manager) {
super.setLayoutManager(new ScrollPaneLayout());
}
}
Next you just have to adjust sizes of your figures in your custom factory, which instantiates your ScrollFigure, and scrollbars will be shown.
Is there a way to make com.google.gwt.user.client.ui.HTML widget being enabled or not-enabled? I tried but there seems no setEnabled(boolean) method :S Share your experience please
Thanks
I'm not sure what you mean by enabled but I'll take a stab at it.
I assume that you mean visible or not visible.
HTMLPanel panel = new HTMLPanel();
panel.setVisible(false); // Disabled
panel.setVisible(true); // Enabled
Hopefully that's what you were looking for.
Only a few HTML elements can be enabled or disabled, like inputs. GWT has setEnabled() for elements that can get focus:
http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/FocusWidget.html#setEnabled(boolean)
Only some form elements(inputs, options) can be disabled.
To disable:
widget.getElement().setAttribute("disabled","disabled");
To enable again:
widget.getElement().removeAttribute("disabled");
For other widget, you need to set their style to mimic "disabling". (e.g. set the color to grey)
Unfortunately there is no such a method in Widget.
But there is a little room to acheive .I made it work with help of google groups
public void setEnabled (boolean e)
{
Iterator<Widget> itr = grd.iterator (); // grd is a FlexTable which
contains my form controls
while (itr.hasNext ())
{
Widget w = itr.next ();
if (w instanceof TextBox)
{
TextBox t = (TextBox) w;
t.setEnabled (e);
}
if (w instanceof PasswordTextBox)
{
PasswordTextBox t = (PasswordTextBox) w;
t.setEnabled (e);
}
...
}
To Give appearance of enable and disable feature in a widget which does not inherit from FocusWidget.
You would need to override both style and event handling implementation. Keep a enableFl in your MyHTMLPanel extends HTMLPanel.
Step 1 - Provide enable and disable style. Using opacity css turn on/off greying sort of coloring. Based on state of enableFl turn on/off the enable/disable feature.
Step 2 - Disable/Enable event handling on the widget by overriding onBrowserEvent and making its execution conditional on your own enableFl state.
Step 3 - Recursively disable all widgets internal to HTMLPanel.
If your use case is simple you might opt to use com.google.gwt.user.client.ui.HTML instead of com.google.gwt.user.client.ui.HTMLPanel .
I have a TabLayoutPanel where I am putting custom widgets in for the tabs to be able to display some images next to the text. I originally worked with TabPanel and using custom HTML for the tab text, but custom tab widgets allows me to modify the image on the fly as needed.
My tab widget is essentially a HorizontalPanel, a number of small images, and a line of text. The problem I'm having is that the tab doesn't want to stick to the bottom of the tab bar like normal. The tab is getting positioned at the top of the space reserved for the tab bar, and there's a gap between it and the bottom of the tab bar. I uploaded an image of the problem to http://imgur.com/fkSHd.jpg.
Is there some style that I need to apply to custom widget tabs to make them appear correctly?
In my brief experience, the newer standards mode panels (they all end in "LayoutPanel") don't get along with the older ones (the ones that just end in "Panel"). So you might consider trying a DockLayoutPanel instead of the HorizontalPanel, and it may be more cooperative.
See https://developers.google.com/web-toolkit/doc/latest/DevGuideUiPanels, particularly the section called "What won't work in Standards Mode?":
HorizontalPanel is a bit trickier. In some cases, you can simply
replace it with a DockLayoutPanel, but that requires that you specify
its childrens' widths explicitly. The most common alternative is to
use FlowPanel, and to use the float: left; CSS property on its
children. And of course, you can continue to use HorizontalPanel
itself, as long as you take the caveats above into account.
After a bit more research, I found the answer here: https://groups.google.com/d/msg/google-web-toolkit/mq7BuDaTNgk/wLqPm5MQeicJ. I had to use InlineLabel or InlineHTML widgets instead of normal Label or HTML widgets. I've tested this solution and it does exactly what I want. I pasted the code of the class below for completeness. Note two things here:
The "float" attribute cannot be set on the last element (the InlineLabel) or the incorrect drawing condition occurs again.
The code could be cleaned up a bit further by having the class extend directly from FlowPanel instead of making it a composite containing a FlowPanel.
package com.whatever;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Float;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.InlineLabel;
public class StatusTab extends Composite
{
public interface StatusImages extends ClientBundle
{
public static StatusImages instance = GWT.create(StatusImages.class);
#Source("images/status-green.png")
ImageResource green();
#Source("images/status-red.png")
ImageResource red();
}
private final ImageResource greenImage;
private final ImageResource redImage;
private final FlowPanel flowPanel;
public LinkStatusTab(String text, int numStatuses) {
greenImage = StatusImages.instance.green();
redImage = StatusImages.instance.red();
flowPanel = new FlowPanel();
initWidget(flowPanel);
for (int i = 0; i < numStatuses; i++)
{
Image statusImg = new Image(redImage);
statusImg.getElement().getStyle().setMarginRight(3, Unit.PX);
statusImg.getElement().getStyle().setFloat(Float.LEFT);
flowPanel.add(statusImg);
}
flowPanel.add(new InlineLabel(text));
}
/**
* Sets the image displayed for a specific status entry.
*/
public void setStatus(int which, boolean status)
{
Image image = (Image)flowPanel.getWidget(which);
if (status)
image.setResource(greenImage);
else
image.setResource(redImage);
}
}
I want to click on an image and therefore want to register (e.g.) a ClickHandler. The image I get from a ClientResource. This works so far to set the image into a table cell:
MyResources.INSTANCE.css().ensureInjected();
Image colorImage = new Image( MyResources.INSTANCE.colorImage() );
Element colorImageElement = colorImage.getElement();
colorImage.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
System.out.println( event );
}
} );
TableElement table = Document.get().createTableElement();
TableRowElement headRow = table.insertRow(-1);
headRow.insertCell(-1).appendChild( colorImageElement );
RootPanel.get().getElement().appendChild( table );
How can I add a listener to the icon? I tried ClickHandler and to put the image on a PushButton and get the Element from this PushButton but all don't work.
But mind, if I add the widget (Image is a Widget) to a panel it works!
RootPanel.get().add( colorImage );
But I am not working with widgets here but with the Element. So the handler disappears and that's the point I don't get how to preserve this added handler information.
In the end I would like to build a table with different rows where I can click on the icon I get a popup menu and thereby change the colour of the row.
You should be able to just add a ClickHandler (or a MouseDownHandler if that fits your needs better).
Like this:
colorImage.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// Do something....
}
});
Don't unwrap your widget and append only the DOM elements. The Widget class allows your code to refer to both elements and events at the same time, and deals with possible memory leaks, as well as grouping your code in logical ways.
This might make sense for other frameworks, but in GWT you almost always want to work with the Widgets directly, adding them together, then appending them to the RootPanel.
If you really want to use a html table to build this up, look at the com.google.gwt.user.client.ui.HTMLTable subclasses, com.google.gwt.user.client.ui.Grid and com.google.gwt.user.client.ui.FlexTable. This probably should never be necessary, unless you are adding multiple items to the table - when trying to specify layouts, use actual layout classes.
did you tried to add image.sinkEvents( Event.ONCLICK | Event.MOUSEEVENTS )?
The image has to be inside a focus widget. I don't know why that is, but somewhere the events don't get propagated right and the DOM events don't fire.
I have a couple of composite widgets which all have dymaincally sizing object within them.
When I instantiate a composite widget I would like it to fill its container as a percentage, say 80% for example.
Each of the objects within the widget will grow to fit inside the composite regardless of composites size but the composite itself wont grow as a percentage of its container.
Is this even possible? I have tried the .setWidth() method but this won't recognise a % asd an argument.
I am not setting the size within the composite widget class.
I have a calling class that instantiates the composite widget and then calls the setWidth() method on the new object.
I will try out your method and if it works then apply it to my problem. I will post again once I have some more information.
Thankyou for your help :-)
Ofcourse it is possible.Composite setWidth() method recognizes % also.Can you give me the sample code you are using? Make sure that calling of setWidth() method must be after the initwidget() call of your composite.try like this
public class Widget1 extends Composite{
private VerticaPanel panel=new VerticalPanel();
public Widget1(){
initWidget(panel);
setWidth("80%");
panel.add(new Widget2());
}
}
public class Widget2 extends Composite{
private VerticaPanel panel=new VerticalPanel();
public Widget2(){
initWidget(panel);
setWidth("100%");
}
}
Here is my test composite class:
**class CompositePane extends Composite {
//Define a panel that contains everything
private VerticalPanel compositePanel = new VerticalPanel();
private Button button1 = new Button("Button1");
public CompositePane(){//Start StatusPane constructor
compositePanel.add(button1);
initWidget(compositePanel);
setWidth("100%");
addStyleName("compositePanel");
}//End of StatusPane constructor
}//End of StatusPane class**
Here is my style attached to this object that shows the edges of the composite object:
.compositePanel{
**border: 5px solid black;
}**
When using a set value of pixels the border expands as expected.
When using 100%, it sit tightly around the button, where I need it to touch the outside edge of its container.
Thanks.Where you are adding this CompositePanel. CompositePanel.setWidth("100%") method makes this compositePanel to use it parents 100% width.So in your case its parent width is less.Try the following example .You will understand that what to do in your code.Now borders width will be 800px.
VerticalPanel parentPanel=new VerticalPanel();
parentPanel.setWidth("800");
parentPanel.add(new CompositePanel());
RootPanel.get().add(parentPanel);