Rebuild eclipse editor - java

I have an eclipse plugin that ships with an editor.
I added a preference to change the color of the syntax highlighting but these changes only apply after I restart the editor manually.
I implemented syntax highlighting via an DefaultDamagerRepairer that gets a Scanner returning a token and in that token I define the respective color. I change the returning token via a PropertyChangeListener applied to the respective preference but as mentioned before the editor does not display the new color until I restart it.
Is there a way to rebuild or redraw the editor programatically?
I have found out that it will update the new colors partly if I start typing in the editor. I assume that this is because of the PresentationReconciler I have set up but I didn't find a way to force this reconciler to recompute the editor's content.

Call the invalidateTextPresentation method of your ITextViewer / ISourceViewer to get it to rebuild the whole screen using the new settings.

Related

How to extend Eclipse's Java editor to recognize my own elements

I want to add references to other elements inside javadoc. The javadoc should look similar to:
/**
* ...
* #my.tag SomeElement
*/
I want to reuse the existing Java editor inside Eclipse. Of course I can type above javadoc already, however I'd like to add some features:
Navigation: upon Ctrl-Click / F3 I want to navigate to the editor showing SomeElement
Auto-completion: Ctrl-Space should complete the text / show valid alternatives
Checking: I want to create a warning marker and underline the SomeElement if it cannot be found
I already figured out that I can do the auto-completion by using the extension point org.eclipse.jdt.ui.javaCompletionProposalComputer, though this seems to be little more complex than I had hoped, so I might be on the wrong track here?
For checking my elements I might be able to use org.eclipse.jdt.core.compilationParticipant, which can generate markers upon compilation which afaik happens with every save operation.
But how can I can manage the navigation feature? Any pointers are welcome!
For navigation you can provide a Hyperlink Detector. You'll want to look at how the Java Editor and its existing detectors are declared in the org.eclipse.jdt.ui plug-in to determine the correct target ID.

Java Rectangular Selection

I previously used rectangular selection mode on my Java project in eclipse, but after doing an Android project, ALT+SHIFT+A now opens this box instead:
How can I get the old behaviour back?
If a plugin messes with your keybindings, you can always go to:
Window > Preferences > General > Keys
There, you can search for Toggle Block Selection (which is what I think you mean by "rectangular selection") and either assign a different key combination to it, or change it back to Alt+Shift+A and (if you want) assign a different combination to whatever had replaced it.

How to add refactor option to my custom editor?

I have my own custom editor and now I want to add refactor option to this editor. I know I can add a new menu item for the same, but I want to use the existing refactor option. Like when user selects text and if it is valid variable (in Java) the all other variables are highlighted and later it is replaced. Also, I want to reuse the same refactor option and not provide new menu item.
Any pointers on how to go about this?
I followed the link: Eclipse rename/refactoring override
Now I get the notifications during each refactor but for my custom editor refactor -> rename menu is disabled. How do I enable it?

Best way to implement refusing a value change by the user in Swing?

I have a JCheckBox that should not be checked by the user when a certain other field is empty.
So now I want to have an error popup and then reset the checkbox (I've considered disabling the checkbox, but the connection to the other field is non-obvious, and a tooltip text IMO not visible enough).
What's the correct way to do that in Swing? Through a PropertyVetoException? Where do I throw it and where do I catch it? My first (probably ugly) idea would be to add a ChangeListener that itself shows the popup and resets the value.
Edit: The question is about Nikki (screenshot below), an app I am developing which geotags images and exports them to Google Earth's KMZ format. The checkbox is used to select the images to include in the export. But this requires the images to be gotagged first (which in turn requires either a timestamp, or manual assignment). I don't think this requirement can be made obvious through the UI layout.
(source: brazzy.de)
I would simply disable the check box and add a message explaining why the option is not available. A nice way to show the message is to display a mini exclamation mark next to the check box and put the message in a tooltip.
Poping up an exception often feels wrong because users don't read error messages. For most users an error message popup means that the application did something wrong, in your case it's the normal behavior.
Edit if you insist on letting the check box enabled, another way to show the user that some info is missing would be to flash the missing data. Eg. if latitude and longitude are missing and the user clicks on export, set a red background onto these fields for a just a second. This will clearly show the user what's missing.
In this screen, don't you want to put the mouse over the red circle to understand what's going on?
validation http://www.vogella.de/articles/EclipseDataBinding/images/validation10.gif
I don't think the Export JCheckBox should be disabled at all. Instead, the Export JButton itself should examine the current export list and display any anomalous entries in a way that allows navigation to a chosen photograph. If all entries are correct, Export would proceed as usual.
Addendum: It think you are right to keep the interface as non-modal as possible. My model for this would be unsaved files when exiting an editor or uncommitted changes when closing a project in an IDE.
If that's a status line at the bottom of the window, you might indicate the number of photographs currently selected for export, adding a count if any still need geocoding.
The field should simply be allowed to disable the checkbox. If the coupling is unintuitive then the GUI layout may have to be reconsidered.
EDIT: I ran it from your page, and I believe the issue here is that you actually have a third and fourth step in addition to select folder, select images. The third step is validate image, and fourth is select images for export. I think your problem is that this is not clearly conveyed in the current layout, and that reflects in your question.
I would suggest that you create a separate column containing the checkbox for each image, and that THAT checkbox is disabled until the image passes validation (step 3). Perhaps with an explanatory text in the column about why the image hasn't passed yet.

Changing the title on an editor when the input changes due to file rename

how would I go about updating the title bar of an Eclipse editor when the file input changes to reflect the new filename? For instance, when the file is renamed but you still have an editor open on the file. Everything I've done so far has failed, even when following the official guidelines on doing this (using special interfaces, classes, etc). The Java editor can seemingly do this fine. If I update the title and post the status update, it just doesn't update. Calling the update methods after this also doesn't update the editor title. Confusing.
Cheers,
Chris
This probably isn't the answer you are looking for but it does work.
Cast your editor to WorkbenchPart (not IWorkbenchPart) and call setPartName(String name).

Categories