How can I add a hyperlink to a JFace Dialog - java

How can I make a hyperlink in a JFace Dialog that when clicked opens the link in the default web browser. A full example would be useful. I know there is a org.eclipse.jface.text.hyperlink package but I can't find a suitable example.

Are you running an RCP application?
If so, then the following code will open your link in the default OS browser:
// 'parent' is assumed to be an SWT composite
Link link = new Link(parent, SWT.NONE);
String message = "This is a link to Google";
link.setText(message);
link.setSize(400, 100);
link.addSelectionListener(new SelectionAdapter(){
#Override
public void widgetSelected(SelectionEvent e) {
System.out.println("You have selected: "+e.text);
try {
// Open default external browser
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(e.text));
}
catch (PartInitException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
catch (MalformedURLException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
}
});
The above assumes that you do not want to scan existing text for hyperlinks but simply wish to create one programmatically. If the former is required then you'll need to use the API from JFace text packages or suchlike.

Related

Trying to upload photo in facebook but not able to click on upload photo link

enter image description hereTrying to upload photo in facebook but not able to click on upload photo link
my_profile.changePicture("E:\My Documents\Desktop");
public class MyProfilePage extends Page {
public void changePicture(String filepath) {
try {
Thread.sleep(9000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
click("profile_picture");
try {
Thread.sleep(9000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
click("upload_picture");
type("upload_picture", filepath);
}
Xpath is stored in config.properties file .
upload_picture=//a[#data-action-type='upload_photo']/div/input[#type='file'][#class='_n _5f0v'][#title='Choose a file to upload'][contains(#id,'js')]
This is modal popup, you have to switch to it first, then you will be able to locate link.
driver.switchTo().activeElement()
#suhail Did you try to simply use sendKeys on the input element without clicking it? As value for sendKeys use path to your file.

Unable to move to next page after clicking on button using Selenium Webdriver in IE11

This is my first post as I am stuck on this problem for many days. My script is unable to move to next page after a click on button. I checked that element is present and then clicked on it. It displays next page but script keeps running and never comes back. It never executes my information message given below.
System.out.println("continue button clicked");
Copying my Selenium and Java Code. Please help...
HTML:
<a tabindex="76" href="javascript:formSubmit()" oncontextmenu="return false">
<img src="/RetailCustomerManagement/resources/graphics/continue_orange_en.gif" style="border:none;"/>
</a>
Java Code:(using a frame work)
boolean isElementpresent = PerformAction.isElementsPresentNameCheck(continuebutton).size()!=0;
System.out.println("Is Element present? " + isElementpresent);
PerformAction.waitForElementToBeClickable(continuebutton);
PerformAction.FuncSubmit(continuebutton);
//PerformAction.FuncClick(continuebutton);
System.out.println("continue button clicked");
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

using java awt robots on browser

Trying to use java awt robots in the deployed application, initially got headless exception
thought changing headless property will do, but still the issue exists
try {
Field defaultHeadlessField = java.awt.GraphicsEnvironment.class.getDeclaredField("defaultHeadless");
defaultHeadlessField.setAccessible(true);
defaultHeadlessField.set(null,Boolean.FALSE);
Field headlessField = java.awt.GraphicsEnvironment.class.getDeclaredField("headless");
headlessField.setAccessible(true);
headlessField.set(null,Boolean.FALSE);
System.out.print(GraphicsEnvironment.isHeadless());
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
try {
Robot robot = new Robot();
but now it says
java.awt.HeadlessException
at sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(HeadlessGraphicsEnvironment.java:64)
basic use case is to simulate keypress(0) on browser window, need some help in solving this issue.

JFrame serialisation with LookAndFeel

I am trying to serialize a JFrame containing a JDesktopPane with several JInternalFrames.
I encountered a problem with the LookAndFeel because for any reason it is not possible to serialize a Swing component with a to the CrossPlatform LnF different one.
So I wrote this test program in order to figure out my possibilites:
public static void main(String[] args) {
try {
JFrame f = new JFrame();
f.setBounds(200,200,200,200);
JTree tree = new JTree();
f.add(tree);
f.setVisible(true);
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(f);
ObjectOutputStream oop = new ObjectOutputStream(
new FileOutputStream(new File("test.serialized")));
oop.writeObject(f);
} catch(IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
This didn't work for two reasons:
I am not able to serialize the frame and the contained tree. Just the tree is fine but just when
I set the LookAndFeel to cross platform in the first place and create my tree afterwards.
Any idea how to fix this?
EDIT:
Sorry for making this not clear:
I am NOT trying to serialize the LnF or something like that.
The LnF doesnt want me to serialize the Frame.
java.io.NotSerializableException: com.apple.laf.AquaTreeUI
And on top of that i am not able to serialize a Frame that contains a Tree.
Exception in thread "AWT-EventQueue-0" java.lang.InternalError: incorrect component
What you are trying is not possible. When you serialize the JFrame object, the LnF is not serialized in any way. That is because the JFrame keeps no memory of this. What LnF is used is stored elsewhere...
What I would do is wrap the JFrame in another object, let's say MyGUI. Inside that, I would store the LnF (as a String for example) in a private field. In the end, serialize MyGUI and, at deserialization, you have the LnF nice and intact and you can set it again.
Check this. Is the implementation proposed by #SoboLAN.

jfilechooser better look?

When I'm using JFileChooser application in my program on Windows 7 it display such window:
But when I run the JWS File Chooser Demo it displays much better window:
Why?
Because the demo doesn't use JFileChooser; it uses javax.jnlp.FileOpenService, which uses the native OS's file dialog. The source code for that demo is here, check it out.
The Oracle Java Web Start app, is actually using the JNLP API instead of Swing's JFileChooser.
Here is a link: http://download.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/jnlpAPI.html
The major difference could be solved by using the native look and feel. See the main() of FileBro for how to do that.
use this code
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (ClassNotFoundException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (InstantiationException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (IllegalAccessException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (UnsupportedLookAndFeelException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}

Categories