How to open Word Application using SWT OLE? - plugins

I need to open the word application using swt ole but not in the shell rather i want open it externally i.e. as a separate application.
Please Help me.
I'm a student and not well versed in swt ole(If possible,please provide me the code).
Thanks in advance!

Try below sample code:
try {
Shell shell = new Shell(Display.getDefault());
Composite displayArea = new Composite(shell, SWT.BORDER);
displayArea.setLayout(new FillLayout());
OleFrame oleFrame = new OleFrame(displayArea, SWT.NONE);
OleClientSite clientSite = new OleClientSite(oleFrame, SWT.NONE, "Word.Document", new File(fileName));
} catch (SWTException error) {
error.printStackTrace();
}

Related

ID attribute not displayed in Browser for Eclipse SWT/RAP HTML components

We are using RAP with Eclipse SWT to render our application UI in browser.
We want to automate the Testing of Application with selenium, which requires IDs for each HTML component.
But the problem is widgets (Text in this case) does not have "id" as an attributes visible in the browser.
We have tried using following setData method of Text widget but still id attribute is not visible in browser.
tf_offerId.setData(SWT.SKIN_ID, "myId1");
tf_offerId.setData(SWT.SKIN_CLASS, "myClass");
Here is our sample Code.
class A {
private Text tf_offerId;
void method1() {
Composite comp_left = new Composite(this, SWT.NONE);
Composite comp = new Composite(comp_left, SWT.NONE);
GridLayout gl_comp = new GridLayout(3, false);
gl_comp.marginWidth = 0;
comp.setLayout(gl_comp);
comp.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false,1, 1));
Label lbl = new Label(comp, SWT.NONE);
lbl.setText("Offer Id / Cluster Id");
lbl.setBackground(new Color(getDisplay(),220,220,220));
lbl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
tf_offerId = new Text(comp, SWT.BORDER);
tf_offerId.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,true, false, 1, 1));
tf_offerId.setToolTipText("Usage:\nsss_pricing/se_configuration-OfferId\nse_calculation-OfferId\nsss_build/sss_validation-ClusterId");
}
}
Please suggest possible solution.
To identify a widget on the client side it is best to define an dedicated test attribute that holds the id used for testing. With this id, the widget can be identified in Selenium.
A discussion of various alternatives to identify widgets on the client side for testing with Selenium can be found here:
How to write UI tests for RAP with Selenium 2.0

How to open a filedialog within an Eclipse Wizard

I'm writing an Eclipseplugin, which has to create a new project. This works so far, but i need to copy an external file into the projectfolder. I intend to have a 'Browse' button on one of my WizardPages, which opens a filedialog, where the user can browse to the file and after closing the dialog i can use the path to this file for various actions. My problem is that the dialog window never opens. Right now i'm trying it that way (snippet from my wizardpage):
public void createControl(Composite composite) {
this.container = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
this.container.setLayout(layout);
layout.numColumns = 2;
Button browseButton = new Button(this.container, SWT.PUSH);
browseButton.setText("Browse");
browseButton.addSelectionListener(new SelectionListener() {
#Override
public void widgetDefaultSelected(SelectionEvent arg0) {
FileDialog fileDialog = new FileDialog(DataPage.this.container.getShell(), SWT.OPEN);
fileDialog.setText("JZOS created File");
String path = fileDialog.open();
DataPage.this.setJzosCreatedName(path);
}
});
I tried several implementations, that i have seen in examples and tutorials but nothing did work. I'm assuming a problem with the Shell that i give to the filedialog. I tried to open a new Shell within the widgetDefaultSelected function but it didn't work either. Any Suggestions?
You should be using the widgetSelected method of SelectionListener not widgetDefaultSelected

Why scrollbar of JtextArea doesn't navigate?

I use one JTextArea and JScrollBar. It has this problem when I run it and it will fill by text, I can't navigate it. i.e. when I click on arrowkey on scrolbar, nothing happen. although I write the update code for it (by using API), but it doesn't work well. What shall i do? Thanks in advance.
I show my code as bellow:
JTextArea Result_field = new JTextArea(5,10);
Result_field.setPreferredSize(new Dimension(5, 10));
JScrollPane scrollPane = new JScrollPane( Result_field );
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
DefaultCaret caret = (DefaultCaret)Result_field.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
PrintStream printStream = new PrintStream(new CustomOutputStreamm(Result_field));
System.setOut(printStream);
MainPanel.add(scrollPane,gbc);
I found out my problem, although we define one JTextArea or ... by the size, But after that we should determine the prefer size again.

Creating own toolbar leveraging existing org.eclipse.ui.menus extension

I have custom editor for eclipse. For particular reasons this editor provide two toolbar areas which are not based on standard action bars provided by eclipse for editor. This two places are dedicated for other plugins to contribute. My intention is to leverage "org.eclipse.ui.menus" extension point with custom menuContribution/locationURI so other plugins can contribute using this extension and associated toolbar:my.editor.toolbar1 and toolbar:my.editor.toolbar2 as locationURI.
My problem is how to "connect" my ToolBar with particular location. I tried following approach but result are not good. I created custom ToolbarContributionRoot event if I should not and also created CustomContributionFactory which extends ExtensionContributionFactory. It works pretty well, but problem is with pulldown commands which submenu is not resolved correctly.
toolbarManager = new ToolBarManager(SWT.FLAT);
ToolbarContributionRoot toolbarRoot = new ToolbarContributionRoot(toolbarManager);
IServiceLocator workbench = PlatformUI.getWorkbench();
IConfigurationElement[] allMenuElements
= Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.ui.menus");
for (IConfigurationElement menuContribution : allMenuElements) {
String locationURI = menuContribution.getAttribute("locationURI");
if ("toolbar:my.editor.toolbar1".equals(locationURI)) {
try {
ExtensionContributionFactory factory = CustomContributionFactory.create(menuContribution);
factory.createContributionItems(workbench, toolbarRoot);
} catch (CoreException e) {
e.printStackTrace();
}
}
}
toolbar = toolbarManager.createControl(root);
GridData gridData = new GridData(GridData.FILL, GridData.FILL, false, false, 1, 1);
toolbar.setLayoutData(gridData);
toolbar.pack();
plugin.xml of "user" looks like this:
<extension point="org.eclipse.ui.menus" id="my.helper.id">
<menuContribution locationURI="toolbar:my.editor.toolbar1">
<command commandId="my.editor.special.command1" />...
Do you have any suggestions how to blend my custom toolbars and "org.eclipse.ui.menus" extension together?
Correct way how to do it is:
toolbarManager = new ToolBarManager(SWT.FLAT);
IServiceLocator workbench = PlatformUI.getWorkbench();
IMenuService menuService = (IMenuService) workbench.getService(IMenuService.class);
menuService.populateContributionManager(toolbarManager, TOOLBAR_LOCATION);
toolbar = toolbarManager.createControl(root);

Writing to a new window

Im trying to get some simple javascript working in gwt but keep failing.
The code:
public static native void createWindow() /*-{
var wndRef = $wnd.open('','edit');
var divTag = document.createElement("div");
divTag.id = "div1";
divTag.setAttribute("align","center");
divTag.style.margin = "0px auto";
divTag.innerHTML = "blah blah blah";
wndRef.document.body.appendChild(divTag);
}-*/;
I am trying to open a new window and write content to it
The problem:
Currently this code opens a new window but its empty.
How do i write content to it ? am i doing something wrong or am i expecting too much from gwt?
Context: My end goal is to open a new Window and have my form panel and various widgets inserted in to it via java methods.
GWT is compiled to Javascript, so GWT can do what JS can do.
If you want to open a new window and inject some content to it then this is the right way:
var win = window.open("", "win", "width=300,height=200"); // a window object
win.document.open("text/html", "replace");
win.document.write("<HTML><HEAD><TITLE>New Document</TITLE></HEAD><BODY>Hello, world!</BODY></HTML>");
win.document.close();