List of usage examples for org.eclipse.jface.dialogs PopupDialog PopupDialog
@Deprecated public PopupDialog(Shell parent, int shellStyle, boolean takeFocusOnOpen, boolean persistBounds, boolean showDialogMenu, boolean showPersistActions, String titleText, String infoText)
PopupDialog. From source file:com.nokia.tools.ui.tooltip.CompositeInformationControl.java
License:Open Source License
public CompositeInformationControl(Shell parentShell, int shellStyle, final int style, String statusFieldText) { shellStyle = shellStyle | SWT.NO_FOCUS; fPopupDialog = new PopupDialog(parentShell, shellStyle, false, false, false, false, null, statusFieldText) { protected Control createDialogArea(Composite parent) { composite = createComposite(parent, style); composite.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.character == 0x1B) // ESC close();// w w w . j a va2s . c o m } public void keyReleased(KeyEvent e) { } }); return composite; } }; fPopupDialog.create(); }
From source file:org.eclipse.rap.demo.presentation.DemoPresentationWorkbenchWindowAdvisor.java
License:Open Source License
private void createMenuBar(final Composite banner) { final Composite menuBar = new Composite(banner, SWT.NONE); menuBar.setBackgroundMode(SWT.INHERIT_FORCE); FormData fdMenuBar = new FormData(); menuBar.setLayoutData(fdMenuBar);/*from w w w . ja v a 2 s . c om*/ fdMenuBar.top = new FormAttachment(100, -26); fdMenuBar.left = new FormAttachment(0, 10); fdMenuBar.bottom = new FormAttachment(100, -8); final ApplicationWindow window = (ApplicationWindow) getWindowConfigurer().getWindow(); MenuManager menuBarManager = window.getMenuBarManager(); IContributionItem[] menuBarItems = menuBarManager.getItems(); List<Action> actions = new ArrayList<Action>(); for (int i = 0; i < menuBarItems.length; i++) { final MenuManager menuManager = (MenuManager) menuBarItems[i]; actions.add(new Action() { @Override public String getId() { return menuManager.getId(); } @Override public String getText() { return menuManager.getMenuText(); } @Override public void run() { final Shell shell = window.getShell(); final Color background = new Color(shell.getDisplay(), 9, 34, 60); final PopupDialog popupDialog = new PopupDialog(shell, SWT.RESIZE | SWT.ON_TOP, false, false, false, false, null, null) { @Override protected Control createDialogArea(Composite parent) { final Composite popup = new Composite(parent, SWT.NONE); popup.setBackgroundMode(SWT.INHERIT_FORCE); popup.setLayout(new FormLayout()); popup.setBackground(background); Label roundedCornerLeft = new Label(popup, SWT.NONE); roundedCornerLeft.setImage(Images.IMG_BANNER_ROUNDED_LEFT); roundedCornerLeft.pack(); FormData fdRoundedCornerLeft = new FormData(); roundedCornerLeft.setLayoutData(fdRoundedCornerLeft); fdRoundedCornerLeft.top = new FormAttachment(100, -5); fdRoundedCornerLeft.left = new FormAttachment(0, 0); Label roundedCornerRight = new Label(popup, SWT.NONE); roundedCornerRight.setImage(Images.IMG_BANNER_ROUNDED_RIGHT); roundedCornerRight.pack(); FormData fdRoundedCornerRight = new FormData(); roundedCornerRight.setLayoutData(fdRoundedCornerRight); fdRoundedCornerRight.top = new FormAttachment(100, -5); fdRoundedCornerRight.left = new FormAttachment(100, -5); final Composite content = new Composite(popup, SWT.NONE); FormData fdContent = new FormData(); content.setLayoutData(fdContent); fdContent.top = new FormAttachment(0, 5); fdContent.left = new FormAttachment(0, 14); content.setLayout(new FillLayout(SWT.VERTICAL)); IContributionItem[] menuItems = menuManager.getItems(); for (int j = 0; j < menuItems.length; j++) { IContributionItem contributionItem = menuItems[j]; if (contributionItem instanceof ActionContributionItem) { ActionContributionItem actionItem = (ActionContributionItem) contributionItem; Action action = (Action) actionItem.getAction(); new ActionBarButton(action, content) { @Override public void run() { close(); super.run(); } }; } } content.pack(); return popup; } }; final Composite popup = new Composite(shell, SWT.NONE); popup.setBackgroundMode(SWT.INHERIT_FORCE); popup.setLayout(new FormLayout()); Label roundedCornerLeft = new Label(popup, SWT.NONE); roundedCornerLeft.setImage(Images.IMG_BANNER_ROUNDED_LEFT); roundedCornerLeft.pack(); FormData fdRoundedCornerLeft = new FormData(); roundedCornerLeft.setLayoutData(fdRoundedCornerLeft); fdRoundedCornerLeft.top = new FormAttachment(100, -5); fdRoundedCornerLeft.left = new FormAttachment(0, 0); roundedCornerLeft.moveAbove(banner); Label roundedCornerRight = new Label(popup, SWT.NONE); roundedCornerRight.setImage(Images.IMG_BANNER_ROUNDED_RIGHT); roundedCornerRight.pack(); FormData fdRoundedCornerRight = new FormData(); roundedCornerRight.setLayoutData(fdRoundedCornerRight); fdRoundedCornerRight.top = new FormAttachment(100, -5); fdRoundedCornerRight.left = new FormAttachment(100, -5); roundedCornerRight.moveAbove(banner); final Composite content = new Composite(popup, SWT.NONE); FormData fdContent = new FormData(); content.setLayoutData(fdContent); fdContent.top = new FormAttachment(0, 5); fdContent.left = new FormAttachment(0, 14); content.setLayout(new FillLayout(SWT.VERTICAL)); IContributionItem[] menuItems = menuManager.getItems(); for (int j = 0; j < menuItems.length; j++) { IContributionItem contributionItem = menuItems[j]; if (contributionItem instanceof ActionContributionItem) { ActionContributionItem actionItem = (ActionContributionItem) contributionItem; Action action = (Action) actionItem.getAction(); new ActionBarButton(action, content); } } content.pack(); popup.setBackground(background); Rectangle popUpBounds = calculatePopUpBounds(banner, menuBar, content); popup.setBounds(popUpBounds); shell.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { Rectangle popUpBounds = calculatePopUpBounds(banner, menuBar, content); popup.setBounds(popUpBounds); } }); popup.moveAbove(null); popupDialog.open(); Listener closeListener = new Listener() { public void handleEvent(Event event) { if (popupDialog.getShell() != null) { popupDialog.getShell().removeListener(SWT.Close, this); popupDialog.getShell().removeListener(SWT.Deactivate, this); popupDialog.getShell().removeListener(SWT.Dispose, this); popupDialog.close(); } if (!popup.isDisposed()) { popup.dispose(); } } }; popupDialog.getShell().addListener(SWT.Deactivate, closeListener); popupDialog.getShell().addListener(SWT.Close, closeListener); popupDialog.getShell().addListener(SWT.Dispose, closeListener); // content.addListener( SWT.Dispose, closeListener ); // Shell controlShell = content.getShell(); // controlShell.addListener( SWT.Move, closeListener ); popupDialog.getShell().setAlpha(0); popupDialog.getShell().setActive(); popupDialog.getShell().setBounds(popUpBounds); // shell.addMouseListener( new MouseAdapter() { // public void mouseUp( final MouseEvent e ) { // //System.out.println( "mouseup" ); // shell.removeMouseListener( this ); // popup.dispose(); // } // } ); } private Rectangle calculatePopUpBounds(Composite banner, Composite menuBar, Composite content) { Rectangle menuBarBounds = menuBar.getBounds(); Rectangle bannerBounds = banner.getBounds(); Display display = menuBar.getDisplay(); Shell shell = menuBar.getShell(); Point bannerPosition = display.map(banner.getParent(), shell, banner.getLocation()); return new Rectangle(bannerPosition.x, bannerBounds.height - 5, menuBarBounds.width + 10, content.getSize().y + 10); } }); } ActionBar.create(actions, menuBar); }