Eclipse SWT - WizardPage widgets validation - eclipse

What is the best way to validate Text, Combo and any other SWT widget included in Eclipse Wizard? Recently, I got into a project in which there are many different wizards. I tried to add FocusListeners, ModifyListeners etc. however the size of code and it's complexity was not what I expected.
Let's say there are two Text elements in WizardPage. They both cannot be empty and should contain only small letters. How to write a validator which checks if fields are empty or contain unexpected characters and display an error message in case something went wrong.
The way it has to be done must be sophisticated, elegant and useful.

I would recommend using JFace databindings (I use them myself). You will be able to add validators to particular binding and automatically show validation errors/warnings in the wizard.

In addition to Eugene I can recommend following site for a nice JFace databinding example in context with wizard pages.
http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet014WizardDialog.java?view=markup
But don't miss to insert those plugins into your plugin.xml
org.eclipse.core.databinding
org.eclipse.core.databinding.beans
org.eclipse.jface.databinding
org.eclipse.core.databinding.property

Related

How to add custom layout to page fragment in Liferay 7.3

I have followed this tutorial https://help.liferay.com/hc/en-us/articles/360018167031-Creating-Layout-Templates to create custom layout for Liferay 7.3. After deploy the layout to the Liferay manually using app manager, I'm not able to find the custom layout in Fragment and Widget option.
When I check in Global Menu > Control Menu > Components > Layout Templates. I'm able to see my custom layout.
Did I missed anything or is there any other way to add custom layout to Fragment and Widget options?
Thanks
You missed one crucial info: "Layout Templates" are only applicable to pages of the type "Widget Page" (the default and pretty much only page layouting method in Liferay 6 and earlier). "Page Fragments", on the other hand, are only applicable to pages of type "Content Page" (which came up somewhere between 7.0 and 7.3). You set the type of a page at the moment you create them, by selecting one of the corresponding page templates.
So, if you want to create a certain row/column layout as a template for your "Content Page", you may want to look into the page fragment type "section". Basically, you'll be creating a Page Fragment that incorporates some <lfr-drop-zone id="invent-your-own-id"></lfr-drop-zone> tags in its HTML. Documentation on dropzones is very sparse at the moment (best source I found is Liferay's issue tracker plus experimenting yourself), but as this tag currently does not allow more attributes than id, you can simply experiment with it.
(Side notes: Due to some arcana in some standard documents, you cannot use the self-closing form of the <lfr-...> tags, so <lfr-drop-zone id="abc" /> will fail silently. Also, remember that the HTML part of a page fragment actually will be interpreted as an FTL template using Freemarkers alternative syntax before the <lfr-...> tags are interpreted., which gives you the option of placing a configurable amount of dropzones using a loop.)
But: take a moment to check whether you really need a custom "dropzone layout", as Liferay already provides you with a configurable "row section" in the content page editor; and anything more complex will give you headaches when making it responsive.
We are going through this exact same situation. Up until 7.1, we used Layout Templates on Widget Pages to enforce a consistent design over our Org's Intranet, while still having per-Department Authors (see Herding Cats).
New requirements, including the Users overall desire to have more control over page layout and simplified editing, as well as personalization (using Segments), are forcing us to implement the features of Widget Pages (and Layout Templates) in Content Pages. So far, Page Fragment Sections (as #orithena suggested) are giving us a path forward.
Now, we're developing for 7.2. 7.3 seems to be taking this concept even further, with the afformentioned drop zones, nested row layouts, and Master Pages.

How to find resources with label decorator's value in eclipse

I am working on an eclipse plugin in which I have used decorators to decorate my resources with different text as a prefix. Now I want to search these resources with the text which I have used while decorating the resources.
What I exactly want is to extend eclipse's open resource dialogue so that I can enter the text which I have used to decorate resources to find them.
So how could I achieve this...
Many thanks..
The Open Resource dialog is not really customizable.
The dialog class is org.eclipse.ui.internal.ide.dialogs.OpenResourceDialog. This extends FilteredResourcesSelectionDialog which contains most of the label providers and the like which you would have to change. However this class is not designed to be modified and would be hard to change.
FilteredResourcesSelectionDialog in turn is derived from FilteredItemsSelectionDialog which can be extended more easily, but you would have to duplicate a lot of code from OpenResourceDialog and FilteredResourcesSelectionDialog.

Displaying an XML string with formatting and syntax highlighting in an Eclipse RCP view

I am currently stuck on what I feel like should be an easy solution, but I am not really getting anywhere with this. I am new to Eclipse RCP. I am trying to implement a view in which, all it does, is display a string, which has been formatted to XML. As in, my application does what it is meant to do, and when the user clicks Save, it saves all the info as an xml. I can get this xml as one long, unformatted string. I want a pane where the user can see (only see, not edit) the XML code that is going to be saved.
The reason I want a view is because this view is a multi-instance view, dependent on the perspective it is in. And I want it to display in XML format, with syntax highlighting. It would be nice for it to look like in an editor with line numbers and such, but with good formatting I am satisfied.
Does anyone know the best (any) way to implement this? Even some 3rd party widget is perfect for me.
Thanks!!
IIRC, the Plug-In editor example does basic syntax coloring and you can use the javax.transform packages to go from a stream to a DOM and back to a (formatted) stream.
just make your editor inherit from StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor.StructuredTextEditor)
For further details here:
FAQ How do I provide syntax coloring in an editor?
Platform Plug-in Developer Guide > Programmer's Guide > Editors

How to add JFace table to Eclipse RCP New Project Wizard

I have a Wizard with two pages: pageone extending WizardNewProjectCreationPage, and pagetwo is extending WizardPage. I want the user to be able to create the project first, and then add files to the project on the second page.
For the latter I want to use a SWT Table (?) like when you pick an interface in the Java Class Wizard in Eclipse IDE (cf. picture here). Also the "Add" button next to it.
How can I achieve this? Do I have to use Eclipse Forms API for this? Or simply add a SWT Table? I have used the Plug-In Spy but the source code given in NewClassWizardPage and NewTypeWizardPage seems to be very specific to this example and I cannot make sense of it.
I've also had a look at vogella's tutorial for JFace table, but I can't get my head around it.
Just some basic steps would be great, or maybe somebody has done this before?
I can easily understand why you're confused... there are indeed many ways to do this. You even left out Data Binding which provides you with yet another way to populate and decorate the table in question.
To sum up the usage of the different APIs:
SWT provides the basic widgets and controls. Often these have a rather irregular low-level interface - especially compared with Swing - but you need to access the SWT controls to lay them out (an exercise that can be complicated in itself). Also many of the listeners are on the controls.
JFace provides a set of viewers on top of the corresponding structured SWT controls - e.g. TableViewer on top of Table. These viewers provides a high-level interface to the functionality of the underlying control - e.g. with models, label providers, sorting, filtering and more. (The viewers can easily be compared with the Swing counterparts...)
Eclipse Forms provides a (relatively) simple way to create views, dialogs, etc that looks like web pages. Examples of this are the various PDE editors.
Data Binding provides a (somewhat complicated) way to bind controls (including Tables) to a data structure (Bean, EMF or POJO based).
So... you have to decide on whether to use the model facet of JFace and Data Binding, but the rest of the APIs are often combined in the same view or dialog.
NewClassWizardPage and NewTypeWizardPage are both particular complicated examples of wizards - don't base your own work on these!
For your particular case - as I understand it - I would use a simple JFace TableViewer to hold the list of interfaces... (I use a TableViewer rather than a ListViewer as the later cannot have an image as part of the label provider.) The "Add" and "Remove" buttons will manipulate the model of the viewer and then update the viewer. You don't need Eclipse Forms as the wizards usually don't look like web pages. And Data Binding is also an overkill here given the very, very simple data for the wizard.
Please note that the function of a wizard is only performed after all the wizard pages has been shown and the "Finish" button is pressed.

GWT "big" Forms

I completed the StockWatcher basic gwt tutorial, and read several pages of documentation but I can't find the solution for a very simple thing.
What if my stock was a "real" object, such as an invoice, with dozens of fields to be entered by hand?b
I suppose I have to write a panel with many text boxes, and on the 'OK' button click, retrieve each textbox value in a awful way:
codeTb.getText();
year.getText();
customerTb.getText();
...
Then build a POJO-DTO and send through the RPC wire.
Really, isn't there a more simple way?
I think about a concept of "Form" in Gwt. Sorry, maybe I didn't find it in the doc, yet.
GWT has what are called Editors. With Editors you can bind Widgets to a DTO and it's fields, so you don't have to do the getText or setText yourself. It's not totaly trivial to use, but you can find more details in the GWT documentation: http://code.google.com/webtoolkit/doc/latest/DevGuideUiEditors.html
What you need is a FormPanel. Take a look here http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/user/client/ui/FormPanel.html