private static void writeText(final Shell shell) throws IOException { String text = shell.getText(); if (WidgetLCAUtil.hasChanged(shell, PROP_TEXT, text, "")) { // JSWriter writer = JSWriter.getWriterFor( shell ); text = WidgetLCAUtil.escapeText(text, false); // writer.set( JSConst.QX_FIELD_CAPTION, text ); IWidgetSynchronizer synchronizer = WidgetSynchronizerFactory.getSynchronizerForWidget(shell); synchronizer.setWidgetProperty(JSConst.QX_FIELD_CAPTION, text); } }
public void preserveValues(final Widget widget) { ControlLCAUtil.preserveValues((Control) widget); Shell shell = (Shell) widget; IWidgetAdapter adapter = WidgetUtil.getAdapter(shell); adapter.preserve(PROP_ACTIVE_CONTROL, getActiveControl(shell)); adapter.preserve(PROP_ACTIVE_SHELL, shell.getDisplay().getActiveShell()); adapter.preserve(PROP_TEXT, shell.getText()); adapter.preserve(PROP_IMAGE, shell.getImage()); adapter.preserve(PROP_ALPHA, new Integer(shell.getAlpha())); adapter.preserve(PROP_MODE, getMode(shell)); adapter.preserve(PROP_FULLSCREEN, Boolean.valueOf(shell.getFullScreen())); adapter.preserve(PROP_SHELL_LISTENER, Boolean.valueOf(ShellEvent.hasListener(shell))); adapter.preserve(PROP_SHELL_MENU, shell.getMenuBar()); adapter.preserve(PROP_MINIMUM_SIZE, shell.getMinimumSize()); WidgetLCAUtil.preserveCustomVariant(shell); }
private boolean closeAddressBook() { if (isModified) { // ask user if they want to save current address book MessageBox box = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO | SWT.CANCEL); box.setText(shell.getText()); box.setMessage(resAddressBook.getString("Close_save")); int choice = box.open(); if (choice == SWT.CANCEL) { return false; } else if (choice == SWT.YES) { if (!save()) return false; } } TableItem[] items = table.getItems(); for (int i = 0; i < items.length; i++) { items[i].dispose(); } return true; }
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Text Editor"); Menu bar = new Menu(shell, SWT.BAR); shell.setMenuBar(bar); MenuItem fileItem = new MenuItem(bar, SWT.CASCADE); fileItem.setText("&File"); Menu fileMenu = new Menu(shell, SWT.DROP_DOWN); fileItem.setMenu(fileMenu); MenuItem saveItem = new MenuItem(fileMenu, SWT.PUSH); saveItem.setText("&Save\tCtrl+S"); saveItem.setAccelerator(SWT.MOD1 + 'S'); saveItem.addListener(SWT.Selection, e -> shell.setModified(false)); MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH); exitItem.setText("Exit"); exitItem.addListener(SWT.Selection, e -> shell.close()); Text text = new Text(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); text.addListener(SWT.Modify, e -> shell.setModified(true)); shell.addListener( SWT.Close, e -> { if (shell.getModified()) { MessageBox box = new MessageBox(shell, SWT.PRIMARY_MODAL | SWT.OK | SWT.CANCEL); box.setText(shell.getText()); box.setMessage("You have unsaved changes, do you want to exit?"); e.doit = box.open() == SWT.OK; } }); shell.setLayout(new FillLayout()); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }