/** * Installs the account defined in this wizard. * * @param userName the user name to sign in with * @param password the password to sign in with * @return the created <tt>ProtocolProviderService</tt> corresponding to the new account * @throws OperationFailedException if the operation didn't succeed */ public ProtocolProviderService signin(final String userName, final String password) throws OperationFailedException { /* * If firstWizardPage is null we are requested sign-in from initial * account registration form we must init firstWizardPage in order to * init default values * Pawel: firstWizardPage is never null, and commitPage fails with no * user ID provided for simple account wizard. Now userName and password * are reentered here. */ final AccountPanel accPanel = (AccountPanel) firstWizardPage.getSimpleForm(); /* * XXX Swing is not thread safe! We've experienced deadlocks on OS X * upon invoking accPanel's setters. In order to address them, (1) * invoke accPanel's setters on the AWT event dispatching thread and (2) * do it only if absolutely necessary. */ String accPanelUsername = accPanel.getUsername(); boolean equals = false; final boolean rememberPassword = (password != null); if (StringUtils.isEquals(accPanelUsername, userName)) { char[] accPanelPasswordChars = accPanel.getPassword(); char[] passwordChars = (password == null) ? null : password.toCharArray(); if (accPanelPasswordChars == null) equals = ((passwordChars == null) || passwordChars.length == 0); else if (passwordChars == null) equals = (accPanelPasswordChars.length == 0); else equals = Arrays.equals(accPanelPasswordChars, passwordChars); if (equals) { boolean accPanelRememberPassword = accPanel.isRememberPassword(); equals = (accPanelRememberPassword == rememberPassword); } } if (!equals) { try { if (SwingUtilities.isEventDispatchThread()) { accPanel.setUsername(userName); accPanel.setPassword(password); accPanel.setRememberPassword(rememberPassword); } else { SwingUtilities.invokeAndWait( new Runnable() { public void run() { accPanel.setUsername(userName); accPanel.setPassword(password); accPanel.setRememberPassword(rememberPassword); } }); } } catch (Exception e) { if (e instanceof OperationFailedException) { throw (OperationFailedException) e; } else { throw new OperationFailedException( "Failed to set username and password on " + accPanel.getClass().getName(), OperationFailedException.INTERNAL_ERROR, e); } } } if (!firstWizardPage.isCommitted()) firstWizardPage.commitPage(); if (!firstWizardPage.isCommitted()) { throw new OperationFailedException( "Could not confirm data.", OperationFailedException.GENERAL_ERROR); } ProtocolProviderFactory factory = JabberAccRegWizzActivator.getJabberProtocolProviderFactory(); return installAccount( factory, registration.getUserID(), // The user id may get changed. // Server part can be added in the // data commit. password); }
/** * Construct (with WhiteboardSession) and send a WhiteboardObject to a contact. * * @param wbSession the white-board session, to which the object would be send * @param ws WhiteboardShape to convert and send * @param c contact * @return WhiteboardObject sent */ public WhiteboardObject sendWhiteboardObject(WhiteboardSession wbSession, WhiteboardShape ws) throws OperationFailedException { Vector supportedWBO = new Vector(Arrays.asList(wbSession.getSupportedWhiteboardObjects())); if (ws instanceof WhiteboardObjectPath) { if (!supportedWBO.contains(WhiteboardObjectPath.NAME)) return null; WhiteboardObjectPath obj = (WhiteboardObjectPath) wbSession.createWhiteboardObject(WhiteboardObjectPath.NAME); ws.setID(obj.getID()); obj.setPoints(((WhiteboardObjectPath) ws).getPoints()); obj.setColor(ws.getColor()); obj.setThickness(ws.getThickness()); wbSession.sendWhiteboardObject(obj); return obj; } else if (ws instanceof WhiteboardObjectPolyLine) { if (!supportedWBO.contains(WhiteboardObjectPolyLine.NAME)) return null; WhiteboardObjectPolyLine obj = (WhiteboardObjectPolyLine) wbSession.createWhiteboardObject(WhiteboardObjectPolyLine.NAME); ws.setID(obj.getID()); obj.setPoints(((WhiteboardObjectPolyLine) ws).getPoints()); obj.setColor(ws.getColor()); obj.setThickness(ws.getThickness()); wbSession.sendWhiteboardObject(obj); return obj; } else if (ws instanceof WhiteboardObjectPolygon) { if (!supportedWBO.contains(WhiteboardObjectPolygon.NAME)) return null; WhiteboardObjectPolygon obj = (WhiteboardObjectPolygon) wbSession.createWhiteboardObject(WhiteboardObjectPolygon.NAME); ws.setID(obj.getID()); obj.setPoints(((WhiteboardObjectPolygon) ws).getPoints()); obj.setBackgroundColor(((WhiteboardObjectPolygon) ws).getBackgroundColor()); obj.setFill(((WhiteboardObjectPolygon) ws).isFill()); obj.setColor(ws.getColor()); obj.setThickness(ws.getThickness()); wbSession.sendWhiteboardObject(obj); return obj; } else if (ws instanceof WhiteboardObjectLine) { if (!supportedWBO.contains(WhiteboardObjectLine.NAME)) return null; WhiteboardObjectLine obj = (WhiteboardObjectLine) wbSession.createWhiteboardObject(WhiteboardObjectLine.NAME); ws.setID(obj.getID()); obj.setWhiteboardPointStart(((WhiteboardObjectLine) ws).getWhiteboardPointStart()); obj.setWhiteboardPointEnd(((WhiteboardObjectLine) ws).getWhiteboardPointEnd()); obj.setColor(ws.getColor()); obj.setThickness(ws.getThickness()); wbSession.sendWhiteboardObject(obj); return obj; } else if (ws instanceof WhiteboardObjectRect) { if (!supportedWBO.contains(WhiteboardObjectRect.NAME)) return null; WhiteboardObjectRect obj = (WhiteboardObjectRect) wbSession.createWhiteboardObject(WhiteboardObjectRect.NAME); ws.setID(obj.getID()); obj.setFill(((WhiteboardObjectRect) ws).isFill()); obj.setHeight(((WhiteboardObjectRect) ws).getHeight()); obj.setWhiteboardPoint(((WhiteboardObjectRect) ws).getWhiteboardPoint()); obj.setWidth((((WhiteboardObjectRect) ws)).getWidth()); obj.setColor(ws.getColor()); obj.setThickness(ws.getThickness()); wbSession.sendWhiteboardObject(obj); return obj; } else if (ws instanceof WhiteboardObjectCircle) { if (!supportedWBO.contains(WhiteboardObjectCircle.NAME)) return null; WhiteboardObjectCircle obj = (WhiteboardObjectCircle) wbSession.createWhiteboardObject(WhiteboardObjectCircle.NAME); ws.setID(obj.getID()); obj.setFill(((WhiteboardObjectCircle) ws).isFill()); obj.setRadius(((WhiteboardObjectCircle) ws).getRadius()); obj.setWhiteboardPoint(((WhiteboardObjectCircle) ws).getWhiteboardPoint()); obj.setBackgroundColor((((WhiteboardObjectCircle) ws)).getBackgroundColor()); obj.setColor(ws.getColor()); obj.setThickness(ws.getThickness()); wbSession.sendWhiteboardObject(obj); return obj; } else if (ws instanceof WhiteboardObjectText) { if (!supportedWBO.contains(WhiteboardObjectText.NAME)) return null; WhiteboardObjectText obj = (WhiteboardObjectText) wbSession.createWhiteboardObject(WhiteboardObjectText.NAME); ws.setID(obj.getID()); obj.setFontName(((WhiteboardObjectText) ws).getFontName()); obj.setFontSize(((WhiteboardObjectText) ws).getFontSize()); obj.setText(((WhiteboardObjectText) ws).getText()); obj.setWhiteboardPoint(((WhiteboardObjectText) ws).getWhiteboardPoint()); obj.setColor(ws.getColor()); obj.setThickness(ws.getThickness()); wbSession.sendWhiteboardObject(obj); return obj; } else if (ws instanceof WhiteboardObjectImage) { if (!supportedWBO.contains(WhiteboardObjectImage.NAME)) return null; WhiteboardObjectImage obj = (WhiteboardObjectImage) wbSession.createWhiteboardObject(WhiteboardObjectImage.NAME); ws.setID(obj.getID()); obj.setBackgroundImage(((WhiteboardObjectImage) ws).getBackgroundImage()); obj.setHeight(((WhiteboardObjectImage) ws).getHeight()); obj.setWhiteboardPoint(((WhiteboardObjectImage) ws).getWhiteboardPoint()); obj.setWidth(((WhiteboardObjectImage) ws).getWidth()); obj.setColor(ws.getColor()); obj.setThickness(ws.getThickness()); wbSession.sendWhiteboardObject(obj); return obj; } return null; }