felix@858: package de.intevation.flys.client.client.ui.chart; felix@858: felix@1519: import java.util.ArrayList; felix@1436: import java.util.HashMap; felix@1436: import java.util.Map; felix@1436: import java.util.LinkedHashMap; felix@1519: import java.util.List; felix@1436: felix@858: import com.google.gwt.core.client.GWT; felix@858: felix@1436: import com.google.gwt.user.client.rpc.AsyncCallback; felix@1436: felix@1436: import com.smartgwt.client.util.SC; felix@1436: felix@858: import com.smartgwt.client.types.Alignment; felix@1436: import com.smartgwt.client.types.ListGridFieldType; felix@1436: felix@858: import com.smartgwt.client.widgets.Canvas; felix@858: import com.smartgwt.client.widgets.grid.ListGrid; felix@858: import com.smartgwt.client.widgets.grid.ListGridField; felix@858: import com.smartgwt.client.widgets.grid.ListGridRecord; felix@858: import com.smartgwt.client.widgets.layout.HLayout; felix@1436: import com.smartgwt.client.widgets.layout.VLayout; felix@858: import com.smartgwt.client.widgets.form.fields.SpinnerItem; felix@858: import com.smartgwt.client.widgets.form.DynamicForm; felix@1436: felix@1436: import com.smartgwt.client.widgets.form.fields.SelectItem; felix@1436: import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; felix@858: import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; felix@858: import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; felix@1436: import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; felix@858: felix@1519: import com.smartgwt.client.widgets.menu.Menu; felix@1519: import com.smartgwt.client.widgets.menu.MenuItem; felix@1519: import com.smartgwt.client.widgets.menu.events.ClickHandler; felix@1519: import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent; felix@1519: felix@858: import de.intevation.flys.client.client.Config; felix@858: import de.intevation.flys.client.shared.model.Artifact; felix@858: import de.intevation.flys.client.shared.model.Collection; felix@858: import de.intevation.flys.client.shared.model.Data; felix@858: import de.intevation.flys.client.shared.model.DefaultArtifact; felix@858: import de.intevation.flys.client.shared.model.DefaultData; felix@858: import de.intevation.flys.client.shared.model.FacetRecord; felix@1436: import de.intevation.flys.client.shared.model.OutputMode; felix@1436: import de.intevation.flys.client.shared.model.Theme; felix@1436: import de.intevation.flys.client.shared.model.ThemeList; felix@858: felix@1444: import de.intevation.flys.client.client.services.CrossSectionKMServiceAsync; felix@1379: import de.intevation.flys.client.client.services.FeedServiceAsync; felix@1444: import de.intevation.flys.client.client.services.LoadArtifactService; felix@1444: import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; felix@1444: felix@1472: import de.intevation.flys.client.client.ui.CollectionView; felix@1472: felix@1444: felix@858: felix@858: /** felix@858: * ThemePanel much like ChartThemePanel, but shows an "Actions" column, felix@1457: * needed for interaction in the CrossSection Charts and a selector to felix@1436: * declare which cross section profile is "master". felix@1457: * Also can show 'area creation' context menus. felix@858: */ felix@858: public class CrossSectionChartThemePanel felix@858: extends ChartThemePanel { felix@1444: /** Artifact Clone/Creation service. */ felix@1444: protected LoadArtifactServiceAsync loadService = felix@1444: GWT.create(LoadArtifactService.class); felix@858: felix@1436: /** Service to query measurement points of cross sections. */ felix@1436: CrossSectionKMServiceAsync kmService = GWT.create( felix@1436: de.intevation.flys.client.client.services.CrossSectionKMService.class); felix@1436: felix@1436: /** UUID of the current "master" cross section. */ felix@1470: protected String currentCSMasterUUID; felix@1436: felix@1436: /** The layout (used for visual active/inactive feedback). */ felix@1436: protected VLayout layout; felix@1436: felix@1475: /** Data item name for CrossSections selected km. */ felix@1476: protected static String CS_KM = "cross_section.km"; felix@1476: felix@1476: /** Data item name for CrossSections selected km. */ felix@1476: protected static String CS_IS_MASTER = "cross_section.master?"; felix@1475: felix@1519: /** Whether or not to move through all cross sections synchronously. */ felix@1519: protected boolean synchronNavigation; felix@1519: raimund@1533: /** Data for master artifact combobox.*/ raimund@1533: protected LinkedHashMap masters; raimund@1533: raimund@1533: /** Combobox for master artifacts.*/ raimund@1533: protected SelectItem masterCb; felix@1475: felix@858: /** felix@858: * Trivial constructor. felix@858: */ felix@858: public CrossSectionChartThemePanel( felix@1475: OutputMode mode, felix@1475: CollectionView view) felix@858: { felix@1555: super(mode, view); felix@1475: } felix@1475: felix@1475: felix@1475: /** Create DefaultArtifact. */ felix@1475: public static DefaultArtifact artifactReference(String uuid) { felix@1475: return new DefaultArtifact(uuid, "TODO:hash"); felix@1475: } felix@1475: felix@1475: felix@1475: /** Access data of collection item of theme. */ felix@1475: public static String dataOf(Theme theme, String dataItemName) { felix@1475: return theme.getCollectionItem().getData().get(dataItemName); felix@858: } felix@858: felix@858: felix@858: /** felix@1436: * Feed an artifact to let it know that it is master wrt cross-sections. felix@1436: * @param artifact uuid of an artifact. felix@1436: */ felix@1436: public void feedTellMaster(final String artifact) { felix@1436: Data[] feedData = DefaultData.createSimpleStringDataArray( felix@1476: CS_IS_MASTER, "1"); felix@1436: felix@1436: feedService.feed( felix@1436: Config.getInstance().getLocale(), felix@1475: artifactReference(artifact), felix@1436: feedData, felix@1436: new AsyncCallback() { felix@1436: public void onFailure(Throwable caught) { felix@1436: GWT.log("Could not feed artifact (" + artifact felix@1436: + ") with master marker: " + caught.getMessage()); felix@1436: SC.warn(MSG.getString(caught.getMessage())); felix@1436: enable(); felix@1436: } felix@1436: public void onSuccess(Artifact artifact) { felix@1436: GWT.log("Successfully injected master mark to " + artifact); felix@1470: setCurrentCSMaster(artifact.getUuid()); felix@1436: requestRedraw(); felix@1436: enable(); felix@1436: } felix@1436: }); felix@1436: } felix@1436: felix@1436: felix@1444: felix@1444: /** felix@1470: * Sets currentCSMasterUUID. felix@1438: */ felix@1470: public String findCurrentCSMaster() { felix@1438: ThemeList themeList = getThemeList(); felix@1438: int count = getThemeList().getThemeCount(); felix@1445: String firstCSUuid = null; felix@1475: Theme firstCS = null; felix@1438: for (int i = 1; i <= count; i++) { felix@1438: Theme theme = themeList.getThemeAt(i); felix@1476: String value = dataOf(theme, CS_IS_MASTER); felix@1438: felix@1445: if (value != null) { felix@1445: if (firstCSUuid == null) { felix@1445: firstCSUuid = theme.getArtifact(); felix@1475: firstCS = theme; felix@1445: } felix@1445: if (!value.equals("0")) { felix@1470: setCurrentCSMaster(theme.getArtifact()); felix@1472: GWT.log("found a master: " + currentCSMasterUUID felix@1472: + "/" + theme.getDescription()); felix@1445: return theme.getDescription(); felix@1445: } felix@1438: } felix@1438: } felix@1445: // There is none selected. Take the first one. felix@1445: if (firstCSUuid != null) { felix@1470: setCurrentCSMaster(firstCSUuid); felix@1445: feedTellMaster(firstCSUuid); felix@1445: } felix@1438: return null; felix@1438: } felix@1438: felix@1444: felix@1438: /** felix@1436: * Create Layout, add a master selection box beneath. felix@1436: */ felix@1436: @Override felix@1436: protected VLayout createLayout() { felix@1438: layout = super.createLayout(); felix@1436: felix@1436: // Create "set master" combobox. raimund@1533: masterCb = new SelectItem(); felix@1436: raimund@1533: masterCb.setTitle(MSG.chart_themepanel_set_master()); raimund@1533: masterCb.setType("comboBox"); raimund@1533: masters = getThemeList().toMapArtifactUUIDDescription("cross_section"); raimund@1533: masterCb.setValueMap(masters); felix@1436: felix@1436: final DynamicForm form = new DynamicForm(); felix@1436: form.setWidth(200); raimund@1533: form.setFields(masterCb); felix@1436: layout.addMember(form); felix@1436: felix@1438: Config config = Config.getInstance(); felix@1438: final String locale = config.getLocale(); felix@1470: findCurrentCSMaster(); raimund@1533: masterCb.setValue(getCurrentCSMaster()); felix@1436: felix@1436: // Add Change Handler to first unset the old master and then set the felix@1436: // new master. raimund@1533: masterCb.addChangeHandler(new ChangeHandler() { felix@1436: public void onChange(ChangeEvent event) { felix@1436: String selectedItem = (String) event.getValue(); felix@1436: final String artifact = selectedItem; felix@1436: felix@1436: disable(); felix@1436: felix@1436: // Tell current master that he is not master anymore. felix@1470: if (getCurrentCSMaster() != null) { felix@1436: Data[] feedData = DefaultData.createSimpleStringDataArray( felix@1476: CS_IS_MASTER, "0"); felix@1436: feedService.feed( felix@1436: locale, felix@1475: artifactReference(getCurrentCSMaster()), felix@1436: feedData, felix@1436: new AsyncCallback() { felix@1436: public void onFailure(Throwable caught) { felix@1470: GWT.log("Could not un-master artifact ("+getCurrentCSMaster()+"): " + felix@1436: caught.getMessage()); felix@1436: SC.warn(MSG.getString(caught.getMessage())); felix@1436: enable(); felix@1436: } felix@1436: public void onSuccess(Artifact oldMaster) { felix@1436: GWT.log("Successfully un-mastered artifact."); felix@1436: feedTellMaster(artifact); felix@1436: } felix@1436: }); felix@1436: } felix@1436: else { felix@1436: feedTellMaster(artifact); felix@1436: } felix@1436: } felix@1436: }); felix@1436: felix@1436: return layout; felix@1436: } felix@1436: felix@1436: felix@1436: /** Disable the UI (becomes gray, inresponsive to user input). */ felix@1436: public void disable() { felix@1436: this.layout.setDisabled(true); felix@1436: } felix@1436: felix@1436: felix@1436: /** DisDisable the UI (becomes ungray, responsive to user input). */ felix@1436: public void enable() { felix@1436: this.layout.setDisabled(false); felix@1436: } felix@1436: felix@1436: felix@1436: /** felix@1436: * Returns a double from the list that has the smallest distance to the felix@1436: * given to value. In case of multiple values with the same difference, felix@1436: * the last one is taken. felix@1436: * @param in possible return values. felix@1436: * @param to the value to be as close to as possible. felix@1436: * @return value from in that is closest to to, -1 if none. felix@1436: */ felix@1436: public static double closest(Double[] in, double to) { felix@1436: if (in == null || in.length == 0) { felix@1436: return -1; felix@1436: } felix@1436: if (in[0] == to) { felix@1436: return to; felix@1436: } felix@1436: double minDiff = Math.abs(to - in[0]); felix@1436: double bestMatch = in[0]; felix@1436: for (int i = 1; i < in.length; i++) { felix@1436: if (in[i] == to) { felix@1436: return to; felix@1436: } felix@1436: double diff = Math.abs(to - in[0]); felix@1436: if (diff < minDiff) { felix@1436: minDiff = diff; felix@1436: bestMatch = in[i]; felix@1436: } felix@1436: } felix@1436: return bestMatch; felix@1436: } felix@1436: felix@1519: /** Feed a single artifact with the km of the crosssection to display. felix@1519: * If its the selected master, also feed the collectionmaster. */ felix@1519: public void sendFeed(final List artifacts, final double kmD) { felix@1519: Config config = Config.getInstance(); felix@1519: final String locale = config.getLocale(); felix@1519: felix@1519: Data[] feedData = felix@1519: DefaultData.createSimpleStringDataArray(CS_KM, felix@1519: Double.valueOf(kmD).toString()); felix@1519: felix@1519: disable(); felix@1519: feedService.feedMany( felix@1519: locale, felix@1519: artifacts, felix@1519: feedData, felix@1519: new AsyncCallback>() { felix@1519: @Override felix@1519: public void onFailure(Throwable caught) { felix@1519: GWT.log("Could not feed many artifacts " + caught.getMessage()); felix@1519: SC.warn(MSG.getString(caught.getMessage())); felix@1519: enable(); felix@1519: } felix@1519: @Override felix@1519: public void onSuccess(List artifact) { felix@1519: GWT.log("Successfully fed many with km"); felix@1519: requestRedraw(); felix@1519: enable(); felix@1519: } felix@1519: }); felix@1519: } felix@1436: felix@1475: /** Feed a single artifact with the km of the crosssection to display. felix@1475: * If its the selected master, also feed the collectionmaster. */ felix@1472: public void sendFeed(final String artUUID, final double kmD) { felix@1472: Config config = Config.getInstance(); felix@1472: final String locale = config.getLocale(); felix@1436: felix@1436: Data[] feedData = felix@1476: DefaultData.createSimpleStringDataArray(CS_KM, felix@1436: Double.valueOf(kmD).toString()); felix@1436: felix@1436: disable(); felix@1436: feedService.feed( felix@1436: locale, felix@1475: artifactReference(artUUID), felix@1436: feedData, felix@1436: new AsyncCallback() { felix@1436: @Override felix@1436: public void onFailure(Throwable caught) { felix@1436: GWT.log("Could not feed artifact " + caught.getMessage()); felix@1436: SC.warn(MSG.getString(caught.getMessage())); felix@1436: enable(); felix@1436: } felix@1436: @Override felix@1436: public void onSuccess(Artifact artifact) { felix@1472: GWT.log("Successfully fed with km"); felix@1436: requestRedraw(); felix@1496: enable(); felix@1436: } felix@1436: }); felix@1436: } felix@1436: felix@1436: felix@1436: /** felix@1379: * Create the handler for ChangeEvents on the Spinner in the felix@1379: * facets that control km of cross section. felix@1379: * felix@1379: * @param feedService The FeedService to send (changed) data to. felix@1379: * @param facetRecord The FacetRecord (~row in table) where this felix@1379: * handler is added to (to a child, to be exact). felix@1379: */ felix@1379: public final ChangedHandler createSpinnerHandler( felix@1379: final FeedServiceAsync feedService, felix@1379: final FacetRecord facetRecord) felix@1379: { felix@1496: Config config = Config.getInstance(); felix@1496: final String locale = config.getLocale(); felix@1379: felix@1379: ChangedHandler handler = new ChangedHandler() felix@1379: { felix@1379: @Override felix@1436: public void onChanged(final ChangedEvent ce) { felix@1379: if (ce.getValue() == null) { felix@1379: return; felix@1379: } felix@1436: felix@1436: // Now, query the value with the kmService. felix@1436: Map map = new HashMap(); felix@1436: final double selected_km = felix@1436: Double.parseDouble(ce.getValue().toString()); felix@1436: felix@1436: int _dbid = -1; felix@1436: try { felix@1436: _dbid = Integer.valueOf(facetRecord.getTheme() felix@1436: .getCollectionItem() felix@1436: .getData().get("cross_section.dbid")); felix@1436: } felix@1436: catch (NumberFormatException nfe) { felix@1436: GWT.log("Could not extract cross-section db id from data."); felix@1436: } felix@1436: final int dbid = _dbid; felix@1436: felix@1436: map.put(dbid, Double.parseDouble(ce.getValue().toString())); felix@1436: felix@1436: disable(); felix@1436: felix@1436: kmService.getCrossSectionKMs(locale, map, 2, felix@1436: new AsyncCallback>() { felix@1436: @Override felix@1379: public void onFailure(Throwable caught) { felix@1436: GWT.log("Could not get single km for " felix@1436: + dbid + ": "+ caught.getMessage()); felix@1436: SC.warn(MSG.getString(caught.getMessage())); felix@1436: updateCollection(); felix@1436: updateGrid(); felix@1436: enable(); felix@1379: } felix@1436: @Override felix@1436: public void onSuccess(Map obj) { felix@1436: Double[] kms = obj.get(dbid); felix@1436: double closest = felix@1436: CrossSectionChartThemePanel.closest(kms, felix@1436: selected_km); felix@1436: GWT.log("Got single km for " + dbid + ", it is " felix@1436: + closest); felix@1436: SpinnerItem item = (SpinnerItem) ce.getItem(); felix@1436: item.setValue(closest); felix@1519: if (synchronNavigation) { felix@1519: // Feed many ... felix@1519: // Find all activated cross section themes felix@1519: ThemeList themes = getThemeList(); felix@1519: int nThemes = themes.getThemeCount(); felix@1519: List artifacts = new ArrayList(); felix@1519: for (int i = 0; i < nThemes; i++) { felix@1519: final Theme theme = themes.getThemeAt(i+1); felix@1519: if (theme.getFacet().equals("cross_section") && felix@1519: theme.getActive() == 1) { felix@1519: artifacts.add(artifactReference(theme.getArtifact())); felix@1519: } felix@1519: } felix@1519: sendFeed(artifacts, felix@1472: closest); felix@1519: } felix@1519: else { felix@1519: sendFeed(facetRecord.getTheme().getArtifact(), felix@1519: closest); felix@1519: } felix@1379: } felix@1519: }); felix@1379: } felix@1379: }; felix@1379: return handler; felix@1379: } felix@1379: felix@1379: felix@1379: /** felix@1438: * Create a "kilometer spinner" for CrossSection Facets. felix@1438: * @param facetRecord The respective Facet/Theme. felix@1438: * @return label, intialized SpinnerItem. felix@1438: */ felix@1438: public SpinnerItem createSpinnerItem(FacetRecord facetRecord) { felix@1438: SpinnerItem spinnerItem = new SpinnerItem(); felix@1438: spinnerItem.setShowTitle(false); felix@1438: spinnerItem.setTitle("Waterlevel-Spinner"); felix@1438: spinnerItem.setWidth(45); felix@1496: spinnerItem.setDefaultValue(Double.valueOf(facetRecord.getTheme() felix@1438: .getCollectionItem() felix@1496: .getData().get(CS_KM))); felix@1438: felix@1438: spinnerItem.setMin(0); felix@1475: spinnerItem.setMax(2000); felix@1496: spinnerItem.setStep(0.1f); felix@1438: spinnerItem.setChangeOnKeypress(true); felix@1438: return spinnerItem; felix@1438: } felix@1438: felix@1438: felix@1438: /** felix@858: * Create and configure the Grid to display. felix@1438: * @return ListGrid with Themes and related controls inside. felix@858: */ felix@858: @Override felix@858: protected ListGrid createGrid() { felix@858: ListGrid list = new ListGrid() { felix@858: @Override felix@1379: protected Canvas createRecordComponent( felix@1379: final ListGridRecord record, felix@1379: Integer colNum) felix@1379: { felix@861: // Only cross_section Facets display an action widget. felix@861: final FacetRecord facetRecord = (FacetRecord) record; felix@861: if (!facetRecord.getTheme().getFacet().equals( felix@1379: "cross_section")) felix@1379: { felix@861: return null; felix@861: } felix@858: felix@858: String fieldName = this.getFieldName(colNum); felix@858: felix@888: if (fieldName.equals(GRID_FIELD_ACTIONS)) { felix@858: HLayout recordCanvas = new HLayout(3); felix@858: recordCanvas.setHeight(22); felix@858: recordCanvas.setAlign(Alignment.CENTER); felix@1438: SpinnerItem spinnerItem = createSpinnerItem(facetRecord); felix@1379: spinnerItem.addChangedHandler( felix@1438: createSpinnerHandler(feedService, facetRecord)); felix@858: felix@858: DynamicForm formWrap = new DynamicForm(); felix@858: formWrap.setFields(spinnerItem); felix@858: formWrap.setTitlePrefix(""); felix@858: formWrap.setTitleSuffix(""); felix@858: recordCanvas.addMember(formWrap); felix@858: return recordCanvas; felix@858: } felix@858: else { felix@858: return null; felix@858: } felix@858: } felix@858: }; felix@858: list.setCanResizeFields(true); felix@858: list.setShowRecordComponents(true); felix@858: list.setShowRecordComponentsByCell(true); felix@858: list.setShowAllRecords(true); felix@1378: list.setShowHeaderContextMenu(false); felix@858: return list; felix@858: } felix@858: felix@858: felix@858: /** felix@858: * Initializes the components (columns) of the theme grid. felix@858: */ felix@858: @Override felix@858: protected void initGrid() { felix@858: list.setCanEdit(true); felix@858: list.setCanSort(false); felix@858: list.setShowRecordComponents(true); felix@858: list.setShowRecordComponentsByCell(true); felix@858: list.setShowHeader(true); felix@858: list.setWidth100(); felix@858: list.setHeight100(); felix@858: felix@858: list.addEditCompleteHandler(this); felix@858: felix@858: ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20); felix@858: active.setType(ListGridFieldType.BOOLEAN); felix@858: felix@858: ListGridField name = new ListGridField( felix@858: GRID_FIELD_NAME, MSG.chart_themepanel_header_themes()); felix@858: name.setType(ListGridFieldType.TEXT); felix@858: felix@858: ListGridField actions = new ListGridField(GRID_FIELD_ACTIONS, felix@891: MSG.chart_themepanel_header_actions(), 50); felix@858: felix@858: list.setFields(active, name, actions); felix@858: } felix@1436: felix@1436: felix@1436: /** Get Current Cross-section Masters uuid. */ felix@1470: public String getCurrentCSMaster() { felix@1470: return currentCSMasterUUID; felix@1436: } felix@1436: felix@1436: felix@1436: /** Set Current Cross-section Masters uuid. */ felix@1470: public void setCurrentCSMaster(String currentMasterUuid) { felix@1470: this.currentCSMasterUUID = currentMasterUuid; felix@1436: } felix@1444: felix@1444: felix@1457: /** Returns name of cross section area facets. */ felix@1457: protected String getAreaFacetName() { felix@1457: return "cross_section.area"; felix@1457: } felix@1444: felix@1444: felix@1444: /** felix@1457: * Return true if two themes are canditates for an area being felix@1457: * rendered between them. felix@1457: * TODO join with canArea, generalize to allow easier modification felix@1457: * in subclasses. felix@1444: */ felix@1457: protected boolean areAreaCompatible(Theme a, Theme b) { felix@1457: if (a.equals(b)) { felix@1457: return false; felix@1444: } felix@1457: return (a.getFacet().equals("cross_section") felix@1457: || a.getFacet().equals("cross_section_water_line")) felix@1457: && (b.getFacet().equals("cross_section") felix@1457: || b.getFacet().equals("cross_section_water_line")); felix@1457: } felix@1444: felix@1452: felix@1457: /** felix@1457: * True if context menu should contain 'create area' submenu on felix@1457: * this theme. felix@1457: */ felix@1457: protected boolean canArea(Theme a) { felix@1457: return a.getFacet().equals("cross_section") felix@1457: || a.getFacet().equals("cross_section_water_line"); felix@1444: } felix@1519: felix@1519: felix@1519: /** felix@1519: * Include synchron navigation item. felix@1519: */ felix@1519: @Override felix@1519: protected Menu getSingleContextMenu(final ListGridRecord[] records) { felix@1519: Menu contextMenu = super.getSingleContextMenu(records); felix@1519: felix@1519: // Synchron checking. felix@1519: MenuItem synchronNavigationMenuItem = new MenuItem(); felix@1519: if (synchronNavigation == true) { felix@1519: synchronNavigationMenuItem.setTitle("Einzeln navigieren"); felix@1519: } felix@1519: else { felix@1519: synchronNavigationMenuItem.setTitle("Synchron navigieren"); felix@1519: } felix@1519: synchronNavigationMenuItem.addClickHandler(new ClickHandler() { felix@1519: public void onClick(MenuItemClickEvent evt) { felix@1519: synchronNavigation = !synchronNavigation; felix@1519: } felix@1519: }); felix@1519: contextMenu.addItem(synchronNavigationMenuItem); felix@1519: felix@1519: return contextMenu; felix@1519: } raimund@1533: raimund@1533: raimund@1533: /** raimund@1533: * This method is used to clear the current theme grid and add new updated raimund@1533: * data. raimund@1533: */ raimund@1533: @Override raimund@1533: protected void updateGrid() { raimund@1533: GWT.log("CrossSectionChartThemePanel.updateGrid"); raimund@1533: raimund@1533: ListGridRecord[] selected = list.getSelectedRecords(); raimund@1533: raimund@1533: clearGrid(); raimund@1533: raimund@1533: ThemeList themeList = getThemeList(); raimund@1533: raimund@1533: if (themeList == null) { raimund@1533: GWT.log("ERROR: No theme list."); raimund@1533: return; raimund@1533: } raimund@1533: raimund@1533: int count = themeList.getThemeCount(); raimund@1533: raimund@1533: for (int i = 1; i <= count; i++) { raimund@1533: Theme theme = themeList.getThemeAt(i); raimund@1533: raimund@1533: if(theme.getFacet().equals("empty.facet")) { raimund@1533: theme.setVisible(0); raimund@1533: } raimund@1533: raimund@1533: if (theme == null || theme.getVisible() == 0) { raimund@1533: continue; raimund@1533: } raimund@1533: raimund@1533: if (theme.getFacet().equals("cross_section")) { raimund@1533: addToReferences(theme); raimund@1533: } raimund@1533: raimund@1533: FacetRecord newRecord = createRecord(theme); raimund@1533: addFacetRecord(newRecord); raimund@1533: raimund@1533: String newArtifact = theme.getArtifact(); raimund@1533: String newFacet = theme.getFacet(); raimund@1533: int newIndex = theme.getIndex(); raimund@1533: raimund@1533: for (ListGridRecord r: selected) { raimund@1533: FacetRecord sel = (FacetRecord) r; raimund@1533: Theme oldTheme = sel.getTheme(); raimund@1533: raimund@1533: if (oldTheme.getArtifact().equals(newArtifact) raimund@1533: && oldTheme.getFacet().equals(newFacet) raimund@1533: && oldTheme.getIndex() == newIndex) { raimund@1533: list.selectRecord(newRecord); raimund@1533: } raimund@1533: } raimund@1533: } raimund@1533: raimund@1533: fireOutputParameterChanged(); raimund@1533: raimund@1533: } raimund@1533: raimund@1533: raimund@1533: /** raimund@1533: * Adds a cross section theme to the master artifacts combobox and finds raimund@1533: * a new master if necessary. raimund@1533: * raimund@1533: * @param theme The cross section theme. raimund@1533: */ raimund@1533: protected void addToReferences(Theme theme) { raimund@1533: masters.put(theme.getArtifact(), theme.getDescription()); raimund@1533: masterCb.setValueMap(masters); raimund@1533: findCurrentCSMaster(); raimund@1533: if (masterCb.getSelectedRecord() == null) { raimund@1533: masterCb.setValue(getCurrentCSMaster()); raimund@1533: } raimund@1533: } felix@858: } felix@858: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :