I want to use some libraries from eclipse to create standalone application.
JFace provides for instance SourceViewer, which is great if you need to show some code in your app (that is what i need). SourceViewer looks like that eclipse editor area and you can configure it as you want. It is really great.
The SourceViewer is configured via
public void configure(SourceViewerConfiguration configuration)
There is JavaSourceViewerConfiguration, which is subclass of SourceViewerConfiguration and it should be good if you want show Java code.
This is JavaSourceViewerConfiguration constructor.
public JavaSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, ITextEditor editor, String partitioning)
The last two parameters could be null, so the QUESTION is how to obtain properly configured IColorManager and IPreferenceStore instances?
What i currently have:
SourceViewer sv = new SourceViewer(sf, new CompositeRuler(), SWT.NONE);
LineNumberRulerColumn lnRuler = new LineNumberRulerColumn();
sv.addVerticalRulerColumn(lnRuler);
PreferenceStore pf = new PreferenceStore();
IColorManager cm = (new JavaTextTools(pf)).getColorManager();
sv.configure(new JavaSourceViewerConfiguration(cm, pf, null, null));
But in this code i always got
Exception in thread "main" java.lang.NullPointerException
at org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration.getConfiguredTextHoverStateMasks(JavaSourceViewerConfiguration.java:639)
at org.eclipse.jface.text.source.SourceViewer.configure(SourceViewer.java:507)
at swtPokus.Main.main(Main.java:37)
I think it is because that PreferenceStore pf should be somehow configured so it contains keys and values which are used by the SourceViewer.
Question2 is where to get those value for PreferenceStore?
Related
as the tile describe, I would love to have the ability to add some cool touchbar buttons to my java application for MacBook Pro 2016 users.. I've not seen yet if there is a way to implement it in java yet.
Anyone got some knowledge on that?
There is a new Java library for interacting with the NSTouchBar API called JTouchBar.
For example using SWT
Shell shell = ...
JTouchBar jTouchBar = new JTouchBar();
jTouchBar.setCustomizationIdentifier("MySWTJavaTouchBar");
// flexible space
jTouchBar.addItem(new TouchBarItem(TouchBarItem.NSTouchBarItemIdentifierFlexibleSpace));
// button
TouchBarButton touchBarButtonImg = new TouchBarButton();
touchBarButtonImg.setTitle("Button 1");
touchBarButtonImg.setAction(new TouchBarViewAction() {
#Override
public void onCall( TouchBarView view ) {
System.out.println("Clicked Button_1.");
}
});
Image image = new Image();
img.setName(ImageName.NSImageNameTouchBarColorPickerFill);
touchBarButtonImg.setImage(image);
jTouchBar.addItem(new TouchBarItem("Button_1", touchBarButtonImg, true));
// label
TouchBarTextField touchBarTextField = new TouchBarTextField();
touchBarTextField.setStringValue("TextField 1");
jTouchBar.addItem(new TouchBarItem("TextField_1", touchBarTextField, true));
// enable touchbar
jTouchBar.enableForShell(shell);
You can find the library on Github:
https://github.com/Thizzer/JTouchBar
By the looks of it, apple doesn't provide support for adding items to the touch bar, never mind doing it in java.
While going through some documentation for the touch bar, it would appear that you will also need an instance of the NSTouchBarItem class. Java doesn't have that, nor provide a way to get that. I doubt that using native methods would work as well, seeing how the instance is app specific and is passed to the application through apple.
Accessing the bar is possible, but only natively.
I use Eclipse Luna 4.4.2
using the "externalize strings" wizard (from right click on the class in the package explorer) it replaces my original strings by another string pointing to the key in the property file.
For example, having this label defined in a class "myFrame" :
JLabel mylabel = new JLabel("original text");
after the wizard the result is:
JLabel mylabel = new JLabel(Messages.getString("myFrame.1")
I would prefer a behavior where the key would be constructed by the component name. It is what happen if I use the other wizard from the windowbuilder view. But this wizard has less options (you can't set to ignore..)
So this result would be better :
JLabel mylabel = new JLabel(Messages.getString("myFrame.mylabel.text")
or even something like
JLabel mylabel = new JLabel(Messages.myFrame_mylabel_text)
I spent a lot of time on searching and found this thread Configuring string externalization in Eclipse to use ${key} as field name
but it is old and I do not have the checkbox "use Eclipe's externalization mechanism" ?!
Also this thread says that the features have been implemented inside Eclipse http://blog.vogella.com/2013/08/12/eclipse-internationalization-part-44-new-features-by-dirk-fauth/
Did I miss some updates ? I installed te latest build of Eclipse-Mars, but it does not help..
Thank you for help !
I'm creating an editor using 'SourceViewer'. Given below is the code snippet from my '#PostConstruct' method.
// viewer is my SourceViewer instance
viewer = new SourceViewer(parent,verticalRuler, styles);
IUndoManager undoManager = new TextViewerUndoManager(25);
undoManager.connect(viewer);
viewer.setUndoManager(undoManager);
Even though a default 'TextViewerUndoManager' associated with 'SourceViewer'. Ctrl+Z and Ctrl+Y is not working.
Another alternative that I tried is to override the 'IUndoManager getUndoManager(ISourceViewer sourceViewer)' of 'SourceViewerConfiguration' subclass and return a 'TextViewerUndoManager'. This approach also doesn't give the desired result.
Kindly let me know what I'm missing in the above approaches.
It is normally the SourceViewerConfiguration that provides the Undo manager, the SourceViewer expects this and will set up the manager from that. The defaults already set up TextViewerUndoManager.
In an e4 application you do not get any default key bindings, commands or handlers so you will have to set up all these to make use of the undo manager.
In your application model declare Commands for undo and redo.
Declare key bindings for Ctrl+Z and Ctrl+Y specifying your commands. You might want to put the key bindings in a Binding Table that is specific to text editors.
Declare Handlers for the undo and redo commands, the code for undo might look like:
public class UndoHandler
{
#Inject
private Adapter _adapter;
#Execute
public void execute(#Named(IServiceConstants.ACTIVE_PART) final MPart part)
{
final ITextOperationTarget opTarget = _adapter.adapt(part.getObject(), ITextOperationTarget.class);
opTarget.doOperation(ITextOperationTarget.UNDO);
}
#CanExecute
public boolean canExecute(#Named(IServiceConstants.ACTIVE_PART) final MPart part)
{
final ITextOperationTarget opTarget = _adapter.adapt(part.getObject(), ITextOperationTarget.class);
if (opTarget == null)
return false;
return opTarget.canDoOperation(ITextOperationTarget.UNDO);
}
}
Redo would be similar but using ITextOperationTarget.REDO.
The order of doing/registering things is important. Be sure to connect the undo manager AFTER setting the document to the SourceViewer instance because on connect() the document will be retrieved from the viewer by the undo manager and if it doesn't find a document it will not register anything and undoable() will always return false.
I will start developing application for Windows. But I want to get rid of the cancel button and the typical Windows format like:
And I want it to look something like that, get rid of windows format and design my application in my own way.
So, will somebody suggest me, how to do that? I searched so much but cannot find any result.
If this app. is written using the Swing GUI toolkit, it is as simple as either using a JWindow, or calling Frame.setUndecorated(true).
Hard to tell what language your question is, here is answer for C++ for WinAPI:
Create your window like that:
HWND hWnd;
WNDCLASS WndCls;
// Create the application window
WndCls.style = CS_HREDRAW | CS_VREDRAW;
WndCls.lpfnWndProc = WndProcedure;
WndCls.cbClsExtra = 0;
WndCls.cbWndExtra = 0;
WndCls.hIcon = NULL;
WndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndCls.lpszMenuName = NULL;
WndCls.lpszClassName = _T("WndClassName");
WndCls.hInstance = GetModuleHandle(NULL);
// Register the window class
RegisterClass(&WndCls);
hWnd = CreateWindow(_T("MyWnd"),
_T("WndClassName"),
WS_BORDER,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
::GetModuleHandle(0),
NULL);
and then:
::ShowWindow(hWnd, SW_SHOW);
SetWindowLong(hWnd, GWL_STYLE, 0);
you will have a white rectangle app which you will be able to paint however you like.
Also, you can spy on window styles using Spy++ from Visual Studio package
It's called the Titlebar. Hide it by removing the form border style.
this.FormBorderStyle= System.Windows.Forms.FormBorderStyle.None;
In my eclipse RCP application i have a text filed to get some values from the user.
Is there any way in eclipse RCP or java to list the old entries while entering the new values [Like content assist]?
Please advice me.
You can use org.eclipse.jface.fieldassist.AutoCompleteField for this. For a text field it might look like this:
new AutoCompleteField(text, new TextContentAdapter(), new String [] {"proposal 1", ...});