/**
* Copyright (C) Gadglet .
*
* This file is part of Gadglet
*
* Gadglet is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Gadglet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Gadglet. If not, see <http://www.gnu.org/licenses/>.
*/
package com.gadglet.gadgets.bookmarks.client;
import com.gadglet.client.gwt.GadgetConfig;
import com.gadglet.client.gwt.core.GadgletQuery;
import com.gadglet.client.gwt.core.GadgletRequest;
import com.gadglet.client.gwt.core.GadgletResponse;
import com.gadglet.client.gwt.ui.DebugDialogBox;
import com.gadglet.client.gwt.ui.SimpleDialogBox;
import com.gadglet.params.GadgetType;
import com.gadglet.params.ReqActionTypes;
import com.gadglet.params.ReqTypes;
import com.google.gwt.gadgets.client.Gadget;
import com.google.gwt.gadgets.client.Gadget.AllowHtmlQuirksMode;
import com.google.gwt.gadgets.client.Gadget.Content;
import com.google.gwt.gadgets.client.Gadget.InjectModulePrefs;
import com.google.gwt.gadgets.client.Gadget.UseLongManifestName;
import com.google.gwt.gadgets.client.NeedsViews;
import com.google.gwt.gadgets.client.PreferencesFeature;
import com.google.gwt.gadgets.client.PreferencesProvider;
import com.google.gwt.gadgets.client.ViewFeature;
/**
* The Gadget "main" object.
* <p> See <a href='http://gwt-google-apis.googlecode.com/svn/javadoc/gadgets/1.2/index.html'>com.google.gwt.gadgets</a>
* <p> See <a href='http://code.google.com/p/gwt-google-apis/wiki/GadgetsGettingStarted'>Gadget using GWT</a>
* <p> NOTE: Google GWT Gadget (ver 1.2) has an issue with the use of "@InjectModulePrefs".
* The Gadget manifest (xml file) is incorrectly formated. Developer must open the compiled manifest
* and fix it manually, by removing additional unnecessary <ModulePrefs> .. </ModulePrefs>
* <p>In the case of "implements NeedsViews" the GWT compiler adds additional unnecessary <Require feature="views"/>
*@see com.google.gwt.gadgets.client.Gadget
*
*/
@InjectModulePrefs(files = {"prefInject.txt"})
// Create a short manifest name (instead of prepending the package prefix)
@UseLongManifestName(false)
@AllowHtmlQuirksMode(false)
@Content(contents = { BookMarksHomeView.class, BookMarksCanvasView.class,BookMarksProfileView.class })
public class BookMarksGadget extends Gadget<BookMarksPreferences> implements
NeedsViews {
private ViewFeature gadgetViewFeature;
public ViewFeature getGadgetViewFeature() {
return gadgetViewFeature;
}
private DebugDialogBox debug = null;
final protected DebugDialogBox errorNotifier = DebugDialogBox
.getErrorNotifier();
final PreferencesFeature prefsUtils = PreferencesProvider.get();
final SimpleDialogBox serverMessage = SimpleDialogBox
.getMesseageDialogBox();
/**
* A config query. Doesn't do much yet, but used to check if user
* is signed up, and perform the registration process if needed
*/
final GadgletQuery configQry = new GadgletQuery(ReqTypes.BIZLET_SIGNED);
final ConfigRequest configRequest = new ConfigRequest(configQry);
final BookMarksHomeView home = new BookMarksHomeView();
final BookMarksCanvasView canvas = new BookMarksCanvasView();
// this one is for Gmail sidebar
final BookMarksProfileView profile = new BookMarksProfileView();
@Override
protected void init(final BookMarksPreferences prefs) {
GadgetConfig gc = GadgetConfig.getGadgetConfig();
// this is a Bizlet type of Gadget
gc.setGadgetType(GadgetType.BIZLET);
debug = DebugDialogBox.getErrorNotifier();
configQry.setRequestAction(ReqActionTypes.CONFIG);
configRequest.makeRequest();
}
@Override
public void initializeFeature(ViewFeature feature) {
gadgetViewFeature = feature;
}
BookMarksGadget getGdget() {
return this;
}
public class ConfigRequest extends GadgletRequest {
GadgletResponse jResponse;
ConfigRequest(GadgletQuery req) {
super(req);
}
/**
* This method will be used whenever the Gadget loads for the first time.
* Used only to check if the user is logged-in and perform registration process
*/
@Override
protected void processResults(GadgletResponse jResponse) {
if (jResponse != null && jResponse.isSuccessful()) {
// handle config & open the right View
if (gadgetViewFeature == null) {
errorNotifier.showError(7, "gadgetViewFeature is null");
home.init(getGdget());
} else if (gadgetViewFeature.getCurrentView().getName()
.toUpperCase().equals("CANVAS"))
canvas.init(getGdget());
else if (gadgetViewFeature.getCurrentView().getName()
.toUpperCase().equals("PROFILE"))
profile.init(getGdget());
else
home.init(getGdget());
}
else
serverMessage.showError((prefsUtils.getMsg(jResponse.getError())));
}
}
}