To show a custom area for toolbar.

To show a custom area for toolbar.

public void postWindowOpen() {
//...
}

//Add to postWindowOpen()
final IWorkbenchWindow window = getWindowConfigurer().getWindow();

Listener listener = new Listener() {
private Shell toolbar;

public void handleEvent(Event event) {
Control control = (Control) event.widget;
Point mouse = control.toDisplay(event.x, event.y);
final Shell shell = window.getShell();
Point location = shell.getLocation();
Point size = shell.getSize();
int xIndent = 2;
int yIndent = 24;
int height = 30;
if (mouse.x > location.x
&& mouse.y > location.y + yIndent
&& location.x + size.x > mouse.x
&& location.y + yIndent + height > mouse.y) {
if (toolbar == null) {
toolbar = new Shell(shell, SWT.NO_TRIM);
toolbar.setSize(size.x - 2 * xIndent, height);
toolbar.setLocation(location.x + xIndent, location.y + yIndent);
GridLayout layout = new GridLayout(24, false);
layout.marginLeft = 0;
layout.marginTop = 0;
toolbar.setLayout(layout);
new Button(toolbar, SWT.PUSH).setText("action 1");
new Button(toolbar, SWT.PUSH).setText("action 2");
new Button(toolbar, SWT.PUSH).setText("action 3");
toolbar.setVisible(true);
}
} else {
if (toolbar != null) {
toolbar.dispose();
toolbar = null;
}
}
}
};

window.getShell().getDisplay().addFilter(SWT.MouseMove, listener);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章