I'm developing an eclipse product and i need to associate a file extension to my editor.
I followed several examples (as like as this and
this) but it seems that the editor ever receives the SWT OpenDocument event.
As described in the fileAssociation example i created an eventListener class to process SWT.OpenDocument events and i added this in my Application class to the display before that the PlatformUI.createAndRunWorkbench() method gets called
public Object start(IApplicationContext context) throws Exception {
Object args = context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
OpenDocumentEventProcessor eProc = new OpenDocumentEventProcessor();
Display display = PlatformUI.createDisplay();
display.addListener(SWT.OpenDocument, eProc);
try{
if(!handleWorkspace(display)){
System.exit(0);
return IApplication.EXIT_OK;
}
int returnCode = PlatformUI.createAndRunWorkbench(display, new XVRWorkbenchAdvisor(args, eProc));
In the product file i added the following program arguments:
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-name
XVR Studio Developer
If I use the same code in a new empty RCP project it works like a charm..
I can't figured out which could be the problem..
can you help me?
Thanks a lot!!
This approach is unknown for me, but since there is no explicit editor call in your pasted code I guess you still rely on eclipse to decide which editor has to be opened. So I guess you still have to define contentypes and file associations declaratively. To do that contribute to "org.eclipse.core.contenttype.contentTypes" extension, add a 'file-association' (file extension...). Get your editor declaration in your plugin xml and add the previously created 'contentTypeBinding' id.
As I have just made this work for an RCP app, I thought it would be helpful to document how I did it here, and provide refs.
I had no use for the 'context.getArguments()..', the 'OpenDocumentEventProcessor' handled everything.
I would suggest that the reason this did not work was that the -name value did not match the value of the 'appName' property in the 'org.eclipse.core.runtime.products' extension point. Just to be sure, I removed the spaces from the appName property and in the -name. Then it worked.
Very useful references are:
For the basic coding:
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fproduct_open_file.htm
For an explanation of how this works:
http://aniefer.blogspot.co.uk/2010/05/opening-files-in-eclipse-from-command.html
One small point that eluded me for some time, was getting the path for the file in several chunks at the place where there was a space in the name. Eventually I realised (in a 'duh!' moment) that I needed to put quotes round the %1 parameter in the installer's (InstallAware) definition for the file association - i.e it became "%1"
Related
When I use CRF++ toolkit for the first time. I have installed it and when I run the crflearn command I'am getting this message :
CRF++: Yet Another CRF Tool Kit Copyright (C) 2005-2013 Taku Kudo, All rights reserved. encoder.cpp(340) [feature_index.open(templfile, trainfile)] feature_index.cpp(135) [ifs] open failed: template_file
Can anyone help me?
The package is pretty well documented here
Can you give the full command you tried to use?
The pattern is crf_learn -t [template_file] [data_file_in_the_right_format]
The package comes with an example template file, here's the head of mine:
U00:%x[-5,0]
U01:%x[-4,0]
U02:%x[-3,0]
U03:%x[-2,0]
U04:%x[-1,0]
U05:%x[0,0]
The data needs to be in a tab delimited format with each data point represented by a row, each column is the feature value for that row and the final column is your gold standard label.
Does that help?
You put wrong file path for template featurefile and model. So, put these files inside CRF-PP folder and fire the crf_learn command. Hope this will solve your issue.
Title is confusing, but don't know how to explain this in a few words:
I have a java application that reads *.example files. I've also added a file association thanks to install4j so my application is launched when the user double clicks any file with extension *.example
It seems that install4j sends the file path in the args[] so it should be easy to open that file and show it in my app. BUT what happens if the app is already running? I can only allow one instance of the application so, how can I know that the user is opening a file?
I've found this: http://resources.ej-technologies.com/install4j/help/api/com/install4j/api/launcher/StartupNotification.html
But I still don't understand how should I use it and what should I add in my app to listen for this event. Where can I find an example?
Based on the documentation you linked to, it looks like you can do this:
StartupNotification.registerStartupListener(new StartupNotification.Listener() {
public void startupPerformed(String parameters) {
System.out.println("Startup performed with parameters " + parameters);
}
});
Since startupPerformed will be called from different threads, you will need to make sure that the code that handles these notifications is thread-safe.
The documentation also says:
For multiple files, files are surrounded by double-quotes and separated by spaces.
So you will need to parse the parameter string yourself as well.
I need to set certain system variables from within the program. My Google fu is failing me in finding any way to do it. How do I do it? (I am okay with hacky approaches. I need to be able to run this app on Windows, Linux, and Mac.)
Edit:
Adding here my comment from below the post, as it isn't readily visible there:
The best link I could found was this, and it sets the variables only in memory. They do not persist after the program exit.
Edit:
I am writing an installer and need to somehow record at system level that installation happened (along with paths to some directories). The next time user runs the setup, the installer will check if the variables already exist in the system, in which case a user will be given an appropriate warning.
If twiddling with environment variables is not a good idea, what will be the best approach to achieve the above?
Use
following methods of system class
// Get a system property
String dir = System.getProperty("user.dir");
// Set a system property
String previousValue = System.setProperty("application.property", "newValue");
for more details reffer
http://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CF8QFjAA&url=http%3A%2F%2Fdocs.oracle.com%2Fjavase%2Ftutorial%2Fessential%2Fenvironment%2Fsysprop.html&ei=oHLgT6agKcborAf_3L3-DA&usg=AFQjCNGWSWRjk3ityPQqreuwx_O7Bp7kdg&sig2=Y1tfYzdXAmNX-hpB8Z64kw
If you want your environment variables to persist after your program ends, I would suggest you use the Properties class. It can be persisted to a file very easily, and vice versa.
First of all, Properties is a java class that is used to hold properties that maybe needed for your program. The basic properties that you are talking about are provided by the operating system. Not all of these can be changed. If you try, you will get a SecutrityException (You can't change the os.name for instance). The basic properties are read from the memory of the computer (basically) you can add additional variables to this by setting environment variables in the operating system you are using. Such as in Win95 you can add to the autoexec.bat the line:
set BARTENDER_NAME=Carl
This line can go in any batch file and BARTENDER_NAME will equal Carl until you reset it.
In your java program If you add the line
System.out.println(System.getProperty("BARTEDER_NAME"));
You'll get Carl as the output.
In the bash shell on Linux or Unix you'd use
BARTENDER_NAME=Carl
export BARTENDER_NAME
You can create your own set of properties for your java program and store them in a file and load them using the Properties load() method.
Hope this helps
from
http://www.coderanch.com/t/387634/java/java/Permanently-setting-System-property
Ok this is off the top of my head so it's extremely hacky and stuff.
Get hold of a process and run the command line command that will set the system variables. This isn't portable but it should suffice for short term till you find a better solution.
Because there is not a standard solution for this, I would recommend you to use a Factory Pattern for this. It means something like:
envManager = null
if system is Windows
`envManager = WindowsEnvManager`
else if system is Linux
`envManager = LinuxEnvManager`
else if system is Mac
`envManager = macEnvManager`
persistEnvironment(envManager);
and the persistEnvironment method would call the specific functions on EnvManager.
How about using Java Preferences API. That way you would store this kind of data in the Registry if you run on Windows. Simple tutorial here.
You can store the preferences per system or per user and the preferences are persistent as well as you desire.
Edit
Example:
package com.stackoverflow.Q11100967;
import java.util.prefs.Preferences;
/**
* #author maba, 2012-06-20
*/
public class App {
public static void main(String[] args) {
Preferences preferences = Preferences.systemNodeForPackage(App.class);
if (!preferences.getBoolean("installed", false)) {
// Install the stuff...
preferences.putBoolean("installed", true);
preferences.put("version", "1.2.3");
}
}
}
On Windows the preferences will be stored at HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Prefs/com/stackoverflow/Q11100967.
In order for this to work you have to run your process with admin privileges or a similar approach.
Edit2
On Linux the preferences would be stored at /etc/.java/.systemPrefs/com/stackoverflow/Q11100967/ in a file called prefs.xml with the following content:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE map SYSTEM "http://java.sun.com/dtd/preferences.dtd">
<map MAP_XML_VERSION="1.0">
<entry key="installed" value="true"/>
<entry key="version" value="1.2.3"/>
</map>
My requirement is simple. At the beginning of each file there should be a block comment like this:
/*
* This file was last modified by {username} at {date} and has revision number {revisionnumber}
*/
I want to populate the {username}, {date} and {revisionnumber} with the appropriate content from SVN.
How can I achieve this with NetBeans and Subversion? I have searched a lot but I can't find exactly what I need.
I looked at this question and got some useful information. It is not exactly duplicate because I am working with NetBeans but the idea is the same. This is my header:
/*
* $LastChangedDate$
* $LastChangedRevision$
*/
Then I go to Team > Subversion > Svn properties and add svn:keywords as property name and LastChangedDate LastChangedRevision as property value.
And when I commit from NetBeans it looks like this:
/*
* $LastChangedDate: 2012-02-13 17:38:57 +0200 (Пн, 13 II 2012) $
* $LastChangedRevision: 27 $
*/
Thanks all for the support! I will accept my answer because other answers do not include the NetBeans information. Nevertheless I give +1 to the other answers.
As this data only exists after the file was committed it should be set by SVN itself, not a client program. (And client-side processing tends to get disabled or not configured at all.) This means there is no simple template/substitute like you want, because then after the first replacement the template variables would be lost.
You can find information abut SVN's keyword substitution here. Then things like $Rev$ can be replaced by $Rev: 12 $.
You can do this with The SubWCRev Program.
SubWCRev is Windows console program which can be used to read the
status of a Subversion working copy and optionally perform keyword
substitution in a template file. This is often used as part of the
build process as a means of incorporating working copy information
into the object you are building. Typically it might be used to
include the revision number in an “About” box.
This is typically done during the build process.
If you use Linux, you can find a Linux binary here. If you wish, you could also write your own using the output of svn log.
I followed Petar Minchev's suggestions, only I put the $LastChangedRevision$ tag not in a comment block but embedded it in a string. Now it is available to programmatically display the revision number in a Help -> About dialog.
String build = "$LastChangedRevision$";
I can later display the revision value in the about dialog using a String that has all of the fluff trimmed off.
String version = build.replace("$LastChangedRevision:", "").replace("$", "").trim();
I recommend a slightly different approach.
Put the following header at the top of your source files.
/*
* This file was last modified by {username} at {date} and has revision number {revisionnumber}
*/
Then add a shell script like this
post update, checkout script
USERNAME=# // use svnversion to get username
DATE=# // use svnversion to get revisio nnumber
sed -e "s#{username}#${USERNAME}#" -e "s#{date}#${DATE}#" ${SOURCE_CONTROL_FILE} > ${SOURCE_FILE}
pre commit script
cat standard_header.txt > ${SOURCE_CONTROL_FILE}
tail --lines $((${LENGTH}-4)) ${SOURCE_FILE} >> ${SOURCE_CONTROL_FILE}
I'm developing an editor plugin for eclipse. It works fine on files within eclipse projects, but when an external file is opened via the "File -> Open File" menu (which works file with, e.g. Java files), I get a page displaying nothing but a horizontal blue line and the word "ERROR". The Error Log of eclipse is empty, as is the log file in the .metadata directory.
What could cause this? How can I diagnose the error when I have no error message that tells me where to look? There doesn't seem to be a way to get more detailed logging from eclipse.
Edit:
I've found that the source of the problem is close to what jamesh mentioned, but not a ClassCastException - there simply is no IDocument instance for the text viewer to display because StorageDocumentProvider.createDocument() returns null. The reason for this is that it only knows how to create documents for instances of org.eclipse.ui.IStorageEditorInput, but in this case it gets an instance of org.eclipse.ui.ide.FileStoreEditorInput, which does not implement that interface, but instead implements org.eclipse.ui.IURIEditorInput
I had the same probleam and finally found solution working for me.
You have to provide 2 different document providers - first extending FileDocumentProvider for files inside your workbench, and second extending TextFileDocumentProvider for other resources outside your workspace. Then you register the right provider acording to the input in your editors doSetInput method like this:
private IDocumentProvider createDocumentProvider(IEditorInput input) {
if(input instanceof IFileEditorInput){
return new XMLTextDocumentProvider();
} else if(input instanceof IStorageEditorInput){
return new XMLFileDocumentProvider();
} else {
return new XMLTextDocumentProvider();
}
}
#Override
protected final void doSetInput(IEditorInput input) throws CoreException {
setDocumentProvider(createDocumentProvider(input));
super.doSetInput(input);
}
then in your new document provider (extending TextFileDocumentProvider) insert somethnig like this:
protected FileInfo createFileInfo(Object element) throws CoreException {
FileInfo info = super.createFileInfo(element);
if(info==null){
info = createEmptyFileInfo();
}
IDocument document = info.fTextFileBuffer.getDocument();
if (document != null) {
/* register your partitioner and other things here
same way as in your fisrt document provider */
}
return info;
}
This works for me :) Finally I have to mention, that I'm not so clever and that I copied this solution from project Amateras (Opensource HTML editor plugin for eclipse)
I'm a little away from the source code at the moment, though I suspect the problem is a ClassCastException:
For a workspace file, the IEditorInput is org.eclipse.ui.IFileEditorInput.
For a local non-workspace file, the IEditorInput is org.eclipse.ui.IStorageEditorInput
The difference is in how you get the contents from the IEditorInput. The JDT does an explicit instanceof check to make the switch.
I don't think that the getAdapter(Class clazz) will return a java.io.InputStream if you offer it.
I don't quite understand why they do it like this, but it feels ugly.
Edit:
A more general point about debugging eclipse apps - it's really very useful to try and assemble all your logs into one place (i.e. the console).
To do this, make sure you use the command line options -console and -consoleLog. The latter has helped save countless hours of time. If you haven't already, learn the most basic things about how to use the console (ss and start are my most often used). This will save some more time diagnosing a certain class of problem.
Did you try creating a JAVA file using the editor, outside the workspace?
When calling the editor with the file path, concat "file://" at the beginning of the file path.e.g: if the path is C://temp//Sample.java, then modify it as file://C://temp//Sample.java.