Eclipse FormEditor button as page title - tabs

I implemented my custom FormEditor. Now I want to let user create new FormPages (a.k.a. tabs) in this editor like it is made e.g. in Chrome tabs. How to insert a "new tab" button near the titles of existing FormPages?
Thank you in advance!
UPD:
I added a FormPage with title "+" and insert new page in listener to PageChangedEvent.

You can add actions to the toolbar at the top right of a FormPage like this:
ScrolledForm form = managedForm.getForm();
IToolBarManager manager = form.getToolBarManager();
Action myAction = new Action("My Action") {
public void run() {
// TODO your action
}
};
myAction.setToolTipText("tooltip text");
myAction.setImageDescriptor(action image descriptor);
manager.add(myAction);

Related

Open an angular template reference in a new browser window

So here is the explanation of the problem I am facing. It might look very similar other already asked questions, but none of them answered my problem.
I want to open an angular template reference in a new browser window (with all the styles) and use that window to print the contents using system print dialog.
By template reference I mean a whole component or may be just a fraction of template of given component.
Please note that I do not want to do it by below methods:
Opening a new route in a new browser window. (Why? this will cause all other things like common toolbar or help open up with the component. Also a new route will be required which is undesired.)
Opening the content in a closable modal.
Ok, This is how I did it using ComponentFactoryResolver and Injector. Just inject these two dependencies in your component which wants to open other component (ReportComponent in this case) in new browser window.
The constructor looks something like this in snippet below.
constructor(
private resolver: ComponentFactoryResolver,
private injector: Injector
) {}
.
.
.
This method opens up the component in new browser window.
public openPrintableReport(): void {
// resolve and instantiate the component which you want to open in new window.
const componentFactory = this.resolver.resolveComponentFactory(ReportComponent);
let component = componentFactory.create(this.injector);
component.changeDetectorRef.detectChanges();
// define external window
this.externalWindow = window.open('', '', 'width=1000,height=1000,left=150,top=200');
// copy all the styles to external window.
document.querySelectorAll('style').forEach(htmlElement => {
this.externalWindow.document.head.appendChild(htmlElement.cloneNode(true));
});
this.externalWindow.document.title = 'Printer Friendly Report';
// attach the component to external window
this.externalWindow.document.body.appendChild(component.location.nativeElement);
}

Unable to switch to newly opened tab in chrome using selenium

I opened a new tab from a link in current page. The tab opened but the focus is not shifted to that tab, nor am I able to switch tab using the following two methods I used. I'm using Chrome.
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
BaseClass.driver.findElement(By.xpath(xpathOfLinkToPage2)).sendKeys(selectLinkOpeninNewTab);
//method one
ArrayList<String> tabs = new ArrayList<String>(BaseClass.driver.getWindowHandles());
BaseClass.driver.switchTo().window(tabs.get(1));
//method two
String selectLinkOpeninNewTab2 = Keys.chord(Keys.CONTROL,Keys.TAB);
BaseClass.driver.findElement(By.cssSelector("body")).sendKeys(selectLinkOpeninNewTab2);
// open Site 1
String site_1_Window= driver.getWindowHandle();
System.out.println(site_1_Window);
// open Site 2
Set site_Windows= driver.getWindowHandles();
System.out.println(site_Windows);
for (String site_2_Window: driver.getWindowHandles())
{
System.out.println(site_2_Window);
driver.switchTo().window(site_2_Window);
}
try using:
driver.SwitchTo().Window(driver.WindowHandles.Last());
also see this: http://www.binaryclips.com/2016/03/selenium-webdriver-in-c-switch-to-new.html and this Selenium webdriver selecting new window c#
//count and enter your tab index beside get
ArrayList<String> newTab = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(newTab.get(2));

Open primefaces tagcloud links in a new window

I'm using primefaces tagcloud. But when i clicked on the links given on the tagcloud, it opened in that same window.But on clicking the tagcloud links it should open in a new window not on the same window.
I want a new window will open when i click on the tagcloud links.
Can anyone please help me about this topics ???
JavaScript solution:
One possible approach could be JavaScript:
<p:tagCloud model="#{tagCloudBean.model}" onclick="preventDefault(event)">
<p:ajax event="select" update="msg" listener="#{tagCloudBean.onSelect}" />
</p:tagCloud>
onclick triggers a JavaScript function which prevents the link from getting opened.
function preventDefault(e) {
e.preventDefault();
}
Also, by adding an ajax event you can call a listener in your managed bean.
public void onSelect(SelectEvent event) {
TagCloudItem item = (TagCloudItem) event.getObject();
String url = item.getUrl();
String script = "window.open('" + url + "');"
RequestContext.getCurrentInstance().execute(script);
}
There you can access the url of the TagCloudItem and execute a JavaScript statement which should open a new browser window.
This possible solution is untested, but just give it a try.

find HTMLEditor cursor pointer for inserting image

as said in topic: JavaFX HTMLEditor - Insert image function
if want to insert image should add below tag to htmlText of htmlEditor
"<img src=\"" + getClass().getResource(PicName[i])) + "\" width=\"" + target.getImage().getWidth() + "\"height=\"" + target.getImage().getHeight() + "\">")
but if want to add image in cursor position how to do it?
You can achieve this in the following way
Use the ScenicView to explore the HTMLEditor
Get WebView inside HTMLEditor
Get WebEngine of that WebView
Run a JavaScript Code to Insert an image to the caret pos using WebEngine
How To Replace HTML using JS
Link to Original Post
function insertHtmlAtCursor(html) {
var range, node;
if (window.getSelection && window.getSelection().getRangeAt) {
range = window.getSelection().getRangeAt(0);
node = range.createContextualFragment(html);
range.insertNode(node);
} else if (document.selection && document.selection.createRange) {
document.selection.createRange().pasteHTML(html);
}
}
How to Execute JS Code Guide
Node webNode = htmlEditor.lookup(".web-view");
if (webNode instanceof WebView) {
WebView webView = (WebView) webNode;
WebEngine engine = webView.getEngine();
engine.executeScript("alert('helo')"); // add js code here
}
text fileds are have a linear datastructure and can have a sequential position and corresponding location in its view.
but for html view the displayed object location on screen to location in the text mapping is a bit difficult so thats why the html editor cant determine the cursor position
im working on some other workaround to insert image at given cursor position.
try to insert a dummy text as a placeholder like ###inserImage#### then replace it with the actual image tag <img src="file:\c:\testhtmleditor\sample01.jpg" />..
Let's try this piece of code
#FXML private HTMLEditor editor;
...
public void insertTextToCurrentFeatureCursorPosition(String text) {
WebView webView = (WebView) editor.lookup(".web-view");
WebPage webPage = Accessor.getPageFor(webView.getEngine());
webPage.executeCommand("insertHTML", text);
}
Where text is the HTML code which wraps the image

LinkButton not accessing EventArg

I am using c#.net.
I am trying to create a LinkButton within the code-behind, when I debug my code I recieve no errors, however its not accessing the EventArg attached to the button, it does however refresh the page. What am I doing wrong?
Button Code
LinkButton myLinkButton = new LinkButton();
myLinkButton.ID = appointment.appID.ToString();
myLinkButton.CommandArgument = appointment.appID.ToString();
myLinkButton.Command += new CommandEventHandler(ViewClick);
myLinkButton.CommandName = appointment.appID.ToString();
myLinkButton.Text = appointment.contactName
Used to style button
string divLook = "height:" + divHeight + "em";
Button is then added to a panel
Panel p = new Panel();
p.Style.Add("linkStyle", divLook);
p.CssClass = "standardLink";
p.Controls.Add(myLinkButton);
dataCell.Controls.Add(p);
protected void ViewClick(object sender, CommandEventArgs e)
{
var appointmentId = Convert.ToInt32(e.CommandArgument);
Debug.Write("Are you even getting in here");
}
Thanks in advance for any help.
Clare
Everything looks legit. I would recommend viewing the source of the generated page and looking at the ID that the link button is getting. It may be duped on the page.