private static Set<Property> open(final Shell shell, final Set<Property> properties) { final PromptDialog dialog = new PromptDialog(shell, properties); if (dialog.open() == Window.OK) { return dialog.selectedProperties; } else { return Collections.emptySet(); } }
public static boolean promptConfirmLauch(Shell shell, IContext context, IProcess process) { boolean continueLaunch = true; int nbValues = 0; if (context == null) { throw new IllegalArgumentException("Context is null"); // $NON-NLS-1$ } // Prompt for context values ? for (IContextParameter parameter : context.getContextParameterList()) { if (parameter.isPromptNeeded()) { nbValues++; } } if (nbValues > 0) { IContext contextCopy = context.clone(); PromptDialog promptDialog = new PromptDialog(shell, contextCopy); if (promptDialog.open() == PromptDialog.OK) { for (IContextParameter param : context.getContextParameterList()) { boolean found = false; IContextParameter paramCopy = null; for (int i = 0; i < contextCopy.getContextParameterList().size() & !found; i++) { paramCopy = contextCopy.getContextParameterList().get(i); if (param.getName().equals(paramCopy.getName())) { // param.setValueList(paramCopy.getValueList()); param.setInternalValue(paramCopy.getValue()); found = true; } } } contextComboViewer.refresh(); contextTableViewer.refresh(); processNeedGenCode(process); } else { continueLaunch = false; } } else { if (context.isConfirmationNeeded()) { continueLaunch = MessageDialog.openQuestion( shell, Messages.getString("ProcessComposite.confirmTitle"), // $NON-NLS-1$ Messages.getString( "ProcessComposite.confirmText", context.getName())); // $NON-NLS-1$ } updateDefaultValueForListTypeParameter(context.getContextParameterList()); } return continueLaunch; }
@Override protected Object run(final Presentation context) { final FormComponentPresentation p = (FormComponentPresentation) context; final SapphirePart part = (SapphirePart) getPart(); final Set<Property> properties = new LinkedHashSet<Property>(); collectProperties(part, properties); for (Iterator<Property> itr = properties.iterator(); itr.hasNext(); ) { if (itr.next().empty()) { itr.remove(); } } if (properties.isEmpty()) { MessageDialog.openInformation(p.shell(), dialogTitle.text(), nothingToDoMessage.text()); } else { final Set<Property> selectedProperties = PromptDialog.open(p.shell(), properties); for (Property property : selectedProperties) { property.clear(); } } return null; }
int PromptAuth(long /*int*/ aChannel, int level, long /*int*/ authInfo, long /*int*/ _retval) { nsIAuthInformation auth = new nsIAuthInformation(authInfo); Browser browser = getBrowser(); if (browser != null) { Mozilla mozilla = (Mozilla) browser.webBrowser; /* * Do not invoke the listeners if this challenge has been failed too many * times because a listener is likely giving incorrect credentials repeatedly * and will do so indefinitely. */ if (mozilla.authCount++ < 3) { for (int i = 0; i < mozilla.authenticationListeners.length; i++) { AuthenticationEvent event = new AuthenticationEvent(browser); event.location = mozilla.lastNavigateURL; mozilla.authenticationListeners[i].authenticate(event); if (!event.doit) { XPCOM.memmove(_retval, new boolean[] {false}); return XPCOM.NS_OK; } if (event.user != null && event.password != null) { nsEmbedString string = new nsEmbedString(event.user); int rc = auth.SetUsername(string.getAddress()); if (rc != XPCOM.NS_OK) SWT.error(rc); string.dispose(); string = new nsEmbedString(event.password); rc = auth.SetPassword(string.getAddress()); if (rc != XPCOM.NS_OK) SWT.error(rc); string.dispose(); XPCOM.memmove(_retval, new boolean[] {true}); return XPCOM.NS_OK; } } } } /* no listener handled the challenge, so show an authentication dialog */ String checkLabel = null; boolean[] checkValue = new boolean[1]; String[] userLabel = new String[1], passLabel = new String[1]; String title = SWT.getMessage("SWT_Authentication_Required"); // $NON-NLS-1$ /* get initial username and password values */ long /*int*/ ptr = XPCOM.nsEmbedString_new(); int rc = auth.GetUsername(ptr); if (rc != XPCOM.NS_OK) SWT.error(rc); int length = XPCOM.nsEmbedString_Length(ptr); long /*int*/ buffer = XPCOM.nsEmbedString_get(ptr); char[] chars = new char[length]; XPCOM.memmove(chars, buffer, length * 2); userLabel[0] = new String(chars); XPCOM.nsEmbedString_delete(ptr); ptr = XPCOM.nsEmbedString_new(); rc = auth.GetPassword(ptr); if (rc != XPCOM.NS_OK) SWT.error(rc); length = XPCOM.nsEmbedString_Length(ptr); buffer = XPCOM.nsEmbedString_get(ptr); chars = new char[length]; XPCOM.memmove(chars, buffer, length * 2); passLabel[0] = new String(chars); XPCOM.nsEmbedString_delete(ptr); /* compute the message text */ ptr = XPCOM.nsEmbedString_new(); rc = auth.GetRealm(ptr); if (rc != XPCOM.NS_OK) SWT.error(rc); length = XPCOM.nsEmbedString_Length(ptr); buffer = XPCOM.nsEmbedString_get(ptr); chars = new char[length]; XPCOM.memmove(chars, buffer, length * 2); String realm = new String(chars); XPCOM.nsEmbedString_delete(ptr); nsIChannel channel = new nsIChannel(aChannel); long /*int*/[] uri = new long /*int*/[1]; rc = channel.GetURI(uri); if (rc != XPCOM.NS_OK) SWT.error(rc); if (uri[0] == 0) Mozilla.error(XPCOM.NS_NOINTERFACE); nsIURI nsURI = new nsIURI(uri[0]); long /*int*/ host = XPCOM.nsEmbedCString_new(); rc = nsURI.GetHost(host); if (rc != XPCOM.NS_OK) SWT.error(rc); length = XPCOM.nsEmbedCString_Length(host); buffer = XPCOM.nsEmbedCString_get(host); byte[] bytes = new byte[length]; XPCOM.memmove(bytes, buffer, length); String hostString = new String(bytes); XPCOM.nsEmbedCString_delete(host); nsURI.Release(); String message; if (realm.length() > 0 && hostString.length() > 0) { message = Compatibility.getMessage( "SWT_Enter_Username_and_Password", new String[] {realm, hostString}); // $NON-NLS-1$ } else { message = ""; // $NON-NLS-1$ } /* open the prompter */ Shell shell = browser == null ? new Shell() : browser.getShell(); PromptDialog dialog = new PromptDialog(shell); boolean[] result = new boolean[1]; dialog.promptUsernameAndPassword( title, message, checkLabel, userLabel, passLabel, checkValue, result); XPCOM.memmove(_retval, result); if (result[0]) { /* User selected OK */ nsEmbedString string = new nsEmbedString(userLabel[0]); rc = auth.SetUsername(string.getAddress()); if (rc != XPCOM.NS_OK) SWT.error(rc); string.dispose(); string = new nsEmbedString(passLabel[0]); rc = auth.SetPassword(string.getAddress()); if (rc != XPCOM.NS_OK) SWT.error(rc); string.dispose(); } return XPCOM.NS_OK; }