Eclipse: Ctrl+Shift+Right is incorrect - java

Consider this simple class:
package net.zomis.test;
public class Test {
public Test() {
}
public void registerSomething(String key) {
}
}
When I have the cursor placed right before registerSomething and pressing CtrlShift→, I'm used to Eclipse only selecting register at first. But now, it selects the entire registerSomething text, when I press it again it selects the entire method (from public void to }), when I press it again it selects the entire class, and the last time the entire file is selected. The exactly same thing happens if I press CtrlShift←.
Also, when I simply click the End key, I get an option to choose: Line End or Text End.
What has gone wrong in my settings for this to happen? Where can I find these keybindings?
If it matters, I have this workspace within my Dropbox-folder to synchronize it between my PC and Mac.

Turns our that the fact that I had the workspace in my Dropbox folder matters a lot. Note to everybody else: Do not share your workspace between computers. How I solved this is the following:
Create a new workspace on each computer
In the computer-specific workspace, import projects from your shared Dropbox/other folder
I noticed that when having a shared workspace on the computers, the Mac somehow changed the key-bindings to the Mac-version, which made them not work on the PC. The correct Ctrl+Shift+→ key-binding on Mac is Alt+Shift+→.
So by using a separate workspace on each computer, I can use that computer's specific key-bindings, without mixing them up.

Open the preferences dialog from the Main Menu: Window->Preferences.
In the dialog, open General->Keys. You'll see a table of keybindings, with a field with type filter text. In that field, type: Ctrl+Shift+Right, and you'll narrow the table down to this key.
The behavior that you expect - only register is selected with the first keypress - is the behavior that I see when using Ctrl+Shift+Right, and the keybinding for me is: Select Next Word.
There is a Restore Command button that should reset this binding if it has been changed.

Related

Eclipse RCP 4.x - Defining workspace location

I know that this question was asked many times, but I didn't find an exact answer which would fulfill my desires :)
Long story short:
I've got simple E4 application, product project, feature and main plugin with simple trim window.
Works, after exporting works too.
Now. I add lifeCycleURI property, create bundleclass for it and create simple dialog with Text area and a Button. Run it\export it and it works, before running main Trim Window dialog is shown. Fine.. Cool etc.
But I want to enter location eg. C:\TEST and after clicking button I want it to be my workspace area for the application (with .metedata and so on). HOW ???
Of course I've tried with :
Location instanceLocation = Platform.getInstanceLocation();
instanceLocation.set(new URL("file", null, "C:\TEST"), false);
But... It says that I can't change location cause it is already set... Tried to use above in Activator. The same. Tried to add
-data #noDefault in products Launching Arguments ... The same...
I always try to accomplish my tasks by myself but this.... this... ehh... Help ?
You should be able to do this in the #PostContextCreate method of the life cycle class. Don't specify the '-data' argument
#PostContextCreate
public void postContextCreate()
{
Location instanceLoc = Platform.getInstanceLocation();
// Stop if location is set
if (instanceLoc.isSet())
return;
File file = new File("C:\\TEST");
instanceLocation.set(file.toURL(), false);
}
Note: You need '\\' in your file path.
This is adapted from code which I use in my e4 RCP.
If you are currently testing the application from within Eclipse you will need to clear the workspace location in the 'Run Configuration' for the application. Open 'Run > Run Configurations', find your application and clear the 'Location' field on the 'Main' tab.

Label and comment make a web address. An Easter egg in Netbeans?

It is well known, that if we'll put a web address as a line in a Java method, it should and would be interpreted as a label with // comment after it.
public static void setUpClass() throws Exception {
https://www.google.cz/ <------------------------------- This one
FailOnThreadViolationRepaintManager.install();
}
It seems, that NetBeans has one more interpretation for that: It really interprets the whole line as a web address. It works as web address! When mouse-hovering over it with pressed Ctrl you see the name of the site, and if you click, the page appears in the default browser.
Is it a bug? A feature? Or an Easter egg?
Edit.
Eclipse works almost the same way. But it shows the line as a link only with pressed CTRL + hovering. Whereas Netbeans shows it as a link constantly.

How to set seperate global action handler for multiple instance of eclipse form based plugin editor

I am working on eclipse form based editor. I have given support of handling of Undo Redo and dirty flag to my editor.Both of these feature working fine for single instances of plugin. Problem is coming when i open it with 2 or more files (2 or more instances of eclipse plugin). Now, undo redo starts working weird. They work only for instances that is opened at last.
for eg: Suppose my editor supports '.xeb' file. if i open test1.xeb and test2.xeb files one by one using with my editor. then undo redo only works for instances that is opened for test2.xeb file. If i switch back to other instances, then undo redo of first instance gets appear.
i have below entries in my editor's plugin.xml:
<plugin><extension
point="org.eclipse.ui.editors">
<editor
class="Testeditor"
default="true"
extensions="xeb"
icon="icons/sample.gif"
id="testeditor"
name="editor">
</editor>
</plugin>
i debugged the code and found that this weird behavior is happening due to handling of global action in wrong way.I used below code to set global action handler:
public void setUndoRedoActionHandlers() {
final IActionBars actionBars = getEditorSite().getActionBars();
actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
mUndoAction);
actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
mRedoAction);
actionBars.updateActionBars();
}
i went through some links related to this issue. but couldn't understood the concept to implement this behavior.
http://wiki.eclipse.org/FAQ_How_do_I_find_out_what_view_or_editor_is_selected%3F
http://wiki.eclipse.org/FAQ_How_do_I_hook_into_global_actions,_such_as_Copy_and_Delete%3F
Can any one look into this issue. Thanks in advance.
only override the setFocus() method of MultiPageEditorPart in you editor class and call the appropriate method of setting the global action handler,like this way:
#Override
public void setFocus() {
switch (getActivePage()) {
case 0:
pageOne.setUndoRedoActionHandlers();
break;
case 1:
pageTwo.setUndoRedoActionHandlers();
break;
}
super.setFocus();
}

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");
}
}
});

Is there a way to expand a JFileChooser directory without a mouse

Using a JFileChooser, I can select a directory by double clicking the directory (going down a level) with my mouse. Is there a way to select a directory without the mouse? For example, is there a key binding to go down a directory level or do I have to somehow add a key listener to the JFileChooser?
You should be able to use tab to move between the different parts of the chooser, and then use the arrow keys to change which directory is highlighted, and then press Enter to change the directory to the highlighted one.
I have tested the following example code on my machine (Vista/JDK 1.6) and it works as I would expect:
import javax.swing.*;
public class test {
public static void main(String[] args) {
(new JFileChooser("")).showOpenDialog(new JFrame());
System.out.println("OK!");
}
}
If your project is not responding similiarly in your JFileChooser, I would debug as follows:
Create test.java with only the code necessary to pop up a chooser.
If the test app differently than within your app, its something in your code causing it to fail, such as UI skinning code, keyboard listeners, etc. Modify the example, one change at a time to closer replicate your settings for your chooser in your app and see if you can pinpoint where it breaks.
If even a basic test app doesn't work right, it is probably something about your setup, such as a bug in your JDK version, your OS, etc. Troubleshoot your setup.
Have you tried the space-bar or enter key?
Try using ctrl+enter key to select directory.
This behavior is happened when you set to JFileChooser file selection mode to “files and direcories”:
JFileChooser fileBrowser = new JFileChooser();
fileBrowser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

Categories

Resources