Eclipse RCP: Right aligned search field in toolbar - eclipse-rcp

I would like to have a right aligned search field in the toolbar of an Eclipse RCP application. I already created the text field as ControlContribution and the respective search action in the ActionBarAdvisor class:
protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
//...
toolbar.add(new ControlContribution("searchText") {
//...
This works and I have the search field in the toolbar. But how can I align the search text (or the toolbar with the search text) on the right side?
Thanks,
Michael

If you mean positioning search toolbar on the right hand site of the main toolbar, then consider using these areas instead (when using org.eclipse.ui.menus extension point):
toolbar:org.eclipse.ui.main.toolbar - the top-level tool bar
toolbar:org.eclipse.ui.trim.command1 - the top left trim
toolbar:org.eclipse.ui.trim.command2 - the top right trim
toolbar:org.eclipse.ui.trim.vertical1 - the left vertical trim
toolbar:org.eclipse.ui.trim.vertical2 - the right vertical trim
toolbar:org.eclipse.ui.trim.status - the status line trim

Related

MPart toolbar too small for text ToolControl

I added a search text ToolControl to a MPart toolbar as described here:
Eclipse e4 tool Control in trimbars
http://www.vogella.com/tutorials/EclipseRCP/article.html#toolbar_advanced_toolcontrols
My problem is:
When I have another item (e.g. handled tool item with icon) in the toolbar, I can see most of the text, but not all. When there is no other item, I see just the upper line of the text.
The toolbar height seems not to be adapted to my control,
Whould be great if anyone can help me.
Christin
The basic problem is that although the ToolBar control allows controls as children it doesn't take their depth in to account when calculating the tool bar depth.
The Vogella example (which is intended for the window trim bar rather than a part tool bar) is using a default GridLayout which adds a margin above the search text. You could try using:
Composite comp = new Composite(parent, SWT.NONE);
// GridLayout with no margins
comp.setLayout(GridLayoutFactory.fillDefaults().create());
Text text = new Text(comp, SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL | SWT.BORDER);
text.setMessage("Search");
GridDataFactory.fillDefaults().hint(130, SWT.DEFAULT).applyTo(text);
That is using a GridLayout with no margins.

How to Change the cursor in JavaFX Accordion title bar

I'm using custom cursors and it need to be differ in some components in my screen.
When I set the cursor for Accordion, it doesn't effects title headers but effects the body of each TitledPanes. I even tried to set the cursor for each TitledPane but it doesn't effect the title header. I'm using following way to change the cursor.
ImageCursor cursor_title = new ImageCursor(cursorImg_title,cursorImg_title.getWidth() / 2,cursorImg_title.getHeight() / 2);
accordionBody.setCursor(cursor_title);
Is there a way to change the cursor in title bar of a JavaFX Accordian?
More....
I have changed the padding of title bars using css as follows. Hope it doesn't have any relation to the problem.
.titled-pane > .title {
-fx-padding: 30;
}
A TitledPane is divided into two parts :
Title
Content
When you are setting the Cursor on the Accordion, it delegates it to the content of each TitledPane, but leaves the Title. This is by design.
To force your application to change the cursor on the title as well, we need to set it on each of these nodes. We can fetch all the nodes by using the lookupAll() on the accordion and passing the styleclass they use i.e. .title. Make sure you use this after the scene graph is visible.
accordion.lookupAll(".title").forEach(node -> node.setCursor(Cursor.CLOSED_HAND));
You can use your custom cursor in place of CLOSED_HAND.

How can I switch between two menu bars occupying the same space below the window title in GTK3?

I like to switch menu bars depending on a button or internal state (COM port used). How can I do that in GTK3+ (preferably using Glade and GtkBuilder)? GtkOverlay does not seem to be the correct approach.
Put both menubars in a gtk(v)box and just declare one of the menubars as invisible in Glade (Leave the one you want by default visible). Then you can later switch menubars by hiding/showing them.
Mind, if you are on Ubuntu, you might run into problems. Ubuntu's Unity moves the menu bar to the top of the workspace, and it might not be happy with two menu bars just existing. In a program I made a couple of years ago Ubuntu refused to show the second menu (but I wasn't hiding either of them, so you might be in luck).
Thanks jcoppens for your answer, but I am not sure how the solution would look over all with one of the positions in the vertical box invisible but still occupying space / the height of one menu bar. Wouldn't that create a gap between either the title and the menu bar (first menu bar visible) or the menu bar and the container below (second menu bar visible)?
I solved it by (before I saw your answer):
Using Glade, create a new file and put the two menu bars in there.
In the Glade file for the main window, create a vertical box with one
item right below the title. (In my case, my main frame contains a
vertical box with three items, the first position is kept empty and
will contain one of the two menu bars, the second one contains all
other items inside another container, and the third item contains a
status bar.)
In the C module using GtkBuilder, I switch the menu bars as shown
below:
/**
* This function adds or replaces the menu bar.
* #param id id string for menu bar
*/
void amci_tester_set_menubar(const gchar *id) {
GtkWidget *menu_bar = GTK_WIDGET(gtk_builder_get_object(builder, id));
GtkBox *box_menu = GTK_BOX(gtk_builder_get_object(builder, "boxMainMenu"));
GList *children = gtk_container_get_children(GTK_CONTAINER(box_menu));
if (children != NULL)
gtk_container_remove(GTK_CONTAINER(box_menu), (GtkWidget *) g_list_first(children)->data);
gtk_box_pack_start(box_menu, menu_bar, false, false, 0);
// Although the visible property is shown as being set in the Glade GUI, in
// the Glade file it is not set.
gtk_widget_set_visible(menu_bar, true);
g_list_free(children);
}
In the beginning of main, I put the usual GtkBuilder stuff, instantiating a GtkBuilder object and then adding the default / first to be shown menu bar object:
// Init GTK+.
gtk_init(&argc, &argv);
// Create new GtkBuilder object from file.
builder = gtk_builder_new_from_file(glade_filename_app);
if (builder == NULL) {
g_warning("Could not create builder from %s", glade_filename_app);
return 1;
}
// Add menu bar for PC menu bar (default) from file.
if (!gtk_builder_add_from_file(builder, glade_filename_menu_pc, &error)) {
g_warning("%s", error->message);
g_free(error);
return 1;
}

Eclipse ui: retrieving the first visible line of an editor

In the Eclipse UI, I'd like to set the visible area in an editor. In other words, if the number of lines of my file is larger than the number of lines my editor can show then I want to specify the first shown line. My first approach was to calculate the first visible line via the selection value of its vertical scroll bar. The following link points to my initial question. Its answer explains how to set the first visible line in an editor.
eclipse ui: setting scrollbar but editor does not follow
The problem now is that my initial way of retrieving the first visible line in an editor fails in some cases: Although I verify that the active page is indeed an editor, the focus might be assigned to another page. In such a case, the following code yields the ScrollBar of a different page:
public static void update(final IWorkbenchWindow w)
final Scrollable scrollable =
(Scrollable) w.getWorkbench().getDisplay().getFocusControl();
final ScrollBar vScrollBar = scrollable.getVerticalBar();
So, my question: If editor is the reference of an active editor (ITextEditor and IReusableEditor), how to I get its first visible line?
If you can access the editor ITextViewer or its extension ISourceViewer (usually implemented by the SourceViewer or TextViewer class) you can call the ITextViewer.getTopIndex() method to get the top line index.
If your editor is derived from AbstractTextEditor (or one of its subclasses such as TextEditor) there is a protected method getSourceViewer() that returns this. You may have to add a public method if you want to access this from outside of the editor.

In GWT need to set the value of list box to the one,that was was selected in other selection

I have a full search panel with listbox whose value are read from DB.when a item in listbox selected and search is made.If the results are not found the search panel is condensed (one more search panel) and in condensed search ,we can change the search criteria ,selected a different item in the list box .after changing the search criteria and if search is made ,when the full search panel appears,the value of the list box in full search panel should be same as the one changed/selected in the condensed search panel.
How can we accomplish this.
In simple - If i have two list boxes, load a list box and set the value of the listbox same the other listbox.If value of one listbox is changed, the other should be changed and the value of this listbox is set with the value selected in the previous one.
I would do the following
//you have something like this
ListBox listbox1;
ListBox listbox2;
//add a change handler
listbox1.addChangeHandler(new ChangeHandler() {
#Override
public void onChange(ChangeEvent event)
{
int index = listbox1.getSelectedIndex();
//do your update code here for listbox2
//like a listbox2.setSelectedIndex(index) or something
}
As far as I see its an easy implementation. Add a value change handler on the first listbox and do whatever you want in onChange method.
Regarding your panel need to be collapsed when there is no search results, you can always use vertical panel and set its height to 100% and add another panel to it or Use Dock Panel and add panels to south or best use disclosure panel and play around with it.