Add a custom widget in a CoolBar? - java

Is it possible in a standalone SWT/JFace application to add a custom widget in a CoolBarManager (a text box for exemple) ?
I look for IContributionItem but I didn't find useful examples.
HelpSearchContributionItem seems to work only with a RCP application (it uses objects from RCP : IWorkbenchWindow for example).
Thanks in advance

You should subclass ControlContribution and implement createControl() method.
Then add a ToolBarManager/ToolBarManagerContributionItem to the coolbar, and your subclass of ControlContribution to the ToolBarManager.

Although it is not recommended, you can subclass the ToolItem class and provide your own implementation. To do this you also have to override the checkSubclass method.
public class MyToolItem extends ToolItem {
#Override
protected void checkSubClass(){
// leave it empty
}
}

Related

Gwtbootstrap3. Using bootstrap component only with java code- without ui-binder

Is there possibile to use bootstrap3 elements (from gwtboostrap3 library) without using ui binder, but using java code like it is done with gwt regular widgets?
I could not find a word about it in Documentation.
F.E. Lets take button widget from gwt:
public void onModuleLoad() {
// Make a new button that does something when you click it.
Button b = new Button("Jump!", new ClickHandler() {
public void onClick(ClickEvent event) {
Window.alert("How high?");
}
});
// Add it to the root panel.
RootPanel.get().add(b);
}
}
Which will create:
<button type="button" class="gwt-Button">Jump!</button>
In gwtbootstrap3 I have to do something like that:
<b:Button type="DEFAULT"/>
Please help me with that.
Is it possible to use gwtbootstrap3 library components like button with pure java instead of uibinder xml files?
Is there solution that works out of box?
Or maybe I should write my own classess that extends native gwt widget an add bootstrap releated css classes?
Yes!
You can use the widget as you please, refer to the their javadoc to see what constructors they have! They are a different set of widgets and might not be analogue of GWT standard widgets.
Bonus
GWT UiBinder does no different than you, all it does is reduce the boilerplate, generating java classes that automate the instantiate of the widgets. You can add the compiler option -gen to see these transient classes. Usually , they are deleted after GWT compiles your application, as they are no longer needed. Take a look the the compiler documentation for more info!

Is it possible to add a message bar/ toolbar at the bottom of a titleareadialog?

With my TitleAreaDialog is it possible to add a area or a bar across the bottom, below the buttons. That a message can be displayed to the users, when a operation is taking place.
Here is a example of what I am referring to
AFAIK, this is not possible for JFace Dialogs. Depending on what exactly you are doing, you might want to have a look at JFace ApplicationWindow. This class has a method addStatusLine(). You would have to override the following method:
#Override
protected StatusLineManager createStatusLineManager() {
StatusLineManager statusLineManager = new StatusLineManager();
statusLineManager.setMessage(null, "YOUR_MESSAGE");
return statusLineManager;
}
You can change the text with:
getStatusLineManager().setMessage("YOUR_NEW_MESSAGE");
Here is an excellent overview of the ApplicationWindow class.

Copy tooltip to clipboard

I have a Java program with icons, tooltips...
What I need is that every time a tooltip is showed, the containing text should be copied to the windows clipboard.
Any solution should be a general single solution for all the tooltips. I cannot change the properties of each one of them (there are thousands...)
Thank you!
The way I see it, if you are indeed using Swing, you might need to subclass your components and override createToolTip():
class MyJButton extends JButton {
#Override
public JToolTip createToolTip() {
return new MyJTooltip();
}
}
And:
class MyJTooltip extends JToolTip {
#Override
public void setVisible(boolean aFlag) {
super.setVisible(aFlag);
//copy your text to clipboard here
}
}
Not very practical, not very pretty, but I can't think of another way right now: AFAIK, there is no way to subclass TooltipManager and make it be used as the default.
If you are using JavaFX, things get much easier:
new Button().setTooltip(new MyJavaFxTooltip());

Detecting if a listener has been registered

How can I detect if a new listener has been registered for any widget in my android app? Is there a place where I can intercept the listener when it's being registered?
I may be misunderstanding but you could do something like:
public interface ListenerChangeListener { // Feel free to remove the redundancy :P
public void listenerAdded(ListenerChangeEvent e);
public void listenerRemoved(ListenerChangeEvent e);
}
And
public class ListenerChangeEvent extends AWTEvent // or other class {
// Implementation
}
Finally, subclass your own custom widgets and modify the addXListener() and removeXListener() methods to fire your custom events if any have been added to the component. Then you just create your "Listener" class as per normal and implement your new Listener interface and so on.
It's a bit long and drawn out, again, I may have misunderstood exactly what you were after.
You can get a list of listeners on an object through a getter method (e.g. getActionListeners () on AbstractButton), and check if the one you have added is in the list.

Why do I need to overide "onPlaceRequest" in every Presenter class?

I'm managing the History in my project via Places.
What I do is this:
implement PlaceRequestHandler on top level (for example AppController),
register it -> eventBus.addHandler(PlaceRequestEvent.getType(), this);
implement method "onPlaceRequest" ,where i do project navigation.
I'm using GWT presenter and every presenter in my project overrides the onPlaceRequest method.
Why do I need this, when every request is handled from the top level "onPlaceRequest" method?
I will give an example:
public class AppController implements Presenter, PlaceRequestHandler
...........
public void bind()
{
eventBus.addHandler(PlaceRequestEvent.getType(), this);
...
}
public void onPlaceRequest(PlaceRequestEvent event)
{
// here is the project navigation tree
}
and let's take one presenter
public class SomePresenter extends Presenter<SomePresenter.Display>
{
... here some methods are overriden and
#Override
protected void onPlaceRequest(PlaceRequest request)
{
// what should I do here?
}
}
What is the idea, and how I'm supposed to use it?
Instead of making all of your presenters extend PlaceRequestHandler and managing those events yourself, you can attach a PlaceHistoryHandler and a PlaceController to your event bus. Together, they manage the browser's history and your places for you. When you ask your PlaceController to goTo() a different place, it will stop your current activity and use a mapping of places to activities (your presenters) to choose which one to start next.
To use this technique, you need to have your presenters extend AbstractActivity. Try following through Google's tutorial about it in GWT's documentation called GWT Development with Activities and Places.

Categories

Resources