List of usage examples for org.eclipse.jface.dialogs PopupDialog close
@Override public boolean close()
From source file:com.liferay.ide.project.ui.upgrade.animated.InitConfigureProjectPage.java
License:Open Source License
@Override public void createSpecialDescriptor(Composite parent, int style) { Composite fillLayoutComposite = SWTUtil.createComposite(parent, 2, 2, GridData.FILL_HORIZONTAL); final String descriptor = "The initial step will be to upgrade to Liferay Workspace or Liferay Plugins SDK 7.0. " + "For more details, please see <a>dev.liferay.com</a>."; String url = "https://dev.liferay.com/develop/tutorials"; SWTUtil.createHyperLink(fillLayoutComposite, SWT.WRAP, descriptor, 1, url); final String extensionDec = "The first step will help you convert a Liferay Plugins SDK 6.2 to Liferay Plugins SDK 7.0 or to Liferay Workspace.\n" + "Click the \"import\" button to import your project into Eclipse workspace" + "(this process maybe need 5-10 mins for bundle init).\n" + "Note:\n" + " In order to save time, downloading 7.0 ivy cache locally could be a good choice to upgrade to liferay plugins sdk 7. \n" + " Theme and ext projects will be ignored for that we do not support to upgrade them in this tool currently. \n"; Label image = new Label(fillLayoutComposite, SWT.WRAP); image.setImage(loadImage("question.png")); PopupDialog popupDialog = new PopupDialog(fillLayoutComposite.getShell(), PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, true, false, false, false, false, null, null) { private static final int CURSOR_SIZE = 15; protected Point getInitialLocation(Point initialSize) { Display display = getShell().getDisplay(); Point location = display.getCursorLocation(); location.x += CURSOR_SIZE;//from w w w . j av a2 s . co m location.y += CURSOR_SIZE; return location; } protected Control createDialogArea(Composite parent) { Label label = new Label(parent, SWT.WRAP); label.setText(extensionDec); label.setFont(new Font(null, "Times New Roman", 11, SWT.NORMAL)); GridData gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH); gd.horizontalIndent = PopupDialog.POPUP_HORIZONTALSPACING; gd.verticalIndent = PopupDialog.POPUP_VERTICALSPACING; label.setLayoutData(gd); return label; } }; image.addListener(SWT.MouseHover, new org.eclipse.swt.widgets.Listener() { @Override public void handleEvent(org.eclipse.swt.widgets.Event event) { popupDialog.open(); } }); image.addListener(SWT.MouseExit, new org.eclipse.swt.widgets.Listener() { @Override public void handleEvent(org.eclipse.swt.widgets.Event event) { popupDialog.close(); } }); }
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 ww w.java 2 s . c o m 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); }