Why isn't the page data tab showing in the Designer? - tooltwist

I'm editing a page in the ToolTwist Designer, and I have all the normal tabs shown - edit page, navpoint, test page, source, etc, but the "Page Data" tab is not showing. How can I make the tab show, so I can enter page data for my page?

The page data tab only appears if there is a widget on your page that requires page data. You also need to editing the navpoint, rather than the page, because the page data belongs to the navpoint, and a single page definition might be shared by many navpoints. In other words, the page data allows widgets to appear different at various locations (navpoints) within the website.
If you are developing a widget that you wish to have use page data, you need to do the following:
In the Widget Controller class, implement the "UsesPageData" interface. This tells the Designer that the page data tab needs to be displayed when you click on a navpoint that references a page that included this widget, and on the tab it creates a section where the XML for this widget can be entered, specific to that particular navpoint.
public class CarouselTab extends WbdWidgetController implements UsesPageData
To give the user an indication of what XML the widget expects, you need to implement a method that returns template XML code. For example:
public XData getInitialPageData(WbdWidget instance)
{
StringBuffer xml = new StringBuffer();
xml.append("\n");
xml.append("\n");
xml.append(" id01\n");
xml.append(" [Label 01]\n");
xml.append(" [Add your widget here 01]\n");
xml.append("\n");
xml.append("\n");
xml.append(" id02\n");
xml.append(" [Label 02]\n");
xml.append(" [Add your widget here 02]\n");
xml.append("\n");
xml.append("");
return new XData(xml);
}
Define a property that defines a name to be displayed above where you enter the XML on the page data tab:
protected void init(WbdWidget instance) throws WbdException
{
instance.defineProperty(new WbdStringProperty("pageDataSection", null, "PageDataSection", ""));
...
}
Use the page data when you are generating the page:
#Override
public void renderForJSP(WbdGenerator generator, WbdWidget instance, UimHelper ud, WbdRenderHelper rh) throws WbdException
{
...
Xpc xpc = ud.getXpc();
xpc.start("tooltwist.wbd.getPagedata", "select");
xpc.attrib("navpointId", WbdSession.getNavpointId(ud.getCredentials()));
xpc.attrib("pageDataSection", pageDataSection);
XData pagedata = xpc.run();
// Do something with the page data
...
}

Related

Display string in xml format in browser either using view or controller

I have a string in my model.The string is actually XML content. I have a link on my page, when clicked it opens a new tab and displays the text as XML.
The result should be the same as when I right click on an xml file and open with Internet Explorer. The difference is that this is no file, its text that I need to display as XML in a new tab.
Anyone have an idea how to achieve this without creating a file and without giving a path to a file.
You could have a controller that will serve this XML and set the proper content type header:
public class MyXMLController: Controller
{
public ActionResult Index()
{
MyModel model = GetModelFromSomewhere(...);
return Content(model.StringPropertyContainingXML, "text/xml");
}
}
now all that's left is to write an anchor link pointing to /myxml/index:
#Html.ActionLink("Click to open XML", "index", "myxml", null, new { _target = "blank" })

How to refresh multipage editor's page?

I have created a plugin,Where I have a multi page editor with two pages.
Page1- Source Code Editor.
Page2- For Manipulation.
My problem is if there is any compilation error in the code the second page must display another content like "Error".
Otherwise it will show my manipulation form.
For that I need to fill the composite with diffrent content each time the pageChanges. But it doesnt work.
How can achieve the scenario. While clicking the second page the content must be recreated or refreshed for the new content
public void createPage1(){
intializePage1Composite();
updatePage1Content(this.page1Compostie);
int index = addPage(this.page1Compostie);
setPageText(index, "Service Behaviors ");
}
public void updatePage1Content(Composite composite){
boolean error=getPageStatus();
if(!error){
/**
*Content of Normal Page
*/
}
/**
* setting the page to error
*/
else{
/**
*Content of Error Page
*/
}
}
protected void pageChange(int newPageIndex) {
super.pageChange(newPageIndex);
if (newPageIndex == 1) {
updatePage1Content(this.page1Compostie);
this.page1Compostie.redraw();
}
}
Any advice ?
To replace all the children of a composite you first call dispose() on each existing child control. Next add the new controls. Finally call
composite.layout(true, true);
on the parent composite to force it to update the layout.
If you just want to switch between two sets of controls you can use the GridData.exclude flag and Control.setVisible to include/exclude controls. Again call layout at the end.

How to submit a form in Geb (WebDriver) that has no submit button

I'm building up a test in Geb (WebDriver) that has the need to work with a form that has no submit button. From the user's perspective, it is as simple to use as typing in the search term and hitting the enter key on their keyboard.
Using Geb in a purely script form I can get around this by appending the special key code to the text being typed in, as seen in the following:
import org.openqa.selenium.Keys
$('input[id=myInputField]') << "michael"+Keys.ENTER
That works fine. But if I want to use Geb's recommended Page Object pattern (http://www.gebish.org/manual/0.7.1/pages.html#the_page_object_pattern), I don't see what I should do. What do I define in the content section of my EmployeeSearchPage object to duplicate the missing searchButton and its "to" object reference that tells Geb how to handle the resulting page?
class EmployeeSearchPage extends Page {
static url = "http://localhost:8888/directory/"
static at = { title == "Employee Directory" }
static content = {
searchField { $("input[id=myInputField]") }
// THE FOLLOWING BUTTON DOESN'T EXIST IN MY CASE
searchButton(to: EmployeeListPage) { $("input[value='SUBMIT']") }
}
}
I realize that I could add a submit button to the form that I could for the test and use CSS to position it out of the user's view, but why should I have to adapt the app to the test? Things should work the other way around.
I've been evaluating a lot of web testing frameworks and find that this type of form presents a problem for many of them - at least as far as their documentation is concerned.
Any ideas? Thanks!
You don't need to use js integration to achieve what you want.
You can also define methods on your page class, not only content. You could implement a submit method that would do what you are looking for in the following way:
class EmployeeSearchPage extends Page {
static url = "http://localhost:8888/directory/"
static at = { title == "Employee Directory" }
static content = {
searchField { $("input[id=myInputField]")
}
void submitForm() {
searchField << Keys.ENTER
browser.page EmployeeSearchResultsPage
}
}
and then to use it:
to EmployeeSearchPage
searchField << 'michael' // searchField = 'michael' would have the same effect
submitForm()
Geb provides support to execute JavaScript in the context of the browser, details can be found here in the Geb documentation.
You could use this to submit the form exactly like you would submit it using JavaScript in the webapp itself. For example, if you are using jQuery it would be as simple as:
js.exec('$("#myForm").submit()')

How to set an Image to top right corner of a form heading

I’m using eclipse rcp forms ,
I'm trying to set an Image using
form.setImage()
merely it sets image to the left of form text. How can i place an image towards top right corner of the form title text.
As shown in below pic(image is the default overview tab of any RCP application)
From the above pic I understand that the images/widgets are placed beside the Form text(apologies if I’m wrong).
As a workaround I tried placing a composite in the form head, but I believe that form head comes after form title level(if we consider form title as 1st row, then form head appears as 2nd row)
Composite composite = formToolkit.createComposite(form.getHead(), SWT.NONE);
form.setHeadClient(composite);
formToolkit.paintBordersFor(composite);
composite.setLayout(new GridLayout(2, false));
In this fashion i attempted to place components to the composite but anyways I don't get the desired style as shown in the image.
How to place an image to the top right of the form title
You cannot set images to the right corner. What you see in the attached image is a toolbar with some IContributionItem's
To create something you have to override org.eclipse.ui.forms.editor.SharedHeaderFormEditor.createHeaderContents(IManagedForm) with something like the following:
#Override
protected void createHeaderContents(final IManagedForm headerForm) {
headerForm.getForm().setText("EditorTitle");
headerForm.getForm().setImage(myLeftImage);
headerForm.getToolkit().decorateFormHeading(
headerForm2.getForm().getForm());
Action action = new Action("Do something") {
#Override
public ImageDescriptor getImageDescriptor() {
return imageDescriptorOfRightImage;
}
};
headerForm.getForm().getToolBarManager().add(action);
headerForm.getForm().getToolBarManager().update(true);
}

Getting current Tab/Document in DockPanel Suite

I'm using the DockPanel Suite by Weifen Luo in a little project (webbrowser) and have managed to be able to create tabs and navigate the webbrowser element inside each tab.
But how am I able to change the tabs title/name when the page is navigating to another site?
Basically I just need to get into the current tabs form.
You can get the current tab by using DockPanel's ActiveContent method. For example:
Form myForm = myDockPanel.ActiveContent();
myForm.TabText = "Stack Overflow";
DockPanel.ActiveDocument and DockPanel.ActivePane can also be useful.
After having worked on this a few weeks (not 'till now though :P) I have to say, that this is currently not possible.
You can manage your own (assuming your Document Form is a specific class) by managing:
'FormClosing' and 'Activated' events
'Activated' set your own "active" document to 'this'.
'FormClosing' set your own "active" document to null.
FormClosing is just to catch the case where you are closing the last document. Activated is what manages everything else, like when a new document gets created and is made the active window, etc.
You can use a static global to manage focus. Then access it from anywhere else:
public partial class MyDocument : DockContent
{
public static MyDocument ActiveDocument { get; private set; }
I needed the ability to check which document was active, and set that document to active again after changing some UI elements that automatically reset the active tab, so I used some pieces from here and the DockPanel FAQ, and did some digging to figure out the answer to this problem:
public string GetActive()
{ //Verify if forms that dock in main window are already open
foreach (DockContent form in dockMain.Contents)
{
if (form.DockHandler.Pane.ActiveContent.DockHandler.Form.Name.ToString() == form.Name.ToString())
{
string formName = form.Name.ToString();
return formName;
}
}
return null;
}
And then in some other method you will call:
string activeForm = GetActive();