I'm using the #page rule to set specific options for pages.
I just found out that you can also define different properties for different pages by naming them.
That would be quite useful, but it doesn't seem to work.
Although I can see that iText correctly interprets my named page and stores the name (I can tell, by monitoring CssPageSelectorParser and CssPageTypeSelectorItem), it seems to ignore the page property though, that is used to select which page to use.
Something like this should work, but it doesn't.
#page narrow {
size: 9cm 18cm;
}
#page rotated {
size: landscape;
}
div {
page: narrow;
}
table {
page: rotated;
}
Is there any way of getting this to work or does this feature simply not work?
Cheers,
--Zuzu_Typ--
I'm trying to add an AcroField checkbox to a PDF that's being generated by iText7 pdfHTML. This is not working by default, I saw someone suggest using a custom tag worker but as much as I tried I couldn't get it to work. Does anyone have any idea how to implement this? Or an example?
I've created a very simple example to show you how one can create a custom tag worker and add an acrofield to a document while html to pdf processing.
Look at the next snippet:
class CustomTagWorkerFactory extends DefaultTagWorkerFactory {
#Override
public ITagWorker getCustomTagWorker(IElementNode tag, ProcessorContext context) {
if (tag.name().equals("input")) {
if (AttributeConstants.CHECKBOX.equals(tag.getAttribute(AttributeConstants.TYPE))) {
return new AcroInputTagWorker(tag, context);
}
}
return null;
}
Here I've introduced a custom tag worker factory which will create default tagworkers for all tags except for the one I've specified (<input type="checkbox">).
Now let's add an acrofield to the document on <input type="checkbox"> processing:
class AcroInputTagWorker extends InputTagWorker {
public AcroInputTagWorker(IElementNode element, ProcessorContext context) {
super(element, context);
PdfAcroForm.getAcroForm(context.getPdfDocument(), true)
.addField(PdfFormField.createCheckBox(context.getPdfDocument(), new Rectangle(100, 700, 30, 30), "checkbox", "Off"));
}
That's basically it. The resultant pdf for a very simple html file (basically, just one line: <input type="checkbox">) looks as this:
Now let's briefly discuss what can be improved:
1) you may want to check whether CHECKED attribute is set and consider it while setting the acrofield's value (in the example above I've just set it as "Off")
2) you need to create different acrofield's name values (I've just used "checkbox")
3) you may want to render the acrofield not at a certain position, predefined before html to pdf processing. You may want to let iText define its position dynamically depending on where the input tag is placed.
In that case the solution would be more difficult. You will need to create your own CheckBox element (probably extended from aParagraph) and a renderer for it (probably extended from a ParagraphRender). Then you will need to override its layout method (perhaps just call super.layout() to get the coordinates of the paragraph and only then add the acrofield to the document). That's not easy, but it's certainly worth a try! And if you're not successful, you can always ask another SO question :)
I want to write an eclipse plugin for my computer science lecturer. It's a custom editor with an xml based file format.
I've implemented syntax highlighting and other stuff. But I stuck when it comes to the usage of annotations/marker to show invalid content.
This is how it looks like, if the content is valid:
image of valid conent http://image-upload.de/image/aPcsaa/6c799a671c.png
This is how it looks like, if the content is invalid:
image of invalid conent http://image-upload.de/image/4TdooQ/04d662f397.png
As you can see, invalid attributes will get marked, but the problem is, the whole formatting seems to be lost between these annotations.
I use org.eclipse.jface.text.reconciler.Reconciler for delayed parsing of the content to create the document model. The model is used to format the text and display annotations. All this happens in the void void process(DirtyRegion dirtyRegion) method of the Reconciler.
For text formatting I use <ITextViewer>.changeTextPresentation(textAttributes, false) and for annotation handling I use
IAnnotationModel annotationModel = <ISourceViewer>.getAnnotationModel();
IAnnotationModelExtension annotationModelExtension = (IAnnotationModelExtension) annotationModel;
annotationModelExtension.replaceAnnotations(oldAnnotations, newAnnotations);
Since the Reconciler does not use the swt thread I have to use this construct to avoid exceptions:
<ITextViewer>.getTextWidget().getDisplay().asyncExec(new Runnable() {
#Override
public void run() {
<ITextViewer>.changeTextPresentation(textAttributes, false);
updateAnnotations(nodes);
}
});
By the way ITextViewer and ISourceViewer are meant as the same viewer object.
As annotation type I've testet: org.eclipse.ui.workbench.texteditor.spelling and some others, also custom types, but all with the same result.
I'm not quite sure, what I do wrong, could it be because it is all in a single call?
I hope someone can help me with this problem.
Thank you in advance.
I'm using SmartGWT 2.5 with Java & Mozilla FF 3.6.x.
I want to open pickList of ComboboxItem or SelectItem manually that means programatically. Is it possible? It's OK if I need to use JavaScript to achieve this. Any hint or solution is appreciated.
I finally got the answer. Posting it here might be useful to others. I've used
comboxItem.showPicker();
to achieve manual opening of picklist of ComboboxItem.
In SmartGWT 2.4 (I didn't check newer versions), the showPicker() method of SelectItem does only show an empty div, not the pick list of the select item. (It does work for the ComboBoxItem, as mentioned by RAS' answer).
Some digging into the underlying SmartClient code showed that on the JavaScript side, there is a showPickList() method which is called when the icon is clicked (or on some other events), but this is not exposed by the Java class.
So I used a piece of JSNI (modified from the source code of SelectItem.showPicker) to call this method:
public static native void showPickList(SelectItem item) /*-{
var jsItem = item.#com.smartgwt.client.core.DataClass::getJsObj()();
if(jsItem.showPickList) {
jsItem.showPickList();
}
}-*/
Calling showPickList(item) for any such pick list now opens the picker.
What's the best way to externalize large quantities of HTML in a GWT app? We have a rather complicated GWT app of about 30 "pages"; each page has a sort of guide at the bottom that is several paragraphs of HTML markup. I'd like to externalize the HTML so that it can remain as "unescaped" as possible.
I know and understand how to use property files in GWT; that's certainly better than embedding the content in Java classes, but still kind of ugly for HTML (you need to backslashify everything, as well as escape quotes, etc.)
Normally this is the kind of thing you would put in a JSP, but I don't see any equivalent to that in GWT. I'm considering just writing a widget that will simply fetch the content from html files on the server and then add the text to an HTML widget. But it seems there ought to be a simpler way.
I've used ClientBundle in a similar setting. I've created a package my.resources and put my HTML document and the following class there:
package my.resources;
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.TextResource;
public interface MyHtmlResources extends ClientBundle {
public static final MyHtmlResources INSTANCE = GWT.create(MyHtmlResources.class);
#Source("intro.html")
public TextResource getIntroHtml();
}
Then I get the content of that file by calling the following from my GWT client code:
HTML htmlPanel = new HTML();
String html = MyHtmlResources.INSTANCE.getIntroHtml().getText();
htmlPanel.setHTML(html);
See http://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.html for further information.
You can use some templating mechanism. Try FreeMarker or Velocity templates. You'll be having your HTML in files that will be retrieved by templating libraries. These files can be named with proper extensions, e.g. .html, .css, .js obsearvable on their own.
I'd say you load the external html through a Frame.
Frame frame = new Frame();
frame.setUrl(GWT.getModuleBase() + getCurrentPageHelp());
add(frame);
You can arrange some convention or lookup for the getCurrentPageHelp() to return the appropriate path (eg: /manuals/myPage/help.html)
Here's an example of frame in action.
In GWT 2.0, you can do this using the UiBinder.
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'>
<div>
Hello, <span ui:field='nameSpan’/>, this is just good ‘ol HTML.
</div>
</ui:UiBinder>
These files are kept separate from your Java code and can be edited as HTML. They are also provide integration with GWT widgets, so that you can easily access elements within the HTML from your GWT code.
GWT 2.0, when released, should have a ClientBundle, which probably tackles this need.
You could try implementing a Generator to load external HTML from a file at compile time and build a class that emits it. There doesn't seem to be too much help online for creating generators but here's a post to the GWT group that might get you started: GWT group on groups.google.com.
I was doing similar research and, so far, I see that the best way to approach this problem is via the DeclarativeUI or UriBind. Unfortunately it still in incubator, so we need to work around the problem.
I solve it in couple of different ways:
Active overlay, i.e.: you create your standard HTML/CSS and inject the GET code via <script> tag. Everywhere you need to access an element from GWT code you write something like this:
RootPanel.get("element-name").setVisible(false);
You write your code 100% GWT and then, if a big HTML chunk is needed, you bring it to the client either via IFRAME or via AJAX and then inject it via HTML panel like this:
String html = "<div id='one' "
+ "style='border:3px dotted blue;'>"
+ "</div><div id='two' "
+ "style='border:3px dotted green;'"
+ "></div>";
HTMLPanel panel = new HTMLPanel(html);
panel.setSize("200px", "120px");
panel.addStyleName("demo-panel");
panel.add(new Button("Do Nothing"), "one");
panel.add(new TextBox(), "two");
RootPanel.get("demo").add(panel);
Why not to use good-old IFRAME? Just create an iFrame where you wish to put a hint and change its location when GWT 'page' changes.
Advantages:
Hits are stored in separate maintainable HTML files of any structure
AJAX-style loading with no coding at all on server side
If needed, application could still interact with loaded info
Disadvantages:
Each hint file should have link to shared CSS for common look-and-feel
Hard to internationalize
To make this approach a bit better, you might handle loading errors and redirect to default language/topic on 404 errors. So, search priority will be like that:
Current topic for current language
Current topic for default language
Default topic for current language
Default error page
I think it's quite easy to create such GWT component to incorporate iFrame interactions
The GWT Portlets framework (http://code.google.com/p/gwtportlets/) includes a WebAppContentPortlet. This serves up any content from your web app (static HTML, JSPs etc.). You can put it on a page with additional functionality in other Portlets and everything is fetched with a single async call when the page loads.
Have a look at the source for WebAppContentPortlet and WebAppContentDataProvider to see how it is done or try using the framework itself. Here are the relevant bits of source:
WebAppContentPortlet (client side)
((HasHTML)getWidget()).setHTML(html == null ? "<i>Web App Content</i>" : html);
WebAppContentDataProvider (server side):
HttpServletRequest servletRequest = req.getServletRequest();
String path = f.path.startsWith("/") ? f.path : "/" + f.path;
RequestDispatcher rd = servletRequest.getRequestDispatcher(path);
BufferedResponse res = new BufferedResponse(req.getServletResponse());
try {
rd.include(servletRequest, res);
res.getWriter().flush();
f.html = new String(res.toByteArray(), res.getCharacterEncoding());
} catch (Exception e) {
log.error("Error including '" + path + "': " + e, e);
f.html = "Error including '" + path +
"'<br>(see server log for details)";
}
You can use servlets with jsps for the html parts of the page and still include the javascript needed to run the gwt app on the page.
I'm not sure I understand your question, but I'm going to assume you've factored out this common summary into it's own widget. If so, the problem is that you don't like the ugly way of embedding HTML into the Java code.
GWT 2.0 has UiBinder, which allows you to define the GUI in raw HTMLish template, and you can inject values into the template from the Java world. Read through the dev guide and it gives a pretty good outline.
Take a look at
http://code.google.com/intl/es-ES/webtoolkit/doc/latest/DevGuideClientBundle.html
You can try GWT App with html templates generated and binded on run-time, no compiling-time.
Not knowing GWT, but can't you define and anchor div tag in your app html then perform a get against the HTML files that you need, and append to the div? How different would this be from a micro-template?
UPDATE:
I just found this nice jQuery plugin in an answer to another StackOverflow question.