PageRenderTime 120ms CodeModel.GetById 4ms app.highlight 102ms RepoModel.GetById 1ms app.codeStats 1ms

/webportal/src/main/java/org/ala/spatial/analysis/web/AddToolComposer.java

http://alageospatialportal.googlecode.com/
Java | 2960 lines | 2411 code | 365 blank | 184 comment | 900 complexity | 4c4f0b610966be9bc2d7ece35b97c4f3 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1package org.ala.spatial.analysis.web;
   2
   3import au.com.bytecode.opencsv.CSVReader;
   4import au.org.emii.portal.composer.UtilityComposer;
   5import au.org.emii.portal.menu.MapLayer;
   6import au.org.emii.portal.settings.SettingsSupplementary;
   7import au.org.emii.portal.util.LayerSelection;
   8import au.org.emii.portal.util.LayerUtilities;
   9import java.io.IOException;
  10import java.io.InputStreamReader;
  11import java.io.Reader;
  12import java.io.StringReader;
  13import java.net.URLEncoder;
  14import java.text.DecimalFormat;
  15import java.text.SimpleDateFormat;
  16import java.util.ArrayList;
  17import java.util.Date;
  18import java.util.HashMap;
  19import java.util.Hashtable;
  20import java.util.Iterator;
  21import java.util.List;
  22import java.util.Map;
  23import java.util.logging.Level;
  24import java.util.logging.Logger;
  25import javax.servlet.http.Cookie;
  26import javax.servlet.http.HttpServletResponse;
  27import net.sf.json.JSONArray;
  28import net.sf.json.JSONObject;
  29import org.ala.logger.client.RemoteLogger;
  30import org.ala.spatial.data.Query;
  31import org.ala.spatial.util.CommonData;
  32import org.ala.spatial.data.BiocacheQuery;
  33import org.ala.spatial.data.QueryUtil;
  34import org.ala.spatial.data.UploadQuery;
  35import org.ala.spatial.util.SelectedArea;
  36import org.ala.spatial.util.UserData;
  37import org.ala.spatial.util.Util;
  38import org.apache.commons.httpclient.HttpClient;
  39import org.apache.commons.httpclient.methods.PostMethod;
  40import org.apache.commons.httpclient.methods.StringRequestEntity;
  41import org.apache.commons.lang.StringUtils;
  42import org.zkoss.util.media.Media;
  43import org.zkoss.zk.ui.Components;
  44import org.zkoss.zk.ui.Executions;
  45import org.zkoss.zk.ui.SuspendNotAllowedException;
  46import org.zkoss.zk.ui.event.CheckEvent;
  47import org.zkoss.zk.ui.event.Event;
  48import org.zkoss.zk.ui.event.EventListener;
  49import org.zkoss.zk.ui.event.Events;
  50import org.zkoss.zk.ui.event.ForwardEvent;
  51import org.zkoss.zk.ui.event.UploadEvent;
  52import org.zkoss.zk.ui.util.Clients;
  53import org.zkoss.zul.Button;
  54import org.zkoss.zul.Checkbox;
  55import org.zkoss.zul.Comboitem;
  56import org.zkoss.zul.Div;
  57import org.zkoss.zul.Doublebox;
  58import org.zkoss.zul.Filedownload;
  59import org.zkoss.zul.Fileupload;
  60import org.zkoss.zul.Image;
  61import org.zkoss.zul.Label;
  62import org.zkoss.zul.Listbox;
  63import org.zkoss.zul.Listcell;
  64import org.zkoss.zul.Listitem;
  65import org.zkoss.zul.ListitemRenderer;
  66import org.zkoss.zul.Menuitem;
  67import org.zkoss.zul.Menupopup;
  68import org.zkoss.zul.Messagebox;
  69import org.zkoss.zul.Radio;
  70import org.zkoss.zul.Radiogroup;
  71import org.zkoss.zul.Textbox;
  72import org.zkoss.zul.Vbox;
  73import org.zkoss.zul.Window;
  74
  75/**
  76 * 
  77 * TODO: NC 20130712 - This class really needs to be reviewed when we get a chance. 
  78 * 
  79 * @author ajay
  80 */
  81public class AddToolComposer extends UtilityComposer {
  82
  83    SettingsSupplementary settingsSupplementary;
  84    RemoteLogger remoteLogger;
  85    int currentStep = 1, totalSteps = 5;
  86    Map<String, Object> params;
  87    String selectedMethod = "";
  88    String pid = "";
  89    Radiogroup rgArea, rgAreaHighlight, rgSpecies, rgSpeciesBk;
  90    Radio rMaxent, rAloc, rScatterplot, rGdm, rTabulation;
  91    Radio rSpeciesAll, rSpeciesMapped, rSpeciesSearch, rSpeciesUploadLSID, rSpeciesUploadSpecies, rMultiple;
  92    Radio rSpeciesNoneBk, rSpeciesAllBk, rSpeciesMappedBk, rSpeciesSearchBk, rSpeciesUploadLSIDBk, rSpeciesUploadSpeciesBk, rMultipleBk;
  93    Radio rAreaWorld, rAreaCustom, rAreaWorldHighlight, rAreaSelected;
  94    Button btnCancel, btnOk, btnBack, btnHelp;
  95    Textbox tToolName;
  96    SpeciesAutoCompleteComponent searchSpeciesACComp, bgSearchSpeciesACComp;
  97    //SpeciesAutoComplete searchSpeciesAuto, bgSearchSpeciesAuto;
  98    EnvironmentalList lbListLayers;
  99    Div divSpeciesSearch, divSpeciesSearchBk;
 100    EnvLayersCombobox cbLayer1;
 101    EnvLayersCombobox cbLayer2;
 102    String winTop = "300px";
 103    String winLeft = "500px";
 104    // boolean setCustomArea = false;
 105    boolean hasCustomArea = false;
 106    MapLayer prevTopArea = null;
 107    Fileupload fileUpload;
 108    SelectedLayersCombobox selectedLayersCombobox;
 109    Div tlinfo;
 110    Textbox tLayerList;
 111    Div dLayerSummary;
 112    EnvLayersCombobox cbLayer, cbLayerEnvironmentalOnly, cbLayerMix;
 113    Button bLayerListDownload1;
 114    Button bLayerListDownload2;
 115    Label lLayersSelected, lendemicNote;
 116    Button btnClearSelection;
 117    Menupopup mpLayer2, mpLayer1;
 118    Doublebox dResolution;
 119    Vbox vboxMultiple, vboxMultipleBk;
 120    SpeciesAutoCompleteComponent mSearchSpeciesACComp, mSearchSpeciesACCompBk;
 121    //SpeciesAutoComplete mSearchSpeciesAuto, mSearchSpeciesAutoBk;
 122    Textbox tMultiple, tMultipleBk;
 123    Listbox lMultiple, lMultipleBk;
 124    boolean includeAnalysisLayers = true;
 125    boolean includeContextualLayers = false;
 126    boolean singleLayerDomain = true;
 127    boolean fullList = false;
 128    boolean includeAnalysisLayersForUploadQuery = false;
 129    boolean includeAnalysisLayersForAnyQuery = false;
 130    boolean mpLayersIncludeAnalysisLayers = false;
 131    Checkbox chkGeoKosherTrue, chkGeoKosherFalse,  chkEndemicSpecies;
 132    Checkbox chkGeoKosherTrueBk, chkGeoKosherFalseBk;
 133    boolean[] defaultGeospatialKosher = { true, true, false };
 134
 135    private Label lEstimateMessage;
 136    private Button bLogin;
 137    private Div notLoggedIn;
 138    private Div isLoggedIn;
 139    boolean isBackgroundProcess = true;
 140    boolean hasEstimated = false;
 141    
 142    //stuff for the dynamic species list inclusion
 143    private Vbox vboxImportSL, vboxImportSLBk; //the box layout for the import species list
 144    private SpeciesListListbox speciesListListbox,speciesListListboxBk;
 145    
 146    @Override
 147    public void afterCompose() {
 148        super.afterCompose();
 149
 150        winTop = this.getTop();
 151        winLeft = this.getLeft();
 152
 153        setupDefaultParams();
 154        setParams(Executions.getCurrent().getArg());
 155
 156        //add the species lists stuff
 157        if(rSpeciesUploadLSID != null && this.hasFellow("splistbox")) {
 158            vboxImportSL = (Vbox)this.getFellow("splistbox").getFellow("vboxImportSL");
 159            speciesListListbox = (SpeciesListListbox)this.getFellow("splistbox").getFellow("speciesListListbox");
 160            speciesListListbox.addEventListener("onSlCheckBoxChanged", new EventListener(){
 161              @Override
 162              public void onEvent(Event event) throws Exception {
 163                  btnOk.setDisabled((Integer)event.getData() == 0);
 164              }
 165            });
 166        }
 167
 168        if(rSpeciesUploadLSIDBk != null && this.hasFellow("splistboxbk")){
 169            vboxImportSLBk = (Vbox)this.getFellow("splistboxbk").getFellow("vboxImportSL");
 170            speciesListListboxBk = (SpeciesListListbox)this.getFellow("splistboxbk").getFellow("speciesListListbox");
 171            speciesListListbox.addEventListener("onSlCheckBoxChanged", new EventListener(){
 172              @Override
 173              public void onEvent(Event event) throws Exception {
 174                  btnOk.setDisabled((Integer)event.getData() == 0);
 175              }
 176            });
 177        }
 178        
 179        updateWindowTitle();
 180
 181        fixFocus();
 182
 183        if (lbListLayers != null) {
 184            lbListLayers.clearSelection();
 185            lbListLayers.updateDistances();
 186        }
 187
 188        // init mpLayer1 and mpLayer2
 189        if (mpLayer1 != null && mpLayer2 != null) {
 190            for (MapLayer ml : getMapComposer().getGridLayers()) {
 191                addToMpLayers(ml, false);
 192            }
 193        }
 194
 195        if (mSearchSpeciesACComp != null) {
 196            mSearchSpeciesACComp.getAutoComplete().setBiocacheOnly(true);
 197        }
 198        if (mSearchSpeciesACCompBk != null) {
 199            mSearchSpeciesACCompBk.getAutoComplete().setBiocacheOnly(true);
 200        }
 201
 202        // init includeLayers
 203        if (cbLayer != null) {
 204            cbLayer.setIncludeLayers("AllLayers");
 205            cbLayer.refresh("");
 206        }
 207        if (cbLayerEnvironmentalOnly != null) {
 208            cbLayerEnvironmentalOnly.setIncludeLayers("EnvironmentalLayers");
 209            cbLayerEnvironmentalOnly.refresh("");
 210        }
 211        if (cbLayer1 != null) {
 212            cbLayer1.setIncludeLayers("EnvironmentalLayers");
 213            cbLayer1.refresh("");
 214        }
 215        if (cbLayer2 != null) {
 216            cbLayer2.setIncludeLayers("EnvironmentalLayers");
 217            cbLayer2.refresh("");
 218        }
 219        if (cbLayerMix != null) {
 220            cbLayerMix.setIncludeLayers("MixLayers");
 221            cbLayerMix.refresh("");
 222        }
 223
 224        updateDefaultGeospatialKosherValues();
 225    }
 226
 227    void updateDefaultGeospatialKosherValues() {
 228        if (chkGeoKosherTrue != null) {
 229            defaultGeospatialKosher[0] = chkGeoKosherTrue.isChecked();
 230        }
 231        if (chkGeoKosherFalse != null) {
 232            defaultGeospatialKosher[1] = chkGeoKosherFalse.isChecked();
 233        }
 234        
 235    }
 236
 237    void addToMpLayers(MapLayer ml, boolean analysis) {
 238        // get layer name
 239        String name = null;
 240        String url = ml.getUri();
 241        if (analysis) {
 242            name = ml.getName();
 243        } else {
 244            int p1 = url.indexOf("ALA:") + 4;
 245            int p2 = url.indexOf("&", p1);
 246            if (p1 > 4) {
 247                if (p2 < 0) {
 248                    p2 = url.length();
 249                }
 250                name = url.substring(p1, p2);
 251            }
 252        }
 253
 254        // cbLayer1
 255        Menuitem mi = new Menuitem(ml.getDisplayName());
 256        mi.setValue(name);
 257        mi.addEventListener("onClick", new EventListener() {
 258
 259            public void onEvent(Event event) throws Exception {
 260                Menuitem mi = (Menuitem) event.getTarget();
 261                cbLayer1.setValue(mi.getValue() + " ");
 262                cbLayer1.refresh(mi.getValue());
 263                for (Object o : cbLayer1.getItems()) {
 264                    Comboitem ci = (Comboitem) o;
 265                    JSONObject jo = (JSONObject) ci.getValue();
 266                    if (jo.getString("name").equals(mi.getValue())) {
 267                        cbLayer1.setSelectedItem(ci);
 268                        cbLayer1.setText(ci.getLabel());
 269                        toggles();
 270                        return;
 271                    }
 272                }
 273            }
 274        });
 275        mi.setParent(mpLayer1);
 276
 277        // cbLayer2
 278        mi = new Menuitem(ml.getDisplayName());
 279        mi.setValue(name);
 280        mi.addEventListener("onClick", new EventListener() {
 281
 282            public void onEvent(Event event) throws Exception {
 283                Menuitem mi = (Menuitem) event.getTarget();
 284                cbLayer2.setValue(mi.getValue() + " ");
 285                cbLayer2.refresh(mi.getValue());
 286                for (Object o : cbLayer2.getItems()) {
 287                    Comboitem ci = (Comboitem) o;
 288                    JSONObject jo = (JSONObject) ci.getValue();
 289                    if (jo.getString("name").equals(mi.getValue())) {
 290                        cbLayer2.setSelectedItem(ci);
 291                        cbLayer2.setText(ci.getLabel());
 292                        toggles();
 293                        return;
 294                    }
 295                }
 296            }
 297        });
 298        mi.setParent(mpLayer2);
 299    }
 300
 301    private void setupDefaultParams() {
 302        Hashtable<String, Object> p = new Hashtable<String, Object>();
 303        p.put("step1", "Select area(s)");
 304        p.put("step2", "Select species(s)");
 305        p.put("step3", "Select grid(s)");
 306        p.put("step4", "Select your analytical options");
 307        p.put("step5", "Name your output for");
 308
 309        if (params == null) {
 310            params = p;
 311        } else {
 312            setParams(p);
 313        }
 314
 315        Div currentDiv = (Div) getFellowIfAny("atstep" + currentStep);
 316        btnOk.setLabel("Next >");
 317    }
 318
 319    public void updateWindowTitle() {
 320        this.setTitle("Step " + currentStep + " of " + totalSteps + " - " + selectedMethod);
 321    }
 322
 323    public void updateName(String name) {
 324        if (tToolName != null) {
 325            tToolName.setValue(name);
 326        }
 327    }
 328
 329    private void loadSummaryDetails() {
 330        try {
 331            Div atsummary = (Div) getFellowIfAny("atsummary");
 332            if (atsummary != null) {
 333                String summary = "";
 334                summary += "<strong>Analytical tool</strong>: " + selectedMethod;
 335                summary += "<strong>Area</strong>: ";
 336                summary += "<strong>Species</strong>: ";
 337                summary += "<strong>Grids</strong>: ";
 338                summary += "<strong>Additional options</strong>: ";
 339                atsummary.setContext(summary);
 340            }
 341        } catch (Exception e) {
 342        }
 343    }
 344
 345    public void setParams(Map<String, Object> params) {
 346        // iterate thru' the passed params and load them into the
 347        // existing default params
 348        if (params == null) {
 349            setupDefaultParams();
 350        }
 351        if (params != null && params.keySet() != null && params.keySet().iterator() != null) {
 352            Iterator<String> it = params.keySet().iterator();
 353            while (it.hasNext()) {
 354                String key = it.next();
 355                this.params.put(key, params.get(key));
 356            }
 357        } else {
 358            this.params = params;
 359        }
 360    }
 361
 362    public void loadSpeciesLayers() {
 363        loadSpeciesLayers(false);
 364    }
 365
 366    public void loadSpeciesLayers(boolean biocacheOnly) {
 367        try {
 368
 369            Radiogroup rgSpecies = (Radiogroup) getFellowIfAny("rgSpecies");
 370            Radio rSpeciesMapped = (Radio) getFellowIfAny("rSpeciesMapped");
 371
 372            List<MapLayer> layers = getMapComposer().getSpeciesLayers();
 373
 374            Radio selectedSpecies = null;
 375            String selectedSpeciesLayer = (String) params.get("speciesLayerName");
 376            int speciesLayersCount = 0;
 377
 378            for (int i = 0; i < layers.size(); i++) {
 379                MapLayer lyr = layers.get(i);
 380                if (biocacheOnly && lyr.getData("query") != null && !(lyr.getData("query") instanceof BiocacheQuery)) {
 381                    continue;
 382                }
 383                if (lyr.getSubType() != LayerUtilities.SPECIES_UPLOAD) {
 384                    speciesLayersCount++;
 385                }
 386
 387                Radio rSp = new Radio(lyr.getDisplayName());
 388                rSp.setValue(lyr.getName());
 389                rSp.setId(lyr.getName().replaceAll(" ", ""));
 390                rgSpecies.insertBefore(rSp, rSpeciesMapped);
 391
 392                if (selectedSpeciesLayer != null && rSp.getValue().equals(selectedSpeciesLayer)) {
 393                    selectedSpecies = rSp;
 394                }
 395            }
 396
 397            if (speciesLayersCount > 1) {
 398                rSpeciesMapped.setLabel("All " + speciesLayersCount + " species currently mapped (excludes coordinate uploads)");
 399            } else {
 400                rSpeciesMapped.setVisible(false);
 401            }
 402
 403            if (selectedSpecies != null) {
 404                rgSpecies.setSelectedItem(selectedSpecies);
 405            } else if (selectedSpeciesLayer != null && selectedSpeciesLayer.equals("none")) {
 406                rgSpecies.setSelectedItem(rSpeciesAll);
 407            } else if (layers.size() > 0) {
 408                rgSpecies.setSelectedItem(rgSpecies.getItemAtIndex(1));
 409            } else {
 410                for (int i = 0; i < rgSpecies.getItemCount(); i++) {
 411                    if (rgSpecies.getItemAtIndex(i).isVisible() && rgSpecies.getItemAtIndex(i) != rSpeciesAll) {
 412                        rgSpecies.setSelectedItem(rgSpecies.getItemAtIndex(i));
 413                        break;
 414                    }
 415                }
 416            }
 417
 418            updateGeospatialKosherCheckboxes();
 419        } catch (Exception e) {
 420            logger.error("Unable to load species layers:", e);
 421            //e.printStackTrace(System.out);
 422        }
 423    }
 424
 425    public void loadSpeciesLayersBk() {
 426        try {
 427            Radiogroup rgSpecies = (Radiogroup) getFellowIfAny("rgSpeciesBk");
 428
 429            List<MapLayer> layers = getMapComposer().getSpeciesLayers();
 430            int speciesLayersCount = 0;
 431
 432            for (int i = 0; i < layers.size(); i++) {
 433                MapLayer lyr = layers.get(i);
 434                if (lyr.getSubType() != LayerUtilities.SPECIES_UPLOAD) {
 435                    speciesLayersCount++;
 436                }
 437
 438                Radio rSp = new Radio(lyr.getDisplayName());
 439                rSp.setValue(lyr.getName());
 440                rSp.setId(lyr.getName().replaceAll(" ", "") + "__bk");
 441                rgSpecies.insertBefore(rSp, rSpeciesMappedBk);
 442            }
 443
 444            if (speciesLayersCount > 1) {
 445                rSpeciesMappedBk.setLabel("All " + speciesLayersCount + " species currently mapped (excludes coordinate uploads)");
 446            } else {
 447                rSpeciesMappedBk.setVisible(false);
 448            }
 449
 450            updateGeospatialKosherCheckboxesBk();
 451        } catch (Exception e) {
 452            logger.error("Unable to load species layers:", e);            
 453        }
 454    }
 455
 456    public void loadAreaLayers() {
 457        loadAreaLayers(null);
 458    }
 459
 460    public void loadAreaLayers(String selectedAreaName) {
 461        try {
 462            Radiogroup rgArea = (Radiogroup) getFellowIfAny("rgArea");
 463            // remove all radio buttons that don't have an id
 464            for (int i = rgArea.getItemCount() - 1; i >= 0; i--) {
 465                String id = ((Radio) rgArea.getItems().get(i)).getId();
 466                if (id == null || id.length() == 0) {
 467                    rgArea.removeItemAt(i);
 468                } else {
 469                    rgArea.getItemAtIndex(i).setSelected(false);
 470                }
 471            }
 472
 473            Radio rAreaCurrent = (Radio) getFellowIfAny("rAreaCurrent");
 474
 475            String selectedLayerName = (String) params.get("polygonLayerName");
 476            Radio rSelectedLayer = null;
 477
 478            StringBuilder allWKT = new StringBuilder();
 479            int count_not_envelopes = 0;
 480            List<MapLayer> layers = getMapComposer().getPolygonLayers();
 481            for (int i = 0; i < layers.size(); i++) {
 482                MapLayer lyr = layers.get(i);
 483                Radio rAr = new Radio(lyr.getDisplayName());
 484                rAr.setValue(lyr.getWKT());
 485
 486                if (!lyr.getWKT().contains("ENVELOPE")) {
 487                    if (count_not_envelopes > 0) {
 488                        allWKT.append(',');
 489                    }
 490                    count_not_envelopes++;
 491                    String wkt = lyr.getWKT();
 492                    if (wkt.startsWith("GEOMETRYCOLLECTION(")) {
 493                        wkt = wkt.substring("GEOMETRYCOLLECTION(".length(), wkt.length() - 1);
 494                    }
 495                    allWKT.append(wkt);
 496                }
 497
 498                rAr.setParent(rgArea);
 499                rgArea.insertBefore(rAr, rAreaCurrent);
 500
 501                if (selectedLayerName != null && lyr.getName().equals(selectedLayerName)) {
 502                    rSelectedLayer = rAr;
 503                    rAreaSelected = rAr;
 504                }
 505            }
 506
 507            if (!layers.isEmpty() && count_not_envelopes > 1) {
 508                Radio rAr = new Radio("All area layers" + ((count_not_envelopes < layers.size()) ? " (excluding Environmental Envelopes)" : ""));
 509                rAr.setValue("GEOMETRYCOLLECTION(" + allWKT.toString() + ")");
 510                rAr.setParent(rgArea);
 511                rgArea.insertBefore(rAr, rAreaCurrent);
 512            }
 513
 514            if (selectedAreaName != null && !selectedAreaName.equals("")) {
 515                for (int i = 0; i < rgArea.getItemCount(); i++) {
 516                    if (rgArea.getItemAtIndex(i).isVisible() && rgArea.getItemAtIndex(i).getLabel().equals(selectedAreaName)) {
 517                        rAreaSelected = rgArea.getItemAtIndex(i);
 518                        logger.debug("2.resetting indexToSelect = " + i);
 519                        rgArea.setSelectedItem(rAreaSelected);
 520                        break;
 521                    }
 522                }
 523            } else if (rSelectedLayer != null) {
 524                rAreaSelected = rSelectedLayer;
 525                rgArea.setSelectedItem(rAreaSelected);
 526            } else if (selectedLayerName != null && selectedLayerName.equals("none")) {
 527                rgArea.setSelectedItem(rAreaWorld);
 528                rAreaSelected = rAreaWorld;
 529                rgArea.setSelectedItem(rAreaSelected);
 530            } else {
 531                for (int i = 0; i < rgArea.getItemCount(); i++) {
 532                    if (rgArea.getItemAtIndex(i).isVisible()) {
 533                        rAreaSelected = rgArea.getItemAtIndex(i);
 534                        rgArea.setSelectedItem(rAreaSelected);
 535                        break;
 536                    }
 537                }
 538            }
 539
 540            if (chkEndemicSpecies != null) {
 541                updateEndemicCheckBox();
 542            }
 543
 544            Clients.evalJavaScript("jq('#" + rAreaSelected.getUuid() + "-real').attr('checked', true);");
 545
 546        } catch (Exception e) {
 547            logger.error("Unable to load active area layers:", e);            
 548        }
 549    }
 550
 551    public void loadAreaHighlightLayers(String selectedAreaName) {
 552        try {
 553            Radiogroup rgArea = (Radiogroup) getFellowIfAny("rgAreaHighlight");
 554            // remove all radio buttons that don't have an id
 555            for (int i = rgArea.getItemCount() - 1; i >= 0; i--) {
 556                String id = ((Radio) rgArea.getItems().get(i)).getId();
 557                if (id == null || id.length() == 0) {
 558                    rgArea.removeItemAt(i);
 559                } else {
 560                    rgArea.getItemAtIndex(i).setSelected(false);
 561                }
 562            }
 563
 564            Radio rAreaCurrentHighlight = (Radio) getFellowIfAny("rAreaCurrentHighlight");
 565
 566            String selectedLayerName = (String) params.get("polygonLayerName");
 567            Radio rSelectedLayer = null;
 568
 569            StringBuilder allWKT = new StringBuilder();
 570            int count_not_envelopes = 0;
 571            List<MapLayer> layers = getMapComposer().getPolygonLayers();
 572            for (int i = 0; i < layers.size(); i++) {
 573                MapLayer lyr = layers.get(i);
 574                Radio rAr = new Radio(lyr.getDisplayName());
 575                rAr.setValue(lyr.getWKT());
 576
 577                if (!lyr.getWKT().contains("ENVELOPE")) {
 578                    if (count_not_envelopes > 0) {
 579                        allWKT.append(',');
 580                    }
 581                    count_not_envelopes++;
 582                    String wkt = lyr.getWKT();
 583                    if (wkt.startsWith("GEOMETRYCOLLECTION(")) {
 584                        wkt = wkt.substring("GEOMETRYCOLLECTION(".length(), wkt.length() - 1);
 585                    }
 586                    allWKT.append(wkt);
 587                }
 588
 589                rAr.setParent(rgArea);
 590                rgArea.insertBefore(rAr, rAreaCurrentHighlight);
 591
 592                if (selectedLayerName != null && lyr.getName().equals(selectedLayerName)) {
 593                    rSelectedLayer = rAr;
 594                    // rAreaSelected = rAr;
 595                }
 596            }
 597
 598            if (!layers.isEmpty() && count_not_envelopes > 1) {
 599                Radio rAr = new Radio("All area layers" + ((count_not_envelopes < layers.size()) ? " (excluding Environmental Envelopes)" : ""));
 600                rAr.setValue("GEOMETRYCOLLECTION(" + allWKT.toString() + ")");
 601                rAr.setParent(rgArea);
 602                rgArea.insertBefore(rAr, rAreaCurrentHighlight);
 603            }
 604
 605            if (selectedAreaName != null && !selectedAreaName.equals("")) {
 606                for (int i = 0; i < rgArea.getItemCount(); i++) {
 607                    if (rgArea.getItemAtIndex(i).isVisible() && rgArea.getItemAtIndex(i).getLabel().equals(selectedAreaName)) {
 608                        logger.debug("2.resetting indexToSelect = " + i);
 609                        rgArea.setSelectedItem(rgArea.getItemAtIndex(i));
 610                        break;
 611                    }
 612                }
 613            } else if (rSelectedLayer != null) {
 614                rgArea.setSelectedItem(rAreaSelected);
 615            } else if (selectedLayerName != null && selectedLayerName.equals("none")) {
 616                rgArea.setSelectedItem(rAreaWorld);
 617            } else {
 618                for (int i = 0; i < rgArea.getItemCount(); i++) {
 619                    if (rgArea.getItemAtIndex(i).isVisible()) {
 620                        // rAreaSelected = rgArea.getItemAtIndex(i);
 621                        rgArea.setSelectedItem(rgArea.getItemAtIndex(i));
 622                        break;
 623                    }
 624                }
 625            }
 626            Clients.evalJavaScript("jq('#" + rgArea.getSelectedItem().getUuid() + "-real').attr('checked', true);");
 627
 628        } catch (Exception e) {
 629            logger.error("Unable to load active area layers:", e);            
 630        }
 631    }
 632
 633    public void loadAreaLayersHighlight() {
 634        try {
 635
 636            Radiogroup rgArea = (Radiogroup) getFellowIfAny("rgAreaHighlight");
 637            Radio rAreaCurrent = (Radio) getFellowIfAny("rAreaCurrentHighlight");
 638            Radio rAreaNone = (Radio) getFellowIfAny("rAreaNoneHighlight");
 639
 640            List<MapLayer> layers = getMapComposer().getPolygonLayers();
 641            for (int i = 0; i < layers.size(); i++) {
 642                MapLayer lyr = layers.get(i);
 643                Radio rAr = new Radio(lyr.getDisplayName());
 644                rAr.setId(lyr.getName().replaceAll(" ", ""));
 645                rAr.setValue(lyr.getWKT());
 646                rAr.setParent(rgArea);
 647                rgArea.insertBefore(rAr, rAreaCurrent);
 648            }
 649
 650            rAreaNone.setSelected(true);
 651        } catch (Exception e) {
 652            logger.error("Unable to load active area layers:", e);            
 653        }
 654    }
 655
 656    public void loadGridLayers(boolean includeAnalysisLayers, boolean includeContextualLayers, boolean singleLayerDomain) {
 657        this.includeAnalysisLayers = includeAnalysisLayers;
 658        this.includeContextualLayers = includeContextualLayers;
 659        this.singleLayerDomain = singleLayerDomain;
 660        this.fullList = true;
 661
 662        if (selectedLayersCombobox != null) {
 663            selectedLayersCombobox.init(getMapComposer().getLayerSelections(), getMapComposer(), false);
 664        }
 665        try {
 666
 667            if (fullList) {
 668                lbListLayers.init(getMapComposer(), includeAnalysisLayers, !includeContextualLayers, singleLayerDomain);
 669                lbListLayers.updateDistances();
 670            } else {
 671                List<MapLayer> layers = getMapComposer().getPolygonLayers();
 672                for (int i = 0; i < layers.size(); i++) {
 673                    MapLayer lyr = layers.get(i);
 674                    // System.out.println(lyr.getDisplayName());
 675                }
 676            }
 677
 678            String layers = (String) params.get("environmentalLayerName");
 679            if (layers != null) {
 680                lbListLayers.selectLayers(layers.split(","));
 681            }
 682
 683            lbListLayers.renderAll();
 684        } catch (Exception e) {
 685            logger.error("Unable to load species layers:", e);            
 686        }
 687    }
 688
 689    public void onCheck$rgArea(Event event) {
 690        if (rgArea == null) {
 691            return;
 692        }
 693        // setCustomArea = false;
 694        hasCustomArea = false;
 695        rAreaSelected = rgArea.getSelectedItem();
 696        try {
 697            rAreaSelected = (Radio) ((org.zkoss.zk.ui.event.ForwardEvent) event).getOrigin().getTarget();
 698        } catch (Exception e) {
 699        }
 700        if (rAreaSelected == rAreaCustom) {
 701            // setCustomArea = true;
 702            hasCustomArea = false;
 703        }
 704
 705        
 706        // case for enabling the endemic checkbox
 707        // System.out.println("RADIO SELECTED = " + rAreaSelected.getValue());
 708
 709        if (chkEndemicSpecies != null) {
 710            updateEndemicCheckBox();
 711        }
 712    }
 713
 714    private void updateEndemicCheckBox() {
 715        // check to see if the area is within the required size...
 716        boolean showEndemic = false;
 717        String value = rAreaSelected.getValue();
 718        if (rAreaSelected != null) {
 719            if (value.equals("australia") || value.equals("world") || value.equals("custom")) {
 720                // System.out.println("Large areas");
 721
 722            } else {
 723
 724                String areaName = rAreaSelected.getLabel();
 725                MapLayer ml = getMapComposer().getMapLayer(areaName);
 726                String sarea = "";
 727                if (value.equals("current")) {
 728                    // check to see if the current extent is within the maximum
 729                    // area
 730                    SelectedArea sa = getSelectedArea();
 731                    sarea = sa.getKm2Area();
 732                } else if (ml != null) {
 733                    sarea = (String) ml.getData("area");
 734                    if (sarea == null)
 735                        sarea = ml.calculateAndStoreArea();
 736                } else {
 737                    // for 'all areas'
 738                    SelectedArea sa = new SelectedArea(null, rAreaSelected.getValue());
 739                    sarea = sa.getKm2Area();
 740
 741                }
 742                try {
 743                    Float area = Float.parseFloat(sarea.replaceAll(",", ""));
 744                    showEndemic = (area <= CommonData.maxEndemicArea);
 745                } catch (NumberFormatException e) {
 746
 747                }
 748
 749            }
 750        }
 751        chkEndemicSpecies.setDisabled(!showEndemic);
 752        chkEndemicSpecies.setChecked(false);
 753
 754        if(lendemicNote != null){
 755            if (showEndemic){
 756                lendemicNote.setValue("Please note this may take several minutes depending on the area selected.");
 757            } else{
 758                lendemicNote.setValue("The selected area is too large to be considered for endemic species.");
 759            }
 760        }
 761    }
 762
 763    public void onCheck$rgAreaHighlight(Event event) {
 764        if (rgAreaHighlight == null) {
 765            return;
 766        }
 767        // setCustomArea = false;
 768        hasCustomArea = false;
 769        if (rgAreaHighlight.getSelectedItem().getId().equals("rAreaCustomHighlight")) {
 770            // setCustomArea = true;
 771            hasCustomArea = false;
 772        }
 773    }
 774
 775    public void onCheck$rgSpecies(Event event) {
 776        if (rgSpecies == null) {
 777            return;
 778        }
 779        Radio selectedItem = rgSpecies.getSelectedItem();
 780        try {
 781            selectedItem = (Radio) ((org.zkoss.zk.ui.event.ForwardEvent) event).getOrigin().getTarget();
 782        } catch (Exception e) {
 783        }
 784        try {
 785            if(event != null&&selectedItem != rSpeciesUploadLSID){
 786                vboxImportSL.setVisible(false);
 787            }
 788            if(event != null && vboxImportSLBk != null && selectedItem != rSpeciesUploadLSIDBk){
 789                vboxImportSLBk.setVisible(false);
 790            }
 791            // Check to see if we are perform a normal or background upload
 792            if (rgSpecies != null && selectedItem == rSpeciesSearch) {
 793                if (divSpeciesSearch != null) {
 794                    divSpeciesSearch.setVisible(true);
 795                    vboxMultiple.setVisible(false);
 796                    if (event != null) {
 797                        toggles();
 798                    }
 799                    return;
 800                }
 801            }
 802            if (divSpeciesSearch != null) {
 803                divSpeciesSearch.setVisible(false);
 804            }
 805
 806            if (selectedItem == rSpeciesUploadSpecies) {
 807                // btnOk.setVisible(false);
 808                // fileUpload.setVisible(true);                
 809                btnOk.setVisible(true);
 810                vboxMultiple.setVisible(false);
 811            } else if(selectedItem == rSpeciesUploadLSID) {
 812                btnOk.setDisabled(true);
 813                vboxImportSL.setVisible(true);
 814                vboxMultiple.setVisible(false);
 815            } else if (rMultiple != null && rMultiple.isSelected()) {
 816            
 817                vboxMultiple.setVisible(true);
 818            }  else {
 819                btnOk.setDisabled(false);
 820                vboxMultiple.setVisible(false);
 821            }
 822
 823            if (event != null) {
 824                toggles();
 825            }
 826
 827            // set default geospatial kosher checkboxes unless a map layers has
 828            // been chosen
 829            MapLayer ml = null;
 830            Query q = null;
 831            if (rgSpecies.getSelectedItem() != null && rgSpecies.getSelectedItem().getValue() != null && (ml = getMapComposer().getMapLayer(rgSpecies.getSelectedItem().getValue())) != null
 832                    && (q = (Query) ml.getData("query")) != null && q instanceof BiocacheQuery) {
 833                setGeospatialKosherCheckboxes(((BiocacheQuery) q).getGeospatialKosher());
 834            } else {
 835                setGeospatialKosherCheckboxes(defaultGeospatialKosher);
 836            }
 837            updateGeospatialKosherCheckboxes();
 838        } catch (Exception e) {
 839        }
 840    }
 841
 842    public void onCheck$rgSpeciesBk(Event event) {
 843        if (rgSpeciesBk == null) {
 844            return;
 845        }
 846        Radio selectedItem = rgSpeciesBk.getSelectedItem();
 847        try {
 848            selectedItem = (Radio) ((org.zkoss.zk.ui.event.ForwardEvent) event).getOrigin().getTarget();
 849        } catch (Exception e) {
 850        }
 851        try {
 852          
 853          if(event != null&&selectedItem != rSpeciesUploadLSID){
 854              vboxImportSL.setVisible(false);
 855          }
 856          if(event != null &&vboxImportSLBk != null && selectedItem != rSpeciesUploadLSIDBk){
 857              vboxImportSLBk.setVisible(false);
 858          }
 859          
 860            if (rgSpeciesBk != null && selectedItem == rSpeciesSearchBk) {
 861                if (divSpeciesSearchBk != null) {
 862                    divSpeciesSearchBk.setVisible(true);
 863                    vboxMultipleBk.setVisible(false);
 864                    if (event != null) {
 865                        toggles();
 866                    }
 867                    return;
 868                }
 869            }
 870
 871            if (divSpeciesSearchBk != null) {
 872                divSpeciesSearchBk.setVisible(false);
 873            }
 874            
 875            if(selectedItem == rSpeciesUploadLSIDBk) {
 876              btnOk.setDisabled(true);
 877              vboxImportSLBk.setVisible(true);
 878              vboxMultiple.setVisible(false);
 879            } else if (selectedItem == rSpeciesUploadSpeciesBk) {
 880                // btnOk.setVisible(false);
 881                // fileUpload.setVisible(true);
 882                btnOk.setVisible(true);
 883            }
 884
 885            if (rMultipleBk != null && rMultipleBk.isSelected()) {
 886                vboxMultipleBk.setVisible(true);
 887            } else {
 888                vboxMultipleBk.setVisible(false);
 889            }
 890
 891            if (event != null) {
 892                toggles();
 893            }
 894
 895            // set default geospatial kosher checkboxes unless a map layers has
 896            // been chosen
 897            MapLayer ml = null;
 898            Query q = null;
 899            if (rgSpeciesBk.getSelectedItem() != null && rgSpeciesBk.getSelectedItem().getValue() != null && (ml = getMapComposer().getMapLayer(rgSpeciesBk.getSelectedItem().getValue())) != null
 900                    && (q = (Query) ml.getData("query")) != null && q instanceof BiocacheQuery) {
 901                setGeospatialKosherCheckboxesBk(((BiocacheQuery) q).getGeospatialKosher());
 902            } else {
 903                setGeospatialKosherCheckboxesBk(defaultGeospatialKosher);
 904            }
 905            updateGeospatialKosherCheckboxes();
 906            updateGeospatialKosherCheckboxesBk();
 907        } catch (Exception e) {
 908        }
 909    }
 910
 911    public void onValueSelected$searchSpeciesACComp(Event event){
 912        toggles();
 913    }
 914//DELETE    
 915//    public void onSelect$searchSpeciesAuto(Event event) {
 916//        toggles();
 917//    }
 918
 919    public void onClick$btnHelp(Event event) {
 920        String helpurl = "";
 921
 922        if (selectedMethod.equals("Prediction")) {
 923            helpurl = "http://www.ala.org.au/spatial-portal-help/analysis-prediction-tab/";
 924        } else if (selectedMethod.equals("Sampling")) {
 925            helpurl = "http://www.ala.org.au/spatial-portal-help/analysis-sampling-tab/";
 926        } else if (selectedMethod.equals("Classification")) {
 927            helpurl = "http://www.ala.org.au/spatial-portal-help/analysis-classification-tab/";
 928        } else if (selectedMethod.equals("Scatterplot")) {
 929            helpurl = "http://www.ala.org.au/spatial-portal-help/scatterplot-tab/";
 930        }
 931
 932        if (StringUtils.isNotBlank(helpurl)) {
 933            getMapComposer().activateLink(helpurl, "Help", false, "");
 934        }
 935    }
 936
 937    public void onClick$btnCancel(Event event) {
 938        currentStep = 1;
 939        if (lbListLayers != null) {
 940            lbListLayers.clearSelection();
 941            toggles();
 942        }
 943        this.detach();
 944    }
 945
 946    public void onClick$btnBack(Event event) {
 947
 948        Div currentDiv = (Div) getFellowIfAny("atstep" + currentStep);
 949        Div nextDiv = (Div) getFellowIfAny("atstep" + (currentStep + 1));
 950        Div previousDiv = (currentStep > 1) ? ((Div) getFellowIfAny("atstep" + (currentStep - 1))) : null;
 951
 952        if (currentDiv.getZclass().contains("first")) {
 953            btnBack.setDisabled(true);
 954        } else {
 955            currentDiv.setVisible(false);
 956            previousDiv.setVisible(true);
 957
 958            Image currentStepCompletedImg = (Image) getFellowIfAny("imgCompletedStep" + (currentStep - 1));
 959            currentStepCompletedImg.setVisible(false);
 960
 961            Label nextStepLabel = (Label) getFellowIfAny("lblStep" + (currentStep));
 962            nextStepLabel.setStyle("font-weight:normal");
 963
 964            Label currentStepLabel = (Label) getFellowIfAny("lblStep" + (currentStep - 1));
 965            currentStepLabel.setStyle("font-weight:bold");
 966
 967            currentStep--;
 968
 969            if (previousDiv != null) {
 970                btnBack.setDisabled(((!previousDiv.getZclass().contains("first")) ? false : true));
 971            }
 972        }
 973
 974        btnOk.setLabel("Next >");
 975        toggles();
 976        updateWindowTitle();
 977        displayTrafficLightInfo();
 978
 979    }
 980
 981    private void displayTrafficLightInfo() {
 982        if (tlinfo != null) {
 983            if (selectedMethod.equalsIgnoreCase("Prediction") && currentStep == 3) {
 984                tlinfo.setVisible(true);
 985            } else if (selectedMethod.equalsIgnoreCase("Classification") && currentStep == 2) {
 986                tlinfo.setVisible(true);
 987            } else if (selectedMethod.equalsIgnoreCase("GDM") && currentStep == 3) {
 988                tlinfo.setVisible(true);
 989            } else if (selectedMethod.equalsIgnoreCase("Sampling") && currentStep == 3) {
 990                tlinfo.setVisible(true);
 991            } else {
 992                tlinfo.setVisible(false);
 993            }
 994        }
 995    }
 996
 997    public void resetWindowFromSpeciesUpload(String lsid, String type) {
 998        try {
 999            if (type.compareTo("cancel") == 0) {
1000                fixFocus();
1001                return;
1002            }
1003            if (type.compareTo("normal") == 0) {
1004                setLsid(lsid);
1005            }
1006            if (type.compareTo("bk") == 0) {
1007                setLsidBk(lsid);
1008            }
1009            if (type.compareTo("assemblage") == 0) {
1010                setMultipleLsids(lsid);
1011            }
1012            if (type.compareTo("assemblagebk") == 0) {
1013                setMultipleLsidsBk(lsid);
1014            }
1015        } catch (Exception e) {
1016            logger.error("Exception when resetting analysis window", e);            
1017        }
1018    }
1019
1020    public void resetWindow(String selectedArea) {
1021        try {
1022
1023            if (selectedArea == null) {
1024                hasCustomArea = false;
1025            } else if (selectedArea.trim().equals("")) {
1026                hasCustomArea = false;
1027            } else {
1028                hasCustomArea = true;
1029            }
1030
1031            boolean ok = false;
1032            if (hasCustomArea) {
1033                MapLayer curTopArea = null;
1034                List<MapLayer> layers = getMapComposer().getPolygonLayers();
1035                if (layers != null && layers.size() > 0) {
1036                    curTopArea = layers.get(0);
1037                } else {
1038                    curTopArea = null;
1039                }
1040
1041                if (curTopArea != prevTopArea) {
1042                    if (isAreaHighlightTab()) {
1043                        loadAreaHighlightLayers(curTopArea.getDisplayName());
1044                    } else if (isAreaTab()) {
1045                        loadAreaLayers(curTopArea.getDisplayName());
1046                    }
1047
1048                    ok = true;
1049                }
1050            }
1051            this.setTop(winTop);
1052            this.setLeft(winLeft);
1053
1054            this.doModal();
1055
1056            if (ok) {
1057                onClick$btnOk(null);
1058                hasCustomArea = false;
1059            }
1060
1061            fixFocus();
1062        } catch (InterruptedException ex) {
1063            logger.error("InterruptedException when resetting analysis window", ex);            
1064        } catch (SuspendNotAllowedException ex) {
1065            logger.error("Exception when resetting analysis window", ex);            
1066        }
1067    }
1068
1069    public void onClick$btnOk(Event event) {
1070        if (btnOk.isDisabled()) {
1071            return;
1072        }
1073        boolean successful = false;
1074        try {
1075          
1076            if (!hasCustomArea && (isAreaCustom() || isAreaHighlightCustom())) {
1077                this.doOverlapped();
1078                this.setTop("-9999px");
1079                this.setLeft("-9999px");
1080
1081                Map<String, Object> winProps = new HashMap<String, Object>();
1082                winProps.put("parent", this);
1083                winProps.put("parentname", "AddTool");
1084                winProps.put("selectedMethod", selectedMethod);
1085
1086                List<MapLayer> layers = getMapComposer().getPolygonLayers();
1087                if (layers != null && layers.size() > 0) {
1088                    prevTopArea = layers.get(0);
1089                } else {
1090                    prevTopArea = null;
1091                }
1092
1093                Window window = (Window) Executions.createComponents("WEB-INF/zul/AddArea.zul", this, winProps);
1094                window.setAttribute("winProps", winProps, true);
1095                window.doModal();
1096
1097                return;
1098            }
1099
1100            Div currentDiv = (Div) getFellowIfAny("atstep" + currentStep);
1101            Div nextDiv = (Div) getFellowIfAny("atstep" + (currentStep + 1));
1102            Div previousDiv = (currentStep > 1) ? ((Div) getFellowIfAny("atstep" + (currentStep + 1))) : null;
1103            
1104          //check to see if one of the "create new species list" radio buttons is seleceted
1105          //ONLY perform these checks if the "lMultiple" or lMultipleBk" is on the current page
1106            if(Components.isAncestor(currentDiv, lMultiple)&& rMultiple.isChecked()){
1107                // display the dialog and change the radio button to "use existing"...
1108              showExportSpeciesListDialog(lMultiple);
1109              return;
1110            } else if (Components.isAncestor(currentDiv, lMultipleBk)&& rMultipleBk.isChecked()){
1111                showExportSpeciesListDialog(lMultipleBk);
1112                return;
1113            }
1114
1115            if (!currentDiv.getZclass().contains("last")) {
1116                if (currentDiv.getZclass().contains("species") && (rSpeciesUploadSpecies.isSelected())) {
1117                    Boolean test = currentDiv.getZclass().contains("species") && (rSpeciesUploadSpecies.isSelected());
1118                    logger.debug("test=" + test);
1119                    onClick$btnUpload(event);
1120
1121                } else {
1122                    currentDiv.setVisible(false);
1123                    nextDiv.setVisible(true);
1124
1125                    Image previousStepCompletedImg = (Image) getFellowIfAny("imgCompletedStep" + (currentStep));
1126                    previousStepCompletedImg.setVisible(true);
1127
1128                    Label previousStepLabel = (Label) getFellowIfAny("lblStep" + (currentStep));
1129                    previousStepLabel.setStyle("font-weight:normal");
1130
1131                    Label currentStepLabel = (Label) getFellowIfAny("lblStep" + (currentStep + 1));
1132                    currentStepLabel.setStyle("font-weight:bold");
1133
1134                    // now include the extra options for step 4
1135                    if (nextDiv != null) {
1136
1137                        if (nextDiv.getZclass().contains("last")) {
1138                            loadSummaryDetails();
1139                            onLastPanel();
1140                        }
1141                        btnOk.setLabel("Next >");
1142                    }
1143
1144                    currentStep++;
1145
1146                    successful = true;
1147                }
1148            } else {
1149                saveLayerSelection();
1150
1151                successful = onFinish();
1152
1153                if (successful) {
1154                    currentStep = 1;
1155                }
1156            }
1157
1158            if (successful) {
1159                if (nextDiv != null && rgSpecies != null && (includeAnalysisLayersForUploadQuery || includeAnalysisLayersForAnyQuery)) {
1160                    Query q = getSelectedSpecies();
1161                    if (q != null) {
1162                        boolean test = (includeAnalysisLayersForAnyQuery || (q instanceof UploadQuery));
1163
1164                        if (selectedLayersCombobox != null) {
1165                            if ((selectedLayersCombobox.getIncludeAnalysisLayers()) != test) {
1166                                selectedLayersCombobox.init(getMapComposer().getLayerSelections(), getMapComposer(), test);
1167                            }
1168                        }
1169                        if (lbListLayers != null) {
1170                            if ((lbListLayers.getIncludeAnalysisLayers()) != test) {
1171                                String[] selectedLayers = lbListLayers.getSelectedLayers();
1172                                lbListLayers.init(getMapComposer(), test, !includeContextualLayers, singleLayerDomain);
1173                                lbListLayers.updateDistances();
1174
1175                                if (selectedLayers != null && selectedLayers.length > 0) {
1176                                    lbListLayers.selectLayers(selectedLayers);
1177                                }
1178
1179                                lbListLayers.renderAll();
1180                            }
1181                        }
1182                        if (cbLayer != null) {
1183                            if ((cbLayer.getIncludeAnalysisLayers()) != test) {
1184                                cbLayer.setIncludeAnalysisLayers(test);
1185                            }
1186                        }
1187                        if (cbLayerEnvironmentalOnly != null) {
1188                            if ((cbLayerEnvironmentalOnly.getIncludeAnalysisLayers()) != test) {
1189                                cbLayerEnvironmentalOnly.setIncludeAnalysisLayers(test);
1190                            }
1191                        }
1192                        if (cbLayer1 != null) {
1193                            if ((cbLayer1.getIncludeAnalysisLayers()) != test) {
1194                                cbLayer1.setIncludeAnalysisLayers(test);
1195                            }
1196                        }
1197                        if (cbLayer2 != null) {
1198                            if ((cbLayer2.getIncludeAnalysisLayers()) != test) {
1199                                cbLayer2.setIncludeAnalysisLayers(test);
1200                            }
1201                        }
1202                        if (cbLayerMix != null) {
1203                            if ((cbLayerMix.getIncludeAnalysisLayers()) != test) {
1204                                cbLayerMix.setIncludeAnalysisLayers(test);
1205                            }
1206                        }
1207                        if (mpLayer1 != null && mpLayer2 != null && mpLayersIncludeAnalysisLayers != test) {
1208                            // remove
1209                            while (mpLayer1.getChildren().size() > 0) {
1210                                mpLayer1.removeChild(mpLayer1.getFirstChild());
1211                            }
1212                            while (mpLayer2.getChildren().size() > 0) {
1213                                mpLayer2.removeChild(mpLayer2.getFirstChild());
1214                            }
1215                            // add
1216                            for (MapLayer ml : getMapComposer().getGridLayers()) {
1217                                addToMpLayers(ml, false);
1218                            }
1219                            mpLayersIncludeAnalysisLayers = test;
1220                            if (mpLayersIncludeAnalysisLayers) {
1221                                for (MapLayer ml : getMapComposer().getAnalysisLayers()) {
1222                                    if (ml.getSubType() != LayerUtilities.ALOC) {
1223                                        addToMpLayers(ml, true);
1224                                    }
1225                                }
1226                            }
1227                        }
1228                    }
1229                }
1230                if (nextDiv != null && nextDiv.getZclass().contains("last")) {
1231                    updateLayerListText();
1232                }
1233
1234                btnBack.setDisabled(false);
1235                updateWindowTitle();
1236            }
1237
1238        } catch (Exception ex) {
1239            Logger.getLogger(AddToolComposer.class.getName()).log(Level.SEVERE, null, ex);
1240        }
1241
1242        toggles();
1243        displayTrafficLightInfo();
1244
1245        fixFocus();
1246    }
1247
1248    void fixFocus() {
1249        // set element of focus
1250    }
1251
1252    public void onLastPanel() {
1253    }
1254
1255    public boolean onFinish() {
1256        try {
1257            this.detach();
1258            Messagebox.show("Running your analysis tool: " + selectedMethod);
1259
1260        } catch (InterruptedException ex) {
1261            Logger.getLogger(AddToolComposer.class.getName()).log(Level.SEVERE, null, ex);
1262        } catch (Exception e) {
1263        }
1264
1265        return true;
1266    }
1267
1268    public void loadMap(Event event) {
1269    }
1270
1271    public long getEstimate() {
1272        return -1;
1273    }
1274
1275    public void onClick$bLogin(Event event) {
1276        getMapComposer().activateLink("https://auth.ala.org.au/cas/login", "Login", false);
1277
1278        // Window extWin = (Window) getFellowIfAny("externalContentWindow");
1279        // extWin.addEventListener("onClose", new EventListener() {
1280        // @Override
1281        // public void onEvent(Event event) throws Exception

Large files files are truncated, but you can click here to view the full file