Freezing the tool tip after clicking on it - eclipse

I am trying use org.eclipse.jface.window.DefaultToolTip to display some UI components like checkbox,radio buttons placed on composite. When user clicks on a text, the tooltip with pops up to and displays the UI components.
Issue: I want to freeze tool tip once user clicks inside this tooltip. Using toolTip.setHideOnMouseDown(false); I am able to check/un-check the check boxes/radio buttons as long as I am inside the tool tip area. Once mouse pointer exits the tool tip area, the tooltip disappears. How can this be avoided. I am looking for similar behaviour which is available for eclipse tooltips( javadoc, method definition). In Eclipse tooltip, if we click/press f2, tooltip will remain active until we click outside of the tooltip area.
Edit: I also tried to use Eclipse Plugin Spy on tooltip, but no success.
Any thoughts.

What Eclipse does when F2 is pressed is to create a new Shell with exactly the same size and contents as the tooltip and closes the original tooltip.
I use code like the following in an extended tooltip class:
/**
* Switch from tool tip to a normal window.
*/
private void showWindow()
{
if (_control.isDisposed())
return;
final Shell shell = new Shell(_control.getShell(), SWT.CLOSE | SWT.ON_TOP | SWT.RESIZE);
shell.setLayout(new FillLayout());
createBody(shell);
final Point currLoc = _parent.getShell().getLocation();
final Rectangle client = _parent.getClientArea();
final Rectangle bounds = shell.computeTrim(currLoc.x, currLoc.y, client.width, client.height);
shell.setBounds(bounds);
shell.open();
// Hide the tool tip window
hide();
}
_control is the control passed to the constructor.

Related

Is there a way to have a Window object be always on top of another Window object? (Modal Dialog)

public void ShowDialog()
{
Window dialogWindow = new Window(new SampleDialog());
Application.Current.OpenWindow(dialogWindow);
// dialogWindow should always be on top of MainPage Window
}
I will be needing a modal dialog to be on top of another modal dialog as well. like how Save Dialogs are on top of lets say the notepad app and the the prompt "Do you want to replace it?" dialog is on top of the save dialog.
I have tried Community toolkit popup. but it can only have 1 popup per window. PushModalAsync is not a desirable outcome as it is still preferred to have separated dialogs.
According to the official docuement about the Windows in .Net Maui, the X and Y property of the Windows can set the position of it. But I tried to use the two properties, they didn't work.
Here is my Code:
Window window = new Window(new NewPage1());
window.MaximumHeight = 200;
window.MaximumWidth = 400;
var width = App.Current.Windows.First().Width;
var height = App.Current.Windows.First().Height;
window.X = width/2;
window.Y = height/2;
You can create a project with .net 7(These propertoes doesn't exist in the .net 6) to test. In addition, you can report it to the maui on the github.

How to refresh GXT's combo box after each call

I have a combo box. When I click a link, it opens a popup including a combo box (with data loaded from database). It always keeps data from the first call (it does not refresh).
How can I refresh this?
VerticalPanel vp = new VerticalPanel();
vp.setSpacing(10);
ListStore<State> states = new ListStore<State>();
states.add(getStates());
ComboBox<State> combo = new ComboBox<State>();
combo.setEmptyText("Select a state...");
combo.setDisplayField("name");
combo.setWidth(150);
combo.setStore(states);
combo.setTypeAhead(true);
combo.setTriggerAction(TriggerAction.ALL);
vp.add(combo);
Assuming, that you are working with GXT and there fore are using the GXT Window class, you can do something like this:
myWindow.addBeforeShowHandler(new BeforeShowEvent.BeforeShowHandler() {
#Override
public void onBeforeShow(BeforeShowEvent event) {
mxComoBox.clear();
}
});
You see the old value, because a popup will be reused. so you have to clear the value of the combo, when the popup get visible.
This code should work with GXT 3.1.2. Older versions of GXT might have a different coding.
Hope that helps.

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.

gtkmm button not maintaining size and location

I have created two gtkmm button and added to HBox object. I called pack_end, and maintained the size as 21,20. But, the sizes are not maintained. Here is the code i have written and the window that i got while running the program.
Note: MYWindow is subclass of Gtk::Window
void MYWindow::customizeTitleBar()
{
//create a vertical box
Gtk::VBox *vBox = new Gtk::VBox(FALSE,0);
//create a horizontal box
Gtk::HBox *hBox = new Gtk::HBox(TRUE,0);
hBox->set_border_width(5);
//create title bar image
Gtk::Image *titleBarImage = new Gtk::Image("src/WindowTitleBar.png");
titleBarImage->set_alignment(Gtk::ALIGN_LEFT);
// hBox->pack_start(*titleBarImage,Gtk::PACK_EXPAND_WIDGET,0);
//create cloze button for window
mButtonClose = new Gtk::Button;
(*mButtonClose).set_size_request(21,20);
Gtk::Image *mImage = new Gtk::Image("src/Maximize.jpeg");
(*mButtonClose).add(*mImage);
(*mButtonClose).set_image_position(Gtk::POS_TOP);
// connecting close window function when cliked on close button
//(*mButtonClose).signal_clicked().connect( sigc::mem_fun(this, &MYWindow::closeWindow));
hBox->pack_end(*mButtonClose,Gtk::PACK_EXPAND_WIDGET,0);
Gtk::Button * mBtton = new Gtk::Button;
mBtton->set_size_request(21,20);
Gtk::Image *img = new Gtk::Image("src/Maximize.jpeg");
mBtton->add(*img);
mBtton->set_image_position(Gtk::POS_TOP);
hBox->pack_end(*mBtton,Gtk::PACK_EXPAND_WIDGET,0);
vBox->add(*hBox);
//drawing area box
Gtk::HBox *hBoxDrawingArea = new Gtk::HBox;
Gtk::DrawingArea *mDrawingArea = new Gtk::DrawingArea;
hBoxDrawingArea->pack_start(*mDrawingArea,Gtk::PACK_EXPAND_WIDGET,0);
vBox->add(*hBoxDrawingArea);
//status bar hBox
Gtk::HBox *hBoxStatusBar = new Gtk::HBox;
vBox->add(*hBoxStatusBar);
this->add(*vBox);
this->show_all();
}
I am not yet a gtk expert (but I'm learning), here's one thing you can try, which is what I've been doing.
Make a little standalone project using glade. Glade makes it really easy to screw around with all the packing settings so you can immediately see the effects of your changes.
I think in the case of resizing the window, you'll have to save the glade file and run your program (using gtkbuilder to render the glade file) and manually resize the window to see the effect, but once you make the standalone project, you can use it for other gtk testing.
And if you're like me, you'll get swayed by the wonderfulness that is glade and build your whole system that way.
But basically, it sounds like a packing issue, because I've got buttons that don't resize all over the place.
As for not moving, I'm not sure you can do that, but again I'm not an expert. I think you should be able to pin the size of some if not all of the hbox pieces so that the button inside them will not move, but I'm not sure what happens if you don't have any hbox parts that can't be variably sized to take up the slack when you grow the window.
Again, sounds like something fun to try in glade. :-)
I think you pack to FALSE , Maybe this is the problem :
Gtk::HBox *hBox = new Gtk::HBox(TRUE,0)
I use python gtk with something like this:
box1.pack_start(box2,False)

Drawing into an Eclipse editor

I am trying to draw some shapes (boxed ans arrows) into, i.e., "over" the text in an eclipse editor. To get started, I wrote the following code:
IWorkbenchPage activePage = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
final Shell shell2 = activePage.getActiveEditor().getSite().getShell();
shell2.addPaintListener(new PaintListener(){
public void paintControl(PaintEvent e){
Rectangle clientArea = shell2.getClientArea();
e.gc.drawLine(0,0,clientArea.width,clientArea.height);
}
});
The problem with this code is twofold: (1) The line is drawn not across the editor but across the entire workbench, i.e., Eclipse window, and (2) the line is drawn behind (!) all other controls like toolbars and editors. This causes the line to be almost invisible: it only shows at some pixels between other controls.
How can I draw a line across a control like a text editor in Eclipse?
The problem that you have is that you are getting the Shell, not the actual component for the editor. The Shell is the whole window where Eclipse is being shown.
I think the only solution is to create your own Editor implementation, and then in the createPartControl() method you can create a text area and then add the paint listener to it.
You can get started with:
http://www.realsolve.co.uk/site/tech/jface-text.php
And then, looking at the source code of AbstractTextEditor, you can find the "real" SWT component that you want to draw to. You would need to override the method that creates the UI components, copy the original code and add your custom painting.
I'm not sure if it works, but you need to extend the TextEditor:
public class MyEditor extends TextEditor {
protected StyledText createTextWidget(Composite parent, int styles) {
StyledText widget = super.createTextWidget( parent, styles );
widget.addPaintListener( <yourPaintlistener> );
return widget;
}
}
That should at least get you the basic text-drawing control of the editor. Still, it's a PITA to work with these classes, as it is very internal stuff from eclipse, and neither documented nor really extensible.
Good luck with that :)