Enable only Java working sets in IWorkingSetSelectionDialog - java

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.

Related

How to hide JBTextField placeholder when user starts typing

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()
);

How to show addicional information popup in auto-complete using IContentAssistProcessor

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

How to implement printing in chrome pacakaged app created from GWT Application.?

I have integrated the GWT application with Chrome packaged app with help of DirectLinkerinstaller like the code below:
public class CSPCompatibleLinker extends DirectInstallLinker {
#Override
protected String getJsInstallLocation(LinkerContext context) {
return "com/google/gwt/core/ext/linker/impl/installLocationMainWindow.js";
}
}
But now I want to call print function from Chrome packaged app. When I call window.print() it allows me to print current window, but I need to open a new separate window and print that.
Could you anyone please help me in this?
I can't answer anything about GWT or DirectLinkerinstaller, but here's an answer about Chrome Apps, assuming that's what you're asking about:
You use the chrome.app.window.create API to create a window. Then, you can call the print method for that window.
In my apps, I seldom want to print what's in a window, but rather something I've generated specifically for printing. For that, I create a PDF with jsPDF (Google it), which works well. Then I display the PDF in a window, and let the user print the PDF (or save it).

Eclipse RCP: Custom console

I am trying to create a console that would work as a shell for a custom programming language. It would be very similar to the pydev interactive console.
Currently, my RCP uses the basic TextConsole and is connected to the shell via pipes so it just displays whatever the shell displays and if the user enters anything in the RCP console, the same is written in the shell.
I want to be able to do a bit more such as move the caret position, add events for up and down arrow keys etc. I believe to do that I need to add a StyledText widget to the console which is done via the ConsoleViewer.
So my question is, that is there any way for me to either override the TextConsole's ConsoleViewer or if I were to extend TextConsole and create my own, then how do I link it with the launch configuration (the one that connects the shell via pipes)?
Also, to get the current default console I use DebugUITools.getConsole(process).
I'm sorry if I haven't put all the information needed; it is a bit difficult to explain. I am happy to add more information.
An idea...
From what I understand I can create a TextConsolePage from the TextConsole using createPage(ConsoleView). Once I have the page I can set the viewer via setViewer(viewer). Here I thought if I create my own viewer (which will have the appropriate stylewidget) then that could be a lead. The only problem is that the viewer needs a Composite and I can't seem to figure out where to get that from.
Why don't you just follow what PyDev does (if you're able to cope with the EPL license)?
The relevant code may be found at:
https://github.com/aptana/Pydev/tree/ad4fd3512c899b73264e4ee981be0c4b69ed5b27/plugins/org.python.pydev/src_dltk_console
https://github.com/aptana/Pydev/tree/ad4fd3512c899b73264e4ee981be0c4b69ed5b27/plugins/org.python.pydev.debug/src_console
So I thought I would answer this myself as I was finally able to accomplish the console. It still is a working prototype but I guess as you keep adding things, you can clean up the code more and more. For my current purposes this is how it worked.
If you want the short version, then I basically mimicked the ProcessConsole provided by Eclipse as that is what I needed: a console in which I can connect a process but since the ProcessConsole is internal, I like to avoid extending those classes.
Following is an outline of the classes I used to achieve interaction with my console. I am not going to give the pretext as to where MyConsole was created. Basically, instead of using DebugUITools.getConsole(myProcess), I used my own myProcess.getConsole() method. MyProcess extends RuntimeProcess.
class MyConsole extends IOConsole {
private IOConsoleInputStream fInput;
private IOConsoleOutputStream fOutput;
private IStreamsProxy fStreamsProxy;
private ConsoleHistory history;
//This is to remember the caret position after the prompt
private int caretAtPrompt;
/* in the console so when you need to replace the command on up and down
* arrow keys you have the position.
* I just did a caretAtPrompt += String.Length wherever string was
* appended to the console. Mainly in the streamlistener and
* InputJob unless you specifically output something to the output
* stream.
*/
//In the constructor you assign all the above fields. Below are some
//to point out.
//fInput = getInputStream();
// fStreamsProxy = process.getStreamsProxy();
// fOutput = newOutputStream();
//We must override the following method to get access to the caret
#Override
public IPageBookViewPage createPage(IConsoleView view) {
return new MyConsolePage(this, view);
}
//After this I followed the ProcessConsole and added the
//InputJob and StreamListener
//defined in there.
}
class MyConsolePage extends TextConsolePage {
//Not much in this class, just override the createViewer
// to return MyConsoleViewer
}
class MyConsoleViewer extends TextConsoleViewer {
//This is the most important class and most of the work is done here
//Again I basically copied everything from IOConsoleViewer and then
//updated whatever I needed
//I added a VerifyKeyListener for the up and down arrow
//keys for the console history
MyConsoleViewer (Composite parent, MyConsole console) {
//I have omitted a lot of code as it was too much to put up,
//just highlighted a few
getTextWidget().addVerifyKeyListener(new MyKeyChecker());
}
class MyKeyChecker implements VerifyKeyListener {...}
}
This is the code for ProcessConsole.
This is the code for IOConsoleViewer.
The ConsoleHistory class I created just had a doubly linked string list to save all the commands the user entered. Quite a simple class to create.
Once you look at the Eclipse classes (ProcessConsole and IOConsoleViewer) it is actually all quite self explanatory. I haven't put in much code here because there is quite a bit. But hopefully this gives some direction as I was completely lost when I started.
I am happy to answer questions though and add more specific code if anyone asks.

How do I open a new workbench window (with its own WorkbenchWindowAdvisor) from an existing workbench window?

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.

Categories

Resources