use of org.eclipse.swt.events.ControlListener in project eclipse.jdt.ui by eclipse-jdt.
the class ResizableDialog method getInitialSize.
@Override
protected Point getInitialSize() {
int width = 0;
int height = 0;
final Shell s = getShell();
if (s != null) {
s.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent arg0) {
fNewBounds = s.getBounds();
}
@Override
public void controlResized(ControlEvent arg0) {
fNewBounds = s.getBounds();
}
});
}
IDialogSettings bounds = fSettings.getSection(DIALOG_BOUNDS_KEY);
if (bounds == null) {
if (fBundle != null) {
width = JavaCompareUtilities.getInteger(fBundle, WIDTH, 0);
height = JavaCompareUtilities.getInteger(fBundle, HEIGHT, 0);
Shell shell = getParentShell();
if (shell != null) {
Point parentSize = shell.getSize();
if (width <= 0)
width = parentSize.x - 300;
if (height <= 0)
height = parentSize.y - 200;
}
} else {
Shell shell = getParentShell();
if (shell != null) {
Point parentSize = shell.getSize();
width = parentSize.x - 100;
height = parentSize.y - 100;
}
}
if (width < 700)
width = 700;
if (height < 500)
height = 500;
} else {
try {
width = bounds.getInt(WIDTH);
} catch (NumberFormatException e) {
width = 700;
}
try {
height = bounds.getInt(HEIGHT);
} catch (NumberFormatException e) {
height = 500;
}
}
return new Point(width, height);
}
use of org.eclipse.swt.events.ControlListener in project eclipse.jdt.ui by eclipse-jdt.
the class BreadcrumbItemDropDown method installCloser.
/**
* The closer closes the given shell when the focus is lost.
*
* @param shell the shell to install the closer to
*/
private void installCloser(final Shell shell) {
final Listener focusListener = event -> {
Widget focusElement = event.widget;
boolean isFocusBreadcrumbTreeFocusWidget = focusElement == shell || focusElement instanceof Tree && ((Tree) focusElement).getShell() == shell;
boolean isFocusWidgetParentShell = focusElement instanceof Control && ((Control) focusElement).getShell().getParent() == shell;
switch(event.type) {
case SWT.FocusIn:
if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
// $NON-NLS-1$
System.out.println("focusIn - is breadcrumb tree: " + isFocusBreadcrumbTreeFocusWidget);
if (!isFocusBreadcrumbTreeFocusWidget && !isFocusWidgetParentShell) {
if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
// $NON-NLS-1$
System.out.println("==> closing shell since focus in other widget");
shell.close();
}
break;
case SWT.FocusOut:
if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
// $NON-NLS-1$
System.out.println("focusOut - is breadcrumb tree: " + isFocusBreadcrumbTreeFocusWidget);
if (event.display.getActiveShell() == null) {
if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
// $NON-NLS-1$
System.out.println("==> closing shell since event.display.getActiveShell() == null");
shell.close();
}
break;
default:
Assert.isTrue(false);
}
};
final Display display = shell.getDisplay();
display.addFilter(SWT.FocusIn, focusListener);
display.addFilter(SWT.FocusOut, focusListener);
final ControlListener controlListener = new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
shell.close();
}
@Override
public void controlResized(ControlEvent e) {
shell.close();
}
};
fToolBar.getShell().addControlListener(controlListener);
shell.addDisposeListener(e -> {
if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
// $NON-NLS-1$
System.out.println("==> shell disposed");
display.removeFilter(SWT.FocusIn, focusListener);
display.removeFilter(SWT.FocusOut, focusListener);
if (!fToolBar.isDisposed()) {
fToolBar.getShell().removeControlListener(controlListener);
}
});
shell.addShellListener(new ShellListener() {
@Override
public void shellActivated(ShellEvent e) {
}
@Override
public void shellClosed(ShellEvent e) {
if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
// $NON-NLS-1$
System.out.println("==> shellClosed");
if (!fMenuIsShown)
return;
fMenuIsShown = false;
fDropDownViewer = null;
}
@Override
public void shellDeactivated(ShellEvent e) {
}
@Override
public void shellDeiconified(ShellEvent e) {
}
@Override
public void shellIconified(ShellEvent e) {
}
});
}
use of org.eclipse.swt.events.ControlListener in project org.eclipse.rap by eclipse-rap.
the class WBWRenderer method hookControllerLogic.
@Override
public void hookControllerLogic(MUIElement me) {
super.hookControllerLogic(me);
Widget widget = (Widget) me.getWidget();
if (widget instanceof Shell && me instanceof MWindow) {
final Shell shell = (Shell) widget;
final MWindow w = (MWindow) me;
shell.addControlListener(new ControlListener() {
/**
*/
private static final long serialVersionUID = 1L;
@Override
public void controlResized(ControlEvent e) {
// Don't store the maximized size in the model
if (shell.getMaximized())
return;
try {
ignoreSizeChanges = true;
w.setWidth(shell.getSize().x);
w.setHeight(shell.getSize().y);
} finally {
ignoreSizeChanges = false;
}
}
@Override
public void controlMoved(ControlEvent e) {
// Don't store the maximized size in the model
if (shell.getMaximized())
return;
try {
ignoreSizeChanges = true;
w.setX(shell.getLocation().x);
w.setY(shell.getLocation().y);
} finally {
ignoreSizeChanges = false;
}
}
});
shell.addShellListener(new ShellAdapter() {
/**
*/
private static final long serialVersionUID = 1L;
@Override
public void shellClosed(ShellEvent e) {
// override the shell close event
e.doit = false;
MWindow window = (MWindow) e.widget.getData(OWNING_ME);
IWindowCloseHandler closeHandler = window.getContext().get(IWindowCloseHandler.class);
// request, clean-up as necessary
if (closeHandler == null || closeHandler.close(window)) {
cleanUp(window);
}
}
});
shell.addListener(SWT.Activate, new Listener() {
/**
*/
private static final long serialVersionUID = 1L;
@Override
public void handleEvent(org.eclipse.swt.widgets.Event event) {
MUIElement parentME = w.getParent();
if (parentME instanceof MApplication) {
MApplication app = (MApplication) parentME;
app.setSelectedElement(w);
w.getContext().activate();
} else if (parentME == null) {
parentME = (MUIElement) ((EObject) w).eContainer();
if (parentME instanceof MContext) {
w.getContext().activate();
}
}
updateNonFocusState(SWT.Activate, w);
}
});
shell.addListener(SWT.Deactivate, new Listener() {
/**
*/
private static final long serialVersionUID = 1L;
@Override
public void handleEvent(org.eclipse.swt.widgets.Event event) {
updateNonFocusState(SWT.Deactivate, w);
}
});
}
}
use of org.eclipse.swt.events.ControlListener in project org.eclipse.rap by eclipse-rap.
the class GridColumn_Test method testAddRemoveControlListener.
@Test
public void testAddRemoveControlListener() {
ControlListener listener = new ControlAdapter() {
};
assertFalse(column.isListening(SWT.Move));
assertFalse(column.isListening(SWT.Resize));
column.addControlListener(listener);
assertTrue(column.isListening(SWT.Move));
assertTrue(column.isListening(SWT.Resize));
column.removeControlListener(listener);
assertFalse(column.isListening(SWT.Move));
assertFalse(column.isListening(SWT.Resize));
}
use of org.eclipse.swt.events.ControlListener in project org.eclipse.rap by eclipse-rap.
the class Shell_Test method testFullScreen.
@Test
public void testFullScreen() {
final java.util.List<String> log = new ArrayList<String>();
Rectangle displayBounds = new Rectangle(0, 0, 800, 600);
getDisplayAdapter(display).setBounds(displayBounds);
Rectangle shellBounds = new Rectangle(10, 10, 100, 100);
shell.setBounds(shellBounds);
shell.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent event) {
log.add("controlMoved");
}
@Override
public void controlResized(ControlEvent event) {
log.add("controlResized");
}
});
shell.open();
assertFalse(shell.getFullScreen());
assertFalse(shell.getMaximized());
assertFalse(shell.getMinimized());
log.clear();
shell.setMaximized(true);
assertFalse(shell.getFullScreen());
assertTrue(shell.getMaximized());
assertFalse(shell.getMinimized());
assertEquals(2, log.size());
assertEquals("controlMoved", log.get(0));
assertEquals("controlResized", log.get(1));
assertEquals(displayBounds, shell.getBounds());
shell.setMinimized(true);
assertFalse(shell.getFullScreen());
assertFalse(shell.getMaximized());
assertTrue(shell.getMinimized());
shell.setMinimized(false);
assertFalse(shell.getFullScreen());
assertTrue(shell.getMaximized());
assertFalse(shell.getMinimized());
log.clear();
shell.setFullScreen(true);
assertTrue(shell.getFullScreen());
assertFalse(shell.getMaximized());
assertFalse(shell.getMinimized());
assertEquals(0, log.size());
assertEquals(displayBounds, shell.getBounds());
log.clear();
shell.setMaximized(true);
assertTrue(shell.getFullScreen());
assertFalse(shell.getMaximized());
assertFalse(shell.getMinimized());
assertEquals(0, log.size());
assertEquals(displayBounds, shell.getBounds());
log.clear();
shell.setMaximized(false);
assertTrue(shell.getFullScreen());
assertFalse(shell.getMaximized());
assertFalse(shell.getMinimized());
assertEquals(0, log.size());
assertEquals(displayBounds, shell.getBounds());
log.clear();
shell.setMinimized(true);
assertTrue(shell.getFullScreen());
assertFalse(shell.getMaximized());
assertTrue(shell.getMinimized());
assertEquals(0, log.size());
log.clear();
shell.setMinimized(false);
assertTrue(shell.getFullScreen());
assertFalse(shell.getMaximized());
assertFalse(shell.getMinimized());
assertEquals(0, log.size());
log.clear();
shell.setFullScreen(false);
assertFalse(shell.getFullScreen());
assertTrue(shell.getMaximized());
assertFalse(shell.getMinimized());
assertEquals(0, log.size());
assertEquals(displayBounds, shell.getBounds());
shell.setMaximized(false);
shell.setMinimized(true);
log.clear();
shell.setFullScreen(true);
assertTrue(shell.getFullScreen());
assertFalse(shell.getMaximized());
assertFalse(shell.getMinimized());
assertEquals(2, log.size());
assertEquals("controlMoved", log.get(0));
assertEquals("controlResized", log.get(1));
assertEquals(displayBounds, shell.getBounds());
log.clear();
shell.setFullScreen(false);
assertFalse(shell.getFullScreen());
assertFalse(shell.getMaximized());
assertFalse(shell.getMinimized());
assertEquals(2, log.size());
assertEquals("controlMoved", log.get(0));
assertEquals("controlResized", log.get(1));
assertEquals(shellBounds, shell.getBounds());
shell.setFullScreen(true);
log.clear();
shell.setBounds(20, 20, 200, 200);
assertFalse(shell.getFullScreen());
assertFalse(shell.getMaximized());
assertFalse(shell.getMinimized());
assertEquals(2, log.size());
assertEquals("controlMoved", log.get(0));
assertEquals("controlResized", log.get(1));
}
Aggregations