reload compare editor input - java

I have a CompareEditorInput shown in CompareEditor, it compares textual data. I need to reload CompareEditorInput when it is changed outside of CompareEditor.
Open compare editor (CompareUI.openCompareEditor(input))
Compare input is changed (ISteramContentAccessor.getContents() returns changed content)
Tell opened compare editor to reload CompareEditorInput <- needs to be implemented.

You could call setInput(sameInput) on CompareEditor, but since CompareEditor is internal and setInput() is not public in EditorPart then a workaround is to call IEditorPart.init(IEditorSite site, IEditorInput input).
IWorkbenchWindow wnd = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IEditorPart editor = wnd.getActivePage().findEditor(input);
editor.init((IEditorSite) editor.getSite(), input);

The new java io package java.nio.file package provides a file change notification API, called the Watch Service API. using this you can monitor the file on the disk and track for any changes. Check this for further reference
Create a separate thread which uses the WatchService API and monitors the file in the background and if finds any changes on disk, notify the user.

Related

eXist-db embedded mode backup / restore

I'm attempting to use eXist-db in embedded mode in a Java program to produce an interactive fiction game.
Is there any information on invoking backups and restores from within my own java application, so as to initially load the story and all files, and then to perform a save/restore function?
Also, any suggestions on how to format my xml for such use would be appreciated.
You can invoke the backup directly by passing in the URI of your embedded eXist instance. For example:
import org.exist.backup.Backup;
//omitted for brevity
final Backup backup = new Backup("admin, "adminPass", "xmldb:exist:///db")
backup.backup(false, null);
You can use any collection path instead of just /db. Also if you are running this from within a Swing application you can use:
backup.backup(true, frame);
To have a backup dialog appear.
Hope that helps.

Eclipse plugin - accessing the editor

So, I’m currently developing a plugin for the eclipse IDE. In a nutshell, the plugin is a collaborative real time code editor where the editor is eclipse (which is something like Google documents but with the code and on eclipse). Meaning that when I install the plugin, I would be able to connect -using my Gmail account- eclipse to the partner’s eclipse. And when I start coding on my machine, my partner would be seeing what I write and vice versa.
The problem I’m currently facing is accessing eclipse’s editor. For example, I have to monitor all the changes in the active document so that every time a change happens, the other partner’s IDE would be notified with this change.
I found and read about the IDcoumentProvider, IDocument and IEditorInput classes and they’re somehow connected but I can’t understand this connection or how to use it. So if someone can explain this connection I would really appreciate it. Also if there is another way to achieve my goal?
You can access the IEditorPart via the IWorkbenchPage.
IEditorPart editor = ((IWorkbenchPage) PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()).getActiveEditor();
From there, you have access to various other classes, including the editor's IEditorInput, the File loaded by that editor, or the underlying GUI Control element. (Note that depending on the kind of editor (text files, diagram, etc.) you may have to cast to different classes.)
FileEditorInput input = (FileEditorInput) editor.getEditorInput();
StyledText editorControl = ((StyledText) editor.getAdapter(Control.class));
String path = input.getFile().getRawLocationURI().getRawPath();
Now, you can add a listener to the Control, e.g. a KeyAdapter for monitoring all key strokes occurring in the respective editor.
editorControl.addKeyListener(new KeyAdapter() {
#Override
public void keyPressed(KeyEvent e) {
System.out.println("Editing in file " + path);
}
});
Or, if monitoring all key strokes is too much, you can register an IPropertyListener to the editor. This listener will e.g. be notified whenever the editor gets 'dirty' or when it is saved. The meaning of propId can be found in IWorkbenchPartConstants.
editor.addPropertyListener(new IPropertyListener() {
#Override
public void propertyChanged(Object source, int propId) {
if (propId == IWorkbenchPartConstants.PROP_DIRTY) {
System.out.println("'Dirty' Property Changed");
}
}
});

Skip missing editor files when starting workbench

The standard behavior of the Eclipse workbench is to preserve the set of open files between invocations, and attempt to reopen those same files on restart. If any of the files is missing, then a placeholder editor appears showing an error message about the missing file. We'd like to change the behavior of our Eclipse RCP application to just silently skip any missing files instead.
We're already writing our own IApplication, WorkbenchAdvisor, etc; these classes get to inject various behaviors into the platform, but I haven't found a way to accomplish these through these classes. How could we implement the desired behavior?
The way I've handled this is actually in the editor being created: Override setInput to examine the IEditorInput being passed in for validity by calling editorInput.exists() (which, in the case of a FileEditorInput, checks to see if the file exists) or if you're using custom editor inputs, any other validation you need.
If the editorInput fails validation, then close the editor asynchronously (Eclipse doesn't like it when an editor closes before it finishes opening):
public void close () {
Display.getDefault().asyncExec(new Runnable () {
public void run () {
getSite().getPage().closeEditor(YourEditorClass.this, false);
}
});
}
An alternative way of handling this issue is to just disable reopening the editors on startup - see In Eclipse, how to close the open files(editors) when exiting without auto-load in next startup

Take action on NetBean's editor's window closing

We are using NetBeans Platform 7.0.1, and have implemented support for a new language using this (now “obsolete”) tutorial.
Since all our contents are stored in a database, and not on files, we open them like this:
FileSystem fs = FileUtil.createMemoryFileSystem();
FileObject fo = fs.getRoot().createData(fileName, fileExtension);
… write contents from database to `fo` ….
DataObject data = MyMultiDataObject.find(fo);
EditorCookie.Observable cookie = data.getCookie(EditorCookie.Observable.class);
cookie.open();
… forces undock of editor window …
And, in our layer.xml, have added a custom button to Save that sends the content back to the database.
However, when the user closes the file (by either closing the tab or the window), we haven’t figured a way of saving it.
Adding a PropertyChangeListener to the Cookie and watching for PROP_DOCUMENT (and newValue() == null) seems to do the trick for when the window is closed. But how does one get the return value from the confirmation window (I’m referring to when the file is closed after changes, the message File xxx.xxx is modified. Save it?)?
Well, it seems we've been approaching the problem in the wrong way.
Since we are opening the file in-memory, it was suggested in the netbeans-dev list that we should listen for changes in the file itself, by using
fo.addFileChangeListener(new CustomFileChangeListener());
public class CustomFileChangeListener implements FileChangeListener {
#Override
public void fileChanged(FileEvent fe) {
... file has been saved in the editor, sync with database ...
}
}
And keep it synchronized that way, taking advantage of the built-in NetBeans Platform "save" functionality.

Where do I localize strings in some of the menu items with Netbeans?

So I made a standard swing application in Netbeans 6.8 but I can't find where the resource file that defines the localized string for the Exit menu item under File.
It doesn't seem to be defined among the resource files in <project>/resources. Is this a standard string somewhere or am I missing something?
The "Exit" string doesn't get defined as a localized string like the File menu item -- it gets generated into code through the Netbeans GUI builder. That is why you don't see it in the properties file.
If you open the file {ProjectName}View.java you can see that it gets defined through the netbeans GUI builder. Click on the file menu and then the exit menu item in the GUI builder and you can look at the properties of the swing item. One of the properties is the text of the JMenuItem.
Then these properties get generated into code.
Are you just trying to shut down your application in such a way that you are able to do clean-up tasks before the system shuts down? If so then on the Java Sun site they say that you need to override the shutdown method; specifically :
#Override
protected void shutdown() {
// The default shutdown saves session window state.
super.shutdown();
// Now perform any other shutdown tasks you need.
}
This is located at this location

Categories

Resources