I included a HELP_CONTENTS action from the ActionFactory in my RCP application but I would like to open a PDF file when I call it in the application and not the normal xml file. Is that possible? I didn't find any examples online.
If you use HelpContentsAction then you'll get Eclipse help. If you want to display your own file then create your own action (you can reuse the icon and text if you want to).
Use IWorkbenchPage.openEditor(IEditorInput input, String editorId) method to open PDF file:
org.eclipse.core.resources.IFile workspaceFile;
java.io.File externalFile;
//PDF in workspace
IEditorInput input = new FileEditorInput(workspaceFile);
//or external
IFileSystem fs = org.eclipse.core.filesystem.EFS.getLocalFileSystem();
IFileStore fileStore = fs.fromLocalFile(externalFile);
input = new FileStoreEditorInput(fileStore);
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.openEditor(input, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
Related
Just getting started with Katalon Recorder. After navigating and loading a page, is there a way to store the entire page text? I am trying to automate a function where I have to click into a list item, select all, copy and paste into excel.
The comment from Mate Mrše is off to a good start. Here's some example code that fleshes out the details. The following code saves the page to an html file. From there you'll need additional processing to put it into another document format, such as Excel.
// add the following two imports for the webdriver
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import org.openqa.selenium.WebDriver as WebDriver
// open browser/navigate, etc
// WebUI.openBrowser('https://google.com')
WebUI.delay(5)
WebDriver driver = DriverFactory.getWebDriver()
def src = driver.getPageSource()
def file1 = new File('c:/1/the_saved_web_page.htm')
file1.write(src)
Editor templates in eclipse can be imported from xml file. Instead of manually importing, wanted to create a plugin. Which will import the templates.xml kept in specified folder at start of the eclipse.
How this can be achieved?
You can use the JFace org.eclipse.jface.text.templates.persistence.TemplateReaderWriter to read a template.xml. Something like:
File file = .... file to read
TemplateReaderWriter reader = new TemplateReaderWriter();
InputStream input = new BufferedInputStream(new FileInputStream(file));
TemplatePersistenceData[] datas = reader.read(input, null);
(code to deal with errors and closing the input left out)
You can then put the data in a TemplateStore:
TemplateStore fTemplateStore = ... store to use
for (TemplatePersistenceData data: datas) {
fTemplateStore.add(data);
}
fTemplateStore.save();
The template store you use depends on which templates you are updating.
For the Java Editor template store you can get the store with
JavaPlugin.getDefault().getTemplateStore();
But the JavaPlugin is not part of the official Eclipse API.
The above code is a simplified version of the import code in org.eclipse.ui.texteditor.templates.TemplatePreferencePage
I am developing a eclipse plugin to ease the development using a proprietary version control system.
Right now there is only a command prompt version of the system available for this VCS and its run in terminal. So from my eclipse plugin I want to provide a simple menu options to do the things like check-out and check-in and internally call these commands.
But to run these commands I need to pass the argument 'path' of the selected .java file in the editor/project explorer. How can I get the path of the source file to the plugin?
Get the current workbench page:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
the workbench page implements ISelectionService so you can get the current selection:
ISelection selection = page.getSelection();
this will generally by an IStructuredSelection (but you need to check)
IStructuredSelection sel = (IStructuredSelection)selection;
See if this adapts to an IFile:
Object selObject = sel.getFirstElement(); // or iterate through all the selection elements
IFile file = Platform.getAdapterManager().getAdapter(selObject, IFile.class);
if you get a file the full path is:
String location = file.getLocation().toOSString();
If the current part is an editor then the selection you receive might be a text string. So you need to deal with editors separately:
IWorkbenchPart activePart = page.getActivePart();
if (activePart instanceof IEditorPart)
{
IEditorInput input = ((IEditorPart)activePart).getEditorInput();
if (input instanceof IFileEditorInput)
{
IFile file = ((IFileEditorInput)input).getFile();
...
}
}
I'm trying to generate a .pdf file using mPDF in a Zend Framework application, from the output of the action.
Here is the code of my action:
public function testAction()
{
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$this->view->foo = 'bar';
$this->render();
$output = $this->getResponse()->getBody();
$layout = new Zend_Layout();
$layout->content = $output;
$layout->setLayoutPath(dirname(dirname(__FILE__)) . '/views/layouts/');
$layout->setViewSuffix('tpl');
$layout->setLayout('pdf');
$html = $layout->render();
$mpdf = new mPDF('utf-8', 'A4');
$mpdf->WriteHTML($html);
$mpdf->Output('report.pdf', 'D');
}
If the content to be displayed is long (i.e. a few paragraphs), when downloading the .pdf file, Adobe Reader throws the following error: Adobe Reader could not open 'report.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
However, if I pass the same output to mpdf as a static variable, without using Zend Layout render, then the .pdf file opens without any errors. Also, Adobe Reader throws the issue if and only if the content is long (i.e. it works if there are only a couple of words).
Is there any limit I should be aware of?
there should not be space at beginning and at the end of file so check these space,
Adobe Reader is less forgiving than some othe PDF readers if the PDF file is corrupt. Open your PDF document in a text editor and check that the file starts with something like:
%PDF-1.4
%âãÃÓ
Sometimes PHP error notices are found at the top of the file.
Source : mpdf forum IanBack's answer
I need to give a input text file in GWT FileUpload and test it using Selenium Webdriver.
I have Upload widget, In that I need to give a text file as input. Then click a upload button to do my functionality.
i tried this,
driver.findElement(By.id("uploadField")).sendKeys("C:/Desktop/Input.txt");
driver.findElement(By.id("uploadButton")).click();
but I'm not able to give input to this upload field.
Can anyone help me?
See this code is working for me see : use correct file path in sendkeys
driver.get("http://www.freepdfconvert.com/");
driver.findElement(By.id("UploadedFile")).sendKeys("C:\\Users\\username\\Downloads\\HP1.pdf");
try {
Thread.sleep(4000);
}
catch (Exception e) {}
driver.findElement(By.name("pdfsubmit")).click();
}
or
driver.findElement(By.id("uploadField")).sendKeys("C:/xyz.txt");
driver.findElement(By.name("uploadButton")).click();
Use name or Xpath then check .
Edit
Yes it run for all browser but for IE and chrome you have to add small code.
IE:
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
Chrome
File file = new File("E://chromedriver.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();`