Gwtbootstrap3. Using bootstrap component only with java code- without ui-binder - java

Is there possibile to use bootstrap3 elements (from gwtboostrap3 library) without using ui binder, but using java code like it is done with gwt regular widgets?
I could not find a word about it in Documentation.
F.E. Lets take button widget from gwt:
public void onModuleLoad() {
// Make a new button that does something when you click it.
Button b = new Button("Jump!", new ClickHandler() {
public void onClick(ClickEvent event) {
Window.alert("How high?");
}
});
// Add it to the root panel.
RootPanel.get().add(b);
}
}
Which will create:
<button type="button" class="gwt-Button">Jump!</button>
In gwtbootstrap3 I have to do something like that:
<b:Button type="DEFAULT"/>
Please help me with that.
Is it possible to use gwtbootstrap3 library components like button with pure java instead of uibinder xml files?
Is there solution that works out of box?
Or maybe I should write my own classess that extends native gwt widget an add bootstrap releated css classes?

Yes!
You can use the widget as you please, refer to the their javadoc to see what constructors they have! They are a different set of widgets and might not be analogue of GWT standard widgets.
Bonus
GWT UiBinder does no different than you, all it does is reduce the boilerplate, generating java classes that automate the instantiate of the widgets. You can add the compiler option -gen to see these transient classes. Usually , they are deleted after GWT compiles your application, as they are no longer needed. Take a look the the compiler documentation for more info!

Related

How to use CellTable.Style with GWT 2.7.0 without UiBinder?

I joined a GWT application project a few weeks ago. The codebase was started back in 2009. I am trying to replace a FlexTable with a CellTable so that I can take advantage of the sortable columns. The current version of GWT in the project is 2.7.0, but looking through the code, it looks like there are some features still used that have gone out of style. I am new to GWT, I could be wrong.
So far, things are functionally good. However, GWT seems to be overriding my attempts to update the CSS. I used the GWT dynatablerf sample as a model to add CSS to the CellTable. The TimeSlotWidget uses CellTable.Style:
interface TableResources extends CellTable.Resources {
#Override
#Source(value = {CellTable.Style.DEFAULT_CSS, "CellTablePatch.css"})
CellTable.Style cellTableStyle();
}
And then applies it to the CellTable like this:
table = new CellTable<TimeSlotListWidget.ScheduleRow>(ROWS_IN_A_DAY,
GWT.<TableResources> create(TableResources.class));
I tried to use this approach in my code. I even omitted the CellTable.Style.DEFAULT_CSS from the value list and created my own CSS stylesheet which started as a copy of the GWT CellTable.css
I noticed that GWT TimeSlotListWidget sample has an ui.xml file with UIBinder. My project does not currently use UIBinder.
When I run my code, there is a <style> block inserted into the page that seems to be the standard GWT CellTable.css. Then directly after that, another <style> block is inserted with my CSS. And my CSS is not overriding the standard GWT CSS.
How can I keep the GWT CellTable.css from being inserted? Why is it being inserted?
The problem is that in your code, you reuse CellTable.Style, and two different ClientBundles have used the same type but each bound their own CSS to it.
Instead, extend the CellTable.Style interface, and use that in your bundle:
interface MyCellTableStyle extends CellTable.Style {}
interface TableResources extends CellTable.Resources {
#Override
#Source(value = {CellTable.Style.DEFAULT_CSS, "CellTablePatch.css"})
MyCellTableStyle cellTableStyle();
}

GWT UiBinder I18n

As the title says I need some help with GWT's i18n in use with UiBinder. I want to internationalize my application using static i18n. The book I use for learning only presents a way of internationalizing ui.xml files by having the compiler generate keys for Constants/Messages and a default file, but there has to be an easier way to do this. That's why I tried using the ui:with tag like this to use my internationalized constants (inside the upFace):
<ui:with type="havis.ui.shared.resourcebundle.ConstantsResource" field="lang"></ui:with>
<g:ToggleButton ui:field="observeButton">
<g:upFace>{lang.observe}</g:upFace>
<g:downFace>Observing</g:downFace>
</g:ToggleButton>
This doesn't work, the button shows the text {lang.observe} which also seems logical, but now my question is: Is there any way to use constants like this? And if not could someone explain how I should use constants in UiBinder files instead (without having the compiler generate files and keys)?
Anywhere HTML is accepted (such as within upFace), you can use <ui:msg>, <ui:text> and <ui:safehtml> (and anywhere plain text is expected, you can use <ui:msg> and <ui:text>).
So in your case:
<ui:with type="havis.ui.shared.resourcebundle.ConstantsResource" field="lang"></ui:with>
<g:ToggleButton ui:field="observeButton">
<g:upFace><ui:text from="{lang.observe}"/></g:upFace>
<g:downFace>Observing</g:downFace>
</g:ToggleButton>
See http://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Hello_Text_Resources and http://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Hello_Html_Resources about ui:text and ui:safehtml.
You can use constants like this :
.ui.xml :
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'>
<ui:with field="constants" type="my.client.resources.AppResources.AppConstants"/>
<g:FlowPanel>
<g:Label text="{constants.label}"/>
</g:FlowPanel>
and the AppResources interface :
public interface ApplicationResources extends ClientBundle {
public static final ApplicationConstants CONSTANTS = GWT.create(ApplicationConstants.class);
public interface ApplicationConstants extends com.google.gwt.i18n.client.Constants {
#DefaultStringValue("my label")
String label();
}
}
But for i18n you should really follow what the GWT manual says, i.e. there
is no other (clean) way than prepare all the property files (one for each language) and generate all the required permutations. This primarily delegates
to GWT all the language detection-related stuff, and the solution provided by
GWT performs quite well at runtime. The only drawback is that the compile time
is a little higher (since you'll have permutations for every browser in every language you specify).

How to change theme in SWT application

I'm new to developing SWT applications and am looking for an easy way to change the theme of a small application which I have already developed.
After doing some googling I'm able to tell that there seems to be something called presentations which seems like a way I can download a ready made theme and just apply it to my application. Is that right?
Alternatively can anyone point me to a good tutorial on the right way to go about it?
thanks
If you are just talking about SWT without Ecipse RCP, then there is no way to theme the application.
One of the main advantage of SWT is that it uses OS resources to resemble system applications. Using themes would contradict this approach.
If you are however using Eclipse RCP 4, look at #Ran's answer.
The org.eclipse.e4.ui.css.swt.theme extension point supports the creation of extensions for themes. This extension defines an ID for the style and a pointer to the CSS file.
You can also define the default theme via the cssTheme property in your org.eclipse.core.runtime.products extension. This can also be used to define a fixed styling.
To switch the styling you use the IThemeEngine.
package com.example.e4.rcp.todo.handlers;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.css.swt.theme.IThemeEngine;
public class ThemeSwitchHandler {
// Remember the state
static boolean defaulttheme= true;
#Execute
public void switchTheme(IThemeEngine engine) {
System.out.println("ThemeSwitchHandler called");
// The last argument controls
// whether the change should be persisted and
// restored on restart
if (!defaulttheme) {
engine.setTheme("com.vogella.e4.todo.defaulttheme", true);
} else {
engine.setTheme("com.vogella.e4.todo.redtheme", true);
}
defaulttheme= !defaulttheme;
}
}

How to disable DatePicker in GWT?

As You know com.google.gwt.user.datepicker.client.DatePicker haven't method setEnabled(boolean). I have DatePicker with ValueChangeHandler and all what I need is disable datepicker (code in onValueChange shouldn't work).
Of course I can do:
boolean disable;
datePicker.addValueChangeHandler(new ValueChangeHandler() {
#Override
public void onValueChange(ValueChangeEvent<Date> event) {
if(!disable) {
// my code here
}
}
});
but I won't do this. I want write something like that:
datePicker.setEnabled(false);
Any ideas?
GWT 2.3.0
I haven't used GWT in a while, so this is more of a pointer than an answer, but I wanted to include several links so used the answer box ;).
DatePicker is a Composite, so I don't think you can't enable/disable it directly. But you can add a preview handler to disable events, or throw a panel over it (and grey it out, for instance). See this answer for info on that: Disable user interaction in a GWT container?
As a general note, everything that extends from FocusWidget is enable/disable-able, but composites are collections of other widgets so they work differently.

DJ JWebBrowser: how to show but disable Address and Button bars?

I am using chrriis.dj.nativeswing.swtimpl.components.JWebBrowser in my swing application to open web page.
The page is going to show "Facebook Authentication" page and I want to prevent user from inputting some other URL other than I specify and also Forward and Back buttons should be visible but not has no affect.
So following functions are applicable for my goal
setButtonBarVisible(false);
setLocationBarVisible(false);
Once user completes the authentication I will handle the locationChanged event.
#Override
public void locationChanged(WebBrowserNavigationEvent arg0) {
System.out.println("locationChanged!");
....
}
}
I think what you want is a custom decorator. Check the demo application, under "JWebBrowser > Custom Decorator".
In your case, you could create a new decorator class, as an adapted copy of DefaultWebBrowserDecorator or a subclass with appropriate override.
You would also have to decide if this decorator is to be used only by one instance of the JWebBrowser or all instances (like child popups, etc.)

Categories

Resources