I'm new to plugin development for IntelliJ.
I'm using JBTextField as a text input so I can set the placeholder text using JBTextField.getEmptyText().setText(...) method.
But according to the IntelliJ Platform UI Guidelines it says:
Hide the placeholder when the user starts typing, not when the input field gets the focus.
which is not the way that the textfield itself does. It hides the placeholder when it gets focus.
The question is, how can I change this behavior so that the placeholder disappears when the user type something (For example something like the native IDE's "New Class" popup window).
I found a solution based on this answer by Yann Cebron.
The default behavior from com.intellij.ui.components.TextComponentEmptyText#isStatusVisible can be customized via JBTextField.STATUS_VISIBLE_FUNCTION property which is a reference to a BooleanFunction<JTextComponent>.
So we can reference a boolean function to the STATUS_VISIBLE_FUNCTION key like this:
import com.intellij.ui.components.JBTextField;
import com.intellij.ui.components.TextComponentEmptyText;
import com.intellij.util.BooleanFunction;
textField = new JBTextField();
textField.getEmptyText().setText("Placeholder...");
textField.putClientProperty(
TextComponentEmptyText.STATUS_VISIBLE_FUNCTION,
(BooleanFunction<JBTextField>) tf -> tf.getText().isEmpty()
);
Related
I am currently using a IWorkingSetSelectionDialog created by a IWorkingSetManager. By default, clicking on the "new..." button in this dialog asks the user which type of working set should be created. But I would like to restrict to Java working sets, as in Package Explorer. Anyone know how this could be achieved?
I think if you use the:
public IWorkingSetSelectionDialog createWorkingSetSelectionDialog(
Shell parentShell, boolean multi, String[] workingsSetIds)
method and specify the Java working set id (org.eclipse.jdt.ui.JavaWorkingSetPage in the final parameter:
new String [] {"org.eclipse.jdt.ui.JavaWorkingSetPage"}
you will get what you want.
I am a newcomer to Eclipse PreferencePages and am currently creating a new FieldEditorPreferencePage for my project. However, having FileFieldEditors() or DirectoryFieldEditors() greys-out the "Apply" and "OK" buttons in my custom preference page. On the other hand, the other FieldEditors (Boolean- and Combo-) do not disable the "Apply" and "OK" buttons.
Furthermore, changing everything to Xtext's LanguageRootPreferencePage seems to work as well (though I'd prefer not to use it as I want the custom preference page to show up in it's own tab).
For example:
//Simplified example of code
public class XPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage, IWorkbenchPropertyPage {
public XPreferencePage() {
super(FieldEditorPreferencePage.GRID);
setDescription("something");
}
protected void initialize() {
super.initalize();
//IPropertyChangeListeners go here
}
protected void createFieldEditors() {
//"Apply" and "OK" works here
g = new BooleanFieldEditor(SConstants.GENERATOR, "Generate Bindings", getFieldEditorParent());
addField(g);
//"Apply" and "OK" is greyed-out starting here
gp = new FileFieldEditor(SConstants.GENERATOR_PATH, "Generator Path:", false, 0, getFieldEditorParent());
gp.setEmptyStringAllowed(true);
addField(gp);
...
}
...
}
Is there anyway to fix this? I followed the tutorial from Eclipse Article-Field-Editors but it doesn't seem to work for me. Reading online says it can be due to negative IntegerField (which I don't have) or that I'm trying to change the default settings (which I don't have either).
I am using Eclipse Mars 4.5.0.
UPDATE: The code above (partially) worked for FileFieldEditors. However, for some reason I need to click FileFieldEditor field and check and uncheck the checkbox directly above the FileFieldEditor for each FileFieldEditor in the preference page before the "Apply" and "OK" buttons are available again.
Furthermore, I have also implemented a IPropertyChangeListener which deactivates certain fields when certain checkboxes are unchecked which means this "check and uncheck" workaround would not work for me. I have also tried setting the default focus to one of my checkboxes but that didn't work
FileFieldEditor(String name, String labelText, Composite parent) defalult validates the path when the text widget loose the focus that is what you are giving invalid as default value.
For e.g. if you give C:\\User\\XXX then this path should physically exist then and only it will not grey out ok and apply button.
You can also use below constructor by setting your validation stratergy.
FileFieldEditor(String name, String labelText,boolean enforceAbsolute, int validationStrategy, Composite parent)
value of validationStrategy
1 for the editor performs validation only when the text widget
loses focus.
0 for the editor performs validation after every key
stroke.
I created a custom eclipse editor (AbstractDecoratedTextEditor) and I implemented an auto-complete feature using IContentAssistProcessor.
In the class thats extends IContentAssistProcessor, I overrided the method computeCompletionProposals that returns a list of ICompletionProposal.
But when the auto-complete dialog is running, I cant show the additional information in yellow dialog like in Java.
For example, in Java I have the Javadoc dialog:
But in my custom auto-complete I cant create this yellow dialog to show additional information.
How can I create this dialog?
For the additional information popup to show, you need two things:
ICompletionProposal#getAdditionalProposalInfo() must return a string that contains the information, that's what you probably already have.
the ContentAssistant that is used to show the proposals must have an IInformationControlCreator set. Use contentAssistant.setInformationControlCreator() to assign one. Here is an example of an information control creator:
class SimpleInformationControlCreator implements IInformationControlCreator {
public IInformationControl createInformationControl( Shell shell ) {
return new DefaultInformationControl( shell, true );
}
}
I've been struggling with the problem in the subject for a bit longer than I'd like to admit.
I'm attempting to programatically execute the same Action that occurs when the user either clicks on the View > Collapse All button or right-clicks within the editor window and then Code Folding > Fold All.
What I tried\found so far:
The String that corresponds to the Action may be found in the enum com.mathworks.mde.editor.ActionID and is: 'collapse-all-folds'.
When the Action activates, the following method seems to be executed: org.netbeans.api.editor.fold.FoldUtilities.collapseAll(...) (hence the netbeans tag).
This code allows me to get instances of EditorAction, ActionManager, MatlabEditor:
jEd = com.mathworks.mlservices.MLEditorServices.getEditorApplication.getActiveEditor;
jAm = com.mathworks.mde.editor.ActionManager(jEd);
jAc = com.mathworks.mde.editor.EditorAction('collapse-all-folds');
My problem is that I can't find a way to actually activate the Action.
Any ideas / alternatives?
EDIT1: After digging a bit in "the book", I think I came even closer than before (but still not quite there). Quoting from the book:
Java GUI components often use anActionMapto store runnableActionsthat are
invoked by listeners on mouse, keyboard, property, or container events. Unlike object methods,Actionscannot be directly invoked by MATLAB.
And then a workaround is explained which involves roughly: getting some sort of an Action object; creating an ActionEvent and invoking Action's actionPerformed with the ActionEvent as an argument, as implemented below:
import java.awt.event.*;
jEd = com.mathworks.mlservices.MLEditorServices.getEditorApplication.getActiveEditor;
jAm = com.mathworks.mde.editor.ActionManager(jEd);
jAc = jAm.getAction(com.mathworks.mde.editor.EditorAction('collapse-all-folds'));
jAe = ActionEvent(jAm, ActionEvent.ACTION_PERFORMED, '');
jAc.actionPerformed(jAe);
This code runs without errors - but does (seemingly?) nothing. I suspect that I'm calling ActionEvent and actionPerformed on the wrong objects (ActionManager has possibly nothing to do with this problem at all).
P.S.
I know that there's a hotkey that does this (Ctrl + =), but this is not what I'm looking for (unless there's a command to simulate a hotkey press :) ).
After immeasurable digging, trial and way too much error - I've done it!
function FullyCollapseCurrentScript()
%// Get the relevant javax.swing.text.JTextComponent:
jTc = com.mathworks.mlservices.MLEditorServices ...
.getEditorApplication.getActiveEditor.getTextComponent();
%// Get the FoldHierarchy for the JTextComponent:
jFh = org.netbeans.api.editor.fold.FoldHierarchy.get(jTc);
%// Finally, collapse every possible fold:
org.netbeans.api.editor.fold.FoldUtilities.collapseAll(jFh);
end
or if compressed into a single, messy, command:
org.netbeans.api.editor.fold.FoldUtilities.collapseAll(...
org.netbeans.api.editor.fold.FoldHierarchy.get(com.mathworks. ...
mlservices.MLEditorServices.getEditorApplication.getActiveEditor. ...
getTextComponent()));
Note that this works on the script currently open in the editor.
Not a perfect solution but simulating the default hotkey press with java.awt.robot is possible.
...finding a way to actually fire the Action directly would be better...
import java.awt.Robot;
import java.awt.event.*;
RoboKey = Robot;
jTextComp = com.mathworks.mlservices.MLEditorServices. ...
getEditorApplication.getActiveEditor.getTextComponent;
jTextComp.grabFocus()
drawnow; %// give time for focus
if jTextComp.hasFocus()
RoboKey.keyPress(KeyEvent.VK_CONTROL);
RoboKey.keyPress(KeyEvent.VK_EQUALS);
RoboKey.keyRelease(KeyEvent.VK_CONTROL);
RoboKey.keyRelease(KeyEvent.VK_EQUALS);
com.mathworks.mde.cmdwin.CmdWin.getInstance.grabFocus; %// focus back to cmdwin
else
warning('Failed to collapse folds: Editor could not take focus')
end
I have a RCP applicaton from which I need to show a GEF Editor in a modal "dialog". But since the editor framework seems to be tightly coupled to the use of a workbench window etc I need to find a why to open a new workbench window (with its own WorkbenchWindowAdvisor etc) so that I can open my GEF editor within this workbench window. Once I get this workbenchWindow opened I will set the style of the WorkbenchWindow's shell to be application modal.
I have done this in a customer project using the following components:
A static class with a method openNewWindow(String type, ...). This is the method you call to open a new window. The type argument specifies the wanted type of window.
The class looks up the specified type via a new extension point to get an ILocalWorkbenchWindowAdvisor and the initial perspective ID.
It then saves the information in global variables and calls IWorkbench.openWorkbenchWindow(perspectiveID, ...)
In ApplicationWorkbenchAdvisor.createWorkbenchWindowAdvisor(...) a new advisor is create based on the saved ILocalWorkbenchWindowAdvisor - the returned advisor basically delegates all the postWindowCreate(...), etc to the same methods in ILocalWorkbenchWindowAdvisor...
If no ILocalWorkbenchWindowAdvisor is saved - which is the case for the very first window to be opened - the type "mainWindow" is looked up and used...
It works pretty well and let all parts of the project add new windows as needed.
Use the command "org.eclipse.ui.window.newWindow" to open a new window. In your WorkbenchWindowAdvisor.preWindowOpen(), set the shell style on the IWorkbenchWindowConfigurer to be application modal. You can also hide the coolbar, menu and status bars, so it looks more like a dialog than a window.