view src/econnect/wp3_3/client/core/StiCore.java @ 32:f635bbdc6a03

local KML display (beta)
author Sebastian Kruse <skruse@mpiwg-berlin.mpg.de>
date Fri, 30 Nov 2012 15:17:25 +0100
parents c7701b00ca5b
children fe646332827c
line wrap: on
line source

package econnect.wp3_3.client.core;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;

import econnect.wp3_3.client.core.ApplicationGrid;
import econnect.wp3_3.client.widgets.map.Map;
import econnect.wp3_3.client.widgets.map.StiMap;
import econnect.wp3_3.client.widgets.table.StiTable;
import econnect.wp3_3.client.widgets.timeplot.StiTimeplot;
import econnect.wp3_3.client.widgets.timeplot.Timeplot;

/**
 * Implementation of the wrapper for the STICore class of the STI JavaScript source
*/
public class StiCore extends JavaScriptObject {
	
	protected StiCore(){
	}
	
    /**
     * Initializes a STICore element
     *
     * @return the STICore object
    */
	public static native StiCore createStiCore() /*-{
		var core = new $wnd.STICore();
		$wnd.loadKml = function( kmlString, term ){
			core.parseKml(kmlString, term);
		}
		return core;
	}-*/;

    /**
     * Sets the widgets for the core component
     * 
     * @param map the javascript object of the map widget
     * @param plot the javascript object of the timeplot widget
    */
	public final native void setElements( StiMap map, StiTimeplot plot ) /*-{
		this.setElements(map, plot);
	}-*/;

    /**
     * Adds a dataset to the actual history entry
     * 
     * @param dataSet the dataset to add
    */
	public final native void addDataSet( DataSet dataSet ) /*-{
		this.addDataSet( dataSet );
	}-*/;

    /**
     * Getter for the dataSets of the actual history entry
     * 
     * @return the dataSets of the actual history entry
    */
	public final native JsArray<DataSet> getDataSets() /*-{
		return this.history[this.historyIndex].dataSets;
	}-*/;
	
    /**
     * Getter for the length of the history
     * 
     * @return the length of the history
    */
	public final native int getHistoryLength() /*-{
		return this.history.length;
	}-*/;

    /**
     * Switches to another history entry with the given index
     * 
     * @param index the index of the history entry to load
    */
	public final native void switchThroughHistory( int index ) /*-{
		this.switchThroughHistory(index);
	}-*/;

    /**
     * Set of static methods that are needed for the javascript source to communicate to the GWT source
     * 
     * @param table the table item to communicate selection changes in the other widgets
     * @param grid the application grid to update the history
     * @param plot the timeplot element to update the number of zoom levels for the slider control
     * @param map the map to manage addition of elements and to change the zoomlevel of the slider control
    */
	public static native void exportStaticMethods(StiTable table, ApplicationGrid grid, Timeplot plot, Map map ) /*-{
    	$wnd.updateTables = function(hover){
    		table.@econnect.wp3_3.client.widgets.table.StiTable::updateTables(Z)(hover);
    	}
    	$wnd.initTables = function(){
    		table.@econnect.wp3_3.client.widgets.table.StiTable::initTables()();
    	}
    	$wnd.addHistoryItem = function(index){
    		grid.@econnect.wp3_3.client.core.ApplicationGrid::addHistoryItem(I)(index);
    	}
    	$wnd.setZoomLevels = function(levels){
    		plot.@econnect.wp3_3.client.widgets.timeplot.Timeplot::setZoomLevels(I)(levels);
    	}
    	$wnd.setTimeZoom = function(value){
    		plot.@econnect.wp3_3.client.widgets.timeplot.Timeplot::setValue(I)(value);
    	}
    	$wnd.animationImage = function(animate){
    		plot.@econnect.wp3_3.client.widgets.timeplot.Timeplot::animationImage(Z)(animate);
    	}
    	$wnd.setMapZoom = function(value){
    		map.@econnect.wp3_3.client.widgets.map.Map::setValue(F)(value);
    	}
    	$wnd.switchToNavigation = function(){
    		map.@econnect.wp3_3.client.widgets.map.Map::switchToNavigation()();
    	}
    	$wnd.setDefinedBounds = function(){
    		grid.@econnect.wp3_3.client.core.ApplicationGrid::setDefinedBounds()();
    	}
		$wnd.setAddElementContext = function( longitude, latitude, left, top, width, height ){
			map.@econnect.wp3_3.client.widgets.map.Map::setAddElementContext(DDIIII)(longitude,latitude,left,top,width,height);
		}
 	}-*/;

    /**
     * Deletes the dataset at the given index
     * 
     * @param index the index of the dataset to delete
    */
	public final native void deleteDataSet( int index ) /*-{
		this.deleteDataSet(index);
	}-*/;

    /**
     * Getter for the cellcolor with a specific index and a specific percental value of a dataobject
     * 
     * @param i the (set) index of the dataobject
     * @param p the percental selection value of the dataobject
     * @return the calculated cellcolor
    */
	public static native String getCellColor( int i, double p ) /*-{
		return $wnd.getCellColor(i,p);
	}-*/;

    /**
     * Getter for the bordercolor of a cell with a specific index and a selection status of a dataobject
     * 
     * @param i the (set) index of the dataobject
     * @param selected the selection status of the dataobject
     * @return the calculated bordercolor of the cell
    */
	public static native String getBorderColor( int i, boolean selected ) /*-{
		return $wnd.getBorderColor(i,selected);
	}-*/;
	
    /**
     * Updates the timeplot and map widget of selections have been made in the table widget
    */
	public final native void updateTimeAndMap() /*-{
		this.updateTimeAndMap();
	}-*/;

    /**
     * Resets the core
    */
	public final native void reset() /*-{
		this.reset();
	}-*/;

    /**
     * Refines the core
    */
	public final native void refine() /*-{
		this.refine();
	}-*/;

	/**
     * Adds an element to the individual dataset
     * 
     * @param object the dataobject to add
    */
	public final native void addElement(DataObject object) /*-{
		this.addElement(object);
	}-*/;

    /**
     * Refines the dataset with the given index by the given text
     * 
     * Moved to DynamicStiTable.
     * 
     * @param text the refine text
     * @param index the index of the dataset
    */
	/*
	public final native void refineByText(String text, int index) /*-{
		this.refineByText(text,index);
	}-*///;

	/**
     * Getter for the SimileAjax value for the granularity of a second
     *
     * @return the SimileAjax granularity value of a second
    */
	public final native int getSecondGranularity() /*-{
		return $wnd.SimileAjax.DateTime.SECOND;
	}-*/;

    /**
     * Getter for the SimileAjax value for the granularity of a day
     *
     * @return the SimileAjax granularity value of a day
    */
	public final native int getDateGranularity() /*-{
		return $wnd.SimileAjax.DateTime.DAY;
	}-*/;

    /**
     * Getter for the SimileAjax value for the granularity of a month
     *
     * @return the SimileAjax granularity value of a month
    */
	public final native int getMonthGranularity() /*-{
		return $wnd.SimileAjax.DateTime.MONTH;
	}-*/;

    /**
     * Getter for the SimileAjax value for the granularity of a year
     *
     * @return the SimileAjax granularity value of a year
    */
	public final native int getYearGranularity() /*-{
		return $wnd.SimileAjax.DateTime.YEAR;
	}-*/;

    /**
     * Security hover unselection of elements if browser events got stucked
    */
	public final native void undoHover() /*-{
		this.undoHover(true);
	}-*/;
	
    /**
     * Trigger function for an alert message
     *
     * @param text the text for the alert message
    */
	public final native void alert( String text ) /*-{
		alert(text);
	}-*/;

    /**
     * Getter for the name of the DataObject
     *
     * @return name of the data object
    */
	public final native JsArray<DataSet> getHistoryDataSets(int index) /*-{
		return this.history[index].dataSets;
	}-*/;	

    /**
     * Getter for the color id of a dataset; needed for images for the table
     *
     * @return index the index of a dataset
     * @return the color id for the dataset
    */
	public final native int getColorId(int index) /*-{
		return $wnd.getColorId(index);
	}-*/;

    /**
     * Triggers the export of selected data elements to a new dataset
     * 
     * @param id the id of the dataset to export selected elements
    */
	public final native void storeSelected(int id) /*-{
		this.storeSelected(id);
	}-*/;

    /**
     * Getter for the number of items within a category
     * 
     * @param ds the index of the datasource
     * @param cat the index of the category
     * @return the number of items of a category
    */
	public final native int getItemCount(int ds, int cat) /*-{		
    	return this.sources[ds].categories[cat].items.length;
	}-*/;

	/**
     * Getter for the label of a static dataset
     * 
     * @param ds the index of the datasource
     * @param cat the category of the dataset
     * @param id the index of the dataset
     * @return the label of a dataset
    */
	public final native String getLabel(int ds, int cat, int id) /*-{
    	return this.sources[ds].categories[cat].items[id].label;
	}-*/;
	
    /**
     * Getter for the number of categories
     * 
     * @param ds the index of the datasource
     * @return the number of categories
    */
	public final native int getCategories(int ds) /*-{
    	return this.sources[ds].categories.length;
	}-*/;

    /**
     * Getter for a datasource name
     * 
     * @param ds the index of the datasource
     * @return the name of the datasource
    */
	public final native String getDatasourceLabel(int ds) /*-{
    	return this.sources[ds].label;
	}-*/;
	
    /**
     * Getter for the number of datasources
     * 
     * @return the number of datasources
    */
	public final native int getDatasources() /*-{
    	return this.sources.length;
	}-*/;

    /**
     * Converts ascii to hex symbols
     * 
     * @return the converted string
    */
	public final native String asciiToHex(String text) /*-{
		var ascii = new Array( "!","#","$","%","&","'","(",")","*","+",",","/",":",";","=","?","@","[","]", " " );
		var hex = new Array( "%21","%23","%24","!$#","%26","%27","%28","%29","%2a","%2b","%2c","%2f","%3a","%3b","%3d","%3f","%40","%5b","%5d","%20" );
		for( var i=0; i<ascii.length; i++ ){
			while(text.indexOf(ascii[i])!= -1){
				text = text.replace(ascii[i],hex[i]);	
			}
		}
		text = text.replace(/!$#/g,"%25");
		return text;
	}-*/;
	
    /**
     * Converts hex to ascii symbols
     * 
     * @return the converted String
    */
	public final native String hexToAscii(String text) /*-{
		var ascii = new Array( "!","#","$","%","&","'","(",")","*","+",",","/",":",";","=","?","@","[","]", " " );
		var hex = new Array( "%21","%23","%24","%25","%26","%27","%28","%29","%2a","%2b","%2c","%2f","%3a","%3b","%3d","%3f","%40","%5b","%5d","%20" );
		for( var i=0; i<ascii.length; i++ ){
			while(text.indexOf(hex[i])!= -1){
				text = text.replace(hex[i],ascii[i]);
			}
		}
		return text;
	}-*/;
	
	/**
     * Tests if the maximum number of datasets for the visualization is reached
     * 
     * @return true if there is no space for a new dataset
    */
	public final native boolean isMaximumReached() /*-{
		return this.history[this.historyIndex].dataSets.length >= $wnd.parallelSearches;
	}-*/;

    /**
     * Tests if there are already individual elements
     * 
     * @return true if there are already individual elements
    */
	public final native boolean individualSet() /*-{
		return this.individualDataSet != null;
	}-*/;

	/**
     * Getter for the number of items of the datasource
     * 
     * @param ds the index of the datasource
     * @return true if the datasource has items
    */
	public final native boolean hasItems(int ds) /*-{
		if( this.sources[ds].url == undefined ){
			return true;
		} 
    	return false;
	}-*/;

    /**
     * Getter for a category name
     * 
     * @param ds the index of the datasource
     * @param cat the index of the category
     * @return the name of the category
    */
	public final native String getCategory(int ds, int cat) /*-{
    	return this.sources[ds].categories[cat].category;
	}-*/;

	/**
     * Opens the static kml file that corresponds to the selected item 
     * 
     * @param ds the index of the datasource
     * @param cat the category of the dataset
     * @param id the index of the dataset
    */
	public final native void openStaticKml(int ds, int cat, int id) /*-{
		this.parseKml( this.sources[ds].categories[cat].items[id].url, this.sources[ds].categories[cat].items[id].label, ds ); 
	}-*/;
	
	/**
     * Triggers a server request to generate a kml file depending on user input 
     * 
     * @param ds the index of the datasource
     * @param input the user input text
    */
	public final native void openDynamicKml(int ds, String input) /*-{
		this.retrieveKml( ds, input ); 
	}-*/;

	/**
     * Opens a local KML file via HTML5 FileAPI 
     * 
     * @param ds the index of the datasource
     * @param input the user input text
    */
	public final native void openLocalKml(int ds, String fileName) /*-{
		this.retrieveLocalKml( ds, fileName ); 
	}-*/;

	/**
     * places a configured time refinement 
    */
	public final native void refineByTime(String minTime, String maxTime) /*-{
		this.refineByTime( minTime, maxTime ); 
	}-*/;

	public final native boolean isIEBrowser() /*-{
		if( navigator.appName == 'Microsoft Internet Explorer' ){
			return true;
		}
		return false;
	}-*/;

}