When I set the logo for my java plugin, the logo of other windows of eclipse are changed.
I have a class which extends Wizard and implements IObjectActionDelegate. Then, I have override the run function and write the below code in it.
wizard = new StartWizard();
dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard);
Bundle bundle = Platform.getBundle("Plugin");
URL url = FileLocator.find(bundle, new Path("icon/Logo.png"), null);
ImageDescriptor desc = ImageDescriptor.createFromURL(url);
Image image = desc.createImage();
WizardDialog.setDefaultImage(image);
I have read the solution set forth to the similar post on Only changing the logo of special plugin. The problem is that I have extended Wizard and cannot extend WizardDialog instead.
Since you are creating WizardDialog yourself you can actually extend that class if you want.
In a Wizard you can get the current Shell by calling:
Shell shell = getContainer().getShell();
shell.setImage(your image);
It looks like the wizard addPages method would be suitable for this code.
Related
I am working in an RCP application similar to Eclipse where the user can navigate in Project Explorer tree and opens any file in the Editor
i am Setting the RCP application title in a class which extends "WorkbenchWindowAdvisor" as the following:
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setTitle("My RCP Application title");
But what i need to show up in title bar the perspective name and the opened file path like in normal eclipse:
any suggestions
Thanks
This is requires listening to a lot of events in your WorkbenchWindowAdvisor.
In the preWindowOpen method you need to add listeners for:
Page activation and closing using configurer.getWindow().addPageListener(listener) The pageActivated and pageClosed listener methods need to update the title.
Perspective changes using configurer.getWindow().addPerspectiveListener(listener). The perspectiveActivated, perspectiveSavedAs, perspectiveDeactivated methods need to update the title.
Part activations using configurer.getWindow().getPartService().addPartListener(listener). This need to use an IPartListener2. The partActivated, partBroughtToTop, partClosed, partHidden, partVisible methods need to update the title.
You get the open file path from the active editor:
IWorkbenchPage currentPage = configurer.getWindow().getActivePage();
IEditorPart activeEditor = currentPage.getActiveEditor();
if (activeEditor != null) {
path = activeEditor.getTitleToolTip();
}
and the perspective name:
IPerspectiveDescriptor persp = currentPage.getPerspective();
if (persp != null) {
label = persp.getLabel();
}
The full, even more complex, code for this is in org.eclipse.ui.internal.ide.application.IDEWorkbenchWindowAdvisor
I made a custom Eclipse plugin that uses and displays multiple dialogs, and I want to know if I could set the top left icon image with the one I use in the plugin's icons folder. I want to get that icon and set it instead of the default one that Eclipse uses.
I'm overriding the configureShell() method to change the dialog title, and I also want to change the icon.
#Override
protected void configureShell(Shell parent){
super.configureShell(parent);
parent.setText("Choose variant...");
Image icon = new Image(parent.getDisplay(), "icons/best.gif"); - this method does not work as it cannot find the file
parent.setImage(icon);
}
I also tried using the getClass().getResource("best.gif") and having the image in the same package, still can't find the location I'm giving(FileNotFoundException), and also, the Image constructor does not accept URL objects.
#Override
protected void configureShell(Shell parent){
super.configureShell(parent);
parent.setText("Choose variant...");
Image icon = new Image(parent.getDisplay(), getClass().getResource("icons/best.gif"));
parent.setImage(icon);
}
Is there a way to use the icon that I already have in my eclipse plugin?
The main problem is getting the icon from the icons folder of the plugin and making it a Image object.
Thank you.
You can register the icon in your plugins activator class like this:
#Override
protected void initializeImageRegistry(final ImageRegistry reg) {
reg.put(IMAGE_PATH, imageDescriptorFromPlugin(PLUGIN_ID, IMAGE_PATH));
}
The image path is relative to your plugin, e.g. icons/icon.png.
You can access these images via the activator class as well:
final Image image = MyActivatorClass.getDefault().getImageRegistry().get(IMAGE_PATH);
myShell.setImage(image);
(Note that I used the image path as key in the image registry, you do not have to do it like this but it makes everything a little bit less complicated by just using the same static String.)
For an Eclipse plugin you use the FileLocator class to find resources in your plugin.
For an image use something like:
String path = "icons/best.gif";
URL url = FileLocator.find(bundle, new Path(path), null);
ImageDescriptor desc = ImageDescriptor.createFromURL(url);
Image image = desc.createImage();
Note: You must arrange for the image to be disposed when no longer needed.
If your activator extends AbstractUIPlugin you can also use the ImageRegistry available from that. The registry will deal with disposing.
Be sure that the icons directory is listed in the build.properties file. Missing this will causes issues when you export your plugin.
I create an action and set image for this action
Action showErrWarnAct = new Action();
Bundle bundle = FrameworkUtil.getBundle(Activator.class);
URL url = FileLocator.find(bundle, new Path("icons/warning.png"), null);
ImageDescriptor image = ImageDescriptor.createFromURL(url);
showErrWarnAct.setImageDescriptor(image);
I want to change the image of action when hover on it. So I use setHoverImageDescriptor
showErrWarnAct.setHoverImageDescriptor(image2);
But the image does not change when I hover the mouse on it. How can I do it?
I think the very old Eclipse bug fix 53617 changed the behavior of Actions (in tool bars at least) so that the hover image is ignored.
The bug does mention a preference value which can be set in the 'plugin_customization.ini' to use the old behavior.
I took the rendered page from the SWT Browser and exported it to an image. My problem is that I am not able to get it to export properly when the shell is not visible. How can I go about hiding the browser and have the image export properly?
I have tried setting shell.Visible() to false but that messes up the image export.
This is how I export the image (not sure if this is necessary to the question):
GC source = new GC (shell);
Image image = new Image(display, browser.getClientArea());
source.copyArea(image, 0, 0);
ImageLoader io = new ImageLoader ();
io.data = new ImageData[] { image.getImageData() };
File f = new File (currentDir+"/workpng.png");
io.save (f.getAbsolutePath(), SWT.IMAGE_PNG);
This might be impossible because the X server/Windows will throw away all rendering commands when the window isn't visible (no point in rendering what you can't see).
Also what is the client area of the browser in this case?
To make this work, you'll need to allow the shell to open be visible (i.e. not hidden by some other window). Tools like Jenkins use a plugin that starts an X session with Xvfb or Xvnc. After setting the env variable DISPLAY, all UI rendering goes to these sessions.
Is there any way to open a new window with a specified URL using java only.I know that we can use window.open in javascript but i need it to be in java page.Anyidea?.
You can use Applet's context and the showDocument() method.
Example:
String link = "http://www.google.com";
URL u = new URL(link);
AppletContext a = getAppletContext();
a.showDocument(u,"_self");
You can change the window/tab opening the link by changing the _self to _blank
If it's indeed an applet, and you want to create a Java window (JFrame or similar), see AlphaMale's comment.
If what you want instead is a new browser window, you can either follow inquizitive's answer, or alternatively use JSObject to run arbitrary JavaScript code:
import netscape.javascript.*; // add plugin.jar to classpath during compilation
...
JSObject window = JSObject.getWindow(this);
window.eval('window.open(url)');
This is more useful to interact with the page's scripts, of course, if what you want is just open another tab using the Applet API may be simpler.