PageRenderTime 40ms CodeModel.GetById 26ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/v3.2/nimbits-tds/src/com/nimbits/client/panels/FacebookPanel.java

http://nimbits-server.googlecode.com/
Java | 114 lines | 64 code | 29 blank | 21 comment | 3 complexity | b38a9828bba9d6a7a42a57f04b97bdb0 MD5 | raw file
  1/*
  2 * Copyright (c) 2010 Tonic Solutions LLC.
  3 *
  4 * http://www.nimbits.com
  5 *
  6 *
  7 * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  8 *
  9 * http://www.gnu.org/licenses/gpl.html
 10 *
 11 * Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 12 */
 13
 14package com.nimbits.client.panels;
 15
 16import com.extjs.gxt.ui.client.widget.ContentPanel;
 17import com.extjs.gxt.ui.client.widget.Label;
 18import com.extjs.gxt.ui.client.widget.LayoutContainer;
 19import com.extjs.gxt.ui.client.widget.layout.FillLayout;
 20import com.google.gwt.core.client.GWT;
 21import com.google.gwt.user.client.Element;
 22import com.google.gwt.user.client.rpc.AsyncCallback;
 23import com.nimbits.client.exception.NimbitsException;
 24import com.nimbits.client.model.Const;
 25import com.nimbits.client.model.email.EmailAddress;
 26import com.nimbits.client.service.facebook.FacebookService;
 27import com.nimbits.client.service.facebook.FacebookServiceAsync;
 28
 29import java.io.UnsupportedEncodingException;
 30import java.util.Map;
 31
 32
 33/**
 34 * Created by Benjamin Sautner
 35 * User: benjamin
 36 * Date: 4/13/11
 37 * Time: 12:38 PM
 38 */
 39public class FacebookPanel extends LayoutContainer {
 40
 41    private final String facebookOauthCode;
 42    private final Map<String, String> settings;
 43
 44
 45    public FacebookPanel(String code, Map<String, String> someSettings) {
 46        facebookOauthCode = code;
 47        this.settings = someSettings;
 48
 49    }
 50
 51    protected void onRender(Element target, int index) {
 52        super.onRender(target, index);
 53        ContentPanel c = new ContentPanel(new FillLayout());
 54        c.setHeaderVisible(false);
 55        c.setFrame(false);
 56        c.setBodyBorder(false);
 57        final Label l = new Label();
 58
 59
 60        String authURL = "https://graph.facebook.com/oauth/authorize" +
 61                "?client_id=" + settings.get(Const.PARAM_FACEBOOK_CLIENT_ID) +
 62                "&redirect_uri=" + "http://apps.facebook.com/nimbits/" +
 63                "&scope=user_status,publish_stream,offline_access,email";
 64
 65
 66        if (facebookOauthCode == null) {
 67
 68            l.setText("<P></P>" +
 69                    "<P>Nimbits does not run inside of facebook... When you use the nimbits server on <a href = \"http://app.nimbits.com\" target=\"_blank\"> http://app.nimbits.com</A>, " +
 70                    "you can configure data points to post to your facebook news feed whenever they are updated or if they go into" +
 71                    " an alarm state. </P> <BR><BR>" +
 72                    "<P>In order to have Nimbits post to your facebook News Feed" +
 73                    " you must add it to your profile. </P><BR><BR><BR>" +
 74                    "<center><P><font size =+1> <A href =\"" + authURL + "\" target=\"_top\" >Authorize Nimbits by clicking here.</A></font></p></center>" +
 75                    "");
 76
 77        } else {
 78            FacebookServiceAsync facebookService = GWT.create(FacebookService.class);
 79            try {
 80                facebookService.facebookLogin(facebookOauthCode, new AsyncCallback<EmailAddress>() {
 81
 82                    @Override
 83                    public void onFailure(Throwable caught) {
 84
 85                        l.setText(caught.getMessage() + "  " + facebookOauthCode);
 86
 87                    }
 88
 89                    @Override
 90                    public void onSuccess(EmailAddress result) {
 91                        l.setText("<P>You have successfuly added facebook to your Nimbits account. You can now log into <A href =\"http://www.nimbits.com\" target=\"_blank\" >Nimbits Data Logger</A> and configure your data points to relay new values and alerts to facebook.</p>" +
 92                                "");
 93
 94                        //	l.setText(result);
 95
 96                    }
 97
 98                });
 99            } catch (UnsupportedEncodingException e) {
100                //  e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
101            } catch (NimbitsException e) {
102                //   e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
103            }
104
105
106        }
107
108        c.add(l);
109
110
111        add(c);
112
113    }
114}