I have a working web application developed with GWT. Now that it has to resize on a tablet or smaller screens I thought of using GWT Bootstrap. But the existing application has only one project.html and project.css file under war folder. Currently no UI binders are used. There are four screens displaying different charts created by d3js.
My Question is it still possible to use gwt bootstrap for resizing? Or what about only Bootstrap and use the css file without any UI binders?
Which approach is better ? As im confused and have spent couple of hours searching and reading.
If you plan to interact in your GWT app with bootstrap components (i.e. NavBar, Caoursel, etc) then I would go with gwt-bootstrap because you don't have to use JSNI and you get some type safety.
If you don't need to interact those components or you use mostly pure HTML in your GWT app you can also use plain bootstrap and add the corresponding classes.
Edit code example:
UiBinder:
<b:NavPills>
<b:AnchorListItem active="true">Item 1</b:AnchorListItem>
<b:AnchorListItem>Item 2</b:AnchorListItem>
<b:AnchorListItem>Item 3</b:AnchorListItem>
<b:AnchorListItem enabled="false">Item 4</b:AnchorListItem>
<b:AnchorListItem pull="RIGHT">Pulled right</b:AnchorListItem>
</b:NavPills>
Code:
NavPills pills = new NavPills();
AnchorListItem item1 = new AnchorListItem("Item 1");
item1.setActive(true);
pills.add(item1);
pills.add(new AnchorListItem("Item 2");
pills.add(new AnchorListItem("Item 3");
...
Related
As the title says I'm wondering whether Eclipse RCP 4 provides any built in cut/copy/paste handlers which can be linked to the org.eclipse.ui.edit.cut, org.eclipse.ui.edit.copy and org.eclipse.ui.edit.paste commands?
I appreciate that that a custom handler may be needed for some SWT widgets or more complex use cases with cut/copy/paste operations, but I can't help but feel I'm trying to re-invent the wheel to copy some text from one component and paste in into another.
If there aren't any built in cut/copy/paste handlers, are there any well documented examples of how to do this? I understand how to use the clipboard.getContents and clipboard.setContents methods, but have found this starts to become non-trivial when trying to find out what text was selected when the copy command is invoked and which component has focus and whether its read only when the paste command is invoked.
I've looked at this StackOverflow question but it doesn't explain whether there any built in handlers or offer any guidance on writing my own handlers.
For a 3.x compatibilty mode Eclipse 4 application these commands are defined as:
<command
name="%command.cut.name"
description="%command.cut.description"
categoryId="org.eclipse.ui.category.edit"
id="org.eclipse.ui.edit.cut"
defaultHandler="org.eclipse.ui.internal.handlers.WidgetMethodHandler:cut" />
<command
name="%command.copy.name"
description="%command.copy.description"
categoryId="org.eclipse.ui.category.edit"
id="org.eclipse.ui.edit.copy"
defaultHandler="org.eclipse.ui.internal.handlers.WidgetMethodHandler:copy" />
<command
name="%command.paste.name"
description="%command.paste.description"
categoryId="org.eclipse.ui.category.edit"
id="org.eclipse.ui.edit.paste"
defaultHandler="org.eclipse.ui.internal.handlers.WidgetMethodHandler:paste" />
So they all use org.eclipse.ui.internal.handlers.WidgetMethodHandler as the default handler which is used when no other handler is active.
This handler uses reflection to look for the method name cut, copy or paste in the currently focussed SWT Widget and calls that method if it is found.
For a pure e4 application there is no default definition of cut/copy/paste commands and the WidgetMethodHandler is not available. SWT controls will continue to support cut/copy/paste but there is no other support.
You can put text in the clipboard using something like:
Clipboard clipboard = new Clipboard(Display.getCurrent());
clipboard.setContents(new Object [] {"Text for clipboard"},
new Transfer [] {TextTransfer.getInstance()});
clipboard.dispose()
and get text from the clipboard with:
Clipboard clipboard = new Clipboard(Display.getCurrent());
String text = (String)clipboard.getContents(TextTransfer.getInstance());
clipboard.dispose()
I have been asked by my friend to make an application for Chrome and it requires me to have context-sensitive menus as below:
I have never really made anything for Chrome before and I have a few questions regarding it:
I will have to develop a plug-in, right ?
If so, is there a specific set of rules I have to follow ?
I know I can use GWT to compile Java to JavaScript
3. This context sensitive menu is the same as JPopupMenu ?
The application I want to develop is simple:
Copy some text,
right-click, click on the context sensitive menu
apply simple Caesar's cipher to the text
open a new JFrame with JtextArea in it to display the encrypted text.
What you're creating is called an "extension", not a "plug-in". A browser extension is written using HTML, CSS and Javascript, and got access to APIs for direct interaction with the browser.
Plug-ins, on the other hand, are compiled binaries such as Flash and Java.
Drop the idea of using GWT for Chrome extensions. It makes development of the extension harder, not easier (open issue).
Especially because you'll find plenty of vanilla JavaScript examples and tutorials in the documentation and Stack Overflow.
You just have to know the relevant APIs:
Copy some text,
right-click, click on the context sensitive menu
Use chrome.contextMenus. There's no need to copy, the selected text is available in the callback (examples).
apply simple Caesar's cipher to the text
Create a JavaScript function to achieve this.
open a new JFrame with JtextArea in it to display the encrypted text.
Create a new window using chrome.windows.create. You could include an extra HTML page in your extension, and use the message passing APIs to populate the text field, but since you appear to be a complete newbie, I show a simple copy-paste method to create and populate this window:
function displayText(title, text) {
var escapeHTML = function(s) { return (s+'').replace(/</g, '<'); };
var style = '*{width:100%;height:100%;box-sizing:border-box}';
style += 'html,body{margin:0;padding:0;}';
style += 'textarea{display:block;}';
var html = '<!DOCTYPE html>';
html += '<html><head><title>';
html += escapeHTML(title);
html += '</title>';
html += '<style>' + style + '</style>';
html += '</head><body><textarea>';
html += escapeHTML(text);
html += '</body></html>'
var url = 'data:text/html,' + encodeURIComponent(html);
chrome.windows.create({
url: url,
focused: true
});
}
Don't forget to read Getting started to learn more about the extension's infrastructure.
Check out Google Chrome Extensions Chrome Extensions
The Getting Started will help you Getting Started
You will find a section on how to use Context Menus.
I am using GXT for UI development. I have used HTML5 for Dragging file from Desktop to my application and upload it. But now i am having reverse requirement. I want to drag files from browser to desktop which will download the file to desktop.
I know that is possible in Chrome only. And had checked the below demo:
http://www.thecssninja.com/javascript/gmail-dragout
I had tried to implement the above code in my GXT application, but the issue is that i am using Editable Grid which is supporting DnD to TreePanel. Now when i drag from grid to Desktop i think its not capturing the browser event (may be i am wrong here).
Any idea, how it should be done?
Thanks.
Below is the small piece of code which i call after the Data had been inserted in Grid. All records are having the CSS class name as ".icon". The problem is that when i start to drag, the "dragstart" is not being called. Any suggestion?
NOTE: This code is working when i create Buttons, Labels, etc and making them draggable=true with other required parameters.
public static native void test(String id)/*-{
var files = $doc.querySelectorAll('.icon');
for (var i = 0, file; file = files[i]; ++i) {
file.addEventListener("dragstart",function(evt){
$wnd.alert("Drag Event started.. ");
evt.dataTransfer.setData("DownloadURL",this.dataset.downloadurl);
},false);
}
}-*/;
I used this, and it successully performs, no you should check some other place in your code.
I want to design new Git client with a clean GUI.
Is it possible to use the power of HTML, CSS and JavaScript in a java application?
I would like to use Java + JGit for models, Java for controllers and HTML + CSS + JavaScript for views.
I don't want a client-server model. I would like to integrate Java and HTML nicely. A DOM event would fire events directly to a Java controller. This way it would be possible to create rich offline application.
You can embed web browser component into your Java Swing/JavaFX Desktop application that displays GUI built with HTML5+CSS+JavaScript. You can see an article that describes how to do this at https://jxbrowser-support.teamdev.com/docs/tutorials/cross-desktop-apps.html
One of the Java Swing/JavaFX libraries that allows embedding Chromium into Java applications is JxBrowser. Using JxBrowser API you can load any web page and work with its DOM and JavaScript. You can even call Java methods from JavaScript code and vice versa. For example:
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.JSFunctionCallback;
import com.teamdev.jxbrowser.chromium.JSObject;
import com.teamdev.jxbrowser.chromium.JSValue;
import com.teamdev.jxbrowser.chromium.events.FinishLoadingEvent;
import com.teamdev.jxbrowser.chromium.events.LoadAdapter;
public class JavaScriptJavaSample {
public static void main(String[] args) {
Browser browser = new Browser();
browser.addLoadListener(new LoadAdapter() {
#Override
public void onFinishLoadingFrame(FinishLoadingEvent event) {
if (event.isMainFrame()) {
Browser browser = event.getBrowser();
JSObject window = (JSObject)
browser.executeJavaScriptAndReturnValue("window");
window.setProperty("MyFunction", new JSFunctionCallback() {
#Override
public Object invoke(Object... args) {
for (Object arg : args) {
System.out.println("arg = " + arg);
}
return "Hello!";
}
});
JSValue returnValue = browser.executeJavaScriptAndReturnValue(
"MyFunction('Hello JxBrowser!', 1, 2, 3, true);");
System.out.println("return value = " + returnValue);
}
}
});
browser.loadURL("about:blank");
}
}
It's not really feasible. Rich clients in Java are done using Swing or SWT.
If you want to use HTML/CSS for your user interface, you need to use the server/client model. It can be as simple as creating a local server and launching a browser that connects to it, but it would still be that model.
If you absolutely need to have HTML/CSS as your UI framework and can't go to a server/client model, your best bet is probably looking at something like Google Native Client, but that uses C/C++ bindings on the backend. I haven't used Native Client so I can't personally give much more information on that front.
Edit to add:
One option is to embed a native browser into your Swing app using something like: http://djproject.sourceforge.net/ns/
There are some pure Java HTML renderers, however, they most likely won't be fully HTML5/CSS3 compliant, let alone possibly have Javascript bugs as well.
See here for some of those options: Pure Java HTML viewer/renderer for use in a Scrollable pane
Like #Reverand Gonzo says, you will need some form of server/client. But you could easily embed a Jetty server into a Java app and then use GWT for your client code.
You can bring in the power of HTML,CSS,JavaScript into your Swing app using JFXPanel to embed JavaFX WebView. Have a look at the SimpleSwingBrowser demo in this link:https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/swing-fx-interoperability.htm
WebView allows to call JavaScript functions from Java and vice versa. It is also a nice way to enhance your legacy Java app with web technologies.
JavaFX 2.2 brought this functionality to providing a user interface component (GUI) that has web view and full browsing functionality.
For more details, see Adding HTML Content to JavaFX Applications.
Use Angular.js with HTML and rest of the things as same in Java, just use classes for business logic, no need to write code for awt/swing. Angular with spring boot are rapid development in Java for webapp with less code in Java without swing use to create best webapp .
I just started creating a SWT/JFace application using the (now free) WindowBuilder from Google (previously instantiations).
I find the Data binding part difficult although it -should- make it easier for me.
For instance, I cannot bind the enabling-property of a button to a (myself defined) boolean function.
Are there any resources (demos, text, tutorials, examples) about using the WindowBuilder GUI and/or the data binding principle?
The information found on the google page or the instantiations page did not help me enough.
For what it's worth:
bindingContext.bindValue(
new ComputedValue() {
public Object calculate() {
// calculate the enablement using the value of other, previously
// created observables.
}
},
WidgetProperties.enabled().observe(theButton)
);
The Eclipse newsgroups are a great place to ask these questions. Try the eclipse.platform.jface newsgroup.